diff --git a/integration-tests/typescript-versions.test.js b/integration-tests/typescript-versions.test.js index 885e9f7..059016e 100644 --- a/integration-tests/typescript-versions.test.js +++ b/integration-tests/typescript-versions.test.js @@ -115,6 +115,29 @@ describe.each(TS_VERSIONS)('with typescript@%s', (version) => { INSTALL_AND_BUILD_TIMEOUT, ); + it( + 'should build a .ts file when tsconfig.json is present in the CWD but no --tsconfig flag is passed (TS5112 regression)', + async () => { + // TS 7 errors with TS5112 when a file is passed on the CLI and an ambient + // tsconfig.json exists in the CWD. --ignoreConfig suppresses it; this test + // locks the exact invocation so the flag cannot be silently dropped. + expect.assertions(2); + const { execute, cleanup, writeFile } = await setup(); + await writeFile('input.ts', VALID_TS); + await writeFile('tsconfig.json', JSON.stringify({ compilerOptions: { strict: true } })); + + const { code, stdout } = await execute( + 'node', + './bin/fastedge-build.js input.ts dist/output.wasm', + ); + + expect(code).toBe(0); + expect(stdout[0]).toContain('Build success!!'); + await cleanup(); + }, + INSTALL_AND_BUILD_TIMEOUT, + ); + it( 'should reject a TypeScript entrypoint with a type error', async () => { diff --git a/src/utils/syntax-checker.ts b/src/utils/syntax-checker.ts index 3122968..5c3a5d9 100644 --- a/src/utils/syntax-checker.ts +++ b/src/utils/syntax-checker.ts @@ -127,6 +127,12 @@ function containsTypeScriptSyntaxErrors(tsInput: string, tsConfigPath?: string): // TS infers from `--target esnext` is es2015, which rejects `import.meta` // with TS1343 even though it is valid ESM that the runtime supports. // `esnext` matches how input is actually consumed: esbuild bundles ESM. + + // TS 6+ errors with TS5112 when a file is passed on the command line and a + // tsconfig.json exists in the CWD. We control all flags explicitly here, so + // ignoring any ambient tsconfig is correct. + const ignoreConfig = typescript.major >= 6 ? ['--ignoreConfig'] : []; + const defaultTscBuildFlags = [ '--noEmit', '--skipLibCheck', @@ -138,6 +144,7 @@ function containsTypeScriptSyntaxErrors(tsInput: string, tsConfigPath?: string): 'esnext', '--moduleResolution', moduleResolution, + ...ignoreConfig, ...includeFastEdgeTypes, tsInput, ];