Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,48 @@ module.exports = class DependencyStream extends Readable {
const basedir = key.slice(0, key.lastIndexOf('/') + 1)
const all = []

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 imports = {}
try {
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 = 'INVALID_JSON'
throw jsonErr
}

const modules = Object.values(imports)
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 = 'MODULE_NOT_FOUND'
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 res of result.resolutions) {
if (isAddonPolyfill(res.input)) {
result.addons.push({
Expand Down
Loading