tsdown 0.5.9 → 0.6.0

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/config.d.ts CHANGED
@@ -1,7 +1,12 @@
1
- export { d as defineConfig } from './config.d-BB68aL5b.js';
2
- import './plugins.d-4au0qSn9.js';
3
- import 'pkg-types';
4
- import 'rolldown';
1
+ import { C as Config } from './options.d-CXI-XGhn.js';
5
2
  import 'publint';
3
+ import 'rolldown';
6
4
  import 'unplugin-isolated-decl';
7
5
  import 'unplugin-unused';
6
+
7
+ /**
8
+ * Defines the configuration for tsdown.
9
+ */
10
+ declare function defineConfig(options: Config): Config;
11
+
12
+ export { defineConfig };
@@ -0,0 +1,61 @@
1
+ import Debug from "debug";
2
+
3
+ //#region src/utils/general.ts
4
+ function toArray(val, defaultValue) {
5
+ if (Array.isArray(val)) return val;
6
+ else if (val == null) {
7
+ if (defaultValue) return [defaultValue];
8
+ return [];
9
+ } else return [val];
10
+ }
11
+ function debounce(fn, wait) {
12
+ let timeout;
13
+ return function(...args) {
14
+ if (timeout) clearTimeout(timeout);
15
+ timeout = setTimeout(() => {
16
+ timeout = undefined;
17
+ fn.apply(this, args);
18
+ }, wait);
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ //#region src/features/external.ts
24
+ const debug = Debug("tsdown:external");
25
+ function ExternalPlugin(options, pkg) {
26
+ const deps = pkg && Array.from(getProductionDeps(pkg));
27
+ return {
28
+ name: "tsdown:external",
29
+ async resolveId(id, importer, { isEntry }) {
30
+ if (isEntry) return;
31
+ const { noExternal } = options;
32
+ if (typeof noExternal === "function" && noExternal(id, importer)) return;
33
+ if (noExternal) {
34
+ const noExternalPatterns = toArray(noExternal);
35
+ if (noExternalPatterns.some((pattern) => {
36
+ return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
37
+ })) return;
38
+ }
39
+ let shouldExternal = false;
40
+ if (options.skipNodeModulesBundle) {
41
+ const resolved = await this.resolve(id);
42
+ if (!resolved) return;
43
+ shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
44
+ }
45
+ if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
46
+ if (shouldExternal) {
47
+ debug("External dependency:", id);
48
+ return {
49
+ id,
50
+ external: true
51
+ };
52
+ }
53
+ }
54
+ };
55
+ }
56
+ function getProductionDeps(pkg) {
57
+ return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
58
+ }
59
+
60
+ //#endregion
61
+ export { ExternalPlugin, debounce, toArray };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { O as Options, R as ResolvedOptions } from './config.d-BB68aL5b.js';
2
- export { C as Config, d as defineConfig } from './config.d-BB68aL5b.js';
1
+ import { O as Options, R as ResolvedOptions } from './options.d-CXI-XGhn.js';
2
+ export { C as Config } from './options.d-CXI-XGhn.js';
3
3
  import { ConsolaInstance } from 'consola';
4
- import './plugins.d-4au0qSn9.js';
5
- import 'pkg-types';
6
- import 'rolldown';
4
+ export { defineConfig } from './config.js';
7
5
  import 'publint';
6
+ import 'rolldown';
8
7
  import 'unplugin-isolated-decl';
9
8
  import 'unplugin-unused';
10
9
 
package/dist/index.js CHANGED
@@ -1,23 +1,19 @@
1
1
  import { defineConfig } from "./config-0LDjKwZ7.js";
2
2
  import { debug, logger, setSilent } from "./logger-4bmpqibt.js";
3
- import { ExternalPlugin } from "./external-QIv-o_HK.js";
3
+ import { ExternalPlugin, debounce, toArray } from "./external-CaGWwJ2H.js";
4
4
  import path, { dirname, normalize, sep } from "node:path";
5
5
  import process from "node:process";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { build as build$1 } from "rolldown";
8
8
  import { transformPlugin } from "rolldown/experimental";
9
- import { IsolatedDecl } from "unplugin-isolated-decl";
10
- import { Unused } from "unplugin-unused";
11
9
  import { access, readdir, rm, stat } from "node:fs/promises";
12
10
  import Debug from "debug";
13
11
  import { glob } from "tinyglobby";
14
12
  import { rollup } from "rollup";
15
13
  import DtsPlugin from "rollup-plugin-dts";
16
14
  import { readPackageJSON } from "pkg-types";
17
- import { publint } from "publint";
18
- import { formatMessage } from "publint/utils";
19
15
  import readline from "node:readline";
20
- import pc from "picocolors";
16
+ import { blue, bold, dim, underline } from "ansis";
21
17
  import { loadConfig } from "unconfig";
22
18
 
23
19
  //#region src/utils/fs.ts
@@ -66,26 +62,6 @@ async function cleanOutDir(cwd, patterns) {
66
62
  }
67
63
  }
68
64
 
69
- //#endregion
70
- //#region src/utils/general.ts
71
- function toArray(val, defaultValue) {
72
- if (Array.isArray(val)) return val;
73
- else if (val == null) {
74
- if (defaultValue) return [defaultValue];
75
- return [];
76
- } else return [val];
77
- }
78
- function debounce(fn, wait) {
79
- let timeout;
80
- return function(...args) {
81
- if (timeout) clearTimeout(timeout);
82
- timeout = setTimeout(() => {
83
- timeout = undefined;
84
- fn.apply(this, args);
85
- }, wait);
86
- };
87
- }
88
-
89
65
  //#endregion
90
66
  //#region src/features/dts.ts
91
67
  const TEMP_DTS_DIR = ".tsdown-types";
@@ -145,9 +121,11 @@ function resolveOutputExtension(pkg, format, fixedExtension) {
145
121
  //#endregion
146
122
  //#region src/features/publint.ts
147
123
  const debug$1 = Debug("tsdown:publint");
148
- async function publint$1(pkg) {
124
+ async function publint(pkg) {
125
+ const { publint: publint$1 } = await import("publint");
126
+ const { formatMessage } = await import("publint/utils");
149
127
  debug$1("Running publint");
150
- const { messages } = await publint();
128
+ const { messages } = await publint$1();
151
129
  debug$1("Found %d issues", messages.length);
152
130
  if (!messages.length) logger.success("No publint issues found");
153
131
  let hasError = false;
@@ -216,7 +194,7 @@ function shortcuts(restart) {
216
194
  if (loggedKeys.has(shortcut$1.key)) continue;
217
195
  loggedKeys.add(shortcut$1.key);
218
196
  if (shortcut$1.action == null) continue;
219
- logger.info(pc.dim(" press ") + pc.bold(`${shortcut$1.key} + enter`) + pc.dim(` to ${shortcut$1.description}`));
197
+ logger.info(dim(" press ") + bold(`${shortcut$1.key} + enter`) + dim(` to ${shortcut$1.description}`));
220
198
  }
221
199
  return;
222
200
  }
@@ -266,7 +244,7 @@ async function resolveEntry(entry) {
266
244
  const objectEntry = await toObjectEntry(entry);
267
245
  const entries = Object.values(objectEntry);
268
246
  if (entries.length === 0) throw new Error(`Cannot find entry: ${JSON.stringify(entry)}`);
269
- logger.info(`entry: ${pc.blue(entries.join(", "))}`);
247
+ logger.info(`entry: ${blue(entries.join(", "))}`);
270
248
  return objectEntry;
271
249
  }
272
250
  async function toObjectEntry(entry) {
@@ -290,10 +268,10 @@ async function resolveOptions(options) {
290
268
  ...subConfig,
291
269
  ...options
292
270
  };
293
- let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, bundleDts: bundleDts$1 = true, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$2 = false } = subOptions;
271
+ let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, bundleDts: bundleDts$1 = true, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false } = subOptions;
294
272
  entry = await resolveEntry(entry);
295
273
  if (clean === true) clean = [];
296
- if (publint$2 === true) publint$2 = {};
274
+ if (publint$1 === true) publint$1 = {};
297
275
  return {
298
276
  ...subOptions,
299
277
  entry,
@@ -311,7 +289,7 @@ async function resolveOptions(options) {
311
289
  watch,
312
290
  shims,
313
291
  skipNodeModulesBundle,
314
- publint: publint$2
292
+ publint: publint$1
315
293
  };
316
294
  })), configFile];
317
295
  }
@@ -365,7 +343,7 @@ async function loadConfigFile(options) {
365
343
  cwd,
366
344
  defaults: {}
367
345
  });
368
- if (sources.length > 0) logger.info(`Using tsdown config: ${pc.underline(sources.join(", "))}`);
346
+ if (sources.length > 0) logger.info(`Using tsdown config: ${underline(sources.join(", "))}`);
369
347
  const file = sources[0];
370
348
  return [toArray(config), file];
371
349
  }
@@ -418,9 +396,9 @@ async function buildSingle(resolved) {
418
396
  platform,
419
397
  define,
420
398
  plugins: [
421
- (pkg || resolved.skipNodeModulesBundle) && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
422
- unused && Unused.rolldown(unused === true ? {} : unused),
423
- dts && IsolatedDecl.rolldown({
399
+ (pkg || resolved.skipNodeModulesBundle) && ExternalPlugin(resolved, pkg),
400
+ unused && (await import("unplugin-unused")).Unused.rolldown(unused === true ? {} : unused),
401
+ dts && (await import("unplugin-isolated-decl")).IsolatedDecl.rolldown({
424
402
  ...dts,
425
403
  extraOutdir: resolved.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
426
404
  }),
@@ -445,7 +423,7 @@ async function buildSingle(resolved) {
445
423
  });
446
424
  if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension, format$1);
447
425
  }));
448
- if (resolved.publint) if (pkg) await publint$1(pkg);
426
+ if (resolved.publint) if (pkg) await publint(pkg);
449
427
  else logger.warn("publint is enabled but package.json is not found");
450
428
  logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
451
429
  await onSuccess?.();
@@ -1,8 +1,8 @@
1
- import { version } from "./package-DJ0bMKNl.js";
1
+ import { version } from "./package-Doir6ANF.js";
2
2
  import process from "node:process";
3
3
  import { readFile, unlink, writeFile } from "node:fs/promises";
4
4
  import consola from "consola";
5
- import pc from "picocolors";
5
+ import { gray, green, red } from "ansis";
6
6
  import { existsSync } from "node:fs";
7
7
  import { diffLines } from "diff";
8
8
 
@@ -15,7 +15,7 @@ function diff(original, updated) {
15
15
  });
16
16
  for (const line of diff$1) {
17
17
  const { value } = line;
18
- text += line.added ? pc.green(value) : line.removed ? pc.red(value) : pc.gray(line.value);
18
+ text += line.added ? green(value) : line.removed ? red(value) : gray(line.value);
19
19
  }
20
20
  return text;
21
21
  }
@@ -1,6 +1,5 @@
1
- import { E as External } from './plugins.d-4au0qSn9.js';
2
1
  import { Options as Options$3 } from 'publint';
3
- import { InputOptions, ModuleFormat, OutputOptions, InternalModuleFormat } from 'rolldown';
2
+ import { InputOptions, ModuleFormat, ExternalOption, OutputOptions, InternalModuleFormat } from 'rolldown';
4
3
  import { Options as Options$1 } from 'unplugin-isolated-decl';
5
4
  import { Options as Options$2 } from 'unplugin-unused';
6
5
 
@@ -24,7 +23,8 @@ interface Options {
24
23
  format?: ModuleFormat | ModuleFormat[];
25
24
  globalName?: string;
26
25
  plugins?: InputOptions["plugins"];
27
- external?: External;
26
+ external?: ExternalOption;
27
+ noExternal?: Arrayable<string | RegExp> | ((id: string, importer: string | undefined) => boolean | null | undefined | void);
28
28
  outDir?: string;
29
29
  clean?: boolean | string[];
30
30
  silent?: boolean;
@@ -47,7 +47,8 @@ interface Options {
47
47
  /** @default true */
48
48
  bundleDts?: boolean;
49
49
  /**
50
- * Enable unused dependencies check with `unplugin-unused` (experimental)
50
+ * Enable unused dependencies check with `unplugin-unused`
51
+ * Requires `unplugin-unused` to be installed.
51
52
  */
52
53
  unused?: boolean | Options$2;
53
54
  watch?: boolean | string | string[];
@@ -65,6 +66,10 @@ interface Options {
65
66
  * @default false
66
67
  */
67
68
  fixedExtension?: boolean;
69
+ /**
70
+ * Run publint after bundling.
71
+ * Requires `publint` to be installed.
72
+ */
68
73
  publint?: boolean | Options$3;
69
74
  }
70
75
  /**
@@ -72,15 +77,10 @@ interface Options {
72
77
  */
73
78
  type Config = Arrayable<Omit<Options, "config">>;
74
79
  type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
75
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "onSuccess" | "dts" | "fixedExtension">, {
80
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension">, {
76
81
  format: NormalizedFormat[]
77
82
  clean: string[] | false
78
83
  dts: false | Options$1
79
84
  }>, "config">;
80
85
 
81
- /**
82
- * Defines the configuration for tsdown.
83
- */
84
- declare function defineConfig(options: Config): Config;
85
-
86
- export { type Config as C, type Options as O, type ResolvedOptions as R, defineConfig as d };
86
+ export type { Config as C, Options as O, ResolvedOptions as R };
@@ -0,0 +1,6 @@
1
+
2
+ //#region package.json
3
+ var version = "0.6.0";
4
+
5
+ //#endregion
6
+ export { version };
package/dist/plugins.d.ts CHANGED
@@ -1,3 +1,10 @@
1
- export { a as ExternalPlugin } from './plugins.d-4au0qSn9.js';
2
- import 'pkg-types';
3
- import 'rolldown';
1
+ import { R as ResolvedOptions } from './options.d-CXI-XGhn.js';
2
+ import { PackageJson } from 'pkg-types';
3
+ import { Plugin } from 'rolldown';
4
+ import 'publint';
5
+ import 'unplugin-isolated-decl';
6
+ import 'unplugin-unused';
7
+
8
+ declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Plugin;
9
+
10
+ export { ExternalPlugin };
package/dist/plugins.js CHANGED
@@ -1,3 +1,3 @@
1
- import { ExternalPlugin } from "./external-QIv-o_HK.js";
1
+ import { ExternalPlugin } from "./external-CaGWwJ2H.js";
2
2
 
3
3
  export { ExternalPlugin };
package/dist/run.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { logger, setSilent } from "./logger-4bmpqibt.js";
2
- import { version } from "./package-DJ0bMKNl.js";
2
+ import { version } from "./package-Doir6ANF.js";
3
3
  import process from "node:process";
4
4
  import { VERSION } from "rolldown";
5
- import pc from "picocolors";
5
+ import { dim } from "ansis";
6
6
  import { cac } from "cac";
7
7
 
8
8
  //#region src/cli.ts
@@ -10,13 +10,13 @@ const cli = cac("tsdown");
10
10
  cli.help().version(version);
11
11
  cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).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("--minify", "Minify output").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("-w, --watch [path]", "Watch mode").action(async (input, flags) => {
12
12
  setSilent(!!flags.silent);
13
- logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${VERSION}`)}`);
13
+ logger.info(`tsdown ${dim(`v${version}`)} powered by rolldown ${dim(`v${VERSION}`)}`);
14
14
  const { build: build$1 } = await import("./index.js");
15
15
  if (input.length > 0) flags.entry = input;
16
16
  await build$1(flags);
17
17
  });
18
18
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
19
- const { migrate } = await import("./migrate-DynPUYzO.js");
19
+ const { migrate } = await import("./migrate-pZBdQXB2.js");
20
20
  await migrate(args);
21
21
  });
22
22
  async function runCLI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.5.9",
3
+ "version": "0.6.0",
4
4
  "description": "An even faster bundler powered by Rolldown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,40 +40,52 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
+ "peerDependencies": {
44
+ "publint": "^0.3.0",
45
+ "unplugin-unused": "^0.4.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "publint": {
49
+ "optional": true
50
+ },
51
+ "unplugin-unused": {
52
+ "optional": true
53
+ }
54
+ },
43
55
  "dependencies": {
56
+ "ansis": "^3.15.0",
44
57
  "cac": "^6.7.14",
45
58
  "chokidar": "^4.0.3",
46
59
  "consola": "^3.4.0",
47
60
  "debug": "^4.4.0",
48
61
  "diff": "^7.0.0",
49
- "picocolors": "^1.1.1",
50
62
  "pkg-types": "^1.3.1",
51
- "publint": "^0.3.3",
52
63
  "rolldown": "^1.0.0-beta.3",
53
- "rollup": "^4.34.4",
64
+ "rollup": "^4.34.8",
54
65
  "rollup-plugin-dts": "^6.1.1",
55
- "tinyglobby": "^0.2.10",
66
+ "tinyglobby": "^0.2.11",
56
67
  "unconfig": "^7.0.0",
57
- "unplugin-isolated-decl": "^0.11.0",
58
- "unplugin-unused": "^0.4.1"
68
+ "unplugin-isolated-decl": "^0.11.2"
59
69
  },
60
70
  "devDependencies": {
61
- "@sxzz/eslint-config": "^5.0.1",
62
- "@sxzz/prettier-config": "^2.1.2",
71
+ "@sxzz/eslint-config": "^5.1.1",
72
+ "@sxzz/prettier-config": "^2.2.0",
63
73
  "@sxzz/test-utils": "^0.5.1",
64
74
  "@types/debug": "^4.1.12",
65
75
  "@types/diff": "^7.0.1",
66
- "@types/node": "^22.13.1",
67
- "bumpp": "^10.0.2",
68
- "eslint": "^9.19.0",
69
- "oxc-transform": "^0.48.2",
70
- "prettier": "^3.4.2",
76
+ "@types/node": "^22.13.4",
77
+ "bumpp": "^10.0.3",
78
+ "eslint": "^9.20.1",
79
+ "oxc-transform": "^0.51.0",
80
+ "prettier": "^3.5.1",
81
+ "publint": "^0.3.5",
71
82
  "tinyexec": "^0.3.2",
72
83
  "tsup": "^8.3.6",
73
- "tsx": "^4.19.2",
84
+ "tsx": "^4.19.3",
74
85
  "typescript": "~5.7.3",
75
86
  "unplugin-ast": "^0.14.0",
76
- "vitest": "^3.0.5"
87
+ "unplugin-unused": "^0.4.1",
88
+ "vitest": "^3.0.6"
77
89
  },
78
90
  "engines": {
79
91
  "node": ">=18.0.0"
@@ -1,33 +0,0 @@
1
- import Debug from "debug";
2
-
3
- //#region src/features/external.ts
4
- const debug = Debug("tsdown:external");
5
- function ExternalPlugin(pkg, skipNodeModulesBundle) {
6
- const deps = pkg && Array.from(getProductionDeps(pkg));
7
- return {
8
- name: "tsdown:external",
9
- async resolveId(id, importer, { isEntry }) {
10
- if (isEntry) return;
11
- let shouldExternal = false;
12
- if (skipNodeModulesBundle) {
13
- const resolved = await this.resolve(id);
14
- if (!resolved) return;
15
- shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
16
- }
17
- if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
18
- if (shouldExternal) {
19
- debug("External dependency:", id);
20
- return {
21
- id,
22
- external: true
23
- };
24
- }
25
- }
26
- };
27
- }
28
- function getProductionDeps(pkg) {
29
- return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
30
- }
31
-
32
- //#endregion
33
- export { ExternalPlugin };
@@ -1,6 +0,0 @@
1
-
2
- //#region package.json
3
- var version = "0.5.9";
4
-
5
- //#endregion
6
- export { version };
@@ -1,7 +0,0 @@
1
- import { PackageJson } from 'pkg-types';
2
- import { InputOptions, Plugin } from 'rolldown';
3
-
4
- type External = InputOptions["external"];
5
- declare function ExternalPlugin(pkg?: PackageJson, skipNodeModulesBundle?: boolean): Plugin;
6
-
7
- export { type External as E, ExternalPlugin as a };