Skip to content

Commit

Permalink
feat: force not removing comments while generating ts declaration
Browse files Browse the repository at this point in the history
To preserve jsdoc comments
  • Loading branch information
adbayb committed Mar 17, 2022
1 parent 628e461 commit dfc65a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions examples/ts-module/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ interface ButtonProps {
label: string;
}

/**
* Button component
*/
export const Button = (props: ButtonProps) => {
return (
<>
Expand Down
18 changes: 5 additions & 13 deletions src/bundler/bundler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable sonarjs/cognitive-complexity */
import path from "path";
import { build } from "esbuild";
import { helpers } from "termost";
import { CWD } from "../constants";
import { ModuleFormat } from "../types";
import { getPackageMetadata } from "./package";
import { jsxPlugin } from "./plugins";
import { getTypeScriptConfiguration } from "./typescript";
import {
generateTypeScriptDeclaration,
getTypeScriptConfiguration,
} from "./typescript";

type BundleParameters = {
isProduction: boolean;
Expand Down Expand Up @@ -36,16 +37,7 @@ export const bundle = async ({

if (!outfile) return null;

try {
const typingDir = path.dirname(outfile);

await helpers.exec(
`tsc --declaration --emitDeclarationOnly --incremental --outDir ${typingDir}`,
{ cwd: CWD }
);
} catch (error) {
throw new Error(`Typing generation failed:\n${error}`);
}
await generateTypeScriptDeclaration(outfile);

return outfile;
};
Expand Down
18 changes: 17 additions & 1 deletion src/bundler/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "path";
import { dirname, resolve } from "path";
import { helpers } from "termost";
import { CWD } from "../constants";

export type TypeScriptConfiguration = {
Expand Down Expand Up @@ -44,6 +45,21 @@ export const getTypeScriptConfiguration =
}
};

export const generateTypeScriptDeclaration = async (outfile: string) => {
const outdir = dirname(outfile);

try {
await helpers.exec(
`tsc --declaration --emitDeclarationOnly --incremental --removeComments false --outDir ${outdir}`,
{ cwd: CWD }
);

return outdir;
} catch (error) {
throw new Error(`Type generation failed:\n${error}`);
}
};

export const hasTypeScript = (
tsConfig: TypeScriptConfiguration | null
): tsConfig is TypeScriptConfiguration => {
Expand Down

0 comments on commit dfc65a0

Please sign in to comment.