diff --git a/.changeset/twenty-grapes-enjoy.md b/.changeset/twenty-grapes-enjoy.md new file mode 100644 index 0000000..3d8b245 --- /dev/null +++ b/.changeset/twenty-grapes-enjoy.md @@ -0,0 +1,6 @@ +--- +"@joshwooding/vite-plugin-react-docgen-typescript": patch +--- + +fix the incorrect `ts` `import()` +optimize performance by creating `tsProgram` just once diff --git a/src/index.ts b/src/index.ts index 266be2f..a2533f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"); @@ -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; @@ -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; }