From b6b2cf83dcb7d711a55f9c6b3ddcb52ea4658025 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 00:26:29 +1000 Subject: [PATCH 1/6] support-bare-module --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index a1bded5..16806f7 100644 --- a/index.js +++ b/index.js @@ -186,6 +186,21 @@ module.exports = class DependencyStream extends Readable { const basedir = key.slice(0, key.lastIndexOf('/') + 1) const all = [] + for (const input of deps.imports) { + const output = await this._resolveModule(input, basedir) + const data = await this.drive.get(output) + if (data === null) throw new Error('Key not found: ' + key) + const source = b4a.toString(data) + const obj = JSON.parse(source) + const inputs = Object.values(obj) + const outputs = await Promise.all(inputs.map((item) => this._resolveModule(item, basedir))) + outputs.forEach(item => { + if (!result.resolutions.some(item => item.input === item)) { + result.resolutions.push({ isImport: false, position: null, input: item, output: null }) + } + }) + } + for (const res of result.resolutions) { if (isAddonPolyfill(res.input)) { result.addons.push({ From 3f1ba72dc3d20a7dc0b4754172779aab9d0bc52f Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 00:57:57 +1000 Subject: [PATCH 2/6] convert to for loop --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 16806f7..881d60f 100644 --- a/index.js +++ b/index.js @@ -194,11 +194,11 @@ module.exports = class DependencyStream extends Readable { const obj = JSON.parse(source) const inputs = Object.values(obj) const outputs = await Promise.all(inputs.map((item) => this._resolveModule(item, basedir))) - outputs.forEach(item => { - if (!result.resolutions.some(item => item.input === item)) { - result.resolutions.push({ isImport: false, position: null, input: item, output: null }) + for (const output of outputs) { + if (!result.resolutions.some(item => item.input === output)) { + result.resolutions.push({ isImport: false, position: null, input: output, output: null }) } - }) + } } for (const res of result.resolutions) { From cf1641c6e380d93b727f25e425b53b10a476dbf1 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 01:17:19 +1000 Subject: [PATCH 3/6] importsAttributes --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 881d60f..47e845c 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ module.exports = class DependencyStream extends Readable { const basedir = key.slice(0, key.lastIndexOf('/') + 1) const all = [] - for (const input of deps.imports) { + for (const input of deps.importsAttributes) { const output = await this._resolveModule(input, basedir) const data = await this.drive.get(output) if (data === null) throw new Error('Key not found: ' + key) From 1374299b1b42f0f96c1f4dd5676fc642aecef1ed Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 01:24:36 +1000 Subject: [PATCH 4/6] rename --- index.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 47e845c..a9f5d84 100644 --- a/index.js +++ b/index.js @@ -186,17 +186,37 @@ module.exports = class DependencyStream extends Readable { const basedir = key.slice(0, key.lastIndexOf('/') + 1) const all = [] - for (const input of deps.importsAttributes) { - const output = await this._resolveModule(input, basedir) - const data = await this.drive.get(output) + for (const attrInput of deps.importsAttributes) { + const attrOutput = await this._resolveModule(attrInput, basedir) + const data = await this.drive.get(attrOutput) if (data === null) throw new Error('Key not found: ' + key) + const source = b4a.toString(data) - const obj = JSON.parse(source) - const inputs = Object.values(obj) - const outputs = await Promise.all(inputs.map((item) => this._resolveModule(item, basedir))) - for (const output of outputs) { - if (!result.resolutions.some(item => item.input === output)) { - result.resolutions.push({ isImport: false, position: null, input: output, output: null }) + let obj = {} + try { + obj = JSON.parse(source) + } catch (err) { + const jsonErr = new Error(`Invalid import attribute json file: ${key}`) + jsonErr.code = 'ERROR_IMPORT_ATTRIBUTE_JSON_PARSE' + throw jsonErr + } + + const modules = Object.values(obj) + const resolvedModules = [] + for (const item of modules) { + try { + const res = await this._resolveModule(item, basedir) + resolvedModules.push(res) + } catch (err) { + const resolveErr = new Error(`Failed to resolve module ${item}`) + resolveErr.code = 'ERROR_IMPORT_ATTRIBUTE_MODULE_RESOLVE' + throw resolveErr + } + } + + for (const resolvedModule of resolvedModules) { + if (!result.resolutions.some(item => item.input === resolvedModule)) { + result.resolutions.push({ isImport: false, position: null, input: resolvedModule, output: null }) } } } From 72f8727a0b8c4ce67648c584f6f468136c202480 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 20:21:06 +1000 Subject: [PATCH 5/6] check deps.importsAttributes --- index.js | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index a9f5d84..957370f 100644 --- a/index.js +++ b/index.js @@ -186,37 +186,39 @@ module.exports = class DependencyStream extends Readable { const basedir = key.slice(0, key.lastIndexOf('/') + 1) const all = [] - for (const attrInput of deps.importsAttributes) { - const attrOutput = await this._resolveModule(attrInput, basedir) - const data = await this.drive.get(attrOutput) - if (data === null) throw new Error('Key not found: ' + key) - - const source = b4a.toString(data) - let obj = {} - try { - obj = JSON.parse(source) - } catch (err) { - const jsonErr = new Error(`Invalid import attribute json file: ${key}`) - jsonErr.code = 'ERROR_IMPORT_ATTRIBUTE_JSON_PARSE' - throw jsonErr - } - - const modules = Object.values(obj) - const resolvedModules = [] - for (const item of modules) { + if (deps.importsAttributes) { + for (const attrInput of deps.importsAttributes) { + const attrOutput = await this._resolveModule(attrInput, basedir) + const data = await this.drive.get(attrOutput) + if (data === null) throw new Error('Key not found: ' + key) + + const source = b4a.toString(data) + let obj = {} try { - const res = await this._resolveModule(item, basedir) - resolvedModules.push(res) + obj = JSON.parse(source) } catch (err) { - const resolveErr = new Error(`Failed to resolve module ${item}`) - resolveErr.code = 'ERROR_IMPORT_ATTRIBUTE_MODULE_RESOLVE' - throw resolveErr + const jsonErr = new Error(`Invalid import attribute json file: ${key}`) + jsonErr.code = 'ERROR_IMPORT_ATTRIBUTE_JSON_PARSE' + throw jsonErr + } + + const modules = Object.values(obj) + const resolvedModules = [] + for (const item of modules) { + try { + const res = await this._resolveModule(item, basedir) + resolvedModules.push(res) + } catch (err) { + const resolveErr = new Error(`Failed to resolve module ${item}`) + resolveErr.code = 'ERROR_IMPORT_ATTRIBUTE_MODULE_RESOLVE' + throw resolveErr + } } - } - for (const resolvedModule of resolvedModules) { - if (!result.resolutions.some(item => item.input === resolvedModule)) { - result.resolutions.push({ isImport: false, position: null, input: resolvedModule, output: null }) + for (const resolvedModule of resolvedModules) { + if (!result.resolutions.some(item => item.input === resolvedModule)) { + result.resolutions.push({ isImport: false, position: null, input: resolvedModule, output: null }) + } } } } From 50f463c25182df9f7a5862213d6744d90b0f89f4 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 17 Sep 2025 20:50:25 +1000 Subject: [PATCH 6/6] unwrap imports --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 957370f..dd37845 100644 --- a/index.js +++ b/index.js @@ -193,16 +193,21 @@ module.exports = class DependencyStream extends Readable { if (data === null) throw new Error('Key not found: ' + key) const source = b4a.toString(data) - let obj = {} + let imports = {} try { - obj = JSON.parse(source) + const obj = JSON.parse(source) + if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) { + throw new Error(`Invalid import attribute json file: ${key}`) + } + if ('imports' in obj) imports = obj.imports + else imports = obj } catch (err) { const jsonErr = new Error(`Invalid import attribute json file: ${key}`) - jsonErr.code = 'ERROR_IMPORT_ATTRIBUTE_JSON_PARSE' + jsonErr.code = 'INVALID_JSON' throw jsonErr } - const modules = Object.values(obj) + const modules = Object.values(imports) const resolvedModules = [] for (const item of modules) { try { @@ -210,7 +215,7 @@ module.exports = class DependencyStream extends Readable { resolvedModules.push(res) } catch (err) { const resolveErr = new Error(`Failed to resolve module ${item}`) - resolveErr.code = 'ERROR_IMPORT_ATTRIBUTE_MODULE_RESOLVE' + resolveErr.code = 'MODULE_NOT_FOUND' throw resolveErr } }