bare-module 3.2.2 → 4.0.0

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
@@ -197,6 +197,8 @@ Constant | Description
197
197
  `BUNDLE` |
198
198
  `ADDON` |
199
199
 
200
+ #### `Module.protocol`
201
+
200
202
  #### `Module.cache`
201
203
 
202
204
  #### `const url = Module.resolve(specifier, parentURL[, options])`
package/index.js CHANGED
@@ -234,7 +234,7 @@ const Module = module.exports = exports = class Module {
234
234
  }
235
235
 
236
236
  static _extensions = Object.create(null)
237
- static _protocols = Object.create(null)
237
+ static _protocol = null
238
238
  static _cache = module.cache || Object.create(null)
239
239
  static _modules = new Set()
240
240
  static _conditions = ['bare', 'node']
@@ -353,9 +353,9 @@ const Module = module.exports = exports = class Module {
353
353
  }
354
354
  }
355
355
 
356
- static Protocol = Protocol
357
- static Bundle = Bundle
358
- static constants = constants
356
+ static get protocol () {
357
+ return this._protocol
358
+ }
359
359
 
360
360
  static get cache () {
361
361
  return this._cache
@@ -378,7 +378,7 @@ const Module = module.exports = exports = class Module {
378
378
  defaultType = referrer ? referrer._defaultType : 0,
379
379
  cache = referrer ? referrer._cache : self._cache,
380
380
  main = referrer ? referrer._main : null,
381
- protocol = referrer ? referrer._protocol : self._protocols['file:'],
381
+ protocol = referrer ? referrer._protocol : self._protocol,
382
382
  imports = referrer ? referrer._imports : null,
383
383
  resolutions = referrer ? referrer._resolutions : null,
384
384
  builtins = referrer ? referrer._builtins : null,
@@ -435,7 +435,7 @@ const Module = module.exports = exports = class Module {
435
435
  isImport = false,
436
436
 
437
437
  referrer = null,
438
- protocol = referrer ? referrer._protocol : self._protocols['file:'],
438
+ protocol = referrer ? referrer._protocol : self._protocol,
439
439
  imports = referrer ? referrer._imports : null,
440
440
  resolutions = referrer ? referrer._resolutions : null,
441
441
  builtins = referrer ? referrer._builtins : null,
@@ -507,6 +507,11 @@ const Module = module.exports = exports = class Module {
507
507
  }
508
508
  }
509
509
 
510
+ exports.Protocol = Protocol
511
+ exports.Bundle = Bundle
512
+
513
+ exports.constants = constants
514
+
510
515
  // For Node.js compatibility
511
516
  exports.builtinModules = []
512
517
 
@@ -534,7 +539,7 @@ const createRequire = exports.createRequire = function createRequire (parentURL,
534
539
  defaultType = referrer ? referrer._defaultType : constants.types.SCRIPT,
535
540
  cache = referrer ? referrer._cache : self._cache,
536
541
  main = referrer ? referrer._main : null,
537
- protocol = referrer ? referrer._protocol : self._protocols['file:'],
542
+ protocol = referrer ? referrer._protocol : self._protocol,
538
543
  imports = referrer ? referrer._imports : null,
539
544
  resolutions = referrer ? referrer._resolutions : null,
540
545
  builtins = referrer ? referrer._builtins : null,
@@ -724,17 +729,32 @@ Module._extensions['.bundle'] = function (module, source, referrer) {
724
729
  }
725
730
  }
726
731
 
727
- Module._protocols['file:'] = new Protocol({
732
+ Module._protocol = new Protocol({
728
733
  postresolve (url) {
729
- return pathToFileURL(binding.realpath(fileURLToPath(url)))
734
+ switch (url.protocol) {
735
+ case 'file:':
736
+ return pathToFileURL(binding.realpath(fileURLToPath(url)))
737
+ default:
738
+ return url
739
+ }
730
740
  },
731
741
 
732
742
  exists (url) {
733
- return binding.exists(fileURLToPath(url))
743
+ switch (url.protocol) {
744
+ case 'file:':
745
+ return binding.exists(fileURLToPath(url))
746
+ default:
747
+ return false
748
+ }
734
749
  },
735
750
 
736
751
  read (url) {
737
- return Buffer.from(binding.read(fileURLToPath(url)))
752
+ switch (url.protocol) {
753
+ case 'file:':
754
+ return Buffer.from(binding.read(fileURLToPath(url)))
755
+ default:
756
+ throw errors.UNKNOWN_PROTOCOL(`Cannot load module '${url.href}'`)
757
+ }
738
758
  }
739
759
  })
740
760
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "3.2.2",
3
+ "version": "4.0.0",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "bare-bundle": "^1.0.0",
30
30
  "bare-module-resolve": "^1.6.0",
31
- "bare-path": "^2.0.0",
31
+ "bare-path": "^3.0.0",
32
32
  "cjs-module-lexer": "^1.2.3",
33
33
  "url-file-url": "^1.0.2"
34
34
  },