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