bare-module 4.8.3 → 4.8.4
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 +12 -3
- package/lib/errors.js +6 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -501,6 +501,8 @@ module.exports = exports = class Module {
|
|
|
501
501
|
|
|
502
502
|
if (resolution) return protocol.postresolve(resolution)
|
|
503
503
|
|
|
504
|
+
const candidates = []
|
|
505
|
+
|
|
504
506
|
for (const resolution of resolve(
|
|
505
507
|
resolved,
|
|
506
508
|
parentURL,
|
|
@@ -516,6 +518,8 @@ module.exports = exports = class Module {
|
|
|
516
518
|
},
|
|
517
519
|
readPackage
|
|
518
520
|
)) {
|
|
521
|
+
candidates.push(resolution)
|
|
522
|
+
|
|
519
523
|
switch (resolution.protocol) {
|
|
520
524
|
case 'builtin:':
|
|
521
525
|
return resolution
|
|
@@ -526,9 +530,14 @@ module.exports = exports = class Module {
|
|
|
526
530
|
}
|
|
527
531
|
}
|
|
528
532
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
)
|
|
533
|
+
let message = `Cannot find module '${specifier}' imported from '${parentURL.href}`
|
|
534
|
+
|
|
535
|
+
if (candidates.length > 0) {
|
|
536
|
+
message += '\nCandidates:'
|
|
537
|
+
message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
throw errors.MODULE_NOT_FOUND(message, candidates)
|
|
532
541
|
|
|
533
542
|
function readPackage(packageURL) {
|
|
534
543
|
if (protocol.exists(packageURL, constants.types.JSON)) {
|
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) {
|