rolldown-plugin-dts 0.9.3 → 0.9.5
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.d.ts +8 -1
- package/dist/index.js +27 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,12 @@ interface Options {
|
|
|
63
63
|
sourcemap?: boolean;
|
|
64
64
|
/** Resolve external types used in dts files from `node_modules` */
|
|
65
65
|
resolve?: boolean | (string | RegExp)[];
|
|
66
|
+
/**
|
|
67
|
+
* When `true`, the plugin will resolve `paths` in `tsconfig.json`.
|
|
68
|
+
*
|
|
69
|
+
* This option is enabled when `paths` is set in `compilerOptions`.
|
|
70
|
+
*/
|
|
71
|
+
resolvePaths?: boolean;
|
|
66
72
|
}
|
|
67
73
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
68
74
|
type OptionsResolved = Overwrite<Required<Options>, {
|
|
@@ -78,7 +84,8 @@ declare function resolveOptions({
|
|
|
78
84
|
sourcemap,
|
|
79
85
|
dtsInput,
|
|
80
86
|
emitDtsOnly,
|
|
81
|
-
resolve
|
|
87
|
+
resolve,
|
|
88
|
+
resolvePaths
|
|
82
89
|
}: Options): OptionsResolved;
|
|
83
90
|
|
|
84
91
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -853,8 +853,24 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
|
|
|
853
853
|
//#endregion
|
|
854
854
|
//#region src/resolve.ts
|
|
855
855
|
const meta = { dtsFile: true };
|
|
856
|
-
function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
856
|
+
function createDtsResolvePlugin({ tsconfig, resolve, resolvePaths }) {
|
|
857
857
|
const resolver = createResolver({ tsconfig: tsconfig ? tsconfig : void 0 });
|
|
858
|
+
function resolveDependency(id, importer) {
|
|
859
|
+
let shouldResolve;
|
|
860
|
+
if (typeof resolve === "boolean") shouldResolve = resolve;
|
|
861
|
+
else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
|
|
862
|
+
if (shouldResolve) {
|
|
863
|
+
const resolution = resolver(id, importer);
|
|
864
|
+
if (resolution) return {
|
|
865
|
+
id: resolution,
|
|
866
|
+
meta
|
|
867
|
+
};
|
|
868
|
+
} else return {
|
|
869
|
+
id,
|
|
870
|
+
external: true,
|
|
871
|
+
meta
|
|
872
|
+
};
|
|
873
|
+
}
|
|
858
874
|
return {
|
|
859
875
|
name: "rolldown-plugin-dts:resolve",
|
|
860
876
|
resolveId: {
|
|
@@ -868,30 +884,20 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
|
|
|
868
884
|
meta
|
|
869
885
|
};
|
|
870
886
|
}
|
|
887
|
+
if (!resolvePaths && (RE_NODE_MODULES.test(id) || !isRelative(id))) return resolveDependency(id, importer);
|
|
871
888
|
let resolution = await this.resolve(id, importer, options);
|
|
872
889
|
if (!resolution && !id.endsWith(".d")) resolution = await this.resolve(`${id}.d`, importer, options);
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
const resolution$1 = resolver(id, importer);
|
|
879
|
-
if (resolution$1) return {
|
|
880
|
-
id: resolution$1,
|
|
881
|
-
meta
|
|
882
|
-
};
|
|
883
|
-
} else return {
|
|
884
|
-
id,
|
|
885
|
-
external: true,
|
|
886
|
-
meta
|
|
887
|
-
};
|
|
888
|
-
}
|
|
890
|
+
if (resolution?.id.startsWith("\0")) return {
|
|
891
|
+
...resolution,
|
|
892
|
+
meta
|
|
893
|
+
};
|
|
894
|
+
if (resolvePaths && (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id))) return resolveDependency(resolution?.id || id, importer);
|
|
889
895
|
if (!resolution || resolution.external) return resolution;
|
|
890
896
|
if (RE_JS.test(resolution.id)) {
|
|
891
897
|
resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, options);
|
|
892
898
|
if (!resolution) return;
|
|
893
899
|
} else if (RE_TS.test(resolution.id) && !RE_DTS.test(resolution.id)) {
|
|
894
|
-
|
|
900
|
+
await Promise.any([this.load(resolution), new Promise((resolve$1) => setTimeout(resolve$1, 200))]);
|
|
895
901
|
resolution.id = filename_ts_to_dts(resolution.id);
|
|
896
902
|
}
|
|
897
903
|
if (RE_DTS.test(resolution.id)) return {
|
|
@@ -916,7 +922,7 @@ function dts(options = {}) {
|
|
|
916
922
|
plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
|
|
917
923
|
return plugins;
|
|
918
924
|
}
|
|
919
|
-
function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
|
|
925
|
+
function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, resolvePaths }) {
|
|
920
926
|
if (tsconfig === true || tsconfig == null) {
|
|
921
927
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
922
928
|
tsconfig = path$1;
|
|
@@ -948,7 +954,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
|
|
|
948
954
|
sourcemap,
|
|
949
955
|
dtsInput,
|
|
950
956
|
emitDtsOnly,
|
|
951
|
-
resolve
|
|
957
|
+
resolve,
|
|
958
|
+
resolvePaths: resolvePaths ?? !!compilerOptions?.paths
|
|
952
959
|
};
|
|
953
960
|
}
|
|
954
961
|
|