rolldown-plugin-dts 0.9.2 → 0.9.4
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 +23 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -631,11 +631,11 @@ function overwriteNode(node, newNode) {
|
|
|
631
631
|
|
|
632
632
|
//#endregion
|
|
633
633
|
//#region src/utils/tsc.ts
|
|
634
|
-
const debug$
|
|
634
|
+
const debug$2 = Debug("rolldown-plugin-dts:tsc");
|
|
635
635
|
let ts;
|
|
636
636
|
let formatHost;
|
|
637
637
|
function initTs() {
|
|
638
|
-
debug$
|
|
638
|
+
debug$2("loading typescript");
|
|
639
639
|
const require = createRequire(import.meta.url);
|
|
640
640
|
ts = require("typescript");
|
|
641
641
|
formatHost = {
|
|
@@ -643,7 +643,7 @@ function initTs() {
|
|
|
643
643
|
getNewLine: () => ts.sys.newLine,
|
|
644
644
|
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
645
645
|
};
|
|
646
|
-
debug$
|
|
646
|
+
debug$2(`loaded typescript: ${ts.version}`);
|
|
647
647
|
}
|
|
648
648
|
const defaultCompilerOptions = {
|
|
649
649
|
declaration: true,
|
|
@@ -669,9 +669,9 @@ function createOrGetTsModule(programs, compilerOptions, id, isEntry, dtsMap) {
|
|
|
669
669
|
file: sourceFile
|
|
670
670
|
};
|
|
671
671
|
}
|
|
672
|
-
debug$
|
|
672
|
+
debug$2(`create program for module: ${id}`);
|
|
673
673
|
const module = createTsProgram(compilerOptions, dtsMap, id);
|
|
674
|
-
debug$
|
|
674
|
+
debug$2(`created program for module: ${id}`);
|
|
675
675
|
programs.push(module.program);
|
|
676
676
|
return module;
|
|
677
677
|
}
|
|
@@ -686,13 +686,13 @@ function createTsProgram(compilerOptions, dtsMap, id) {
|
|
|
686
686
|
host.fileExists = (fileName) => {
|
|
687
687
|
const module = getTsModule(dtsMap, fileName);
|
|
688
688
|
if (module) return true;
|
|
689
|
-
if (debug$
|
|
689
|
+
if (debug$2.enabled && !RE_NODE_MODULES.test(fileName)) debug$2(`file exists from fs: ${fileName}`);
|
|
690
690
|
return _fileExists(fileName);
|
|
691
691
|
};
|
|
692
692
|
host.readFile = (fileName) => {
|
|
693
693
|
const module = getTsModule(dtsMap, fileName);
|
|
694
694
|
if (module) return module.code;
|
|
695
|
-
if (debug$
|
|
695
|
+
if (debug$2.enabled && !RE_NODE_MODULES.test(fileName)) debug$2(`read file from fs: ${fileName}`);
|
|
696
696
|
return _readFile(fileName);
|
|
697
697
|
};
|
|
698
698
|
const entries = Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id);
|
|
@@ -712,10 +712,10 @@ function tscEmit(module) {
|
|
|
712
712
|
file,
|
|
713
713
|
(fileName, code) => {
|
|
714
714
|
if (fileName.endsWith(".map")) {
|
|
715
|
-
debug$
|
|
715
|
+
debug$2(`emit dts sourcemap: ${fileName}`);
|
|
716
716
|
map = JSON.parse(code);
|
|
717
717
|
} else {
|
|
718
|
-
debug$
|
|
718
|
+
debug$2(`emit dts: ${fileName}`);
|
|
719
719
|
dtsCode = code;
|
|
720
720
|
}
|
|
721
721
|
},
|
|
@@ -739,6 +739,7 @@ function getTsModule(dtsMap, tsId) {
|
|
|
739
739
|
|
|
740
740
|
//#endregion
|
|
741
741
|
//#region src/generate.ts
|
|
742
|
+
const debug$1 = Debug("rolldown-plugin-dts:generate");
|
|
742
743
|
function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emitDtsOnly = false }) {
|
|
743
744
|
const dtsMap = new Map();
|
|
744
745
|
/**
|
|
@@ -757,9 +758,12 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
757
758
|
name: "rolldown-plugin-dts:generate",
|
|
758
759
|
async buildStart(options) {
|
|
759
760
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
760
|
-
|
|
761
|
-
resolved
|
|
762
|
-
|
|
761
|
+
debug$1("resolving input alias %s -> %s", name, id);
|
|
762
|
+
let resolved = await this.resolve(id);
|
|
763
|
+
if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
|
|
764
|
+
const resolvedId = resolved?.id || id;
|
|
765
|
+
debug$1("resolved input alias %s -> %s", id, resolvedId);
|
|
766
|
+
inputAliasMap.set(resolvedId, name);
|
|
763
767
|
}
|
|
764
768
|
},
|
|
765
769
|
outputOptions(options) {
|
|
@@ -864,9 +868,12 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
864
868
|
meta
|
|
865
869
|
};
|
|
866
870
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
if (
|
|
871
|
+
let resolution = await this.resolve(id, importer, options);
|
|
872
|
+
if (!resolution && !id.endsWith(".d")) resolution = await this.resolve(`${id}.d`, importer, options);
|
|
873
|
+
if (resolution?.id.startsWith("\0")) return {
|
|
874
|
+
...resolution,
|
|
875
|
+
meta
|
|
876
|
+
};
|
|
870
877
|
if (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id)) {
|
|
871
878
|
let shouldResolve;
|
|
872
879
|
if (typeof resolve === "boolean") shouldResolve = resolve;
|
|
@@ -888,7 +895,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
888
895
|
resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, options);
|
|
889
896
|
if (!resolution) return;
|
|
890
897
|
} else if (RE_TS.test(resolution.id) && !RE_DTS.test(resolution.id)) {
|
|
891
|
-
await this.load(resolution);
|
|
898
|
+
await Promise.any([this.load(resolution), new Promise((resolve$1) => setTimeout(resolve$1, 200))]);
|
|
892
899
|
resolution.id = filename_ts_to_dts(resolution.id);
|
|
893
900
|
}
|
|
894
901
|
if (RE_DTS.test(resolution.id)) return {
|