rolldown-plugin-dts 0.8.0 → 0.8.2
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/dist/index.js +48 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,56 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { MagicStringAST } from "magic-string-ast";
|
|
2
3
|
import { parseSync } from "oxc-parser";
|
|
3
|
-
import
|
|
4
|
+
import process from "node:process";
|
|
4
5
|
import { createResolver } from "dts-resolver";
|
|
5
6
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
6
7
|
import { isolatedDeclaration } from "oxc-transform";
|
|
7
8
|
import { createRequire } from "node:module";
|
|
8
9
|
import Debug from "debug";
|
|
9
10
|
|
|
11
|
+
//#region src/utils/filename.ts
|
|
12
|
+
const RE_JS = /\.([cm]?)jsx?$/;
|
|
13
|
+
const RE_TS = /\.([cm]?)tsx?$/;
|
|
14
|
+
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
15
|
+
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
16
|
+
function filename_js_to_dts(id) {
|
|
17
|
+
return id.replace(RE_JS, ".d.$1ts");
|
|
18
|
+
}
|
|
19
|
+
function filename_ts_to_dts(id) {
|
|
20
|
+
return id.replace(RE_TS, ".d.$1ts");
|
|
21
|
+
}
|
|
22
|
+
function filename_dts_to(id, ext) {
|
|
23
|
+
return id.replace(RE_DTS, `.$1${ext}`);
|
|
24
|
+
}
|
|
25
|
+
function isRelative(id) {
|
|
26
|
+
return path.isAbsolute(id) || id[0] === ".";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/dts-input.ts
|
|
31
|
+
function createDtsInputPlugin() {
|
|
32
|
+
return {
|
|
33
|
+
name: "rolldown-plugin-dts:dts-input",
|
|
34
|
+
outputOptions(options) {
|
|
35
|
+
return {
|
|
36
|
+
...options,
|
|
37
|
+
entryFileNames: "[name].ts"
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
resolveId: {
|
|
41
|
+
order: "pre",
|
|
42
|
+
handler(id, importer, options) {
|
|
43
|
+
if (options.isEntry) return;
|
|
44
|
+
if (RE_NODE_MODULES.test(id) || !isRelative(id)) return {
|
|
45
|
+
id,
|
|
46
|
+
external: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
10
54
|
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
11
55
|
var WalkerBase = class {
|
|
12
56
|
constructor() {
|
|
@@ -168,25 +212,6 @@ function getIdentifierRange(node, offset = 0) {
|
|
|
168
212
|
return [node.start + offset, node.end + offset];
|
|
169
213
|
}
|
|
170
214
|
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/utils/filename.ts
|
|
173
|
-
const RE_JS = /\.([cm]?)jsx?$/;
|
|
174
|
-
const RE_TS = /\.([cm]?)tsx?$/;
|
|
175
|
-
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
176
|
-
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
177
|
-
function filename_js_to_dts(id) {
|
|
178
|
-
return id.replace(RE_JS, ".d.$1ts");
|
|
179
|
-
}
|
|
180
|
-
function filename_ts_to_dts(id) {
|
|
181
|
-
return id.replace(RE_TS, ".d.$1ts");
|
|
182
|
-
}
|
|
183
|
-
function filename_dts_to(id, ext) {
|
|
184
|
-
return id.replace(RE_DTS, `.$1${ext}`);
|
|
185
|
-
}
|
|
186
|
-
function isRelative(id) {
|
|
187
|
-
return path.isAbsolute(id) || id[0] === ".";
|
|
188
|
-
}
|
|
189
|
-
|
|
190
215
|
//#endregion
|
|
191
216
|
//#region src/utils/magic-string.ts
|
|
192
217
|
function overwriteOrAppend(s, range, replacement, suffix) {
|
|
@@ -579,6 +604,7 @@ function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclarations,
|
|
|
579
604
|
...compilerOptions
|
|
580
605
|
};
|
|
581
606
|
} else if (typeof tsconfig === "string") {
|
|
607
|
+
tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
|
|
582
608
|
const config = parseTsconfig(tsconfig);
|
|
583
609
|
compilerOptions = {
|
|
584
610
|
...config.compilerOptions,
|
|
@@ -754,7 +780,8 @@ function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclarations,
|
|
|
754
780
|
//#region src/index.ts
|
|
755
781
|
function dts(options = {}) {
|
|
756
782
|
const plugins = [];
|
|
757
|
-
if (
|
|
783
|
+
if (options.dtsInput) plugins.push(createDtsInputPlugin());
|
|
784
|
+
else plugins.push(createGeneratePlugin(options));
|
|
758
785
|
plugins.push(createFakeJsPlugin(options));
|
|
759
786
|
return plugins;
|
|
760
787
|
}
|