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 + } +}