bare-module 4.8.6 → 5.0.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.
- package/CMakeLists.txt +1 -1
- package/README.md +3 -18
- package/binding.c +48 -72
- package/index.d.ts +0 -3
- package/index.js +94 -82
- 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);
|
|
249
|
+
err = js_add_teardown_callback(env, bare_module__on_teardown, context);
|
|
239
250
|
assert(err == 0);
|
|
240
251
|
|
|
241
|
-
|
|
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);
|
|
254
|
-
assert(err == 0);
|
|
255
|
-
|
|
256
|
-
err = js_delete_reference(env, context->ctx);
|
|
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);
|
|
@@ -386,7 +384,7 @@ bare_module_create_synthetic_module(js_env_t *env, js_callback_info_t *info) {
|
|
|
386
384
|
if (err < 0) goto err;
|
|
387
385
|
|
|
388
386
|
js_value_t *result;
|
|
389
|
-
err = js_create_external(env, (void *) module,
|
|
387
|
+
err = js_create_external(env, (void *) module, bare_module__on_finalize, NULL, &result);
|
|
390
388
|
if (err < 0) goto err;
|
|
391
389
|
|
|
392
390
|
free(export_names);
|
|
@@ -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
|
@@ -8,17 +8,22 @@ const constants = require('./lib/constants')
|
|
|
8
8
|
const errors = require('./lib/errors')
|
|
9
9
|
const binding = require('./binding')
|
|
10
10
|
|
|
11
|
+
const kind = Symbol.for('bare.module.kind')
|
|
12
|
+
|
|
11
13
|
const isWindows = Bare.platform === 'win32'
|
|
12
14
|
|
|
13
15
|
const { startsWithWindowsDriveLetter } = resolve
|
|
14
16
|
|
|
15
17
|
module.exports = exports = class Module {
|
|
18
|
+
static get [kind]() {
|
|
19
|
+
return 0 // Compatibility version
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
constructor(url) {
|
|
17
23
|
this._url = url
|
|
18
24
|
this._state = 0
|
|
19
25
|
this._type = 0
|
|
20
|
-
this._defaultType =
|
|
21
|
-
this._cache = null
|
|
26
|
+
this._defaultType = 0
|
|
22
27
|
this._main = null
|
|
23
28
|
this._exports = null
|
|
24
29
|
this._imports = null
|
|
@@ -26,28 +31,23 @@ module.exports = exports = class Module {
|
|
|
26
31
|
this._builtins = null
|
|
27
32
|
this._conditions = null
|
|
28
33
|
this._protocol = null
|
|
29
|
-
this.
|
|
34
|
+
this._cache = null
|
|
35
|
+
this._source = null
|
|
30
36
|
this._function = null
|
|
31
37
|
this._names = null
|
|
32
38
|
this._handle = null
|
|
33
39
|
|
|
34
40
|
Object.preventExtensions(this)
|
|
41
|
+
}
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
get [kind]() {
|
|
44
|
+
return Module[kind]
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
get url() {
|
|
40
48
|
return this._url
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
get filename() {
|
|
44
|
-
return urlToPath(this._url)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get dirname() {
|
|
48
|
-
return urlToDirname(this._url)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
51
|
get type() {
|
|
52
52
|
return this._type
|
|
53
53
|
}
|
|
@@ -56,10 +56,6 @@ module.exports = exports = class Module {
|
|
|
56
56
|
return this._defaultType
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
get cache() {
|
|
60
|
-
return this._cache
|
|
61
|
-
}
|
|
62
|
-
|
|
63
59
|
get main() {
|
|
64
60
|
return this._main
|
|
65
61
|
}
|
|
@@ -92,6 +88,20 @@ module.exports = exports = class Module {
|
|
|
92
88
|
return this._protocol
|
|
93
89
|
}
|
|
94
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
|
+
|
|
95
105
|
// For Node.js compatibility
|
|
96
106
|
get id() {
|
|
97
107
|
return this.filename
|
|
@@ -102,17 +112,6 @@ module.exports = exports = class Module {
|
|
|
102
112
|
return this.dirname
|
|
103
113
|
}
|
|
104
114
|
|
|
105
|
-
destroy() {
|
|
106
|
-
this._state |= constants.states.DESTROYED
|
|
107
|
-
|
|
108
|
-
if (this._handle) {
|
|
109
|
-
binding.deleteModule(this._handle)
|
|
110
|
-
this._handle = null
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Module._modules.delete(this)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
115
|
_transform(isImport, isDynamicImport) {
|
|
117
116
|
if (isDynamicImport) {
|
|
118
117
|
this._run()
|
|
@@ -145,7 +144,7 @@ module.exports = exports = class Module {
|
|
|
145
144
|
|
|
146
145
|
switch (module._type) {
|
|
147
146
|
case constants.types.SCRIPT: {
|
|
148
|
-
const result = lex(module.
|
|
147
|
+
const result = lex(module._source)
|
|
149
148
|
|
|
150
149
|
for (const { name } of result.exports) names.add(name)
|
|
151
150
|
|
|
@@ -205,7 +204,7 @@ module.exports = exports = class Module {
|
|
|
205
204
|
this._state |= constants.states.EVALUATED
|
|
206
205
|
|
|
207
206
|
if (this._type === constants.types.SCRIPT) {
|
|
208
|
-
const require = createRequire(this._url, { module: this })
|
|
207
|
+
const require = exports.createRequire(this._url, { module: this })
|
|
209
208
|
|
|
210
209
|
this._exports = {}
|
|
211
210
|
|
|
@@ -254,7 +253,6 @@ module.exports = exports = class Module {
|
|
|
254
253
|
static _extensions = Object.create(null)
|
|
255
254
|
static _protocol = null
|
|
256
255
|
static _cache = module.cache || Object.create(null)
|
|
257
|
-
static _modules = new Set()
|
|
258
256
|
static _conditions = ['bare', 'node', Bare.platform, Bare.arch]
|
|
259
257
|
|
|
260
258
|
static _handle = binding.init(
|
|
@@ -405,7 +403,6 @@ module.exports = exports = class Module {
|
|
|
405
403
|
const {
|
|
406
404
|
isImport = false,
|
|
407
405
|
isDynamicImport = false,
|
|
408
|
-
|
|
409
406
|
referrer = null,
|
|
410
407
|
attributes,
|
|
411
408
|
type = typeForAttributes(attributes),
|
|
@@ -449,6 +446,27 @@ module.exports = exports = class Module {
|
|
|
449
446
|
module._builtins = builtins
|
|
450
447
|
module._conditions = conditions
|
|
451
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
|
+
|
|
452
470
|
let extension =
|
|
453
471
|
canonicalExtensionForType(type) || path.extname(url.pathname)
|
|
454
472
|
|
|
@@ -483,7 +501,6 @@ module.exports = exports = class Module {
|
|
|
483
501
|
|
|
484
502
|
const {
|
|
485
503
|
isImport = false,
|
|
486
|
-
|
|
487
504
|
referrer = null,
|
|
488
505
|
attributes,
|
|
489
506
|
type = typeForAttributes(attributes),
|
|
@@ -691,8 +708,21 @@ function typeForAttributes(attributes) {
|
|
|
691
708
|
}
|
|
692
709
|
}
|
|
693
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
|
+
|
|
694
725
|
exports.Protocol = Protocol
|
|
695
|
-
exports.Bundle = Bundle
|
|
696
726
|
|
|
697
727
|
exports.constants = constants
|
|
698
728
|
|
|
@@ -704,15 +734,11 @@ exports.isBuiltin = function isBuiltin() {
|
|
|
704
734
|
return false
|
|
705
735
|
}
|
|
706
736
|
|
|
707
|
-
|
|
708
|
-
parentURL,
|
|
709
|
-
opts = {}
|
|
710
|
-
) {
|
|
737
|
+
exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
711
738
|
const self = Module
|
|
712
739
|
|
|
713
740
|
let {
|
|
714
741
|
module = null,
|
|
715
|
-
|
|
716
742
|
referrer = null,
|
|
717
743
|
type = constants.types.SCRIPT,
|
|
718
744
|
defaultType = referrer ? referrer._defaultType : constants.types.SCRIPT,
|
|
@@ -795,7 +821,7 @@ const createRequire = (exports.createRequire = function createRequire(
|
|
|
795
821
|
}
|
|
796
822
|
|
|
797
823
|
return require
|
|
798
|
-
}
|
|
824
|
+
}
|
|
799
825
|
|
|
800
826
|
if (Bare.simulator) Module._conditions.push('simulator')
|
|
801
827
|
|
|
@@ -837,20 +863,18 @@ Module._extensions['.cjs'] = function (module, source, referrer) {
|
|
|
837
863
|
|
|
838
864
|
module._type = constants.types.SCRIPT
|
|
839
865
|
|
|
840
|
-
if (protocol.
|
|
841
|
-
module._exports = protocol.load(module._url)
|
|
842
|
-
} else {
|
|
843
|
-
if (source === null) source = protocol.read(module._url)
|
|
866
|
+
if (source === null) source = protocol.read(module._url)
|
|
844
867
|
|
|
845
|
-
|
|
868
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
846
869
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
)
|
|
853
|
-
|
|
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
|
+
)
|
|
854
878
|
}
|
|
855
879
|
|
|
856
880
|
Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
@@ -860,20 +884,18 @@ Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
|
860
884
|
|
|
861
885
|
module._type = constants.types.MODULE
|
|
862
886
|
|
|
863
|
-
if (protocol.
|
|
864
|
-
module._exports = protocol.load(module._url)
|
|
865
|
-
} else {
|
|
866
|
-
if (source === null) source = protocol.read(module._url)
|
|
887
|
+
if (source === null) source = protocol.read(module._url)
|
|
867
888
|
|
|
868
|
-
|
|
889
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
869
890
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
891
|
+
module._source = source
|
|
892
|
+
|
|
893
|
+
module._handle = binding.createModule(
|
|
894
|
+
module._url.href,
|
|
895
|
+
source.toString(),
|
|
896
|
+
0,
|
|
897
|
+
self._handle
|
|
898
|
+
)
|
|
877
899
|
}
|
|
878
900
|
|
|
879
901
|
Module._extensions['.json'] = function (module, source, referrer) {
|
|
@@ -881,15 +903,12 @@ Module._extensions['.json'] = function (module, source, referrer) {
|
|
|
881
903
|
|
|
882
904
|
module._type = constants.types.JSON
|
|
883
905
|
|
|
884
|
-
if (protocol.
|
|
885
|
-
module._exports = protocol.load(module._url)
|
|
886
|
-
} else {
|
|
887
|
-
if (source === null) source = protocol.read(module._url)
|
|
906
|
+
if (source === null) source = protocol.read(module._url)
|
|
888
907
|
|
|
889
|
-
|
|
908
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
890
909
|
|
|
891
|
-
|
|
892
|
-
|
|
910
|
+
module._source = source
|
|
911
|
+
module._exports = JSON.parse(source.toString())
|
|
893
912
|
}
|
|
894
913
|
|
|
895
914
|
Module._extensions['.bare'] = function (module, source, referrer) {
|
|
@@ -923,7 +942,7 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
|
923
942
|
|
|
924
943
|
const bundle = Bundle.from(source).mount(module._url.href + '/')
|
|
925
944
|
|
|
926
|
-
module.
|
|
945
|
+
module._source = source
|
|
927
946
|
module._imports = bundle.imports
|
|
928
947
|
module._resolutions = bundle.resolutions
|
|
929
948
|
|
|
@@ -959,7 +978,7 @@ Module._extensions['.bin'] = function (module, source, referrer) {
|
|
|
959
978
|
|
|
960
979
|
if (typeof source === 'string') source = Buffer.from(source)
|
|
961
980
|
|
|
962
|
-
module._exports = source
|
|
981
|
+
module._source = module._exports = source
|
|
963
982
|
}
|
|
964
983
|
|
|
965
984
|
Module._extensions['.txt'] = function (module, source, referrer) {
|
|
@@ -969,9 +988,10 @@ Module._extensions['.txt'] = function (module, source, referrer) {
|
|
|
969
988
|
|
|
970
989
|
if (source === null) source = protocol.read(module._url)
|
|
971
990
|
|
|
972
|
-
if (typeof source
|
|
991
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
973
992
|
|
|
974
|
-
module.
|
|
993
|
+
module._source = source
|
|
994
|
+
module._exports = source.toString()
|
|
975
995
|
}
|
|
976
996
|
|
|
977
997
|
Module._protocol = new Protocol({
|
|
@@ -1012,14 +1032,6 @@ Module._protocol = new Protocol({
|
|
|
1012
1032
|
}
|
|
1013
1033
|
})
|
|
1014
1034
|
|
|
1015
|
-
Bare.prependListener('teardown', () => {
|
|
1016
|
-
for (const module of Module._modules) {
|
|
1017
|
-
module.destroy()
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
binding.destroy(Module._handle)
|
|
1021
|
-
})
|
|
1022
|
-
|
|
1023
1035
|
function toURL(value, base) {
|
|
1024
1036
|
if (isURL(value)) return value
|
|
1025
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.1",
|
|
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
|