bare-module-traverse 1.1.0 → 1.2.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 +6 -6
  2. package/index.js +14 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -17,8 +17,8 @@ function readModule (url) {
17
17
  // Read `url` if it exists, otherwise `null`
18
18
  }
19
19
 
20
- function listPrefix (url) {
21
- // Return a list of URLs that have `url` as a prefix. The list may be empty.
20
+ function * listPrefix (url) {
21
+ // Yield URLs that have `url` as a prefix. The list may be empty.
22
22
  }
23
23
 
24
24
  for (const dependency of traverse(new URL('file:///directory/file.js'), readModule, listPrefix)) {
@@ -35,8 +35,8 @@ async function readModule (url) {
35
35
  // Read `url` if it exists, otherwise `null`
36
36
  }
37
37
 
38
- async function listPrefix (url) {
39
- // Return a list of URLs that have `url` as a prefix. The list may be empty.
38
+ async function * listPrefix (url) {
39
+ // Yield URLs that have `url` as a prefix. The list may be empty.
40
40
  }
41
41
 
42
42
  for await (const dependency of traverse(new URL('file:///directory/file.js'), readModule, listPrefix)) {
@@ -48,7 +48,7 @@ for await (const dependency of traverse(new URL('file:///directory/file.js'), re
48
48
 
49
49
  #### `const dependencies = traverse(url[, options], readModule[, listPrefix])`
50
50
 
51
- Traverse the module graph rooted at `url`, which must be a WHATWG `URL` instance. `readModule` is called with a `URL` instance for every module to be read and must either return the module source, if it exists, or `null`. `listPrefix` is called with a `URL` instance of every prefix to be listed and must return a list of `URL` instances that have the specified `URL` as a prefix. If not provided, prefixes won't be traversed. If one or both of `readModule` or `listPrefix` returns a promise, synchronous iteration is not supported.
51
+ Traverse the module graph rooted at `url`, which must be a WHATWG `URL` instance. `readModule` is called with a `URL` instance for every module to be read and must either return the module source, if it exists, or `null`. `listPrefix` is called with a `URL` instance of every prefix to be listed and must return a list of `URL` instances that have the specified `URL` as a prefix. If not provided, prefixes won't be traversed. If `readModule` returns a promise or `listPrefix` returns a promise generator, synchronous iteration is not supported.
52
52
 
53
53
  Options include:
54
54
 
@@ -76,7 +76,7 @@ Synchronously iterate the module graph. Each yielded dependency has the followin
76
76
 
77
77
  #### `for await (const dependency of dependencies)`
78
78
 
79
- Asynchronously iterate the module graph. If one or both of `readModule` or `listPrefix` returns promises, these will be awaited. The same comments as `for (const dependency of dependencies)` apply.
79
+ Asynchronously iterate the module graph. If `readModule` returns a promise or `listPrefix` returns a promise generator, these will be awaited. The same comments as `for (const dependency of dependencies)` apply.
80
80
 
81
81
  ### Resolution
82
82
 
package/index.js CHANGED
@@ -32,7 +32,13 @@ module.exports = exports = function traverse (entry, opts, readModule, listPrefi
32
32
  if (value.module) {
33
33
  next = generator.next(readModule(value.module))
34
34
  } else if (value.prefix) {
35
- next = generator.next(listPrefix(value.prefix))
35
+ const result = []
36
+
37
+ for (const url of listPrefix(value.prefix)) {
38
+ result.push(url)
39
+ }
40
+
41
+ next = generator.next(result)
36
42
  } else {
37
43
  if (value.children) queue.push(value.children)
38
44
  else yield value.dependency
@@ -61,7 +67,13 @@ module.exports = exports = function traverse (entry, opts, readModule, listPrefi
61
67
  if (value.module) {
62
68
  next = generator.next(await readModule(value.module))
63
69
  } else if (value.prefix) {
64
- next = generator.next(await listPrefix(value.prefix))
70
+ const result = []
71
+
72
+ for await (const url of listPrefix(value.prefix)) {
73
+ result.push(url)
74
+ }
75
+
76
+ next = generator.next(result)
65
77
  } else {
66
78
  if (value.children) queue.push(value.children)
67
79
  else yield value.dependency
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",