Skip to content

Commit

Permalink
fix: dts export missed (#5)
Browse files Browse the repository at this point in the history
the first file
  • Loading branch information
2nthony authored Mar 6, 2024
1 parent 6023fe5 commit 280a042
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { spawnSync } from "node:child_process";
import { resolve } from "node:path";
import { resolve, basename } from "node:path";
import { jsxDir, srcEntries, svgDir } from "./shared.mjs";
import fg from "fast-glob";
import { writeFileSync } from "node:fs";

gen();

Expand All @@ -22,6 +24,7 @@ function gen() {
]);

if (iconsRes.status !== 0) {
console.error(iconsRes.stderr.toString());
process.exit(iconsRes.status);
}

Expand All @@ -42,7 +45,28 @@ function gen() {
"--clean",
]);
if (compileRes.status !== 0) {
console.error(compileRes.stderr.toString());
process.exit(compileRes.status);
}

// HACK: force override `{set}/index.d.ts`
// did not know why the first file ignored
console.info(`[${set}]`, "overriding `index.d.ts`");

const dtsFiles = fg.sync("**/*.d.ts", {
cwd: set,
ignore: ["index.d.ts"],
});
const dtsString =
dtsFiles
.map((filename) => {
const dtsExtname = ".d.ts";
const name = basename(filename, dtsExtname);

return `export { default as ${name} } from './${name}.js';`;
})
.join("\n") + `\nimport 'react'`;

writeFileSync(resolve(set, "index.d.ts"), dtsString, "utf8");
}
}

0 comments on commit 280a042

Please sign in to comment.