bare-module 4.8.5 → 5.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/CMakeLists.txt +1 -1
- package/README.md +3 -18
- package/binding.c +47 -71
- package/index.d.ts +0 -3
- package/index.js +101 -86
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -3
- package/lib/errors.js +8 -0
- package/lib/protocol.js +0 -1
- package/package.json +2 -2
- 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/CMakeLists.txt
CHANGED
package/README.md
CHANGED
|
@@ -268,7 +268,6 @@ The flags for the current state of a module.
|
|
|
268
268
|
| :------------ | :------------------------------------------- |
|
|
269
269
|
| `EVALUATED` | The module has been evaluated. |
|
|
270
270
|
| `SYNTHESIZED` | The module named exports have been detected. |
|
|
271
|
-
| `DESTROYED` | The module has been unloaded. |
|
|
272
271
|
|
|
273
272
|
#### `Module.constants.types`
|
|
274
273
|
|
|
@@ -290,6 +289,9 @@ The default `ModuleProtocol` class for resolving, reading and loading modules. S
|
|
|
290
289
|
|
|
291
290
|
The global cache of loaded modules.
|
|
292
291
|
|
|
292
|
+
> [!WARNING]
|
|
293
|
+
> The cache may contain `Module` instances from several independent versions of `bare-module` as the cache is inherited through the module graph.
|
|
294
|
+
|
|
293
295
|
#### `const url = Module.resolve(specifier, parentURL[, options])`
|
|
294
296
|
|
|
295
297
|
Resolve the module `specifier` relative to the `parentURL`. `specifier` is a string and `parentURL` is a WHATWG `URL`.
|
|
@@ -454,10 +456,6 @@ An array of conditions used to resolve dependencies while loading the module. Se
|
|
|
454
456
|
|
|
455
457
|
The `ModuleProtocol` class used for resolving, reading and loading modules. See [Protocols](#protocols).
|
|
456
458
|
|
|
457
|
-
#### `module.destroy()`
|
|
458
|
-
|
|
459
|
-
Unloads the module.
|
|
460
|
-
|
|
461
459
|
### CommonJS modules
|
|
462
460
|
|
|
463
461
|
#### `require(specifier[, options])`
|
|
@@ -635,13 +633,6 @@ methods = {
|
|
|
635
633
|
// A function that returns the source code of a URL represented as a string or
|
|
636
634
|
// buffer.
|
|
637
635
|
read,
|
|
638
|
-
// function (url): object
|
|
639
|
-
// A function that returns the evaluated exports for the url. This is
|
|
640
|
-
// only called for Javascript modules (extensions `.js`, `.cjs` & `.mjs`)
|
|
641
|
-
// by default. If defined, this function will skip calling `read()` and
|
|
642
|
-
// evaluating the source method for the default implementations of the
|
|
643
|
-
// Javascript extensions.
|
|
644
|
-
load,
|
|
645
636
|
// function (url): URL
|
|
646
637
|
// A function used to post process URLs for addons before `postresolve()`.
|
|
647
638
|
addon,
|
|
@@ -651,12 +642,6 @@ methods = {
|
|
|
651
642
|
}
|
|
652
643
|
```
|
|
653
644
|
|
|
654
|
-
### Bundles
|
|
655
|
-
|
|
656
|
-
#### `const bundle = new Module.Bundle()`
|
|
657
|
-
|
|
658
|
-
See <https://github.com/holepunchto/bare-bundle>.
|
|
659
|
-
|
|
660
645
|
## License
|
|
661
646
|
|
|
662
647
|
Apache-2.0
|
package/binding.c
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include <uv.h>
|
|
10
10
|
|
|
11
11
|
typedef struct {
|
|
12
|
+
js_env_t *env;
|
|
12
13
|
js_ref_t *ctx;
|
|
13
14
|
js_ref_t *on_import;
|
|
14
15
|
js_ref_t *on_evaluate;
|
|
@@ -192,6 +193,27 @@ err:
|
|
|
192
193
|
assert(err == 0);
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
static void
|
|
197
|
+
bare_module__on_teardown(void *data) {
|
|
198
|
+
int err;
|
|
199
|
+
|
|
200
|
+
bare_module_context_t *context = data;
|
|
201
|
+
|
|
202
|
+
js_env_t *env = context->env;
|
|
203
|
+
|
|
204
|
+
err = js_delete_reference(env, context->on_import);
|
|
205
|
+
assert(err == 0);
|
|
206
|
+
|
|
207
|
+
err = js_delete_reference(env, context->on_evaluate);
|
|
208
|
+
assert(err == 0);
|
|
209
|
+
|
|
210
|
+
err = js_delete_reference(env, context->on_meta);
|
|
211
|
+
assert(err == 0);
|
|
212
|
+
|
|
213
|
+
err = js_delete_reference(env, context->ctx);
|
|
214
|
+
assert(err == 0);
|
|
215
|
+
}
|
|
216
|
+
|
|
195
217
|
static js_value_t *
|
|
196
218
|
bare_module_init(js_env_t *env, js_callback_info_t *info) {
|
|
197
219
|
int err;
|
|
@@ -208,7 +230,9 @@ bare_module_init(js_env_t *env, js_callback_info_t *info) {
|
|
|
208
230
|
|
|
209
231
|
js_value_t *result;
|
|
210
232
|
err = js_create_unsafe_arraybuffer(env, sizeof(bare_module_context_t), (void **) &context, &result);
|
|
211
|
-
|
|
233
|
+
assert(err == 0);
|
|
234
|
+
|
|
235
|
+
context->env = env;
|
|
212
236
|
|
|
213
237
|
err = js_create_reference(env, argv[0], 1, &context->ctx);
|
|
214
238
|
assert(err == 0);
|
|
@@ -222,41 +246,13 @@ bare_module_init(js_env_t *env, js_callback_info_t *info) {
|
|
|
222
246
|
err = js_create_reference(env, argv[3], 1, &context->on_meta);
|
|
223
247
|
assert(err == 0);
|
|
224
248
|
|
|
225
|
-
err =
|
|
226
|
-
assert(err == 0);
|
|
227
|
-
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
static js_value_t *
|
|
232
|
-
bare_module_destroy(js_env_t *env, js_callback_info_t *info) {
|
|
233
|
-
int err;
|
|
234
|
-
|
|
235
|
-
size_t argc = 1;
|
|
236
|
-
js_value_t *argv[1];
|
|
237
|
-
|
|
238
|
-
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
239
|
-
assert(err == 0);
|
|
240
|
-
|
|
241
|
-
assert(argc == 1);
|
|
242
|
-
|
|
243
|
-
bare_module_context_t *context;
|
|
244
|
-
err = js_get_arraybuffer_info(env, argv[0], (void **) &context, NULL);
|
|
245
|
-
if (err < 0) return NULL;
|
|
246
|
-
|
|
247
|
-
err = js_delete_reference(env, context->on_import);
|
|
248
|
-
assert(err == 0);
|
|
249
|
-
|
|
250
|
-
err = js_delete_reference(env, context->on_evaluate);
|
|
251
|
-
assert(err == 0);
|
|
252
|
-
|
|
253
|
-
err = js_delete_reference(env, context->on_meta);
|
|
249
|
+
err = js_add_teardown_callback(env, bare_module__on_teardown, context);
|
|
254
250
|
assert(err == 0);
|
|
255
251
|
|
|
256
|
-
err =
|
|
252
|
+
err = js_on_dynamic_import(env, bare_module__on_dynamic_import, (void *) context);
|
|
257
253
|
assert(err == 0);
|
|
258
254
|
|
|
259
|
-
return
|
|
255
|
+
return result;
|
|
260
256
|
}
|
|
261
257
|
|
|
262
258
|
static js_value_t *
|
|
@@ -282,12 +278,8 @@ bare_module_create_function(js_env_t *env, js_callback_info_t *info) {
|
|
|
282
278
|
|
|
283
279
|
js_value_t **args = malloc(sizeof(js_value_t *) * args_len);
|
|
284
280
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (err < 0 || fetched != args_len) {
|
|
289
|
-
goto err;
|
|
290
|
-
}
|
|
281
|
+
err = js_get_array_elements(env, argv[1], args, args_len, 0, NULL);
|
|
282
|
+
if (err < 0) goto err;
|
|
291
283
|
|
|
292
284
|
js_value_t *source = argv[2];
|
|
293
285
|
|
|
@@ -309,6 +301,16 @@ err:
|
|
|
309
301
|
return NULL;
|
|
310
302
|
}
|
|
311
303
|
|
|
304
|
+
static void
|
|
305
|
+
bare_module__on_finalize(js_env_t *env, void *data, void *finalize_hint) {
|
|
306
|
+
int err;
|
|
307
|
+
|
|
308
|
+
js_module_t *module = data;
|
|
309
|
+
|
|
310
|
+
err = js_delete_module(env, module);
|
|
311
|
+
assert(err == 0);
|
|
312
|
+
}
|
|
313
|
+
|
|
312
314
|
static js_value_t *
|
|
313
315
|
bare_module_create_module(js_env_t *env, js_callback_info_t *info) {
|
|
314
316
|
int err;
|
|
@@ -341,7 +343,7 @@ bare_module_create_module(js_env_t *env, js_callback_info_t *info) {
|
|
|
341
343
|
if (err < 0) return NULL;
|
|
342
344
|
|
|
343
345
|
js_value_t *result;
|
|
344
|
-
err = js_create_external(env, (void *) module,
|
|
346
|
+
err = js_create_external(env, (void *) module, bare_module__on_finalize, NULL, &result);
|
|
345
347
|
if (err < 0) return NULL;
|
|
346
348
|
|
|
347
349
|
return result;
|
|
@@ -370,12 +372,8 @@ bare_module_create_synthetic_module(js_env_t *env, js_callback_info_t *info) {
|
|
|
370
372
|
|
|
371
373
|
js_value_t **export_names = malloc(sizeof(js_value_t *) * names_len);
|
|
372
374
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (err < 0 || fetched != names_len) {
|
|
377
|
-
goto err;
|
|
378
|
-
}
|
|
375
|
+
err = js_get_array_elements(env, argv[1], export_names, names_len, 0, NULL);
|
|
376
|
+
if (err < 0) goto err;
|
|
379
377
|
|
|
380
378
|
bare_module_context_t *context;
|
|
381
379
|
err = js_get_arraybuffer_info(env, argv[2], (void **) &context, NULL);
|
|
@@ -399,28 +397,6 @@ err:
|
|
|
399
397
|
return NULL;
|
|
400
398
|
}
|
|
401
399
|
|
|
402
|
-
static js_value_t *
|
|
403
|
-
bare_module_delete_module(js_env_t *env, js_callback_info_t *info) {
|
|
404
|
-
int err;
|
|
405
|
-
|
|
406
|
-
size_t argc = 1;
|
|
407
|
-
js_value_t *argv[1];
|
|
408
|
-
|
|
409
|
-
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
410
|
-
assert(err == 0);
|
|
411
|
-
|
|
412
|
-
assert(argc == 1);
|
|
413
|
-
|
|
414
|
-
js_module_t *module;
|
|
415
|
-
err = js_get_value_external(env, argv[0], (void **) &module);
|
|
416
|
-
if (err < 0) return NULL;
|
|
417
|
-
|
|
418
|
-
err = js_delete_module(env, module);
|
|
419
|
-
assert(err == 0);
|
|
420
|
-
|
|
421
|
-
return NULL;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
400
|
static js_value_t *
|
|
425
401
|
bare_module_set_export(js_env_t *env, js_callback_info_t *info) {
|
|
426
402
|
int err;
|
|
@@ -603,7 +579,8 @@ bare_module_realpath(js_env_t *env, js_callback_info_t *info) {
|
|
|
603
579
|
return result;
|
|
604
580
|
|
|
605
581
|
err:
|
|
606
|
-
js_throw_error(env, uv_err_name(err), uv_strerror(err));
|
|
582
|
+
err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
|
|
583
|
+
assert(err == 0);
|
|
607
584
|
|
|
608
585
|
return NULL;
|
|
609
586
|
}
|
|
@@ -681,7 +658,8 @@ bare_module_read(js_env_t *env, js_callback_info_t *info) {
|
|
|
681
658
|
return result;
|
|
682
659
|
|
|
683
660
|
err:
|
|
684
|
-
js_throw_error(env, uv_err_name(err), uv_strerror(err));
|
|
661
|
+
err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
|
|
662
|
+
assert(err == 0);
|
|
685
663
|
|
|
686
664
|
return NULL;
|
|
687
665
|
}
|
|
@@ -700,12 +678,10 @@ bare_module_exports(js_env_t *env, js_value_t *exports) {
|
|
|
700
678
|
}
|
|
701
679
|
|
|
702
680
|
V("init", bare_module_init)
|
|
703
|
-
V("destroy", bare_module_destroy)
|
|
704
681
|
|
|
705
682
|
V("createFunction", bare_module_create_function)
|
|
706
683
|
V("createModule", bare_module_create_module)
|
|
707
684
|
V("createSyntheticModule", bare_module_create_synthetic_module)
|
|
708
|
-
V("deleteModule", bare_module_delete_module)
|
|
709
685
|
V("setExport", bare_module_set_export)
|
|
710
686
|
V("runModule", bare_module_run_module)
|
|
711
687
|
V("getNamespace", bare_module_get_namespace)
|
package/index.d.ts
CHANGED
|
@@ -57,8 +57,6 @@ interface Module {
|
|
|
57
57
|
readonly resolutions: ResolutionsMap
|
|
58
58
|
readonly type: number
|
|
59
59
|
readonly url: URL
|
|
60
|
-
|
|
61
|
-
destroy(): void
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
declare class Module {
|
|
@@ -87,7 +85,6 @@ declare namespace Module {
|
|
|
87
85
|
type LoadOptions,
|
|
88
86
|
type ResolveOptions,
|
|
89
87
|
Protocol,
|
|
90
|
-
Bundle,
|
|
91
88
|
constants
|
|
92
89
|
}
|
|
93
90
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* global Bare */
|
|
2
1
|
const path = require('bare-path')
|
|
3
2
|
const resolve = require('bare-module-resolve')
|
|
4
3
|
const lex = require('bare-module-lexer')
|
|
@@ -9,17 +8,22 @@ const constants = require('./lib/constants')
|
|
|
9
8
|
const errors = require('./lib/errors')
|
|
10
9
|
const binding = require('./binding')
|
|
11
10
|
|
|
11
|
+
const kind = Symbol.for('bare.module.kind')
|
|
12
|
+
|
|
12
13
|
const isWindows = Bare.platform === 'win32'
|
|
13
14
|
|
|
14
15
|
const { startsWithWindowsDriveLetter } = resolve
|
|
15
16
|
|
|
16
17
|
module.exports = exports = class Module {
|
|
18
|
+
static get [kind]() {
|
|
19
|
+
return 0 // Compatibility version
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
constructor(url) {
|
|
18
23
|
this._url = url
|
|
19
24
|
this._state = 0
|
|
20
25
|
this._type = 0
|
|
21
|
-
this._defaultType =
|
|
22
|
-
this._cache = null
|
|
26
|
+
this._defaultType = 0
|
|
23
27
|
this._main = null
|
|
24
28
|
this._exports = null
|
|
25
29
|
this._imports = null
|
|
@@ -27,28 +31,23 @@ module.exports = exports = class Module {
|
|
|
27
31
|
this._builtins = null
|
|
28
32
|
this._conditions = null
|
|
29
33
|
this._protocol = null
|
|
30
|
-
this.
|
|
34
|
+
this._cache = null
|
|
35
|
+
this._source = null
|
|
31
36
|
this._function = null
|
|
32
37
|
this._names = null
|
|
33
38
|
this._handle = null
|
|
34
39
|
|
|
35
40
|
Object.preventExtensions(this)
|
|
41
|
+
}
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
get [kind]() {
|
|
44
|
+
return Module[kind]
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
get url() {
|
|
41
48
|
return this._url
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
get filename() {
|
|
45
|
-
return urlToPath(this._url)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get dirname() {
|
|
49
|
-
return urlToDirname(this._url)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
51
|
get type() {
|
|
53
52
|
return this._type
|
|
54
53
|
}
|
|
@@ -57,10 +56,6 @@ module.exports = exports = class Module {
|
|
|
57
56
|
return this._defaultType
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
get cache() {
|
|
61
|
-
return this._cache
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
get main() {
|
|
65
60
|
return this._main
|
|
66
61
|
}
|
|
@@ -93,6 +88,20 @@ module.exports = exports = class Module {
|
|
|
93
88
|
return this._protocol
|
|
94
89
|
}
|
|
95
90
|
|
|
91
|
+
get cache() {
|
|
92
|
+
return this._cache
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// For Node.js compatibility
|
|
96
|
+
get filename() {
|
|
97
|
+
return urlToPath(this._url)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// For Node.js compatibility
|
|
101
|
+
get dirname() {
|
|
102
|
+
return urlToDirname(this._url)
|
|
103
|
+
}
|
|
104
|
+
|
|
96
105
|
// For Node.js compatibility
|
|
97
106
|
get id() {
|
|
98
107
|
return this.filename
|
|
@@ -103,17 +112,6 @@ module.exports = exports = class Module {
|
|
|
103
112
|
return this.dirname
|
|
104
113
|
}
|
|
105
114
|
|
|
106
|
-
destroy() {
|
|
107
|
-
this._state |= constants.states.DESTROYED
|
|
108
|
-
|
|
109
|
-
if (this._handle) {
|
|
110
|
-
binding.deleteModule(this._handle)
|
|
111
|
-
this._handle = null
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
Module._modules.delete(this)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
115
|
_transform(isImport, isDynamicImport) {
|
|
118
116
|
if (isDynamicImport) {
|
|
119
117
|
this._run()
|
|
@@ -146,7 +144,7 @@ module.exports = exports = class Module {
|
|
|
146
144
|
|
|
147
145
|
switch (module._type) {
|
|
148
146
|
case constants.types.SCRIPT: {
|
|
149
|
-
const result = lex(module.
|
|
147
|
+
const result = lex(module._source)
|
|
150
148
|
|
|
151
149
|
for (const { name } of result.exports) names.add(name)
|
|
152
150
|
|
|
@@ -206,7 +204,7 @@ module.exports = exports = class Module {
|
|
|
206
204
|
this._state |= constants.states.EVALUATED
|
|
207
205
|
|
|
208
206
|
if (this._type === constants.types.SCRIPT) {
|
|
209
|
-
const require = createRequire(this._url, { module: this })
|
|
207
|
+
const require = exports.createRequire(this._url, { module: this })
|
|
210
208
|
|
|
211
209
|
this._exports = {}
|
|
212
210
|
|
|
@@ -255,7 +253,6 @@ module.exports = exports = class Module {
|
|
|
255
253
|
static _extensions = Object.create(null)
|
|
256
254
|
static _protocol = null
|
|
257
255
|
static _cache = module.cache || Object.create(null)
|
|
258
|
-
static _modules = new Set()
|
|
259
256
|
static _conditions = ['bare', 'node', Bare.platform, Bare.arch]
|
|
260
257
|
|
|
261
258
|
static _handle = binding.init(
|
|
@@ -406,7 +403,6 @@ module.exports = exports = class Module {
|
|
|
406
403
|
const {
|
|
407
404
|
isImport = false,
|
|
408
405
|
isDynamicImport = false,
|
|
409
|
-
|
|
410
406
|
referrer = null,
|
|
411
407
|
attributes,
|
|
412
408
|
type = typeForAttributes(attributes),
|
|
@@ -450,6 +446,27 @@ module.exports = exports = class Module {
|
|
|
450
446
|
module._builtins = builtins
|
|
451
447
|
module._conditions = conditions
|
|
452
448
|
|
|
449
|
+
if (
|
|
450
|
+
typeof attributes === 'object' &&
|
|
451
|
+
attributes !== null &&
|
|
452
|
+
typeof attributes.imports === 'string'
|
|
453
|
+
) {
|
|
454
|
+
const resolved = self.resolve(attributes.imports, url, {
|
|
455
|
+
referrer: module
|
|
456
|
+
})
|
|
457
|
+
|
|
458
|
+
const imports = self.load(resolved, {
|
|
459
|
+
referrer: module,
|
|
460
|
+
type: constants.types.JSON
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
module._imports = mixinImports(
|
|
464
|
+
module._imports,
|
|
465
|
+
imports._exports,
|
|
466
|
+
resolved
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
453
470
|
let extension =
|
|
454
471
|
canonicalExtensionForType(type) || path.extname(url.pathname)
|
|
455
472
|
|
|
@@ -484,7 +501,6 @@ module.exports = exports = class Module {
|
|
|
484
501
|
|
|
485
502
|
const {
|
|
486
503
|
isImport = false,
|
|
487
|
-
|
|
488
504
|
referrer = null,
|
|
489
505
|
attributes,
|
|
490
506
|
type = typeForAttributes(attributes),
|
|
@@ -692,8 +708,21 @@ function typeForAttributes(attributes) {
|
|
|
692
708
|
}
|
|
693
709
|
}
|
|
694
710
|
|
|
711
|
+
function mixinImports(target, imports, url) {
|
|
712
|
+
if (typeof imports === 'object' && imports !== null && 'imports' in imports) {
|
|
713
|
+
imports = imports.imports
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (typeof imports !== 'object' || imports === null) {
|
|
717
|
+
throw errors.INVALID_IMPORTS_MAP(
|
|
718
|
+
`Imports map at '${url.href}' is not valid`
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return { ...target, ...imports }
|
|
723
|
+
}
|
|
724
|
+
|
|
695
725
|
exports.Protocol = Protocol
|
|
696
|
-
exports.Bundle = Bundle
|
|
697
726
|
|
|
698
727
|
exports.constants = constants
|
|
699
728
|
|
|
@@ -705,15 +734,11 @@ exports.isBuiltin = function isBuiltin() {
|
|
|
705
734
|
return false
|
|
706
735
|
}
|
|
707
736
|
|
|
708
|
-
|
|
709
|
-
parentURL,
|
|
710
|
-
opts = {}
|
|
711
|
-
) {
|
|
737
|
+
exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
712
738
|
const self = Module
|
|
713
739
|
|
|
714
740
|
let {
|
|
715
741
|
module = null,
|
|
716
|
-
|
|
717
742
|
referrer = null,
|
|
718
743
|
type = constants.types.SCRIPT,
|
|
719
744
|
defaultType = referrer ? referrer._defaultType : constants.types.SCRIPT,
|
|
@@ -796,7 +821,7 @@ const createRequire = (exports.createRequire = function createRequire(
|
|
|
796
821
|
}
|
|
797
822
|
|
|
798
823
|
return require
|
|
799
|
-
}
|
|
824
|
+
}
|
|
800
825
|
|
|
801
826
|
if (Bare.simulator) Module._conditions.push('simulator')
|
|
802
827
|
|
|
@@ -838,20 +863,18 @@ Module._extensions['.cjs'] = function (module, source, referrer) {
|
|
|
838
863
|
|
|
839
864
|
module._type = constants.types.SCRIPT
|
|
840
865
|
|
|
841
|
-
if (protocol.
|
|
842
|
-
module._exports = protocol.load(module._url)
|
|
843
|
-
} else {
|
|
844
|
-
if (source === null) source = protocol.read(module._url)
|
|
866
|
+
if (source === null) source = protocol.read(module._url)
|
|
845
867
|
|
|
846
|
-
|
|
868
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
847
869
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
)
|
|
854
|
-
|
|
870
|
+
module._source = source
|
|
871
|
+
|
|
872
|
+
module._function = binding.createFunction(
|
|
873
|
+
module._url.href,
|
|
874
|
+
['require', 'module', 'exports', '__filename', '__dirname'],
|
|
875
|
+
source.toString(),
|
|
876
|
+
0
|
|
877
|
+
)
|
|
855
878
|
}
|
|
856
879
|
|
|
857
880
|
Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
@@ -861,20 +884,18 @@ Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
|
861
884
|
|
|
862
885
|
module._type = constants.types.MODULE
|
|
863
886
|
|
|
864
|
-
if (protocol.
|
|
865
|
-
module._exports = protocol.load(module._url)
|
|
866
|
-
} else {
|
|
867
|
-
if (source === null) source = protocol.read(module._url)
|
|
887
|
+
if (source === null) source = protocol.read(module._url)
|
|
868
888
|
|
|
869
|
-
|
|
889
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
870
890
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
891
|
+
module._source = source
|
|
892
|
+
|
|
893
|
+
module._handle = binding.createModule(
|
|
894
|
+
module._url.href,
|
|
895
|
+
source.toString(),
|
|
896
|
+
0,
|
|
897
|
+
self._handle
|
|
898
|
+
)
|
|
878
899
|
}
|
|
879
900
|
|
|
880
901
|
Module._extensions['.json'] = function (module, source, referrer) {
|
|
@@ -882,15 +903,12 @@ Module._extensions['.json'] = function (module, source, referrer) {
|
|
|
882
903
|
|
|
883
904
|
module._type = constants.types.JSON
|
|
884
905
|
|
|
885
|
-
if (protocol.
|
|
886
|
-
module._exports = protocol.load(module._url)
|
|
887
|
-
} else {
|
|
888
|
-
if (source === null) source = protocol.read(module._url)
|
|
906
|
+
if (source === null) source = protocol.read(module._url)
|
|
889
907
|
|
|
890
|
-
|
|
908
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
891
909
|
|
|
892
|
-
|
|
893
|
-
|
|
910
|
+
module._source = source
|
|
911
|
+
module._exports = JSON.parse(source.toString())
|
|
894
912
|
}
|
|
895
913
|
|
|
896
914
|
Module._extensions['.bare'] = function (module, source, referrer) {
|
|
@@ -924,7 +942,7 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
|
924
942
|
|
|
925
943
|
const bundle = Bundle.from(source).mount(module._url.href + '/')
|
|
926
944
|
|
|
927
|
-
module.
|
|
945
|
+
module._source = source
|
|
928
946
|
module._imports = bundle.imports
|
|
929
947
|
module._resolutions = bundle.resolutions
|
|
930
948
|
|
|
@@ -960,7 +978,7 @@ Module._extensions['.bin'] = function (module, source, referrer) {
|
|
|
960
978
|
|
|
961
979
|
if (typeof source === 'string') source = Buffer.from(source)
|
|
962
980
|
|
|
963
|
-
module._exports = source
|
|
981
|
+
module._source = module._exports = source
|
|
964
982
|
}
|
|
965
983
|
|
|
966
984
|
Module._extensions['.txt'] = function (module, source, referrer) {
|
|
@@ -970,16 +988,19 @@ Module._extensions['.txt'] = function (module, source, referrer) {
|
|
|
970
988
|
|
|
971
989
|
if (source === null) source = protocol.read(module._url)
|
|
972
990
|
|
|
973
|
-
if (typeof source
|
|
991
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
974
992
|
|
|
975
|
-
module.
|
|
993
|
+
module._source = source
|
|
994
|
+
module._exports = source.toString()
|
|
976
995
|
}
|
|
977
996
|
|
|
978
997
|
Module._protocol = new Protocol({
|
|
979
998
|
postresolve(url) {
|
|
980
999
|
switch (url.protocol) {
|
|
981
1000
|
case 'file:':
|
|
982
|
-
return pathToFileURL(
|
|
1001
|
+
return pathToFileURL(
|
|
1002
|
+
binding.realpath(path.toNamespacedPath(fileURLToPath(url)))
|
|
1003
|
+
)
|
|
983
1004
|
default:
|
|
984
1005
|
return url
|
|
985
1006
|
}
|
|
@@ -989,7 +1010,7 @@ Module._protocol = new Protocol({
|
|
|
989
1010
|
switch (url.protocol) {
|
|
990
1011
|
case 'file:':
|
|
991
1012
|
return binding.exists(
|
|
992
|
-
fileURLToPath(url),
|
|
1013
|
+
path.toNamespacedPath(fileURLToPath(url)),
|
|
993
1014
|
type === constants.types.ASSET
|
|
994
1015
|
? binding.FILE | binding.DIR
|
|
995
1016
|
: binding.FILE
|
|
@@ -1002,21 +1023,15 @@ Module._protocol = new Protocol({
|
|
|
1002
1023
|
read(url) {
|
|
1003
1024
|
switch (url.protocol) {
|
|
1004
1025
|
case 'file:':
|
|
1005
|
-
return Buffer.from(
|
|
1026
|
+
return Buffer.from(
|
|
1027
|
+
binding.read(path.toNamespacedPath(fileURLToPath(url)))
|
|
1028
|
+
)
|
|
1006
1029
|
default:
|
|
1007
1030
|
throw errors.UNKNOWN_PROTOCOL(`Cannot load module '${url.href}'`)
|
|
1008
1031
|
}
|
|
1009
1032
|
}
|
|
1010
1033
|
})
|
|
1011
1034
|
|
|
1012
|
-
Bare.prependListener('teardown', () => {
|
|
1013
|
-
for (const module of Module._modules) {
|
|
1014
|
-
module.destroy()
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
binding.destroy(Module._handle)
|
|
1018
|
-
})
|
|
1019
|
-
|
|
1020
1035
|
function toURL(value, base) {
|
|
1021
1036
|
if (isURL(value)) return value
|
|
1022
1037
|
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -52,6 +52,14 @@ module.exports = class ModuleError extends Error {
|
|
|
52
52
|
)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
static INVALID_IMPORTS_MAP(msg) {
|
|
56
|
+
return new ModuleError(
|
|
57
|
+
msg,
|
|
58
|
+
'INVALID_IMPORTS_MAP',
|
|
59
|
+
ModuleError.INVALID_IMPORTS_MAP
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
static TYPE_INCOMPATIBLE(msg) {
|
|
56
64
|
return new ModuleError(
|
|
57
65
|
msg,
|
package/lib/protocol.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Module support for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/holepunchto/bare-module#readme",
|
|
35
35
|
"engines": {
|
|
36
|
-
"bare": ">=1.
|
|
36
|
+
"bare": ">=1.20.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"bare-bundle": "^1.3.0",
|
|
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
|