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

Added support for allowJs compiler option #221

Merged
merged 2 commits into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compile-dts.ts
Expand Up @@ -96,10 +96,14 @@ function changeExtensionToDts(fileName: string): string {
function getDeclarationFiles(rootFiles: readonly string[], compilerOptions: ts.CompilerOptions): Map<string, string> {
// 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 '<filename>' because it would overwrite input file.
compilerOptions = {
...compilerOptions,
noEmit: false,
declaration: true,
emitDeclarationOnly: true,
};

const program = ts.createProgram(rootFiles, compilerOptions);
Expand Down
5 changes: 5 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions tests/e2e/test-cases/allow-js/hello.js
@@ -0,0 +1,3 @@
const hello = { test: 1 };

export { hello }
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/allow-js/input.ts
@@ -0,0 +1,5 @@
import { hello } from "./hello.js";

export function test() {
return hello
}
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/allow-js/output.d.ts
@@ -0,0 +1,5 @@
export declare function test(): {
test: number;
};

export {};
6 changes: 6 additions & 0 deletions tests/e2e/test-cases/allow-js/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true
}
}