bare-module-traverse 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +96 -8
- package/lib/errors.js +8 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -211,7 +211,7 @@ Options are the same as `traverse()` for all functions.
|
|
|
211
211
|
> [!WARNING]
|
|
212
212
|
> These functions are currently subject to change between minor releases. If using them directly, make sure to specify a tilde range (`~1.2.3`) when declaring the module dependency.
|
|
213
213
|
|
|
214
|
-
#### `const generator = traverse.module(url, source, artifacts, visited[, options])`
|
|
214
|
+
#### `const generator = traverse.module(url, source, attributes, artifacts, visited[, options])`
|
|
215
215
|
|
|
216
216
|
#### `const generator = traverse.package(url, source, artifacts, visited[, options])`
|
|
217
217
|
|
package/index.js
CHANGED
|
@@ -20,7 +20,9 @@ module.exports = exports = function traverse(
|
|
|
20
20
|
*[Symbol.iterator]() {
|
|
21
21
|
const artifacts = { addons: [], assets: [] }
|
|
22
22
|
|
|
23
|
-
const queue = [
|
|
23
|
+
const queue = [
|
|
24
|
+
exports.module(entry, null, {}, artifacts, new Set(), opts)
|
|
25
|
+
]
|
|
24
26
|
|
|
25
27
|
while (queue.length > 0) {
|
|
26
28
|
const generator = queue.pop()
|
|
@@ -61,7 +63,9 @@ module.exports = exports = function traverse(
|
|
|
61
63
|
async *[Symbol.asyncIterator]() {
|
|
62
64
|
const artifacts = { addons: [], assets: [] }
|
|
63
65
|
|
|
64
|
-
const queue = [
|
|
66
|
+
const queue = [
|
|
67
|
+
exports.module(entry, null, {}, artifacts, new Set(), opts)
|
|
68
|
+
]
|
|
65
69
|
|
|
66
70
|
while (queue.length > 0) {
|
|
67
71
|
const generator = queue.pop()
|
|
@@ -103,7 +107,14 @@ module.exports = exports = function traverse(
|
|
|
103
107
|
|
|
104
108
|
exports.resolve = resolve
|
|
105
109
|
|
|
106
|
-
exports.module = function* (
|
|
110
|
+
exports.module = function* (
|
|
111
|
+
url,
|
|
112
|
+
source,
|
|
113
|
+
attributes,
|
|
114
|
+
artifacts,
|
|
115
|
+
visited,
|
|
116
|
+
opts = {}
|
|
117
|
+
) {
|
|
107
118
|
const { resolutions = null } = opts
|
|
108
119
|
|
|
109
120
|
if (visited.has(url.href)) return false
|
|
@@ -149,6 +160,23 @@ exports.module = function* (url, source, artifacts, visited, opts = {}) {
|
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
|
|
163
|
+
if (
|
|
164
|
+
typeof attributes === 'object' &&
|
|
165
|
+
attributes !== null &&
|
|
166
|
+
typeof attributes.imports === 'string'
|
|
167
|
+
) {
|
|
168
|
+
const url = new URL(attributes.imports)
|
|
169
|
+
|
|
170
|
+
const source = yield { module: url }
|
|
171
|
+
|
|
172
|
+
if (source !== null) {
|
|
173
|
+
opts = {
|
|
174
|
+
...opts,
|
|
175
|
+
imports: mixinImports(opts.imports, JSON.parse(source), url)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
152
180
|
yield* exports.imports(url, source, imports, artifacts, visited, opts)
|
|
153
181
|
|
|
154
182
|
yield { dependency: { url, source, imports: compressImportsMap(imports) } }
|
|
@@ -209,7 +237,7 @@ exports.preresolved = function* (
|
|
|
209
237
|
}
|
|
210
238
|
} else {
|
|
211
239
|
yield {
|
|
212
|
-
children: exports.module(url, null, artifacts, visited, opts)
|
|
240
|
+
children: exports.module(url, null, {}, artifacts, visited, opts)
|
|
213
241
|
}
|
|
214
242
|
}
|
|
215
243
|
} else {
|
|
@@ -241,6 +269,8 @@ exports.imports = function* (
|
|
|
241
269
|
|
|
242
270
|
let yielded = false
|
|
243
271
|
|
|
272
|
+
const queue = []
|
|
273
|
+
|
|
244
274
|
for (const entry of lex(source).imports) {
|
|
245
275
|
let specifier = entry.specifier
|
|
246
276
|
let condition = 'default'
|
|
@@ -252,6 +282,28 @@ exports.imports = function* (
|
|
|
252
282
|
condition = 'asset'
|
|
253
283
|
}
|
|
254
284
|
|
|
285
|
+
if (entry.attributes.imports) {
|
|
286
|
+
const specifier = entry.attributes.imports
|
|
287
|
+
|
|
288
|
+
queue.push({
|
|
289
|
+
entry: {
|
|
290
|
+
type: 0,
|
|
291
|
+
specifier,
|
|
292
|
+
names: [],
|
|
293
|
+
attributes: {},
|
|
294
|
+
position: [0, 0, 0]
|
|
295
|
+
},
|
|
296
|
+
specifier,
|
|
297
|
+
condition: 'default'
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
queue.push({ entry, specifier, condition })
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
while (queue.length > 0) {
|
|
305
|
+
const { entry, specifier, condition } = queue.shift()
|
|
306
|
+
|
|
255
307
|
matchedConditions.push(condition)
|
|
256
308
|
|
|
257
309
|
const resolver = resolve(entry, parentURL, { ...opts, matchedConditions })
|
|
@@ -285,7 +337,14 @@ exports.imports = function* (
|
|
|
285
337
|
|
|
286
338
|
for (const url of prefix) {
|
|
287
339
|
yield {
|
|
288
|
-
children: exports.module(
|
|
340
|
+
children: exports.module(
|
|
341
|
+
url,
|
|
342
|
+
null,
|
|
343
|
+
{},
|
|
344
|
+
artifacts,
|
|
345
|
+
visited,
|
|
346
|
+
opts
|
|
347
|
+
)
|
|
289
348
|
}
|
|
290
349
|
|
|
291
350
|
addURL(artifacts.assets, url)
|
|
@@ -299,8 +358,21 @@ exports.imports = function* (
|
|
|
299
358
|
if (source !== null) {
|
|
300
359
|
addResolution(imports, specifier, matchedConditions, url)
|
|
301
360
|
|
|
361
|
+
const attributes = entry.attributes
|
|
362
|
+
|
|
363
|
+
if (attributes.imports) {
|
|
364
|
+
attributes.imports = imports[attributes.imports].default
|
|
365
|
+
}
|
|
366
|
+
|
|
302
367
|
yield {
|
|
303
|
-
children: exports.module(
|
|
368
|
+
children: exports.module(
|
|
369
|
+
url,
|
|
370
|
+
source,
|
|
371
|
+
attributes,
|
|
372
|
+
artifacts,
|
|
373
|
+
visited,
|
|
374
|
+
opts
|
|
375
|
+
)
|
|
304
376
|
}
|
|
305
377
|
|
|
306
378
|
resolved = yielded = true
|
|
@@ -367,7 +439,7 @@ exports.prebuilds = function* (packageURL, artifacts, visited, opts = {}) {
|
|
|
367
439
|
addURL(artifacts.addons, url)
|
|
368
440
|
|
|
369
441
|
yield {
|
|
370
|
-
children: exports.module(url, source, artifacts, visited, opts)
|
|
442
|
+
children: exports.module(url, source, {}, artifacts, visited, opts)
|
|
371
443
|
}
|
|
372
444
|
|
|
373
445
|
yielded = true
|
|
@@ -397,7 +469,9 @@ exports.assets = function* (
|
|
|
397
469
|
if (source !== null) {
|
|
398
470
|
addURL(artifacts.assets, url)
|
|
399
471
|
|
|
400
|
-
yield {
|
|
472
|
+
yield {
|
|
473
|
+
children: exports.module(url, source, {}, artifacts, visited, opts)
|
|
474
|
+
}
|
|
401
475
|
|
|
402
476
|
yielded = true
|
|
403
477
|
}
|
|
@@ -582,3 +656,17 @@ function compressImportsMapEntry(resolved) {
|
|
|
582
656
|
|
|
583
657
|
return Object.fromEntries(entries)
|
|
584
658
|
}
|
|
659
|
+
|
|
660
|
+
function mixinImports(target, imports, url) {
|
|
661
|
+
if (typeof imports === 'object' && imports !== null && 'imports' in imports) {
|
|
662
|
+
imports = imports.imports
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (typeof imports !== 'object' || imports === null) {
|
|
666
|
+
throw errors.INVALID_IMPORTS_MAP(
|
|
667
|
+
`Imports map at '${url.href}' is not valid`
|
|
668
|
+
)
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return { ...target, ...imports }
|
|
672
|
+
}
|
package/lib/errors.js
CHANGED
|
@@ -35,4 +35,12 @@ module.exports = class ModuleTraverseError extends Error {
|
|
|
35
35
|
ModuleTraverseError.ASSET_NOT_FOUND
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
static INVALID_IMPORTS_MAP(msg) {
|
|
40
|
+
return new ModuleTraverseError(
|
|
41
|
+
msg,
|
|
42
|
+
'INVALID_IMPORTS_MAP',
|
|
43
|
+
ModuleTraverseError.INVALID_IMPORTS_MAP
|
|
44
|
+
)
|
|
45
|
+
}
|
|
38
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module-traverse",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Low-level module graph traversal for Bare",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"homepage": "https://github.com/holepunchto/bare-module-traverse#readme",
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"bare-addon-resolve": "^1.5.0",
|
|
57
|
-
"bare-module-lexer": "^1.
|
|
57
|
+
"bare-module-lexer": "^1.4.0",
|
|
58
58
|
"bare-module-resolve": "^1.7.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|