-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor diagnostics to be a set and apply output formatting
- Loading branch information
1 parent
61cc519
commit 86e04ac
Showing
2 changed files
with
9 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ import { isBuiltin } from 'node:module'; | |
const SUPPORTED_EXPORT_CONDITIONS = ['import', 'module-sync', 'default']; | ||
const IMPORT_MAP_RESOLVED_PREFIX = '/~'; | ||
const importMap = new Map(); | ||
// TODO make diagnostics a Map | ||
const diagnostics = {}; | ||
const diagnostics = new Map(); | ||
|
||
function updateImportMap(key, value, resolvedRoot) { | ||
importMap.set( | ||
|
@@ -25,7 +24,7 @@ function resolveBareSpecifier(specifier) { | |
try { | ||
resolvedPath = import.meta.resolve(specifier); | ||
} catch (e) { | ||
diagnostics[specifier] = `ERROR (${e.code}): unable to resolve specifier => \`${specifier}\` \n${e.message}`; | ||
diagnostics.set(specifier, `ERROR (${e.code}): unable to resolve specifier => \`${specifier}\`\n${e.message}\n`); | ||
} | ||
|
||
return resolvedPath; | ||
|
@@ -190,7 +189,7 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) { | |
|
||
if (!matched) { | ||
// ex. https://unpkg.com/browse/[email protected]/package.json | ||
diagnostics[dependency] = `no supported export conditions (\`${SUPPORTED_EXPORT_CONDITIONS.join(', ')}\`) for dependency => \`${dependency}\``; | ||
diagnostics.set(dependency, `no supported export conditions (\`${SUPPORTED_EXPORT_CONDITIONS.join(', ')}\`) for dependency => \`${dependency}\``); | ||
} | ||
} else { | ||
// handle (unconditional) subpath exports | ||
|
@@ -212,7 +211,7 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) { | |
updateImportMap(dependency, 'index.js', resolvedRoot); | ||
} else { | ||
// ex: https://unpkg.com/browse/[email protected]/package.json | ||
diagnostics[dependency] = `WARNING: No supported entry point detected for => \`${dependency}\``; | ||
diagnostics.set(dependency, `WARNING: No supported entry point detected for => \`${dependency}\``); | ||
} | ||
} | ||
|
||
|
@@ -244,7 +243,7 @@ async function walkPackageJson(packageJson = {}, walkedPackages = new Set()) { | |
// https://github.com/nodejs/node/issues/56652 | ||
// https://nodejs.org/api/modules.html#built-in-modules | ||
if (!isBuiltin(resolved)) { | ||
diagnostics[dependency] = `WARNING: No package.json resolved for => \`${dependency}\`, resolved to \`${resolved}\``; | ||
diagnostics.set(dependency, `WARNING: No package.json resolved for => \`${dependency}\`, resolved to \`${resolved}\``); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters