rolldown-plugin-dts 0.7.1 → 0.7.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 +42 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { MagicStringAST } from "magic-string-ast";
2
2
  import { parseSync } from "oxc-parser";
3
3
  import path from "node:path";
4
- import process from "node:process";
5
4
  import { createResolver } from "dts-resolver";
6
5
  import { getTsconfig } from "get-tsconfig";
7
6
  import { isolatedDeclaration } from "oxc-transform";
@@ -171,7 +170,7 @@ function getIdentifierRange(node, offset = 0) {
171
170
 
172
171
  //#endregion
173
172
  //#region src/utils/filename.ts
174
- const RE_JS = /\.([cm]?)js$/;
173
+ const RE_JS = /\.([cm]?)jsx?$/;
175
174
  const RE_TS = /\.([cm]?)tsx?$/;
176
175
  const RE_DTS = /\.d\.([cm]?)ts$/;
177
176
  const RE_NODE_MODULES = /node_modules/;
@@ -579,7 +578,7 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
579
578
  let programs = [];
580
579
  return {
581
580
  name: "rolldown-plugin-dts:generate",
582
- buildStart(options) {
581
+ async buildStart(options) {
583
582
  if (!compilerOptions) {
584
583
  const { config } = getTsconfig(options.cwd) || {};
585
584
  compilerOptions = config?.compilerOptions;
@@ -588,12 +587,10 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
588
587
  if (isolatedDeclaration$1 === true) isolatedDeclaration$1 = {};
589
588
  if (isolatedDeclaration$1 && isolatedDeclaration$1.stripInternal == null) isolatedDeclaration$1.stripInternal = !!compilerOptions?.stripInternal;
590
589
  if (!isolatedDeclaration$1) initTs();
591
- if (!Array.isArray(options.input)) {
592
- const cwd = options.cwd || process.cwd();
593
- for (const [fileName, inputFilePath] of Object.entries(options.input)) {
594
- const id = path.resolve(cwd, inputFilePath);
595
- inputAliasMap.set(id, fileName);
596
- }
590
+ if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
591
+ let resolved = await this.resolve(id, void 0, { skipSelf: true });
592
+ resolved ||= await this.resolve(`./${id}`, void 0, { skipSelf: true });
593
+ inputAliasMap.set(resolved?.id || id, name);
597
594
  }
598
595
  },
599
596
  outputOptions(options) {
@@ -649,41 +646,55 @@ function createGeneratePlugin({ compilerOptions, isolatedDeclaration: isolatedDe
649
646
  }
650
647
  }
651
648
  },
652
- async resolveId(id, importer) {
649
+ async resolveId(id, importer, options) {
653
650
  if (dtsMap.has(id)) return {
654
651
  id,
655
652
  meta
656
653
  };
657
- if (importer && this.getModuleInfo(importer)?.meta.dtsFile) {
658
- if (!isRelative(id)) {
659
- let shouldResolve;
660
- if (typeof resolve === "boolean") shouldResolve = resolve;
661
- else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
662
- if (shouldResolve) {
663
- const resolution$1 = resolver(id, importer);
664
- if (resolution$1) return {
665
- id: resolution$1,
666
- meta
667
- };
668
- } else return {
669
- id,
670
- external: true,
654
+ if (!importer || !this.getModuleInfo(importer)?.meta.dtsFile) return;
655
+ if (RE_DTS.test(id)) {
656
+ const resolution$1 = await this.resolve(id, importer, options);
657
+ if (!resolution$1) return;
658
+ return {
659
+ ...resolution$1,
660
+ meta
661
+ };
662
+ }
663
+ if (!isRelative(id)) {
664
+ let shouldResolve;
665
+ if (typeof resolve === "boolean") shouldResolve = resolve;
666
+ else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
667
+ if (shouldResolve) {
668
+ const resolution$1 = resolver(id, importer);
669
+ if (resolution$1) return {
670
+ id: resolution$1,
671
671
  meta
672
672
  };
673
- }
674
- const resolution = await this.resolve(id, filename_dts_to(importer, "ts"));
675
- if (!resolution || resolution.external) return;
676
- const dtsId = filename_ts_to_dts(resolution.id);
677
- if (dtsMap.has(dtsId)) return {
678
- id: dtsId,
673
+ } else return {
674
+ id,
675
+ external: true,
679
676
  meta
680
677
  };
681
- await this.load(resolution);
678
+ }
679
+ let resolution = await this.resolve(id, filename_dts_to(importer, "ts"));
680
+ if (!resolution || resolution.external) return;
681
+ let dtsId;
682
+ if (RE_JS.test(resolution.id)) {
683
+ resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, { skipSelf: false });
684
+ if (!resolution) return;
685
+ dtsId = resolution.id;
686
+ } else {
687
+ dtsId = filename_ts_to_dts(resolution.id);
682
688
  if (dtsMap.has(dtsId)) return {
683
689
  id: dtsId,
684
690
  meta
685
691
  };
686
692
  }
693
+ await this.load(resolution);
694
+ if (RE_DTS.test(resolution.id) || dtsMap.has(dtsId)) return {
695
+ id: dtsId,
696
+ meta
697
+ };
687
698
  },
688
699
  load: {
689
700
  filter: { id: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",