From ee753e779032b8f7245b38e928d7b3b9a7a810f9 Mon Sep 17 00:00:00 2001 From: Hashim1999164 <64767361+Hashim1999164@users.noreply.github.com> Date: Fri, 28 Aug 2026 23:38:18 +0500 Subject: [PATCH] Allow TypeScript configs that set allowImportingTsExtensions. ncc already forces noEmit false to emit JavaScript, which then fails with TS5096 when the project also enabled allowImportingTsExtensions. Ignore that config diagnostic and keep emitDeclarationOnly off so .ts import specifiers still typecheck. --- src/index.js | 6 ++++++ test/cli.js | 7 +++++++ test/fixtures/ts-allow-importing-ts-extensions/dep.ts | 1 + test/fixtures/ts-allow-importing-ts-extensions/input.ts | 2 ++ .../ts-allow-importing-ts-extensions/tsconfig.json | 9 +++++++++ 5 files changed, 25 insertions(+) create mode 100644 test/fixtures/ts-allow-importing-ts-extensions/dep.ts create mode 100644 test/fixtures/ts-allow-importing-ts-extensions/input.ts create mode 100644 test/fixtures/ts-allow-importing-ts-extensions/tsconfig.json diff --git a/src/index.js b/src/index.js index 8db36879..6b02897b 100644 --- a/src/index.js +++ b/src/index.js @@ -365,12 +365,18 @@ function ncc ( options: { transpileOnly, compiler: eval('__dirname + "/typescript.js"'), + // ncc emits JS, so noEmit is forced off. TS5096 then fires if the + // project enabled allowImportingTsExtensions; ignore that config error. + ignoreDiagnostics: (fullTsconfig.compilerOptions || {}).allowImportingTsExtensions + ? [5096] + : [], compilerOptions: { module: 'esnext', target: 'esnext', ...fullTsconfig.compilerOptions, allowSyntheticDefaultImports: true, noEmit: false, + emitDeclarationOnly: false, outDir: '//' } } diff --git a/test/cli.js b/test/cli.js index 1ac38536..e038095f 100644 --- a/test/cli.js +++ b/test/cli.js @@ -70,6 +70,13 @@ module.exports = [ args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"], expect: { code: 0 } }, + { + args: ["build", "-o", "tmp", "test/fixtures/ts-allow-importing-ts-extensions/input.ts"], + expect (code, stdout, stderr) { + const fs = require('fs'); + return code === 0 && fs.readFileSync(join('tmp', 'index.js'), 'utf8').indexOf('value') !== -1; + } + }, { args: ["build", "-o", "tmp", "test/fixtures/test.cjs"], expect (code, stdout, stderr) { diff --git a/test/fixtures/ts-allow-importing-ts-extensions/dep.ts b/test/fixtures/ts-allow-importing-ts-extensions/dep.ts new file mode 100644 index 00000000..efeee5db --- /dev/null +++ b/test/fixtures/ts-allow-importing-ts-extensions/dep.ts @@ -0,0 +1 @@ +export const value = 1; diff --git a/test/fixtures/ts-allow-importing-ts-extensions/input.ts b/test/fixtures/ts-allow-importing-ts-extensions/input.ts new file mode 100644 index 00000000..be4af8ed --- /dev/null +++ b/test/fixtures/ts-allow-importing-ts-extensions/input.ts @@ -0,0 +1,2 @@ +import { value } from './dep.ts'; +console.log(value); diff --git a/test/fixtures/ts-allow-importing-ts-extensions/tsconfig.json b/test/fixtures/ts-allow-importing-ts-extensions/tsconfig.json new file mode 100644 index 00000000..dcaf38d4 --- /dev/null +++ b/test/fixtures/ts-allow-importing-ts-extensions/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "noEmit": true + } +}