bare-module 4.6.0 → 4.6.2
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 +2 -0
- package/index.js +33 -2
- package/lib/errors.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -32,6 +32,8 @@ const Module = module.exports = exports = class Module {
|
|
|
32
32
|
this._names = null
|
|
33
33
|
this._handle = null
|
|
34
34
|
|
|
35
|
+
Object.preventExtensions(this)
|
|
36
|
+
|
|
35
37
|
Module._modules.add(this)
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -374,9 +376,17 @@ const Module = module.exports = exports = class Module {
|
|
|
374
376
|
conditions = referrer ? referrer._conditions : self._conditions
|
|
375
377
|
} = opts
|
|
376
378
|
|
|
377
|
-
|
|
379
|
+
let module = cache[url.href] || null
|
|
380
|
+
|
|
381
|
+
if (module !== null) {
|
|
382
|
+
if (type !== 0 && type !== module._type) {
|
|
383
|
+
throw errors.TYPE_INCOMPATIBLE(`Module '${module.url.href}' is not of type '${nameOfType(type)}'`)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return module._transform(isImport, isDynamicImport)
|
|
387
|
+
}
|
|
378
388
|
|
|
379
|
-
|
|
389
|
+
module = cache[url.href] = new Module(url)
|
|
380
390
|
|
|
381
391
|
try {
|
|
382
392
|
switch (url.protocol) {
|
|
@@ -563,6 +573,27 @@ function canonicalExtensionForType (type) {
|
|
|
563
573
|
}
|
|
564
574
|
}
|
|
565
575
|
|
|
576
|
+
function nameOfType (type) {
|
|
577
|
+
switch (type) {
|
|
578
|
+
case constants.types.SCRIPT:
|
|
579
|
+
return 'script'
|
|
580
|
+
case constants.types.MODULE:
|
|
581
|
+
return 'module'
|
|
582
|
+
case constants.types.JSON:
|
|
583
|
+
return 'json'
|
|
584
|
+
case constants.types.BUNDLE:
|
|
585
|
+
return 'bundle'
|
|
586
|
+
case constants.types.ADDON:
|
|
587
|
+
return 'bare'
|
|
588
|
+
case constants.types.BINARY:
|
|
589
|
+
return 'binary'
|
|
590
|
+
case constants.types.TEXT:
|
|
591
|
+
return 'text'
|
|
592
|
+
default:
|
|
593
|
+
return null
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
566
597
|
function typeForAttributes (attributes) {
|
|
567
598
|
if (typeof attributes !== 'object' || attributes === null) return 0
|
|
568
599
|
|
package/lib/errors.js
CHANGED
|
@@ -31,4 +31,8 @@ module.exports = class ModuleError extends Error {
|
|
|
31
31
|
static INVALID_URL_PATH (msg) {
|
|
32
32
|
return new ModuleError(msg, 'INVALID_URL_PATH', ModuleError.INVALID_URL_PATH)
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
static TYPE_INCOMPATIBLE (msg) {
|
|
36
|
+
return new ModuleError(msg, 'TYPE_INCOMPATIBLE', ModuleError.TYPE_INCOMPATIBLE)
|
|
37
|
+
}
|
|
34
38
|
}
|