Skip to content

Commit b996a66

Browse files
l0lawrenceCopilot
andcommitted
Make diff2html import resilient to aggregate typecheck
Use a non-literal import specifier + local type so a typecheck that doesn't install this package's deps (e.g. the parent repo's check:eng, which includes core/eng) doesn't fail with TS2307; availability is validated at runtime. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 244f134 commit b996a66

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

eng/emitter-diff/src/diff.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,22 @@ export function writePatch(diff: DiffResult, outFile: string, log: Logger): void
125125
* optional dependency loaded lazily so the core runs without it installed.
126126
*/
127127
export async function writeHtml(diff: DiffResult, outFile: string, log: Logger): Promise<void> {
128-
let html: (typeof import("diff2html"))["html"];
128+
// diff2html is an optional dependency, loaded lazily. Use a non-literal
129+
// specifier and a local type so an aggregate typecheck that doesn't install
130+
// this package's deps (e.g. the parent repo's `check:eng`, which includes
131+
// `core/eng`) doesn't fail to resolve it — we validate availability at runtime.
132+
type Diff2Html = { html(patch: string, options: Record<string, unknown>): string };
133+
const specifier: string = "diff2html";
134+
let mod: Diff2Html;
129135
try {
130-
({ html } = await import("diff2html"));
136+
mod = (await import(specifier)) as unknown as Diff2Html;
131137
} catch {
132138
throw new Error(
133139
"Rendering --html requires the 'diff2html' package. Install it in eng/emitter-diff " +
134140
"(it is declared as a dependency) or run with `pnpm` so it is available.",
135141
);
136142
}
137-
const body = html(diff.patch, {
143+
const body = mod.html(diff.patch, {
138144
drawFileList: true,
139145
matching: "lines",
140146
outputFormat: "side-by-side",

0 commit comments

Comments
 (0)