Skip to content

Commit 20c2492

Browse files
committed
feat(cli): expose tsdown types and entry
1 parent 895581e commit 20c2492

7 files changed

Lines changed: 91 additions & 17 deletions

File tree

packages/cli/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
"types": "./binding/index.d.ts"
6767
},
6868
"./package.json": "./package.json",
69+
"./lib": {
70+
"import": "./dist/lib.js",
71+
"types": "./dist/lib.d.ts"
72+
},
6973
"./test": {
7074
"import": {
7175
"types": "./dist/test/index.d.ts",

packages/cli/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { defineConfig as defineLibConfig } from '@voidzero-dev/vite-plus-core/lib';
12
import { defineConfig } from '@voidzero-dev/vite-plus-test/config';
23

34
import type { OxfmtConfig } from './oxfmt-config';
@@ -11,6 +12,8 @@ declare module '@voidzero-dev/vite-plus-core' {
1112
lint?: OxlintConfig;
1213

1314
fmt?: OxfmtConfig;
15+
16+
lib?: Parameters<typeof defineLibConfig>[0];
1417
}
1518
}
1619

packages/cli/src/lib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { defineConfig, build, buildSingle, globalLogger } from '@voidzero-dev/vite-plus-core/lib';
2+
export type * from '@voidzero-dev/vite-plus-core/lib';

packages/core/build-support/rewrite-imports.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import pkgJson from '../package.json' with { type: 'json' };
44

55
export const RewriteImportsPlugin: Plugin = {
66
name: 'rewrite-imports-for-vite-plus',
7-
resolveId(id: string) {
8-
if (id.startsWith('vite/')) {
9-
return { id: id.replace(/^vite\//, `${pkgJson.name}/`), external: true };
10-
}
11-
if (id === 'rolldown') {
12-
return { id: `${pkgJson.name}/rolldown`, external: true };
13-
}
14-
if (id.startsWith('rolldown/')) {
15-
return {
16-
id: id.replace(/^rolldown\//, `${pkgJson.name}/rolldown/`),
17-
external: true,
18-
};
19-
}
7+
resolveId: {
8+
order: 'pre',
9+
handler(id: string) {
10+
if (id.startsWith('vite/')) {
11+
return { id: id.replace(/^vite\//, `${pkgJson.name}/`), external: true };
12+
}
13+
if (id === 'rolldown') {
14+
return { id: `${pkgJson.name}/rolldown`, external: true };
15+
}
16+
if (id.startsWith('rolldown/')) {
17+
return {
18+
id: id.replace(/^rolldown\//, `${pkgJson.name}/rolldown/`),
19+
external: true,
20+
};
21+
}
22+
},
2023
},
2124
};

packages/core/build.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join, parse, resolve } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44

55
import { build, type BuildOptions } from 'rolldown';
6+
import { dts } from 'rolldown-plugin-dts';
67
import { glob } from 'tinyglobby';
78

89
import { RewriteImportsPlugin } from './build-support/rewrite-imports';
@@ -46,7 +47,8 @@ async function buildVite() {
4647
external === 'tinyglobby' ||
4748
external === 'fdir' ||
4849
external === 'rolldown')) ||
49-
(external instanceof RegExp && external.test('rolldown/'))
50+
external === 'yaml' ||
51+
(external instanceof RegExp && (external.test('rolldown/') || external.test('vite/')))
5052
);
5153
});
5254
}
@@ -71,6 +73,8 @@ async function buildVite() {
7173

7274
if (Array.isArray(config.plugins)) {
7375
config.plugins = [
76+
// Add RewriteImportsPlugin to handle vite/rolldown import rewrites
77+
RewriteImportsPlugin,
7478
{
7579
name: 'rewrite-static-paths',
7680
transform(_, id, meta) {
@@ -112,8 +116,6 @@ async function buildVite() {
112116
}
113117
},
114118
},
115-
// Add RewriteImportsPlugin to handle vite/rolldown import rewrites
116-
RewriteImportsPlugin,
117119
...config.plugins.filter((plugin) => {
118120
return !(
119121
typeof plugin === 'object' &&
@@ -243,7 +245,10 @@ async function bundleTsdown() {
243245

244246
// Re-build tsdown cli
245247
await build({
246-
input: join(tsdownSourceDir, 'dist/run.mjs'),
248+
input: {
249+
run: join(tsdownSourceDir, 'dist/run.mjs'),
250+
index: join(tsdownSourceDir, 'dist/index.mjs'),
251+
},
247252
output: {
248253
format: 'esm',
249254
cleanDir: true,
@@ -253,6 +258,23 @@ async function bundleTsdown() {
253258
external: (id: string) => tsdownExternal.some((e) => id.startsWith(e)),
254259
plugins: [RewriteImportsPlugin],
255260
});
261+
262+
await build({
263+
input: {
264+
'index-types': join(tsdownSourceDir, 'dist/index.d.mts'),
265+
},
266+
output: {
267+
format: 'esm',
268+
dir: join(projectDir, 'dist/tsdown'),
269+
},
270+
plugins: [
271+
RewriteImportsPlugin,
272+
dts({
273+
oxc: true,
274+
dtsInput: true,
275+
}),
276+
],
277+
});
256278
}
257279

258280
// Actually do nothing now, we will polish it in the future when `vitepress` is ready

packages/core/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
"default": "./dist/pluginutils/index.js",
4949
"types": "./dist/pluginutils/index.d.ts"
5050
},
51+
"./lib": {
52+
"default": "./dist/tsdown/index.mjs",
53+
"types": "./dist/tsdown/index-types.d.ts"
54+
},
5155
"./types/*": {
5256
"types": "./dist/vite/types/*"
5357
},
@@ -160,9 +164,12 @@
160164
"@oxc-node/cli": "catalog:",
161165
"@oxc-node/core": "catalog:",
162166
"es-module-lexer": "^1.7.0",
167+
"hookable": "^6.0.1",
163168
"magic-string": "^0.30.21",
169+
"pkg-types": "^2.3.0",
164170
"picocolors": "^1.1.1",
165171
"rolldown": "workspace:*",
172+
"rolldown-plugin-dts": "catalog:",
166173
"vite": "workspace:*",
167174
"rollup": "^4.18.0",
168175
"rollup-plugin-license": "^3.6.0",

pnpm-lock.yaml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)