Skip to content

Commit

Permalink
Merge pull request #18 from localip/master
Browse files Browse the repository at this point in the history
allow custom context paths (mainly for transpiled projects) & update readme loader script
  • Loading branch information
Kyza committed Jul 26, 2022
2 parents 0dfb3db + bcd4b6a commit 3288843
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ Place these in the new `app` folder you made. Don't forget to change the `"locat
#### `index.js`

```js
const pkg = require("./package.json");
const Module = require("module");
const path = require("path");
require(path.join(
require(path.join(__dirname, "package.json")).location,
"kernel.asar"
));

try {
const kernel = require(path.join(pkg.location, "kernel.asar"));
if (kernel?.default) kernel.default({ startOriginal: true });
} catch(e) {
console.error("Kernel failed to load: ", e.message);
Module._load(path.join(__dirname, "..", "app-original.asar"), null, true);
}
```
#### `package.json`
Expand Down
24 changes: 22 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/core/packageLoader/loadPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ export default function loadPackage(

const pack = getPackages()[packageID];

const packageScript = path.join(pack.path, `${context}.js`);
const packageScript = path.join(pack.path, pack[context] ?? context);
const hasScript = (() => {
try {
require.resolve(packageScript);
return true;
} catch {
return false;
}
})();

if (fs.existsSync(packageScript)) {
if (hasScript) {
const packageExport = require(packageScript);
const packageInstance = packageExport.default
? packageExport.default
Expand Down

0 comments on commit 3288843

Please sign in to comment.