diff --git a/src/compile-dts.ts b/src/compile-dts.ts index b84c42c..db094a5 100644 --- a/src/compile-dts.ts +++ b/src/compile-dts.ts @@ -96,10 +96,14 @@ function changeExtensionToDts(fileName: string): string { function getDeclarationFiles(rootFiles: readonly string[], compilerOptions: ts.CompilerOptions): Map { // we must pass `declaration: true` and `noEmit: false` if we want to generate declaration files // see https://github.com/microsoft/TypeScript/issues/24002#issuecomment-550549393 + // also, we don't want to generate anything apart from declarations so that's why `emitDeclarationOnly: true` is here + // it allows to run the tool for projects with allowJs flag enabled to avoid errors like: + // error TS5055: Cannot write file '' because it would overwrite input file. compilerOptions = { ...compilerOptions, noEmit: false, declaration: true, + emitDeclarationOnly: true, }; const program = ts.createProgram(rootFiles, compilerOptions); diff --git a/tests/e2e/test-cases/allow-js/config.ts b/tests/e2e/test-cases/allow-js/config.ts new file mode 100644 index 0000000..f1fb1a8 --- /dev/null +++ b/tests/e2e/test-cases/allow-js/config.ts @@ -0,0 +1,5 @@ +import { TestCaseConfig } from '../../test-cases/test-case-config'; + +const config: TestCaseConfig = {}; + +export = config; diff --git a/tests/e2e/test-cases/allow-js/hello.js b/tests/e2e/test-cases/allow-js/hello.js new file mode 100644 index 0000000..4544e17 --- /dev/null +++ b/tests/e2e/test-cases/allow-js/hello.js @@ -0,0 +1,3 @@ +const hello = { test: 1 }; + +export { hello } diff --git a/tests/e2e/test-cases/allow-js/input.ts b/tests/e2e/test-cases/allow-js/input.ts new file mode 100644 index 0000000..9e91fc8 --- /dev/null +++ b/tests/e2e/test-cases/allow-js/input.ts @@ -0,0 +1,5 @@ +import { hello } from "./hello.js"; + +export function test() { + return hello +} diff --git a/tests/e2e/test-cases/allow-js/output.d.ts b/tests/e2e/test-cases/allow-js/output.d.ts new file mode 100644 index 0000000..57c4d37 --- /dev/null +++ b/tests/e2e/test-cases/allow-js/output.d.ts @@ -0,0 +1,5 @@ +export declare function test(): { + test: number; +}; + +export {}; diff --git a/tests/e2e/test-cases/allow-js/tsconfig.json b/tests/e2e/test-cases/allow-js/tsconfig.json new file mode 100644 index 0000000..bf3a541 --- /dev/null +++ b/tests/e2e/test-cases/allow-js/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true + } +}