bare-module-traverse 1.2.0 → 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 +20 -11
- package/lib/errors.js +8 -0
- package/lib/resolve/bare.js +38 -0
- package/lib/resolve/default.js +10 -0
- package/lib/resolve/node.js +22 -0
- package/lib/resolve.js +3 -65
- package/package.json +5 -2
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
|
-
|
|
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[
|
|
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
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const lex = require('bare-module-lexer')
|
|
2
|
+
const resolve = require('../resolve')
|
|
3
|
+
|
|
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
|
+
} = opts
|
|
12
|
+
|
|
13
|
+
let extensions
|
|
14
|
+
let conditions = ['bare', 'node', platform, arch]
|
|
15
|
+
|
|
16
|
+
if (simulator) conditions = [...conditions, 'simulator']
|
|
17
|
+
|
|
18
|
+
if (entry.type & lex.constants.ADDON) {
|
|
19
|
+
extensions = ['.bare', '.node']
|
|
20
|
+
conditions = ['addon', ...conditions]
|
|
21
|
+
|
|
22
|
+
return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (entry.type & lex.constants.ASSET) {
|
|
26
|
+
conditions = ['asset', ...conditions]
|
|
27
|
+
} else {
|
|
28
|
+
extensions = ['.js', '.cjs', '.mjs', '.json', '.bare', '.node']
|
|
29
|
+
|
|
30
|
+
if (entry.type & lex.constants.REQUIRE) {
|
|
31
|
+
conditions = ['require', ...conditions]
|
|
32
|
+
} else if (entry.type & lex.constants.IMPORT) {
|
|
33
|
+
conditions = ['import', ...conditions]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return resolve.module(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const lex = require('bare-module-lexer')
|
|
2
|
+
const resolve = require('../resolve')
|
|
3
|
+
|
|
4
|
+
module.exports = function (entry, parentURL, opts) {
|
|
5
|
+
if (entry.type & lex.constants.ADDON) {
|
|
6
|
+
return resolve.addon(entry.specifier || '.', parentURL, opts)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return resolve.module(entry.specifier, parentURL, opts)
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const lex = require('bare-module-lexer')
|
|
2
|
+
const resolve = require('../resolve')
|
|
3
|
+
|
|
4
|
+
module.exports = function (entry, parentURL, opts) {
|
|
5
|
+
let extensions
|
|
6
|
+
let conditions
|
|
7
|
+
|
|
8
|
+
if (entry.type & lex.constants.ADDON) {
|
|
9
|
+
extensions = ['.node']
|
|
10
|
+
|
|
11
|
+
return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (entry.type & lex.constants.REQUIRE) {
|
|
15
|
+
extensions = ['.js', '.json', '.node']
|
|
16
|
+
conditions = ['node', 'require']
|
|
17
|
+
} else if (entry.type & lex.constants.IMPORT) {
|
|
18
|
+
conditions = ['node', 'import']
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return resolve.module(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
22
|
+
}
|
package/lib/resolve.js
CHANGED
|
@@ -1,68 +1,6 @@
|
|
|
1
|
-
const lex = require('bare-module-lexer')
|
|
2
|
-
|
|
3
1
|
exports.module = require('bare-module-resolve').module
|
|
4
2
|
exports.addon = require('bare-addon-resolve').addon
|
|
5
3
|
|
|
6
|
-
exports.default =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return exports.module(entry.specifier, parentURL, opts)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.bare = function resolve (entry, parentURL, opts = {}) {
|
|
15
|
-
const runtime = require('#runtime')
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
platform = runtime.platform,
|
|
19
|
-
arch = runtime.arch,
|
|
20
|
-
simulator = false
|
|
21
|
-
} = opts
|
|
22
|
-
|
|
23
|
-
let extensions
|
|
24
|
-
let conditions = ['bare', 'node', platform, arch]
|
|
25
|
-
|
|
26
|
-
if (simulator) conditions = [...conditions, 'simulator']
|
|
27
|
-
|
|
28
|
-
if (entry.type & lex.constants.ADDON) {
|
|
29
|
-
extensions = ['.bare', '.node']
|
|
30
|
-
conditions = ['addon', ...conditions]
|
|
31
|
-
|
|
32
|
-
return exports.addon(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (entry.type & lex.constants.ASSET) {
|
|
36
|
-
conditions = ['asset', ...conditions]
|
|
37
|
-
} else {
|
|
38
|
-
extensions = ['.js', '.cjs', '.mjs', '.json', '.bare', '.node']
|
|
39
|
-
|
|
40
|
-
if (entry.type & lex.constants.REQUIRE) {
|
|
41
|
-
conditions = ['require', ...conditions]
|
|
42
|
-
} else if (entry.type & lex.constants.IMPORT) {
|
|
43
|
-
conditions = ['import', ...conditions]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return exports.module(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.node = function resolve (entry, parentURL, opts) {
|
|
51
|
-
let extensions
|
|
52
|
-
let conditions
|
|
53
|
-
|
|
54
|
-
if (entry.type & lex.constants.ADDON) {
|
|
55
|
-
extensions = ['.node']
|
|
56
|
-
|
|
57
|
-
return exports.addon(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (entry.type & lex.constants.REQUIRE) {
|
|
61
|
-
extensions = ['.js', '.json', '.node']
|
|
62
|
-
conditions = ['node', 'require']
|
|
63
|
-
} else if (entry.type & lex.constants.IMPORT) {
|
|
64
|
-
conditions = ['node', 'import']
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return exports.module(entry.specifier, parentURL, { extensions, conditions, ...opts })
|
|
68
|
-
}
|
|
4
|
+
exports.default = require('./resolve/default')
|
|
5
|
+
exports.bare = require('./resolve/bare')
|
|
6
|
+
exports.node = require('./resolve/node')
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module-traverse",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Low-level module graph traversal for Bare",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
7
7
|
"./package": "./package.json",
|
|
8
|
-
"./resolve": "./lib/resolve.js"
|
|
8
|
+
"./resolve": "./lib/resolve.js",
|
|
9
|
+
"./resolve/default": "./lib/resolve/default.js",
|
|
10
|
+
"./resolve/bare": "./lib/resolve/bare.js",
|
|
11
|
+
"./resolve/node": "./lib/resolve/node.js"
|
|
9
12
|
},
|
|
10
13
|
"files": [
|
|
11
14
|
"index.js",
|