bare-module 6.3.2 → 6.4.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 +1 -1
- package/binding.c +61 -28
- package/index.js +260 -232
- package/package.json +3 -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/README.md
CHANGED
|
@@ -442,7 +442,7 @@ The import map when the module was loaded.
|
|
|
442
442
|
|
|
443
443
|
#### `module.resolutions`
|
|
444
444
|
|
|
445
|
-
A map of preresolved imports with keys being serialized parent URLs and values being `"imports"` maps.
|
|
445
|
+
A map of preresolved imports with keys being serialized parent URLs and values being `"imports"` maps. Resolutions performed while loading the module are cached in this map, keyed by the condition (`"import"`, `"require"`, or `"asset"`) that produced them, so that repeated resolutions of the same specifier can be served from the cache.
|
|
446
446
|
|
|
447
447
|
#### `module.builtins`
|
|
448
448
|
|
package/binding.c
CHANGED
|
@@ -34,20 +34,20 @@ bare_module__on_static_import(js_env_t *env, js_value_t *specifier, js_value_t *
|
|
|
34
34
|
err = js_get_reference_value(env, context->on_import, &on_import);
|
|
35
35
|
assert(err == 0);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
err =
|
|
37
|
+
js_value_t *id;
|
|
38
|
+
err = js_get_module_id(env, referrer, &id);
|
|
39
39
|
assert(err == 0);
|
|
40
40
|
|
|
41
|
-
js_value_t *args[
|
|
41
|
+
js_value_t *args[5] = {specifier, assertions, NULL, id};
|
|
42
42
|
|
|
43
|
-
err =
|
|
44
|
-
|
|
43
|
+
err = js_get_undefined(env, &args[2]);
|
|
44
|
+
assert(err == 0);
|
|
45
45
|
|
|
46
|
-
err = js_get_boolean(env, false, &args[
|
|
46
|
+
err = js_get_boolean(env, false, &args[4]);
|
|
47
47
|
assert(err == 0);
|
|
48
48
|
|
|
49
49
|
js_value_t *result;
|
|
50
|
-
err = js_call_function(env, ctx, on_import,
|
|
50
|
+
err = js_call_function(env, ctx, on_import, 5, args, &result);
|
|
51
51
|
if (err < 0) goto err;
|
|
52
52
|
|
|
53
53
|
js_module_t *module;
|
|
@@ -84,13 +84,13 @@ bare_module__on_dynamic_import(js_env_t *env, js_value_t *specifier, js_value_t
|
|
|
84
84
|
err = js_get_reference_value(env, context->on_import, &on_import);
|
|
85
85
|
assert(err == 0);
|
|
86
86
|
|
|
87
|
-
js_value_t *args[
|
|
87
|
+
js_value_t *args[5] = {specifier, assertions, referrer, id};
|
|
88
88
|
|
|
89
|
-
err = js_get_boolean(env, true, &args[
|
|
89
|
+
err = js_get_boolean(env, true, &args[4]);
|
|
90
90
|
assert(err == 0);
|
|
91
91
|
|
|
92
92
|
js_value_t *result;
|
|
93
|
-
err = js_call_function(env, ctx, on_import,
|
|
93
|
+
err = js_call_function(env, ctx, on_import, 5, args, &result);
|
|
94
94
|
if (err < 0) goto err;
|
|
95
95
|
|
|
96
96
|
err = js_escape_handle(env, scope, result, &result);
|
|
@@ -126,14 +126,11 @@ bare_module__on_evaluate(js_env_t *env, js_module_t *module, void *data) {
|
|
|
126
126
|
err = js_get_reference_value(env, context->on_evaluate, &on_evaluate);
|
|
127
127
|
assert(err == 0);
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
err =
|
|
129
|
+
js_value_t *id;
|
|
130
|
+
err = js_get_module_id(env, module, &id);
|
|
131
131
|
assert(err == 0);
|
|
132
132
|
|
|
133
|
-
js_value_t *args[1];
|
|
134
|
-
|
|
135
|
-
err = js_create_string_utf8(env, (utf8_t *) name, -1, &args[0]);
|
|
136
|
-
if (err < 0) goto err;
|
|
133
|
+
js_value_t *args[1] = {id};
|
|
137
134
|
|
|
138
135
|
js_value_t *result;
|
|
139
136
|
err = js_call_function(env, ctx, on_evaluate, 1, args, &result);
|
|
@@ -167,16 +164,11 @@ bare_module__on_meta(js_env_t *env, js_module_t *module, js_value_t *meta, void
|
|
|
167
164
|
err = js_get_reference_value(env, context->on_meta, &on_meta);
|
|
168
165
|
assert(err == 0);
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
err =
|
|
167
|
+
js_value_t *id;
|
|
168
|
+
err = js_get_module_id(env, module, &id);
|
|
172
169
|
assert(err == 0);
|
|
173
170
|
|
|
174
|
-
js_value_t *args[2];
|
|
175
|
-
|
|
176
|
-
err = js_create_string_utf8(env, (utf8_t *) name, -1, &args[0]);
|
|
177
|
-
if (err < 0) goto err;
|
|
178
|
-
|
|
179
|
-
args[1] = meta;
|
|
171
|
+
js_value_t *args[2] = {id, meta};
|
|
180
172
|
|
|
181
173
|
js_value_t *result;
|
|
182
174
|
err = js_call_function(env, ctx, on_meta, 2, args, &result);
|
|
@@ -300,6 +292,23 @@ err:
|
|
|
300
292
|
return NULL;
|
|
301
293
|
}
|
|
302
294
|
|
|
295
|
+
static js_value_t *
|
|
296
|
+
bare_module_get_function_id(js_env_t *env, js_callback_info_t *info) {
|
|
297
|
+
int err;
|
|
298
|
+
|
|
299
|
+
size_t argc = 1;
|
|
300
|
+
js_value_t *argv[1];
|
|
301
|
+
|
|
302
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
303
|
+
assert(err == 0);
|
|
304
|
+
|
|
305
|
+
js_value_t *result;
|
|
306
|
+
err = js_get_function_id(env, argv[0], &result);
|
|
307
|
+
if (err < 0) return NULL;
|
|
308
|
+
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
|
|
303
312
|
static void
|
|
304
313
|
bare_module__on_finalize(js_env_t *env, void *data, void *finalize_hint) {
|
|
305
314
|
int err;
|
|
@@ -397,7 +406,7 @@ err:
|
|
|
397
406
|
}
|
|
398
407
|
|
|
399
408
|
static js_value_t *
|
|
400
|
-
|
|
409
|
+
bare_module_set_module_export(js_env_t *env, js_callback_info_t *info) {
|
|
401
410
|
int err;
|
|
402
411
|
|
|
403
412
|
size_t argc = 3;
|
|
@@ -480,7 +489,7 @@ bare_module_run_module(js_env_t *env, js_callback_info_t *info) {
|
|
|
480
489
|
}
|
|
481
490
|
|
|
482
491
|
static js_value_t *
|
|
483
|
-
|
|
492
|
+
bare_module_get_module_namespace(js_env_t *env, js_callback_info_t *info) {
|
|
484
493
|
int err;
|
|
485
494
|
|
|
486
495
|
size_t argc = 1;
|
|
@@ -500,6 +509,27 @@ bare_module_get_namespace(js_env_t *env, js_callback_info_t *info) {
|
|
|
500
509
|
return result;
|
|
501
510
|
}
|
|
502
511
|
|
|
512
|
+
static js_value_t *
|
|
513
|
+
bare_module_get_module_id(js_env_t *env, js_callback_info_t *info) {
|
|
514
|
+
int err;
|
|
515
|
+
|
|
516
|
+
size_t argc = 1;
|
|
517
|
+
js_value_t *argv[1];
|
|
518
|
+
|
|
519
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
520
|
+
assert(err == 0);
|
|
521
|
+
|
|
522
|
+
js_module_t *module;
|
|
523
|
+
err = js_get_value_external(env, argv[0], (void **) &module);
|
|
524
|
+
if (err < 0) return NULL;
|
|
525
|
+
|
|
526
|
+
js_value_t *result;
|
|
527
|
+
err = js_get_module_id(env, module, &result);
|
|
528
|
+
if (err < 0) return NULL;
|
|
529
|
+
|
|
530
|
+
return result;
|
|
531
|
+
}
|
|
532
|
+
|
|
503
533
|
static js_value_t *
|
|
504
534
|
bare_module_exists(js_env_t *env, js_callback_info_t *info) {
|
|
505
535
|
int err;
|
|
@@ -679,11 +709,14 @@ bare_module_exports(js_env_t *env, js_value_t *exports) {
|
|
|
679
709
|
V("init", bare_module_init)
|
|
680
710
|
|
|
681
711
|
V("createFunction", bare_module_create_function)
|
|
712
|
+
V("getFunctionID", bare_module_get_function_id)
|
|
713
|
+
|
|
682
714
|
V("createModule", bare_module_create_module)
|
|
683
715
|
V("createSyntheticModule", bare_module_create_synthetic_module)
|
|
684
|
-
V("
|
|
716
|
+
V("setModuleExport", bare_module_set_module_export)
|
|
685
717
|
V("runModule", bare_module_run_module)
|
|
686
|
-
V("
|
|
718
|
+
V("getModuleID", bare_module_get_module_id)
|
|
719
|
+
V("getModuleNamespace", bare_module_get_module_namespace)
|
|
687
720
|
|
|
688
721
|
V("exists", bare_module_exists)
|
|
689
722
|
V("realpath", bare_module_realpath)
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('bare-path')
|
|
2
2
|
const resolve = require('bare-module-resolve')
|
|
3
3
|
const lex = require('bare-module-lexer')
|
|
4
|
+
const strip = require('bare-type-stripper')
|
|
4
5
|
const { isURL, fileURLToPath, pathToFileURL } = require('bare-url')
|
|
5
6
|
const Bundle = require('bare-bundle')
|
|
6
7
|
const Protocol = require('./lib/protocol')
|
|
@@ -193,6 +194,10 @@ module.exports = exports = class Module {
|
|
|
193
194
|
this._names = Array.from(names)
|
|
194
195
|
|
|
195
196
|
this._handle = binding.createSyntheticModule(this._url.href, this._names, Module._handle)
|
|
197
|
+
|
|
198
|
+
const id = binding.getModuleID(this._handle)
|
|
199
|
+
|
|
200
|
+
Module._registry.set(id, this)
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
_evaluate() {
|
|
@@ -211,7 +216,7 @@ module.exports = exports = class Module {
|
|
|
211
216
|
} else if (this._type === constants.types.MODULE) {
|
|
212
217
|
this._run()
|
|
213
218
|
|
|
214
|
-
this._exports = binding.
|
|
219
|
+
this._exports = binding.getModuleNamespace(this._handle)
|
|
215
220
|
}
|
|
216
221
|
}
|
|
217
222
|
|
|
@@ -245,6 +250,8 @@ module.exports = exports = class Module {
|
|
|
245
250
|
|
|
246
251
|
static _protocol = null
|
|
247
252
|
|
|
253
|
+
static _registry = new WeakMap()
|
|
254
|
+
|
|
248
255
|
static _cache =
|
|
249
256
|
module[kind] === Module[kind] ? module.cache || Object.create(null) : Object.create(null)
|
|
250
257
|
|
|
@@ -252,18 +259,20 @@ module.exports = exports = class Module {
|
|
|
252
259
|
|
|
253
260
|
static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
|
|
254
261
|
|
|
255
|
-
static _onimport(specifier, attributes,
|
|
256
|
-
const referrer = this.
|
|
262
|
+
static _onimport(specifier, attributes, referrerName, id, isDynamicImport) {
|
|
263
|
+
const referrer = this._registry.get(id) || null
|
|
257
264
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
)
|
|
265
|
+
let parentURL
|
|
266
|
+
|
|
267
|
+
if (referrer !== null) {
|
|
268
|
+
parentURL = referrer._url
|
|
269
|
+
} else if (isDynamicImport) {
|
|
270
|
+
parentURL = referrerName ? toURL(referrerName) : pathToFileURL('./')
|
|
271
|
+
} else {
|
|
272
|
+
throw errors.MODULE_NOT_FOUND(`Cannot find referrer for module '${specifier}'`, specifier)
|
|
264
273
|
}
|
|
265
274
|
|
|
266
|
-
const resolved = this.resolve(specifier,
|
|
275
|
+
const resolved = this.resolve(specifier, parentURL, {
|
|
267
276
|
isImport: true,
|
|
268
277
|
referrer,
|
|
269
278
|
attributes
|
|
@@ -277,15 +286,15 @@ module.exports = exports = class Module {
|
|
|
277
286
|
})
|
|
278
287
|
|
|
279
288
|
return isDynamicImport
|
|
280
|
-
? module._promise.then(() => binding.
|
|
289
|
+
? module._promise.then(() => binding.getModuleNamespace(module._handle))
|
|
281
290
|
: module._handle
|
|
282
291
|
}
|
|
283
292
|
|
|
284
|
-
static _onevaluate(
|
|
285
|
-
const module = this.
|
|
293
|
+
static _onevaluate(id) {
|
|
294
|
+
const module = this._registry.get(id) || null
|
|
286
295
|
|
|
287
296
|
if (module === null) {
|
|
288
|
-
throw errors.MODULE_NOT_FOUND(
|
|
297
|
+
throw errors.MODULE_NOT_FOUND('Cannot find module')
|
|
289
298
|
}
|
|
290
299
|
|
|
291
300
|
module._evaluate()
|
|
@@ -304,17 +313,15 @@ module.exports = exports = class Module {
|
|
|
304
313
|
value = module._exports[name]
|
|
305
314
|
}
|
|
306
315
|
|
|
307
|
-
binding.
|
|
316
|
+
binding.setModuleExport(module._handle, name, value)
|
|
308
317
|
}
|
|
309
318
|
}
|
|
310
319
|
|
|
311
|
-
static _onmeta(
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
const module = this._cache[href] || null
|
|
320
|
+
static _onmeta(id, meta) {
|
|
321
|
+
const module = this._registry.get(id) || null
|
|
315
322
|
|
|
316
323
|
if (module === null) {
|
|
317
|
-
throw errors.MODULE_NOT_FOUND(
|
|
324
|
+
throw errors.MODULE_NOT_FOUND('Cannot find module')
|
|
318
325
|
}
|
|
319
326
|
|
|
320
327
|
const referrer = module
|
|
@@ -327,7 +334,7 @@ module.exports = exports = class Module {
|
|
|
327
334
|
meta.filename = module.filename // For Node.js compatibility
|
|
328
335
|
|
|
329
336
|
meta.resolve = function resolve(specifier, parentURL = referrer._url) {
|
|
330
|
-
return
|
|
337
|
+
return Module.resolve(specifier, toURL(parentURL, referrer._url), {
|
|
331
338
|
referrer
|
|
332
339
|
}).href
|
|
333
340
|
}
|
|
@@ -349,7 +356,7 @@ module.exports = exports = class Module {
|
|
|
349
356
|
meta.addon.host = Bare.Addon.host
|
|
350
357
|
|
|
351
358
|
meta.asset = function asset(specifier, parentURL = referrer._url) {
|
|
352
|
-
return
|
|
359
|
+
return Module.asset(specifier, toURL(parentURL, referrer._url), {
|
|
353
360
|
referrer
|
|
354
361
|
}).href
|
|
355
362
|
}
|
|
@@ -378,8 +385,6 @@ module.exports = exports = class Module {
|
|
|
378
385
|
}
|
|
379
386
|
|
|
380
387
|
static load(url, source = null, opts = {}) {
|
|
381
|
-
const self = Module
|
|
382
|
-
|
|
383
388
|
if (
|
|
384
389
|
!ArrayBuffer.isView(source) &&
|
|
385
390
|
!Bundle.isBundle(source) &&
|
|
@@ -390,20 +395,22 @@ module.exports = exports = class Module {
|
|
|
390
395
|
source = null
|
|
391
396
|
}
|
|
392
397
|
|
|
398
|
+
const referrer = opts.referrer || null
|
|
399
|
+
const inherited = inherit(referrer)
|
|
400
|
+
|
|
393
401
|
const {
|
|
394
402
|
isImport = false,
|
|
395
403
|
isDynamicImport = false,
|
|
396
|
-
referrer = null,
|
|
397
404
|
attributes,
|
|
398
405
|
type = typeForAttributes(attributes),
|
|
399
|
-
defaultType =
|
|
400
|
-
cache =
|
|
401
|
-
main =
|
|
402
|
-
protocol =
|
|
403
|
-
imports =
|
|
404
|
-
resolutions =
|
|
405
|
-
builtins =
|
|
406
|
-
conditions =
|
|
406
|
+
defaultType = inherited.defaultType,
|
|
407
|
+
cache = inherited.cache,
|
|
408
|
+
main = inherited.main,
|
|
409
|
+
protocol = inherited.protocol,
|
|
410
|
+
imports = inherited.imports,
|
|
411
|
+
resolutions = inherited.resolutions,
|
|
412
|
+
builtins = inherited.builtins,
|
|
413
|
+
conditions = inherited.conditions
|
|
407
414
|
} = opts
|
|
408
415
|
|
|
409
416
|
let module = cache[url.href] || null
|
|
@@ -441,11 +448,11 @@ module.exports = exports = class Module {
|
|
|
441
448
|
attributes !== null &&
|
|
442
449
|
typeof attributes.imports === 'string'
|
|
443
450
|
) {
|
|
444
|
-
const resolved =
|
|
451
|
+
const resolved = Module.resolve(attributes.imports, referrer._url, {
|
|
445
452
|
referrer: module
|
|
446
453
|
})
|
|
447
454
|
|
|
448
|
-
const imports =
|
|
455
|
+
const imports = Module.load(resolved, {
|
|
449
456
|
referrer: module,
|
|
450
457
|
type: constants.types.JSON
|
|
451
458
|
})
|
|
@@ -455,7 +462,7 @@ module.exports = exports = class Module {
|
|
|
455
462
|
|
|
456
463
|
let extension = canonicalExtensionForType(type) || path.extname(url.pathname)
|
|
457
464
|
|
|
458
|
-
if (extension in
|
|
465
|
+
if (extension in Module._extensions === false) {
|
|
459
466
|
if (defaultType) {
|
|
460
467
|
extension = canonicalExtensionForType(defaultType) || '.js'
|
|
461
468
|
} else {
|
|
@@ -463,7 +470,7 @@ module.exports = exports = class Module {
|
|
|
463
470
|
}
|
|
464
471
|
}
|
|
465
472
|
|
|
466
|
-
|
|
473
|
+
Module._extensions[extension](module, source, referrer)
|
|
467
474
|
}
|
|
468
475
|
}
|
|
469
476
|
|
|
@@ -476,25 +483,26 @@ module.exports = exports = class Module {
|
|
|
476
483
|
}
|
|
477
484
|
|
|
478
485
|
static resolve(specifier, parentURL, opts = {}) {
|
|
479
|
-
const self = Module
|
|
480
|
-
|
|
481
486
|
if (typeof specifier !== 'string') {
|
|
482
487
|
throw new TypeError(
|
|
483
488
|
`Specifier must be a string. Received type ${typeof specifier} (${specifier})`
|
|
484
489
|
)
|
|
485
490
|
}
|
|
486
491
|
|
|
492
|
+
const referrer = opts.referrer || null
|
|
493
|
+
const inherited = inherit(referrer)
|
|
494
|
+
|
|
487
495
|
const {
|
|
488
496
|
isImport = false,
|
|
489
|
-
referrer = null,
|
|
490
497
|
attributes,
|
|
491
498
|
type = typeForAttributes(attributes),
|
|
492
499
|
extensions = extensionsForType(type),
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
500
|
+
cache = referrer ? referrer._cache : Object.create(null),
|
|
501
|
+
protocol = inherited.protocol,
|
|
502
|
+
imports = inherited.imports,
|
|
503
|
+
resolutions = inherited.resolutions,
|
|
504
|
+
builtins = inherited.builtins,
|
|
505
|
+
conditions = inherited.conditions
|
|
498
506
|
} = opts
|
|
499
507
|
|
|
500
508
|
const resolved = protocol.preresolve(specifier, parentURL)
|
|
@@ -516,53 +524,52 @@ module.exports = exports = class Module {
|
|
|
516
524
|
builtins: builtins ? Object.keys(builtins) : [],
|
|
517
525
|
engines: Bare.versions
|
|
518
526
|
},
|
|
519
|
-
|
|
527
|
+
readPackageFor(protocol, cache)
|
|
520
528
|
)) {
|
|
521
529
|
candidates.push(resolution)
|
|
522
530
|
|
|
531
|
+
const condition = isImport ? 'import' : 'require'
|
|
532
|
+
|
|
523
533
|
switch (resolution.protocol) {
|
|
524
534
|
case 'builtin:':
|
|
535
|
+
cacheResolution(resolutions, parentURL, resolved, condition, resolution)
|
|
536
|
+
|
|
525
537
|
return resolution
|
|
526
538
|
default:
|
|
527
539
|
if (protocol.exists(resolution, type)) {
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
540
|
+
const postresolved = protocol.postresolve(resolution)
|
|
532
541
|
|
|
533
|
-
|
|
542
|
+
cacheResolution(resolutions, parentURL, resolved, condition, postresolved)
|
|
534
543
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
throw errors.MODULE_NOT_FOUND(message, specifier, parentURL, candidates)
|
|
541
|
-
|
|
542
|
-
function readPackage(packageURL) {
|
|
543
|
-
if (protocol.exists(packageURL, constants.types.JSON)) {
|
|
544
|
-
return Module.load(packageURL, { protocol })._exports
|
|
544
|
+
return postresolved
|
|
545
|
+
}
|
|
545
546
|
}
|
|
546
|
-
|
|
547
|
-
return null
|
|
548
547
|
}
|
|
548
|
+
|
|
549
|
+
throw errors.MODULE_NOT_FOUND(
|
|
550
|
+
notFound('module', specifier, parentURL, candidates),
|
|
551
|
+
specifier,
|
|
552
|
+
parentURL,
|
|
553
|
+
candidates
|
|
554
|
+
)
|
|
549
555
|
}
|
|
550
556
|
|
|
551
557
|
static asset(specifier, parentURL, opts = {}) {
|
|
552
|
-
const self = Module
|
|
553
|
-
|
|
554
558
|
if (typeof specifier !== 'string') {
|
|
555
559
|
throw new TypeError(
|
|
556
560
|
`Specifier must be a string. Received type ${typeof specifier} (${specifier})`
|
|
557
561
|
)
|
|
558
562
|
}
|
|
559
563
|
|
|
564
|
+
const referrer = opts.referrer || null
|
|
565
|
+
const inherited = inherit(referrer)
|
|
566
|
+
|
|
560
567
|
const {
|
|
561
|
-
|
|
562
|
-
protocol =
|
|
563
|
-
imports =
|
|
564
|
-
resolutions =
|
|
565
|
-
conditions =
|
|
568
|
+
cache = referrer ? referrer._cache : Object.create(null),
|
|
569
|
+
protocol = inherited.protocol,
|
|
570
|
+
imports = inherited.imports,
|
|
571
|
+
resolutions = inherited.resolutions,
|
|
572
|
+
conditions = inherited.conditions
|
|
566
573
|
} = opts
|
|
567
574
|
|
|
568
575
|
const resolved = protocol.preresolve(specifier, parentURL)
|
|
@@ -582,120 +589,135 @@ module.exports = exports = class Module {
|
|
|
582
589
|
resolutions,
|
|
583
590
|
engines: Bare.versions
|
|
584
591
|
},
|
|
585
|
-
|
|
592
|
+
readPackageFor(protocol, cache)
|
|
586
593
|
)) {
|
|
587
594
|
candidates.push(resolution)
|
|
588
595
|
|
|
589
596
|
if (protocol.exists(resolution, constants.types.ASSET)) {
|
|
590
|
-
|
|
597
|
+
const postresolved = protocol.postresolve(
|
|
598
|
+
protocol.asset ? protocol.asset(resolution) : resolution
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
cacheResolution(resolutions, parentURL, resolved, 'asset', postresolved)
|
|
602
|
+
|
|
603
|
+
return postresolved
|
|
591
604
|
}
|
|
592
605
|
}
|
|
593
606
|
|
|
594
|
-
|
|
607
|
+
throw errors.ASSET_NOT_FOUND(
|
|
608
|
+
notFound('asset', specifier, parentURL, candidates),
|
|
609
|
+
specifier,
|
|
610
|
+
parentURL,
|
|
611
|
+
candidates
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const Module = exports
|
|
617
|
+
|
|
618
|
+
function inherit(referrer) {
|
|
619
|
+
return {
|
|
620
|
+
defaultType: referrer ? referrer._defaultType : 0,
|
|
621
|
+
cache: referrer ? referrer._cache : Module._cache,
|
|
622
|
+
main: referrer ? referrer._main : null,
|
|
623
|
+
protocol: referrer ? referrer._protocol : Module._protocol,
|
|
624
|
+
imports: referrer ? referrer._imports : null,
|
|
625
|
+
resolutions: referrer ? referrer._resolutions : Object.create(null),
|
|
626
|
+
builtins: referrer ? referrer._builtins : null,
|
|
627
|
+
conditions: referrer ? referrer._conditions : Module._conditions
|
|
628
|
+
}
|
|
629
|
+
}
|
|
595
630
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
631
|
+
function readPackageFor(protocol, cache) {
|
|
632
|
+
return function readPackage(packageURL) {
|
|
633
|
+
if (protocol.exists(packageURL, constants.types.JSON)) {
|
|
634
|
+
return Module.load(packageURL, { protocol, cache })._exports
|
|
599
635
|
}
|
|
600
636
|
|
|
601
|
-
|
|
637
|
+
return null
|
|
638
|
+
}
|
|
639
|
+
}
|
|
602
640
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
return Module.load(packageURL, { protocol })._exports
|
|
606
|
-
}
|
|
641
|
+
function notFound(kind, specifier, parentURL, candidates) {
|
|
642
|
+
let message = `Cannot find ${kind} '${specifier}' imported from '${parentURL.href}'`
|
|
607
643
|
|
|
608
|
-
|
|
609
|
-
|
|
644
|
+
if (candidates.length > 0) {
|
|
645
|
+
message += '\nCandidates:'
|
|
646
|
+
message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
|
|
610
647
|
}
|
|
648
|
+
|
|
649
|
+
return message
|
|
611
650
|
}
|
|
612
651
|
|
|
613
|
-
const
|
|
652
|
+
const typeInfo = {
|
|
653
|
+
[constants.types.SCRIPT]: {
|
|
654
|
+
name: 'script',
|
|
655
|
+
attribute: 'script',
|
|
656
|
+
canonicalExtension: '.cjs',
|
|
657
|
+
extensions: ['.js', '.cjs', '.ts', '.cts']
|
|
658
|
+
},
|
|
659
|
+
[constants.types.MODULE]: {
|
|
660
|
+
name: 'module',
|
|
661
|
+
attribute: 'module',
|
|
662
|
+
canonicalExtension: '.mjs',
|
|
663
|
+
extensions: ['.js', '.mjs', '.ts', '.mts']
|
|
664
|
+
},
|
|
665
|
+
[constants.types.JSON]: {
|
|
666
|
+
name: 'json',
|
|
667
|
+
attribute: 'json',
|
|
668
|
+
canonicalExtension: '.json',
|
|
669
|
+
extensions: ['.json']
|
|
670
|
+
},
|
|
671
|
+
[constants.types.BUNDLE]: {
|
|
672
|
+
name: 'bundle',
|
|
673
|
+
attribute: 'bundle',
|
|
674
|
+
canonicalExtension: '.bundle',
|
|
675
|
+
extensions: ['.bundle']
|
|
676
|
+
},
|
|
677
|
+
[constants.types.ADDON]: {
|
|
678
|
+
name: 'bare',
|
|
679
|
+
attribute: 'addon',
|
|
680
|
+
canonicalExtension: '.bare',
|
|
681
|
+
extensions: ['.bare', '.node']
|
|
682
|
+
},
|
|
683
|
+
[constants.types.BINARY]: {
|
|
684
|
+
name: 'binary',
|
|
685
|
+
attribute: 'binary',
|
|
686
|
+
canonicalExtension: '.bin',
|
|
687
|
+
extensions: ['.bin']
|
|
688
|
+
},
|
|
689
|
+
[constants.types.TEXT]: {
|
|
690
|
+
name: 'text',
|
|
691
|
+
attribute: 'text',
|
|
692
|
+
canonicalExtension: '.txt',
|
|
693
|
+
extensions: ['.txt']
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const defaultExtensions = ['.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.json', '.bare', '.node']
|
|
698
|
+
|
|
699
|
+
const typeByAttribute = Object.create(null)
|
|
700
|
+
|
|
701
|
+
for (const type in typeInfo) {
|
|
702
|
+
typeByAttribute[typeInfo[type].attribute] = +type
|
|
703
|
+
}
|
|
614
704
|
|
|
615
705
|
function extensionsForType(type) {
|
|
616
|
-
|
|
617
|
-
case constants.types.SCRIPT:
|
|
618
|
-
return ['.js', '.cjs']
|
|
619
|
-
case constants.types.MODULE:
|
|
620
|
-
return ['.js', '.mjs']
|
|
621
|
-
case constants.types.JSON:
|
|
622
|
-
return ['.json']
|
|
623
|
-
case constants.types.BUNDLE:
|
|
624
|
-
return ['.bundle']
|
|
625
|
-
case constants.types.ADDON:
|
|
626
|
-
return ['.bare', '.node']
|
|
627
|
-
case constants.types.BINARY:
|
|
628
|
-
return ['.bin']
|
|
629
|
-
case constants.types.TEXT:
|
|
630
|
-
return ['.txt']
|
|
631
|
-
default:
|
|
632
|
-
return ['.js', '.cjs', '.mjs', '.json', '.bare', '.node']
|
|
633
|
-
}
|
|
706
|
+
return type in typeInfo ? typeInfo[type].extensions : defaultExtensions
|
|
634
707
|
}
|
|
635
708
|
|
|
636
709
|
function canonicalExtensionForType(type) {
|
|
637
|
-
|
|
638
|
-
case constants.types.SCRIPT:
|
|
639
|
-
return '.cjs'
|
|
640
|
-
case constants.types.MODULE:
|
|
641
|
-
return '.esm'
|
|
642
|
-
case constants.types.JSON:
|
|
643
|
-
return '.json'
|
|
644
|
-
case constants.types.BUNDLE:
|
|
645
|
-
return '.bundle'
|
|
646
|
-
case constants.types.ADDON:
|
|
647
|
-
return '.bare'
|
|
648
|
-
case constants.types.BINARY:
|
|
649
|
-
return '.bin'
|
|
650
|
-
case constants.types.TEXT:
|
|
651
|
-
return '.txt'
|
|
652
|
-
default:
|
|
653
|
-
return null
|
|
654
|
-
}
|
|
710
|
+
return type in typeInfo ? typeInfo[type].canonicalExtension : null
|
|
655
711
|
}
|
|
656
712
|
|
|
657
713
|
function nameOfType(type) {
|
|
658
|
-
|
|
659
|
-
case constants.types.SCRIPT:
|
|
660
|
-
return 'script'
|
|
661
|
-
case constants.types.MODULE:
|
|
662
|
-
return 'module'
|
|
663
|
-
case constants.types.JSON:
|
|
664
|
-
return 'json'
|
|
665
|
-
case constants.types.BUNDLE:
|
|
666
|
-
return 'bundle'
|
|
667
|
-
case constants.types.ADDON:
|
|
668
|
-
return 'bare'
|
|
669
|
-
case constants.types.BINARY:
|
|
670
|
-
return 'binary'
|
|
671
|
-
case constants.types.TEXT:
|
|
672
|
-
return 'text'
|
|
673
|
-
default:
|
|
674
|
-
return null
|
|
675
|
-
}
|
|
714
|
+
return type in typeInfo ? typeInfo[type].name : null
|
|
676
715
|
}
|
|
677
716
|
|
|
678
717
|
function typeForAttributes(attributes) {
|
|
679
718
|
if (typeof attributes !== 'object' || attributes === null) return 0
|
|
680
719
|
|
|
681
|
-
|
|
682
|
-
case 'script':
|
|
683
|
-
return constants.types.SCRIPT
|
|
684
|
-
case 'module':
|
|
685
|
-
return constants.types.MODULE
|
|
686
|
-
case 'json':
|
|
687
|
-
return constants.types.JSON
|
|
688
|
-
case 'bundle':
|
|
689
|
-
return constants.types.BUNDLE
|
|
690
|
-
case 'addon':
|
|
691
|
-
return constants.types.ADDON
|
|
692
|
-
case 'binary':
|
|
693
|
-
return constants.types.BINARY
|
|
694
|
-
case 'text':
|
|
695
|
-
return constants.types.TEXT
|
|
696
|
-
default:
|
|
697
|
-
return 0
|
|
698
|
-
}
|
|
720
|
+
return typeByAttribute[attributes.type] || 0
|
|
699
721
|
}
|
|
700
722
|
|
|
701
723
|
function mixinImports(target, imports, url) {
|
|
@@ -710,6 +732,25 @@ function mixinImports(target, imports, url) {
|
|
|
710
732
|
return { ...target, ...imports }
|
|
711
733
|
}
|
|
712
734
|
|
|
735
|
+
function cacheResolution(resolutions, parentURL, specifier, condition, resolved) {
|
|
736
|
+
if (resolutions === null) return
|
|
737
|
+
|
|
738
|
+
let imports = resolutions[parentURL.href]
|
|
739
|
+
|
|
740
|
+
if (typeof imports !== 'object' || imports === null) {
|
|
741
|
+
imports = resolutions[parentURL.href] = Object.create(null)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// Don't overwrite any preexisting entries, such as those from a bundle, as
|
|
745
|
+
// they take precedence over what we resolve ourselves.
|
|
746
|
+
if (specifier in imports) return
|
|
747
|
+
|
|
748
|
+
// Cache the resolution behind the condition that produced it as the same
|
|
749
|
+
// specifier may resolve differently depending on whether it is imported,
|
|
750
|
+
// required, or resolved as an asset.
|
|
751
|
+
imports[specifier] = { [condition]: resolved.href }
|
|
752
|
+
}
|
|
753
|
+
|
|
713
754
|
exports.Protocol = Protocol
|
|
714
755
|
|
|
715
756
|
exports.constants = constants
|
|
@@ -723,22 +764,22 @@ exports.isBuiltin = function isBuiltin() {
|
|
|
723
764
|
}
|
|
724
765
|
|
|
725
766
|
exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
726
|
-
const
|
|
767
|
+
const inherited = inherit(opts.referrer)
|
|
727
768
|
|
|
728
|
-
|
|
729
|
-
module = null,
|
|
730
|
-
referrer = null,
|
|
769
|
+
const {
|
|
731
770
|
type = constants.types.SCRIPT,
|
|
732
|
-
defaultType =
|
|
733
|
-
cache =
|
|
734
|
-
main =
|
|
735
|
-
protocol =
|
|
736
|
-
imports =
|
|
737
|
-
resolutions =
|
|
738
|
-
builtins =
|
|
739
|
-
conditions =
|
|
771
|
+
defaultType = inherited.defaultType || constants.types.SCRIPT,
|
|
772
|
+
cache = inherited.cache,
|
|
773
|
+
main = inherited.main,
|
|
774
|
+
protocol = inherited.protocol,
|
|
775
|
+
imports = inherited.imports,
|
|
776
|
+
resolutions = inherited.resolutions,
|
|
777
|
+
builtins = inherited.builtins,
|
|
778
|
+
conditions = inherited.conditions
|
|
740
779
|
} = opts
|
|
741
780
|
|
|
781
|
+
let module = opts.module || null
|
|
782
|
+
|
|
742
783
|
if (module === null) {
|
|
743
784
|
module = new Module(toURL(parentURL))
|
|
744
785
|
|
|
@@ -753,17 +794,17 @@ exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
|
753
794
|
module._conditions = conditions
|
|
754
795
|
}
|
|
755
796
|
|
|
756
|
-
referrer = module
|
|
797
|
+
const referrer = module
|
|
757
798
|
|
|
758
799
|
function require(specifier, opts = {}) {
|
|
759
800
|
const attributes = opts && opts.with
|
|
760
801
|
|
|
761
|
-
const resolved =
|
|
802
|
+
const resolved = Module.resolve(specifier, referrer._url, {
|
|
762
803
|
referrer,
|
|
763
804
|
attributes
|
|
764
805
|
})
|
|
765
806
|
|
|
766
|
-
const module =
|
|
807
|
+
const module = Module.load(resolved, { referrer, attributes })
|
|
767
808
|
|
|
768
809
|
return module._exports
|
|
769
810
|
}
|
|
@@ -772,7 +813,7 @@ exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
|
772
813
|
require.cache = module._cache
|
|
773
814
|
|
|
774
815
|
require.resolve = function resolve(specifier, parentURL = referrer._url) {
|
|
775
|
-
return urlToPath(
|
|
816
|
+
return urlToPath(Module.resolve(specifier, toURL(parentURL, referrer._url), { referrer }))
|
|
776
817
|
}
|
|
777
818
|
|
|
778
819
|
require.addon = function addon(specifier = '.', parentURL = referrer._url) {
|
|
@@ -794,15 +835,22 @@ exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
|
794
835
|
}
|
|
795
836
|
|
|
796
837
|
require.asset = function asset(specifier, parentURL = referrer._url) {
|
|
797
|
-
return urlToPath(
|
|
838
|
+
return urlToPath(Module.asset(specifier, toURL(parentURL, referrer._url), { referrer }))
|
|
798
839
|
}
|
|
799
840
|
|
|
800
841
|
return require
|
|
801
842
|
}
|
|
802
843
|
|
|
803
|
-
|
|
804
|
-
|
|
844
|
+
function readSource(module, source) {
|
|
845
|
+
if (source === null) source = module._protocol.read(module._url)
|
|
805
846
|
|
|
847
|
+
if (typeof source === 'string') source = Buffer.from(source)
|
|
848
|
+
|
|
849
|
+
return source
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
Module._extensions['.js'] = function (module, source, referrer) {
|
|
853
|
+
const cache = module._cache
|
|
806
854
|
const protocol = module._protocol
|
|
807
855
|
const resolutions = module._resolutions
|
|
808
856
|
|
|
@@ -811,13 +859,13 @@ Module._extensions['.js'] = function (module, source, referrer) {
|
|
|
811
859
|
for (const packageURL of resolve.lookupPackageScope(module._url, {
|
|
812
860
|
resolutions
|
|
813
861
|
})) {
|
|
814
|
-
if (
|
|
815
|
-
pkg =
|
|
862
|
+
if (cache[packageURL.href]) {
|
|
863
|
+
pkg = cache[packageURL.href]
|
|
816
864
|
break
|
|
817
865
|
}
|
|
818
866
|
|
|
819
867
|
if (protocol.exists(packageURL, constants.types.JSON)) {
|
|
820
|
-
pkg =
|
|
868
|
+
pkg = Module.load(packageURL, { protocol, cache })
|
|
821
869
|
break
|
|
822
870
|
}
|
|
823
871
|
}
|
|
@@ -830,17 +878,13 @@ Module._extensions['.js'] = function (module, source, referrer) {
|
|
|
830
878
|
// The package is explicitly declared as an ES module.
|
|
831
879
|
(info && info.type === 'module')
|
|
832
880
|
|
|
833
|
-
return
|
|
881
|
+
return Module._extensions[isESM ? '.mjs' : '.cjs'](module, source, referrer)
|
|
834
882
|
}
|
|
835
883
|
|
|
836
884
|
Module._extensions['.cjs'] = function (module, source, referrer) {
|
|
837
|
-
const protocol = module._protocol
|
|
838
|
-
|
|
839
885
|
module._type = constants.types.SCRIPT
|
|
840
886
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
if (typeof source === 'string') source = Buffer.from(source)
|
|
887
|
+
source = readSource(module, source)
|
|
844
888
|
|
|
845
889
|
module._source = source
|
|
846
890
|
|
|
@@ -850,46 +894,46 @@ Module._extensions['.cjs'] = function (module, source, referrer) {
|
|
|
850
894
|
source.toString(),
|
|
851
895
|
0
|
|
852
896
|
)
|
|
897
|
+
|
|
898
|
+
const id = binding.getFunctionID(module._function)
|
|
899
|
+
|
|
900
|
+
Module._registry.set(id, module)
|
|
853
901
|
}
|
|
854
902
|
|
|
855
903
|
Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
856
|
-
|
|
904
|
+
module._type = constants.types.MODULE
|
|
857
905
|
|
|
858
|
-
|
|
906
|
+
source = readSource(module, source)
|
|
859
907
|
|
|
860
|
-
module.
|
|
908
|
+
module._source = source
|
|
861
909
|
|
|
862
|
-
|
|
910
|
+
module._handle = binding.createModule(module._url.href, source.toString(), 0, Module._handle)
|
|
863
911
|
|
|
864
|
-
|
|
912
|
+
const id = binding.getModuleID(module._handle)
|
|
865
913
|
|
|
866
|
-
|
|
914
|
+
Module._registry.set(id, module)
|
|
915
|
+
}
|
|
867
916
|
|
|
868
|
-
|
|
917
|
+
for (const [typescript, javascript] of [
|
|
918
|
+
['.ts', '.js'],
|
|
919
|
+
['.cts', '.cjs'],
|
|
920
|
+
['.mts', '.mjs']
|
|
921
|
+
]) {
|
|
922
|
+
Module._extensions[typescript] = function (module, source, referrer) {
|
|
923
|
+
return Module._extensions[javascript](module, strip(readSource(module, source)), referrer)
|
|
924
|
+
}
|
|
869
925
|
}
|
|
870
926
|
|
|
871
927
|
Module._extensions['.json'] = function (module, source, referrer) {
|
|
872
|
-
const protocol = module._protocol
|
|
873
|
-
|
|
874
928
|
module._type = constants.types.JSON
|
|
875
929
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (typeof source === 'string') source = Buffer.from(source)
|
|
930
|
+
source = readSource(module, source)
|
|
879
931
|
|
|
880
932
|
module._source = source
|
|
881
933
|
module._exports = JSON.parse(source.toString())
|
|
882
934
|
}
|
|
883
935
|
|
|
884
|
-
Module._extensions['.bare'] = function (module, source, referrer) {
|
|
885
|
-
module._type = constants.types.ADDON
|
|
886
|
-
|
|
887
|
-
referrer = module
|
|
888
|
-
|
|
889
|
-
module._exports = Bare.Addon.load(module._url, { referrer }).exports
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
Module._extensions['.node'] = function (module, source, referrer) {
|
|
936
|
+
Module._extensions['.bare'] = Module._extensions['.node'] = function (module, source, referrer) {
|
|
893
937
|
module._type = constants.types.ADDON
|
|
894
938
|
|
|
895
939
|
referrer = module
|
|
@@ -898,15 +942,11 @@ Module._extensions['.node'] = function (module, source, referrer) {
|
|
|
898
942
|
}
|
|
899
943
|
|
|
900
944
|
Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
901
|
-
const self = Module
|
|
902
|
-
|
|
903
945
|
const protocol = module._protocol
|
|
904
946
|
|
|
905
947
|
module._type = constants.types.BUNDLE
|
|
906
948
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
if (typeof source === 'string') source = Buffer.from(source)
|
|
949
|
+
source = readSource(module, source)
|
|
910
950
|
|
|
911
951
|
referrer = module
|
|
912
952
|
|
|
@@ -931,32 +971,24 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
|
931
971
|
})
|
|
932
972
|
|
|
933
973
|
if (bundle.main) {
|
|
934
|
-
module._exports =
|
|
974
|
+
module._exports = Module.load(new URL(bundle.main), bundle.read(bundle.main), {
|
|
935
975
|
referrer
|
|
936
976
|
})._exports
|
|
937
977
|
}
|
|
938
978
|
}
|
|
939
979
|
|
|
940
980
|
Module._extensions['.bin'] = function (module, source, referrer) {
|
|
941
|
-
const protocol = module._protocol
|
|
942
|
-
|
|
943
981
|
module._type = constants.types.BINARY
|
|
944
982
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (typeof source === 'string') source = Buffer.from(source)
|
|
983
|
+
source = readSource(module, source)
|
|
948
984
|
|
|
949
985
|
module._source = module._exports = source
|
|
950
986
|
}
|
|
951
987
|
|
|
952
988
|
Module._extensions['.txt'] = function (module, source, referrer) {
|
|
953
|
-
const protocol = module._protocol
|
|
954
|
-
|
|
955
989
|
module._type = constants.types.TEXT
|
|
956
990
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (typeof source === 'string') source = Buffer.from(source)
|
|
991
|
+
source = readSource(module, source)
|
|
960
992
|
|
|
961
993
|
module._source = source
|
|
962
994
|
module._exports = source.toString()
|
|
@@ -1007,15 +1039,7 @@ function toURL(value, base) {
|
|
|
1007
1039
|
function urlToPath(url) {
|
|
1008
1040
|
if (url.protocol === 'file:') return fileURLToPath(url)
|
|
1009
1041
|
|
|
1010
|
-
|
|
1011
|
-
if (/%2f|%5c/i.test(url.pathname)) {
|
|
1012
|
-
throw errors.INVALID_URL_PATH('The URL path must not include encoded \\ or / characters')
|
|
1013
|
-
}
|
|
1014
|
-
} else {
|
|
1015
|
-
if (/%2f/i.test(url.pathname)) {
|
|
1016
|
-
throw errors.INVALID_URL_PATH('The URL path must not include encoded / characters')
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1042
|
+
assertValidURLPath(url)
|
|
1019
1043
|
|
|
1020
1044
|
return decodeURIComponent(url.pathname)
|
|
1021
1045
|
}
|
|
@@ -1023,6 +1047,12 @@ function urlToPath(url) {
|
|
|
1023
1047
|
function urlToDirname(url) {
|
|
1024
1048
|
if (url.protocol === 'file:') return path.dirname(fileURLToPath(url))
|
|
1025
1049
|
|
|
1050
|
+
assertValidURLPath(url)
|
|
1051
|
+
|
|
1052
|
+
return decodeURIComponent(new URL('.', url).pathname).replace(/\/$/, '')
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
function assertValidURLPath(url) {
|
|
1026
1056
|
if (isWindows) {
|
|
1027
1057
|
if (/%2f|%5c/i.test(url.pathname)) {
|
|
1028
1058
|
throw errors.INVALID_URL_PATH('The URL path must not include encoded \\ or / characters')
|
|
@@ -1032,6 +1062,4 @@ function urlToDirname(url) {
|
|
|
1032
1062
|
throw errors.INVALID_URL_PATH('The URL path must not include encoded / characters')
|
|
1033
1063
|
}
|
|
1034
1064
|
}
|
|
1035
|
-
|
|
1036
|
-
return decodeURIComponent(new URL('.', url).pathname).replace(/\/$/, '')
|
|
1037
1065
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "Module support for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -35,13 +35,14 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/holepunchto/bare-module#readme",
|
|
37
37
|
"engines": {
|
|
38
|
-
"bare": ">=1.29.
|
|
38
|
+
"bare": ">=1.29.4"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"bare-bundle": "^1.3.0",
|
|
42
42
|
"bare-module-lexer": "^1.0.0",
|
|
43
43
|
"bare-module-resolve": "^1.8.0",
|
|
44
44
|
"bare-path": "^3.0.0",
|
|
45
|
+
"bare-type-stripper": "^0.1.2",
|
|
45
46
|
"bare-url": "^2.0.1"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
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
|