diff --git a/build.config.ts b/build.config.ts index a192625..2b5f0c1 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,5 +1,4 @@ -import { mkdir, writeFile } from "node:fs/promises"; -import { dirname, join } from "node:path"; +import { rm, glob } from "node:fs/promises"; import { defineBuildConfig } from "unbuild"; export default defineBuildConfig({ @@ -11,21 +10,9 @@ export default defineBuildConfig({ }, externals: [], hooks: { - async "build:done"(ctx) { - const entries = Object.keys(ctx.pkg.exports || {}) - .filter((key) => key.startsWith("./")) - .map((key) => key.slice(2)); - for (const entry of entries) { - const dst = join(ctx.options.rootDir, entry + ".d.ts"); - console.log(">", dst); - await mkdir(dirname(dst), { recursive: true }); - const relativePath = - ("..".repeat(entry.split("/").length - 1) || ".") + `/dist/${entry}`; - await writeFile( - dst, - `export * from "${relativePath}";\nexport { default } from "${relativePath}";\n`, - "utf8", - ); + async "build:done"() { + for await (const file of glob("dist/**/*.d.ts")) { + await rm(file); } }, }, diff --git a/package.json b/package.json index b7edd06..e3b23ac 100644 --- a/package.json +++ b/package.json @@ -16,37 +16,29 @@ "type": "module", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" + "types": "./dist/index.d.mts", + "import": "./dist/index.mjs" }, "./json5": { - "types": "./dist/json5.d.ts", - "import": "./dist/json5.mjs", - "require": "./dist/json5.cjs" + "types": "./dist/json5.d.mts", + "import": "./dist/json5.mjs" }, "./jsonc": { - "types": "./dist/jsonc.d.ts", - "import": "./dist/jsonc.mjs", - "require": "./dist/jsonc.cjs" + "types": "./dist/jsonc.d.mts", + "import": "./dist/jsonc.mjs" }, "./toml": { - "types": "./dist/toml.d.ts", - "import": "./dist/toml.mjs", - "require": "./dist/toml.cjs" + "types": "./dist/toml.d.mts", + "import": "./dist/toml.mjs" }, "./yaml": { - "types": "./dist/yaml.d.ts", - "import": "./dist/yaml.mjs", - "require": "./dist/yaml.cjs" + "types": "./dist/yaml.d.mts", + "import": "./dist/yaml.mjs" } }, - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "types": "./dist/index.d.mts", "files": [ - "dist", - "*.d.ts" + "dist" ], "scripts": { "build": "unbuild", @@ -83,4 +75,4 @@ "yaml": "^2.7.0" }, "packageManager": "pnpm@10.5.2" -} \ No newline at end of file +}