Skip to content

Commit b359d99

Browse files
committed
fix(typescript): compatible runTsc() for fixupImpliedNodeFormatForFile
1 parent 555cb62 commit b359d99

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/typescript/lib/node/utils.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ export function fixupImpliedNodeFormatForFile(
4747
return;
4848
}
4949
// https://github.com/microsoft/TypeScript/blob/669c25c091ad4d32298d0f33b0e4e681d46de3ea/src/compiler/program.ts#L1354
50-
const validExts = [ts.Extension.Dts, ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Js, ts.Extension.Jsx];
50+
const validExts = ['.d.ts', '.ts', '.tsx', '.js', '.jsx'];
5151
if (validExts.some(ext => sourceFile.fileName.endsWith(ext))) {
5252
return;
5353
}
54-
const asTs = sourceFile.fileName + ts.Extension.Ts;
55-
sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile?.(asTs, packageJsonInfoCache, host, options);
54+
const asTs = sourceFile.fileName + '.ts';
55+
// Use getImpliedNodeFormatForFileWroker instead of getImpliedNodeFormatForFile for runTsc() compatibility
56+
const impliedNodeFormat = (ts as any).getImpliedNodeFormatForFileWroker?.(
57+
asTs,
58+
packageJsonInfoCache,
59+
host,
60+
options,
61+
)?.impliedNodeFormat;
62+
if (impliedNodeFormat === undefined) {
63+
return;
64+
}
65+
sourceFile.impliedNodeFormat = impliedNodeFormat;
5666
return () => sourceFile.impliedNodeFormat = undefined;
5767
}

0 commit comments

Comments
 (0)