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 +24 -14
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/errors.js +6 -2
- package/package.json +1 -1
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.
|
|
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(
|
|
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
|
-
|
|
530
|
-
|
|
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)) {
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
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
|
-
|
|
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) {
|