tsdown 0.11.8 → 0.11.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.
@@ -1,4 +1,4 @@
1
- import { UserConfig, UserConfigFn } from "./index-BoDsEHb5.js";
1
+ import { UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  /**
package/dist/config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { UserConfig, UserConfigFn } from "./index-BoDsEHb5.js";
2
- import { defineConfig$1 as defineConfig } from "./config-DILVUP_s.js";
1
+ import { UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
+ import { defineConfig$1 as defineConfig } from "./config-Cyqx6Xup.js";
3
3
  export { UserConfig, UserConfigFn, defineConfig };
@@ -296,13 +296,17 @@ interface Options$3 {
296
296
  * This allows you to build multiple packages in a monorepo.
297
297
  */
298
298
  workspace?: Workspace | Arrayable<string> | true;
299
+ /**
300
+ * Filter workspace packages. This option is only available in workspace mode.
301
+ */
302
+ filter?: RegExp | string | string[];
299
303
  }
300
304
  /**
301
305
  * Options without specifying config file path.
302
306
  */
303
- type UserConfig = Arrayable<Omit<Options$3, "config">>;
307
+ type UserConfig = Arrayable<Omit<Options$3, "config" | "filter">>;
304
308
  type UserConfigFn = (cliOptions: Options$3) => Awaitable<UserConfig>;
305
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name">, {
309
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name">, {
306
310
  format: NormalizedFormat[];
307
311
  target?: string[];
308
312
  clean: string[];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./index-BoDsEHb5.js";
2
- import { defineConfig$1 as defineConfig } from "./config-DILVUP_s.js";
1
+ import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
+ import { defineConfig$1 as defineConfig } from "./config-Cyqx6Xup.js";
3
3
  import "ansis";
4
4
  import { InternalModuleFormat } from "rolldown";
5
5
 
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import { up as up$1 } from "empathic/find";
19
19
  import { loadConfig } from "unconfig";
20
20
 
21
21
  //#region src/features/clean.ts
22
- const debug$4 = Debug("tsdown:clean");
22
+ const debug$3 = Debug("tsdown:clean");
23
23
  const RE_LAST_SLASH = /[/\\]$/;
24
24
  async function cleanOutDir(configs) {
25
25
  const removes = new Set();
@@ -39,10 +39,10 @@ async function cleanOutDir(configs) {
39
39
  if (!removes.size) return;
40
40
  logger.info(`Cleaning ${removes.size} files`);
41
41
  await Promise.all([...removes].map(async (file) => {
42
- debug$4("Removing", file);
42
+ debug$3("Removing", file);
43
43
  await fsRemove(file);
44
44
  }));
45
- debug$4("Removed %d files", removes.size);
45
+ debug$3("Removed %d files", removes.size);
46
46
  }
47
47
  function resolveClean(clean, outDir, cwd) {
48
48
  if (clean === true) clean = [slash(outDir)];
@@ -136,11 +136,11 @@ async function LightningCSSPlugin(options) {
136
136
 
137
137
  //#endregion
138
138
  //#region src/utils/package.ts
139
- const debug$3 = Debug("tsdown:package");
139
+ const debug$2 = Debug("tsdown:package");
140
140
  async function readPackageJson(dir) {
141
141
  const packageJsonPath = up({ cwd: dir });
142
142
  if (!packageJsonPath) return;
143
- debug$3("Reading package.json:", packageJsonPath);
143
+ debug$2("Reading package.json:", packageJsonPath);
144
144
  const contents = await readFile(packageJsonPath, "utf8");
145
145
  return JSON.parse(contents);
146
146
  }
@@ -198,19 +198,20 @@ function createChunkFilename(basename, jsExtension, dtsExtension) {
198
198
 
199
199
  //#endregion
200
200
  //#region src/features/publint.ts
201
- const debug$2 = Debug("tsdown:publint");
201
+ const debug$1 = Debug("tsdown:publint");
202
202
  async function publint(options) {
203
203
  if (!options.publint) return;
204
204
  if (!options.pkg) {
205
205
  logger.warn("publint is enabled but package.json is not found");
206
206
  return;
207
207
  }
208
- debug$2("Running publint");
208
+ const t = performance.now();
209
+ debug$1("Running publint");
209
210
  const { publint: publint$1 } = await import("publint");
210
211
  const { formatMessage } = await import("publint/utils");
211
212
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
212
- debug$2("Found %d issues", messages.length);
213
- if (!messages.length) logger.success("No publint issues found");
213
+ debug$1("Found %d issues", messages.length);
214
+ if (!messages.length) logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
214
215
  let hasError = false;
215
216
  for (const message of messages) {
216
217
  hasError ||= message.type === "error";
@@ -223,7 +224,7 @@ async function publint(options) {
223
224
  logger[logType](formattedMessage);
224
225
  }
225
226
  if (hasError) {
226
- debug$2("Found errors, setting exit code to 1");
227
+ debug$1("Found errors, setting exit code to 1");
227
228
  process.exitCode = 1;
228
229
  }
229
230
  }
@@ -293,12 +294,12 @@ function shortcuts(restart) {
293
294
 
294
295
  //#endregion
295
296
  //#region src/features/watch.ts
296
- const endsWithPackageJson = /[\\/]package\.json$/;
297
- async function watchBuild(options, configFile, rebuild, restart) {
297
+ const endsWithConfig = /[\\/](?:package\.json|tsdown\.config.*)$/;
298
+ async function watchBuild(options, configFiles, rebuild, restart) {
298
299
  if (typeof options.watch === "boolean" && options.outDir === options.cwd) throw new Error(`Watch is enabled, but output directory is the same as the current working directory.Please specify a different watch directory using ${blue`watch`} option,or set ${blue`outDir`} to a different directory.`);
299
300
  const files = toArray(typeof options.watch === "boolean" ? options.cwd : options.watch);
300
301
  logger.info(`Watching for changes in ${files.join(", ")}`);
301
- if (configFile) files.push(configFile);
302
+ files.push(...configFiles);
302
303
  const { watch } = await import("chokidar");
303
304
  const debouncedRebuild = debounce(rebuild, 100);
304
305
  const watcher = watch(files, {
@@ -311,7 +312,7 @@ async function watchBuild(options, configFile, rebuild, restart) {
311
312
  ]
312
313
  });
313
314
  watcher.on("all", (type, file) => {
314
- if (endsWithPackageJson.test(file) || configFile === file) {
315
+ if (configFiles.includes(file) || endsWithConfig.test(file)) {
315
316
  logger.info(`Reload config: ${file}`);
316
317
  restart();
317
318
  return;
@@ -325,13 +326,11 @@ async function watchBuild(options, configFile, rebuild, restart) {
325
326
  //#endregion
326
327
  //#region src/features/entry.ts
327
328
  async function resolveEntry(entry, cwd, name) {
328
- if (!entry || Object.keys(entry).length === 0) {
329
- const nameLabel = name ? `[${name}] ` : "";
330
- throw new Error(`${nameLabel}No input files, try "tsdown <your-file>" instead`);
331
- }
329
+ const nameLabel = name ? `[${name}] ` : "";
330
+ if (!entry || Object.keys(entry).length === 0) throw new Error(`${nameLabel}No input files, try "tsdown <your-file>" instead`);
332
331
  const entryMap = await toObjectEntry(entry, cwd);
333
332
  const entries = Object.values(entryMap);
334
- if (entries.length === 0) throw new Error(`Cannot find entry: ${JSON.stringify(entry)}`);
333
+ if (entries.length === 0) throw new Error(`${nameLabel}Cannot find entry: ${JSON.stringify(entry)}`);
335
334
  logger.info(prettyName(name), `entry: ${generateColor(name)(entries.map((entry$1) => path.relative(cwd, entry$1)).join(", "))}`);
336
335
  return entryMap;
337
336
  }
@@ -489,7 +488,7 @@ async function loadConfigFile(options, workspace) {
489
488
 
490
489
  //#endregion
491
490
  //#region src/options/index.ts
492
- const debug$1 = Debug("tsdown:options");
491
+ const debug = Debug("tsdown:options");
493
492
  const DEFAULT_EXCLUDE_WORKSPACE = [
494
493
  "**/node_modules/**",
495
494
  "**/dist/**",
@@ -497,19 +496,24 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
497
496
  "**/t?(e)mp/**"
498
497
  ];
499
498
  async function resolveOptions(options) {
499
+ const files = [];
500
+ debug("options %O", options);
501
+ debug("loading config file: %s", options.config);
500
502
  const { configs: rootConfigs, file } = await loadConfigFile(options);
501
503
  if (file) {
502
- debug$1("Loaded config file %s", file);
503
- debug$1("Root configs %o", rootConfigs);
504
- }
504
+ files.push(file);
505
+ debug("loaded root config file %s", file);
506
+ debug("root configs %o", rootConfigs);
507
+ } else debug("no root config file found");
505
508
  const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
506
- const workspaceConfigs = await resolveWorkspace(rootConfig, options);
509
+ const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
510
+ if (workspaceFiles) files.push(...workspaceFiles);
507
511
  return Promise.all(workspaceConfigs.map((config) => resolveConfig(config)));
508
512
  }))).flat();
509
- debug$1("Resolved configs %O", configs);
513
+ debug("resolved configs %O", configs);
510
514
  return {
511
515
  configs,
512
- file
516
+ files
513
517
  };
514
518
  }
515
519
  async function resolveWorkspace(config, options) {
@@ -519,7 +523,10 @@ async function resolveWorkspace(config, options) {
519
523
  };
520
524
  const rootCwd = normalized.cwd || process.cwd();
521
525
  let { workspace } = normalized;
522
- if (!workspace) return [normalized];
526
+ if (!workspace) return {
527
+ configs: [normalized],
528
+ files: []
529
+ };
523
530
  if (workspace === true) workspace = {};
524
531
  else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
525
532
  let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
@@ -536,19 +543,35 @@ async function resolveWorkspace(config, options) {
536
543
  absolute: true
537
544
  })).map((file) => path.resolve(file));
538
545
  if (packages.length === 0) throw new Error("No workspace packages found, please check your config");
546
+ if (options.filter) {
547
+ if (typeof options.filter === "string" && options.filter.length > 2 && options.filter[0] === "/" && options.filter.at(-1) === "/") options.filter = new RegExp(options.filter.slice(1, -1));
548
+ packages = packages.filter((path$1) => {
549
+ return typeof options.filter === "string" ? path$1.includes(options.filter) : Array.isArray(options.filter) ? options.filter.some((filter) => path$1.includes(filter)) : options.filter.test(path$1);
550
+ });
551
+ if (packages.length === 0) throw new Error("No packages matched the filters");
552
+ }
553
+ const files = [];
539
554
  const configs = (await Promise.all(packages.map(async (cwd) => {
540
- const { configs: configs$1 } = await loadConfigFile({
555
+ debug("loading workspace config %s", cwd);
556
+ const { configs: configs$1, file } = await loadConfigFile({
541
557
  ...options,
542
558
  config: workspaceConfig,
543
559
  cwd
544
560
  }, cwd);
561
+ if (file) {
562
+ debug("loaded workspace config file %s", file);
563
+ files.push(file);
564
+ } else debug("no workspace config file found in %s", cwd);
545
565
  return configs$1.map((config$1) => ({
546
566
  ...normalized,
547
567
  cwd,
548
568
  ...config$1
549
569
  }));
550
570
  }))).flat();
551
- return configs;
571
+ return {
572
+ configs,
573
+ files
574
+ };
552
575
  }
553
576
  async function resolveConfig(userConfig) {
554
577
  let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace } = userConfig;
@@ -612,20 +635,12 @@ async function mergeUserOptions(defaults, user, args) {
612
635
 
613
636
  //#endregion
614
637
  //#region src/index.ts
615
- const debug = Debug("tsdown:main");
616
638
  /**
617
639
  * Build with tsdown.
618
640
  */
619
641
  async function build(userOptions = {}) {
620
642
  if (typeof userOptions.silent === "boolean") logger.setSilent(userOptions.silent);
621
- debug("Loading config");
622
- const { configs, file: configFile } = await resolveOptions(userOptions);
623
- if (configFile) {
624
- debug("Loaded config:", configFile);
625
- configs.forEach((config) => {
626
- debug("using resolved config: %O", config);
627
- });
628
- } else debug("No config file found");
643
+ const { configs, files: configFiles } = await resolveOptions(userOptions);
629
644
  let cleanPromise;
630
645
  const clean = () => {
631
646
  if (cleanPromise) return cleanPromise;
@@ -637,7 +652,7 @@ async function build(userOptions = {}) {
637
652
  for (const [i, config] of configs.entries()) {
638
653
  const rebuild = rebuilds[i];
639
654
  if (!rebuild) continue;
640
- const watcher = await watchBuild(config, configFile, rebuild, restart);
655
+ const watcher = await watchBuild(config, configFiles, rebuild, restart);
641
656
  cleanCbs.push(() => watcher.close());
642
657
  }
643
658
  if (cleanCbs.length) shortcuts(restart);
@@ -1,5 +1,5 @@
1
1
  import { logger } from "./logger-BdIBA2vO.js";
2
- import { version } from "./package-BjzIq4Wm.js";
2
+ import { version } from "./package-BbnQTn6e.js";
3
3
  import process from "node:process";
4
4
  import { bold, green, underline } from "ansis";
5
5
  import { readFile, unlink, writeFile } from "node:fs/promises";
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.11.9";
3
+
4
+ //#endregion
5
+ export { version };
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./index-BoDsEHb5.js";
1
+ import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./index-B5B9KM9d.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
package/dist/run.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { logger, resolveComma, toArray } from "./logger-BdIBA2vO.js";
3
- import { version } from "./package-BjzIq4Wm.js";
3
+ import { version } from "./package-BbnQTn6e.js";
4
4
  import module from "node:module";
5
5
  import process from "node:process";
6
6
  import { dim } from "ansis";
@@ -14,7 +14,7 @@ cli.help().version(version);
14
14
  cli.command("[...files]", "Bundle files", {
15
15
  ignoreOptionDefaultValue: true,
16
16
  allowUnknownOptions: true
17
- }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [scope]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "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("--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("-W, --workspace [dir]", "Enable workspace mode").action(async (input, flags) => {
17
+ }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [scope]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "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("--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("-W, --workspace [dir]", "Enable workspace mode").option("-f, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").action(async (input, flags) => {
18
18
  logger.setSilent(!!flags.silent);
19
19
  logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
20
20
  const { build: build$1 } = await import("./index.js");
@@ -22,7 +22,7 @@ cli.command("[...files]", "Bundle files", {
22
22
  await build$1(flags);
23
23
  });
24
24
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
25
- const { migrate } = await import("./migrate-DJbJNdWb.js");
25
+ const { migrate } = await import("./migrate-CDIgKGak.js");
26
26
  await migrate(args);
27
27
  });
28
28
  async function runCLI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.11.8";
3
-
4
- //#endregion
5
- export { version };