rolldown-plugin-dts 0.14.3 → 0.15.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 +53 -64
- package/dist/context-BG0dlajy.js +23 -0
- package/dist/context-DIRjVfC4.d.ts +12 -0
- package/dist/{index-B4kTNEjT.d.ts → index-BPD4iQBs.d.ts} +6 -5
- package/dist/index.d.ts +60 -44
- package/dist/index.js +39 -31
- package/dist/{tsc-Czx4mPt7.js → tsc-BSxLVaDe.js} +5 -13
- package/dist/tsc-context.d.ts +2 -0
- package/dist/tsc-context.js +3 -0
- package/dist/{tsc/worker.d.ts → tsc-worker.d.ts} +2 -1
- package/dist/{tsc/worker.js → tsc-worker.js} +3 -2
- package/dist/tsc.d.ts +3 -0
- package/dist/tsc.js +4 -0
- package/package.json +6 -4
- package/dist/tsc-HJvJZNLs.js +0 -3
package/README.md
CHANGED
|
@@ -36,31 +36,25 @@ You can find an example in [here](./rolldown.config.ts).
|
|
|
36
36
|
|
|
37
37
|
Configuration options for the plugin.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
### General Options
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
#### `cwd`
|
|
42
42
|
|
|
43
43
|
The directory in which the plugin will search for the `tsconfig.json` file.
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### dtsInput
|
|
45
|
+
#### `dtsInput`
|
|
48
46
|
|
|
49
47
|
Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
|
|
50
48
|
|
|
51
49
|
When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### emitDtsOnly
|
|
51
|
+
#### `emitDtsOnly`
|
|
56
52
|
|
|
57
53
|
If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
|
|
58
54
|
|
|
59
55
|
This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### tsconfig
|
|
57
|
+
#### `tsconfig`
|
|
64
58
|
|
|
65
59
|
The path to the `tsconfig.json` file.
|
|
66
60
|
|
|
@@ -69,85 +63,69 @@ The path to the `tsconfig.json` file.
|
|
|
69
63
|
|
|
70
64
|
**Default:** `'tsconfig.json'`
|
|
71
65
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### tsconfigRaw
|
|
66
|
+
#### `tsconfigRaw`
|
|
75
67
|
|
|
76
68
|
Pass a raw `tsconfig.json` object directly to the plugin.
|
|
77
69
|
|
|
78
70
|
See: [TypeScript tsconfig documentation](https://www.typescriptlang.org/tsconfig)
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### incremental
|
|
83
|
-
|
|
84
|
-
Controls how project references and incremental builds are handled:
|
|
85
|
-
|
|
86
|
-
- 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.
|
|
87
|
-
- 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.
|
|
88
|
-
- If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
|
|
89
|
-
|
|
90
|
-
Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
|
|
72
|
+
#### `compilerOptions`
|
|
91
73
|
|
|
92
|
-
|
|
74
|
+
Override the `compilerOptions` specified in `tsconfig.json`.
|
|
93
75
|
|
|
94
|
-
|
|
95
|
-
> This option is only used when [`isolatedDeclarations`](#isolateddeclarations) is `false`.
|
|
76
|
+
See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/tsconfig/#compilerOptions)
|
|
96
77
|
|
|
97
|
-
|
|
78
|
+
#### `sourcemap`
|
|
98
79
|
|
|
99
|
-
|
|
80
|
+
If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
100
81
|
|
|
101
|
-
|
|
82
|
+
#### `resolve`
|
|
102
83
|
|
|
103
|
-
|
|
84
|
+
Resolve external types used in `.d.ts` files from `node_modules`.
|
|
104
85
|
|
|
105
|
-
|
|
86
|
+
- If `true`, all external types are resolved.
|
|
87
|
+
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
106
88
|
|
|
107
|
-
###
|
|
89
|
+
### `tsc` Options
|
|
108
90
|
|
|
109
|
-
|
|
91
|
+
> [!NOTE]
|
|
92
|
+
> These options are only applicable when `oxc` and `tsgo` are not enabled.
|
|
110
93
|
|
|
111
|
-
|
|
94
|
+
#### `build`
|
|
112
95
|
|
|
113
|
-
|
|
96
|
+
Build mode for the TypeScript compiler:
|
|
114
97
|
|
|
115
|
-
|
|
98
|
+
- 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.
|
|
99
|
+
- 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.
|
|
116
100
|
|
|
117
|
-
|
|
101
|
+
**Default:** `false`
|
|
118
102
|
|
|
119
|
-
|
|
103
|
+
#### `incremental`
|
|
120
104
|
|
|
121
|
-
|
|
105
|
+
Controls how project references and incremental builds are handled:
|
|
122
106
|
|
|
123
|
-
|
|
107
|
+
- 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.
|
|
108
|
+
- If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
|
|
124
109
|
|
|
125
|
-
|
|
126
|
-
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
110
|
+
Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
|
|
127
111
|
|
|
128
|
-
|
|
112
|
+
**Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
|
|
129
113
|
|
|
130
|
-
|
|
114
|
+
#### `vue`
|
|
131
115
|
|
|
132
116
|
If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
|
|
133
117
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
### parallel
|
|
118
|
+
#### `parallel`
|
|
137
119
|
|
|
138
120
|
If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
|
|
139
121
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
### eager
|
|
122
|
+
#### `eager`
|
|
143
123
|
|
|
144
124
|
If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
|
|
145
125
|
|
|
146
126
|
This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
|
|
147
127
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
### newContext
|
|
128
|
+
#### `newContext`
|
|
151
129
|
|
|
152
130
|
If `true`, the plugin will create a new isolated context for each build,
|
|
153
131
|
ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
@@ -156,29 +134,40 @@ By default, the plugin may reuse internal caches or incremental build artifacts
|
|
|
156
134
|
to speed up repeated builds. Enabling this option forces a clean context,
|
|
157
135
|
guaranteeing that all type definitions are generated from scratch.
|
|
158
136
|
|
|
159
|
-
|
|
137
|
+
`invalidateContextFile` API can be used to clear invalidated files from the context.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { globalContext, invalidateContextFile } from 'rolldown-plugin-dts/tsc'
|
|
141
|
+
invalidateContextFile(globalContext, 'src/foo.ts')
|
|
142
|
+
```
|
|
160
143
|
|
|
161
|
-
|
|
144
|
+
#### `emitJs`
|
|
162
145
|
|
|
163
146
|
If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
|
|
164
147
|
This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
|
|
165
148
|
|
|
166
149
|
Enabled by default when `allowJs` in compilerOptions is `true`.
|
|
167
150
|
|
|
168
|
-
|
|
151
|
+
### Oxc
|
|
169
152
|
|
|
170
|
-
|
|
153
|
+
#### `oxc`
|
|
171
154
|
|
|
172
|
-
|
|
155
|
+
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.
|
|
173
156
|
|
|
174
|
-
|
|
157
|
+
This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
175
158
|
|
|
176
|
-
|
|
159
|
+
### TypeScript Go
|
|
177
160
|
|
|
178
161
|
> [!WARNING]
|
|
179
|
-
> This
|
|
162
|
+
> This feature is experimental and not yet recommended for production environments.
|
|
163
|
+
|
|
164
|
+
#### `tsgo`
|
|
165
|
+
|
|
166
|
+
**[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
|
|
167
|
+
|
|
168
|
+
To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
|
|
180
169
|
|
|
181
|
-
|
|
170
|
+
`tsconfigRaw` option will be ignored when this option is enabled.
|
|
182
171
|
|
|
183
172
|
## Differences from `rollup-plugin-dts`
|
|
184
173
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Debug from "debug";
|
|
2
|
+
|
|
3
|
+
//#region src/tsc/context.ts
|
|
4
|
+
const debug = Debug("rolldown-plugin-dts:tsc-context");
|
|
5
|
+
function createContext() {
|
|
6
|
+
const programs = [];
|
|
7
|
+
const files = /* @__PURE__ */ new Map();
|
|
8
|
+
return {
|
|
9
|
+
programs,
|
|
10
|
+
files
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function invalidateContextFile(context, file) {
|
|
14
|
+
debug(`invalidating context file: ${file}`);
|
|
15
|
+
context.files.delete(file);
|
|
16
|
+
context.programs = context.programs.filter((program) => {
|
|
17
|
+
return !program.getSourceFiles().some((sourceFile) => sourceFile.fileName === file);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const globalContext = createContext();
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createContext, globalContext, invalidateContextFile };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/tsc/context.d.ts
|
|
4
|
+
interface TscContext {
|
|
5
|
+
programs: ts.Program[];
|
|
6
|
+
files: Map<string, string>;
|
|
7
|
+
}
|
|
8
|
+
declare function createContext(): TscContext;
|
|
9
|
+
declare function invalidateContextFile(context: TscContext, file: string): void;
|
|
10
|
+
declare const globalContext: TscContext;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { TscContext, createContext, globalContext, invalidateContextFile };
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
+
import { TscContext } from "./context-DIRjVfC4.js";
|
|
1
2
|
import { TsConfigJson } from "get-tsconfig";
|
|
2
3
|
import ts from "typescript";
|
|
3
4
|
import { SourceMapInput } from "rolldown";
|
|
4
5
|
|
|
5
6
|
//#region src/tsc/index.d.ts
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
interface TscModule {
|
|
8
|
+
program: ts.Program;
|
|
9
|
+
file: ts.SourceFile;
|
|
9
10
|
}
|
|
10
11
|
interface TscOptions {
|
|
11
12
|
tsconfig?: string;
|
|
12
13
|
tsconfigRaw: TsConfigJson;
|
|
13
14
|
cwd: string;
|
|
15
|
+
build: boolean;
|
|
14
16
|
incremental: boolean;
|
|
15
17
|
entries?: string[];
|
|
16
18
|
id: string;
|
|
17
19
|
vue?: boolean;
|
|
18
20
|
context?: TscContext;
|
|
19
21
|
}
|
|
20
|
-
declare function createContext(): TscContext;
|
|
21
22
|
interface TscResult {
|
|
22
23
|
code?: string;
|
|
23
24
|
map?: SourceMapInput;
|
|
@@ -25,4 +26,4 @@ interface TscResult {
|
|
|
25
26
|
}
|
|
26
27
|
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
27
28
|
//#endregion
|
|
28
|
-
export {
|
|
29
|
+
export { TscModule, TscOptions, TscResult, tscEmit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-4MoswV50.js";
|
|
2
|
-
import { TscContext, createContext } from "./index-B4kTNEjT.js";
|
|
3
2
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
4
3
|
import { TsConfigJson } from "get-tsconfig";
|
|
5
4
|
import { Plugin } from "rolldown";
|
|
6
5
|
|
|
7
6
|
//#region src/options.d.ts
|
|
8
|
-
interface
|
|
7
|
+
interface GeneralOptions {
|
|
9
8
|
/**
|
|
10
9
|
* The directory in which the plugin will search for the `tsconfig.json` file.
|
|
11
10
|
*/
|
|
@@ -38,6 +37,31 @@ interface Options {
|
|
|
38
37
|
*/
|
|
39
38
|
tsconfigRaw?: Omit<TsConfigJson, "compilerOptions">;
|
|
40
39
|
/**
|
|
40
|
+
* Override the `compilerOptions` specified in `tsconfig.json`.
|
|
41
|
+
*
|
|
42
|
+
* @see https://www.typescriptlang.org/tsconfig/#compilerOptions
|
|
43
|
+
*/
|
|
44
|
+
compilerOptions?: TsConfigJson.CompilerOptions;
|
|
45
|
+
/**
|
|
46
|
+
* If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
47
|
+
*/
|
|
48
|
+
sourcemap?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Resolve external types used in `.d.ts` files from `node_modules`.
|
|
51
|
+
*/
|
|
52
|
+
resolve?: boolean | (string | RegExp)[];
|
|
53
|
+
}
|
|
54
|
+
interface TscOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Build mode for the TypeScript compiler:
|
|
57
|
+
*
|
|
58
|
+
* - 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.
|
|
59
|
+
* - 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.
|
|
60
|
+
*
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
build?: boolean;
|
|
64
|
+
/**
|
|
41
65
|
* If your tsconfig.json has
|
|
42
66
|
* [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
|
|
43
67
|
* `rolldown-plugin-dts` will use [`tsc
|
|
@@ -63,32 +87,11 @@ interface Options {
|
|
|
63
87
|
* [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
64
88
|
* enabled.
|
|
65
89
|
*
|
|
66
|
-
* This option is only used when {@link Options.
|
|
90
|
+
* This option is only used when {@link Options.oxc} is
|
|
67
91
|
* `false`.
|
|
68
92
|
*/
|
|
69
93
|
incremental?: boolean;
|
|
70
94
|
/**
|
|
71
|
-
* Override the `compilerOptions` specified in `tsconfig.json`.
|
|
72
|
-
*
|
|
73
|
-
* @see https://www.typescriptlang.org/tsconfig/#compilerOptions
|
|
74
|
-
*/
|
|
75
|
-
compilerOptions?: TsConfigJson.CompilerOptions;
|
|
76
|
-
/**
|
|
77
|
-
* If `true`, the plugin will generate `.d.ts` files using Oxc,
|
|
78
|
-
* which is significantly faster than the TypeScript compiler.
|
|
79
|
-
*
|
|
80
|
-
* This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
81
|
-
*/
|
|
82
|
-
isolatedDeclarations?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
83
|
-
/**
|
|
84
|
-
* If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
85
|
-
*/
|
|
86
|
-
sourcemap?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Resolve external types used in `.d.ts` files from `node_modules`.
|
|
89
|
-
*/
|
|
90
|
-
resolve?: boolean | (string | RegExp)[];
|
|
91
|
-
/**
|
|
92
95
|
* If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
|
|
93
96
|
*/
|
|
94
97
|
vue?: boolean;
|
|
@@ -104,15 +107,6 @@ interface Options {
|
|
|
104
107
|
*/
|
|
105
108
|
eager?: boolean;
|
|
106
109
|
/**
|
|
107
|
-
* **[Experimental]** Enables DTS generation using `tsgo`.
|
|
108
|
-
*
|
|
109
|
-
* To use this option, make sure `@typescript/native-preview` is installed as a dependency.
|
|
110
|
-
*
|
|
111
|
-
* **Note:** This option is not yet recommended for production environments.
|
|
112
|
-
* `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
|
|
113
|
-
*/
|
|
114
|
-
tsgo?: boolean;
|
|
115
|
-
/**
|
|
116
110
|
* If `true`, the plugin will create a new isolated context for each build,
|
|
117
111
|
* ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
118
112
|
*
|
|
@@ -128,32 +122,53 @@ interface Options {
|
|
|
128
122
|
* This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
|
|
129
123
|
*
|
|
130
124
|
* Enabled by default when `allowJs` in compilerOptions is `true`.
|
|
125
|
+
* This option is only used when {@link Options.oxc} is
|
|
126
|
+
* `false`.
|
|
131
127
|
*/
|
|
132
128
|
emitJs?: boolean;
|
|
133
129
|
}
|
|
130
|
+
interface Options extends GeneralOptions, TscOptions {
|
|
131
|
+
/**
|
|
132
|
+
* If `true`, the plugin will generate `.d.ts` files using Oxc,
|
|
133
|
+
* which is significantly faster than the TypeScript compiler.
|
|
134
|
+
*
|
|
135
|
+
* This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
136
|
+
*/
|
|
137
|
+
oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
138
|
+
/**
|
|
139
|
+
* **[Experimental]** Enables DTS generation using `tsgo`.
|
|
140
|
+
*
|
|
141
|
+
* To use this option, make sure `@typescript/native-preview` is installed as a dependency.
|
|
142
|
+
*
|
|
143
|
+
* **Note:** This option is not yet recommended for production environments.
|
|
144
|
+
* `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
|
|
145
|
+
*/
|
|
146
|
+
tsgo?: boolean;
|
|
147
|
+
}
|
|
134
148
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
135
149
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
136
150
|
tsconfig: string | undefined;
|
|
137
|
-
|
|
151
|
+
oxc: IsolatedDeclarationsOptions | false;
|
|
138
152
|
tsconfigRaw: TsConfigJson;
|
|
139
153
|
}>;
|
|
140
154
|
declare function resolveOptions({
|
|
141
155
|
cwd,
|
|
156
|
+
dtsInput,
|
|
157
|
+
emitDtsOnly,
|
|
142
158
|
tsconfig,
|
|
143
|
-
incremental,
|
|
144
|
-
compilerOptions,
|
|
145
159
|
tsconfigRaw: overriddenTsconfigRaw,
|
|
146
|
-
|
|
160
|
+
compilerOptions,
|
|
147
161
|
sourcemap,
|
|
148
|
-
dtsInput,
|
|
149
|
-
emitDtsOnly,
|
|
150
162
|
resolve,
|
|
163
|
+
build,
|
|
164
|
+
incremental,
|
|
151
165
|
vue,
|
|
152
166
|
parallel,
|
|
153
167
|
eager,
|
|
154
|
-
tsgo,
|
|
155
168
|
newContext,
|
|
156
|
-
emitJs
|
|
169
|
+
emitJs,
|
|
170
|
+
oxc,
|
|
171
|
+
tsgo
|
|
157
172
|
}: Options): OptionsResolved;
|
|
158
173
|
//#endregion
|
|
159
174
|
//#region src/fake-js.d.ts
|
|
@@ -166,9 +181,10 @@ declare function createFakeJsPlugin({
|
|
|
166
181
|
declare function createGeneratePlugin({
|
|
167
182
|
tsconfig,
|
|
168
183
|
tsconfigRaw,
|
|
184
|
+
build,
|
|
169
185
|
incremental,
|
|
170
186
|
cwd,
|
|
171
|
-
|
|
187
|
+
oxc,
|
|
172
188
|
emitDtsOnly,
|
|
173
189
|
vue,
|
|
174
190
|
parallel,
|
|
@@ -176,9 +192,9 @@ declare function createGeneratePlugin({
|
|
|
176
192
|
tsgo,
|
|
177
193
|
newContext,
|
|
178
194
|
emitJs
|
|
179
|
-
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "
|
|
195
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs">): Plugin;
|
|
180
196
|
//#endregion
|
|
181
197
|
//#region src/index.d.ts
|
|
182
198
|
declare function dts(options?: Options): Plugin[];
|
|
183
199
|
//#endregion
|
|
184
|
-
export { type Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE,
|
|
200
|
+
export { type 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,16 +1,15 @@
|
|
|
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_to_dts } from "./filename-Dz6Li3gj.js";
|
|
2
|
-
import { createContext } from "./
|
|
3
|
-
import path from "node:path";
|
|
2
|
+
import { createContext, globalContext, invalidateContextFile } from "./context-BG0dlajy.js";
|
|
4
3
|
import Debug from "debug";
|
|
5
4
|
import _generate from "@babel/generator";
|
|
6
5
|
import { parse } from "@babel/parser";
|
|
7
6
|
import * as t from "@babel/types";
|
|
8
7
|
import { isDeclarationType, isTypeOf, resolveString } from "ast-kit";
|
|
8
|
+
import path from "node:path";
|
|
9
9
|
import { fork, spawn } from "node:child_process";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
13
|
-
import { createBirpc } from "birpc";
|
|
14
13
|
import { ResolverFactory, isolatedDeclaration } from "rolldown/experimental";
|
|
15
14
|
import process from "node:process";
|
|
16
15
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
@@ -243,7 +242,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
243
242
|
if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
|
|
244
243
|
return {
|
|
245
244
|
...options,
|
|
246
|
-
sourcemap: sourcemap
|
|
245
|
+
sourcemap: options.sourcemap || sourcemap,
|
|
247
246
|
entryFileNames: options.entryFileNames ?? (dtsInput ? "[name].ts" : void 0),
|
|
248
247
|
chunkFileNames(chunk) {
|
|
249
248
|
const original = (typeof options.chunkFileNames === "function" ? options.chunkFileNames(chunk) : options.chunkFileNames) || "[name]-[hash].js";
|
|
@@ -634,13 +633,13 @@ function inheritNodeComments(oldNode, newNode) {
|
|
|
634
633
|
//#endregion
|
|
635
634
|
//#region src/generate.ts
|
|
636
635
|
const debug$1 = Debug("rolldown-plugin-dts:generate");
|
|
637
|
-
const WORKER_URL = "./tsc
|
|
636
|
+
const WORKER_URL = "./tsc-worker.js";
|
|
638
637
|
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
639
638
|
const child = spawn(...args);
|
|
640
639
|
child.on("close", () => resolve());
|
|
641
640
|
child.on("error", (error) => reject(error));
|
|
642
641
|
});
|
|
643
|
-
function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd,
|
|
642
|
+
function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs }) {
|
|
644
643
|
const dtsMap = /* @__PURE__ */ new Map();
|
|
645
644
|
/**
|
|
646
645
|
* A map of input id to output file name
|
|
@@ -657,20 +656,19 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
657
656
|
let tscModule;
|
|
658
657
|
let tscContext;
|
|
659
658
|
let tsgoDist;
|
|
660
|
-
if (!tsgo && parallel) {
|
|
661
|
-
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
662
|
-
rpc = createBirpc({}, {
|
|
663
|
-
post: (data) => childProcess.send(data),
|
|
664
|
-
on: (fn) => childProcess.on("message", fn)
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
659
|
return {
|
|
668
660
|
name: "rolldown-plugin-dts:generate",
|
|
669
661
|
async buildStart(options) {
|
|
670
662
|
if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
|
|
671
|
-
else if (!
|
|
672
|
-
|
|
673
|
-
|
|
663
|
+
else if (!oxc) if (parallel) {
|
|
664
|
+
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
665
|
+
rpc = (await import("birpc")).createBirpc({}, {
|
|
666
|
+
post: (data) => childProcess.send(data),
|
|
667
|
+
on: (fn) => childProcess.on("message", fn)
|
|
668
|
+
});
|
|
669
|
+
} else {
|
|
670
|
+
tscModule = await import("./tsc.js");
|
|
671
|
+
if (newContext) tscContext = createContext();
|
|
674
672
|
}
|
|
675
673
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
676
674
|
debug$1("resolving input alias %s -> %s", name, id);
|
|
@@ -748,8 +746,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
748
746
|
debug$1("[tsgo]", dtsPath, "is missing");
|
|
749
747
|
throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
|
|
750
748
|
}
|
|
751
|
-
} else if (
|
|
752
|
-
const result = isolatedDeclaration(id, code,
|
|
749
|
+
} else if (oxc && !RE_VUE.test(id)) {
|
|
750
|
+
const result = isolatedDeclaration(id, code, oxc);
|
|
753
751
|
if (result.errors.length) {
|
|
754
752
|
const [error] = result.errors;
|
|
755
753
|
return this.error({
|
|
@@ -767,6 +765,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
767
765
|
const options = {
|
|
768
766
|
tsconfig,
|
|
769
767
|
tsconfigRaw,
|
|
768
|
+
build,
|
|
770
769
|
incremental,
|
|
771
770
|
cwd,
|
|
772
771
|
entries,
|
|
@@ -799,6 +798,9 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
799
798
|
}).catch(() => {});
|
|
800
799
|
tsgoDist = void 0;
|
|
801
800
|
if (newContext) tscContext = void 0;
|
|
801
|
+
},
|
|
802
|
+
watchChange(id) {
|
|
803
|
+
if (tscModule) invalidateContextFile(tscContext || globalContext, id);
|
|
802
804
|
}
|
|
803
805
|
};
|
|
804
806
|
}
|
|
@@ -826,7 +828,7 @@ async function runTsgo(root, tsconfig) {
|
|
|
826
828
|
//#endregion
|
|
827
829
|
//#region src/options.ts
|
|
828
830
|
let warnedTsgo = false;
|
|
829
|
-
function resolveOptions({ cwd = process.cwd(),
|
|
831
|
+
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, build = false, incremental = false, vue = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
830
832
|
let resolvedTsconfig;
|
|
831
833
|
if (tsconfig === true || tsconfig == null) {
|
|
832
834
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -848,33 +850,39 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
848
850
|
...overriddenTsconfigRaw,
|
|
849
851
|
compilerOptions
|
|
850
852
|
};
|
|
851
|
-
|
|
852
|
-
if (
|
|
853
|
-
if (
|
|
854
|
-
|
|
855
|
-
|
|
853
|
+
oxc ??= !!(compilerOptions?.isolatedDeclarations && !vue && !tsgo);
|
|
854
|
+
if (oxc === true) oxc = {};
|
|
855
|
+
if (oxc) {
|
|
856
|
+
oxc.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
857
|
+
oxc.sourcemap = !!compilerOptions.declarationMap;
|
|
856
858
|
}
|
|
857
859
|
emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
|
|
860
|
+
if (tsgo) {
|
|
861
|
+
if (vue) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");
|
|
862
|
+
if (oxc) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.");
|
|
863
|
+
}
|
|
864
|
+
if (oxc && vue) throw new Error("[rolldown-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");
|
|
858
865
|
if (tsgo && !warnedTsgo) {
|
|
859
866
|
console.warn("The `tsgo` option is experimental and may change in the future.");
|
|
860
867
|
warnedTsgo = true;
|
|
861
868
|
}
|
|
862
869
|
return {
|
|
863
870
|
cwd,
|
|
871
|
+
dtsInput,
|
|
872
|
+
emitDtsOnly,
|
|
864
873
|
tsconfig,
|
|
865
874
|
tsconfigRaw,
|
|
866
|
-
incremental,
|
|
867
|
-
isolatedDeclarations,
|
|
868
875
|
sourcemap,
|
|
869
|
-
dtsInput,
|
|
870
|
-
emitDtsOnly,
|
|
871
876
|
resolve,
|
|
877
|
+
build,
|
|
878
|
+
incremental,
|
|
872
879
|
vue,
|
|
873
880
|
parallel,
|
|
874
881
|
eager,
|
|
875
|
-
tsgo,
|
|
876
882
|
newContext,
|
|
877
|
-
emitJs
|
|
883
|
+
emitJs,
|
|
884
|
+
oxc,
|
|
885
|
+
tsgo
|
|
878
886
|
};
|
|
879
887
|
}
|
|
880
888
|
|
|
@@ -940,4 +948,4 @@ function dts(options = {}) {
|
|
|
940
948
|
}
|
|
941
949
|
|
|
942
950
|
//#endregion
|
|
943
|
-
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE,
|
|
951
|
+
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { globalContext } from "./context-BG0dlajy.js";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
|
-
import path from "node:path";
|
|
3
3
|
import Debug from "debug";
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
import ts from "typescript";
|
|
5
6
|
|
|
6
7
|
//#region src/tsc/system.ts
|
|
@@ -92,15 +93,6 @@ function createVueProgramFactory(ts$1) {
|
|
|
92
93
|
//#region src/tsc/index.ts
|
|
93
94
|
const debug = Debug("rolldown-plugin-dts:tsc");
|
|
94
95
|
debug(`loaded typescript: ${ts.version}`);
|
|
95
|
-
function createContext() {
|
|
96
|
-
const programs = [];
|
|
97
|
-
const files = /* @__PURE__ */ new Map();
|
|
98
|
-
return {
|
|
99
|
-
programs,
|
|
100
|
-
files
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const globalContext = createContext();
|
|
104
96
|
const formatHost = {
|
|
105
97
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
106
98
|
getNewLine: () => ts.sys.newLine,
|
|
@@ -185,11 +177,11 @@ function parseTsconfig(tsconfigPath, fsSystem) {
|
|
|
185
177
|
if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
|
|
186
178
|
return parsedConfig;
|
|
187
179
|
}
|
|
188
|
-
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd, context = globalContext }) {
|
|
180
|
+
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, build, incremental, vue, cwd, context = globalContext }) {
|
|
189
181
|
const fsSystem = createFsSystem(context.files);
|
|
190
182
|
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
191
183
|
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
|
|
192
|
-
if (tsconfig &&
|
|
184
|
+
if (tsconfig && build) {
|
|
193
185
|
const projectPaths = buildSolution(tsconfig, incremental, context);
|
|
194
186
|
debug(`collected projects: ${JSON.stringify(projectPaths)}`);
|
|
195
187
|
const project = findProjectContainingFile(projectPaths, id, fsSystem);
|
|
@@ -277,4 +269,4 @@ function tscEmit(tscOptions) {
|
|
|
277
269
|
}
|
|
278
270
|
|
|
279
271
|
//#endregion
|
|
280
|
-
export {
|
|
272
|
+
export { tscEmit };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import "./context-BG0dlajy.js";
|
|
2
|
+
import { tscEmit } from "./tsc-BSxLVaDe.js";
|
|
3
3
|
import process from "node:process";
|
|
4
|
+
import { createBirpc } from "birpc";
|
|
4
5
|
|
|
5
6
|
//#region src/tsc/worker.ts
|
|
6
7
|
const functions = { tscEmit };
|
package/dist/tsc.d.ts
ADDED
package/dist/tsc.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "A Rolldown plugin to bundle dts files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": "./dist/index.js",
|
|
25
25
|
"./filename": "./dist/filename.js",
|
|
26
|
+
"./tsc": "./dist/tsc.js",
|
|
27
|
+
"./tsc-context": "./dist/tsc-context.js",
|
|
28
|
+
"./tsc-worker": "./dist/tsc-worker.js",
|
|
26
29
|
"./package.json": "./package.json"
|
|
27
30
|
},
|
|
28
31
|
"publishConfig": {
|
|
@@ -56,9 +59,9 @@
|
|
|
56
59
|
"get-tsconfig": "^4.10.1"
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
|
-
"@sxzz/eslint-config": "^7.1.
|
|
62
|
+
"@sxzz/eslint-config": "^7.1.2",
|
|
60
63
|
"@sxzz/prettier-config": "^2.2.3",
|
|
61
|
-
"@sxzz/test-utils": "^0.5.
|
|
64
|
+
"@sxzz/test-utils": "^0.5.9",
|
|
62
65
|
"@types/babel__generator": "^7.27.0",
|
|
63
66
|
"@types/debug": "^4.1.12",
|
|
64
67
|
"@types/node": "^24.1.0",
|
|
@@ -74,7 +77,6 @@
|
|
|
74
77
|
"rollup-plugin-dts": "^6.2.1",
|
|
75
78
|
"tinyglobby": "^0.2.14",
|
|
76
79
|
"tsdown": "^0.13.0",
|
|
77
|
-
"tsx": "^4.20.3",
|
|
78
80
|
"typescript": "^5.8.3",
|
|
79
81
|
"vitest": "^3.2.4",
|
|
80
82
|
"vue": "^3.5.18",
|
package/dist/tsc-HJvJZNLs.js
DELETED