bare-module-traverse 1.3.3 → 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 -11
  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 = {}) {
@@ -269,6 +275,22 @@ exports.imports = function* (
269
275
  addResolution(imports, specifier, matchedConditions, url)
270
276
 
271
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
+ }
272
294
  } else {
273
295
  const source = yield { module: url }
274
296
 
@@ -285,7 +307,6 @@ exports.imports = function* (
285
307
 
286
308
  if (resolved) {
287
309
  if (condition === 'addon') addURL(artifacts.addons, url)
288
- else if (condition === 'asset') addURL(artifacts.assets, url)
289
310
 
290
311
  resolutions++
291
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",