rolldown-plugin-dts 0.8.1 → 0.8.3

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -25
  2. package/package.json +11 -8
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,7 +8,58 @@ 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
55
+ /**
56
+ * @typedef { import('estree').Node} Node
57
+ * @typedef {{
58
+ * skip: () => void;
59
+ * remove: () => void;
60
+ * replace: (node: Node) => void;
61
+ * }} WalkerContext
62
+ */
12
63
  var WalkerBase = class {
13
64
  constructor() {
14
65
  /** @type {boolean} */
@@ -52,6 +103,17 @@ var WalkerBase = class {
52
103
 
53
104
  //#endregion
54
105
  //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
106
+ /**
107
+ * @typedef { import('estree').Node} Node
108
+ * @typedef { import('./walker.js').WalkerContext} WalkerContext
109
+ * @typedef {(
110
+ * this: WalkerContext,
111
+ * node: Node,
112
+ * parent: Node | null,
113
+ * key: string | number | symbol | null | undefined,
114
+ * index: number | null | undefined
115
+ * ) => void} SyncHandler
116
+ */
55
117
  var SyncWalker = class extends WalkerBase {
56
118
  /**
57
119
  *
@@ -157,6 +219,19 @@ function isNode(value) {
157
219
 
158
220
  //#endregion
159
221
  //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
222
+ /**
223
+ * @typedef {import('estree').Node} Node
224
+ * @typedef {import('./sync.js').SyncHandler} SyncHandler
225
+ * @typedef {import('./async.js').AsyncHandler} AsyncHandler
226
+ */
227
+ /**
228
+ * @param {Node} ast
229
+ * @param {{
230
+ * enter?: SyncHandler
231
+ * leave?: SyncHandler
232
+ * }} walker
233
+ * @returns {Node | null}
234
+ */
160
235
  function walk(ast, { enter, leave }) {
161
236
  const instance = new SyncWalker(enter, leave);
162
237
  return instance.visit(ast, null);
@@ -169,25 +244,6 @@ function getIdentifierRange(node, offset = 0) {
169
244
  return [node.start + offset, node.end + offset];
170
245
  }
171
246
 
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
247
  //#endregion
192
248
  //#region src/utils/magic-string.ts
193
249
  function overwriteOrAppend(s, range, replacement, suffix) {
@@ -267,7 +323,6 @@ function createFakeJsPlugin({ dtsInput }) {
267
323
  if (node.type === "TSDeclareFunction" || node.type.endsWith("Declaration")) {
268
324
  const binding = node.type === "VariableDeclaration" ? node.declarations[0].id : node.id;
269
325
  const code$1 = s.sliceNode(node);
270
- const jsdoc = comments.find((c) => c.type === "Block" && c.value[0] === "*" && c.start < node.start && stmt.start - c.end <= 1);
271
326
  const offset = node.start;
272
327
  let bindingRange;
273
328
  if (sideEffect) bindingRange = [0, 0];
@@ -289,7 +344,6 @@ function createFakeJsPlugin({ dtsInput }) {
289
344
  binding: bindingRange,
290
345
  deps: depsSymbols,
291
346
  needDeclare,
292
- jsdoc: jsdoc ? s.sliceNode(jsdoc) : void 0,
293
347
  preserveName: sideEffect
294
348
  });
295
349
  const runtime = `[${symbolId}, ${depsString}${depsString && sideEffect ? ", " : ""}${sideEffect ? "sideEffect()" : ""}]`;
@@ -332,7 +386,7 @@ function createFakeJsPlugin({ dtsInput }) {
332
386
  continue;
333
387
  }
334
388
  const symbolId = symbolIdNode.value;
335
- const { code: code$1, binding, deps, needDeclare, jsdoc, preserveName } = retrieve(symbolId);
389
+ const { code: code$1, binding, deps, needDeclare, preserveName } = retrieve(symbolId);
336
390
  const depsRaw = depsNodes.filter((node$1) => node$1?.type === "ArrowFunctionExpression").map((dep) => s.sliceNode(dep.body));
337
391
  const ss = new MagicStringAST(code$1);
338
392
  if (!preserveName) overwriteOrAppend(ss, binding, s.sliceNode(decl.id));
@@ -341,7 +395,6 @@ function createFakeJsPlugin({ dtsInput }) {
341
395
  overwriteOrAppend(ss, [start, end], depsRaw.shift(), suffix);
342
396
  }
343
397
  if (needDeclare) ss.prepend("declare ");
344
- if (jsdoc) ss.prepend(`${jsdoc}\n`);
345
398
  s.overwriteNode(node, ss.toString());
346
399
  }
347
400
  const str = s.toString();
@@ -756,7 +809,8 @@ function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclarations,
756
809
  //#region src/index.ts
757
810
  function dts(options = {}) {
758
811
  const plugins = [];
759
- if (!options.dtsInput) plugins.push(createGeneratePlugin(options));
812
+ if (options.dtsInput) plugins.push(createDtsInputPlugin());
813
+ else plugins.push(createGeneratePlugin(options));
760
814
  plugins.push(createFakeJsPlugin(options));
761
815
  return plugins;
762
816
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -41,11 +41,11 @@
41
41
  "dts-resolver": "^1.0.0",
42
42
  "get-tsconfig": "^4.10.0",
43
43
  "magic-string-ast": "^0.9.1",
44
- "oxc-parser": "^0.64.0",
45
- "oxc-transform": "^0.64.0"
44
+ "oxc-parser": "^0.65.0",
45
+ "oxc-transform": "^0.65.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@sxzz/eslint-config": "^6.1.1",
48
+ "@sxzz/eslint-config": "^6.1.2",
49
49
  "@sxzz/prettier-config": "^2.2.1",
50
50
  "@sxzz/test-utils": "^0.5.5",
51
51
  "@types/debug": "^4.1.12",
@@ -53,19 +53,22 @@
53
53
  "@types/node": "^22.14.1",
54
54
  "bumpp": "^10.1.0",
55
55
  "diff": "^7.0.0",
56
- "eslint": "^9.25.0",
56
+ "eslint": "^9.25.1",
57
57
  "estree-walker": "^3.0.3",
58
58
  "prettier": "^3.5.3",
59
- "rolldown": "^1.0.0-beta.7",
59
+ "rolldown": "1.0.0-beta.7-commit.c2596d3",
60
60
  "rollup-plugin-dts": "^6.2.1",
61
- "tsdown": "^0.8.1",
61
+ "tsdown": "^0.9.2",
62
62
  "tsx": "^4.19.3",
63
63
  "typescript": "^5.8.3",
64
- "vitest": "^3.1.1"
64
+ "vitest": "^3.1.2"
65
65
  },
66
66
  "engines": {
67
67
  "node": ">=20.18.0"
68
68
  },
69
+ "resolutions": {
70
+ "rolldown-plugin-dts": "workspace:*"
71
+ },
69
72
  "prettier": "@sxzz/prettier-config",
70
73
  "scripts": {
71
74
  "lint": "eslint --cache .",