-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: fix output drivers to top level drivers
- Loading branch information
Showing
2 changed files
with
16 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters