Skip to content

Commit

Permalink
build!: esm-only dist
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 1, 2025
1 parent f3c8ae7 commit 2faa1f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
21 changes: 4 additions & 17 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
}
},
},
Expand Down
34 changes: 13 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -83,4 +75,4 @@
"yaml": "^2.7.0"
},
"packageManager": "[email protected]"
}
}

0 comments on commit 2faa1f6

Please sign in to comment.