bare-module-traverse 1.7.3 → 1.8.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 +21 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -232,7 +232,7 @@ Options are the same as `traverse()` for all functions.
|
|
|
232
232
|
|
|
233
233
|
#### `const generator = traverse.imports(parentURL, source, imports, artifacts, visited[, options])`
|
|
234
234
|
|
|
235
|
-
#### `const generator = traverse.
|
|
235
|
+
#### `const generator = traverse.addons(parentURL, artifacts, visited[, options])`
|
|
236
236
|
|
|
237
237
|
#### `const generator = traverse.assets(patterns, parentURL, artifacts, visited[, options])`
|
|
238
238
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { lookupPackageScope, conditionMatches } = require('bare-module-resolve')
|
|
2
|
-
const { lookupPrebuildsScope } = require('bare-addon-resolve')
|
|
3
2
|
const lex = require('bare-module-lexer')
|
|
4
3
|
const resolve = require('./lib/resolve')
|
|
5
4
|
const errors = require('./lib/errors')
|
|
@@ -233,8 +232,10 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
|
|
|
233
232
|
|
|
234
233
|
const lexer = { imports: [] }
|
|
235
234
|
|
|
236
|
-
if (type === constants.SCRIPT || constants.MODULE) {
|
|
235
|
+
if (type === constants.SCRIPT || type === constants.MODULE) {
|
|
237
236
|
yield* exports.imports(url, source, imports, artifacts, lexer, visited, opts)
|
|
237
|
+
} else if (type === constants.ADDON) {
|
|
238
|
+
yield* exports.addons(url, artifacts, visited, opts)
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
yield {
|
|
@@ -254,10 +255,6 @@ exports.package = function* (url, source, artifacts, visited, opts = {}) {
|
|
|
254
255
|
if (info) {
|
|
255
256
|
yield { dependency: { url, source, imports: {}, lexer: { imports: [] } } }
|
|
256
257
|
|
|
257
|
-
if (info.addon) {
|
|
258
|
-
yield { children: exports.prebuilds(url, artifacts, visited, opts) }
|
|
259
|
-
}
|
|
260
|
-
|
|
261
258
|
if (info.assets) {
|
|
262
259
|
yield {
|
|
263
260
|
children: exports.assets(info.assets, url, artifacts, visited, opts)
|
|
@@ -405,21 +402,19 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
|
|
|
405
402
|
|
|
406
403
|
resolved = yielded = true
|
|
407
404
|
} else if (condition === 'asset') {
|
|
408
|
-
const prefix =
|
|
409
|
-
|
|
410
|
-
if (prefix.length !== 0) {
|
|
411
|
-
addResolution(imports, specifier, matchedConditions, url)
|
|
405
|
+
const prefix = url
|
|
412
406
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
addURL(artifacts.assets, url)
|
|
407
|
+
for (const url of yield { prefix }) {
|
|
408
|
+
yield {
|
|
409
|
+
children: exports.module(url, null, {}, artifacts, visited, opts)
|
|
419
410
|
}
|
|
420
411
|
|
|
412
|
+
addURL(artifacts.assets, url)
|
|
413
|
+
|
|
421
414
|
resolved = yielded = true
|
|
422
415
|
}
|
|
416
|
+
|
|
417
|
+
if (resolved) addResolution(imports, specifier, matchedConditions, url)
|
|
423
418
|
} else {
|
|
424
419
|
const source = yield { module: url }
|
|
425
420
|
|
|
@@ -474,48 +469,25 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
|
|
|
474
469
|
return yielded
|
|
475
470
|
}
|
|
476
471
|
|
|
477
|
-
|
|
478
|
-
// Handle backwards compatibility with the `target` option
|
|
479
|
-
if (opts.target) {
|
|
480
|
-
const { target, ...rest } = opts
|
|
481
|
-
rest.hosts = target
|
|
482
|
-
opts = rest
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const {
|
|
486
|
-
host = null, // Shorthand for single host resolution
|
|
487
|
-
hosts = host !== null ? [host] : [],
|
|
488
|
-
matchedConditions = []
|
|
489
|
-
} = opts
|
|
490
|
-
|
|
491
|
-
const [prebuildsURL = null] = lookupPrebuildsScope(packageURL, opts)
|
|
492
|
-
|
|
493
|
-
if (prebuildsURL === null) return false
|
|
472
|
+
const ADDON_EXTENSION = /\.(bare|node)$/
|
|
494
473
|
|
|
474
|
+
exports.addons = function* (parentURL, artifacts, visited, opts = {}) {
|
|
495
475
|
let yielded = false
|
|
496
476
|
|
|
497
|
-
|
|
498
|
-
const prefix = new URL(
|
|
477
|
+
if (ADDON_EXTENSION.test(parentURL.pathname)) {
|
|
478
|
+
const prefix = new URL(parentURL)
|
|
499
479
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
matchedConditions.push(...conditions)
|
|
480
|
+
prefix.pathname = prefix.pathname.replace(ADDON_EXTENSION, '') + '/'
|
|
503
481
|
|
|
504
482
|
for (const url of yield { prefix }) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
addURL(artifacts.addons, url)
|
|
483
|
+
yield {
|
|
484
|
+
children: exports.module(url, null, {}, artifacts, visited, opts)
|
|
485
|
+
}
|
|
509
486
|
|
|
510
|
-
|
|
511
|
-
children: exports.module(url, source, {}, artifacts, visited, opts)
|
|
512
|
-
}
|
|
487
|
+
addURL(artifacts.addons, url)
|
|
513
488
|
|
|
514
|
-
|
|
515
|
-
}
|
|
489
|
+
yielded = true
|
|
516
490
|
}
|
|
517
|
-
|
|
518
|
-
for (const _ of conditions) matchedConditions.pop()
|
|
519
491
|
}
|
|
520
492
|
|
|
521
493
|
return yielded
|