bare-module 3.0.8 → 3.0.9

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 +20 -12
  2. package/lib/errors.js +0 -4
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -170,18 +170,18 @@ const Module = module.exports = exports = class Module {
170
170
 
171
171
  static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
172
172
 
173
- static _onimport (specifier, assertions, referrerURL, isDynamicImport) {
174
- const referrer = this._cache[referrerURL] || null
173
+ static _onimport (href, assertions, referrerHref, isDynamicImport) {
174
+ const referrer = this._cache[referrerHref] || null
175
175
 
176
176
  if (referrer === null) {
177
- let msg = `Cannot find referrer for module '${specifier}'`
177
+ let msg = `Cannot find referrer for module '${href}'`
178
178
 
179
- if (referrerURL) msg += ` imported from '${referrerURL}'`
179
+ if (referrerHref) msg += ` imported from '${referrerHref}'`
180
180
 
181
- throw errors.REFERRER_MISSING(msg)
181
+ throw errors.MODULE_NOT_FOUND(msg)
182
182
  }
183
183
 
184
- const url = this.resolve(specifier, referrer._url, {
184
+ const url = this.resolve(href, referrer._url, {
185
185
  isImport: true,
186
186
  referrer
187
187
  })
@@ -207,8 +207,12 @@ const Module = module.exports = exports = class Module {
207
207
  return module._handle
208
208
  }
209
209
 
210
- static _onevaluate (specifier) {
211
- const module = this._cache[specifier]
210
+ static _onevaluate (href) {
211
+ const module = this._cache[href] || null
212
+
213
+ if (module === null) {
214
+ throw errors.MODULE_NOT_FOUND(`Cannot find module '${href}'`)
215
+ }
212
216
 
213
217
  binding.setExport(module._handle, 'default', module._exports)
214
218
 
@@ -217,10 +221,14 @@ const Module = module.exports = exports = class Module {
217
221
  }
218
222
  }
219
223
 
220
- static _onmeta (specifier, meta) {
224
+ static _onmeta (href, meta) {
221
225
  const self = Module
222
226
 
223
- const module = this._cache[specifier]
227
+ const module = this._cache[href] || null
228
+
229
+ if (module === null) {
230
+ throw errors.MODULE_NOT_FOUND(`Cannot find module '${href}'`)
231
+ }
224
232
 
225
233
  const referrer = module
226
234
 
@@ -282,9 +290,9 @@ const Module = module.exports = exports = class Module {
282
290
  conditions = referrer ? referrer._conditions : self._conditions
283
291
  } = opts
284
292
 
285
- if (self._cache[url.href]) return self._cache[url.href]._transform(isImport, isDynamicImport)
293
+ if (cache[url.href]) return cache[url.href]._transform(isImport, isDynamicImport)
286
294
 
287
- const module = self._cache[url.href] = new Module(url)
295
+ const module = cache[url.href] = new Module(url)
288
296
 
289
297
  switch (url.protocol) {
290
298
  case 'builtin:':
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.9",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [