rolldown-plugin-dts 0.14.3 → 0.15.0
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 +47 -66
- package/dist/context-BG0dlajy.js +23 -0
- package/dist/context-DIRjVfC4.d.ts +12 -0
- package/dist/{index-B4kTNEjT.d.ts → index-D_X_vGiL.d.ts} +5 -5
- package/dist/index.d.ts +9 -8
- package/dist/index.js +32 -26
- package/dist/{tsc-Czx4mPt7.js → tsc-BjWJCGE1.js} +3 -11
- 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,61 @@ 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.
|
|
91
|
-
|
|
92
|
-
**Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
|
|
93
|
-
|
|
94
|
-
> [!NOTE]
|
|
95
|
-
> This option is only used when [`isolatedDeclarations`](#isolateddeclarations) is `false`.
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
### compilerOptions
|
|
72
|
+
#### `compilerOptions`
|
|
100
73
|
|
|
101
74
|
Override the `compilerOptions` specified in `tsconfig.json`.
|
|
102
75
|
|
|
103
76
|
See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/tsconfig/#compilerOptions)
|
|
104
77
|
|
|
105
|
-
|
|
78
|
+
#### `sourcemap`
|
|
106
79
|
|
|
107
|
-
|
|
80
|
+
If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
108
81
|
|
|
109
|
-
|
|
82
|
+
#### `resolve`
|
|
110
83
|
|
|
111
|
-
|
|
84
|
+
Resolve external types used in `.d.ts` files from `node_modules`.
|
|
112
85
|
|
|
113
|
-
|
|
86
|
+
- If `true`, all external types are resolved.
|
|
87
|
+
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
114
88
|
|
|
115
|
-
###
|
|
89
|
+
### `tsc` Options
|
|
116
90
|
|
|
117
|
-
|
|
91
|
+
> [!NOTE]
|
|
92
|
+
> These options are only applicable when `oxc` and `tsgo` are not enabled.
|
|
118
93
|
|
|
119
|
-
|
|
94
|
+
#### `incremental`
|
|
120
95
|
|
|
121
|
-
|
|
96
|
+
Controls how project references and incremental builds are handled:
|
|
122
97
|
|
|
123
|
-
|
|
98
|
+
- 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.
|
|
99
|
+
- 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.
|
|
100
|
+
- If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
|
|
124
101
|
|
|
125
|
-
|
|
126
|
-
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
102
|
+
Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
|
|
127
103
|
|
|
128
|
-
|
|
104
|
+
**Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
|
|
129
105
|
|
|
130
|
-
|
|
106
|
+
#### `vue`
|
|
131
107
|
|
|
132
108
|
If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
|
|
133
109
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
### parallel
|
|
110
|
+
#### `parallel`
|
|
137
111
|
|
|
138
112
|
If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
|
|
139
113
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
### eager
|
|
114
|
+
#### `eager`
|
|
143
115
|
|
|
144
116
|
If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
|
|
145
117
|
|
|
146
118
|
This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
|
|
147
119
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
### newContext
|
|
120
|
+
#### `newContext`
|
|
151
121
|
|
|
152
122
|
If `true`, the plugin will create a new isolated context for each build,
|
|
153
123
|
ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
@@ -156,29 +126,40 @@ By default, the plugin may reuse internal caches or incremental build artifacts
|
|
|
156
126
|
to speed up repeated builds. Enabling this option forces a clean context,
|
|
157
127
|
guaranteeing that all type definitions are generated from scratch.
|
|
158
128
|
|
|
159
|
-
|
|
129
|
+
`invalidateContextFile` API can be used to clear invalidated files from the context.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { globalContext, invalidateContextFile } from 'rolldown-plugin-dts/tsc'
|
|
133
|
+
invalidateContextFile(globalContext, 'src/foo.ts')
|
|
134
|
+
```
|
|
160
135
|
|
|
161
|
-
|
|
136
|
+
#### `emitJs`
|
|
162
137
|
|
|
163
138
|
If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
|
|
164
139
|
This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
|
|
165
140
|
|
|
166
141
|
Enabled by default when `allowJs` in compilerOptions is `true`.
|
|
167
142
|
|
|
168
|
-
|
|
143
|
+
### Oxc
|
|
169
144
|
|
|
170
|
-
|
|
145
|
+
#### `oxc`
|
|
171
146
|
|
|
172
|
-
|
|
147
|
+
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
148
|
|
|
174
|
-
|
|
149
|
+
This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
175
150
|
|
|
176
|
-
|
|
151
|
+
### TypeScript Go
|
|
177
152
|
|
|
178
153
|
> [!WARNING]
|
|
179
|
-
> This
|
|
154
|
+
> This feature is experimental and not yet recommended for production environments.
|
|
155
|
+
|
|
156
|
+
#### `tsgo`
|
|
157
|
+
|
|
158
|
+
**[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
|
|
159
|
+
|
|
160
|
+
To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
|
|
180
161
|
|
|
181
|
-
|
|
162
|
+
`tsconfigRaw` option will be ignored when this option is enabled.
|
|
182
163
|
|
|
183
164
|
## Differences from `rollup-plugin-dts`
|
|
184
165
|
|
|
@@ -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,11 +1,12 @@
|
|
|
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;
|
|
@@ -17,7 +18,6 @@ interface TscOptions {
|
|
|
17
18
|
vue?: boolean;
|
|
18
19
|
context?: TscContext;
|
|
19
20
|
}
|
|
20
|
-
declare function createContext(): TscContext;
|
|
21
21
|
interface TscResult {
|
|
22
22
|
code?: string;
|
|
23
23
|
map?: SourceMapInput;
|
|
@@ -25,4 +25,4 @@ interface TscResult {
|
|
|
25
25
|
}
|
|
26
26
|
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
27
27
|
//#endregion
|
|
28
|
-
export {
|
|
28
|
+
export { TscModule, TscOptions, TscResult, tscEmit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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";
|
|
@@ -63,7 +62,7 @@ interface Options {
|
|
|
63
62
|
* [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
|
|
64
63
|
* enabled.
|
|
65
64
|
*
|
|
66
|
-
* This option is only used when {@link Options.
|
|
65
|
+
* This option is only used when {@link Options.oxc} is
|
|
67
66
|
* `false`.
|
|
68
67
|
*/
|
|
69
68
|
incremental?: boolean;
|
|
@@ -79,7 +78,7 @@ interface Options {
|
|
|
79
78
|
*
|
|
80
79
|
* This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
|
|
81
80
|
*/
|
|
82
|
-
|
|
81
|
+
oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
83
82
|
/**
|
|
84
83
|
* If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
|
|
85
84
|
*/
|
|
@@ -128,13 +127,15 @@ interface Options {
|
|
|
128
127
|
* This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
|
|
129
128
|
*
|
|
130
129
|
* Enabled by default when `allowJs` in compilerOptions is `true`.
|
|
130
|
+
* This option is only used when {@link Options.oxc} is
|
|
131
|
+
* `false`.
|
|
131
132
|
*/
|
|
132
133
|
emitJs?: boolean;
|
|
133
134
|
}
|
|
134
135
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
135
136
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
136
137
|
tsconfig: string | undefined;
|
|
137
|
-
|
|
138
|
+
oxc: IsolatedDeclarationsOptions | false;
|
|
138
139
|
tsconfigRaw: TsConfigJson;
|
|
139
140
|
}>;
|
|
140
141
|
declare function resolveOptions({
|
|
@@ -143,7 +144,7 @@ declare function resolveOptions({
|
|
|
143
144
|
incremental,
|
|
144
145
|
compilerOptions,
|
|
145
146
|
tsconfigRaw: overriddenTsconfigRaw,
|
|
146
|
-
|
|
147
|
+
oxc,
|
|
147
148
|
sourcemap,
|
|
148
149
|
dtsInput,
|
|
149
150
|
emitDtsOnly,
|
|
@@ -168,7 +169,7 @@ declare function createGeneratePlugin({
|
|
|
168
169
|
tsconfigRaw,
|
|
169
170
|
incremental,
|
|
170
171
|
cwd,
|
|
171
|
-
|
|
172
|
+
oxc,
|
|
172
173
|
emitDtsOnly,
|
|
173
174
|
vue,
|
|
174
175
|
parallel,
|
|
@@ -176,9 +177,9 @@ declare function createGeneratePlugin({
|
|
|
176
177
|
tsgo,
|
|
177
178
|
newContext,
|
|
178
179
|
emitJs
|
|
179
|
-
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "
|
|
180
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs">): Plugin;
|
|
180
181
|
//#endregion
|
|
181
182
|
//#region src/index.d.ts
|
|
182
183
|
declare function dts(options?: Options): Plugin[];
|
|
183
184
|
//#endregion
|
|
184
|
-
export { type Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE,
|
|
185
|
+
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, 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({
|
|
@@ -799,6 +797,9 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
799
797
|
}).catch(() => {});
|
|
800
798
|
tsgoDist = void 0;
|
|
801
799
|
if (newContext) tscContext = void 0;
|
|
800
|
+
},
|
|
801
|
+
watchChange(id) {
|
|
802
|
+
if (tscModule) invalidateContextFile(tscContext || globalContext, id);
|
|
802
803
|
}
|
|
803
804
|
};
|
|
804
805
|
}
|
|
@@ -826,7 +827,7 @@ async function runTsgo(root, tsconfig) {
|
|
|
826
827
|
//#endregion
|
|
827
828
|
//#region src/options.ts
|
|
828
829
|
let warnedTsgo = false;
|
|
829
|
-
function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {},
|
|
830
|
+
function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, oxc, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false, newContext = false, emitJs }) {
|
|
830
831
|
let resolvedTsconfig;
|
|
831
832
|
if (tsconfig === true || tsconfig == null) {
|
|
832
833
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -848,13 +849,18 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
848
849
|
...overriddenTsconfigRaw,
|
|
849
850
|
compilerOptions
|
|
850
851
|
};
|
|
851
|
-
|
|
852
|
-
if (
|
|
853
|
-
if (
|
|
854
|
-
|
|
855
|
-
|
|
852
|
+
oxc ??= !!(compilerOptions?.isolatedDeclarations && !vue && !tsgo);
|
|
853
|
+
if (oxc === true) oxc = {};
|
|
854
|
+
if (oxc) {
|
|
855
|
+
oxc.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
856
|
+
oxc.sourcemap = !!compilerOptions.declarationMap;
|
|
856
857
|
}
|
|
857
858
|
emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
|
|
859
|
+
if (tsgo) {
|
|
860
|
+
if (vue) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");
|
|
861
|
+
if (oxc) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.");
|
|
862
|
+
}
|
|
863
|
+
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
864
|
if (tsgo && !warnedTsgo) {
|
|
859
865
|
console.warn("The `tsgo` option is experimental and may change in the future.");
|
|
860
866
|
warnedTsgo = true;
|
|
@@ -864,7 +870,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
864
870
|
tsconfig,
|
|
865
871
|
tsconfigRaw,
|
|
866
872
|
incremental,
|
|
867
|
-
|
|
873
|
+
oxc,
|
|
868
874
|
sourcemap,
|
|
869
875
|
dtsInput,
|
|
870
876
|
emitDtsOnly,
|
|
@@ -940,4 +946,4 @@ function dts(options = {}) {
|
|
|
940
946
|
}
|
|
941
947
|
|
|
942
948
|
//#endregion
|
|
943
|
-
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE,
|
|
949
|
+
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,
|
|
@@ -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-BjWJCGE1.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.0",
|
|
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