bare-module 2.5.0 → 2.5.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 +36 -42
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const Module = module.exports = exports = class Module {
|
|
|
16
16
|
this._main = null
|
|
17
17
|
this._exports = null
|
|
18
18
|
this._imports = null
|
|
19
|
+
this._builtins = null
|
|
19
20
|
this._info = null
|
|
20
21
|
this._protocol = null
|
|
21
22
|
this._handle = null
|
|
@@ -100,16 +101,13 @@ const Module = module.exports = exports = class Module {
|
|
|
100
101
|
static _onimport (specifier, assertions, referrerFilename, dynamic) {
|
|
101
102
|
const referrer = this._cache[referrerFilename]
|
|
102
103
|
|
|
103
|
-
let protocol
|
|
104
|
+
let protocol
|
|
104
105
|
|
|
105
106
|
if (referrer) {
|
|
106
107
|
protocol = this._protocolFor(specifier, referrer._protocol)
|
|
107
108
|
|
|
108
|
-
imports = referrer._imports
|
|
109
|
-
|
|
110
109
|
specifier = this.resolve(specifier, path.dirname(referrer._filename), {
|
|
111
110
|
protocol,
|
|
112
|
-
imports,
|
|
113
111
|
referrer
|
|
114
112
|
})
|
|
115
113
|
} else {
|
|
@@ -129,7 +127,6 @@ const Module = module.exports = exports = class Module {
|
|
|
129
127
|
|
|
130
128
|
const module = this.load(specifier, {
|
|
131
129
|
protocol: this._protocolFor(specifier, protocol),
|
|
132
|
-
imports,
|
|
133
130
|
referrer,
|
|
134
131
|
dynamic,
|
|
135
132
|
type
|
|
@@ -185,6 +182,7 @@ const Module = module.exports = exports = class Module {
|
|
|
185
182
|
static createRequire (filename, opts = {}) {
|
|
186
183
|
const {
|
|
187
184
|
imports = null,
|
|
185
|
+
builtins = null,
|
|
188
186
|
protocol = this._protocolFor(filename, this._protocols['file:']),
|
|
189
187
|
type = constants.types.SCRIPT,
|
|
190
188
|
defaultType = constants.types.SCRIPT
|
|
@@ -195,6 +193,7 @@ const Module = module.exports = exports = class Module {
|
|
|
195
193
|
module._type = type
|
|
196
194
|
module._defaultType = defaultType
|
|
197
195
|
module._imports = imports
|
|
196
|
+
module._builtins = builtins
|
|
198
197
|
module._protocol = protocol
|
|
199
198
|
|
|
200
199
|
const referrer = module
|
|
@@ -203,7 +202,6 @@ const Module = module.exports = exports = class Module {
|
|
|
203
202
|
const resolve = (specifier) => {
|
|
204
203
|
return this.resolve(specifier, dirname, {
|
|
205
204
|
protocol: this._protocolFor(specifier, protocol),
|
|
206
|
-
imports,
|
|
207
205
|
referrer
|
|
208
206
|
})
|
|
209
207
|
}
|
|
@@ -211,7 +209,6 @@ const Module = module.exports = exports = class Module {
|
|
|
211
209
|
const require = (specifier) => {
|
|
212
210
|
const module = this.load(resolve(specifier), {
|
|
213
211
|
protocol: this._protocolFor(specifier, protocol),
|
|
214
|
-
imports,
|
|
215
212
|
referrer
|
|
216
213
|
})
|
|
217
214
|
|
|
@@ -239,14 +236,14 @@ const Module = module.exports = exports = class Module {
|
|
|
239
236
|
}
|
|
240
237
|
|
|
241
238
|
let {
|
|
242
|
-
referrer = null,
|
|
243
|
-
protocol = this._protocolFor(specifier, this._protocols['file:']),
|
|
244
|
-
imports = null,
|
|
245
|
-
builtins = null,
|
|
246
239
|
dynamic = false,
|
|
240
|
+
referrer = null,
|
|
241
|
+
protocol = this._protocolFor(specifier, referrer ? referrer._protocol : this._protocols['file:']),
|
|
242
|
+
imports = referrer ? referrer._imports : null,
|
|
243
|
+
builtins = referrer ? referrer._builtins : null,
|
|
247
244
|
main = referrer ? referrer._main : null,
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
defaultType = referrer ? referrer._defaultType : 0,
|
|
246
|
+
type = 0
|
|
250
247
|
} = opts
|
|
251
248
|
|
|
252
249
|
if (this._cache[specifier]) return this._transform(this._cache[specifier], referrer, dynamic)
|
|
@@ -274,8 +271,11 @@ const Module = module.exports = exports = class Module {
|
|
|
274
271
|
if (builtins && specifier in builtins) {
|
|
275
272
|
module._exports = builtins[specifier]
|
|
276
273
|
} else {
|
|
277
|
-
module._defaultType = defaultType
|
|
278
274
|
module._main = main || module
|
|
275
|
+
module._defaultType = defaultType
|
|
276
|
+
module._protocol = protocol
|
|
277
|
+
module._imports = imports
|
|
278
|
+
module._builtins = builtins
|
|
279
279
|
module._info = this._loadPackageManifest(path.dirname(module._filename), protocol)
|
|
280
280
|
|
|
281
281
|
let extension = this._extensionFor(type) || path.extname(specifier)
|
|
@@ -289,7 +289,7 @@ const Module = module.exports = exports = class Module {
|
|
|
289
289
|
throw errors.INVALID_BUNDLE_EXTENSION(`Invalid extension for bundle '${specifier}'`)
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
this._extensions[extension].call(this, module, source, referrer
|
|
292
|
+
this._extensions[extension].call(this, module, source, referrer)
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
return this._transform(module, referrer, dynamic)
|
|
@@ -326,9 +326,9 @@ const Module = module.exports = exports = class Module {
|
|
|
326
326
|
|
|
327
327
|
let {
|
|
328
328
|
referrer = null,
|
|
329
|
-
protocol = this._protocols['file:'],
|
|
330
|
-
imports = null,
|
|
331
|
-
builtins = null,
|
|
329
|
+
protocol = referrer ? referrer._protocol : this._protocols['file:'],
|
|
330
|
+
imports = referrer ? referrer._imports : null,
|
|
331
|
+
builtins = referrer ? referrer._builtins : null,
|
|
332
332
|
conditions = ['import', 'require', 'bare', 'node']
|
|
333
333
|
} = opts
|
|
334
334
|
|
|
@@ -644,7 +644,7 @@ const Module = module.exports = exports = class Module {
|
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
Module._extensions['.js'] = function (module, source, referrer
|
|
647
|
+
Module._extensions['.js'] = function (module, source, referrer) {
|
|
648
648
|
const isESM = (
|
|
649
649
|
// The default type is ES modules.
|
|
650
650
|
(module._defaultType === constants.types.MODULE) ||
|
|
@@ -653,18 +653,18 @@ Module._extensions['.js'] = function (module, source, referrer, protocol, import
|
|
|
653
653
|
(module._info && module._info.type === 'module') ||
|
|
654
654
|
|
|
655
655
|
// The source is a data: URI and the referrer is itself an ES module.
|
|
656
|
-
(
|
|
656
|
+
(module._protocol === this._protocols['data:'] && referrer && referrer._type === constants.types.MODULE)
|
|
657
657
|
)
|
|
658
658
|
|
|
659
659
|
const loader = this._extensions[isESM ? '.mjs' : '.cjs']
|
|
660
660
|
|
|
661
|
-
return loader.call(this, module, source, referrer
|
|
661
|
+
return loader.call(this, module, source, referrer)
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
Module._extensions['.cjs'] = function (module, source, referrer
|
|
664
|
+
Module._extensions['.cjs'] = function (module, source, referrer) {
|
|
665
|
+
const protocol = module._protocol
|
|
666
|
+
|
|
665
667
|
module._type = constants.types.SCRIPT
|
|
666
|
-
module._protocol = protocol
|
|
667
|
-
module._imports = imports
|
|
668
668
|
|
|
669
669
|
if (protocol.load) {
|
|
670
670
|
module._exports = protocol.load(module._filename)
|
|
@@ -680,7 +680,6 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
680
680
|
const resolve = (specifier) => {
|
|
681
681
|
return this.resolve(specifier, dirname, {
|
|
682
682
|
protocol: this._protocolFor(specifier, protocol),
|
|
683
|
-
imports,
|
|
684
683
|
referrer
|
|
685
684
|
})
|
|
686
685
|
}
|
|
@@ -688,7 +687,6 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
688
687
|
const require = (specifier) => {
|
|
689
688
|
const module = this.load(resolve(specifier), {
|
|
690
689
|
protocol: this._protocolFor(specifier, protocol),
|
|
691
|
-
imports,
|
|
692
690
|
referrer
|
|
693
691
|
})
|
|
694
692
|
|
|
@@ -718,10 +716,10 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
718
716
|
}
|
|
719
717
|
}
|
|
720
718
|
|
|
721
|
-
Module._extensions['.mjs'] = function (module, source, referrer
|
|
719
|
+
Module._extensions['.mjs'] = function (module, source, referrer) {
|
|
720
|
+
const protocol = module._protocol
|
|
721
|
+
|
|
722
722
|
module._type = constants.types.MODULE
|
|
723
|
-
module._protocol = protocol
|
|
724
|
-
module._imports = imports
|
|
725
723
|
|
|
726
724
|
if (protocol.load) {
|
|
727
725
|
module._exports = protocol.load(module._filename)
|
|
@@ -734,10 +732,10 @@ Module._extensions['.mjs'] = function (module, source, referrer, protocol, impor
|
|
|
734
732
|
}
|
|
735
733
|
}
|
|
736
734
|
|
|
737
|
-
Module._extensions['.json'] = function (module, source, referrer
|
|
735
|
+
Module._extensions['.json'] = function (module, source, referrer) {
|
|
736
|
+
const protocol = module._protocol
|
|
737
|
+
|
|
738
738
|
module._type = constants.types.JSON
|
|
739
|
-
module._protocol = protocol
|
|
740
|
-
module._imports = imports
|
|
741
739
|
|
|
742
740
|
if (protocol.load) {
|
|
743
741
|
module._exports = protocol.load(module._filename)
|
|
@@ -750,26 +748,22 @@ Module._extensions['.json'] = function (module, source, referrer, protocol, impo
|
|
|
750
748
|
}
|
|
751
749
|
}
|
|
752
750
|
|
|
753
|
-
Module._extensions['.bare'] = function (module, source, referrer
|
|
751
|
+
Module._extensions['.bare'] = function (module, source, referrer) {
|
|
754
752
|
module._type = constants.types.ADDON
|
|
755
|
-
module._protocol = protocol
|
|
756
|
-
module._imports = imports
|
|
757
753
|
|
|
758
754
|
module._exports = Bare.Addon.load(module._filename)
|
|
759
755
|
}
|
|
760
756
|
|
|
761
|
-
Module._extensions['.node'] = function (module, source, referrer
|
|
757
|
+
Module._extensions['.node'] = function (module, source, referrer) {
|
|
762
758
|
module._type = constants.types.ADDON
|
|
763
|
-
module._protocol = protocol
|
|
764
|
-
module._imports = imports
|
|
765
759
|
|
|
766
760
|
module._exports = Bare.Addon.load(module._filename)
|
|
767
761
|
}
|
|
768
762
|
|
|
769
|
-
Module._extensions['.bundle'] = function (module, source, referrer
|
|
763
|
+
Module._extensions['.bundle'] = function (module, source, referrer) {
|
|
764
|
+
const protocol = module._protocol
|
|
765
|
+
|
|
770
766
|
module._type = constants.types.BUNDLE
|
|
771
|
-
module._protocol = protocol
|
|
772
|
-
module._imports = imports
|
|
773
767
|
|
|
774
768
|
if (source === null) source = protocol.read(module._filename)
|
|
775
769
|
|
|
@@ -777,7 +771,7 @@ Module._extensions['.bundle'] = function (module, source, referrer, protocol, im
|
|
|
777
771
|
|
|
778
772
|
const bundle = this._bundleFor(module._filename, protocol, source)
|
|
779
773
|
|
|
780
|
-
module._exports = this.load(bundle.main, bundle.read(bundle.main), { protocol,
|
|
774
|
+
module._exports = this.load(bundle.main, bundle.read(bundle.main), { protocol, referrer })._exports
|
|
781
775
|
}
|
|
782
776
|
|
|
783
777
|
Module._protocols['file:'] = new Protocol({
|