bare-module-traverse 1.7.4 → 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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +21 -45
  3. 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.prebuilds(packageURL, artifacts, visited[, options])`
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 {
@@ -401,21 +402,19 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
401
402
 
402
403
  resolved = yielded = true
403
404
  } else if (condition === 'asset') {
404
- const prefix = yield { prefix: url }
405
+ const prefix = url
405
406
 
406
- if (prefix.length !== 0) {
407
- addResolution(imports, specifier, matchedConditions, url)
408
-
409
- for (const url of prefix) {
410
- yield {
411
- children: exports.module(url, null, {}, artifacts, visited, opts)
412
- }
413
-
414
- addURL(artifacts.assets, url)
407
+ for (const url of yield { prefix }) {
408
+ yield {
409
+ children: exports.module(url, null, {}, artifacts, visited, opts)
415
410
  }
416
411
 
412
+ addURL(artifacts.assets, url)
413
+
417
414
  resolved = yielded = true
418
415
  }
416
+
417
+ if (resolved) addResolution(imports, specifier, matchedConditions, url)
419
418
  } else {
420
419
  const source = yield { module: url }
421
420
 
@@ -470,48 +469,25 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
470
469
  return yielded
471
470
  }
472
471
 
473
- exports.prebuilds = function* (packageURL, artifacts, visited, opts = {}) {
474
- // Handle backwards compatibility with the `target` option
475
- if (opts.target) {
476
- const { target, ...rest } = opts
477
- rest.hosts = target
478
- opts = rest
479
- }
480
-
481
- const {
482
- host = null, // Shorthand for single host resolution
483
- hosts = host !== null ? [host] : [],
484
- matchedConditions = []
485
- } = opts
486
-
487
- const [prebuildsURL = null] = lookupPrebuildsScope(packageURL, opts)
488
-
489
- if (prebuildsURL === null) return false
472
+ const ADDON_EXTENSION = /\.(bare|node)$/
490
473
 
474
+ exports.addons = function* (parentURL, artifacts, visited, opts = {}) {
491
475
  let yielded = false
492
476
 
493
- for (const host of hosts) {
494
- const prefix = new URL(host + '/', prebuildsURL)
495
-
496
- const conditions = host.split('-')
477
+ if (ADDON_EXTENSION.test(parentURL.pathname)) {
478
+ const prefix = new URL(parentURL)
497
479
 
498
- matchedConditions.push(...conditions)
480
+ prefix.pathname = prefix.pathname.replace(ADDON_EXTENSION, '') + '/'
499
481
 
500
482
  for (const url of yield { prefix }) {
501
- const source = yield { module: url }
502
-
503
- if (source !== null) {
504
- addURL(artifacts.addons, url)
483
+ yield {
484
+ children: exports.module(url, null, {}, artifacts, visited, opts)
485
+ }
505
486
 
506
- yield {
507
- children: exports.module(url, source, {}, artifacts, visited, opts)
508
- }
487
+ addURL(artifacts.addons, url)
509
488
 
510
- yielded = true
511
- }
489
+ yielded = true
512
490
  }
513
-
514
- for (const _ of conditions) matchedConditions.pop()
515
491
  }
516
492
 
517
493
  return yielded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.7.4",
3
+ "version": "1.8.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {