bare-module-traverse 1.2.1 → 1.2.2

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
@@ -238,6 +238,15 @@ exports.imports = function * (parentURL, source, imports, artifacts, visited, op
238
238
 
239
239
  let next = resolver.next()
240
240
  let resolved = false
241
+ let specifier = entry.specifier
242
+ let key = 'default'
243
+
244
+ if (entry.type & lex.constants.ADDON) {
245
+ specifier = specifier || '.'
246
+ key = 'addon'
247
+ } else if (entry.type & lex.constants.ASSET) {
248
+ key = 'asset'
249
+ }
241
250
 
242
251
  while (next.done !== true) {
243
252
  const value = next.value
@@ -252,17 +261,10 @@ exports.imports = function * (parentURL, source, imports, artifacts, visited, op
252
261
  const source = yield { module: url }
253
262
 
254
263
  if (source !== null) {
255
- let key = 'default'
256
-
257
- if (entry.type & lex.constants.ADDON) {
258
- key = 'addon'
259
- addURL(artifacts.addons, url)
260
- } else if (entry.type & lex.constants.ASSET) {
261
- key = 'asset'
262
- addURL(artifacts.assets, url)
263
- }
264
+ if (key === 'addon') addURL(artifacts.addons, url)
265
+ else if (key === 'asset') addURL(artifacts.assets, url)
264
266
 
265
- imports[entry.specifier] = { [key]: url.href, ...imports[entry.specifier] }
267
+ imports[specifier] = { [key]: url.href, ...imports[specifier] }
266
268
 
267
269
  yield { children: exports.module(url, source, artifacts, visited, opts) }
268
270
 
@@ -276,7 +278,14 @@ exports.imports = function * (parentURL, source, imports, artifacts, visited, op
276
278
  }
277
279
 
278
280
  if (!resolved) {
279
- throw errors.MODULE_NOT_FOUND(`Cannot find module '${entry.specifier}' imported from '${parentURL.href}'`)
281
+ switch (key) {
282
+ case 'addon':
283
+ throw errors.ADDON_NOT_FOUND(`Cannot find addon '${specifier}' imported from '${parentURL.href}'`)
284
+ case 'asset':
285
+ throw errors.ASSET_NOT_FOUND(`Cannot find asset '${specifier}' imported from '${parentURL.href}'`)
286
+ default:
287
+ throw errors.MODULE_NOT_FOUND(`Cannot find module '${specifier}' imported from '${parentURL.href}'`)
288
+ }
280
289
  }
281
290
  }
282
291
 
package/lib/errors.js CHANGED
@@ -15,4 +15,12 @@ module.exports = class ModuleTraverseError extends Error {
15
15
  static MODULE_NOT_FOUND (msg) {
16
16
  return new ModuleTraverseError(msg, 'MODULE_NOT_FOUND', ModuleTraverseError.MODULE_NOT_FOUND)
17
17
  }
18
+
19
+ static ADDON_NOT_FOUND (msg) {
20
+ return new ModuleTraverseError(msg, 'ADDON_NOT_FOUND', ModuleTraverseError.ADDON_NOT_FOUND)
21
+ }
22
+
23
+ static ASSET_NOT_FOUND (msg) {
24
+ return new ModuleTraverseError(msg, 'ASSET_NOT_FOUND', ModuleTraverseError.ASSET_NOT_FOUND)
25
+ }
18
26
  }
@@ -19,7 +19,7 @@ module.exports = function (entry, parentURL, opts = {}) {
19
19
  extensions = ['.bare', '.node']
20
20
  conditions = ['addon', ...conditions]
21
21
 
22
- return resolve.addon(entry.specifier, parentURL, { extensions, conditions, ...opts })
22
+ return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
23
23
  }
24
24
 
25
25
  if (entry.type & lex.constants.ASSET) {
@@ -3,7 +3,7 @@ const resolve = require('../resolve')
3
3
 
4
4
  module.exports = function (entry, parentURL, opts) {
5
5
  if (entry.type & lex.constants.ADDON) {
6
- return resolve.addon(entry.specifier, parentURL, opts)
6
+ return resolve.addon(entry.specifier || '.', parentURL, opts)
7
7
  }
8
8
 
9
9
  return resolve.module(entry.specifier, parentURL, opts)
@@ -8,7 +8,7 @@ module.exports = function (entry, parentURL, opts) {
8
8
  if (entry.type & lex.constants.ADDON) {
9
9
  extensions = ['.node']
10
10
 
11
- return resolve.addon(entry.specifier, parentURL, { extensions, conditions, ...opts })
11
+ return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
12
12
  }
13
13
 
14
14
  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.1",
3
+ "version": "1.2.2",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",