rolldown-plugin-dts 0.8.1 → 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 +46 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { MagicStringAST } from "magic-string-ast";
|
|
2
3
|
import { parseSync } from "oxc-parser";
|
|
3
|
-
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { createResolver } from "dts-resolver";
|
|
6
6
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
@@ -8,6 +8,49 @@ import { isolatedDeclaration } from "oxc-transform";
|
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import Debug from "debug";
|
|
10
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
|
|
11
54
|
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
12
55
|
var WalkerBase = class {
|
|
13
56
|
constructor() {
|
|
@@ -169,25 +212,6 @@ function getIdentifierRange(node, offset = 0) {
|
|
|
169
212
|
return [node.start + offset, node.end + offset];
|
|
170
213
|
}
|
|
171
214
|
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/utils/filename.ts
|
|
174
|
-
const RE_JS = /\.([cm]?)jsx?$/;
|
|
175
|
-
const RE_TS = /\.([cm]?)tsx?$/;
|
|
176
|
-
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
177
|
-
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
178
|
-
function filename_js_to_dts(id) {
|
|
179
|
-
return id.replace(RE_JS, ".d.$1ts");
|
|
180
|
-
}
|
|
181
|
-
function filename_ts_to_dts(id) {
|
|
182
|
-
return id.replace(RE_TS, ".d.$1ts");
|
|
183
|
-
}
|
|
184
|
-
function filename_dts_to(id, ext) {
|
|
185
|
-
return id.replace(RE_DTS, `.$1${ext}`);
|
|
186
|
-
}
|
|
187
|
-
function isRelative(id) {
|
|
188
|
-
return path.isAbsolute(id) || id[0] === ".";
|
|
189
|
-
}
|
|
190
|
-
|
|
191
215
|
//#endregion
|
|
192
216
|
//#region src/utils/magic-string.ts
|
|
193
217
|
function overwriteOrAppend(s, range, replacement, suffix) {
|
|
@@ -756,7 +780,8 @@ function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclarations,
|
|
|
756
780
|
//#region src/index.ts
|
|
757
781
|
function dts(options = {}) {
|
|
758
782
|
const plugins = [];
|
|
759
|
-
if (
|
|
783
|
+
if (options.dtsInput) plugins.push(createDtsInputPlugin());
|
|
784
|
+
else plugins.push(createGeneratePlugin(options));
|
|
760
785
|
plugins.push(createFakeJsPlugin(options));
|
|
761
786
|
return plugins;
|
|
762
787
|
}
|