Skip to content

Commit

Permalink
Fix the ts import, optimize for creating tsProgram once (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen authored Dec 21, 2022
1 parent 2b506c9 commit 9463cc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-grapes-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@joshwooding/vite-plugin-react-docgen-typescript": patch
---

fix the incorrect `ts` `import()`
optimize performance by creating `tsProgram` just once
14 changes: 5 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Options } from "./utils/options";

const getUtils = async (config: Options) => {
const docGen = await import("react-docgen-typescript");
const ts = await import("typescript");
const { default: ts } = await import("typescript");
const { generateDocgenCodeBlock } = await import("./utils/generate");
const { getOptions } = await import("./utils/options");

Expand All @@ -30,14 +30,14 @@ const getUtils = async (config: Options) => {
)
.reduce((carry, files) => carry.concat(files), []);

const tsProgram = ts.createProgram(files, compilerOptions);

const result = {
ts,
files,
compilerOptions,
docGenParser,
filter,
generateOptions,
generateDocgenCodeBlock,
tsProgram,
};

return result;
Expand All @@ -51,17 +51,13 @@ export default function reactDocgenTypescript(config: Options = {}): Plugin {
async transform(src, id) {
try {
const {
ts,
filter,
files,
docGenParser,
compilerOptions,
generateOptions,
generateDocgenCodeBlock,
tsProgram,
} = await utilsPromise;

const tsProgram = ts.createProgram(files, compilerOptions);

if (!filter(id)) {
return;
}
Expand Down

0 comments on commit 9463cc0

Please sign in to comment.