bare-module 4.7.0 → 4.7.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/index.js CHANGED
@@ -13,8 +13,8 @@ const isWindows = Bare.platform === 'win32'
13
13
 
14
14
  const { startsWithWindowsDriveLetter } = resolve
15
15
 
16
- const Module = module.exports = exports = class Module {
17
- constructor (url) {
16
+ module.exports = exports = class Module {
17
+ constructor(url) {
18
18
  this._url = url
19
19
  this._state = 0
20
20
  this._type = 0
@@ -37,73 +37,73 @@ const Module = module.exports = exports = class Module {
37
37
  Module._modules.add(this)
38
38
  }
39
39
 
40
- get url () {
40
+ get url() {
41
41
  return this._url
42
42
  }
43
43
 
44
- get filename () {
44
+ get filename() {
45
45
  return urlToPath(this._url)
46
46
  }
47
47
 
48
- get dirname () {
48
+ get dirname() {
49
49
  return urlToDirname(this._url)
50
50
  }
51
51
 
52
- get type () {
52
+ get type() {
53
53
  return this._type
54
54
  }
55
55
 
56
- get defaultType () {
56
+ get defaultType() {
57
57
  return this._defaultType
58
58
  }
59
59
 
60
- get cache () {
60
+ get cache() {
61
61
  return this._cache
62
62
  }
63
63
 
64
- get main () {
64
+ get main() {
65
65
  return this._main
66
66
  }
67
67
 
68
- get exports () {
68
+ get exports() {
69
69
  return this._exports
70
70
  }
71
71
 
72
- set exports (value) {
72
+ set exports(value) {
73
73
  this._exports = value
74
74
  }
75
75
 
76
- get imports () {
76
+ get imports() {
77
77
  return this._imports
78
78
  }
79
79
 
80
- get resolutions () {
80
+ get resolutions() {
81
81
  return this._resolutions
82
82
  }
83
83
 
84
- get builtins () {
84
+ get builtins() {
85
85
  return this._builtins
86
86
  }
87
87
 
88
- get conditions () {
88
+ get conditions() {
89
89
  return Array.from(this._conditions)
90
90
  }
91
91
 
92
- get protocol () {
92
+ get protocol() {
93
93
  return this._protocol
94
94
  }
95
95
 
96
96
  // For Node.js compatibility
97
- get id () {
97
+ get id() {
98
98
  return this.filename
99
99
  }
100
100
 
101
101
  // For Node.js compatibility
102
- get path () {
102
+ get path() {
103
103
  return this.dirname
104
104
  }
105
105
 
106
- destroy () {
106
+ destroy() {
107
107
  this._state |= constants.states.DESTROYED
108
108
 
109
109
  if (this._handle) {
@@ -114,11 +114,11 @@ const Module = module.exports = exports = class Module {
114
114
  Module._modules.delete(this)
115
115
  }
116
116
 
117
- _run () {
117
+ _run() {
118
118
  binding.runModule(this._handle, Module._handle, Module._onrun)
119
119
  }
120
120
 
121
- _transform (isImport, isDynamicImport) {
121
+ _transform(isImport, isDynamicImport) {
122
122
  if (isDynamicImport) {
123
123
  this._synthesize()
124
124
  this._evaluate(true /* eagerRun */)
@@ -131,7 +131,7 @@ const Module = module.exports = exports = class Module {
131
131
  return this
132
132
  }
133
133
 
134
- _synthesize () {
134
+ _synthesize() {
135
135
  if ((this._state & constants.states.SYNTHESIZED) !== 0) return
136
136
 
137
137
  this._state |= constants.states.SYNTHESIZED
@@ -159,9 +159,15 @@ const Module = module.exports = exports = class Module {
159
159
 
160
160
  for (const { specifier, type } of result.imports) {
161
161
  if (type & lex.constants.REEXPORT) {
162
- const resolved = Module.resolve(specifier, referrer._url, { isImport: true, referrer })
162
+ const resolved = Module.resolve(specifier, referrer._url, {
163
+ isImport: true,
164
+ referrer
165
+ })
163
166
 
164
- const module = Module.load(resolved, { isImport: true, referrer })
167
+ const module = Module.load(resolved, {
168
+ isImport: true,
169
+ referrer
170
+ })
165
171
 
166
172
  if (module._names) {
167
173
  for (const name of module._names) names.add(name)
@@ -188,10 +194,14 @@ const Module = module.exports = exports = class Module {
188
194
 
189
195
  this._names = Array.from(names)
190
196
 
191
- this._handle = binding.createSyntheticModule(this._url.href, this._names, Module._handle)
197
+ this._handle = binding.createSyntheticModule(
198
+ this._url.href,
199
+ this._names,
200
+ Module._handle
201
+ )
192
202
  }
193
203
 
194
- _evaluate (eagerRun = false) {
204
+ _evaluate(eagerRun = false) {
195
205
  if ((this._state & constants.states.EVALUATED) !== 0) return
196
206
 
197
207
  this._state |= constants.states.EVALUATED
@@ -221,7 +231,7 @@ const Module = module.exports = exports = class Module {
221
231
  }
222
232
  }
223
233
 
224
- [Symbol.for('bare.inspect')] () {
234
+ [Symbol.for('bare.inspect')]() {
225
235
  return {
226
236
  __proto__: { constructor: Module },
227
237
 
@@ -243,23 +253,39 @@ const Module = module.exports = exports = class Module {
243
253
  static _modules = new Set()
244
254
  static _conditions = ['bare', 'node', Bare.platform, Bare.arch]
245
255
 
246
- static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
256
+ static _handle = binding.init(
257
+ this,
258
+ this._onimport,
259
+ this._onevaluate,
260
+ this._onmeta
261
+ )
247
262
 
248
- static _onimport (specifier, attributes, referrerHref, isDynamicImport) {
263
+ static _onimport(specifier, attributes, referrerHref, isDynamicImport) {
249
264
  const referrer = this._cache[referrerHref] || null
250
265
 
251
266
  if (referrer === null) {
252
- throw errors.MODULE_NOT_FOUND(`Cannot find referrer for module '${specifier}' imported from '${referrerHref}'`)
267
+ throw errors.MODULE_NOT_FOUND(
268
+ `Cannot find referrer for module '${specifier}' imported from '${referrerHref}'`
269
+ )
253
270
  }
254
271
 
255
- const resolved = this.resolve(specifier, referrer._url, { isImport: true, referrer, attributes })
272
+ const resolved = this.resolve(specifier, referrer._url, {
273
+ isImport: true,
274
+ referrer,
275
+ attributes
276
+ })
256
277
 
257
- const module = this.load(resolved, { isImport: true, isDynamicImport, referrer, attributes })
278
+ const module = this.load(resolved, {
279
+ isImport: true,
280
+ isDynamicImport,
281
+ referrer,
282
+ attributes
283
+ })
258
284
 
259
285
  return module._handle
260
286
  }
261
287
 
262
- static _onevaluate (href) {
288
+ static _onevaluate(href) {
263
289
  const module = this._cache[href] || null
264
290
 
265
291
  if (module === null) {
@@ -272,11 +298,10 @@ const Module = module.exports = exports = class Module {
272
298
  let value
273
299
 
274
300
  if (
275
- name === 'default' && (
276
- typeof module._exports !== 'object' ||
301
+ name === 'default' &&
302
+ (typeof module._exports !== 'object' ||
277
303
  module._exports === null ||
278
- name in module._exports === false
279
- )
304
+ name in module._exports === false)
280
305
  ) {
281
306
  value = module._exports
282
307
  } else {
@@ -287,7 +312,7 @@ const Module = module.exports = exports = class Module {
287
312
  }
288
313
  }
289
314
 
290
- static _onmeta (href, meta) {
315
+ static _onmeta(href, meta) {
291
316
  const self = Module
292
317
 
293
318
  const module = this._cache[href] || null
@@ -302,51 +327,72 @@ const Module = module.exports = exports = class Module {
302
327
  meta.main = module._main === module
303
328
  meta.cache = module._cache
304
329
 
305
- meta.resolve = function resolve (specifier, parentURL = referrer._url) {
306
- return self.resolve(specifier, toURL(parentURL, referrer._url), { referrer }).href
330
+ meta.resolve = function resolve(specifier, parentURL = referrer._url) {
331
+ return self.resolve(specifier, toURL(parentURL, referrer._url), {
332
+ referrer
333
+ }).href
307
334
  }
308
335
 
309
- meta.addon = function addon (specifier = '.', parentURL = referrer._url) {
310
- const resolved = Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), { referrer })
336
+ meta.addon = function addon(specifier = '.', parentURL = referrer._url) {
337
+ const resolved = Bare.Addon.resolve(
338
+ specifier,
339
+ toURL(parentURL, referrer._url),
340
+ { referrer }
341
+ )
311
342
 
312
343
  const addon = Bare.Addon.load(resolved, { referrer })
313
344
 
314
345
  return addon._exports
315
346
  }
316
347
 
317
- meta.addon.resolve = function resolve (specifier = '.', parentURL = referrer._url) {
318
- return Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), { referrer }).href
348
+ meta.addon.resolve = function resolve(
349
+ specifier = '.',
350
+ parentURL = referrer._url
351
+ ) {
352
+ return Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), {
353
+ referrer
354
+ }).href
319
355
  }
320
356
 
321
357
  meta.addon.host = Bare.Addon.host
322
358
 
323
- meta.asset = function asset (specifier, parentURL = referrer._url) {
324
- return self.asset(specifier, toURL(parentURL, referrer._url), { referrer }).href
359
+ meta.asset = function asset(specifier, parentURL = referrer._url) {
360
+ return self.asset(specifier, toURL(parentURL, referrer._url), {
361
+ referrer
362
+ }).href
325
363
  }
326
364
  }
327
365
 
328
- static _onrun (reason, promise, err = reason) {
366
+ static _onrun(reason, promise, err = reason) {
329
367
  if (err) {
330
368
  promise.catch(() => {}) // Don't leak the rejection
331
369
 
332
370
  throw err
333
371
  } else {
334
- promise.catch((err) => queueMicrotask(() => { throw err }))
372
+ promise.catch((err) =>
373
+ queueMicrotask(() => {
374
+ throw err
375
+ })
376
+ )
335
377
  }
336
378
  }
337
379
 
338
- static get protocol () {
380
+ static get protocol() {
339
381
  return this._protocol
340
382
  }
341
383
 
342
- static get cache () {
384
+ static get cache() {
343
385
  return this._cache
344
386
  }
345
387
 
346
- static load (url, source = null, opts = {}) {
388
+ static load(url, source = null, opts = {}) {
347
389
  const self = Module
348
390
 
349
- if (!ArrayBuffer.isView(source) && typeof source !== 'string' && source !== null) {
391
+ if (
392
+ !ArrayBuffer.isView(source) &&
393
+ typeof source !== 'string' &&
394
+ source !== null
395
+ ) {
350
396
  opts = source
351
397
  source = null
352
398
  }
@@ -372,7 +418,9 @@ const Module = module.exports = exports = class Module {
372
418
 
373
419
  if (module !== null) {
374
420
  if (type !== 0 && type !== module._type) {
375
- throw errors.TYPE_INCOMPATIBLE(`Module '${module.url.href}' is not of type '${nameOfType(type)}'`)
421
+ throw errors.TYPE_INCOMPATIBLE(
422
+ `Module '${module.url.href}' is not of type '${nameOfType(type)}'`
423
+ )
376
424
  }
377
425
 
378
426
  return module._transform(isImport, isDynamicImport)
@@ -396,10 +444,12 @@ const Module = module.exports = exports = class Module {
396
444
  module._builtins = builtins
397
445
  module._conditions = conditions
398
446
 
399
- let extension = canonicalExtensionForType(type) || path.extname(url.pathname)
447
+ let extension =
448
+ canonicalExtensionForType(type) || path.extname(url.pathname)
400
449
 
401
450
  if (extension in self._extensions === false) {
402
- if (defaultType) extension = canonicalExtensionForType(defaultType) || '.js'
451
+ if (defaultType)
452
+ extension = canonicalExtensionForType(defaultType) || '.js'
403
453
  else extension = '.js'
404
454
  }
405
455
 
@@ -415,11 +465,13 @@ const Module = module.exports = exports = class Module {
415
465
  }
416
466
  }
417
467
 
418
- static resolve (specifier, parentURL, opts = {}) {
468
+ static resolve(specifier, parentURL, opts = {}) {
419
469
  const self = Module
420
470
 
421
471
  if (typeof specifier !== 'string') {
422
- throw new TypeError(`Specifier must be a string. Received type ${typeof specifier} (${specifier})`)
472
+ throw new TypeError(
473
+ `Specifier must be a string. Received type ${typeof specifier} (${specifier})`
474
+ )
423
475
  }
424
476
 
425
477
  const {
@@ -442,18 +494,24 @@ const Module = module.exports = exports = class Module {
442
494
 
443
495
  if (resolution) return protocol.postresolve(resolution)
444
496
 
445
- for (const resolution of resolve(resolved, parentURL, {
446
- conditions: isImport ? ['import', ...conditions] : ['require', ...conditions],
447
- imports,
448
- resolutions,
449
- extensions,
450
- builtins: builtins ? Object.keys(builtins) : [],
451
- engines: {
452
- ...Bare.versions
453
- }
454
- }, readPackage)) {
497
+ for (const resolution of resolve(
498
+ resolved,
499
+ parentURL,
500
+ {
501
+ conditions: isImport
502
+ ? ['import', ...conditions]
503
+ : ['require', ...conditions],
504
+ imports,
505
+ resolutions,
506
+ extensions,
507
+ builtins: builtins ? Object.keys(builtins) : [],
508
+ engines: Bare.versions
509
+ },
510
+ readPackage
511
+ )) {
455
512
  switch (resolution.protocol) {
456
- case 'builtin:': return resolution
513
+ case 'builtin:':
514
+ return resolution
457
515
  default:
458
516
  if (protocol.exists(resolution)) {
459
517
  return protocol.postresolve(resolution)
@@ -461,9 +519,11 @@ const Module = module.exports = exports = class Module {
461
519
  }
462
520
  }
463
521
 
464
- throw errors.MODULE_NOT_FOUND(`Cannot find module '${specifier}' imported from '${parentURL.href}'`)
522
+ throw errors.MODULE_NOT_FOUND(
523
+ `Cannot find module '${specifier}' imported from '${parentURL.href}'`
524
+ )
465
525
 
466
- function readPackage (packageURL) {
526
+ function readPackage(packageURL) {
467
527
  if (protocol.exists(packageURL)) {
468
528
  return Module.load(packageURL, { protocol })._exports
469
529
  }
@@ -472,11 +532,13 @@ const Module = module.exports = exports = class Module {
472
532
  }
473
533
  }
474
534
 
475
- static asset (specifier, parentURL, opts = {}) {
535
+ static asset(specifier, parentURL, opts = {}) {
476
536
  const self = Module
477
537
 
478
538
  if (typeof specifier !== 'string') {
479
- throw new TypeError(`Specifier must be a string. Received type ${typeof specifier} (${specifier})`)
539
+ throw new TypeError(
540
+ `Specifier must be a string. Received type ${typeof specifier} (${specifier})`
541
+ )
480
542
  }
481
543
 
482
544
  const {
@@ -493,19 +555,29 @@ const Module = module.exports = exports = class Module {
493
555
 
494
556
  if (resolution) return protocol.postresolve(resolution)
495
557
 
496
- for (const resolution of resolve(resolved, parentURL, {
497
- conditions: ['asset', ...conditions],
498
- imports,
499
- resolutions
500
- }, readPackage)) {
558
+ for (const resolution of resolve(
559
+ resolved,
560
+ parentURL,
561
+ {
562
+ conditions: ['asset', ...conditions],
563
+ imports,
564
+ resolutions,
565
+ engines: Bare.versions
566
+ },
567
+ readPackage
568
+ )) {
501
569
  if (protocol.exists(resolution)) {
502
- return protocol.postresolve(protocol.asset ? protocol.asset(resolution) : resolution)
570
+ return protocol.postresolve(
571
+ protocol.asset ? protocol.asset(resolution) : resolution
572
+ )
503
573
  }
504
574
  }
505
575
 
506
- throw errors.ASSET_NOT_FOUND(`Cannot find asset '${specifier}' imported from '${parentURL.href}'`)
576
+ throw errors.ASSET_NOT_FOUND(
577
+ `Cannot find asset '${specifier}' imported from '${parentURL.href}'`
578
+ )
507
579
 
508
- function readPackage (packageURL) {
580
+ function readPackage(packageURL) {
509
581
  if (protocol.exists(packageURL)) {
510
582
  return Module.load(packageURL, { protocol })._exports
511
583
  }
@@ -515,7 +587,9 @@ const Module = module.exports = exports = class Module {
515
587
  }
516
588
  }
517
589
 
518
- function extensionsForType (type) {
590
+ const Module = exports
591
+
592
+ function extensionsForType(type) {
519
593
  switch (type) {
520
594
  case constants.types.SCRIPT:
521
595
  return ['.js', '.cjs']
@@ -536,7 +610,7 @@ function extensionsForType (type) {
536
610
  }
537
611
  }
538
612
 
539
- function canonicalExtensionForType (type) {
613
+ function canonicalExtensionForType(type) {
540
614
  switch (type) {
541
615
  case constants.types.SCRIPT:
542
616
  return '.cjs'
@@ -557,7 +631,7 @@ function canonicalExtensionForType (type) {
557
631
  }
558
632
  }
559
633
 
560
- function nameOfType (type) {
634
+ function nameOfType(type) {
561
635
  switch (type) {
562
636
  case constants.types.SCRIPT:
563
637
  return 'script'
@@ -578,7 +652,7 @@ function nameOfType (type) {
578
652
  }
579
653
  }
580
654
 
581
- function typeForAttributes (attributes) {
655
+ function typeForAttributes(attributes) {
582
656
  if (typeof attributes !== 'object' || attributes === null) return 0
583
657
 
584
658
  switch (attributes.type) {
@@ -610,11 +684,14 @@ exports.constants = constants
610
684
  exports.builtinModules = []
611
685
 
612
686
  // For Node.js compatibility
613
- exports.isBuiltin = function isBuiltin () {
687
+ exports.isBuiltin = function isBuiltin() {
614
688
  return false
615
689
  }
616
690
 
617
- const createRequire = exports.createRequire = function createRequire (parentURL, opts = {}) {
691
+ const createRequire = (exports.createRequire = function createRequire(
692
+ parentURL,
693
+ opts = {}
694
+ ) {
618
695
  const self = Module
619
696
 
620
697
  let {
@@ -648,10 +725,13 @@ const createRequire = exports.createRequire = function createRequire (parentURL,
648
725
 
649
726
  referrer = module
650
727
 
651
- function require (specifier, opts = {}) {
728
+ function require(specifier, opts = {}) {
652
729
  const attributes = opts && opts.with
653
730
 
654
- const resolved = self.resolve(specifier, referrer._url, { referrer, attributes })
731
+ const resolved = self.resolve(specifier, referrer._url, {
732
+ referrer,
733
+ attributes
734
+ })
655
735
 
656
736
  const module = self.load(resolved, { referrer, attributes })
657
737
 
@@ -661,12 +741,18 @@ const createRequire = exports.createRequire = function createRequire (parentURL,
661
741
  require.main = module._main
662
742
  require.cache = module._cache
663
743
 
664
- require.resolve = function resolve (specifier, parentURL = referrer._url) {
665
- return urlToPath(self.resolve(specifier, toURL(parentURL, referrer._url), { referrer }))
744
+ require.resolve = function resolve(specifier, parentURL = referrer._url) {
745
+ return urlToPath(
746
+ self.resolve(specifier, toURL(parentURL, referrer._url), { referrer })
747
+ )
666
748
  }
667
749
 
668
- require.addon = function addon (specifier = '.', parentURL = referrer._url) {
669
- const resolved = Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), { referrer })
750
+ require.addon = function addon(specifier = '.', parentURL = referrer._url) {
751
+ const resolved = Bare.Addon.resolve(
752
+ specifier,
753
+ toURL(parentURL, referrer._url),
754
+ { referrer }
755
+ )
670
756
 
671
757
  const addon = Bare.Addon.load(resolved, { referrer })
672
758
 
@@ -675,16 +761,25 @@ const createRequire = exports.createRequire = function createRequire (parentURL,
675
761
 
676
762
  require.addon.host = Bare.Addon.host
677
763
 
678
- require.addon.resolve = function resolve (specifier = '.', parentURL = referrer._url) {
679
- return urlToPath(Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), { referrer }))
764
+ require.addon.resolve = function resolve(
765
+ specifier = '.',
766
+ parentURL = referrer._url
767
+ ) {
768
+ return urlToPath(
769
+ Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), {
770
+ referrer
771
+ })
772
+ )
680
773
  }
681
774
 
682
- require.asset = function asset (specifier, parentURL = referrer._url) {
683
- return urlToPath(self.asset(specifier, toURL(parentURL, referrer._url), { referrer }))
775
+ require.asset = function asset(specifier, parentURL = referrer._url) {
776
+ return urlToPath(
777
+ self.asset(specifier, toURL(parentURL, referrer._url), { referrer })
778
+ )
684
779
  }
685
780
 
686
781
  return require
687
- }
782
+ })
688
783
 
689
784
  if (Bare.simulator) Module._conditions.push('simulator')
690
785
 
@@ -696,7 +791,9 @@ Module._extensions['.js'] = function (module, source, referrer) {
696
791
 
697
792
  let pkg
698
793
 
699
- for (const packageURL of resolve.lookupPackageScope(module._url, { resolutions })) {
794
+ for (const packageURL of resolve.lookupPackageScope(module._url, {
795
+ resolutions
796
+ })) {
700
797
  if (self._cache[packageURL.href]) {
701
798
  pkg = self._cache[packageURL.href]
702
799
  break
@@ -710,13 +807,11 @@ Module._extensions['.js'] = function (module, source, referrer) {
710
807
 
711
808
  const info = (pkg && pkg._exports) || {}
712
809
 
713
- const isESM = (
810
+ const isESM =
714
811
  // The default type is ES modules.
715
- (constants.types.MODULE === module._defaultType) ||
716
-
812
+ constants.types.MODULE === module._defaultType ||
717
813
  // The package is explicitly declared as an ES module.
718
814
  (info && info.type === 'module')
719
- )
720
815
 
721
816
  return self._extensions[isESM ? '.mjs' : '.cjs'](module, source, referrer)
722
817
  }
@@ -733,7 +828,12 @@ Module._extensions['.cjs'] = function (module, source, referrer) {
733
828
 
734
829
  if (typeof source !== 'string') source = Buffer.coerce(source).toString()
735
830
 
736
- module._function = binding.createFunction(module._url.href, ['require', 'module', 'exports', '__filename', '__dirname'], source, 0)
831
+ module._function = binding.createFunction(
832
+ module._url.href,
833
+ ['require', 'module', 'exports', '__filename', '__dirname'],
834
+ source,
835
+ 0
836
+ )
737
837
  }
738
838
  }
739
839
 
@@ -751,7 +851,12 @@ Module._extensions['.mjs'] = function (module, source, referrer) {
751
851
 
752
852
  if (typeof source !== 'string') source = Buffer.coerce(source).toString()
753
853
 
754
- module._handle = binding.createModule(module._url.href, source, 0, self._handle)
854
+ module._handle = binding.createModule(
855
+ module._url.href,
856
+ source,
857
+ 0,
858
+ self._handle
859
+ )
755
860
  }
756
861
  }
757
862
 
@@ -800,27 +905,33 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
800
905
 
801
906
  referrer = module
802
907
 
803
- const bundle = module._bundle = Bundle.from(source).mount(module._url.href + '/')
908
+ const bundle = (module._bundle = Bundle.from(source).mount(
909
+ module._url.href + '/'
910
+ ))
804
911
 
805
912
  module._imports = bundle.imports
806
913
  module._resolutions = bundle.resolutions
807
914
 
808
915
  module._protocol = protocol.extend({
809
- postresolve (context, url) {
916
+ postresolve(context, url) {
810
917
  return bundle.exists(url.href) ? url : context.postresolve(url)
811
918
  },
812
919
 
813
- exists (context, url) {
920
+ exists(context, url) {
814
921
  return bundle.exists(url.href) || context.exists(url)
815
922
  },
816
923
 
817
- read (context, url) {
924
+ read(context, url) {
818
925
  return bundle.read(url.href) || context.read(url)
819
926
  }
820
927
  })
821
928
 
822
929
  if (bundle.main) {
823
- module._exports = self.load(new URL(bundle.main), bundle.read(bundle.main), { referrer })._exports
930
+ module._exports = self.load(
931
+ new URL(bundle.main),
932
+ bundle.read(bundle.main),
933
+ { referrer }
934
+ )._exports
824
935
  }
825
936
  }
826
937
 
@@ -849,7 +960,7 @@ Module._extensions['.txt'] = function (module, source, referrer) {
849
960
  }
850
961
 
851
962
  Module._protocol = new Protocol({
852
- postresolve (url) {
963
+ postresolve(url) {
853
964
  switch (url.protocol) {
854
965
  case 'file:':
855
966
  return pathToFileURL(binding.realpath(fileURLToPath(url)))
@@ -858,7 +969,7 @@ Module._protocol = new Protocol({
858
969
  }
859
970
  },
860
971
 
861
- exists (url) {
972
+ exists(url) {
862
973
  switch (url.protocol) {
863
974
  case 'file:':
864
975
  return binding.exists(fileURLToPath(url))
@@ -867,7 +978,7 @@ Module._protocol = new Protocol({
867
978
  }
868
979
  },
869
980
 
870
- read (url) {
981
+ read(url) {
871
982
  switch (url.protocol) {
872
983
  case 'file:':
873
984
  return Buffer.from(binding.read(fileURLToPath(url)))
@@ -877,16 +988,15 @@ Module._protocol = new Protocol({
877
988
  }
878
989
  })
879
990
 
880
- Bare
881
- .prependListener('teardown', () => {
882
- for (const module of Module._modules) {
883
- module.destroy()
884
- }
991
+ Bare.prependListener('teardown', () => {
992
+ for (const module of Module._modules) {
993
+ module.destroy()
994
+ }
885
995
 
886
- binding.destroy(Module._handle)
887
- })
996
+ binding.destroy(Module._handle)
997
+ })
888
998
 
889
- function toURL (value, base) {
999
+ function toURL(value, base) {
890
1000
  if (isURL(value)) return value
891
1001
 
892
1002
  if (startsWithWindowsDriveLetter(value)) {
@@ -896,34 +1006,42 @@ function toURL (value, base) {
896
1006
  return URL.parse(value, base) || pathToFileURL(value)
897
1007
  }
898
1008
 
899
- function urlToPath (url) {
1009
+ function urlToPath(url) {
900
1010
  if (url.protocol === 'file:') return fileURLToPath(url)
901
1011
 
902
1012
  if (isWindows) {
903
1013
  if (/%2f|%5c/i.test(url.pathname)) {
904
- throw errors.INVALID_URL_PATH('The URL path must not include encoded \\ or / characters')
1014
+ throw errors.INVALID_URL_PATH(
1015
+ 'The URL path must not include encoded \\ or / characters'
1016
+ )
905
1017
  }
906
1018
  } else {
907
1019
  if (/%2f/i.test(url.pathname)) {
908
- throw errors.INVALID_URL_PATH('The URL path must not include encoded / characters')
1020
+ throw errors.INVALID_URL_PATH(
1021
+ 'The URL path must not include encoded / characters'
1022
+ )
909
1023
  }
910
1024
  }
911
1025
 
912
1026
  return decodeURIComponent(url.pathname)
913
1027
  }
914
1028
 
915
- function urlToDirname (url) {
1029
+ function urlToDirname(url) {
916
1030
  if (url.protocol === 'file:') return path.dirname(fileURLToPath(url))
917
1031
 
918
1032
  if (isWindows) {
919
1033
  if (/%2f|%5c/i.test(url.pathname)) {
920
- throw errors.INVALID_URL_PATH('The URL path must not include encoded \\ or / characters')
1034
+ throw errors.INVALID_URL_PATH(
1035
+ 'The URL path must not include encoded \\ or / characters'
1036
+ )
921
1037
  }
922
1038
  } else {
923
1039
  if (/%2f/i.test(url.pathname)) {
924
- throw errors.INVALID_URL_PATH('The URL path must not include encoded / characters')
1040
+ throw errors.INVALID_URL_PATH(
1041
+ 'The URL path must not include encoded / characters'
1042
+ )
925
1043
  }
926
1044
  }
927
1045
 
928
- return decodeURIComponent((new URL('.', url)).pathname).replace(/\/$/, '')
1046
+ return decodeURIComponent(new URL('.', url).pathname).replace(/\/$/, '')
929
1047
  }