bare-module-traverse 1.2.0 → 1.2.1

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.
@@ -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 = function resolve (entry, parentURL, opts) {
7
- if (entry.type & lex.constants.ADDON) {
8
- return exports.addon(entry.specifier, parentURL, opts)
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.0",
3
+ "version": "1.2.1",
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",