tsdown 0.18.4 → 0.19.0-beta.2

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.
@@ -1,4 +1,4 @@
1
- import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport } from "./index-BfO1W_C3.mjs";
1
+ import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport } from "./index-CMl71wtM.mjs";
2
2
 
3
3
  //#region src/config/options.d.ts
4
4
  declare function mergeConfig(defaults: UserConfig, overrides: UserConfig): UserConfig;
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { a as globalLogger, c as matchPattern, f as resolveComma, h as toArray, i as getNameLabel, m as slash, n as createLogger, p as resolveRegex, r as generateColor, u as pkgExists } from "./logger-s1ImI5j1.mjs";
3
+ import { a as globalLogger, c as matchPattern, f as resolveComma, h as toArray, i as getNameLabel, m as slash, n as createLogger, p as resolveRegex, r as generateColor, u as pkgExists } from "./logger-D_2uXZBG.mjs";
4
4
  import { access, cp, readFile, rm, stat } from "node:fs/promises";
5
5
  import path, { dirname, extname, normalize, sep } from "node:path";
6
6
  import process, { env } from "node:process";
@@ -9,13 +9,13 @@ import { blue, underline } from "ansis";
9
9
  import { createDefu } from "defu";
10
10
  import { createDebug } from "obug";
11
11
  import { glob, isDynamicPattern } from "tinyglobby";
12
+ import { pathToFileURL } from "node:url";
12
13
  const picomatch = __cjs_require("picomatch");
13
14
  import { RE_CSS, RE_DTS } from "rolldown-plugin-dts/filename";
14
15
  import { readFileSync, writeFileSync } from "node:fs";
15
16
  const minVersion = __cjs_require("semver/ranges/min-version.js");
16
17
  import { up } from "empathic/find";
17
18
  import { up as up$1 } from "empathic/package";
18
- import { pathToFileURL } from "node:url";
19
19
  import { init, isSupported } from "import-without-cache";
20
20
  import { createConfigCoreLoader } from "unconfig-core";
21
21
 
@@ -70,12 +70,12 @@ function stripExtname(filePath) {
70
70
 
71
71
  //#endregion
72
72
  //#region src/features/clean.ts
73
- const debug$2 = createDebug("tsdown:clean");
73
+ const debug$3 = createDebug("tsdown:clean");
74
74
  const RE_LAST_SLASH = /[/\\]$/;
75
75
  async function cleanOutDir(configs) {
76
76
  const removes = /* @__PURE__ */ new Set();
77
77
  for (const config of configs) {
78
- if (config.debug && (config.debug.clean ?? true)) config.clean.push(".rolldown");
78
+ if (config.devtools && (config.devtools.clean ?? true)) config.clean.push("node_modules/.rolldown");
79
79
  if (!config.clean.length) continue;
80
80
  const files = await glob(config.clean, {
81
81
  cwd: config.cwd,
@@ -89,10 +89,10 @@ async function cleanOutDir(configs) {
89
89
  if (!removes.size) return;
90
90
  globalLogger.info(`Cleaning ${removes.size} files`);
91
91
  await Promise.all([...removes].map(async (file) => {
92
- debug$2("Removing", file);
92
+ debug$3("Removing", file);
93
93
  await fsRemove(file);
94
94
  }));
95
- debug$2("Removed %d files", removes.size);
95
+ debug$3("Removed %d files", removes.size);
96
96
  }
97
97
  function resolveClean(clean, outDir, cwd) {
98
98
  if (clean === true) clean = [slash(outDir)];
@@ -103,17 +103,23 @@ function resolveClean(clean, outDir, cwd) {
103
103
  async function cleanChunks(outDir, chunks) {
104
104
  await Promise.all(chunks.map(async (chunk) => {
105
105
  const filePath = path.resolve(outDir, chunk.fileName);
106
- debug$2("Removing chunk file", filePath);
106
+ debug$3("Removing chunk file", filePath);
107
107
  await fsRemove(filePath);
108
108
  }));
109
109
  }
110
110
 
111
111
  //#endregion
112
112
  //#region src/features/css.ts
113
+ const defaultCssBundleName = "style.css";
114
+ function resolveCssOptions(options = {}) {
115
+ return {
116
+ splitting: options.splitting ?? true,
117
+ fileName: options.fileName ?? defaultCssBundleName
118
+ };
119
+ }
113
120
  const RE_CSS_HASH = /-[\w-]+\.css$/;
114
121
  const RE_CHUNK_HASH = /-[\w-]+\.(m?js|cjs)$/;
115
122
  const RE_CHUNK_EXT = /\.(m?js|cjs)$/;
116
- const defaultCssBundleName = "style.css";
117
123
  /**
118
124
  * Normalize CSS file name by removing hash pattern and extension.
119
125
  * e.g., "async-DcjEOEdU.css" -> "async"
@@ -268,9 +274,8 @@ function detectIndentation(jsonText) {
268
274
  //#endregion
269
275
  //#region src/features/pkg/exports.ts
270
276
  async function writeExports(options, chunks) {
271
- const pkg = options.pkg;
272
- const exports = options.exports;
273
- const { publishExports, ...generated } = await generateExports(pkg, chunks, exports, options.logger);
277
+ const { pkg } = options;
278
+ const { publishExports, ...generated } = await generateExports(pkg, chunks, options);
274
279
  const updatedPkg = {
275
280
  ...pkg,
276
281
  ...generated,
@@ -289,24 +294,27 @@ function shouldExclude(fileName, exclude) {
289
294
  if (!exclude?.length) return false;
290
295
  return matchPattern(fileName, exclude);
291
296
  }
292
- async function generateExports(pkg, chunks, { devExports, all, packageJson = true, exclude, customExports }, logger) {
297
+ async function generateExports(pkg, chunks, options) {
298
+ let { exports: { devExports, all, packageJson = true, exclude, customExports, legacy }, css, logger } = options;
293
299
  const pkgRoot = path.dirname(pkg.packageJsonPath);
294
300
  let main, module, cjsTypes, esmTypes;
295
301
  const exportsMap = /* @__PURE__ */ new Map();
296
302
  const formats = Object.keys(chunks);
297
303
  if (!formats.includes("cjs") && !formats.includes("es")) logger.warn(`No CJS or ESM formats found in chunks for package ${pkg.name}`);
304
+ const isPureESM = formats.length === 1 && formats[0] === "es";
305
+ legacy ??= !isPureESM;
298
306
  for (const [format, chunksByFormat] of Object.entries(chunks)) {
299
307
  if (format !== "es" && format !== "cjs") continue;
300
- const filteredChunks = chunksByFormat.filter((chunk) => chunk.type === "chunk" && chunk.isEntry && !shouldExclude(chunk.fileName, exclude));
308
+ const filteredChunks = chunksByFormat.filter((chunk) => {
309
+ if (chunk.type !== "chunk" || !chunk.isEntry) return false;
310
+ const [name] = getExportName(chunk);
311
+ return !shouldExclude(name, exclude);
312
+ });
301
313
  const onlyOneEntry = filteredChunks.filter((chunk) => !RE_DTS.test(chunk.fileName)).length === 1;
302
314
  for (const chunk of filteredChunks) {
303
- const normalizedName = slash(chunk.fileName);
304
- let name = stripExtname(normalizedName);
305
- const isDts = name.endsWith(".d");
306
- if (isDts) name = name.slice(0, -2);
315
+ let [name, normalizedName, isDts] = getExportName(chunk);
307
316
  const isIndex = onlyOneEntry || name === "index";
308
- const outDirRelative = slash(path.relative(pkgRoot, chunk.outDir));
309
- const distFile = `${outDirRelative ? `./${outDirRelative}` : "."}/${normalizedName}`;
317
+ const distFile = join$1(pkgRoot, chunk.outDir, normalizedName);
310
318
  if (isIndex) {
311
319
  name = ".";
312
320
  if (format === "cjs") if (isDts) cjsTypes = distFile;
@@ -332,6 +340,7 @@ async function generateExports(pkg, chunks, { devExports, all, packageJson = tru
332
340
  });
333
341
  let exports = Object.fromEntries(sortedExportsMap.map(([name, subExport]) => [name, genSubExport(devExports, subExport)]));
334
342
  exportMeta(exports, all, packageJson);
343
+ exportCss(exports, chunks, css, pkgRoot);
335
344
  if (customExports) exports = await customExports(exports, {
336
345
  pkg,
337
346
  chunks,
@@ -341,6 +350,7 @@ async function generateExports(pkg, chunks, { devExports, all, packageJson = tru
341
350
  if (devExports) {
342
351
  publishExports = Object.fromEntries(sortedExportsMap.map(([name, subExport]) => [name, genSubExport(false, subExport)]));
343
352
  exportMeta(publishExports, all, packageJson);
353
+ exportCss(publishExports, chunks, css, pkgRoot);
344
354
  if (customExports) publishExports = await customExports(publishExports, {
345
355
  pkg,
346
356
  chunks,
@@ -348,9 +358,9 @@ async function generateExports(pkg, chunks, { devExports, all, packageJson = tru
348
358
  });
349
359
  }
350
360
  return {
351
- main: main || module || pkg.main,
352
- module: module || pkg.module,
353
- types: cjsTypes || esmTypes || pkg.types,
361
+ main: legacy ? main || module || pkg.main : void 0,
362
+ module: legacy ? module || pkg.module : void 0,
363
+ types: legacy ? cjsTypes || esmTypes || pkg.types : pkg.types,
354
364
  exports,
355
365
  publishExports
356
366
  };
@@ -372,6 +382,14 @@ function exportMeta(exports, all, packageJson) {
372
382
  if (all) exports["./*"] = "./*";
373
383
  else if (packageJson) exports["./package.json"] = "./package.json";
374
384
  }
385
+ function exportCss(exports, chunks, { splitting }, pkgRoot) {
386
+ if (splitting) return;
387
+ for (const chunksByFormat of Object.values(chunks)) for (const chunk of chunksByFormat) if (chunk.type === "asset" && RE_CSS.test(chunk.fileName)) {
388
+ const filename = slash(chunk.fileName);
389
+ exports[`./${filename}`] = join$1(pkgRoot, chunk.outDir, filename);
390
+ return;
391
+ }
392
+ }
375
393
  function hasExportsTypes(pkg) {
376
394
  const exports = pkg?.exports;
377
395
  if (!exports) return false;
@@ -384,6 +402,21 @@ function hasExportsTypes(pkg) {
384
402
  }
385
403
  return false;
386
404
  }
405
+ function getExportName(chunk) {
406
+ const normalizedName = slash(chunk.fileName);
407
+ let name = stripExtname(normalizedName);
408
+ const isDts = name.endsWith(".d");
409
+ if (isDts) name = name.slice(0, -2);
410
+ return [
411
+ name,
412
+ normalizedName,
413
+ isDts
414
+ ];
415
+ }
416
+ function join$1(pkgRoot, outDir, fileName) {
417
+ const outDirRelative = slash(path.relative(pkgRoot, outDir));
418
+ return `${outDirRelative ? `./${outDirRelative}` : "."}/${fileName}`;
419
+ }
387
420
 
388
421
  //#endregion
389
422
  //#region src/features/target.ts
@@ -438,11 +471,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, color, nameLabel) {
438
471
 
439
472
  //#endregion
440
473
  //#region src/utils/package.ts
441
- const debug$1 = createDebug("tsdown:package");
474
+ const debug$2 = createDebug("tsdown:package");
442
475
  async function readPackageJson(dir) {
443
476
  const packageJsonPath = up$1({ cwd: dir });
444
477
  if (!packageJsonPath) return;
445
- debug$1("Reading package.json:", packageJsonPath);
478
+ debug$2("Reading package.json:", packageJsonPath);
446
479
  const contents = await readFile(packageJsonPath, "utf8");
447
480
  return {
448
481
  ...JSON.parse(contents),
@@ -468,10 +501,10 @@ function normalizeFormat(format) {
468
501
 
469
502
  //#endregion
470
503
  //#region src/config/file.ts
471
- const debug = createDebug("tsdown:config:file");
504
+ const debug$1 = createDebug("tsdown:config:file");
472
505
  async function loadViteConfig(prefix, cwd, configLoader) {
473
506
  const loader = resolveConfigLoader(configLoader);
474
- debug("Loading Vite config via loader: ", loader);
507
+ debug$1("Loading Vite config via loader: ", loader);
475
508
  const parser = createParser(loader);
476
509
  const [result] = await createConfigCoreLoader({
477
510
  sources: [{
@@ -516,7 +549,7 @@ async function loadConfigFile(inlineConfig, workspace) {
516
549
  }
517
550
  }
518
551
  const loader = resolveConfigLoader(inlineConfig.configLoader);
519
- debug("Using config loader:", loader);
552
+ debug$1("Using config loader:", loader);
520
553
  const parser = createParser(loader);
521
554
  const [result] = await createConfigCoreLoader({
522
555
  sources: overrideConfig ? [{
@@ -603,15 +636,15 @@ async function unrunImport(id) {
603
636
 
604
637
  //#endregion
605
638
  //#region src/config/options.ts
606
- const debugLog = createDebug("tsdown:config:options");
639
+ const debug = createDebug("tsdown:config:options");
607
640
  async function resolveUserConfig(userConfig, inlineConfig) {
608
- let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, css, fixedExtension = platform === "node", debug: debug$3 = false, write = true } = userConfig;
641
+ let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, css, fixedExtension = platform === "node", devtools = false, write = true } = userConfig;
609
642
  const pkg = await readPackageJson(cwd);
610
643
  if (workspace) name ||= pkg?.name;
611
644
  const color = generateColor(name);
612
645
  const nameLabel = getNameLabel(color, name);
613
646
  if (!filterConfig(inlineConfig.filter, cwd, name)) {
614
- debugLog("[filter] skipping config %s", cwd);
647
+ debug("[filter] skipping config %s", cwd);
615
648
  return [];
616
649
  }
617
650
  const logger = createLogger(logLevel, {
@@ -660,7 +693,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
660
693
  ...envFromProcess,
661
694
  ...env$1
662
695
  };
663
- debugLog(`Environment variables: %O`, env$1);
696
+ debug(`Environment variables: %O`, env$1);
664
697
  if (fromVite) {
665
698
  const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd, inlineConfig.configLoader);
666
699
  if (viteUserConfig) {
@@ -683,11 +716,11 @@ async function resolveUserConfig(userConfig, inlineConfig) {
683
716
  noExternal = (id) => matchPattern(id, noExternalPatterns);
684
717
  }
685
718
  if (inlineOnly != null) inlineOnly = toArray(inlineOnly);
686
- debug$3 = resolveFeatureOption(debug$3, {});
687
- if (debug$3) if (watch) {
688
- if (debug$3.devtools) logger.warn("Devtools is not supported in watch mode, disabling it.");
689
- debug$3.devtools = false;
690
- } else debug$3.devtools ??= !!pkgExists("@vitejs/devtools/cli");
719
+ devtools = resolveFeatureOption(devtools, {});
720
+ if (devtools) if (watch) {
721
+ if (devtools.ui) logger.warn("Devtools UI is not supported in watch mode, disabling it.");
722
+ devtools.ui = false;
723
+ } else devtools.ui ??= !!pkgExists("@vitejs/devtools/cli");
691
724
  const config = {
692
725
  ...userConfig,
693
726
  alias,
@@ -695,13 +728,9 @@ async function resolveUserConfig(userConfig, inlineConfig) {
695
728
  cjsDefault,
696
729
  clean,
697
730
  copy: publicDir || copy,
698
- css: {
699
- splitting: true,
700
- fileName: defaultCssBundleName,
701
- ...css
702
- },
731
+ css: resolveCssOptions(css),
703
732
  cwd,
704
- debug: debug$3,
733
+ devtools,
705
734
  dts,
706
735
  entry: resolvedEntry,
707
736
  env: env$1,
package/dist/config.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-BfO1W_C3.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-NHDK5cAy.mjs";
1
+ import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-CMl71wtM.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-C2C2OcsY.mjs";
3
3
  export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./logger-s1ImI5j1.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-DlCfPR2i.mjs";
1
+ import "./logger-D_2uXZBG.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-CQ0WjrHu.mjs";
3
3
 
4
4
  export { defineConfig, mergeConfig };
@@ -59,14 +59,14 @@ interface CssOptions {
59
59
  fileName?: string;
60
60
  }
61
61
  //#endregion
62
- //#region src/features/debug.d.ts
63
- interface DebugOptions extends NonNullable<InputOptions["debug"]> {
62
+ //#region src/features/devtools.d.ts
63
+ interface DevtoolsOptions extends NonNullable<InputOptions["devtools"]> {
64
64
  /**
65
65
  * **[experimental]** Enable devtools integration. `@vitejs/devtools` must be installed as a dependency.
66
66
  *
67
67
  * Defaults to true, if `@vitejs/devtools` is installed.
68
68
  */
69
- devtools?: boolean | Partial<StartOptions>;
69
+ ui?: boolean | Partial<StartOptions>;
70
70
  /**
71
71
  * Clean devtools stale sessions.
72
72
  *
@@ -498,19 +498,6 @@ interface TsdownBundle extends AsyncDisposable {
498
498
  config: ResolvedConfig;
499
499
  }
500
500
  //#endregion
501
- //#region src/utils/logger.d.ts
502
- type LogType = "error" | "warn" | "info";
503
- type LogLevel = LogType | "silent";
504
- interface Logger {
505
- level: LogLevel;
506
- info: (...args: any[]) => void;
507
- warn: (...args: any[]) => void;
508
- warnOnce: (...args: any[]) => void;
509
- error: (...args: any[]) => void;
510
- success: (...args: any[]) => void;
511
- }
512
- declare const globalLogger: Logger;
513
- //#endregion
514
501
  //#region src/features/pkg/exports.d.ts
515
502
  interface ExportsOptions {
516
503
  /**
@@ -529,16 +516,24 @@ interface ExportsOptions {
529
516
  */
530
517
  all?: boolean;
531
518
  /**
532
- * Define globs or RegExp patterns to exclude files from exports.
533
- * This is useful for excluding files that should not be part of the package exports,
534
- * such as bin files or internal utilities.
519
+ * Specifies file patterns (as glob patterns or regular expressions) to exclude from package exports.
520
+ * Use this to prevent certain files from being included in the exported package, such as test files, binaries, or internal utilities.
521
+ *
522
+ * **Note:** Do not include file extensions, and paths should be relative to the dist directory.
535
523
  *
536
524
  * @example
537
- * ```js
538
- * exclude: ['**\/*.test.ts', '**\/*.spec.ts', /internal/]
539
- * ```
525
+ * exclude: ['cli', '**\/*.test', /internal/]
540
526
  */
541
527
  exclude?: (RegExp | string)[];
528
+ /**
529
+ * Generate legacy fields (`main` and `module`) for older Node.js and bundlers
530
+ * that do not support package `exports` field.
531
+ *
532
+ * Defaults to false, if only ESM builds are included, true otherwise.
533
+ *
534
+ * @see {@link https://github.com/publint/publint/issues/24}
535
+ */
536
+ legacy?: boolean;
542
537
  customExports?: (exports: Record<string, any>, context: {
543
538
  pkg: PackageJson;
544
539
  chunks: ChunksByFormat;
@@ -549,6 +544,19 @@ interface ExportsOptions {
549
544
  //#region src/features/pkg/publint.d.ts
550
545
  interface PublintOptions extends Options {}
551
546
  //#endregion
547
+ //#region src/utils/logger.d.ts
548
+ type LogType = "error" | "warn" | "info";
549
+ type LogLevel = LogType | "silent";
550
+ interface Logger {
551
+ level: LogLevel;
552
+ info: (...args: any[]) => void;
553
+ warn: (...args: any[]) => void;
554
+ warnOnce: (...args: any[]) => void;
555
+ error: (...args: any[]) => void;
556
+ success: (...args: any[]) => void;
557
+ }
558
+ declare const globalLogger: Logger;
559
+ //#endregion
552
560
  //#region src/features/report.d.ts
553
561
  interface ReportOptions {
554
562
  /**
@@ -885,15 +893,15 @@ interface UserConfig {
885
893
  */
886
894
  ignoreWatch?: Arrayable<string | RegExp>;
887
895
  /**
888
- * **[experimental]** Enable debug mode.
896
+ * **[experimental]** Enable devtools.
889
897
  *
890
- * Both debug mode and Vite DevTools are still under development, and this is for early testers only.
898
+ *DevTools is still under development, and this is for early testers only.
891
899
  *
892
900
  * This may slow down the build process significantly.
893
901
  *
894
902
  * @default false
895
903
  */
896
- debug?: WithEnabled<DebugOptions>;
904
+ devtools?: WithEnabled<DevtoolsOptions>;
897
905
  /**
898
906
  * You can specify command to be executed after a successful build, specially useful for Watch mode
899
907
  */
@@ -1010,10 +1018,10 @@ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "from
1010
1018
  report: false | ReportOptions;
1011
1019
  tsconfig: false | string;
1012
1020
  exports: false | ExportsOptions;
1013
- debug: false | DebugOptions;
1021
+ devtools: false | DevtoolsOptions;
1014
1022
  publint: false | PublintOptions;
1015
1023
  attw: false | AttwOptions;
1016
1024
  unused: false | UnusedOptions;
1017
1025
  }>;
1018
1026
  //#endregion
1019
- export { OutExtensionFactory as A, CopyOptions as B, RolldownChunk as C, ChunkAddonFunction as D, ChunkAddon as E, RolldownContext as F, TsdownHooks as I, DebugOptions as L, PackageJsonWithPath as M, PackageType as N, ChunkAddonObject as O, BuildContext as P, CssOptions as R, globalLogger as S, AttwOptions as T, CopyOptionsFn as V, ReportOptions as _, NoExternalFn as a, ExportsOptions as b, Sourcemap as c, UnusedOptions as d, UserConfig as f, Workspace as g, WithEnabled as h, InlineConfig as i, OutExtensionObject as j, OutExtensionContext as k, TreeshakingOptions as l, UserConfigFn as m, DtsOptions as n, NormalizedFormat as o, UserConfigExport as p, Format as r, ResolvedConfig as s, CIOption as t, TsdownInputOption as u, ReportPlugin as v, TsdownBundle as w, Logger as x, PublintOptions as y, CopyEntry as z };
1027
+ export { OutExtensionFactory as A, CopyOptions as B, RolldownChunk as C, ChunkAddonFunction as D, ChunkAddon as E, RolldownContext as F, TsdownHooks as I, DevtoolsOptions as L, PackageJsonWithPath as M, PackageType as N, ChunkAddonObject as O, BuildContext as P, CssOptions as R, ExportsOptions as S, AttwOptions as T, CopyOptionsFn as V, ReportOptions as _, NoExternalFn as a, globalLogger as b, Sourcemap as c, UnusedOptions as d, UserConfig as f, Workspace as g, WithEnabled as h, InlineConfig as i, OutExtensionObject as j, OutExtensionContext as k, TreeshakingOptions as l, UserConfigFn as m, DtsOptions as n, NormalizedFormat as o, UserConfigExport as p, Format as r, ResolvedConfig as s, CIOption as t, TsdownInputOption as u, ReportPlugin as v, TsdownBundle as w, PublintOptions as x, Logger as y, CopyEntry as z };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, I as TsdownHooks, L as DebugOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as globalLogger, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as ExportsOptions, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as Logger, y as PublintOptions, z as CopyEntry } from "./index-BfO1W_C3.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-NHDK5cAy.mjs";
1
+ import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./index-CMl71wtM.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-C2C2OcsY.mjs";
3
3
  import * as Rolldown from "rolldown";
4
4
 
5
5
  //#region src/index.d.ts
@@ -8,4 +8,4 @@ import * as Rolldown from "rolldown";
8
8
  */
9
9
  declare function build(userOptions?: InlineConfig): Promise<TsdownBundle[]>;
10
10
  //#endregion
11
- export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DebugOptions, DtsOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, Rolldown, RolldownChunk, RolldownContext, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, defineConfig, globalLogger, mergeConfig };
11
+ export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DevtoolsOptions, DtsOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, Rolldown, RolldownChunk, RolldownContext, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, defineConfig, globalLogger, mergeConfig };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as globalLogger } from "./logger-s1ImI5j1.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-DlCfPR2i.mjs";
3
- import { i as shimFile, n as build, r as buildSingle, t as Rolldown } from "./src-DrqLE2Pt.mjs";
1
+ import { a as globalLogger } from "./logger-D_2uXZBG.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-CQ0WjrHu.mjs";
3
+ import { i as shimFile, n as build, r as buildSingle, t as Rolldown } from "./src-DhBpfeQw.mjs";
4
4
 
5
5
  export { Rolldown, build, buildSingle, defineConfig, globalLogger, mergeConfig, shimFile };
@@ -3,6 +3,7 @@ const __cjs_require = __cjs_createRequire(import.meta.url);
3
3
  import { createRequire } from "node:module";
4
4
  import process from "node:process";
5
5
  import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
6
+ import { pathToFileURL } from "node:url";
6
7
  const picomatch = __cjs_require("picomatch");
7
8
 
8
9
  //#region rolldown:runtime
@@ -46,7 +47,7 @@ function pkgExists(moduleName) {
46
47
  }
47
48
  async function importWithError(moduleName, resolvePaths) {
48
49
  let resolved;
49
- if (resolvePaths) resolved = __require.resolve(moduleName, { paths: resolvePaths });
50
+ if (resolvePaths) resolved = pathToFileURL(__require.resolve(moduleName, { paths: resolvePaths })).href;
50
51
  try {
51
52
  return await import(resolved || moduleName);
52
53
  } catch (error) {
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.19.0-beta.2";
3
+
4
+ //#endregion
5
+ export { version as t };
@@ -1,4 +1,4 @@
1
- import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, x as Logger } from "./index-BfO1W_C3.mjs";
1
+ import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, y as Logger } from "./index-CMl71wtM.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/features/external.d.ts
package/dist/plugins.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import "./logger-s1ImI5j1.mjs";
2
- import "./config-DlCfPR2i.mjs";
3
- import { a as WatchPlugin, c as NodeProtocolPlugin, l as ExternalPlugin, o as ShebangPlugin, s as ReportPlugin } from "./src-DrqLE2Pt.mjs";
1
+ import "./logger-D_2uXZBG.mjs";
2
+ import "./config-CQ0WjrHu.mjs";
3
+ import { a as WatchPlugin, c as NodeProtocolPlugin, l as ExternalPlugin, o as ShebangPlugin, s as ReportPlugin } from "./src-DhBpfeQw.mjs";
4
4
 
5
5
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
package/dist/run.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { a as globalLogger, f as resolveComma, h as toArray } from "./logger-s1ImI5j1.mjs";
3
- import { t as version } from "./package-BZkqghxy.mjs";
2
+ import { a as globalLogger, f as resolveComma, h as toArray } from "./logger-D_2uXZBG.mjs";
3
+ import { t as version } from "./package-PFFWH-Jh.mjs";
4
4
  import module from "node:module";
5
5
  import process from "node:process";
6
6
  import { dim } from "ansis";
@@ -10,17 +10,17 @@ import { x } from "tinyexec";
10
10
  import { cac } from "cac";
11
11
 
12
12
  //#region src/features/debug.ts
13
- const debug = createDebug("tsdown:debug");
14
- function enableDebugLog(cliOptions) {
15
- const { debugLogs } = cliOptions;
16
- if (!debugLogs) return;
13
+ const debugLog = createDebug("tsdown:debug");
14
+ function enableDebug(cliOptions) {
15
+ const { debug } = cliOptions;
16
+ if (!debug) return;
17
17
  let namespace;
18
- if (debugLogs === true) namespace = "tsdown:*";
19
- else namespace = resolveComma(toArray(debugLogs)).map((v) => `tsdown:${v}`).join(",");
18
+ if (debug === true) namespace = "tsdown:*";
19
+ else namespace = resolveComma(toArray(debug)).map((v) => `tsdown:${v}`).join(",");
20
20
  const ns = namespaces();
21
21
  if (ns) namespace += `,${ns}`;
22
22
  enable(namespace);
23
- debug("Debugging enabled", namespace);
23
+ debugLog("Debugging enabled", namespace);
24
24
  }
25
25
 
26
26
  //#endregion
@@ -30,7 +30,7 @@ cli.help().version(version);
30
30
  cli.command("[...files]", "Bundle files", {
31
31
  ignoreOptionDefaultValue: true,
32
32
  allowUnknownOptions: true
33
- }).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug", "Enable debug mode").option("--debug-logs [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("--no-write", "Disable writing files to disk, incompatible with watch mode").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
33
+ }).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("--no-write", "Disable writing files to disk, incompatible with watch mode").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
34
34
  globalLogger.level = flags.logLevel || (flags.silent ? "error" : "info");
35
35
  globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
36
36
  const { build: build$1 } = await import("./index.mjs");
@@ -57,7 +57,7 @@ cli.command("migrate", "[deprecated] Migrate from tsup to tsdown. Use \"npx tsdo
57
57
  });
58
58
  async function runCLI() {
59
59
  cli.parse(process.argv, { run: false });
60
- enableDebugLog(cli.options);
60
+ enableDebug(cli.options);
61
61
  try {
62
62
  await cli.runMatchedCommand();
63
63
  } catch (error) {
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { a as globalLogger, c as matchPattern, d as promiseWithResolvers, f as resolveComma, h as toArray, l as noop, m as slash, o as prettyFormat, s as importWithError, t as LogLevels } from "./logger-s1ImI5j1.mjs";
4
- import { a as loadConfigFile, c as formatBytes, d as cleanOutDir, f as fsCopy, h as lowestCommonAncestor, i as resolveUserConfig, l as CssCodeSplitPlugin, m as fsRemove, o as getPackageType, p as fsExists, r as mergeUserOptions, s as writeExports, u as cleanChunks } from "./config-DlCfPR2i.mjs";
5
- import { t as version } from "./package-BZkqghxy.mjs";
3
+ import { a as globalLogger, c as matchPattern, d as promiseWithResolvers, f as resolveComma, h as toArray, l as noop, m as slash, o as prettyFormat, s as importWithError, t as LogLevels } from "./logger-D_2uXZBG.mjs";
4
+ import { a as loadConfigFile, c as formatBytes, d as cleanOutDir, f as fsCopy, h as lowestCommonAncestor, i as resolveUserConfig, l as CssCodeSplitPlugin, m as fsRemove, o as getPackageType, p as fsExists, r as mergeUserOptions, s as writeExports, u as cleanChunks } from "./config-CQ0WjrHu.mjs";
5
+ import { t as version } from "./package-PFFWH-Jh.mjs";
6
6
  import { builtinModules, isBuiltin } from "node:module";
7
7
  import { chmod, mkdtemp, readFile, writeFile } from "node:fs/promises";
8
8
  import path, { join } from "node:path";
@@ -11,8 +11,8 @@ import util, { formatWithOptions, promisify } from "node:util";
11
11
  import { blue, bold, dim, green, underline } from "ansis";
12
12
  import { createDebug } from "obug";
13
13
  import { glob, isDynamicPattern } from "tinyglobby";
14
- import { RE_CSS, RE_DTS, RE_JS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
15
14
  import { fileURLToPath } from "node:url";
15
+ import { RE_CSS, RE_DTS, RE_JS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
16
16
  import { clearRequireCache } from "import-without-cache";
17
17
  import * as Rolldown from "rolldown";
18
18
  import { VERSION, build, watch } from "rolldown";
@@ -171,6 +171,17 @@ function renameTarget(target, rename, src) {
171
171
  return typeof rename === "string" ? rename : rename(parsedPath.name, parsedPath.ext.replace(".", ""), src);
172
172
  }
173
173
 
174
+ //#endregion
175
+ //#region src/features/devtools.ts
176
+ async function startDevtoolsUI(config) {
177
+ const { start } = await importWithError("@vitejs/devtools/cli-commands");
178
+ await start({
179
+ host: "127.0.0.1",
180
+ open: true,
181
+ ...typeof config.ui === "object" ? config.ui : {}
182
+ });
183
+ }
184
+
174
185
  //#endregion
175
186
  //#region src/features/hooks.ts
176
187
  async function createHooks(options) {
@@ -742,7 +753,7 @@ async function getBuildOptions(config, format, configFiles, bundle, cjsDts = fal
742
753
  return rolldownConfig;
743
754
  }
744
755
  async function resolveInputOptions(config, format, configFiles, bundle, cjsDts, isDualFormat) {
745
- const { alias, cjsDefault, cwd, debug: debug$7, dts, entry, env: env$1, external, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch: watch$1 } = config;
756
+ const { alias, cjsDefault, cwd, devtools, dts, entry, env: env$1, external, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch: watch$1 } = config;
746
757
  const plugins = [];
747
758
  if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
748
759
  if (config.pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config));
@@ -806,7 +817,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
806
817
  if (log.code === "MIXED_EXPORT") return;
807
818
  defaultHandler(level, log);
808
819
  } : void 0,
809
- debug: debug$7 || void 0,
820
+ devtools: devtools || void 0,
810
821
  checks: { pluginTimings: false }
811
822
  }, config.inputOptions, [format, { cjsDts }]);
812
823
  }
@@ -944,19 +955,11 @@ async function build$1(userOptions = {}) {
944
955
  const bundles = await Promise.all(configs.map((options) => {
945
956
  return buildSingle(options, configFiles, options.pkg ? configChunksByPkg[options.pkg.packageJsonPath].formats.size > 1 : true, clean, restart, done);
946
957
  }));
947
- const firstDevtoolsConfig = configs.find((config) => config.debug && config.debug.devtools);
958
+ const firstDevtoolsConfig = configs.find((config) => config.devtools && config.devtools.ui);
948
959
  if (configs.some((config) => config.watch)) {
949
960
  disposeCbs.push(shortcuts(restart));
950
961
  for (const bundle of bundles) disposeCbs.push(bundle[asyncDispose]);
951
- } else if (firstDevtoolsConfig) {
952
- const { start } = await importWithError("@vitejs/devtools/cli-commands");
953
- const devtoolsOptions = firstDevtoolsConfig.debug.devtools;
954
- await start({
955
- host: "127.0.0.1",
956
- open: true,
957
- ...typeof devtoolsOptions === "object" ? devtoolsOptions : {}
958
- });
959
- }
962
+ } else if (firstDevtoolsConfig) startDevtoolsUI(firstDevtoolsConfig.devtools);
960
963
  return bundles;
961
964
  }
962
965
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsdown",
3
3
  "type": "module",
4
- "version": "0.18.4",
4
+ "version": "0.19.0-beta.2",
5
5
  "description": "The Elegant Bundler for Libraries",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -22,8 +22,6 @@
22
22
  "./package.json": "./package.json",
23
23
  "./client": "./client.d.ts"
24
24
  },
25
- "main": "./dist/index.mjs",
26
- "module": "./dist/index.mjs",
27
25
  "types": "./dist/index.d.mts",
28
26
  "typesVersions": {
29
27
  "*": {
@@ -84,14 +82,14 @@
84
82
  "import-without-cache": "^0.2.5",
85
83
  "obug": "^2.1.1",
86
84
  "picomatch": "^4.0.3",
87
- "rolldown": "1.0.0-beta.57",
85
+ "rolldown": "1.0.0-beta.58",
88
86
  "rolldown-plugin-dts": "^0.20.0",
89
87
  "semver": "^7.7.3",
90
88
  "tinyexec": "^1.0.2",
91
89
  "tinyglobby": "^0.2.15",
92
90
  "tree-kill": "^1.2.2",
93
91
  "unconfig-core": "^7.4.2",
94
- "unrun": "^0.2.21"
92
+ "unrun": "^0.2.22"
95
93
  },
96
94
  "devDependencies": {
97
95
  "@arethetypeswrong/core": "^0.18.2",
@@ -101,7 +99,7 @@
101
99
  "@types/node": "^25.0.3",
102
100
  "@types/picomatch": "^4.0.2",
103
101
  "@types/semver": "^7.7.1",
104
- "@typescript/native-preview": "7.0.0-dev.20251230.1",
102
+ "@typescript/native-preview": "7.0.0-dev.20260101.1",
105
103
  "@unocss/eslint-plugin": "^66.5.12",
106
104
  "@vitejs/devtools": "^0.0.0-alpha.22",
107
105
  "@vitest/coverage-v8": "4.0.16",
@@ -120,6 +118,7 @@
120
118
  "rolldown-plugin-require-cjs": "^0.3.3",
121
119
  "typescript": "~5.9.3",
122
120
  "unocss": "^66.5.12",
121
+ "unplugin-ast": "^0.15.4",
123
122
  "unplugin-lightningcss": "^0.4.4",
124
123
  "unplugin-unused": "^0.5.6",
125
124
  "vite": "^8.0.0-beta.5",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.18.4";
3
-
4
- //#endregion
5
- export { version as t };