diff --git a/packages/hooks/package.json b/packages/hooks/package.json index 51c936e..d7d4559 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -34,7 +34,7 @@ "directory": "packages/hooks" }, "scripts": { - "build": "vite build && node scripts/remove-redundant-dts.js", + "build": "vite build", "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage" @@ -45,6 +45,7 @@ "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@vitest/coverage-c8": "^0.28.4", + "fast-glob": "^3.2.12", "jsdom": "^21.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/packages/hooks/plugins/remove-redundant-dts.ts b/packages/hooks/plugins/remove-redundant-dts.ts new file mode 100644 index 0000000..78232cf --- /dev/null +++ b/packages/hooks/plugins/remove-redundant-dts.ts @@ -0,0 +1,11 @@ +import glob from "fast-glob"; +import { rm } from "fs/promises"; +import { normalizePath } from "vite"; + +export async function removeRedundantDts() { + const files = await glob("*.d.ts", { + cwd: "dist", + ignore: ["!index.d.ts"], + }); + files.forEach((file) => rm(normalizePath(`dist/${file}`))); +} diff --git a/packages/hooks/scripts/remove-redundant-dts.js b/packages/hooks/scripts/remove-redundant-dts.js deleted file mode 100644 index 6080754..0000000 --- a/packages/hooks/scripts/remove-redundant-dts.js +++ /dev/null @@ -1,16 +0,0 @@ -import { existsSync, readdirSync, rmSync } from "fs"; - -removeRedundantDts(); - -function removeRedundantDts() { - const outDir = "dist"; - - if (!existsSync(outDir)) { - console.warn("Output directory not found, skipping script."); - return; - } - - readdirSync(outDir) - .filter((file) => file.endsWith(".d.ts") && !file.startsWith("index")) - .forEach((file) => rmSync(`${outDir}/${file}`)); -} diff --git a/packages/hooks/vite.config.ts b/packages/hooks/vite.config.ts index b949d93..dce52e5 100644 --- a/packages/hooks/vite.config.ts +++ b/packages/hooks/vite.config.ts @@ -3,12 +3,14 @@ import { defineConfig } from "vite"; import dts from "vite-plugin-dts"; import tsconfigPaths from "vite-tsconfig-paths"; +import { removeRedundantDts } from "./plugins/remove-redundant-dts"; export default defineConfig({ plugins: [ tsconfigPaths(), dts({ rollupTypes: true, + afterBuild: removeRedundantDts, }), ], build: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 35e5b27..2136640 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,6 +98,7 @@ importers: '@types/react': ^18.0.27 '@types/react-dom': ^18.0.10 '@vitest/coverage-c8': ^0.28.4 + fast-glob: ^3.2.12 jsdom: ^21.1.0 react: ^18.2.0 react-dom: ^18.2.0 @@ -113,6 +114,7 @@ importers: '@types/react': 18.0.27 '@types/react-dom': 18.0.10 '@vitest/coverage-c8': 0.28.4_jsdom@21.1.0 + fast-glob: 3.2.12 jsdom: 21.1.0 react: 18.2.0 react-dom: 18.2.0_react@18.2.0