rolldown-plugin-dts 0.27.7 → 0.27.9
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.mts
CHANGED
|
@@ -2,6 +2,11 @@ import { Plugin } from "rolldown";
|
|
|
2
2
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
3
3
|
import { TsconfigJson } from "get-tsconfig";
|
|
4
4
|
//#region src/options.d.ts
|
|
5
|
+
interface Logger {
|
|
6
|
+
info: (...args: any[]) => void;
|
|
7
|
+
warn: (...args: any[]) => void;
|
|
8
|
+
error: (...args: any[]) => void;
|
|
9
|
+
}
|
|
5
10
|
interface GeneralOptions {
|
|
6
11
|
/**
|
|
7
12
|
* The generator used to produce `.d.ts` files.
|
|
@@ -107,6 +112,7 @@ interface GeneralOptions {
|
|
|
107
112
|
* @default false
|
|
108
113
|
*/
|
|
109
114
|
sideEffects?: boolean;
|
|
115
|
+
logger?: Logger;
|
|
110
116
|
}
|
|
111
117
|
interface TscOptions {
|
|
112
118
|
/**
|
|
@@ -234,15 +240,15 @@ type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
|
234
240
|
tsconfigRaw: TsconfigJson;
|
|
235
241
|
tsgo: TsgoOptions;
|
|
236
242
|
}>;
|
|
237
|
-
declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, build, incremental, vue, tsMacro, parallel, eager, newContext, emitJs, oxc, tsgo }: Options): OptionsResolved;
|
|
243
|
+
declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, build, incremental, vue, tsMacro, parallel, eager, newContext, emitJs, oxc, tsgo }: Options): OptionsResolved;
|
|
238
244
|
//#endregion
|
|
239
245
|
//#region src/fake-js.d.ts
|
|
240
246
|
declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
|
|
241
247
|
//#endregion
|
|
242
248
|
//#region src/generate.d.ts
|
|
243
|
-
declare function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
|
|
249
|
+
declare function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap" | "logger">): Plugin;
|
|
244
250
|
//#endregion
|
|
245
251
|
//#region src/index.d.ts
|
|
246
252
|
declare function dts(options?: Options): Plugin[];
|
|
247
253
|
//#endregion
|
|
248
|
-
export { type Options, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
254
|
+
export { type Logger, type Options, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as __require } from "./rolldown-runtime-CMgrfpPY.mjs";
|
|
1
2
|
import { a as RE_JSON, c as RE_TS, d as filename_js_to_dts, f as filename_to_dts, i as RE_JS, l as RE_VUE, m as resolveTemplateFn, n as RE_DTS, o as RE_NODE_MODULES, p as replaceTemplateName, r as RE_DTS_MAP, s as RE_ROLLDOWN_RUNTIME, t as RE_CSS, u as filename_dts_to } from "./filename-BR9JpwkC.mjs";
|
|
2
3
|
import { createContext, globalContext, invalidateContextFile } from "./tsc-context.mjs";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
@@ -14,6 +15,7 @@ import { access, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
|
14
15
|
import path from "node:path";
|
|
15
16
|
import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
|
|
16
17
|
import { tmpdir } from "node:os";
|
|
18
|
+
import { styleText } from "node:util";
|
|
17
19
|
import process from "node:process";
|
|
18
20
|
import { getTsconfig, readTsconfig } from "get-tsconfig";
|
|
19
21
|
import { createResolver } from "dts-resolver";
|
|
@@ -764,40 +766,38 @@ function getIdentifierIndex(identifierMap, name) {
|
|
|
764
766
|
}
|
|
765
767
|
//#endregion
|
|
766
768
|
//#region src/tsgo.ts
|
|
767
|
-
const require = createRequire(import.meta.url);
|
|
769
|
+
const require$1 = createRequire(import.meta.url);
|
|
768
770
|
const debug$4 = createDebug("rolldown-plugin-dts:tsgo");
|
|
769
|
-
function
|
|
771
|
+
function isTS70Installed() {
|
|
770
772
|
try {
|
|
771
|
-
const {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
function isTS7Installed() {
|
|
779
|
-
const major = getTypeScriptMajor();
|
|
780
|
-
return major != null && major >= 7;
|
|
773
|
+
const { versionMajorMinor } = require$1("typescript");
|
|
774
|
+
return versionMajorMinor === "7.0";
|
|
775
|
+
} catch {}
|
|
776
|
+
return false;
|
|
781
777
|
}
|
|
782
778
|
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
783
779
|
const child = spawn(...args);
|
|
784
780
|
child.on("close", () => resolve());
|
|
785
781
|
child.on("error", (error) => reject(error));
|
|
786
782
|
});
|
|
787
|
-
|
|
788
|
-
|
|
783
|
+
let tsgoPathCache;
|
|
784
|
+
async function getTsgoPathFromNodeModules(logger) {
|
|
785
|
+
if (tsgoPathCache) return tsgoPathCache;
|
|
786
|
+
const pkgName = isTS70Installed() ? "typescript" : "@typescript/native-preview";
|
|
789
787
|
const tsgoPkg = import.meta.resolve(`${pkgName}/package.json`);
|
|
788
|
+
const { default: { version } } = await import(tsgoPkg, { with: { type: "json" } });
|
|
789
|
+
logger.info(`Emit types with ${styleText("underline", `${pkgName}@${version}`)}`);
|
|
790
790
|
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
|
|
791
|
-
return getExePath();
|
|
791
|
+
return tsgoPathCache = getExePath();
|
|
792
792
|
}
|
|
793
|
-
async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
793
|
+
async function runTsgo(logger, rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
794
794
|
debug$4("[tsgo] rootDir", rootDir);
|
|
795
795
|
let tsgo;
|
|
796
796
|
if (tsgoPath) {
|
|
797
797
|
tsgo = tsgoPath;
|
|
798
798
|
debug$4("[tsgo] using custom path", tsgo);
|
|
799
799
|
} else {
|
|
800
|
-
tsgo = await getTsgoPathFromNodeModules();
|
|
800
|
+
tsgo = await getTsgoPathFromNodeModules(logger);
|
|
801
801
|
debug$4("[tsgo] using tsgo from node_modules", tsgo);
|
|
802
802
|
}
|
|
803
803
|
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
@@ -807,7 +807,8 @@ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
|
807
807
|
"false",
|
|
808
808
|
"--declaration",
|
|
809
809
|
"--emitDeclarationOnly",
|
|
810
|
-
|
|
810
|
+
"-p",
|
|
811
|
+
tsconfig,
|
|
811
812
|
"--outDir",
|
|
812
813
|
tsgoDist,
|
|
813
814
|
"--rootDir",
|
|
@@ -835,7 +836,7 @@ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
|
835
836
|
//#region src/generate.ts
|
|
836
837
|
const debug$3 = createDebug("rolldown-plugin-dts:generate");
|
|
837
838
|
const WORKER_URL = "./tsc-worker.mjs";
|
|
838
|
-
function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
|
|
839
|
+
function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }) {
|
|
839
840
|
const entryIncludes = entry?.filter((p) => p[0] !== "!");
|
|
840
841
|
const entryIgnores = entry?.filter((p) => p[0] === "!").map((p) => p.slice(1));
|
|
841
842
|
const entryMatcher = entry ? (file) => entryIncludes.some((p) => path.matchesGlob(file, p)) && !entryIgnores.some((p) => path.matchesGlob(file, p)) : void 0;
|
|
@@ -858,7 +859,7 @@ function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build,
|
|
|
858
859
|
return {
|
|
859
860
|
name: "rolldown-plugin-dts:generate",
|
|
860
861
|
async buildStart(options) {
|
|
861
|
-
if (generator === "tsgo") tsgoContext = await runTsgo(rootDir, tsconfig, sourcemap, tsgo.path);
|
|
862
|
+
if (generator === "tsgo") tsgoContext = await runTsgo(logger, rootDir, tsconfig, sourcemap, tsgo.path);
|
|
862
863
|
else if (generator === "tsc") if (parallel) tscWorker = createTscWorker();
|
|
863
864
|
else {
|
|
864
865
|
tscModule = await import("./tsc.mjs");
|
|
@@ -1108,7 +1109,7 @@ function collectJsonExports(code) {
|
|
|
1108
1109
|
//#region src/options.ts
|
|
1109
1110
|
const debug$2 = createDebug("rolldown-plugin-dts:options");
|
|
1110
1111
|
let warnedTsgo = false;
|
|
1111
|
-
function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo }) {
|
|
1112
|
+
function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, logger = console, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo }) {
|
|
1112
1113
|
let resolvedTsconfig;
|
|
1113
1114
|
if (tsconfig === true || tsconfig == null) {
|
|
1114
1115
|
const { config, path } = getTsconfig(cwd) || {};
|
|
@@ -1130,11 +1131,27 @@ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = fals
|
|
|
1130
1131
|
...overriddenTsconfigRaw,
|
|
1131
1132
|
compilerOptions
|
|
1132
1133
|
};
|
|
1133
|
-
if (
|
|
1134
|
-
|
|
1134
|
+
if (vue || tsMacro) {
|
|
1135
|
+
if (isTS70Installed()) throw new Error("TypeScript 7.0 does not yet have a stable API and is experimental. The `vue` and `tsMacro` options are not yet supported with TypeScript 7.0.");
|
|
1136
|
+
if (generator && generator !== "tsc") logger.warn("The `vue` and `tsMacro` options are enabled, which requires the `tsc` generator. The `generator` option is ignored.");
|
|
1137
|
+
generator = "tsc";
|
|
1138
|
+
}
|
|
1139
|
+
if (!generator) if (tsgo) generator = "tsgo";
|
|
1135
1140
|
else if (oxc || compilerOptions?.isolatedDeclarations) generator = "oxc";
|
|
1136
|
-
else if (
|
|
1141
|
+
else if (isTS70Installed()) generator = "tsgo";
|
|
1137
1142
|
else generator = "tsc";
|
|
1143
|
+
if (generator === "tsc") try {
|
|
1144
|
+
__require.resolve("typescript");
|
|
1145
|
+
} catch {
|
|
1146
|
+
throw new Error("TypeScript is not installed. You can install `typescript` package, or enable `isolatedDeclarations` in your `tsconfig.json` to use Oxc instead.");
|
|
1147
|
+
}
|
|
1148
|
+
else if (generator === "tsgo") {
|
|
1149
|
+
if (!tsconfig) throw new Error("tsgo generator requires a tsconfig file to be specified.");
|
|
1150
|
+
if (!warnedTsgo) {
|
|
1151
|
+
warnedTsgo = true;
|
|
1152
|
+
logger.warn("TypeScript 7.0 does not yet have a stable API and is experimental. Some options will be unavailable.");
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1138
1155
|
if (oxc === true || !oxc) oxc = {};
|
|
1139
1156
|
if (oxc) {
|
|
1140
1157
|
oxc.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
@@ -1142,10 +1159,6 @@ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = fals
|
|
|
1142
1159
|
}
|
|
1143
1160
|
if (tsgo === true || !tsgo) tsgo = {};
|
|
1144
1161
|
emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
|
|
1145
|
-
if (generator === "tsgo" && !warnedTsgo) {
|
|
1146
|
-
console.warn("TypeScript 7.0 does not yet have a stable API and is experimental. Some options will be unavailable.");
|
|
1147
|
-
warnedTsgo = true;
|
|
1148
|
-
}
|
|
1149
1162
|
const resolved = {
|
|
1150
1163
|
generator,
|
|
1151
1164
|
entry: entry ? Array.isArray(entry) ? entry : [entry] : void 0,
|
|
@@ -1167,7 +1180,8 @@ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = fals
|
|
|
1167
1180
|
newContext,
|
|
1168
1181
|
emitJs,
|
|
1169
1182
|
oxc,
|
|
1170
|
-
tsgo
|
|
1183
|
+
tsgo,
|
|
1184
|
+
logger
|
|
1171
1185
|
};
|
|
1172
1186
|
debug$2("Resolved Options: %O", resolved);
|
|
1173
1187
|
return resolved;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
+
import { t as __require } from "./rolldown-runtime-CMgrfpPY.mjs";
|
|
3
4
|
import { n as RE_DTS, r as RE_DTS_MAP } from "./filename-BR9JpwkC.mjs";
|
|
4
5
|
import { globalContext } from "./tsc-context.mjs";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
6
|
import { createDebug } from "obug";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
const ts = __cjs_require("typescript");
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
-
//#region \0rolldown/runtime.js
|
|
11
|
-
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
12
|
-
//#endregion
|
|
13
10
|
//#region src/tsc/system.ts
|
|
14
11
|
const debug$4 = createDebug("rolldown-plugin-dts:tsc-system");
|
|
15
12
|
/**
|
package/dist/tsc-worker.mjs
CHANGED
package/dist/tsc.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as tscEmit } from "./tsc-
|
|
1
|
+
import { t as tscEmit } from "./tsc-BVghLPtc.mjs";
|
|
2
2
|
export { tscEmit };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.27.
|
|
4
|
+
"version": "0.27.9",
|
|
5
5
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@ts-macro/tsc": "^0.3.6",
|
|
45
|
-
"@typescript/native-preview": "
|
|
45
|
+
"@typescript/native-preview": "*",
|
|
46
46
|
"rolldown": "^1.0.0",
|
|
47
|
-
"typescript": "^5.0.0 || ^6.0.0 ||
|
|
47
|
+
"typescript": "^5.0.0 || ^6.0.0 || ~7.0.0",
|
|
48
48
|
"vue-tsc": "~3.2.0 || ~3.3.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|