Skip to content

Commit f2d6ef9

Browse files
authored
build!: cleanup exports (#3196)
1 parent 805a88a commit f2d6ef9

15 files changed

+39
-102
lines changed

build.config.ts

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFile } from "node:fs/promises";
1+
import { glob, rm, readFile, writeFile } from "node:fs/promises";
22
import { fileURLToPath } from "node:url";
33
import { resolve } from "pathe";
44
import { normalize } from "pathe";
@@ -7,12 +7,9 @@ import { defineBuildConfig } from "unbuild";
77
const srcDir = fileURLToPath(new URL("src", import.meta.url));
88

99
export const subpaths = [
10-
"cli",
1110
"config",
12-
"core",
1311
"kit",
1412
"presets",
15-
"rollup",
1613
"runtime",
1714
"meta",
1815
"types",
@@ -22,32 +19,26 @@ export default defineBuildConfig({
2219
declaration: true,
2320
name: "nitro",
2421
entries: [
25-
// CLI
2622
{ input: "src/cli/index.ts" },
27-
// Config
2823
{ input: "src/config/index.ts" },
29-
// Core
3024
{ input: "src/core/index.ts" },
31-
// Runtime
32-
{ input: "src/runtime/", outDir: "dist/runtime", format: "esm" },
33-
// Kit
3425
{ input: "src/kit/index.ts" },
35-
// Meta
3626
{ 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
4227
{ input: "src/types/index.ts" },
28+
{ input: "src/runtime/", outDir: "dist/runtime", format: "esm" },
29+
{ input: "src/presets/", outDir: "dist/presets", format: "esm" },
4330
],
4431
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+
/ from "\.\/(.+)";$/gm,
37+
(_, relativePath) => ` from "./${relativePath}.mjs";`
38+
);
39+
await writeFile(file.replace(/\.d.ts$/, ".d.mts"), dtsContents);
40+
}
41+
await rm(file);
5142
}
5243
},
5344
},
@@ -63,7 +54,7 @@ export default defineBuildConfig({
6354
alias: {
6455
nitro: "nitro",
6556
"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"),
6758
...Object.fromEntries(
6859
subpaths.map((subpath) => [
6960
`nitro/${subpath}`,
File renamed without changes.

runtime-meta.mjs lib/runtime-meta.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { fileURLToPath } from "node:url";
22

3-
export const pkgDir = fileURLToPath(new URL(".", import.meta.url));
3+
export const pkgDir = fileURLToPath(new URL("..", import.meta.url));
44

55
export const runtimeDir = fileURLToPath(
6-
new URL("dist/runtime/", import.meta.url)
6+
new URL("../dist/runtime/", import.meta.url)
77
);
88

99
export const runtimeDependencies = [

package.json

+11-61
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,24 @@
66
"license": "MIT",
77
"type": "module",
88
"exports": {
9-
"./cli": {
10-
"types": "./cli.d.ts",
11-
"import": "./dist/cli/index.mjs"
12-
},
13-
"./config": {
14-
"types": "./config.d.ts",
15-
"import": "./dist/config/index.mjs"
16-
},
17-
".": {
18-
"types": "./dist/core/index.d.ts",
19-
"import": "./dist/core/index.mjs"
20-
},
21-
"./core": {
22-
"types": "./dist/core/index.d.ts",
23-
"import": "./dist/core/index.mjs"
24-
},
25-
"./kit": {
26-
"types": "./kit.d.ts",
27-
"import": "./dist/kit/index.mjs"
28-
},
29-
"./meta": {
30-
"types": "./dist/meta/index.d.ts",
31-
"import": "./dist/meta/index.mjs"
32-
},
33-
"./presets": {
34-
"types": "./presets.d.ts",
35-
"import": "./dist/presets/index.mjs"
36-
},
37-
"./presets/*": {
38-
"types": "./dist/presets/*.d.ts",
39-
"import": "./dist/presets/*.mjs"
40-
},
41-
"./rollup": {
42-
"types": "./rollup.d.ts",
43-
"import": "./dist/rollup/index.mjs"
44-
},
45-
"./runtime": {
46-
"types": "./runtime.d.ts",
47-
"import": "./dist/runtime/index.mjs"
48-
},
49-
"./runtime/meta": {
50-
"types": "./runtime-meta.d.ts",
51-
"import": "./runtime-meta.mjs"
52-
},
53-
"./runtime/*": {
54-
"types": "./dist/runtime/*.d.ts",
55-
"import": "./dist/runtime/*.mjs"
56-
},
57-
"./dist/runtime/*": {
58-
"types": "./dist/runtime/*.d.ts",
59-
"import": "./dist/runtime/*.mjs"
60-
},
61-
"./types": {
62-
"types": "./types.d.ts",
63-
"import": "./dist/types/index.mjs"
64-
},
65-
"./package.json": "./package.json"
9+
"./package.json": "./package.json",
10+
".": "./dist/core/index.mjs",
11+
"./config": "./dist/config/index.mjs",
12+
"./types": "./dist/types/index.d.mts",
13+
"./kit": "./dist/kit/index.mjs",
14+
"./meta": "./dist/meta/index.mjs",
15+
"./presets": "./dist/presets/index.mjs",
16+
"./runtime": "./dist/runtime/index.mjs",
17+
"./runtime/internal": "./dist/runtime/internal/index.mjs",
18+
"./runtime/meta": "./lib/runtime-meta.mjs"
6619
},
67-
"main": "./dist/core/index.mjs",
68-
"types": "./dist/core/index.d.ts",
6920
"bin": {
7021
"nitro": "./dist/cli/index.mjs",
7122
"nitropack": "./dist/cli/index.mjs"
7223
},
7324
"files": [
7425
"dist",
75-
"*.d.ts",
76-
"runtime-meta.*"
26+
"lib"
7727
],
7828
"scripts": {
7929
"build": "pnpm gen-presets && unbuild",

src/cli/commands/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
createNitro,
88
prepare,
99
prerender,
10-
} from "nitro/core";
10+
} from "nitro";
1111
import { resolve } from "pathe";
1212
import { commonArgs } from "../common";
1313

src/cli/commands/dev.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import nodeCrypto from "node:crypto";
22
import { defineCommand } from "citty";
33
import { consola } from "consola";
44
import { getArgs, parseArgs } from "listhen/cli";
5-
import { build, createDevServer, createNitro, prepare } from "nitro/core";
5+
import { build, createDevServer, createNitro, prepare } from "nitro";
66
import type { Nitro } from "nitro/types";
77
import { resolve } from "pathe";
88
import { commonArgs } from "../common";

src/cli/commands/prepare.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineCommand } from "citty";
2-
import { createNitro, writeTypes } from "nitro/core";
2+
import { createNitro, writeTypes } from "nitro";
33
import { resolve } from "pathe";
44
import { commonArgs } from "../common";
55

src/cli/commands/task/list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineCommand } from "citty";
22
import { consola } from "consola";
3-
import { listTasks, loadOptions } from "nitro/core";
3+
import { listTasks, loadOptions } from "nitro";
44
import { resolve } from "pathe";
55

66
export default defineCommand({

src/cli/commands/task/run.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
22
import { consola } from "consola";
33
import destr from "destr";
4-
import { createNitro, loadOptions, runTask } from "nitro/core";
4+
import { createNitro, loadOptions, runTask } from "nitro";
55
import { resolve } from "pathe";
66

77
export default defineCommand({

src/core/build/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRollupConfig } from "nitro/rollup";
1+
import { getRollupConfig } from "../../rollup";
22
import type { Nitro } from "nitro/types";
33
import { watchDev } from "./dev";
44
import { buildProduction } from "./prod";

src/types/h3.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
CacheOptions,
33
CaptureError,
44
CapturedErrorContext,
5-
} from "nitro/types";
5+
} from "./runtime";
66
import type { Base$Fetch, NitroFetchRequest } from "./fetch/fetch";
77

88
export type H3EventFetch = (

test/fixture/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"paths": {
1111
"nitro/cli": ["../../src/cli"],
1212
"nitro/config": ["../../src/config"],
13-
"nitro/core": ["../../src/core"],
1413
"nitro": ["../../src/core"],
1514
"nitro/runtime": ["../../src/runtime"],
15+
"nitro/runtime/internal": ["./src/runtime/internal"],
1616
"nitro/runtime/meta": ["./runtime-meta"],
1717
"nitro/runtime/*": ["../../src/runtime/*"],
1818
"nitro/kit": ["../../src/kit"],

test/scripts/gen-fixture-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath } from "mlly";
2-
import { createNitro, writeTypes } from "nitro/core";
2+
import { createNitro, writeTypes } from "nitro";
33
import { resolve } from "pathe";
44
import { scanHandlers } from "../../src/core/scan";
55

test/tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createNitro,
1414
prepare,
1515
prerender,
16-
} from "nitro/core";
16+
} from "nitro";
1717
import type { Nitro, NitroConfig } from "nitro/types";
1818
import { type FetchOptions, fetch } from "ofetch";
1919
import { join, resolve } from "pathe";

tsconfig.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
"jsxFragmentFactory": "Fragment",
2121
"lib": ["es2022", "webworker", "dom.iterable"],
2222
"paths": {
23-
"nitro/cli": ["./src/cli"],
24-
"nitro/config": ["./src/config"],
25-
"nitro/core": ["./src/core"],
2623
"nitro": ["./src/core"],
24+
"nitro/config": ["./src/config"],
2725
"nitro/runtime": ["./src/runtime"],
28-
"nitro/runtime/*": ["./src/runtime/*"],
26+
"nitro/runtime/internal": ["./src/runtime/internal"],
2927
"nitro/runtime/meta": ["./runtime-meta"],
3028
"nitro/kit": ["./src/kit"],
3129
"nitro/meta": ["./src/meta"],
3230
"nitro/presets": ["./src/presets"],
33-
"nitro/presets/*": ["./src/presets/*"],
34-
"nitro/rollup": ["./src/rollup"],
3531
"nitro/types": ["./src/types"],
3632
"#nitro-internal-virtual/*": ["./src/types/virtual/*"],
3733
"#internal/nitro": ["./src/runtime"],

0 commit comments

Comments
 (0)