bare-module-traverse 1.2.2 → 1.2.4

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/index.js CHANGED
@@ -229,7 +229,7 @@ exports.preresolved = function * (url, source, resolutions, artifacts, visited,
229
229
  }
230
230
 
231
231
  exports.imports = function * (parentURL, source, imports, artifacts, visited, opts = {}) {
232
- const { resolve = exports.resolve.default } = opts
232
+ const { resolve = exports.resolve.default, builtinProtocol = 'builtin:', linkedProtocol = 'linked:' } = opts
233
233
 
234
234
  let yielded = false
235
235
 
@@ -252,12 +252,21 @@ exports.imports = function * (parentURL, source, imports, artifacts, visited, op
252
252
  const value = next.value
253
253
 
254
254
  if (value.package) {
255
- const url = value.package
256
- const source = yield { module: url }
257
-
258
- next = resolver.next(JSON.parse(source))
255
+ next = resolver.next(JSON.parse(yield { module: value.package }))
259
256
  } else {
260
257
  const url = value.resolution
258
+
259
+ if (url.protocol === builtinProtocol || url.protocol === linkedProtocol) {
260
+ if (key === 'addon') addURL(artifacts.addons, url)
261
+ else if (key === 'asset') addURL(artifacts.assets, url)
262
+
263
+ imports[specifier] = { [key]: url.href, ...imports[specifier] }
264
+
265
+ resolved = yielded = true
266
+
267
+ break
268
+ }
269
+
261
270
  const source = yield { module: url }
262
271
 
263
272
  if (source !== null) {
@@ -7,7 +7,8 @@ module.exports = function (entry, parentURL, opts = {}) {
7
7
  const {
8
8
  platform = runtime.platform,
9
9
  arch = runtime.arch,
10
- simulator = false
10
+ simulator = false,
11
+ host = `${platform}-${arch}${simulator ? '-simulator' : ''}`
11
12
  } = opts
12
13
 
13
14
  let extensions
@@ -19,7 +20,7 @@ module.exports = function (entry, parentURL, opts = {}) {
19
20
  extensions = ['.bare', '.node']
20
21
  conditions = ['addon', ...conditions]
21
22
 
22
- return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
23
+ return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, ...opts })
23
24
  }
24
25
 
25
26
  if (entry.type & lex.constants.ASSET) {
@@ -1,14 +1,26 @@
1
1
  const lex = require('bare-module-lexer')
2
2
  const resolve = require('../resolve')
3
3
 
4
- module.exports = function (entry, parentURL, opts) {
4
+ module.exports = function (entry, parentURL, opts = {}) {
5
+ const runtime = require('#runtime')
6
+
7
+ const {
8
+ platform = runtime.platform,
9
+ arch = runtime.arch,
10
+ simulator = false,
11
+ host = `${platform}-${arch}${simulator ? '-simulator' : ''}`
12
+ } = opts
13
+
5
14
  let extensions
6
- let conditions
15
+ let conditions = ['node', platform, arch]
16
+
17
+ if (simulator) conditions = [...conditions, 'simulator']
7
18
 
8
19
  if (entry.type & lex.constants.ADDON) {
9
20
  extensions = ['.node']
21
+ conditions = ['addon', ...conditions]
10
22
 
11
- return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
23
+ return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, ...opts })
12
24
  }
13
25
 
14
26
  if (entry.type & lex.constants.REQUIRE) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",