bare-module 3.0.8 → 3.0.10

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.
Files changed (3) hide show
  1. package/index.js +29 -13
  2. package/lib/errors.js +0 -4
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -8,6 +8,8 @@ const constants = require('./lib/constants')
8
8
  const errors = require('./lib/errors')
9
9
  const binding = require('./binding')
10
10
 
11
+ const { startsWithWindowsDriveLetter } = resolve
12
+
11
13
  const Module = module.exports = exports = class Module {
12
14
  constructor (url) {
13
15
  this._url = url
@@ -170,18 +172,18 @@ const Module = module.exports = exports = class Module {
170
172
 
171
173
  static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
172
174
 
173
- static _onimport (specifier, assertions, referrerURL, isDynamicImport) {
174
- const referrer = this._cache[referrerURL] || null
175
+ static _onimport (href, assertions, referrerHref, isDynamicImport) {
176
+ const referrer = this._cache[referrerHref] || null
175
177
 
176
178
  if (referrer === null) {
177
- let msg = `Cannot find referrer for module '${specifier}'`
179
+ let msg = `Cannot find referrer for module '${href}'`
178
180
 
179
- if (referrerURL) msg += ` imported from '${referrerURL}'`
181
+ if (referrerHref) msg += ` imported from '${referrerHref}'`
180
182
 
181
- throw errors.REFERRER_MISSING(msg)
183
+ throw errors.MODULE_NOT_FOUND(msg)
182
184
  }
183
185
 
184
- const url = this.resolve(specifier, referrer._url, {
186
+ const url = this.resolve(href, referrer._url, {
185
187
  isImport: true,
186
188
  referrer
187
189
  })
@@ -207,8 +209,12 @@ const Module = module.exports = exports = class Module {
207
209
  return module._handle
208
210
  }
209
211
 
210
- static _onevaluate (specifier) {
211
- const module = this._cache[specifier]
212
+ static _onevaluate (href) {
213
+ const module = this._cache[href] || null
214
+
215
+ if (module === null) {
216
+ throw errors.MODULE_NOT_FOUND(`Cannot find module '${href}'`)
217
+ }
212
218
 
213
219
  binding.setExport(module._handle, 'default', module._exports)
214
220
 
@@ -217,10 +223,14 @@ const Module = module.exports = exports = class Module {
217
223
  }
218
224
  }
219
225
 
220
- static _onmeta (specifier, meta) {
226
+ static _onmeta (href, meta) {
221
227
  const self = Module
222
228
 
223
- const module = this._cache[specifier]
229
+ const module = this._cache[href] || null
230
+
231
+ if (module === null) {
232
+ throw errors.MODULE_NOT_FOUND(`Cannot find module '${href}'`)
233
+ }
224
234
 
225
235
  const referrer = module
226
236
 
@@ -282,9 +292,9 @@ const Module = module.exports = exports = class Module {
282
292
  conditions = referrer ? referrer._conditions : self._conditions
283
293
  } = opts
284
294
 
285
- if (self._cache[url.href]) return self._cache[url.href]._transform(isImport, isDynamicImport)
295
+ if (cache[url.href]) return cache[url.href]._transform(isImport, isDynamicImport)
286
296
 
287
- const module = self._cache[url.href] = new Module(url)
297
+ const module = cache[url.href] = new Module(url)
288
298
 
289
299
  switch (url.protocol) {
290
300
  case 'builtin:':
@@ -406,7 +416,13 @@ exports.isBuiltin = function isBuiltin () {
406
416
  exports.createRequire = function createRequire (parentURL, opts = {}) {
407
417
  const self = Module
408
418
 
409
- if (typeof parentURL === 'string') parentURL = new URL(parentURL, 'file:')
419
+ if (typeof parentURL === 'string') {
420
+ if (startsWithWindowsDriveLetter(parentURL)) {
421
+ parentURL = '/' + parentURL
422
+ }
423
+
424
+ parentURL = new URL(parentURL, 'file:')
425
+ }
410
426
 
411
427
  let {
412
428
  referrer = null,
package/lib/errors.js CHANGED
@@ -23,8 +23,4 @@ module.exports = class ModuleError extends Error {
23
23
  static INVALID_BUNDLE_EXTENSION (msg) {
24
24
  return new ModuleError(msg, 'INVALID_BUNDLE_EXTENSION', ModuleError.INVALID_BUNDLE_EXTENSION)
25
25
  }
26
-
27
- static REFERRER_MISSING (msg) {
28
- return new ModuleError(msg, 'REFERRER_MISSING', ModuleError.REFERRER_MISSING)
29
- }
30
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "homepage": "https://github.com/holepunchto/bare-module#readme",
27
27
  "dependencies": {
28
28
  "bare-bundle": "^0.4.0",
29
- "bare-module-resolve": "^1.4.1",
29
+ "bare-module-resolve": "^1.4.4",
30
30
  "bare-path": "^2.0.0",
31
31
  "bare-url": "^0.3.4"
32
32
  },