1
- import { writeFile } from "node:fs/promises" ;
1
+ import { glob , rm , readFile , writeFile } from "node:fs/promises" ;
2
2
import { fileURLToPath } from "node:url" ;
3
3
import { resolve } from "pathe" ;
4
4
import { normalize } from "pathe" ;
@@ -7,12 +7,9 @@ import { defineBuildConfig } from "unbuild";
7
7
const srcDir = fileURLToPath ( new URL ( "src" , import . meta. url ) ) ;
8
8
9
9
export const subpaths = [
10
- "cli" ,
11
10
"config" ,
12
- "core" ,
13
11
"kit" ,
14
12
"presets" ,
15
- "rollup" ,
16
13
"runtime" ,
17
14
"meta" ,
18
15
"types" ,
@@ -22,32 +19,26 @@ export default defineBuildConfig({
22
19
declaration : true ,
23
20
name : "nitro" ,
24
21
entries : [
25
- // CLI
26
22
{ input : "src/cli/index.ts" } ,
27
- // Config
28
23
{ input : "src/config/index.ts" } ,
29
- // Core
30
24
{ input : "src/core/index.ts" } ,
31
- // Runtime
32
- { input : "src/runtime/" , outDir : "dist/runtime" , format : "esm" } ,
33
- // Kit
34
25
{ input : "src/kit/index.ts" } ,
35
- // Meta
36
26
{ input : "src/meta/index.ts" } ,
37
- // Presets
38
- { input : "src/presets/" , outDir : "dist/presets" , format : "esm" } ,
39
- // Rollup
40
- { input : "src/rollup/index.ts" } ,
41
- // Types
42
27
{ input : "src/types/index.ts" } ,
28
+ { input : "src/runtime/" , outDir : "dist/runtime" , format : "esm" } ,
29
+ { input : "src/presets/" , outDir : "dist/presets" , format : "esm" } ,
43
30
] ,
44
31
hooks : {
45
- async "build:prepare" ( ctx ) {
46
- for ( const subpath of subpaths ) {
47
- await writeFile (
48
- `./${ subpath } .d.ts` ,
49
- `export * from "./dist/${ subpath } /index";`
50
- ) ;
32
+ async "build:done" ( ctx ) {
33
+ for await ( const file of glob ( resolve ( ctx . options . outDir , "**/*.d.ts" ) ) ) {
34
+ if ( file . includes ( "runtime" ) || file . includes ( "presets" ) ) {
35
+ const dtsContents = ( await readFile ( file , "utf8" ) ) . replaceAll (
36
+ / f r o m " \. \/ ( .+ ) " ; $ / gm,
37
+ ( _ , relativePath ) => ` from "./${ relativePath } .mjs";`
38
+ ) ;
39
+ await writeFile ( file . replace ( / \. d .t s $ / , ".d.mts" ) , dtsContents ) ;
40
+ }
41
+ await rm ( file ) ;
51
42
}
52
43
} ,
53
44
} ,
@@ -63,7 +54,7 @@ export default defineBuildConfig({
63
54
alias : {
64
55
nitro : "nitro" ,
65
56
"nitro/meta" : resolve ( srcDir , "../meta.ts" ) ,
66
- "nitro/runtime/meta" : resolve ( srcDir , "../runtime-meta.mjs" ) ,
57
+ "nitro/runtime/meta" : resolve ( srcDir , "../lib/ runtime-meta.mjs" ) ,
67
58
...Object . fromEntries (
68
59
subpaths . map ( ( subpath ) => [
69
60
`nitro/${ subpath } ` ,
0 commit comments