From ab924e1e53a331d77c6d7f63898ac1b8daf54d97 Mon Sep 17 00:00:00 2001 From: eternal Date: Tue, 26 Jul 2022 16:35:22 +0100 Subject: [PATCH 1/4] allow custom context paths (mainly for transpiled projects) --- pnpm-lock.yaml | 24 ++++++++++++++++++++++-- src/core/packageLoader/loadPackage.ts | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index afa8fd5..37dd763 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: 5.3 +lockfileVersion: 5.4 specifiers: '@swc/cli': ^0.1.51 @@ -236,6 +236,12 @@ packages: dev: true optional: true + /@types/keyv/3.1.4: + resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} + dependencies: + '@types/node': 16.9.1 + dev: true + /@types/minimatch/3.0.5: resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} dev: true @@ -248,7 +254,12 @@ packages: /@types/node/16.9.1: resolution: {integrity: sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==} dev: true - optional: true + + /@types/responselike/1.0.0: + resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} + dependencies: + '@types/node': 16.9.1 + dev: true /asar/3.1.0: resolution: {integrity: sha512-vyxPxP5arcAqN4F/ebHd/HhwnAiZtwhglvdmc7BR2f0ywbVNTOpSeyhLDbGXtE/y58hv1oC75TaNIXutnsOZsQ==} @@ -361,6 +372,11 @@ packages: /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.0.0 dev: true @@ -454,6 +470,8 @@ packages: debug: 2.6.9 mkdirp: 0.5.5 yauzl: 2.10.0 + transitivePeerDependencies: + - supports-color dev: true /fast-glob/3.2.7: @@ -592,6 +610,8 @@ packages: dependencies: '@sindresorhus/is': 0.14.0 '@szmarczak/http-timer': 1.1.2 + '@types/keyv': 3.1.4 + '@types/responselike': 1.0.0 cacheable-request: 6.1.0 decompress-response: 3.3.0 duplexer3: 0.1.4 diff --git a/src/core/packageLoader/loadPackage.ts b/src/core/packageLoader/loadPackage.ts index c13f4b6..25c27b3 100644 --- a/src/core/packageLoader/loadPackage.ts +++ b/src/core/packageLoader/loadPackage.ts @@ -14,7 +14,7 @@ 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}${pack[context]?.endsWith(".js") ? "" : ".js"}`); if (fs.existsSync(packageScript)) { const packageExport = require(packageScript); From 2ad31d79401a9e312bbbc9db2744a5827bd52c44 Mon Sep 17 00:00:00 2001 From: eternal Date: Tue, 26 Jul 2022 16:49:47 +0100 Subject: [PATCH 2/4] resolve using require.resolve to account for "index.js" and all other things --- src/core/packageLoader/loadPackage.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/packageLoader/loadPackage.ts b/src/core/packageLoader/loadPackage.ts index 25c27b3..157fb38 100644 --- a/src/core/packageLoader/loadPackage.ts +++ b/src/core/packageLoader/loadPackage.ts @@ -14,9 +14,17 @@ export default function loadPackage( const pack = getPackages()[packageID]; - const packageScript = path.join(pack.path, `${pack[context] ?? context}${pack[context]?.endsWith(".js") ? "" : ".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 From eac3316f1151704ad35f7cded05fe43218495152 Mon Sep 17 00:00:00 2001 From: eternal Date: Tue, 26 Jul 2022 16:50:51 +0100 Subject: [PATCH 3/4] ocd lul --- src/core/packageLoader/loadPackage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/packageLoader/loadPackage.ts b/src/core/packageLoader/loadPackage.ts index 157fb38..7591d0a 100644 --- a/src/core/packageLoader/loadPackage.ts +++ b/src/core/packageLoader/loadPackage.ts @@ -22,7 +22,7 @@ export default function loadPackage( } catch { return false; } - })() + })(); if (hasScript) { const packageExport = require(packageScript); From bcd4b6ad672b1e806dc6ae406fd7c422108fab01 Mon Sep 17 00:00:00 2001 From: eternal Date: Tue, 26 Jul 2022 16:53:31 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a5865a6..dbb4af4 100644 --- a/README.md +++ b/README.md @@ -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`