-
Notifications
You must be signed in to change notification settings - Fork 62
Report actionable internal resolution errors #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
morgan-coded
wants to merge
3
commits into
arethetypeswrong:main
Choose a base branch
from
morgan-coded:fix/257-internal-resolution-diagnostic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@arethetypeswrong/core": patch | ||
| --- | ||
|
|
||
| Report actionable internal resolution errors. |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import assert from "node:assert"; | ||
| import { test } from "node:test"; | ||
| import type { | ||
| Analysis, | ||
| EntrypointResolutionAnalysis, | ||
| InternalResolutionErrorProblem, | ||
| ResolutionKind, | ||
| } from "@arethetypeswrong/core"; | ||
| import { typed } from "@arethetypeswrong/cli/internal/render"; | ||
|
|
||
| type StructuredInternalResolutionErrorProblem = InternalResolutionErrorProblem & { | ||
| entrypoint: string; | ||
| resolutionKind: ResolutionKind; | ||
| resolutionModeName: "esm" | "cjs"; | ||
| conditions?: string[]; | ||
| resolverMessage?: string; | ||
| }; | ||
|
|
||
| const trace = [ | ||
| "Resolving in ESM mode with conditions 'import', 'types', 'node'.", | ||
| "======== Module name './missing' was not resolved. ========", | ||
| ]; | ||
|
|
||
| const problem: StructuredInternalResolutionErrorProblem = { | ||
| kind: "InternalResolutionError", | ||
| entrypoint: ".", | ||
| resolutionKind: "node16-esm", | ||
| resolutionOption: "node16", | ||
| resolutionMode: 99 as InternalResolutionErrorProblem["resolutionMode"], | ||
| resolutionModeName: "esm", | ||
| fileName: "/node_modules/fixture/index.d.mts", | ||
| moduleSpecifier: "./missing", | ||
| conditions: ["import", "types", "node"], | ||
| resolverMessage: "Module name './missing' was not resolved.", | ||
| pos: 0, | ||
| end: 11, | ||
| trace, | ||
| }; | ||
|
|
||
| function resolution(resolutionKind: ResolutionKind, visibleProblems?: number[]): EntrypointResolutionAnalysis { | ||
| return { | ||
| name: "fixture", | ||
| resolutionKind, | ||
| visibleProblems, | ||
| }; | ||
| } | ||
|
|
||
| function analysis(problems: Analysis["problems"] = [problem]): Analysis { | ||
| return { | ||
| packageName: "fixture", | ||
| packageVersion: "1.0.0", | ||
| buildTools: {}, | ||
| types: { kind: "included" }, | ||
| entrypoints: { | ||
| ".": { | ||
| subpath: ".", | ||
| hasTypes: true, | ||
| isWildcard: false, | ||
| resolutions: { | ||
| node10: resolution("node10"), | ||
| "node16-cjs": resolution("node16-cjs"), | ||
| "node16-esm": resolution("node16-esm", problems.length ? [0] : undefined), | ||
| bundler: resolution("bundler"), | ||
| }, | ||
| }, | ||
| }, | ||
| programInfo: { | ||
| node10: {}, | ||
| node16: { moduleKinds: {} }, | ||
| bundler: {}, | ||
| }, | ||
| problems, | ||
| }; | ||
| } | ||
|
|
||
| test("typed renders actionable internal resolution diagnostics and verbose traces", async () => { | ||
| const concise = await typed(analysis(), { emoji: false, format: "ascii" }); | ||
| assert.match( | ||
| concise, | ||
| /'\.\/missing' failed to resolve using node16-esm from '\/node_modules\/fixture\/index\.d\.mts'/, | ||
| ); | ||
| assert.match(concise, /\n {2}'\.\/missing' failed to resolve using node16-esm/); | ||
| assert.doesNotMatch(concise, /for entrypoint/); | ||
| assert.doesNotMatch(concise, /with conditions/); | ||
| assert.doesNotMatch(concise, /from declaration/); | ||
| assert.doesNotMatch(concise, /Module name '\.\/missing' was not resolved/); | ||
| assert.doesNotMatch(concise, /Use -f json/); | ||
|
|
||
| const verbose = await typed(analysis(), { | ||
| emoji: false, | ||
| format: "ascii", | ||
| verbose: true, | ||
| }); | ||
| assert.match(verbose, /Internal resolution trace for '\.\/missing'/); | ||
| for (const line of trace) { | ||
| assert.ok(verbose.includes(line)); | ||
| } | ||
| }); | ||
|
|
||
| test("typed dedupes internal resolution diagnostics across entrypoints in the summary", async () => { | ||
| const duplicate: StructuredInternalResolutionErrorProblem = { ...problem, entrypoint: "./sub" }; | ||
| const concise = await typed(analysis([problem, duplicate]), { emoji: false, format: "ascii" }); | ||
| const matches = | ||
| concise.match(/'\.\/missing' failed to resolve using node16-esm from '\/node_modules\/fixture\/index\.d\.mts'/g) ?? | ||
| []; | ||
| assert.strictEqual(matches.length, 1); | ||
| }); | ||
|
|
||
| test("typed keeps table cells concise when summary is disabled", async () => { | ||
| const output = await typed(analysis(), { | ||
| emoji: false, | ||
| format: "ascii", | ||
| summary: false, | ||
| }); | ||
| assert.match(output, /Internal resolution error: '\.\/missing'/); | ||
| assert.doesNotMatch(output, /with conditions 'import', 'types', 'node'/); | ||
| assert.doesNotMatch(output, /from declaration '\/node_modules\/fixture\/index\.d\.mts'/); | ||
| }); | ||
|
|
||
| test("typed accepts verbose mode without internal resolution errors", async () => { | ||
| const output = await typed(analysis([]), { | ||
| emoji: false, | ||
| format: "ascii", | ||
| verbose: true, | ||
| }); | ||
| assert.doesNotMatch(output, /Internal resolution trace/); | ||
| }); | ||
|
|
||
| test("typed omits unavailable diagnostic parts for an unusual declaration path", async () => { | ||
| const incompleteProblem: StructuredInternalResolutionErrorProblem = { | ||
| ...problem, | ||
| fileName: "/", | ||
| conditions: undefined, | ||
| resolverMessage: undefined, | ||
| trace: [], | ||
| }; | ||
| const output = await typed(analysis([incompleteProblem]), { | ||
| emoji: false, | ||
| format: "ascii", | ||
| verbose: true, | ||
| }); | ||
| assert.match(output, /from '\/'/); | ||
| assert.doesNotMatch(output, /from declaration/); | ||
| assert.doesNotMatch(output, /undefined|Internal resolution trace/); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.