bare-module-traverse 1.2.3 → 1.2.5

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.
package/README.md CHANGED
@@ -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 `readModule` returns a promise or `listPrefix` returns a promise generator, 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 yield `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
 
package/index.js CHANGED
@@ -88,9 +88,7 @@ module.exports = exports = function traverse (entry, opts, readModule, listPrefi
88
88
  }
89
89
  }
90
90
 
91
- function defaultListPrefix () {
92
- return []
93
- }
91
+ function * defaultListPrefix () {}
94
92
 
95
93
  function addURL (array, url) {
96
94
  let lo = 0
@@ -229,7 +227,7 @@ exports.preresolved = function * (url, source, resolutions, artifacts, visited,
229
227
  }
230
228
 
231
229
  exports.imports = function * (parentURL, source, imports, artifacts, visited, opts = {}) {
232
- const { resolve = exports.resolve.default } = opts
230
+ const { resolve = exports.resolve.default, builtinProtocol = 'builtin:', linkedProtocol = 'linked:' } = opts
233
231
 
234
232
  let yielded = false
235
233
 
@@ -252,12 +250,21 @@ exports.imports = function * (parentURL, source, imports, artifacts, visited, op
252
250
  const value = next.value
253
251
 
254
252
  if (value.package) {
255
- const url = value.package
256
- const source = yield { module: url }
257
-
258
- next = resolver.next(JSON.parse(source))
253
+ next = resolver.next(JSON.parse(yield { module: value.package }))
259
254
  } else {
260
255
  const url = value.resolution
256
+
257
+ if (url.protocol === builtinProtocol || url.protocol === linkedProtocol) {
258
+ if (key === 'addon') addURL(artifacts.addons, url)
259
+ else if (key === 'asset') addURL(artifacts.assets, url)
260
+
261
+ imports[specifier] = { [key]: url.href, ...imports[specifier] }
262
+
263
+ resolved = yielded = true
264
+
265
+ break
266
+ }
267
+
261
268
  const source = yield { module: url }
262
269
 
263
270
  if (source !== null) {
@@ -5,6 +5,7 @@ module.exports = function (entry, parentURL, opts = {}) {
5
5
  const runtime = require('#runtime')
6
6
 
7
7
  const {
8
+ linked = false,
8
9
  platform = runtime.platform,
9
10
  arch = runtime.arch,
10
11
  simulator = false,
@@ -17,10 +18,10 @@ module.exports = function (entry, parentURL, opts = {}) {
17
18
  if (simulator) conditions = [...conditions, 'simulator']
18
19
 
19
20
  if (entry.type & lex.constants.ADDON) {
20
- extensions = ['.bare', '.node']
21
+ extensions = linked ? [] : ['.bare', '.node']
21
22
  conditions = ['addon', ...conditions]
22
23
 
23
- return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, ...opts })
24
+ return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, linked, ...opts })
24
25
  }
25
26
 
26
27
  if (entry.type & lex.constants.ASSET) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",