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 CHANGED
@@ -199,6 +199,8 @@ Constant | Description
199
199
  `JSON` |
200
200
  `BUNDLE` |
201
201
  `ADDON` |
202
+ `BINARY` |
203
+ `TEXT` |
202
204
 
203
205
  #### `Module.protocol`
204
206
 
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
- if (cache[url.href]) return cache[url.href]._transform(isImport, isDynamicImport)
377
+ let module = cache[url.href] || null
378
378
 
379
- const module = cache[url.href] = new Module(url)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [