rolldown-plugin-dts 0.27.6 → 0.27.8

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
@@ -14,6 +14,7 @@ import { access, mkdtemp, readFile, rm } from "node:fs/promises";
14
14
  import path from "node:path";
15
15
  import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
16
16
  import { tmpdir } from "node:os";
17
+ import { styleText } from "node:util";
17
18
  import process from "node:process";
18
19
  import { getTsconfig, readTsconfig } from "get-tsconfig";
19
20
  import { createResolver } from "dts-resolver";
@@ -784,20 +785,24 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
784
785
  child.on("close", () => resolve());
785
786
  child.on("error", (error) => reject(error));
786
787
  });
787
- async function getTsgoPathFromNodeModules() {
788
+ let tsgoPathCache;
789
+ async function getTsgoPathFromNodeModules(logger) {
790
+ if (tsgoPathCache) return tsgoPathCache;
788
791
  const pkgName = isTS7Installed() ? "typescript" : "@typescript/native-preview";
789
792
  const tsgoPkg = import.meta.resolve(`${pkgName}/package.json`);
793
+ const { default: { version } } = await import(tsgoPkg, { with: { type: "json" } });
794
+ logger.info(`Emit types with ${styleText("underline", `${pkgName}@${version}`)}`);
790
795
  const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
791
- return getExePath();
796
+ return tsgoPathCache = getExePath();
792
797
  }
793
- async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
798
+ async function runTsgo(logger, rootDir, tsconfig, sourcemap, tsgoPath) {
794
799
  debug$4("[tsgo] rootDir", rootDir);
795
800
  let tsgo;
796
801
  if (tsgoPath) {
797
802
  tsgo = tsgoPath;
798
803
  debug$4("[tsgo] using custom path", tsgo);
799
804
  } else {
800
- tsgo = await getTsgoPathFromNodeModules();
805
+ tsgo = await getTsgoPathFromNodeModules(logger);
801
806
  debug$4("[tsgo] using tsgo from node_modules", tsgo);
802
807
  }
803
808
  const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
@@ -835,7 +840,7 @@ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
835
840
  //#region src/generate.ts
836
841
  const debug$3 = createDebug("rolldown-plugin-dts:generate");
837
842
  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 }) {
843
+ function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }) {
839
844
  const entryIncludes = entry?.filter((p) => p[0] !== "!");
840
845
  const entryIgnores = entry?.filter((p) => p[0] === "!").map((p) => p.slice(1));
841
846
  const entryMatcher = entry ? (file) => entryIncludes.some((p) => path.matchesGlob(file, p)) && !entryIgnores.some((p) => path.matchesGlob(file, p)) : void 0;
@@ -858,7 +863,7 @@ function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build,
858
863
  return {
859
864
  name: "rolldown-plugin-dts:generate",
860
865
  async buildStart(options) {
861
- if (generator === "tsgo") tsgoContext = await runTsgo(rootDir, tsconfig, sourcemap, tsgo.path);
866
+ if (generator === "tsgo") tsgoContext = await runTsgo(logger, rootDir, tsconfig, sourcemap, tsgo.path);
862
867
  else if (generator === "tsc") if (parallel) tscWorker = createTscWorker();
863
868
  else {
864
869
  tscModule = await import("./tsc.mjs");
@@ -1108,7 +1113,7 @@ function collectJsonExports(code) {
1108
1113
  //#region src/options.ts
1109
1114
  const debug$2 = createDebug("rolldown-plugin-dts:options");
1110
1115
  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 }) {
1116
+ 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
1117
  let resolvedTsconfig;
1113
1118
  if (tsconfig === true || tsconfig == null) {
1114
1119
  const { config, path } = getTsconfig(cwd) || {};
@@ -1143,7 +1148,7 @@ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = fals
1143
1148
  if (tsgo === true || !tsgo) tsgo = {};
1144
1149
  emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
1145
1150
  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.");
1151
+ logger.warn("TypeScript 7.0 does not yet have a stable API and is experimental. Some options will be unavailable.");
1147
1152
  warnedTsgo = true;
1148
1153
  }
1149
1154
  const resolved = {
@@ -1167,7 +1172,8 @@ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = fals
1167
1172
  newContext,
1168
1173
  emitJs,
1169
1174
  oxc,
1170
- tsgo
1175
+ tsgo,
1176
+ logger
1171
1177
  };
1172
1178
  debug$2("Resolved Options: %O", resolved);
1173
1179
  return resolved;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
3
  "type": "module",
4
- "version": "0.27.6",
4
+ "version": "0.27.8",
5
5
  "description": "A Rolldown plugin to generate and bundle dts files.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -66,8 +66,8 @@
66
66
  "get-tsconfig": "5.0.0-beta.5",
67
67
  "obug": "^2.1.3",
68
68
  "yuku-ast": "^0.1.7",
69
- "yuku-codegen": "^0.5.46",
70
- "yuku-parser": "^0.5.46"
69
+ "yuku-codegen": "^0.6.1",
70
+ "yuku-parser": "^0.6.1"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@jridgewell/source-map": "^0.3.11",
@@ -81,12 +81,12 @@
81
81
  "arktype": "^2.2.3",
82
82
  "bumpp": "^11.1.0",
83
83
  "diff": "^9.0.0",
84
- "eslint": "^10.6.0",
84
+ "eslint": "^10.7.0",
85
85
  "prettier": "^3.9.5",
86
86
  "rolldown": "^1.1.5",
87
87
  "rolldown-plugin-require-cjs": "^0.4.1",
88
88
  "rollup-plugin-dts": "^6.4.1",
89
- "tsdown": "^0.22.4",
89
+ "tsdown": "^0.22.5",
90
90
  "tsnapi": "^1.0.0",
91
91
  "typescript": "^6.0.3",
92
92
  "vitest": "^4.1.10",