rolldown-plugin-dts 0.7.4 → 0.7.7

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 CHANGED
@@ -45,13 +45,23 @@ interface Options {
45
45
  */
46
46
  emitDtsOnly?: boolean
47
47
 
48
+ /**
49
+ * The path to the `tsconfig.json` file.
50
+ *
51
+ * When set to `false`, the plugin will ignore any `tsconfig.json` file.
52
+ * However, `compilerOptions` can still be specified directly in the options.
53
+ *
54
+ * @default `tsconfig.json`
55
+ */
56
+ tsconfig?: string | boolean
57
+
48
58
  /**
49
59
  * The `compilerOptions` for the TypeScript compiler.
50
- * The default value will be inferred from the `tsconfig.json` file.
51
60
  *
52
61
  * @see https://www.typescriptlang.org/docs/handbook/compiler-options.html
53
62
  */
54
63
  compilerOptions?: TsConfigJson.CompilerOptions
64
+
55
65
  /**
56
66
  * When `true`, the plugin will generate `.d.ts` files using `oxc-transform`,
57
67
  * which is blazingly faster than `typescript` compiler.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ declare function createFakeJsPlugin({ dtsInput }: Pick<Options, "dtsInput">): Pl
7
7
 
8
8
  //#endregion
9
9
  //#region src/generate.d.ts
10
- declare function createGeneratePlugin({ compilerOptions, isolatedDeclaration, resolve, emitDtsOnly }: Pick<Options, "isolatedDeclaration" | "resolve" | "emitDtsOnly" | "compilerOptions">): Plugin;
10
+ declare function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclaration, resolve, emitDtsOnly }: Pick<Options, "isolatedDeclaration" | "resolve" | "emitDtsOnly" | "tsconfig" | "compilerOptions">): Plugin;
11
11
 
12
12
  //#endregion
13
13
  //#region src/index.d.ts
@@ -25,8 +25,16 @@ interface Options {
25
25
  */
26
26
  emitDtsOnly?: boolean;
27
27
  /**
28
+ * The path to the `tsconfig.json` file.
29
+ *
30
+ * When set to `false`, the plugin will ignore any `tsconfig.json` file.
31
+ * However, `compilerOptions` can still be specified directly in the options.
32
+ *
33
+ * @default `tsconfig.json`
34
+ */
35
+ tsconfig?: string | boolean;
36
+ /**
28
37
  * The `compilerOptions` for the TypeScript compiler.
29
- * The default value will be inferred from the `tsconfig.json` file.
30
38
  *
31
39
  * @see https://www.typescriptlang.org/docs/handbook/compiler-options.html
32
40
  */
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { MagicStringAST } from "magic-string-ast";
2
2
  import { parseSync } from "oxc-parser";
3
- import path from "node:path";
4
3
  import { createResolver } from "dts-resolver";
5
- import { getTsconfig } from "get-tsconfig";
4
+ import { getTsconfig, parseTsconfig } from "get-tsconfig";
6
5
  import { isolatedDeclaration } from "oxc-transform";
7
6
  import { createRequire } from "node:module";
8
7
  import Debug from "debug";
@@ -173,7 +172,7 @@ function getIdentifierRange(node, offset = 0) {
173
172
  const RE_JS = /\.([cm]?)jsx?$/;
174
173
  const RE_TS = /\.([cm]?)tsx?$/;
175
174
  const RE_DTS = /\.d\.([cm]?)ts$/;
176
- const RE_NODE_MODULES = /node_modules/;
175
+ const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
177
176
  function filename_js_to_dts(id) {
178
177
  return id.replace(RE_JS, ".d.$1ts");
179
178
  }
@@ -183,9 +182,6 @@ function filename_ts_to_dts(id) {
183
182
  function filename_dts_to(id, ext) {
184
183
  return id.replace(RE_DTS, `.$1${ext}`);
185
184
  }
186
- function isRelative(id) {
187
- return path.isAbsolute(id) || id[0] === ".";
188
- }
189
185
 
190
186
  //#endregion
191
187
  //#region src/utils/magic-string.ts
@@ -562,8 +558,27 @@ function tscEmit(module) {
562
558
  //#endregion
563
559
  //#region src/generate.ts
564
560
  const meta = { dtsFile: true };
565
- function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDeclaration$1, resolve = false, emitDtsOnly = false }) {
561
+ function createGeneratePlugin({ tsconfig, compilerOptions, isolatedDeclaration: isolatedDeclaration$1, resolve = false, emitDtsOnly = false }) {
566
562
  const dtsMap = new Map();
563
+ function resolveOptions(cwd) {
564
+ if (tsconfig === true || tsconfig == null) {
565
+ const { config, path } = getTsconfig(cwd) || {};
566
+ tsconfig = path;
567
+ compilerOptions = {
568
+ ...config?.compilerOptions,
569
+ ...compilerOptions
570
+ };
571
+ } else if (typeof tsconfig === "string") {
572
+ const config = parseTsconfig(tsconfig);
573
+ compilerOptions = {
574
+ ...config.compilerOptions,
575
+ ...compilerOptions
576
+ };
577
+ }
578
+ if (isolatedDeclaration$1 == null) isolatedDeclaration$1 = !!compilerOptions?.isolatedDeclarations;
579
+ if (isolatedDeclaration$1 === true) isolatedDeclaration$1 = {};
580
+ if (isolatedDeclaration$1 && isolatedDeclaration$1.stripInternal == null) isolatedDeclaration$1.stripInternal = !!compilerOptions?.stripInternal;
581
+ }
567
582
  /**
568
583
  * A map of input id to output file name
569
584
  *
@@ -574,18 +589,13 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
574
589
  * ])
575
590
  */
576
591
  const inputAliasMap = new Map();
577
- const resolver = createResolver();
592
+ let resolver;
578
593
  let programs = [];
579
594
  return {
580
595
  name: "rolldown-plugin-dts:generate",
581
596
  async buildStart(options) {
582
- if (!compilerOptions) {
583
- const { config } = getTsconfig(options.cwd) || {};
584
- compilerOptions = config?.compilerOptions;
585
- }
586
- if (isolatedDeclaration$1 == null) isolatedDeclaration$1 = !!compilerOptions?.isolatedDeclarations;
587
- if (isolatedDeclaration$1 === true) isolatedDeclaration$1 = {};
588
- if (isolatedDeclaration$1 && isolatedDeclaration$1.stripInternal == null) isolatedDeclaration$1.stripInternal = !!compilerOptions?.stripInternal;
597
+ resolveOptions(options.cwd);
598
+ resolver = createResolver({ tsconfig: tsconfig ? tsconfig : void 0 });
589
599
  if (!isolatedDeclaration$1) initTs();
590
600
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
591
601
  let resolved = await this.resolve(id, void 0, { skipSelf: true });
@@ -660,7 +670,9 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
660
670
  meta
661
671
  };
662
672
  }
663
- if (!isRelative(id)) {
673
+ let resolution = await this.resolve(id, filename_dts_to(importer, "ts"));
674
+ if (!resolution || resolution.external) return resolution;
675
+ if (RE_NODE_MODULES.test(resolution.id)) {
664
676
  let shouldResolve;
665
677
  if (typeof resolve === "boolean") shouldResolve = resolve;
666
678
  else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
@@ -676,8 +688,6 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
676
688
  meta
677
689
  };
678
690
  }
679
- let resolution = await this.resolve(id, filename_dts_to(importer, "ts"));
680
- if (!resolution || resolution.external) return;
681
691
  let dtsId;
682
692
  if (RE_JS.test(resolution.id)) {
683
693
  resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, { skipSelf: false });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.7.4",
3
+ "version": "0.7.7",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "debug": "^4.4.0",
41
- "dts-resolver": "^0.1.1",
41
+ "dts-resolver": "^1.0.0",
42
42
  "get-tsconfig": "^4.10.0",
43
43
  "magic-string-ast": "^0.9.1",
44
44
  "oxc-parser": "^0.64.0",