bare-module 6.4.0 → 7.0.0
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 +237 -270
- package/binding.c +623 -333
- package/index.d.ts +156 -63
- package/index.js +87 -1002
- package/lib/errors.js +27 -10
- package/lib/loader.d.ts +56 -0
- package/lib/loader.js +1192 -0
- package/lib/module/addon.js +7 -0
- package/lib/module/binary.js +7 -0
- package/lib/module/builtin.js +19 -0
- package/lib/module/bundle.js +47 -0
- package/lib/module/json.js +19 -0
- package/lib/module/script.js +23 -0
- package/lib/module/source-text.js +13 -0
- package/lib/module/synthetic.js +20 -0
- package/lib/module/text.js +7 -0
- package/lib/module/value.js +27 -0
- package/lib/module.js +392 -0
- package/lib/protocol.d.ts +56 -8
- package/lib/protocol.js +93 -26
- package/lib/source.js +18 -0
- package/lib/url.js +52 -0
- package/package.json +18 -8
- package/prebuilds/android-arm/bare-module.bare +0 -0
- package/prebuilds/android-arm64/bare-module.bare +0 -0
- package/prebuilds/android-ia32/bare-module.bare +0 -0
- package/prebuilds/android-x64/bare-module.bare +0 -0
- package/prebuilds/darwin-arm64/bare-module.bare +0 -0
- package/prebuilds/darwin-x64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-module.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-module.bare +0 -0
- package/prebuilds/linux-arm64/bare-module.bare +0 -0
- package/prebuilds/linux-x64/bare-module.bare +0 -0
- package/prebuilds/win32-arm64/bare-module.bare +0 -0
- package/prebuilds/win32-x64/bare-module.bare +0 -0
- package/lib/constants.d.ts +0 -19
- package/lib/constants.js +0 -17
package/lib/protocol.js
CHANGED
|
@@ -1,55 +1,122 @@
|
|
|
1
|
-
|
|
1
|
+
const errors = require('./errors')
|
|
2
|
+
|
|
3
|
+
const kind = Symbol.for('bare.module.protocol.kind')
|
|
4
|
+
|
|
5
|
+
module.exports = exports = class ModuleProtocol {
|
|
6
|
+
static get [kind]() {
|
|
7
|
+
return 0 // Compatibility version
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static isProtocol(value) {
|
|
11
|
+
if (value instanceof ModuleProtocol) return true
|
|
12
|
+
|
|
13
|
+
if (typeof value !== 'object' || value === null) return false
|
|
14
|
+
|
|
15
|
+
return value[kind] === ModuleProtocol[kind]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get [kind]() {
|
|
19
|
+
return ModuleProtocol[kind]
|
|
20
|
+
}
|
|
21
|
+
|
|
2
22
|
constructor(methods = {}, context = null) {
|
|
3
|
-
for (const
|
|
4
|
-
'
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
'
|
|
8
|
-
'read',
|
|
9
|
-
'addon',
|
|
10
|
-
'asset'
|
|
23
|
+
for (const pair of [
|
|
24
|
+
['resolve', 'resolveSync'],
|
|
25
|
+
['exists', 'existsSync'],
|
|
26
|
+
['read', 'readSync'],
|
|
27
|
+
['list', 'listSync']
|
|
11
28
|
]) {
|
|
12
|
-
const
|
|
29
|
+
const overridden = pair.some((name) => typeof methods[name] === 'function')
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} else if (context) {
|
|
17
|
-
const method = context[name]
|
|
31
|
+
for (const name of pair) {
|
|
32
|
+
const method = methods[name]
|
|
18
33
|
|
|
19
34
|
if (typeof method === 'function') {
|
|
20
|
-
this[name] = method
|
|
35
|
+
this[name] = context ? method.bind(this, context) : method.bind(this)
|
|
36
|
+
} else if (context && !overridden) {
|
|
37
|
+
const method = context[name]
|
|
38
|
+
|
|
39
|
+
if (typeof method === 'function') {
|
|
40
|
+
this[name] = method
|
|
41
|
+
}
|
|
21
42
|
}
|
|
22
43
|
}
|
|
23
44
|
}
|
|
24
45
|
}
|
|
25
46
|
|
|
26
|
-
|
|
27
|
-
return specifier
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
postresolve(url) {
|
|
47
|
+
resolve(url) {
|
|
31
48
|
return url
|
|
32
49
|
}
|
|
33
50
|
|
|
34
|
-
|
|
51
|
+
resolveSync(url) {
|
|
52
|
+
const resolution = this.resolve(url)
|
|
53
|
+
|
|
54
|
+
if (isThenable(resolution)) {
|
|
55
|
+
throw errors.UNEXPECTED_PROMISE(
|
|
56
|
+
'Protocol resolve returned a promise during synchronous linking'
|
|
57
|
+
)
|
|
58
|
+
}
|
|
35
59
|
|
|
36
|
-
|
|
60
|
+
return resolution
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exists(url) {
|
|
37
64
|
return false
|
|
38
65
|
}
|
|
39
66
|
|
|
67
|
+
existsSync(url) {
|
|
68
|
+
const exists = this.exists(url)
|
|
69
|
+
|
|
70
|
+
if (isThenable(exists)) {
|
|
71
|
+
throw errors.UNEXPECTED_PROMISE(
|
|
72
|
+
'Protocol exists returned a promise during synchronous linking'
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return exists
|
|
77
|
+
}
|
|
78
|
+
|
|
40
79
|
read(url) {
|
|
41
80
|
return null
|
|
42
81
|
}
|
|
43
82
|
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
readSync(url) {
|
|
84
|
+
const source = this.read(url)
|
|
85
|
+
|
|
86
|
+
if (isThenable(source)) {
|
|
87
|
+
throw errors.UNEXPECTED_PROMISE('Protocol read returned a promise during synchronous linking')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return source
|
|
46
91
|
}
|
|
47
92
|
|
|
48
|
-
|
|
49
|
-
return
|
|
93
|
+
list(url) {
|
|
94
|
+
return []
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
listSync(url) {
|
|
98
|
+
const listing = this.list(url)
|
|
99
|
+
|
|
100
|
+
if (typeof listing[Symbol.iterator] !== 'function') {
|
|
101
|
+
throw errors.UNEXPECTED_PROMISE(
|
|
102
|
+
'Protocol list returned an asynchronous iterable during synchronous linking'
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return listing
|
|
50
107
|
}
|
|
51
108
|
|
|
52
109
|
extend(methods) {
|
|
53
110
|
return new ModuleProtocol(methods, this)
|
|
54
111
|
}
|
|
112
|
+
|
|
113
|
+
[Symbol.for('bare.inspect')]() {
|
|
114
|
+
return {
|
|
115
|
+
__proto__: { constructor: ModuleProtocol }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isThenable(value) {
|
|
121
|
+
return value !== null && typeof value === 'object' && typeof value.then === 'function'
|
|
55
122
|
}
|
package/lib/source.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = class ModuleSource {
|
|
2
|
+
constructor(dependency) {
|
|
3
|
+
this.url = dependency.url
|
|
4
|
+
this.type = dependency.type
|
|
5
|
+
this.naturalType = dependency.naturalType || 0
|
|
6
|
+
this.bytes = toBuffer(dependency.source)
|
|
7
|
+
this.imports = dependency.imports
|
|
8
|
+
this.lexer = dependency.lexer
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get exports() {
|
|
12
|
+
return this.lexer.exports.map((entry) => entry.name)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function toBuffer(source) {
|
|
17
|
+
return typeof source === 'string' ? Buffer.from(source) : source
|
|
18
|
+
}
|
package/lib/url.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const path = require('bare-path')
|
|
2
|
+
const { fileURLToPath } = require('bare-url')
|
|
3
|
+
const errors = require('./errors')
|
|
4
|
+
|
|
5
|
+
const isWindows = Bare.platform === 'win32'
|
|
6
|
+
|
|
7
|
+
exports.urlToPath = function urlToPath(url) {
|
|
8
|
+
if (url.protocol === 'file:') return fileURLToPath(url)
|
|
9
|
+
|
|
10
|
+
if (isOpaque(url)) return url.href
|
|
11
|
+
|
|
12
|
+
assertValidURLPath(url)
|
|
13
|
+
|
|
14
|
+
return decodeURIComponent(url.pathname)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.urlToDirname = function urlToDirname(url) {
|
|
18
|
+
if (url.protocol === 'file:') return path.dirname(fileURLToPath(url))
|
|
19
|
+
|
|
20
|
+
if (isOpaque(url)) return url.href
|
|
21
|
+
|
|
22
|
+
assertValidURLPath(url)
|
|
23
|
+
|
|
24
|
+
return decodeURIComponent(new URL('.', url).pathname).replace(/\/$/, '')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isOpaque(url) {
|
|
28
|
+
return url.pathname[0] !== '/'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function assertValidURLPath(url) {
|
|
32
|
+
const encoded = url.pathname
|
|
33
|
+
|
|
34
|
+
if (encoded.includes('%') === false) return
|
|
35
|
+
|
|
36
|
+
if (isWindows) {
|
|
37
|
+
if (/%2f|%5c/i.test(encoded)) {
|
|
38
|
+
throw errors.INVALID_URL_PATH('The URL path must not include encoded \\ or / characters')
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (/%2f/i.test(encoded)) {
|
|
42
|
+
throw errors.INVALID_URL_PATH('The URL path must not include encoded / characters')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A path is handed on to whoever asked for it, and a NUL ends it early for
|
|
47
|
+
// anything that reads it as a C string. Truncating turns one path into
|
|
48
|
+
// another, so turn it down rather than decode it.
|
|
49
|
+
if (/%00/i.test(encoded)) {
|
|
50
|
+
throw errors.INVALID_URL_PATH('The URL path must not include encoded NUL characters')
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "The module system that powers Bare",
|
|
5
5
|
"exports": {
|
|
6
|
+
"./package": "./package.json",
|
|
6
7
|
".": {
|
|
7
8
|
"types": "./index.d.ts",
|
|
8
9
|
"default": "./index.js"
|
|
9
10
|
},
|
|
10
|
-
"./
|
|
11
|
+
"./protocol": {
|
|
12
|
+
"types": "./lib/protocol.d.ts",
|
|
13
|
+
"default": "./lib/protocol.js"
|
|
14
|
+
},
|
|
15
|
+
"./loader": {
|
|
16
|
+
"types": "./lib/loader.d.ts",
|
|
17
|
+
"default": "./lib/loader.js"
|
|
18
|
+
}
|
|
11
19
|
},
|
|
12
20
|
"files": [
|
|
13
21
|
"index.js",
|
|
@@ -35,15 +43,17 @@
|
|
|
35
43
|
},
|
|
36
44
|
"homepage": "https://github.com/holepunchto/bare-module#readme",
|
|
37
45
|
"engines": {
|
|
38
|
-
"bare": ">=1.
|
|
46
|
+
"bare": ">=1.32.0"
|
|
39
47
|
},
|
|
40
48
|
"dependencies": {
|
|
41
|
-
"bare-bundle": "^1.
|
|
42
|
-
"bare-module-lexer": "^1.
|
|
43
|
-
"bare-module-resolve": "^1.
|
|
49
|
+
"bare-bundle": "^1.11.0",
|
|
50
|
+
"bare-module-lexer": "^1.6.1",
|
|
51
|
+
"bare-module-resolve": "^1.12.3",
|
|
52
|
+
"bare-module-traverse": "~2.5.5",
|
|
44
53
|
"bare-path": "^3.0.0",
|
|
45
54
|
"bare-type-stripper": "^0.1.2",
|
|
46
|
-
"bare-url": "^2.0.1"
|
|
55
|
+
"bare-url": "^2.0.1",
|
|
56
|
+
"promaphore": "^1.0.0"
|
|
47
57
|
},
|
|
48
58
|
"devDependencies": {
|
|
49
59
|
"bare-buffer": "^3.0.2",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/constants.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
declare const constants: {
|
|
2
|
-
states: {
|
|
3
|
-
EVALUATED: number
|
|
4
|
-
SYNTHESIZED: number
|
|
5
|
-
RUN: number
|
|
6
|
-
}
|
|
7
|
-
types: {
|
|
8
|
-
SCRIPT: number
|
|
9
|
-
MODULE: number
|
|
10
|
-
JSON: number
|
|
11
|
-
BUNDLE: number
|
|
12
|
-
ADDON: number
|
|
13
|
-
BINARY: number
|
|
14
|
-
TEXT: number
|
|
15
|
-
ASSET: number
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export = constants
|