Skip to content

Commit

Permalink
build: fix output drivers to top level drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 6, 2023
1 parent 59ec8f4 commit ff3959c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
36 changes: 13 additions & 23 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import { mkdir, writeFile } from "node:fs/promises";
import { dirname, join, relative } from "node:path";
import { fileURLToPath } from "node:url";
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
declaration: true,
rollup: {
emitCJS: true
emitCJS: true,
},
entries: [
"src/index",
"src/server",
{ input: "src/drivers/", outDir: "dist/drivers", format: "esm" },
{ input: "src/drivers/", outDir: "dist/drivers", format: "cjs", ext: "cjs", declaration: false }
{
input: "src/drivers/",
outDir: "drivers",
format: "esm",
},
{
input: "src/drivers/",
outDir: "drivers",
format: "cjs",
ext: "cjs",
declaration: false,
},
],
hooks: {
async "build:done" (ctx) {
for (const entry of ctx.buildEntries) {
if (/^drivers\/.*\.d\.ts$/.test(entry.path)) {
const target = fileURLToPath(new URL(join("dist", entry.path), import.meta.url));
const declaration = fileURLToPath(new URL(entry.path, import.meta.url));
const relativePath = relative(dirname(declaration), target);

await mkdir(dirname(declaration), { recursive: true });
await writeFile(declaration, [
`export * from "${relativePath.slice(0, -5)}";`,
`export { default } from "${relativePath.slice(0, -5)}";`
].join("\n"));
}
}
}
}
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"sideEffects": false,
"exports": {
"./drivers/*": {
"import": "./dist/drivers/*.mjs",
"require": "./dist/drivers/*.cjs",
"types": "./dist/drivers/*.d.ts"
"import": "./drivers/*.mjs",
"require": "./drivers/*.cjs",
"types": "./drivers/*.d.ts"
},
".": {
"import": "./dist/index.mjs",
Expand Down

0 comments on commit ff3959c

Please sign in to comment.