Skip to content
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

fix(typescript): resolve the shim used for tsc in Typescript v5.7 and up #252

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update runTsc.ts
johnsoncodehk committed Dec 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit bf2377ab314ce5ef7faa7a476ec2bcad46fede2a
9 changes: 2 additions & 7 deletions packages/typescript/lib/quickstart/runTsc.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export function runTsc(
) {
getLanguagePlugins = _getLanguagePlugins;

const proxyApiPath = path.resolve(__dirname, '../node/proxyCreateProgram');
const proxyApiPath = require.resolve('../node/proxyCreateProgram');
const readFileSync = fs.readFileSync;

(fs as any).readFileSync = (...args: any[]) => {
@@ -31,12 +31,7 @@ export function runTsc(
const requireRegex = /module\.exports\s*=\s*require\((?:"|')(?<path>\.\/\w+\.js)(?:"|')\)/;
const requirePath = requireRegex.exec(tsc)?.groups?.path;
if (requirePath) {
const tscContent: string = (readFileSync as any)(path.join(path.dirname(tscPath), requirePath))?.toString?.() ?? '';
if (isMainTsc(tscContent)) {
tsc = tscContent;
} else {
throw new Error('Failed to find resolve main tsc module from shim');
}
tsc = readFileSync(path.join(path.dirname(tscPath), requirePath), 'utf8');
} else {
throw new Error('Failed to locate tsc module path from shim');
}