Skip to content

fix: only output files in specified formats #40

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

Merged
merged 3 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ export async function compileAll(
);

// Transpile .d.ts and .js files
if (opts?.js || opts?.dts) {
tsCompile(files, opts?.tsconfig, opts?.dts);
}
tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);

// Remove .ts entries if ts option was not set
if (!opts?.ts) {
for (const [fileName] of files) {
if (fileName.endsWith(".ts")) {
if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
files.delete(fileName);
}
}
Expand Down Expand Up @@ -123,17 +121,21 @@ export function printSourceFiles(ctx: CodeGeneratorContext): string[] {
* Uses provided compiler options and declarations, throws an error if compilation fails.
*
* @param files Map of file names to file content.
* @param dts Whether to generate .d.ts files.
* @param js Whether to generate .js files.
* @param tsconfig TypeScript compiler options.
* @param declaration Whether to generate declaration files.
*/
function tsCompile(
files: Map<string, string>,
dts: boolean,
js: boolean,
tsconfig?: ts.CompilerOptions,
declaration?: boolean,
): void {
if (!dts && !js) {
return;
}

const compileOptions: ts.CompilerOptions = {
noEmit: false,
declaration: declaration ?? false,
moduleResolution: ts.ModuleResolutionKind.Bundler,
target: ts.ScriptTarget.ESNext,
noEmitOnError: false,
Expand All @@ -147,6 +149,8 @@ function tsCompile(
sourceMap: false,
strict: true,
...tsconfig,
emitDeclarationOnly: dts && !js,
declaration: dts,
};

const compilerHost = ts.createCompilerHost(compileOptions);
Expand Down