bare-module-traverse 1.7.4 → 1.8.1

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 +22 -50
  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 {
@@ -319,11 +320,7 @@ exports.preresolved = function* (url, source, resolutions, artifacts, visited, o
319
320
 
320
321
  exports.imports = function* (parentURL, source, imports, artifacts, lexer, visited, opts = {}) {
321
322
  // Handle backwards compatibility with the `target` option
322
- if (opts.target) {
323
- const { target, ...rest } = opts
324
- rest.hosts = target
325
- opts = rest
326
- }
323
+ if (opts.target) opts = { ...opts, hosts: opts.target }
327
324
 
328
325
  const {
329
326
  resolve = exports.resolve.default,
@@ -401,21 +398,19 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
401
398
 
402
399
  resolved = yielded = true
403
400
  } else if (condition === 'asset') {
404
- const prefix = yield { prefix: url }
405
-
406
- if (prefix.length !== 0) {
407
- addResolution(imports, specifier, matchedConditions, url)
401
+ const prefix = url
408
402
 
409
- for (const url of prefix) {
410
- yield {
411
- children: exports.module(url, null, {}, artifacts, visited, opts)
412
- }
413
-
414
- addURL(artifacts.assets, url)
403
+ for (const url of yield { prefix }) {
404
+ yield {
405
+ children: exports.module(url, null, {}, artifacts, visited, opts)
415
406
  }
416
407
 
408
+ addURL(artifacts.assets, url)
409
+
417
410
  resolved = yielded = true
418
411
  }
412
+
413
+ if (resolved) addResolution(imports, specifier, matchedConditions, url)
419
414
  } else {
420
415
  const source = yield { module: url }
421
416
 
@@ -470,48 +465,25 @@ exports.imports = function* (parentURL, source, imports, artifacts, lexer, visit
470
465
  return yielded
471
466
  }
472
467
 
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
468
+ const ADDON_EXTENSION = /\.(bare|node)$/
490
469
 
470
+ exports.addons = function* (parentURL, artifacts, visited, opts = {}) {
491
471
  let yielded = false
492
472
 
493
- for (const host of hosts) {
494
- const prefix = new URL(host + '/', prebuildsURL)
473
+ if (ADDON_EXTENSION.test(parentURL.pathname)) {
474
+ const prefix = new URL(parentURL)
495
475
 
496
- const conditions = host.split('-')
497
-
498
- matchedConditions.push(...conditions)
476
+ prefix.pathname = prefix.pathname.replace(ADDON_EXTENSION, '') + '/'
499
477
 
500
478
  for (const url of yield { prefix }) {
501
- const source = yield { module: url }
502
-
503
- if (source !== null) {
504
- addURL(artifacts.addons, url)
479
+ yield {
480
+ children: exports.module(url, null, {}, artifacts, visited, opts)
481
+ }
505
482
 
506
- yield {
507
- children: exports.module(url, source, {}, artifacts, visited, opts)
508
- }
483
+ addURL(artifacts.addons, url)
509
484
 
510
- yielded = true
511
- }
485
+ yielded = true
512
486
  }
513
-
514
- for (const _ of conditions) matchedConditions.pop()
515
487
  }
516
488
 
517
489
  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.1",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {