rolldown-plugin-dts 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -13
- package/dist/filename-Cqnsj8Gp.mjs +27 -0
- package/dist/filename.mjs +1 -25
- package/dist/{index-DWPGYc3m.d.mts → index-C8o_kIRC.d.mts} +1 -1
- package/dist/index.d.mts +121 -133
- package/dist/index.mjs +68 -48
- package/dist/{tsc-CG1xgNuJ.mjs → tsc-C0UrtIA5.mjs} +4 -3
- package/dist/tsc-context.d.mts +1 -1
- package/dist/tsc-context.mjs +1 -1
- package/dist/tsc-worker.d.mts +1 -2
- package/dist/tsc-worker.mjs +1 -2
- package/dist/tsc.d.mts +1 -2
- package/dist/tsc.mjs +1 -2
- package/package.json +18 -16
- /package/dist/{context-Dt8gPoCq.d.mts → context-CCPZT79j.d.mts} +0 -0
- /package/dist/{context-9CkpILzL.mjs → context-EuY-ImLj.mjs} +0 -0
- /package/dist/{resolver-CyVXxlZv.mjs → resolver-DksQRwY1.mjs} +0 -0
package/README.md
CHANGED
|
@@ -81,16 +81,6 @@ See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/t
|
|
|
81
81
|
|
|
82
82
|
If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
83
83
|
|
|
84
|
-
#### `resolve`
|
|
85
|
-
|
|
86
|
-
Controls whether type definitions from `node_modules` are bundled into your final `.d.ts` file or kept as external `import` statements.
|
|
87
|
-
|
|
88
|
-
By default, dependencies are external, resulting in `import { Type } from 'some-package'`. When bundled, this `import` is removed, and the type definitions from `some-package` are copied directly into your file.
|
|
89
|
-
|
|
90
|
-
- `true`: Bundles all dependencies.
|
|
91
|
-
- `false`: (Default) Keeps all dependencies external.
|
|
92
|
-
- `(string | RegExp)[]`: Bundles only dependencies matching the provided strings or regular expressions (e.g. `['pkg-a', /^@scope\//]`).
|
|
93
|
-
|
|
94
84
|
#### `resolver`
|
|
95
85
|
|
|
96
86
|
Specifies a resolver to resolve type definitions, especially for `node_modules`.
|
|
@@ -200,13 +190,13 @@ To use this option, ensure that `@typescript/native-preview` is installed as a d
|
|
|
200
190
|
|
|
201
191
|
`tsconfigRaw` and `compilerOptions` options will be ignored when this option is enabled.
|
|
202
192
|
|
|
203
|
-
##
|
|
193
|
+
## Code Splitting Support
|
|
204
194
|
|
|
205
|
-
When using Rolldown's
|
|
195
|
+
When using Rolldown's code splitting features `codeSplitting`, you should pay special attention to handling `.d.ts` files. The chunk names for `.d.ts` files must end with `.d`.
|
|
206
196
|
|
|
207
197
|
```ts
|
|
208
198
|
export default {
|
|
209
|
-
|
|
199
|
+
codeSplitting: {
|
|
210
200
|
groups: [
|
|
211
201
|
// handle .d.ts files
|
|
212
202
|
{ test: /foo.*\.d\.[cm]?ts$/, name: 'shared.d' },
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/filename.ts
|
|
2
|
+
const RE_JS = /\.([cm]?)jsx?$/;
|
|
3
|
+
const RE_TS = /\.([cm]?)tsx?$/;
|
|
4
|
+
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
5
|
+
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
6
|
+
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
7
|
+
const RE_CSS = /\.css$/;
|
|
8
|
+
const RE_VUE = /\.vue$/;
|
|
9
|
+
const RE_JSON = /\.json$/;
|
|
10
|
+
function filename_js_to_dts(id) {
|
|
11
|
+
return id.replace(RE_JS, ".d.$1ts");
|
|
12
|
+
}
|
|
13
|
+
function filename_to_dts(id) {
|
|
14
|
+
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".d.ts");
|
|
15
|
+
}
|
|
16
|
+
function filename_dts_to(id, ext) {
|
|
17
|
+
return id.replace(RE_DTS, `.$1${ext}`);
|
|
18
|
+
}
|
|
19
|
+
function resolveTemplateFn(fn, chunk) {
|
|
20
|
+
return typeof fn === "function" ? fn(chunk) : fn;
|
|
21
|
+
}
|
|
22
|
+
function replaceTemplateName(template, name) {
|
|
23
|
+
return template.replaceAll("[name]", name);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { RE_JSON as a, RE_VUE as c, filename_to_dts as d, replaceTemplateName as f, RE_JS as i, filename_dts_to as l, RE_DTS as n, RE_NODE_MODULES as o, resolveTemplateFn as p, RE_DTS_MAP as r, RE_TS as s, RE_CSS as t, filename_js_to_dts as u };
|
package/dist/filename.mjs
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
const RE_JS = /\.([cm]?)jsx?$/;
|
|
3
|
-
const RE_TS = /\.([cm]?)tsx?$/;
|
|
4
|
-
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
5
|
-
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
6
|
-
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
7
|
-
const RE_CSS = /\.css$/;
|
|
8
|
-
const RE_VUE = /\.vue$/;
|
|
9
|
-
const RE_JSON = /\.json$/;
|
|
10
|
-
function filename_js_to_dts(id) {
|
|
11
|
-
return id.replace(RE_JS, ".d.$1ts");
|
|
12
|
-
}
|
|
13
|
-
function filename_to_dts(id) {
|
|
14
|
-
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".d.ts");
|
|
15
|
-
}
|
|
16
|
-
function filename_dts_to(id, ext) {
|
|
17
|
-
return id.replace(RE_DTS, `.$1${ext}`);
|
|
18
|
-
}
|
|
19
|
-
function resolveTemplateFn(fn, chunk) {
|
|
20
|
-
return typeof fn === "function" ? fn(chunk) : fn;
|
|
21
|
-
}
|
|
22
|
-
function replaceTemplateName(template, name) {
|
|
23
|
-
return template.replaceAll("[name]", name);
|
|
24
|
-
}
|
|
1
|
+
import { a as RE_JSON, c as RE_VUE, d as filename_to_dts, f as replaceTemplateName, i as RE_JS, l as filename_dts_to, n as RE_DTS, o as RE_NODE_MODULES, p as resolveTemplateFn, r as RE_DTS_MAP, s as RE_TS, t as RE_CSS, u as filename_js_to_dts } from "./filename-Cqnsj8Gp.mjs";
|
|
25
2
|
|
|
26
|
-
//#endregion
|
|
27
3
|
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_JSON, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_to_dts, replaceTemplateName, resolveTemplateFn };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_JSON, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename.mjs";
|
|
2
1
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
3
2
|
import { TsConfigJson } from "get-tsconfig";
|
|
4
3
|
import { Plugin } from "rolldown";
|
|
@@ -6,178 +5,168 @@ import { Plugin } from "rolldown";
|
|
|
6
5
|
//#region src/options.d.ts
|
|
7
6
|
interface GeneralOptions {
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* The directory in which the plugin will search for the `tsconfig.json` file.
|
|
9
|
+
*/
|
|
11
10
|
cwd?: string;
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
|
|
13
|
+
*
|
|
14
|
+
* When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
|
|
15
|
+
*/
|
|
17
16
|
dtsInput?: boolean;
|
|
18
17
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
* If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
|
|
19
|
+
*
|
|
20
|
+
* This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
|
|
21
|
+
*/
|
|
23
22
|
emitDtsOnly?: boolean;
|
|
24
23
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
* The path to the `tsconfig.json` file.
|
|
25
|
+
*
|
|
26
|
+
* If set to `false`, the plugin will ignore any `tsconfig.json` file.
|
|
27
|
+
* You can still specify `compilerOptions` directly in the options.
|
|
28
|
+
*
|
|
29
|
+
* @default 'tsconfig.json'
|
|
30
|
+
*/
|
|
32
31
|
tsconfig?: string | boolean;
|
|
33
32
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
* Pass a raw `tsconfig.json` object directly to the plugin.
|
|
34
|
+
*
|
|
35
|
+
* @see https://www.typescriptlang.org/tsconfig
|
|
36
|
+
*/
|
|
38
37
|
tsconfigRaw?: Omit<TsConfigJson, "compilerOptions">;
|
|
39
38
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
* Override the `compilerOptions` specified in `tsconfig.json`.
|
|
40
|
+
*
|
|
41
|
+
* @see https://www.typescriptlang.org/tsconfig/#compilerOptions
|
|
42
|
+
*/
|
|
44
43
|
compilerOptions?: TsConfigJson.CompilerOptions;
|
|
45
44
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
46
|
+
*/
|
|
48
47
|
sourcemap?: boolean;
|
|
49
48
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
resolve?: boolean | (string | RegExp)[];
|
|
59
|
-
/**
|
|
60
|
-
* Specifies a resolver to resolve type definitions, especially for `node_modules`.
|
|
61
|
-
*
|
|
62
|
-
* - `'oxc'`: Uses Oxc's module resolution, which is faster and more efficient.
|
|
63
|
-
* - `'tsc'`: Uses TypeScript's native module resolution, which may be more compatible with complex setups, but slower.
|
|
64
|
-
*
|
|
65
|
-
* @default 'oxc'
|
|
66
|
-
*/
|
|
49
|
+
* Specifies a resolver to resolve type definitions, especially for `node_modules`.
|
|
50
|
+
*
|
|
51
|
+
* - `'oxc'`: Uses Oxc's module resolution, which is faster and more efficient.
|
|
52
|
+
* - `'tsc'`: Uses TypeScript's native module resolution, which may be more compatible with complex setups, but slower.
|
|
53
|
+
*
|
|
54
|
+
* @default 'oxc'
|
|
55
|
+
*/
|
|
67
56
|
resolver?: "oxc" | "tsc";
|
|
68
57
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
* Determines how the default export is emitted.
|
|
59
|
+
*
|
|
60
|
+
* If set to `true`, and you are only exporting a single item using `export default ...`,
|
|
61
|
+
* the output will use `export = ...` instead of the standard ES module syntax.
|
|
62
|
+
* This is useful for compatibility with CommonJS.
|
|
63
|
+
*/
|
|
75
64
|
cjsDefault?: boolean;
|
|
76
65
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
* Indicates whether the generated `.d.ts` files have side effects.
|
|
67
|
+
* - If set to `true`, Rolldown will treat the `.d.ts` files as having side effects during tree-shaking.
|
|
68
|
+
* - If set to `false`, Rolldown may consider the `.d.ts` files as side-effect-free, potentially removing them if they are not imported.
|
|
69
|
+
*
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
83
72
|
sideEffects?: boolean;
|
|
84
73
|
}
|
|
85
74
|
interface TscOptions {
|
|
86
75
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
* Build mode for the TypeScript compiler:
|
|
77
|
+
*
|
|
78
|
+
* - If `true`, the plugin will use [`tsc -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript) to build the project and all referenced projects before emitting `.d.ts` files.
|
|
79
|
+
* - If `false`, the plugin will use [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to emit `.d.ts` files without building referenced projects.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
94
83
|
build?: boolean;
|
|
95
84
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
85
|
+
* If your tsconfig.json has
|
|
86
|
+
* [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
|
|
87
|
+
* `rolldown-plugin-dts` will use [`tsc
|
|
88
|
+
* -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript)
|
|
89
|
+
* to build the project and all referenced projects before emitting `.d.ts`
|
|
90
|
+
* files.
|
|
91
|
+
*
|
|
92
|
+
* In such case, if this option is `true`, `rolldown-plugin-dts` will write
|
|
93
|
+
* down all built files into your disk, including
|
|
94
|
+
* [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
95
|
+
* and other built files. This is equivalent to running `tsc -b` in your
|
|
96
|
+
* project.
|
|
97
|
+
*
|
|
98
|
+
* Otherwise, if this option is `false`, `rolldown-plugin-dts` will write
|
|
99
|
+
* built files only into memory and leave a small footprint in your disk.
|
|
100
|
+
*
|
|
101
|
+
* Enabling this option will decrease the build time by caching previous build
|
|
102
|
+
* results. This is helpful when you have a large project with multiple
|
|
103
|
+
* referenced projects.
|
|
104
|
+
*
|
|
105
|
+
* By default, `incremental` is `true` if your tsconfig has
|
|
106
|
+
* [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or
|
|
107
|
+
* [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
108
|
+
* enabled.
|
|
109
|
+
*
|
|
110
|
+
* This option is only used when {@link Options.oxc} is
|
|
111
|
+
* `false`.
|
|
112
|
+
*/
|
|
124
113
|
incremental?: boolean;
|
|
125
114
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
115
|
+
* If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
|
|
116
|
+
*/
|
|
128
117
|
vue?: boolean;
|
|
129
118
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
* If `true`, the plugin will generate `.d.ts` files using `@ts-macro/tsc`.
|
|
120
|
+
*/
|
|
132
121
|
tsMacro?: boolean;
|
|
133
122
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
* If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
|
|
124
|
+
* This enables processing multiple projects in parallel.
|
|
125
|
+
*/
|
|
137
126
|
parallel?: boolean;
|
|
138
127
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
* If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
|
|
129
|
+
*
|
|
130
|
+
* This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
|
|
131
|
+
*/
|
|
143
132
|
eager?: boolean;
|
|
144
133
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
134
|
+
* If `true`, the plugin will create a new isolated context for each build,
|
|
135
|
+
* ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
136
|
+
*
|
|
137
|
+
* By default, the plugin may reuse internal caches or incremental build artifacts
|
|
138
|
+
* to speed up repeated builds. Enabling this option forces a clean context,
|
|
139
|
+
* guaranteeing that all type definitions are generated from scratch.
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
154
143
|
newContext?: boolean;
|
|
155
144
|
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
145
|
+
* If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
|
|
146
|
+
* This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
|
|
147
|
+
*
|
|
148
|
+
* Enabled by default when `allowJs` in compilerOptions is `true`.
|
|
149
|
+
* This option is only used when {@link Options.oxc} is
|
|
150
|
+
* `false`.
|
|
151
|
+
*/
|
|
163
152
|
emitJs?: boolean;
|
|
164
153
|
}
|
|
165
154
|
interface Options extends GeneralOptions, TscOptions {
|
|
166
155
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
156
|
+
* If `true`, the plugin will generate `.d.ts` files using Oxc,
|
|
157
|
+
* which is significantly faster than the TypeScript compiler.
|
|
158
|
+
*
|
|
159
|
+
* This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
160
|
+
*/
|
|
172
161
|
oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
173
162
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
163
|
+
* **[Experimental]** Enables DTS generation using `tsgo`.
|
|
164
|
+
*
|
|
165
|
+
* To use this option, make sure `@typescript/native-preview` is installed as a dependency.
|
|
166
|
+
*
|
|
167
|
+
* **Note:** This option is not yet recommended for production environments.
|
|
168
|
+
* `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
|
|
169
|
+
*/
|
|
181
170
|
tsgo?: boolean;
|
|
182
171
|
}
|
|
183
172
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
@@ -194,7 +183,6 @@ declare function resolveOptions({
|
|
|
194
183
|
tsconfigRaw: overriddenTsconfigRaw,
|
|
195
184
|
compilerOptions,
|
|
196
185
|
sourcemap,
|
|
197
|
-
resolve,
|
|
198
186
|
resolver,
|
|
199
187
|
cjsDefault,
|
|
200
188
|
sideEffects,
|
|
@@ -239,4 +227,4 @@ declare function createGeneratePlugin({
|
|
|
239
227
|
//#region src/index.d.ts
|
|
240
228
|
declare function dts(options?: Options): Plugin[];
|
|
241
229
|
//#endregion
|
|
242
|
-
export { type Options,
|
|
230
|
+
export { type Options, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-
|
|
2
|
+
import { a as RE_JSON, c as RE_VUE, d as filename_to_dts, f as replaceTemplateName, i as RE_JS, l as filename_dts_to, n as RE_DTS, o as RE_NODE_MODULES, p as resolveTemplateFn, r as RE_DTS_MAP, s as RE_TS, t as RE_CSS, u as filename_js_to_dts } from "./filename-Cqnsj8Gp.mjs";
|
|
3
|
+
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-EuY-ImLj.mjs";
|
|
4
4
|
import { createDebug } from "obug";
|
|
5
5
|
const {
|
|
6
6
|
generate
|
|
@@ -22,14 +22,15 @@ const {
|
|
|
22
22
|
readFile,
|
|
23
23
|
rm
|
|
24
24
|
} = globalThis.process.getBuiltinModule("node:fs/promises");
|
|
25
|
+
const path = globalThis.process.getBuiltinModule("node:path");
|
|
26
|
+
import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
|
|
25
27
|
const {
|
|
26
28
|
tmpdir
|
|
27
29
|
} = globalThis.process.getBuiltinModule("node:os");
|
|
28
|
-
const path = globalThis.process.getBuiltinModule("node:path");
|
|
29
|
-
import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
|
|
30
30
|
const process = globalThis.process;
|
|
31
31
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
32
32
|
import { createResolver } from "dts-resolver";
|
|
33
|
+
import { importerId, include } from "rolldown/filter";
|
|
33
34
|
|
|
34
35
|
//#region src/dts-input.ts
|
|
35
36
|
function createDtsInputPlugin({ sideEffects }) {
|
|
@@ -98,10 +99,15 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
98
99
|
handler: transform
|
|
99
100
|
},
|
|
100
101
|
renderChunk,
|
|
101
|
-
generateBundle
|
|
102
|
+
generateBundle(options, bundle) {
|
|
102
103
|
for (const chunk of Object.values(bundle)) {
|
|
103
104
|
if (!RE_DTS_MAP.test(chunk.fileName)) continue;
|
|
104
|
-
|
|
105
|
+
if (sourcemap) {
|
|
106
|
+
if (chunk.type === "chunk" || typeof chunk.source !== "string") continue;
|
|
107
|
+
const map = JSON.parse(chunk.source);
|
|
108
|
+
map.sourcesContent = void 0;
|
|
109
|
+
chunk.source = JSON.stringify(map);
|
|
110
|
+
} else delete bundle[chunk.fileName];
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
};
|
|
@@ -222,6 +228,9 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
222
228
|
const [symbolIdNode, depsFn] = node.declarations[0].init.elements;
|
|
223
229
|
const symbolId = symbolIdNode.value;
|
|
224
230
|
const original = getSymbol(symbolId);
|
|
231
|
+
walkAST(original.decl, { enter(node$1) {
|
|
232
|
+
delete node$1.loc;
|
|
233
|
+
} });
|
|
225
234
|
for (const [i, decl] of node.declarations.entries()) {
|
|
226
235
|
const transformedBinding = {
|
|
227
236
|
...decl.id,
|
|
@@ -596,14 +605,42 @@ function inheritNodeComments(oldNode, newNode) {
|
|
|
596
605
|
}
|
|
597
606
|
|
|
598
607
|
//#endregion
|
|
599
|
-
//#region src/
|
|
600
|
-
const debug$
|
|
601
|
-
const WORKER_URL = "./tsc-worker.mjs";
|
|
608
|
+
//#region src/tsgo.ts
|
|
609
|
+
const debug$3 = createDebug("rolldown-plugin-dts:tsgo");
|
|
602
610
|
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
603
611
|
const child = spawn(...args);
|
|
604
612
|
child.on("close", () => resolve());
|
|
605
613
|
child.on("error", (error) => reject(error));
|
|
606
614
|
});
|
|
615
|
+
async function runTsgo(rootDir, tsconfig, sourcemap) {
|
|
616
|
+
debug$3("[tsgo] rootDir", rootDir);
|
|
617
|
+
const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
|
|
618
|
+
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
|
|
619
|
+
const tsgo = getExePath();
|
|
620
|
+
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
621
|
+
debug$3("[tsgo] tsgoDist", tsgoDist);
|
|
622
|
+
const args = [
|
|
623
|
+
"--noEmit",
|
|
624
|
+
"false",
|
|
625
|
+
"--declaration",
|
|
626
|
+
"--emitDeclarationOnly",
|
|
627
|
+
...tsconfig ? ["-p", tsconfig] : [],
|
|
628
|
+
"--outDir",
|
|
629
|
+
tsgoDist,
|
|
630
|
+
"--rootDir",
|
|
631
|
+
rootDir,
|
|
632
|
+
"--noCheck",
|
|
633
|
+
...sourcemap ? ["--declarationMap"] : []
|
|
634
|
+
];
|
|
635
|
+
debug$3("[tsgo] args %o", args);
|
|
636
|
+
await spawnAsync(tsgo, args, { stdio: "inherit" });
|
|
637
|
+
return tsgoDist;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/generate.ts
|
|
642
|
+
const debug$2 = createDebug("rolldown-plugin-dts:generate");
|
|
643
|
+
const WORKER_URL = "./tsc-worker.mjs";
|
|
607
644
|
function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
|
|
608
645
|
const dtsMap = /* @__PURE__ */ new Map();
|
|
609
646
|
/**
|
|
@@ -625,7 +662,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
625
662
|
return {
|
|
626
663
|
name: "rolldown-plugin-dts:generate",
|
|
627
664
|
async buildStart(options) {
|
|
628
|
-
if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig);
|
|
665
|
+
if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig, sourcemap);
|
|
629
666
|
else if (!oxc) if (parallel) {
|
|
630
667
|
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
631
668
|
rpc = (await import("birpc")).createBirpc({}, {
|
|
@@ -715,11 +752,19 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
715
752
|
if (tsgo) {
|
|
716
753
|
if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
|
|
717
754
|
const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(rootDir), filename_to_dts(id)));
|
|
718
|
-
if (existsSync(dtsPath))
|
|
719
|
-
else {
|
|
755
|
+
if (!existsSync(dtsPath)) {
|
|
720
756
|
debug$2("[tsgo]", dtsPath, "is missing");
|
|
721
757
|
throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
|
|
722
758
|
}
|
|
759
|
+
dtsCode = await readFile(dtsPath, "utf8");
|
|
760
|
+
const mapPath = `${dtsPath}.map`;
|
|
761
|
+
if (existsSync(mapPath)) {
|
|
762
|
+
const mapRaw = await readFile(mapPath, "utf8");
|
|
763
|
+
map = {
|
|
764
|
+
...JSON.parse(mapRaw),
|
|
765
|
+
sources: [id]
|
|
766
|
+
};
|
|
767
|
+
}
|
|
723
768
|
} else if (oxc && !RE_VUE.test(id)) {
|
|
724
769
|
const result = isolatedDeclarationSync(id, code, oxc);
|
|
725
770
|
if (result.errors.length) {
|
|
@@ -796,27 +841,6 @@ export { __json_default_export as default }`;
|
|
|
796
841
|
}
|
|
797
842
|
};
|
|
798
843
|
}
|
|
799
|
-
async function runTsgo(rootDir, tsconfig) {
|
|
800
|
-
const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
|
|
801
|
-
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
|
|
802
|
-
const tsgo = getExePath();
|
|
803
|
-
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
804
|
-
debug$2("[tsgo] tsgoDist", tsgoDist);
|
|
805
|
-
debug$2("[tsgo] rootDir", rootDir);
|
|
806
|
-
await spawnAsync(tsgo, [
|
|
807
|
-
"--noEmit",
|
|
808
|
-
"false",
|
|
809
|
-
"--declaration",
|
|
810
|
-
"--emitDeclarationOnly",
|
|
811
|
-
...tsconfig ? ["-p", tsconfig] : [],
|
|
812
|
-
"--outDir",
|
|
813
|
-
tsgoDist,
|
|
814
|
-
"--rootDir",
|
|
815
|
-
rootDir,
|
|
816
|
-
"--noCheck"
|
|
817
|
-
], { stdio: "inherit" });
|
|
818
|
-
return tsgoDist;
|
|
819
|
-
}
|
|
820
844
|
function collectJsonExportMap(code) {
|
|
821
845
|
const exportMap = /* @__PURE__ */ new Map();
|
|
822
846
|
const { program } = parse(code, {
|
|
@@ -851,7 +875,7 @@ function collectJsonExports(code) {
|
|
|
851
875
|
//#endregion
|
|
852
876
|
//#region src/options.ts
|
|
853
877
|
let warnedTsgo = false;
|
|
854
|
-
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap,
|
|
878
|
+
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
855
879
|
let resolvedTsconfig;
|
|
856
880
|
if (tsconfig === true || tsconfig == null) {
|
|
857
881
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -898,7 +922,6 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
|
|
|
898
922
|
tsconfig,
|
|
899
923
|
tsconfigRaw,
|
|
900
924
|
sourcemap,
|
|
901
|
-
resolve,
|
|
902
925
|
resolver,
|
|
903
926
|
cjsDefault,
|
|
904
927
|
sideEffects,
|
|
@@ -921,10 +944,10 @@ const debug$1 = createDebug("rolldown-plugin-dts:resolver");
|
|
|
921
944
|
function isSourceFile(id) {
|
|
922
945
|
return RE_TS.test(id) || RE_VUE.test(id) || RE_JSON.test(id);
|
|
923
946
|
}
|
|
924
|
-
function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw,
|
|
947
|
+
function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolver, sideEffects }) {
|
|
925
948
|
const baseDtsResolver = createResolver({
|
|
926
949
|
tsconfig,
|
|
927
|
-
resolveNodeModules:
|
|
950
|
+
resolveNodeModules: true,
|
|
928
951
|
ResolverFactory
|
|
929
952
|
});
|
|
930
953
|
const moduleSideEffects = sideEffects ? true : null;
|
|
@@ -932,8 +955,9 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
|
|
|
932
955
|
name: "rolldown-plugin-dts:resolver",
|
|
933
956
|
resolveId: {
|
|
934
957
|
order: "pre",
|
|
958
|
+
filter: [include(importerId(RE_DTS))],
|
|
935
959
|
async handler(id, importer, options) {
|
|
936
|
-
if (!importer
|
|
960
|
+
if (!importer) return;
|
|
937
961
|
const external = {
|
|
938
962
|
id,
|
|
939
963
|
external: true,
|
|
@@ -945,16 +969,16 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
|
|
|
945
969
|
}
|
|
946
970
|
const rolldownResolution = await this.resolve(id, importer, options);
|
|
947
971
|
debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
|
|
972
|
+
if (rolldownResolution?.external) {
|
|
973
|
+
debug$1("Rolldown marked dts import as external:", id);
|
|
974
|
+
return external;
|
|
975
|
+
}
|
|
948
976
|
const dtsResolution = await resolveDtsPath(id, importer, rolldownResolution);
|
|
949
977
|
debug$1("Dts resolution for dts import %O from %O: %O", id, importer, dtsResolution);
|
|
950
978
|
if (!dtsResolution) {
|
|
951
979
|
debug$1("Unresolvable dts import:", id, "from", importer);
|
|
952
980
|
return isFilePath(id) ? null : external;
|
|
953
981
|
}
|
|
954
|
-
if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) {
|
|
955
|
-
debug$1("Externalizing node_modules dts import:", id);
|
|
956
|
-
return external;
|
|
957
|
-
}
|
|
958
982
|
if (RE_DTS.test(dtsResolution)) {
|
|
959
983
|
debug$1("Resolving dts import to declaration file:", id);
|
|
960
984
|
return {
|
|
@@ -973,14 +997,10 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolve, resolver,
|
|
|
973
997
|
}
|
|
974
998
|
}
|
|
975
999
|
};
|
|
976
|
-
function shouldBundleNodeModule(id) {
|
|
977
|
-
if (typeof resolve === "boolean") return resolve;
|
|
978
|
-
return resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
|
|
979
|
-
}
|
|
980
1000
|
async function resolveDtsPath(id, importer, rolldownResolution) {
|
|
981
1001
|
let dtsPath;
|
|
982
1002
|
if (resolver === "tsc") {
|
|
983
|
-
const { tscResolve } = await import("./resolver-
|
|
1003
|
+
const { tscResolve } = await import("./resolver-DksQRwY1.mjs");
|
|
984
1004
|
dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
|
|
985
1005
|
} else dtsPath = baseDtsResolver(id, importer);
|
|
986
1006
|
debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
|
|
@@ -1011,4 +1031,4 @@ function dts(options = {}) {
|
|
|
1011
1031
|
}
|
|
1012
1032
|
|
|
1013
1033
|
//#endregion
|
|
1014
|
-
export {
|
|
1034
|
+
export { createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
2
|
-
import { n as
|
|
2
|
+
import { n as RE_DTS, r as RE_DTS_MAP } from "./filename-Cqnsj8Gp.mjs";
|
|
3
|
+
import { n as globalContext } from "./context-EuY-ImLj.mjs";
|
|
3
4
|
const {
|
|
4
5
|
createRequire
|
|
5
6
|
} = globalThis.process.getBuiltinModule("node:module");
|
|
@@ -108,7 +109,7 @@ function tscEmitBuild(tscOptions) {
|
|
|
108
109
|
let code;
|
|
109
110
|
let map;
|
|
110
111
|
for (const outputFile of outputFiles) {
|
|
111
|
-
if (
|
|
112
|
+
if (RE_DTS.test(outputFile)) {
|
|
112
113
|
if (!fsSystem.fileExists(outputFile)) {
|
|
113
114
|
console.warn(`[rolldown-plugin-dts] Unable to read file ${outputFile}`);
|
|
114
115
|
continue;
|
|
@@ -116,7 +117,7 @@ function tscEmitBuild(tscOptions) {
|
|
|
116
117
|
code = fsSystem.readFile(outputFile);
|
|
117
118
|
continue;
|
|
118
119
|
}
|
|
119
|
-
if (
|
|
120
|
+
if (RE_DTS_MAP.test(outputFile)) {
|
|
120
121
|
if (!fsSystem.fileExists(outputFile)) continue;
|
|
121
122
|
const text = fsSystem.readFile(outputFile);
|
|
122
123
|
if (!text) {
|
package/dist/tsc-context.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as globalContext, i as createContext, n as SourceFileToProjectMap, o as invalidateContextFile, r as TscContext, t as ParsedProject } from "./context-
|
|
1
|
+
import { a as globalContext, i as createContext, n as SourceFileToProjectMap, o as invalidateContextFile, r as TscContext, t as ParsedProject } from "./context-CCPZT79j.mjs";
|
|
2
2
|
export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
|
package/dist/tsc-context.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-
|
|
1
|
+
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-EuY-ImLj.mjs";
|
|
2
2
|
|
|
3
3
|
export { createContext, globalContext, invalidateContextFile };
|
package/dist/tsc-worker.d.mts
CHANGED
package/dist/tsc-worker.mjs
CHANGED
package/dist/tsc.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { i as TscResult, n as TscModule, r as TscOptions, t as tscEmit } from "./index-DWPGYc3m.mjs";
|
|
1
|
+
import { i as TscResult, n as TscModule, r as TscOptions, t as tscEmit } from "./index-C8o_kIRC.mjs";
|
|
3
2
|
export { TscModule, TscOptions, TscResult, tscEmit };
|
package/dist/tsc.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.1",
|
|
5
5
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,8 +30,6 @@
|
|
|
30
30
|
"./tsc-worker": "./dist/tsc-worker.mjs",
|
|
31
31
|
"./package.json": "./package.json"
|
|
32
32
|
},
|
|
33
|
-
"main": "./dist/index.mjs",
|
|
34
|
-
"module": "./dist/index.mjs",
|
|
35
33
|
"types": "./dist/index.d.mts",
|
|
36
34
|
"files": [
|
|
37
35
|
"dist"
|
|
@@ -64,9 +62,9 @@
|
|
|
64
62
|
}
|
|
65
63
|
},
|
|
66
64
|
"dependencies": {
|
|
67
|
-
"@babel/generator": "^7.28.
|
|
68
|
-
"@babel/parser": "^7.28.
|
|
69
|
-
"@babel/types": "^7.28.
|
|
65
|
+
"@babel/generator": "^7.28.6",
|
|
66
|
+
"@babel/parser": "^7.28.6",
|
|
67
|
+
"@babel/types": "^7.28.6",
|
|
70
68
|
"ast-kit": "^2.2.0",
|
|
71
69
|
"birpc": "^4.0.0",
|
|
72
70
|
"dts-resolver": "^2.1.3",
|
|
@@ -74,28 +72,32 @@
|
|
|
74
72
|
"obug": "^2.1.1"
|
|
75
73
|
},
|
|
76
74
|
"devDependencies": {
|
|
77
|
-
"@sxzz/eslint-config": "^7.4.
|
|
75
|
+
"@sxzz/eslint-config": "^7.4.5",
|
|
78
76
|
"@sxzz/prettier-config": "^2.2.6",
|
|
79
77
|
"@sxzz/test-utils": "^0.5.15",
|
|
80
78
|
"@types/babel__generator": "^7.27.0",
|
|
81
|
-
"@types/node": "^25.0.
|
|
82
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
79
|
+
"@types/node": "^25.0.8",
|
|
80
|
+
"@typescript/native-preview": "7.0.0-dev.20260114.1",
|
|
83
81
|
"@volar/typescript": "^2.4.27",
|
|
84
|
-
"@vue/language-core": "^3.2.
|
|
82
|
+
"@vue/language-core": "^3.2.2",
|
|
85
83
|
"arktype": "^2.1.29",
|
|
86
|
-
"bumpp": "^10.
|
|
87
|
-
"diff": "^8.0.
|
|
84
|
+
"bumpp": "^10.4.0",
|
|
85
|
+
"diff": "^8.0.3",
|
|
88
86
|
"eslint": "^9.39.2",
|
|
89
87
|
"prettier": "^3.7.4",
|
|
90
|
-
"rolldown": "^1.0.0-beta.
|
|
88
|
+
"rolldown": "^1.0.0-beta.60",
|
|
89
|
+
"rolldown-plugin-dts-snapshot": "^0.3.2",
|
|
91
90
|
"rolldown-plugin-require-cjs": "^0.3.3",
|
|
92
91
|
"rollup-plugin-dts": "^6.3.0",
|
|
93
92
|
"tinyglobby": "^0.2.15",
|
|
94
|
-
"tsdown": "^0.
|
|
93
|
+
"tsdown": "^0.20.0-beta.2",
|
|
95
94
|
"typescript": "^5.9.3",
|
|
96
|
-
"vitest": "^4.0.
|
|
95
|
+
"vitest": "^4.0.17",
|
|
97
96
|
"vue": "^3.5.26",
|
|
98
|
-
"vue-tsc": "^3.2.
|
|
97
|
+
"vue-tsc": "^3.2.2"
|
|
98
|
+
},
|
|
99
|
+
"resolutions": {
|
|
100
|
+
"rolldown": "^1.0.0-beta.60"
|
|
99
101
|
},
|
|
100
102
|
"prettier": "@sxzz/prettier-config",
|
|
101
103
|
"scripts": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|