Skip to content

Commit 3288843

Browse files
authored
Merge pull request #18 from localip/master
allow custom context paths (mainly for transpiled projects) & update readme loader script
2 parents 0dfb3db + bcd4b6a commit 3288843

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ Place these in the new `app` folder you made. Don't forget to change the `"locat
2929
#### `index.js`
3030

3131
```js
32+
const pkg = require("./package.json");
33+
const Module = require("module");
3234
const path = require("path");
33-
require(path.join(
34-
require(path.join(__dirname, "package.json")).location,
35-
"kernel.asar"
36-
));
35+
36+
try {
37+
const kernel = require(path.join(pkg.location, "kernel.asar"));
38+
if (kernel?.default) kernel.default({ startOriginal: true });
39+
} catch(e) {
40+
console.error("Kernel failed to load: ", e.message);
41+
Module._load(path.join(__dirname, "..", "app-original.asar"), null, true);
42+
}
3743
```
3844
3945
#### `package.json`

pnpm-lock.yaml

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/packageLoader/loadPackage.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ export default function loadPackage(
1414

1515
const pack = getPackages()[packageID];
1616

17-
const packageScript = path.join(pack.path, `${context}.js`);
17+
const packageScript = path.join(pack.path, pack[context] ?? context);
18+
const hasScript = (() => {
19+
try {
20+
require.resolve(packageScript);
21+
return true;
22+
} catch {
23+
return false;
24+
}
25+
})();
1826

19-
if (fs.existsSync(packageScript)) {
27+
if (hasScript) {
2028
const packageExport = require(packageScript);
2129
const packageInstance = packageExport.default
2230
? packageExport.default

0 commit comments

Comments
 (0)