bare-module-traverse 1.3.2 → 1.4.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 (2) hide show
  1. package/index.js +32 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -16,10 +16,6 @@ module.exports = exports = function traverse(
16
16
  opts = {}
17
17
  }
18
18
 
19
- if (typeof listPrefix !== 'function') {
20
- listPrefix = defaultListPrefix
21
- }
22
-
23
19
  return {
24
20
  *[Symbol.iterator]() {
25
21
  const artifacts = { addons: [], assets: [] }
@@ -39,8 +35,14 @@ module.exports = exports = function traverse(
39
35
  } else if (value.prefix) {
40
36
  const result = []
41
37
 
42
- for (const url of listPrefix(value.prefix)) {
43
- result.push(url)
38
+ if (typeof listPrefix === 'function') {
39
+ for (const url of listPrefix(value.prefix)) {
40
+ result.push(url)
41
+ }
42
+ } else {
43
+ if (readModule(value.prefix) !== null) {
44
+ result.push(value.prefix)
45
+ }
44
46
  }
45
47
 
46
48
  next = generator.next(result)
@@ -74,8 +76,14 @@ module.exports = exports = function traverse(
74
76
  } else if (value.prefix) {
75
77
  const result = []
76
78
 
77
- for await (const url of listPrefix(value.prefix)) {
78
- result.push(url)
79
+ if (typeof listPrefix === 'function') {
80
+ for await (const url of listPrefix(value.prefix)) {
81
+ result.push(url)
82
+ }
83
+ } else {
84
+ if ((await readModule(value.prefix)) !== null) {
85
+ result.push(value.prefix)
86
+ }
79
87
  }
80
88
 
81
89
  next = generator.next(result)
@@ -93,8 +101,6 @@ module.exports = exports = function traverse(
93
101
  }
94
102
  }
95
103
 
96
- function* defaultListPrefix() {}
97
-
98
104
  exports.resolve = resolve
99
105
 
100
106
  exports.module = function* (url, source, artifacts, visited, opts = {}) {
@@ -257,8 +263,6 @@ exports.imports = function* (
257
263
 
258
264
  if (value.package) {
259
265
  next = resolver.next(JSON.parse(yield { module: value.package }))
260
- } else if (hasResolution(imports, specifier, matchedConditions)) {
261
- next = resolver.next(false)
262
266
  } else {
263
267
  const url = value.resolution
264
268
 
@@ -271,6 +275,22 @@ exports.imports = function* (
271
275
  addResolution(imports, specifier, matchedConditions, url)
272
276
 
273
277
  resolved = yielded = true
278
+ } else if (condition === 'asset') {
279
+ const prefix = yield { prefix: url }
280
+
281
+ if (prefix.length !== 0) {
282
+ addResolution(imports, specifier, matchedConditions, url)
283
+
284
+ for (const url of prefix) {
285
+ yield {
286
+ children: exports.module(url, null, artifacts, visited, opts)
287
+ }
288
+
289
+ addURL(artifacts.assets, url)
290
+ }
291
+
292
+ resolved = yielded = true
293
+ }
274
294
  } else {
275
295
  const source = yield { module: url }
276
296
 
@@ -287,7 +307,6 @@ exports.imports = function* (
287
307
 
288
308
  if (resolved) {
289
309
  if (condition === 'addon') addURL(artifacts.addons, url)
290
- else if (condition === 'asset') addURL(artifacts.assets, url)
291
310
 
292
311
  resolutions++
293
312
  }
@@ -497,22 +516,6 @@ function removeURL(array, url) {
497
516
  if (array[lo].href === url.href) array.splice(lo, 1)
498
517
  }
499
518
 
500
- function hasResolution(imports, specifier, conditions) {
501
- if (specifier in imports === false) return false
502
-
503
- let current = imports[specifier]
504
-
505
- for (const key of conditions) {
506
- if (key in current === false || typeof current[key] !== 'object') {
507
- return false
508
- }
509
-
510
- current = current[key]
511
- }
512
-
513
- return true
514
- }
515
-
516
519
  function addResolution(imports, specifier, conditions, url) {
517
520
  imports[specifier] = imports[specifier] || {}
518
521
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",