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 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
@@ -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
- if (cache[url.href]) return cache[url.href]._transform(isImport, isDynamicImport)
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
- const module = cache[url.href] = new Module(url)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [