rolldown-plugin-dts 0.13.7 → 0.13.9
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 +127 -85
- package/dist/{filename-B0ey8LZi.d.ts → filename-TbnZq0n4.d.ts} +1 -1
- package/dist/filename.d.ts +1 -1
- package/dist/index.d.ts +68 -24
- package/dist/index.js +118 -69
- package/dist/{utils/tsc-worker.d.ts → tsc/worker.d.ts} +12 -5
- package/dist/{utils/tsc-worker.js → tsc/worker.js} +3 -3
- package/dist/tsc-AS4dxecO.js +221 -0
- package/dist/tsc-CJ55BCXi.js +3 -0
- package/package.json +21 -13
- package/dist/tsc-CN7vXGIS.js +0 -3
- package/dist/tsc-DSR26k5c.js +0 -121
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A Rolldown plugin to generate and bundle dts files.
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Requires **`rolldown@1.0.0-beta.9`** or later.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npm i rolldown-plugin-dts
|
|
@@ -31,90 +31,132 @@ You can find an example in [here](./rolldown.config.ts).
|
|
|
31
31
|
|
|
32
32
|
## Options
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
34
|
+
Configuration options for the plugin.
|
|
35
|
+
Certainly! Here’s your documentation with simplified section titles (just the option name, no type annotation):
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
### cwd
|
|
40
|
+
|
|
41
|
+
The directory in which the plugin will search for the `tsconfig.json` file.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### dtsInput
|
|
46
|
+
|
|
47
|
+
Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
|
|
48
|
+
|
|
49
|
+
When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### emitDtsOnly
|
|
54
|
+
|
|
55
|
+
If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
|
|
56
|
+
|
|
57
|
+
This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### tsconfig
|
|
62
|
+
|
|
63
|
+
The path to the `tsconfig.json` file.
|
|
64
|
+
|
|
65
|
+
- If set to `false`, the plugin will ignore any `tsconfig.json` file.
|
|
66
|
+
- You can still specify `compilerOptions` directly in the options.
|
|
67
|
+
|
|
68
|
+
**Default:** `'tsconfig.json'`
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### tsconfigRaw
|
|
73
|
+
|
|
74
|
+
Pass a raw `tsconfig.json` object directly to the plugin.
|
|
75
|
+
|
|
76
|
+
See: [TypeScript tsconfig documentation](https://www.typescriptlang.org/tsconfig)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### incremental
|
|
81
|
+
|
|
82
|
+
Controls how project references and incremental builds are handled:
|
|
83
|
+
|
|
84
|
+
- If your `tsconfig.json` uses [`references`](https://www.typescriptlang.org/tsconfig/#references), 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.
|
|
85
|
+
- If `incremental` is `true`, all built files (including [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)) will be written to disk, similar to running `tsc -b` in your project.
|
|
86
|
+
- If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
|
|
87
|
+
|
|
88
|
+
Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
|
|
89
|
+
|
|
90
|
+
**Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
|
|
91
|
+
|
|
92
|
+
> [!NOTE]
|
|
93
|
+
> This option is only used when [`isolatedDeclarations`](#isolateddeclarations) is `false`.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### compilerOptions
|
|
98
|
+
|
|
99
|
+
Override the `compilerOptions` specified in `tsconfig.json`.
|
|
100
|
+
|
|
101
|
+
See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/tsconfig/#compilerOptions)
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### isolatedDeclarations
|
|
106
|
+
|
|
107
|
+
If `true`, the plugin will generate `.d.ts` files using [Oxc](https://oxc.rs/docs/guide/usage/transformer.html), which is significantly faster than the TypeScript compiler.
|
|
108
|
+
|
|
109
|
+
This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
### sourcemap
|
|
114
|
+
|
|
115
|
+
If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### resolve
|
|
120
|
+
|
|
121
|
+
Resolve external types used in `.d.ts` files from `node_modules`.
|
|
122
|
+
|
|
123
|
+
- If `true`, all external types are resolved.
|
|
124
|
+
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### vue
|
|
129
|
+
|
|
130
|
+
If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### parallel
|
|
135
|
+
|
|
136
|
+
If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### eager
|
|
141
|
+
|
|
142
|
+
If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
|
|
143
|
+
|
|
144
|
+
This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### tsgo
|
|
149
|
+
|
|
150
|
+
**[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
|
|
151
|
+
|
|
152
|
+
- To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
|
|
153
|
+
- Set to `true` to enable `tsgo` for the current project.
|
|
154
|
+
- If a string is provided, it should be the root path of your source files.
|
|
155
|
+
|
|
156
|
+
> [!WARNING]
|
|
157
|
+
> This option is experimental and not yet recommended for production environments.
|
|
158
|
+
|
|
159
|
+
---
|
|
118
160
|
|
|
119
161
|
## Differences from `rollup-plugin-dts`
|
|
120
162
|
|
|
@@ -11,4 +11,4 @@ declare function filename_ts_to_dts(id: string): string;
|
|
|
11
11
|
declare function filename_dts_to(id: string, ext: "js" | "ts"): string;
|
|
12
12
|
declare function isRelative(id: string): boolean;
|
|
13
13
|
//#endregion
|
|
14
|
-
export { RE_CSS
|
|
14
|
+
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative };
|
package/dist/filename.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RE_CSS
|
|
1
|
+
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative } from "./filename-TbnZq0n4.js";
|
|
2
2
|
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import { RE_CSS
|
|
2
|
-
import { TsConfigJson } from "get-tsconfig";
|
|
1
|
+
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-TbnZq0n4.js";
|
|
3
2
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
3
|
+
import { TsConfigJson } from "get-tsconfig";
|
|
4
4
|
import { Plugin } from "rolldown";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
7
|
-
declare function createFakeJsPlugin({
|
|
8
|
-
dtsInput,
|
|
9
|
-
sourcemap
|
|
10
|
-
}: Pick<OptionsResolved, "dtsInput" | "sourcemap">): Plugin;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/generate.d.ts
|
|
13
|
-
declare function createGeneratePlugin({
|
|
14
|
-
tsconfigRaw,
|
|
15
|
-
tsconfigDir,
|
|
16
|
-
isolatedDeclarations,
|
|
17
|
-
emitDtsOnly,
|
|
18
|
-
vue,
|
|
19
|
-
parallel,
|
|
20
|
-
eager
|
|
21
|
-
}: Pick<OptionsResolved, "tsconfigRaw" | "tsconfigDir" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager">): Plugin;
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/index.d.ts
|
|
6
|
+
//#region src/options.d.ts
|
|
24
7
|
interface Options {
|
|
25
8
|
/**
|
|
26
9
|
* The directory in which the plugin will search for the `tsconfig.json` file.
|
|
@@ -54,6 +37,36 @@ interface Options {
|
|
|
54
37
|
*/
|
|
55
38
|
tsconfigRaw?: Omit<TsConfigJson, "compilerOptions">;
|
|
56
39
|
/**
|
|
40
|
+
* If your tsconfig.json has
|
|
41
|
+
* [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
|
|
42
|
+
* `rolldown-plugin-dts` will use [`tsc
|
|
43
|
+
* -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript)
|
|
44
|
+
* to build the project and all referenced projects before emitting `.d.ts`
|
|
45
|
+
* files.
|
|
46
|
+
*
|
|
47
|
+
* In such case, if this option is `true`, `rolldown-plugin-dts` will write
|
|
48
|
+
* down all built files into your disk, including
|
|
49
|
+
* [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
50
|
+
* and other built files. This is equivalent to running `tsc -b` in your
|
|
51
|
+
* project.
|
|
52
|
+
*
|
|
53
|
+
* Otherwise, if this option is `false`, `rolldown-plugin-dts` will write
|
|
54
|
+
* built files only into memory and leave a small footprint in your disk.
|
|
55
|
+
*
|
|
56
|
+
* Enabling this option will decrease the build time by caching previous build
|
|
57
|
+
* results. This is helpful when you have a large project with multiple
|
|
58
|
+
* referenced projects.
|
|
59
|
+
*
|
|
60
|
+
* By default, `incremental` is `true` if your tsconfig has
|
|
61
|
+
* [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or
|
|
62
|
+
* [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
63
|
+
* enabled.
|
|
64
|
+
*
|
|
65
|
+
* This option is only used when {@link Options.isolatedDeclarations} is
|
|
66
|
+
* `false`.
|
|
67
|
+
*/
|
|
68
|
+
incremental?: boolean;
|
|
69
|
+
/**
|
|
57
70
|
* Override the `compilerOptions` specified in `tsconfig.json`.
|
|
58
71
|
*
|
|
59
72
|
* @see https://www.typescriptlang.org/tsconfig/#compilerOptions
|
|
@@ -89,18 +102,25 @@ interface Options {
|
|
|
89
102
|
* This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
|
|
90
103
|
*/
|
|
91
104
|
eager?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* **[Experimental]** Enables DTS generation using `tsgo`.
|
|
107
|
+
*
|
|
108
|
+
* To use this option, make sure `@typescript/native-preview` is installed as a dependency.
|
|
109
|
+
*
|
|
110
|
+
* **Note:** This option is not yet recommended for production environments.
|
|
111
|
+
*/
|
|
112
|
+
tsgo?: boolean | string;
|
|
92
113
|
}
|
|
93
114
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
94
115
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
95
116
|
tsconfig: string | undefined;
|
|
96
117
|
isolatedDeclarations: IsolatedDeclarationsOptions | false;
|
|
97
118
|
tsconfigRaw: TsConfigJson;
|
|
98
|
-
tsconfigDir: string;
|
|
99
119
|
}>;
|
|
100
|
-
declare function dts(options?: Options): Plugin[];
|
|
101
120
|
declare function resolveOptions({
|
|
102
121
|
cwd,
|
|
103
122
|
tsconfig,
|
|
123
|
+
incremental,
|
|
104
124
|
compilerOptions,
|
|
105
125
|
tsconfigRaw: overriddenTsconfigRaw,
|
|
106
126
|
isolatedDeclarations,
|
|
@@ -110,7 +130,31 @@ declare function resolveOptions({
|
|
|
110
130
|
resolve,
|
|
111
131
|
vue,
|
|
112
132
|
parallel,
|
|
113
|
-
eager
|
|
133
|
+
eager,
|
|
134
|
+
tsgo
|
|
114
135
|
}: Options): OptionsResolved;
|
|
115
136
|
//#endregion
|
|
116
|
-
|
|
137
|
+
//#region src/fake-js.d.ts
|
|
138
|
+
declare function createFakeJsPlugin({
|
|
139
|
+
dtsInput,
|
|
140
|
+
sourcemap
|
|
141
|
+
}: Pick<OptionsResolved, "dtsInput" | "sourcemap">): Plugin;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/generate.d.ts
|
|
144
|
+
declare function createGeneratePlugin({
|
|
145
|
+
tsconfig,
|
|
146
|
+
tsconfigRaw,
|
|
147
|
+
incremental,
|
|
148
|
+
cwd,
|
|
149
|
+
isolatedDeclarations,
|
|
150
|
+
emitDtsOnly,
|
|
151
|
+
vue,
|
|
152
|
+
parallel,
|
|
153
|
+
eager,
|
|
154
|
+
tsgo
|
|
155
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo">): Plugin;
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/index.d.ts
|
|
158
|
+
declare function dts(options?: Options): Plugin[];
|
|
159
|
+
//#endregion
|
|
160
|
+
export { Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts } from "./filename-Dpr2dKWZ.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import process from "node:process";
|
|
4
3
|
import Debug from "debug";
|
|
5
|
-
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
6
4
|
import _generate from "@babel/generator";
|
|
7
5
|
import { parse } from "@babel/parser";
|
|
8
6
|
import * as t from "@babel/types";
|
|
9
7
|
import { isDeclarationType, isTypeOf } from "ast-kit";
|
|
10
|
-
import { fork } from "node:child_process";
|
|
8
|
+
import { fork, spawn } from "node:child_process";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
11
12
|
import { createBirpc } from "birpc";
|
|
12
13
|
import { ResolverFactory, isolatedDeclaration } from "rolldown/experimental";
|
|
14
|
+
import process from "node:process";
|
|
15
|
+
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
13
16
|
import { createResolver } from "dts-resolver";
|
|
14
17
|
|
|
15
18
|
//#region src/dts-input.ts
|
|
@@ -230,8 +233,8 @@ const generate = _generate.default || _generate;
|
|
|
230
233
|
function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
231
234
|
let symbolIdx = 0;
|
|
232
235
|
let identifierIdx = 0;
|
|
233
|
-
const symbolMap = new Map();
|
|
234
|
-
const commentsMap = new Map();
|
|
236
|
+
const symbolMap = /* @__PURE__ */ new Map();
|
|
237
|
+
const commentsMap = /* @__PURE__ */ new Map();
|
|
235
238
|
return {
|
|
236
239
|
name: "rolldown-plugin-dts:fake-js",
|
|
237
240
|
outputOptions(options) {
|
|
@@ -270,7 +273,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
270
273
|
commentsMap.set(id, directives);
|
|
271
274
|
}
|
|
272
275
|
const appendStmts = [];
|
|
273
|
-
const namespaceStmts = new Map();
|
|
276
|
+
const namespaceStmts = /* @__PURE__ */ new Map();
|
|
274
277
|
for (const [i, stmt] of program.body.entries()) {
|
|
275
278
|
const setStmt = (node) => program.body[i] = node;
|
|
276
279
|
if (rewriteImportExport(stmt, setStmt)) continue;
|
|
@@ -383,8 +386,8 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
383
386
|
return inheritNodeComments(node, original.decl);
|
|
384
387
|
}).filter((node) => !!node);
|
|
385
388
|
if (program.body.length === 0) return "export { };";
|
|
386
|
-
const comments = new Set();
|
|
387
|
-
const commentsValue = new Set();
|
|
389
|
+
const comments = /* @__PURE__ */ new Set();
|
|
390
|
+
const commentsValue = /* @__PURE__ */ new Set();
|
|
388
391
|
for (const id of chunk.moduleIds) {
|
|
389
392
|
const preserveComments = commentsMap.get(id);
|
|
390
393
|
if (preserveComments) {
|
|
@@ -420,8 +423,8 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
420
423
|
return symbolMap.get(symbolId);
|
|
421
424
|
}
|
|
422
425
|
function collectDependencies(node, namespaceStmts) {
|
|
423
|
-
const deps = new Set();
|
|
424
|
-
const seen = new Set();
|
|
426
|
+
const deps = /* @__PURE__ */ new Set();
|
|
427
|
+
const seen = /* @__PURE__ */ new Set();
|
|
425
428
|
walk(node, { leave(node$1) {
|
|
426
429
|
if (node$1.type === "ExportNamedDeclaration") {
|
|
427
430
|
for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
|
|
@@ -510,8 +513,8 @@ function patchImportSource(node) {
|
|
|
510
513
|
}
|
|
511
514
|
}
|
|
512
515
|
function patchTsNamespace(nodes) {
|
|
513
|
-
const emptyObjectAssignments = new Map();
|
|
514
|
-
const removed = new Set();
|
|
516
|
+
const emptyObjectAssignments = /* @__PURE__ */ new Map();
|
|
517
|
+
const removed = /* @__PURE__ */ new Set();
|
|
515
518
|
for (const [i, node] of nodes.entries()) {
|
|
516
519
|
if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].id.type === "Identifier" && node.declarations[0].init?.type === "ObjectExpression" && node.declarations[0].init.properties.length === 0) emptyObjectAssignments.set(node.declarations[0].id.name, node);
|
|
517
520
|
if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || !node.expression.callee.name.startsWith("__export")) continue;
|
|
@@ -607,9 +610,14 @@ function inheritNodeComments(oldNode, newNode) {
|
|
|
607
610
|
//#endregion
|
|
608
611
|
//#region src/generate.ts
|
|
609
612
|
const debug$1 = Debug("rolldown-plugin-dts:generate");
|
|
610
|
-
const WORKER_URL = "./
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
+
const WORKER_URL = "./tsc/worker.js";
|
|
614
|
+
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
615
|
+
const child = spawn(...args);
|
|
616
|
+
child.on("close", () => resolve());
|
|
617
|
+
child.on("error", (error) => reject(error));
|
|
618
|
+
});
|
|
619
|
+
function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo }) {
|
|
620
|
+
const dtsMap = /* @__PURE__ */ new Map();
|
|
613
621
|
/**
|
|
614
622
|
* A map of input id to output file name
|
|
615
623
|
*
|
|
@@ -619,11 +627,13 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
|
|
|
619
627
|
* ['/absolute/path/to/src/source_file.ts', 'dist/foo/index'],
|
|
620
628
|
* ])
|
|
621
629
|
*/
|
|
622
|
-
const inputAliasMap = new Map();
|
|
630
|
+
const inputAliasMap = /* @__PURE__ */ new Map();
|
|
623
631
|
let childProcess;
|
|
624
632
|
let rpc;
|
|
625
|
-
let
|
|
626
|
-
|
|
633
|
+
let tscModule;
|
|
634
|
+
let tscContext;
|
|
635
|
+
let tsgoDist;
|
|
636
|
+
if (!tsgo && parallel) {
|
|
627
637
|
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
628
638
|
rpc = createBirpc({}, {
|
|
629
639
|
post: (data) => childProcess.send(data),
|
|
@@ -633,7 +643,24 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
|
|
|
633
643
|
return {
|
|
634
644
|
name: "rolldown-plugin-dts:generate",
|
|
635
645
|
async buildStart(options) {
|
|
636
|
-
if (
|
|
646
|
+
if (tsgo) {
|
|
647
|
+
const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
|
|
648
|
+
const { default: getExePath } = await import(new URL("./lib/getExePath.js", tsgoPkg).href);
|
|
649
|
+
const tsgo$1 = getExePath();
|
|
650
|
+
tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
651
|
+
await spawnAsync(tsgo$1, [
|
|
652
|
+
"--noEmit",
|
|
653
|
+
"false",
|
|
654
|
+
"--declaration",
|
|
655
|
+
"--emitDeclarationOnly",
|
|
656
|
+
...tsconfig ? ["-p", tsconfig] : [],
|
|
657
|
+
"--outDir",
|
|
658
|
+
tsgoDist
|
|
659
|
+
], { stdio: "inherit" });
|
|
660
|
+
} else if (!parallel && (!isolatedDeclarations || vue)) {
|
|
661
|
+
tscModule = await import("./tsc-CJ55BCXi.js");
|
|
662
|
+
tscContext = eager ? void 0 : tscModule.createContext();
|
|
663
|
+
}
|
|
637
664
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
638
665
|
debug$1("resolving input alias %s -> %s", name, id);
|
|
639
666
|
let resolved = await this.resolve(id);
|
|
@@ -698,7 +725,12 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
|
|
|
698
725
|
let dtsCode;
|
|
699
726
|
let map;
|
|
700
727
|
debug$1("generate dts %s from %s", dtsId, id);
|
|
701
|
-
if (
|
|
728
|
+
if (tsgo) {
|
|
729
|
+
if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
|
|
730
|
+
const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(typeof tsgo === "string" ? tsgo : "src"), filename_ts_to_dts(id)));
|
|
731
|
+
if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
|
|
732
|
+
else throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
|
|
733
|
+
} else if (isolatedDeclarations && !RE_VUE.test(id)) {
|
|
702
734
|
const result = isolatedDeclaration(id, code, isolatedDeclarations);
|
|
703
735
|
if (result.errors.length) {
|
|
704
736
|
const [error] = result.errors;
|
|
@@ -715,15 +747,18 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
|
|
|
715
747
|
} else {
|
|
716
748
|
const entries = eager ? void 0 : Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id);
|
|
717
749
|
const options = {
|
|
750
|
+
tsconfig,
|
|
718
751
|
tsconfigRaw,
|
|
719
|
-
|
|
752
|
+
incremental,
|
|
753
|
+
cwd,
|
|
720
754
|
entries,
|
|
721
755
|
id,
|
|
722
|
-
vue
|
|
756
|
+
vue,
|
|
757
|
+
context: tscContext
|
|
723
758
|
};
|
|
724
759
|
let result;
|
|
725
760
|
if (parallel) result = await rpc.tscEmit(options);
|
|
726
|
-
else result = tscEmit(options);
|
|
761
|
+
else result = tscModule.tscEmit(options);
|
|
727
762
|
if (result.error) return this.error(result.error);
|
|
728
763
|
dtsCode = result.code;
|
|
729
764
|
map = result.map;
|
|
@@ -738,14 +773,71 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
|
|
|
738
773
|
generateBundle: emitDtsOnly ? (options, bundle) => {
|
|
739
774
|
for (const fileName of Object.keys(bundle)) if (bundle[fileName].type === "chunk" && !RE_DTS.test(fileName) && !RE_DTS_MAP.test(fileName)) delete bundle[fileName];
|
|
740
775
|
} : void 0,
|
|
741
|
-
buildEnd() {
|
|
776
|
+
async buildEnd() {
|
|
742
777
|
childProcess?.kill();
|
|
778
|
+
if (tsgoDist) await rm(tsgoDist, {
|
|
779
|
+
recursive: true,
|
|
780
|
+
force: true
|
|
781
|
+
}).catch(() => {});
|
|
782
|
+
tscContext = tsgoDist = void 0;
|
|
743
783
|
}
|
|
744
784
|
};
|
|
745
785
|
}
|
|
746
786
|
|
|
747
787
|
//#endregion
|
|
748
|
-
//#region src/
|
|
788
|
+
//#region src/options.ts
|
|
789
|
+
let warnedTsgo = false;
|
|
790
|
+
function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false }) {
|
|
791
|
+
let resolvedTsconfig;
|
|
792
|
+
if (tsconfig === true || tsconfig == null) {
|
|
793
|
+
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
794
|
+
tsconfig = path$1;
|
|
795
|
+
resolvedTsconfig = config;
|
|
796
|
+
} else if (typeof tsconfig === "string") {
|
|
797
|
+
tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
|
|
798
|
+
resolvedTsconfig = parseTsconfig(tsconfig);
|
|
799
|
+
} else tsconfig = void 0;
|
|
800
|
+
compilerOptions = {
|
|
801
|
+
...resolvedTsconfig?.compilerOptions,
|
|
802
|
+
...compilerOptions
|
|
803
|
+
};
|
|
804
|
+
incremental ||= compilerOptions.incremental || !!compilerOptions.tsBuildInfoFile;
|
|
805
|
+
sourcemap ??= !!compilerOptions.declarationMap;
|
|
806
|
+
compilerOptions.declarationMap = sourcemap;
|
|
807
|
+
const tsconfigRaw = {
|
|
808
|
+
...resolvedTsconfig,
|
|
809
|
+
...overriddenTsconfigRaw,
|
|
810
|
+
compilerOptions
|
|
811
|
+
};
|
|
812
|
+
if (isolatedDeclarations == null) isolatedDeclarations = !!compilerOptions?.isolatedDeclarations;
|
|
813
|
+
if (isolatedDeclarations === true) isolatedDeclarations = {};
|
|
814
|
+
if (isolatedDeclarations) {
|
|
815
|
+
isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
816
|
+
isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
|
|
817
|
+
}
|
|
818
|
+
if (tsgo && !warnedTsgo) {
|
|
819
|
+
console.warn("The `tsgo` option is experimental and may change in the future.");
|
|
820
|
+
warnedTsgo = true;
|
|
821
|
+
}
|
|
822
|
+
return {
|
|
823
|
+
cwd,
|
|
824
|
+
tsconfig,
|
|
825
|
+
tsconfigRaw,
|
|
826
|
+
incremental,
|
|
827
|
+
isolatedDeclarations,
|
|
828
|
+
sourcemap,
|
|
829
|
+
dtsInput,
|
|
830
|
+
emitDtsOnly,
|
|
831
|
+
resolve,
|
|
832
|
+
vue,
|
|
833
|
+
parallel,
|
|
834
|
+
eager,
|
|
835
|
+
tsgo
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
//#endregion
|
|
840
|
+
//#region src/resolver.ts
|
|
749
841
|
function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
750
842
|
const resolver = createResolver({
|
|
751
843
|
tsconfig,
|
|
@@ -753,7 +845,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
753
845
|
ResolverFactory
|
|
754
846
|
});
|
|
755
847
|
return {
|
|
756
|
-
name: "rolldown-plugin-dts:
|
|
848
|
+
name: "rolldown-plugin-dts:resolver",
|
|
757
849
|
resolveId: {
|
|
758
850
|
order: "pre",
|
|
759
851
|
async handler(id, importer, options) {
|
|
@@ -804,49 +896,6 @@ function dts(options = {}) {
|
|
|
804
896
|
plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
|
|
805
897
|
return plugins;
|
|
806
898
|
}
|
|
807
|
-
function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false }) {
|
|
808
|
-
let resolvedTsconfig;
|
|
809
|
-
if (tsconfig === true || tsconfig == null) {
|
|
810
|
-
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
811
|
-
tsconfig = path$1;
|
|
812
|
-
resolvedTsconfig = config;
|
|
813
|
-
} else if (typeof tsconfig === "string") {
|
|
814
|
-
tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
|
|
815
|
-
resolvedTsconfig = parseTsconfig(tsconfig);
|
|
816
|
-
} else tsconfig = void 0;
|
|
817
|
-
compilerOptions = {
|
|
818
|
-
...resolvedTsconfig?.compilerOptions,
|
|
819
|
-
...compilerOptions
|
|
820
|
-
};
|
|
821
|
-
sourcemap ??= !!compilerOptions.declarationMap;
|
|
822
|
-
compilerOptions.declarationMap = sourcemap;
|
|
823
|
-
const tsconfigRaw = {
|
|
824
|
-
...resolvedTsconfig,
|
|
825
|
-
...overriddenTsconfigRaw,
|
|
826
|
-
compilerOptions
|
|
827
|
-
};
|
|
828
|
-
const tsconfigDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
829
|
-
if (isolatedDeclarations == null) isolatedDeclarations = !!compilerOptions?.isolatedDeclarations;
|
|
830
|
-
if (isolatedDeclarations === true) isolatedDeclarations = {};
|
|
831
|
-
if (isolatedDeclarations) {
|
|
832
|
-
isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
833
|
-
isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
|
|
834
|
-
}
|
|
835
|
-
return {
|
|
836
|
-
cwd,
|
|
837
|
-
tsconfig,
|
|
838
|
-
tsconfigDir,
|
|
839
|
-
tsconfigRaw,
|
|
840
|
-
isolatedDeclarations,
|
|
841
|
-
sourcemap,
|
|
842
|
-
dtsInput,
|
|
843
|
-
emitDtsOnly,
|
|
844
|
-
resolve,
|
|
845
|
-
vue,
|
|
846
|
-
parallel,
|
|
847
|
-
eager
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
899
|
|
|
851
900
|
//#endregion
|
|
852
901
|
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { TsConfigJson } from "get-tsconfig";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { SourceMapInput } from "rolldown";
|
|
3
4
|
|
|
4
|
-
//#region src/
|
|
5
|
-
|
|
5
|
+
//#region src/tsc/index.d.ts
|
|
6
|
+
interface TscContext {
|
|
7
|
+
programs: ts.Program[];
|
|
8
|
+
files: Map<string, string>;
|
|
9
|
+
}
|
|
6
10
|
interface TscOptions {
|
|
11
|
+
tsconfig?: string;
|
|
7
12
|
tsconfigRaw: TsConfigJson;
|
|
8
|
-
|
|
13
|
+
cwd: string;
|
|
14
|
+
incremental: boolean;
|
|
9
15
|
entries?: string[];
|
|
10
16
|
id: string;
|
|
11
17
|
vue?: boolean;
|
|
18
|
+
context?: TscContext;
|
|
12
19
|
}
|
|
13
20
|
interface TscResult {
|
|
14
21
|
code?: string;
|
|
15
|
-
map?:
|
|
22
|
+
map?: SourceMapInput;
|
|
16
23
|
error?: string;
|
|
17
24
|
}
|
|
18
25
|
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
19
26
|
//#endregion
|
|
20
|
-
//#region src/
|
|
27
|
+
//#region src/tsc/worker.d.ts
|
|
21
28
|
declare const functions: {
|
|
22
29
|
tscEmit: typeof tscEmit;
|
|
23
30
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tscEmit } from "../tsc-
|
|
2
|
-
import process from "node:process";
|
|
1
|
+
import { tscEmit } from "../tsc-AS4dxecO.js";
|
|
3
2
|
import { createBirpc } from "birpc";
|
|
3
|
+
import process from "node:process";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/tsc/worker.ts
|
|
6
6
|
const functions = { tscEmit };
|
|
7
7
|
createBirpc(functions, {
|
|
8
8
|
post: (data) => process.send(data),
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Debug from "debug";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/tsc/system.ts
|
|
7
|
+
const debug$2 = Debug("rolldown-plugin-dts:tsc-system");
|
|
8
|
+
/**
|
|
9
|
+
* A system that writes files to both memory and disk. It will try read files
|
|
10
|
+
* from memory firstly and fallback to disk if not found.
|
|
11
|
+
*/
|
|
12
|
+
function createFsSystem(files) {
|
|
13
|
+
return {
|
|
14
|
+
...ts.sys,
|
|
15
|
+
write(message) {
|
|
16
|
+
debug$2(message);
|
|
17
|
+
},
|
|
18
|
+
resolvePath(path$1) {
|
|
19
|
+
if (files.has(path$1)) return path$1;
|
|
20
|
+
return ts.sys.resolvePath(path$1);
|
|
21
|
+
},
|
|
22
|
+
directoryExists(directory) {
|
|
23
|
+
if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
|
|
24
|
+
return ts.sys.directoryExists(directory);
|
|
25
|
+
},
|
|
26
|
+
fileExists(fileName) {
|
|
27
|
+
if (files.has(fileName)) return true;
|
|
28
|
+
return ts.sys.fileExists(fileName);
|
|
29
|
+
},
|
|
30
|
+
readFile(fileName, ...args) {
|
|
31
|
+
if (files.has(fileName)) return files.get(fileName);
|
|
32
|
+
return ts.sys.readFile(fileName, ...args);
|
|
33
|
+
},
|
|
34
|
+
writeFile(path$1, data, ...args) {
|
|
35
|
+
files.set(path$1, data);
|
|
36
|
+
ts.sys.writeFile(path$1, data, ...args);
|
|
37
|
+
},
|
|
38
|
+
deleteFile(fileName, ...args) {
|
|
39
|
+
files.delete(fileName);
|
|
40
|
+
ts.sys.deleteFile?.(fileName, ...args);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createMemorySystem(files) {
|
|
45
|
+
return {
|
|
46
|
+
...createFsSystem(files),
|
|
47
|
+
writeFile(path$1, data) {
|
|
48
|
+
files.set(path$1, data);
|
|
49
|
+
},
|
|
50
|
+
deleteFile(fileName) {
|
|
51
|
+
files.delete(fileName);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/tsc/vue.ts
|
|
58
|
+
const debug$1 = Debug("rolldown-plugin-dts:vue");
|
|
59
|
+
let createVueProgram;
|
|
60
|
+
const require = createRequire(import.meta.url);
|
|
61
|
+
function loadVueLanguageTools() {
|
|
62
|
+
try {
|
|
63
|
+
const vueTscPath = require.resolve("vue-tsc");
|
|
64
|
+
const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
65
|
+
const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
66
|
+
return {
|
|
67
|
+
proxyCreateProgram,
|
|
68
|
+
vue
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
debug$1("vue language tools not found", error);
|
|
72
|
+
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function createVueProgramFactory(ts$1) {
|
|
76
|
+
if (createVueProgram) return createVueProgram;
|
|
77
|
+
debug$1("loading vue language tools");
|
|
78
|
+
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
79
|
+
return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
|
|
80
|
+
const { configFilePath } = options.options;
|
|
81
|
+
const vueOptions = typeof configFilePath === "string" ? vue.createParsedCommandLine(ts$2, ts$2.sys, configFilePath.replaceAll("\\", "/")).vueOptions : vue.getDefaultCompilerOptions();
|
|
82
|
+
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
|
|
83
|
+
return { languagePlugins: [vueLanguagePlugin] };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/tsc/index.ts
|
|
89
|
+
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
90
|
+
debug(`loaded typescript: ${ts.version}`);
|
|
91
|
+
function createContext() {
|
|
92
|
+
const programs = [];
|
|
93
|
+
const files = /* @__PURE__ */ new Map();
|
|
94
|
+
return {
|
|
95
|
+
programs,
|
|
96
|
+
files
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const globalContext = createContext();
|
|
100
|
+
const formatHost = {
|
|
101
|
+
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
102
|
+
getNewLine: () => ts.sys.newLine,
|
|
103
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
104
|
+
};
|
|
105
|
+
const defaultCompilerOptions = {
|
|
106
|
+
declaration: true,
|
|
107
|
+
noEmit: false,
|
|
108
|
+
emitDeclarationOnly: true,
|
|
109
|
+
noEmitOnError: true,
|
|
110
|
+
checkJs: false,
|
|
111
|
+
declarationMap: false,
|
|
112
|
+
skipLibCheck: true,
|
|
113
|
+
target: 99,
|
|
114
|
+
resolveJsonModule: true,
|
|
115
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
116
|
+
};
|
|
117
|
+
function createOrGetTsModule(options) {
|
|
118
|
+
const { id, entries, context = globalContext } = options;
|
|
119
|
+
const program = context.programs.find((program$1) => {
|
|
120
|
+
const roots = program$1.getRootFileNames();
|
|
121
|
+
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
122
|
+
return roots.includes(id);
|
|
123
|
+
});
|
|
124
|
+
if (program) {
|
|
125
|
+
const sourceFile = program.getSourceFile(id);
|
|
126
|
+
if (sourceFile) return {
|
|
127
|
+
program,
|
|
128
|
+
file: sourceFile
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
debug(`create program for module: ${id}`);
|
|
132
|
+
const module = createTsProgram(options);
|
|
133
|
+
debug(`created program for module: ${id}`);
|
|
134
|
+
context.programs.push(module.program);
|
|
135
|
+
return module;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Build the root project and all its dependencies projects.
|
|
139
|
+
* This is designed for a project (e.g. tsconfig.json) that has "references" to
|
|
140
|
+
* other composite projects (e.g., tsconfig.node.json and tsconfig.app.json).
|
|
141
|
+
* If `incremental` is `true`, the build result will be cached in the
|
|
142
|
+
* `.tsbuildinfo` file so that the next time the project is built (without
|
|
143
|
+
* changes) the build will be super fast. If `incremental` is `false`, the
|
|
144
|
+
* `.tsbuildinfo` file will only be written to the memory.
|
|
145
|
+
*/
|
|
146
|
+
function buildSolution(tsconfig, incremental, context) {
|
|
147
|
+
debug(`building projects for ${tsconfig} with incremental: ${incremental}`);
|
|
148
|
+
const system = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
149
|
+
const host = ts.createSolutionBuilderHost(system);
|
|
150
|
+
const builder = ts.createSolutionBuilder(host, [tsconfig], {
|
|
151
|
+
force: !incremental,
|
|
152
|
+
verbose: true
|
|
153
|
+
});
|
|
154
|
+
const exitStatus = builder.build();
|
|
155
|
+
debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
|
|
156
|
+
}
|
|
157
|
+
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd, context = globalContext }) {
|
|
158
|
+
const fsSystem = createFsSystem(context.files);
|
|
159
|
+
const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, tsconfig ? path.dirname(tsconfig) : cwd);
|
|
160
|
+
if (tsconfig && parsedCmd.projectReferences?.length) buildSolution(tsconfig, incremental, context);
|
|
161
|
+
const compilerOptions = {
|
|
162
|
+
...defaultCompilerOptions,
|
|
163
|
+
...parsedCmd.options
|
|
164
|
+
};
|
|
165
|
+
const rootNames = [...new Set([id, ...entries || parsedCmd.fileNames].map((f) => fsSystem.resolvePath(f)))];
|
|
166
|
+
const host = ts.createCompilerHost(compilerOptions, true);
|
|
167
|
+
host.readFile = fsSystem.readFile;
|
|
168
|
+
host.fileExists = fsSystem.fileExists;
|
|
169
|
+
host.directoryExists = fsSystem.directoryExists;
|
|
170
|
+
const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
|
|
171
|
+
const program = createProgram({
|
|
172
|
+
rootNames,
|
|
173
|
+
options: compilerOptions,
|
|
174
|
+
host,
|
|
175
|
+
projectReferences: parsedCmd.projectReferences
|
|
176
|
+
});
|
|
177
|
+
const sourceFile = program.getSourceFile(id);
|
|
178
|
+
if (!sourceFile) {
|
|
179
|
+
debug(`source file not found in program: ${id}`);
|
|
180
|
+
if (!fsSystem.fileExists(id)) {
|
|
181
|
+
debug(`File ${id} does not exist on disk.`);
|
|
182
|
+
throw new Error(`Source file not found: ${id}`);
|
|
183
|
+
} else {
|
|
184
|
+
debug(`File ${id} exists on disk.`);
|
|
185
|
+
throw new Error(`Unable to load file ${id} from the program. This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
program,
|
|
190
|
+
file: sourceFile
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function tscEmit(tscOptions) {
|
|
194
|
+
debug(`running tscEmit ${tscOptions.id}`);
|
|
195
|
+
const module = createOrGetTsModule(tscOptions);
|
|
196
|
+
const { program, file } = module;
|
|
197
|
+
debug(`got source file: ${file.fileName}`);
|
|
198
|
+
let dtsCode;
|
|
199
|
+
let map;
|
|
200
|
+
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
201
|
+
if (fileName.endsWith(".map")) {
|
|
202
|
+
debug(`emit dts sourcemap: ${fileName}`);
|
|
203
|
+
map = JSON.parse(code);
|
|
204
|
+
} else {
|
|
205
|
+
debug(`emit dts: ${fileName}`);
|
|
206
|
+
dtsCode = code;
|
|
207
|
+
}
|
|
208
|
+
}, void 0, true, void 0, true);
|
|
209
|
+
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
210
|
+
if (!dtsCode && file.isDeclarationFile) {
|
|
211
|
+
debug("nothing was emitted. fallback to sourceFile text.");
|
|
212
|
+
dtsCode = file.getFullText();
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
code: dtsCode,
|
|
216
|
+
map
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
export { createContext, tscEmit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.9",
|
|
4
4
|
"description": "A Rolldown plugin to bundle dts files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,11 +29,15 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
+
"@typescript/native-preview": ">=7.0.0-dev.20250601.1",
|
|
32
33
|
"rolldown": "^1.0.0-beta.9",
|
|
33
34
|
"typescript": "^5.0.0",
|
|
34
35
|
"vue-tsc": "~2.2.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependenciesMeta": {
|
|
38
|
+
"@typescript/native-preview": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
37
41
|
"typescript": {
|
|
38
42
|
"optional": true
|
|
39
43
|
},
|
|
@@ -42,42 +46,46 @@
|
|
|
42
46
|
}
|
|
43
47
|
},
|
|
44
48
|
"dependencies": {
|
|
45
|
-
"@babel/generator": "^7.27.
|
|
46
|
-
"@babel/parser": "^7.27.
|
|
47
|
-
"@babel/types": "^7.27.
|
|
48
|
-
"ast-kit": "^2.
|
|
49
|
+
"@babel/generator": "^7.27.5",
|
|
50
|
+
"@babel/parser": "^7.27.5",
|
|
51
|
+
"@babel/types": "^7.27.6",
|
|
52
|
+
"ast-kit": "^2.1.0",
|
|
49
53
|
"birpc": "^2.3.0",
|
|
50
54
|
"debug": "^4.4.1",
|
|
51
|
-
"dts-resolver": "^2.
|
|
55
|
+
"dts-resolver": "^2.1.1",
|
|
52
56
|
"get-tsconfig": "^4.10.1"
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
55
|
-
"@sxzz/eslint-config": "^7.0.
|
|
59
|
+
"@sxzz/eslint-config": "^7.0.2",
|
|
56
60
|
"@sxzz/prettier-config": "^2.2.1",
|
|
57
61
|
"@sxzz/test-utils": "^0.5.6",
|
|
58
62
|
"@types/babel__generator": "^7.27.0",
|
|
59
63
|
"@types/debug": "^4.1.12",
|
|
60
|
-
"@types/node": "^22.15.
|
|
64
|
+
"@types/node": "^22.15.30",
|
|
65
|
+
"@typescript/native-preview": "7.0.0-dev.20250608.1",
|
|
61
66
|
"@volar/typescript": "^2.4.14",
|
|
62
67
|
"@vue/language-core": "^2.2.10",
|
|
63
68
|
"bumpp": "^10.1.1",
|
|
64
69
|
"diff": "^8.0.2",
|
|
65
|
-
"eslint": "^9.
|
|
70
|
+
"eslint": "^9.28.0",
|
|
66
71
|
"estree-walker": "^3.0.3",
|
|
67
72
|
"prettier": "^3.5.3",
|
|
68
|
-
"rolldown": "1.0.0-beta.
|
|
73
|
+
"rolldown": "1.0.0-beta.11-commit.f051675",
|
|
69
74
|
"rollup-plugin-dts": "^6.2.1",
|
|
70
75
|
"tinyglobby": "^0.2.14",
|
|
71
|
-
"tsdown": "^0.12.
|
|
76
|
+
"tsdown": "^0.12.7",
|
|
72
77
|
"tsx": "^4.19.4",
|
|
73
78
|
"typescript": "^5.8.3",
|
|
74
|
-
"vitest": "^3.
|
|
75
|
-
"vue": "^3.5.
|
|
79
|
+
"vitest": "^3.2.2",
|
|
80
|
+
"vue": "^3.5.16",
|
|
76
81
|
"vue-tsc": "^2.2.10"
|
|
77
82
|
},
|
|
78
83
|
"engines": {
|
|
79
84
|
"node": ">=20.18.0"
|
|
80
85
|
},
|
|
86
|
+
"resolutions": {
|
|
87
|
+
"rolldown": "1.0.0-beta.11-commit.f051675"
|
|
88
|
+
},
|
|
81
89
|
"prettier": "@sxzz/prettier-config",
|
|
82
90
|
"scripts": {
|
|
83
91
|
"lint": "eslint --cache .",
|
package/dist/tsc-CN7vXGIS.js
DELETED
package/dist/tsc-DSR26k5c.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import Debug from "debug";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/vue.ts
|
|
6
|
-
const debug$1 = Debug("rolldown-plugin-dts:vue");
|
|
7
|
-
let createVueProgram;
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
function loadVueLanguageTools() {
|
|
10
|
-
try {
|
|
11
|
-
const vueTscPath = require.resolve("vue-tsc");
|
|
12
|
-
const { proxyCreateProgram } = require(require.resolve("@volar/typescript", { paths: [vueTscPath] }));
|
|
13
|
-
const vue = require(require.resolve("@vue/language-core", { paths: [vueTscPath] }));
|
|
14
|
-
return {
|
|
15
|
-
proxyCreateProgram,
|
|
16
|
-
vue
|
|
17
|
-
};
|
|
18
|
-
} catch (error) {
|
|
19
|
-
debug$1("vue language tools not found", error);
|
|
20
|
-
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function createVueProgramFactory(ts$1) {
|
|
24
|
-
if (createVueProgram) return createVueProgram;
|
|
25
|
-
debug$1("loading vue language tools");
|
|
26
|
-
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
27
|
-
return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
|
|
28
|
-
const { configFilePath } = options.options;
|
|
29
|
-
const vueOptions = typeof configFilePath === "string" ? vue.createParsedCommandLine(ts$2, ts$2.sys, configFilePath.replaceAll("\\", "/")).vueOptions : vue.getDefaultCompilerOptions();
|
|
30
|
-
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
|
|
31
|
-
return { languagePlugins: [vueLanguagePlugin] };
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/utils/tsc.ts
|
|
37
|
-
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
38
|
-
debug(`loaded typescript: ${ts.version}`);
|
|
39
|
-
const programs = [];
|
|
40
|
-
const formatHost = {
|
|
41
|
-
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
42
|
-
getNewLine: () => ts.sys.newLine,
|
|
43
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
44
|
-
};
|
|
45
|
-
const defaultCompilerOptions = {
|
|
46
|
-
declaration: true,
|
|
47
|
-
noEmit: false,
|
|
48
|
-
emitDeclarationOnly: true,
|
|
49
|
-
noEmitOnError: true,
|
|
50
|
-
checkJs: false,
|
|
51
|
-
declarationMap: false,
|
|
52
|
-
skipLibCheck: true,
|
|
53
|
-
target: 99,
|
|
54
|
-
resolveJsonModule: true,
|
|
55
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
56
|
-
};
|
|
57
|
-
function createOrGetTsModule(options) {
|
|
58
|
-
const { id, entries } = options;
|
|
59
|
-
const program = programs.find((program$1) => {
|
|
60
|
-
const roots = program$1.getRootFileNames();
|
|
61
|
-
if (entries) return entries.every((entry) => roots.includes(entry));
|
|
62
|
-
return roots.includes(id);
|
|
63
|
-
});
|
|
64
|
-
if (program) {
|
|
65
|
-
const sourceFile = program.getSourceFile(id);
|
|
66
|
-
if (sourceFile) return {
|
|
67
|
-
program,
|
|
68
|
-
file: sourceFile
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
debug(`create program for module: ${id}`);
|
|
72
|
-
const module = createTsProgram(options);
|
|
73
|
-
debug(`created program for module: ${id}`);
|
|
74
|
-
programs.push(module.program);
|
|
75
|
-
return module;
|
|
76
|
-
}
|
|
77
|
-
function createTsProgram({ entries, id, tsconfigRaw, tsconfigDir, vue }) {
|
|
78
|
-
const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, ts.sys, tsconfigDir);
|
|
79
|
-
const compilerOptions = {
|
|
80
|
-
...defaultCompilerOptions,
|
|
81
|
-
...parsedCmd.options
|
|
82
|
-
};
|
|
83
|
-
const rootNames = [...new Set([id, ...entries || parsedCmd.fileNames].map((f) => ts.sys.resolvePath(f)))];
|
|
84
|
-
const host = ts.createCompilerHost(compilerOptions, true);
|
|
85
|
-
const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
|
|
86
|
-
const program = createProgram({
|
|
87
|
-
rootNames,
|
|
88
|
-
options: compilerOptions,
|
|
89
|
-
host,
|
|
90
|
-
projectReferences: parsedCmd.projectReferences
|
|
91
|
-
});
|
|
92
|
-
const sourceFile = program.getSourceFile(id);
|
|
93
|
-
if (!sourceFile) throw new Error(`Source file not found: ${id}`);
|
|
94
|
-
return {
|
|
95
|
-
program,
|
|
96
|
-
file: sourceFile
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function tscEmit(tscOptions) {
|
|
100
|
-
const module = createOrGetTsModule(tscOptions);
|
|
101
|
-
const { program, file } = module;
|
|
102
|
-
let dtsCode;
|
|
103
|
-
let map;
|
|
104
|
-
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
105
|
-
if (fileName.endsWith(".map")) {
|
|
106
|
-
debug(`emit dts sourcemap: ${fileName}`);
|
|
107
|
-
map = JSON.parse(code);
|
|
108
|
-
} else {
|
|
109
|
-
debug(`emit dts: ${fileName}`);
|
|
110
|
-
dtsCode = code;
|
|
111
|
-
}
|
|
112
|
-
}, void 0, true, void 0, true);
|
|
113
|
-
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
114
|
-
return {
|
|
115
|
-
code: dtsCode,
|
|
116
|
-
map
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
export { tscEmit };
|