bare-module 4.8.0 → 4.8.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.d.ts +127 -0
- package/index.js +8 -4
- package/lib/constants.d.ts +19 -0
- package/lib/protocol.d.ts +27 -0
- package/package.json +18 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import Buffer from 'bare-buffer'
|
|
2
|
+
import URL from 'bare-url'
|
|
3
|
+
import Bundle from 'bare-bundle'
|
|
4
|
+
import {
|
|
5
|
+
type Builtins,
|
|
6
|
+
type Conditions,
|
|
7
|
+
type ImportsMap,
|
|
8
|
+
type ResolutionsMap
|
|
9
|
+
} from 'bare-module-resolve'
|
|
10
|
+
import Protocol from './lib/protocol'
|
|
11
|
+
import constants from './lib/constants'
|
|
12
|
+
|
|
13
|
+
interface Cache {
|
|
14
|
+
[href: string]: Module
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Attributes {
|
|
18
|
+
type: Lowercase<keyof typeof constants.types>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Options {
|
|
22
|
+
attributes?: Attributes
|
|
23
|
+
builtins?: Builtins
|
|
24
|
+
cache?: Cache
|
|
25
|
+
conditions?: Conditions
|
|
26
|
+
defaultType?: number
|
|
27
|
+
imports?: ImportsMap
|
|
28
|
+
main?: Module
|
|
29
|
+
protocol?: Protocol
|
|
30
|
+
referrer?: Module
|
|
31
|
+
resolutions?: ResolutionsMap
|
|
32
|
+
type?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface LoadOptions extends Options {
|
|
36
|
+
isDynamicImport?: boolean
|
|
37
|
+
isImport?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ResolveOptions extends Options {
|
|
41
|
+
isImport?: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface Module {
|
|
45
|
+
readonly builtins: Builtins
|
|
46
|
+
readonly cache: Cache
|
|
47
|
+
readonly conditions: Conditions
|
|
48
|
+
readonly defaultType: number
|
|
49
|
+
readonly dirname: string
|
|
50
|
+
exports: unknown
|
|
51
|
+
readonly filename: string
|
|
52
|
+
readonly id: string
|
|
53
|
+
readonly imports: ImportsMap
|
|
54
|
+
readonly main: Module
|
|
55
|
+
readonly path: string
|
|
56
|
+
readonly protocol: Protocol
|
|
57
|
+
readonly resolutions: ResolutionsMap
|
|
58
|
+
readonly type: number
|
|
59
|
+
readonly url: URL
|
|
60
|
+
|
|
61
|
+
destroy(): void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class Module {
|
|
65
|
+
static readonly protocol: Protocol
|
|
66
|
+
static readonly cache: Cache
|
|
67
|
+
|
|
68
|
+
static load(url: URL, opts: LoadOptions): Module
|
|
69
|
+
static load(
|
|
70
|
+
url: URL,
|
|
71
|
+
source?: Buffer | string | Bundle | null,
|
|
72
|
+
opts?: LoadOptions
|
|
73
|
+
): Module
|
|
74
|
+
|
|
75
|
+
static resolve(specifier: string, parentURL: URL, opts?: ResolveOptions): URL
|
|
76
|
+
|
|
77
|
+
static asset(specifier: string, parentURL: URL, opts?: Options): URL
|
|
78
|
+
|
|
79
|
+
constructor(url: URL)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare namespace Module {
|
|
83
|
+
export {
|
|
84
|
+
type Attributes,
|
|
85
|
+
type Cache,
|
|
86
|
+
type Options,
|
|
87
|
+
type LoadOptions,
|
|
88
|
+
type ResolveOptions,
|
|
89
|
+
Protocol,
|
|
90
|
+
Bundle,
|
|
91
|
+
constants
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const builtinModules: Module[]
|
|
95
|
+
|
|
96
|
+
export function isBuiltin(): boolean
|
|
97
|
+
|
|
98
|
+
export interface CreateRequireOptions extends Options {
|
|
99
|
+
module?: Module
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface RequireOptions {
|
|
103
|
+
with?: Attributes
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface RequireAddon {
|
|
107
|
+
(specifier?: string, parentURL?: URL): string
|
|
108
|
+
host: string
|
|
109
|
+
resolve: (specifier: string, parentURL?: URL) => unknown
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface Require {
|
|
113
|
+
(parentURL: string | URL, opts?: RequireOptions): unknown
|
|
114
|
+
main: Module
|
|
115
|
+
cache: Cache
|
|
116
|
+
resolve: (specifier: string, parentURL?: URL) => string
|
|
117
|
+
addon: RequireAddon
|
|
118
|
+
asset: (specifier: string, parentURL?: URL) => string
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function createRequire(
|
|
122
|
+
parentURL: string | URL,
|
|
123
|
+
opts?: CreateRequireOptions
|
|
124
|
+
): Require
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export = Module
|
package/index.js
CHANGED
|
@@ -158,7 +158,11 @@ module.exports = exports = class Module {
|
|
|
158
158
|
const referrer = module
|
|
159
159
|
|
|
160
160
|
for (const { specifier, type } of result.imports) {
|
|
161
|
-
if (
|
|
161
|
+
if (
|
|
162
|
+
(type & lex.constants.REEXPORT) !== 0 &&
|
|
163
|
+
(type & lex.constants.ADDON) === 0 &&
|
|
164
|
+
(type & lex.constants.ASSET) === 0
|
|
165
|
+
) {
|
|
162
166
|
const resolved = Module.resolve(specifier, referrer._url, {
|
|
163
167
|
isImport: true,
|
|
164
168
|
referrer
|
|
@@ -390,6 +394,7 @@ module.exports = exports = class Module {
|
|
|
390
394
|
|
|
391
395
|
if (
|
|
392
396
|
!ArrayBuffer.isView(source) &&
|
|
397
|
+
!Bundle.isBundle(source) &&
|
|
393
398
|
typeof source !== 'string' &&
|
|
394
399
|
source !== null
|
|
395
400
|
) {
|
|
@@ -907,10 +912,9 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
|
907
912
|
|
|
908
913
|
referrer = module
|
|
909
914
|
|
|
910
|
-
const bundle =
|
|
911
|
-
module._url.href + '/'
|
|
912
|
-
))
|
|
915
|
+
const bundle = Bundle.from(source).mount(module._url.href + '/')
|
|
913
916
|
|
|
917
|
+
module._bundle = bundle
|
|
914
918
|
module._imports = bundle.imports
|
|
915
919
|
module._resolutions = bundle.resolutions
|
|
916
920
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const constants: {
|
|
2
|
+
states: {
|
|
3
|
+
EVALUATED: number
|
|
4
|
+
SYNTHESIZED: number
|
|
5
|
+
DESTROYED: 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
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import URL from 'bare-url'
|
|
2
|
+
import Buffer from 'bare-buffer'
|
|
3
|
+
import { type ImportsMap } from 'bare-module-resolve'
|
|
4
|
+
|
|
5
|
+
interface ModuleProtocol {
|
|
6
|
+
preresolve(specifier: string, parentURL: URL): string
|
|
7
|
+
|
|
8
|
+
postresolve(url: URL): URL
|
|
9
|
+
|
|
10
|
+
resolve(specifier: string, parentURL: URL, imports: ImportsMap): URL
|
|
11
|
+
|
|
12
|
+
exists(url: URL, type: number): boolean
|
|
13
|
+
|
|
14
|
+
read(url: URL): Buffer | string | null
|
|
15
|
+
|
|
16
|
+
addon(url: URL): URL
|
|
17
|
+
|
|
18
|
+
asset(url: URL): URL
|
|
19
|
+
|
|
20
|
+
extend(methods: Partial<ModuleProtocol>): ModuleProtocol
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare class ModuleProtocol {
|
|
24
|
+
constructor(methods?: Partial<ModuleProtocol>, context?: ModuleProtocol)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export = ModuleProtocol
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.2",
|
|
4
4
|
"description": "Module support for JavaScript",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"default": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"./package": "./package.json"
|
|
11
|
+
},
|
|
6
12
|
"files": [
|
|
7
13
|
"index.js",
|
|
14
|
+
"index.d.ts",
|
|
8
15
|
"binding.c",
|
|
9
16
|
"binding.js",
|
|
10
17
|
"CMakeLists.txt",
|
|
@@ -33,9 +40,18 @@
|
|
|
33
40
|
"bare-url": "^2.0.1"
|
|
34
41
|
},
|
|
35
42
|
"devDependencies": {
|
|
43
|
+
"bare-buffer": "^3.0.2",
|
|
36
44
|
"brittle": "^3.1.1",
|
|
37
45
|
"cmake-bare": "^1.1.6",
|
|
38
46
|
"prettier": "^3.3.3",
|
|
39
47
|
"prettier-config-standard": "^7.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"bare-buffer": "*"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"bare-buffer": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
40
56
|
}
|
|
41
57
|
}
|