bare-module 4.8.3 → 4.8.5

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/index.js CHANGED
@@ -114,14 +114,9 @@ module.exports = exports = class Module {
114
114
  Module._modules.delete(this)
115
115
  }
116
116
 
117
- _run() {
118
- binding.runModule(this._handle, Module._handle, Module._onrun)
119
- }
120
-
121
117
  _transform(isImport, isDynamicImport) {
122
118
  if (isDynamicImport) {
123
- this._synthesize()
124
- this._evaluate(true /* eagerRun */)
119
+ this._run()
125
120
  } else if (isImport) {
126
121
  this._synthesize()
127
122
  } else {
@@ -205,7 +200,7 @@ module.exports = exports = class Module {
205
200
  )
206
201
  }
207
202
 
208
- _evaluate(eagerRun = false) {
203
+ _evaluate() {
209
204
  if ((this._state & constants.states.EVALUATED) !== 0) return
210
205
 
211
206
  this._state |= constants.states.EVALUATED
@@ -224,17 +219,23 @@ module.exports = exports = class Module {
224
219
  urlToPath(this._url),
225
220
  urlToDirname(this._url)
226
221
  )
227
-
228
- if (eagerRun) this._run()
229
222
  } else if (this._type === constants.types.MODULE) {
230
223
  this._run()
231
224
 
232
225
  this._exports = binding.getNamespace(this._handle)
233
- } else if (eagerRun) {
234
- this._run()
235
226
  }
236
227
  }
237
228
 
229
+ _run() {
230
+ if ((this._state & constants.states.RUN) !== 0) return
231
+
232
+ this._state |= constants.states.RUN
233
+
234
+ this._synthesize()
235
+
236
+ binding.runModule(this._handle, Module._handle, Module._onrun)
237
+ }
238
+
238
239
  [Symbol.for('bare.inspect')]() {
239
240
  return {
240
241
  __proto__: { constructor: Module },
@@ -501,6 +502,8 @@ module.exports = exports = class Module {
501
502
 
502
503
  if (resolution) return protocol.postresolve(resolution)
503
504
 
505
+ const candidates = []
506
+
504
507
  for (const resolution of resolve(
505
508
  resolved,
506
509
  parentURL,
@@ -516,6 +519,8 @@ module.exports = exports = class Module {
516
519
  },
517
520
  readPackage
518
521
  )) {
522
+ candidates.push(resolution)
523
+
519
524
  switch (resolution.protocol) {
520
525
  case 'builtin:':
521
526
  return resolution
@@ -526,9 +531,14 @@ module.exports = exports = class Module {
526
531
  }
527
532
  }
528
533
 
529
- throw errors.MODULE_NOT_FOUND(
530
- `Cannot find module '${specifier}' imported from '${parentURL.href}'`
531
- )
534
+ let message = `Cannot find module '${specifier}' imported from '${parentURL.href}`
535
+
536
+ if (candidates.length > 0) {
537
+ message += '\nCandidates:'
538
+ message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
539
+ }
540
+
541
+ throw errors.MODULE_NOT_FOUND(message, candidates)
532
542
 
533
543
  function readPackage(packageURL) {
534
544
  if (protocol.exists(packageURL, constants.types.JSON)) {
@@ -2,6 +2,7 @@ declare const constants: {
2
2
  states: {
3
3
  EVALUATED: number
4
4
  SYNTHESIZED: number
5
+ RUN: number
5
6
  DESTROYED: number
6
7
  }
7
8
  types: {
package/lib/constants.js CHANGED
@@ -2,7 +2,8 @@ module.exports = {
2
2
  states: {
3
3
  EVALUATED: 1,
4
4
  SYNTHESIZED: 2,
5
- DESTROYED: 4
5
+ RUN: 4,
6
+ DESTROYED: 8
6
7
  },
7
8
 
8
9
  types: {
package/lib/errors.js CHANGED
@@ -12,12 +12,16 @@ module.exports = class ModuleError extends Error {
12
12
  return 'ModuleError'
13
13
  }
14
14
 
15
- static MODULE_NOT_FOUND(msg) {
16
- return new ModuleError(
15
+ static MODULE_NOT_FOUND(msg, candidates = []) {
16
+ const err = new ModuleError(
17
17
  msg,
18
18
  'MODULE_NOT_FOUND',
19
19
  ModuleError.MODULE_NOT_FOUND
20
20
  )
21
+
22
+ err.candidates = candidates
23
+
24
+ return err
21
25
  }
22
26
 
23
27
  static ASSET_NOT_FOUND(msg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "4.8.3",
3
+ "version": "4.8.5",
4
4
  "description": "Module support for JavaScript",
5
5
  "exports": {
6
6
  ".": {