tsdown 0.6.0 → 0.6.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.
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as Config } from './options.d-CXI-XGhn.js';
1
+ import { U as UserConfig } from './options.d-DY0J98cF.js';
2
2
  import 'publint';
3
3
  import 'rolldown';
4
4
  import 'unplugin-isolated-decl';
@@ -7,6 +7,6 @@ import 'unplugin-unused';
7
7
  /**
8
8
  * Defines the configuration for tsdown.
9
9
  */
10
- declare function defineConfig(options: Config): Config;
10
+ declare function defineConfig(options: UserConfig): UserConfig;
11
11
 
12
12
  export { defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { O as Options, R as ResolvedOptions } from './options.d-DY0J98cF.js';
2
+ export { U as UserConfig } from './options.d-DY0J98cF.js';
3
3
  import { ConsolaInstance } from 'consola';
4
4
  export { defineConfig } from './config.js';
5
5
  import 'publint';
@@ -20,8 +20,8 @@ declare const pkgRoot: string;
20
20
  /**
21
21
  * Build a single configuration, without watch and shortcuts features.
22
22
  *
23
- * @param resolved Resolved options
23
+ * @param config Resolved options
24
24
  */
25
- declare function buildSingle(resolved: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
25
+ declare function buildSingle(config: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
26
26
 
27
27
  export { Options, build, buildSingle, logger, pkgRoot };
package/dist/index.js CHANGED
@@ -106,6 +106,18 @@ function getPackageType(pkg) {
106
106
  }
107
107
  return "commonjs";
108
108
  }
109
+ function normalizeFormat(format) {
110
+ return toArray(format, "es").map((format$1) => {
111
+ switch (format$1) {
112
+ case "es":
113
+ case "esm":
114
+ case "module": return "es";
115
+ case "cjs":
116
+ case "commonjs": return "cjs";
117
+ default: return format$1;
118
+ }
119
+ });
120
+ }
109
121
 
110
122
  //#endregion
111
123
  //#region src/features/output.ts
@@ -194,7 +206,7 @@ function shortcuts(restart) {
194
206
  if (loggedKeys.has(shortcut$1.key)) continue;
195
207
  loggedKeys.add(shortcut$1.key);
196
208
  if (shortcut$1.action == null) continue;
197
- logger.info(dim(" press ") + bold(`${shortcut$1.key} + enter`) + dim(` to ${shortcut$1.description}`));
209
+ logger.info(dim` press ` + bold`${shortcut$1.key} + enter` + dim` to ${shortcut$1.description}`);
198
210
  }
199
211
  return;
200
212
  }
@@ -261,18 +273,27 @@ async function toObjectEntry(entry) {
261
273
  //#endregion
262
274
  //#region src/options.ts
263
275
  async function resolveOptions(options) {
264
- const [config, configFile] = await loadConfigFile(options);
265
- if (config.length === 0) config.push({});
266
- return [await Promise.all(config.map(async (subConfig) => {
276
+ const { configs: userConfigs, file, cwd } = await loadConfigFile(options);
277
+ if (userConfigs.length === 0) userConfigs.push({});
278
+ const configs = await Promise.all(userConfigs.map(async (subConfig) => {
267
279
  const subOptions = {
268
280
  ...subConfig,
269
281
  ...options
270
282
  };
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;
283
+ 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, fromVite, alias } = subOptions;
272
284
  entry = await resolveEntry(entry);
273
285
  if (clean === true) clean = [];
274
286
  if (publint$1 === true) publint$1 = {};
275
- return {
287
+ if (fromVite) {
288
+ const viteUserConfig = await loadViteConfig(cwd);
289
+ if (viteUserConfig) {
290
+ if (Array.isArray(alias)) throw new TypeError("Unsupported resolve.alias in Vite config. Use object instead of array");
291
+ if (viteUserConfig.plugins) plugins = [viteUserConfig.plugins, plugins];
292
+ const viteAlias = viteUserConfig.resolve?.alias;
293
+ if (viteAlias && !Array.isArray(viteAlias)) alias = viteAlias;
294
+ }
295
+ }
296
+ const config = {
276
297
  ...subOptions,
277
298
  entry,
278
299
  plugins,
@@ -289,35 +310,34 @@ async function resolveOptions(options) {
289
310
  watch,
290
311
  shims,
291
312
  skipNodeModulesBundle,
292
- publint: publint$1
313
+ publint: publint$1,
314
+ alias
293
315
  };
294
- })), configFile];
295
- }
296
- function normalizeFormat(format) {
297
- return toArray(format, "es").map((format$1) => {
298
- switch (format$1) {
299
- case "es":
300
- case "esm":
301
- case "module": return "es";
302
- case "cjs":
303
- case "commonjs": return "cjs";
304
- default: return format$1;
305
- }
306
- });
316
+ return config;
317
+ }));
318
+ return {
319
+ configs,
320
+ file
321
+ };
307
322
  }
308
323
  async function loadConfigFile(options) {
309
- let { config: filePath } = options;
310
- if (filePath === false) return [[]];
311
324
  let cwd = process.cwd();
312
325
  let overrideConfig = false;
313
- let stats;
314
- if (typeof filePath === "string" && (stats = await stat(filePath).catch(() => null))) {
315
- const resolved = path.resolve(filePath);
316
- if (stats.isFile()) {
317
- overrideConfig = true;
318
- filePath = resolved;
319
- cwd = path.dirname(filePath);
320
- } else cwd = resolved;
326
+ let { config: filePath } = options;
327
+ if (filePath === false) return {
328
+ configs: [],
329
+ cwd
330
+ };
331
+ if (typeof filePath === "string") {
332
+ const stats = await stat(filePath).catch(() => null);
333
+ if (stats) {
334
+ const resolved = path.resolve(filePath);
335
+ if (stats.isFile()) {
336
+ overrideConfig = true;
337
+ filePath = resolved;
338
+ cwd = path.dirname(filePath);
339
+ } else if (stats.isDirectory()) cwd = resolved;
340
+ }
321
341
  }
322
342
  const { config, sources } = await loadConfig({
323
343
  sources: overrideConfig ? [{
@@ -345,7 +365,38 @@ async function loadConfigFile(options) {
345
365
  });
346
366
  if (sources.length > 0) logger.info(`Using tsdown config: ${underline(sources.join(", "))}`);
347
367
  const file = sources[0];
348
- return [toArray(config), file];
368
+ return {
369
+ configs: toArray(config),
370
+ file,
371
+ cwd
372
+ };
373
+ }
374
+ async function loadViteConfig(cwd) {
375
+ const { config, sources: [source] } = await loadConfig({
376
+ sources: [{
377
+ files: "vite.config",
378
+ extensions: [
379
+ "ts",
380
+ "mts",
381
+ "cts",
382
+ "js",
383
+ "mjs",
384
+ "cjs",
385
+ "json",
386
+ ""
387
+ ]
388
+ }],
389
+ cwd,
390
+ defaults: {}
391
+ });
392
+ if (!source) return;
393
+ logger.info(`Using Vite config: ${underline(source)}`);
394
+ const resolved = await config;
395
+ if (typeof resolved === "function") return resolved({
396
+ command: "build",
397
+ mode: "production"
398
+ });
399
+ return resolved;
349
400
  }
350
401
  async function mergeUserOptions(defaults, user, args) {
351
402
  const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
@@ -358,17 +409,17 @@ async function mergeUserOptions(defaults, user, args) {
358
409
  //#endregion
359
410
  //#region src/index.ts
360
411
  async function build(userOptions = {}) {
361
- typeof userOptions.silent === "boolean" && setSilent(userOptions.silent);
412
+ if (typeof userOptions.silent === "boolean") setSilent(userOptions.silent);
362
413
  debug("Loading config");
363
- const [resolveds, configFile] = await resolveOptions(userOptions);
414
+ const { configs, file: configFile } = await resolveOptions(userOptions);
364
415
  if (configFile) debug("Loaded config:", configFile);
365
416
  else debug("No config file found");
366
- const rebuilds = await Promise.all(resolveds.map(buildSingle));
417
+ const rebuilds = await Promise.all(configs.map(buildSingle));
367
418
  const cleanCbs = [];
368
- for (const [i, resolved] of resolveds.entries()) {
419
+ for (const [i, config] of configs.entries()) {
369
420
  const rebuild = rebuilds[i];
370
421
  if (!rebuild) continue;
371
- const watcher = await watchBuild(resolved, configFile, rebuild, restart);
422
+ const watcher = await watchBuild(config, configFile, rebuild, restart);
372
423
  cleanCbs.push(() => watcher.close());
373
424
  }
374
425
  if (cleanCbs.length) shortcuts(restart);
@@ -379,8 +430,8 @@ async function build(userOptions = {}) {
379
430
  }
380
431
  const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
381
432
  const pkgRoot = path.resolve(dirname$1, "..");
382
- async function buildSingle(resolved) {
383
- const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = resolved;
433
+ async function buildSingle(config) {
434
+ const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = config;
384
435
  if (clean) await cleanOutDir(outDir, clean);
385
436
  const pkg = await readPackageJson(process.cwd());
386
437
  await rebuild(true);
@@ -396,34 +447,34 @@ async function buildSingle(resolved) {
396
447
  platform,
397
448
  define,
398
449
  plugins: [
399
- (pkg || resolved.skipNodeModulesBundle) && ExternalPlugin(resolved, pkg),
450
+ (pkg || config.skipNodeModulesBundle) && ExternalPlugin(config, pkg),
400
451
  unused && (await import("unplugin-unused")).Unused.rolldown(unused === true ? {} : unused),
401
452
  dts && (await import("unplugin-isolated-decl")).IsolatedDecl.rolldown({
402
453
  ...dts,
403
- extraOutdir: resolved.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
454
+ extraOutdir: config.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
404
455
  }),
405
456
  target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
406
457
  userPlugins
407
458
  ].filter((plugin) => !!plugin),
408
459
  inject: { ...shims && getShimsInject(format$1, platform) }
409
- }, resolved.inputOptions, [format$1]);
460
+ }, config.inputOptions, [format$1]);
410
461
  const extension = resolveOutputExtension(pkg, format$1, fixedExtension);
411
462
  const outputOptions = await mergeUserOptions({
412
463
  format: format$1,
413
- name: resolved.globalName,
464
+ name: config.globalName,
414
465
  sourcemap,
415
466
  dir: outDir,
416
467
  minify,
417
468
  entryFileNames: `[name].${extension}`,
418
469
  chunkFileNames: `[name]-[hash].${extension}`
419
- }, resolved.outputOptions, [format$1]);
470
+ }, config.outputOptions, [format$1]);
420
471
  await build$1({
421
472
  ...inputOptions,
422
473
  output: outputOptions
423
474
  });
424
- if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension, format$1);
475
+ if (config.dts && config.bundleDts) await bundleDts(config, extension, format$1);
425
476
  }));
426
- if (resolved.publint) if (pkg) await publint(pkg);
477
+ if (config.publint) if (pkg) await publint(pkg);
427
478
  else logger.warn("publint is enabled but package.json is not found");
428
479
  logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
429
480
  await onSuccess?.();
@@ -1,4 +1,4 @@
1
- import { version } from "./package-Doir6ANF.js";
1
+ import { version } from "./package-CsxLeVcz.js";
2
2
  import process from "node:process";
3
3
  import { readFile, unlink, writeFile } from "node:fs/promises";
4
4
  import consola from "consola";
@@ -1,5 +1,5 @@
1
1
  import { Options as Options$3 } from 'publint';
2
- import { InputOptions, ModuleFormat, ExternalOption, OutputOptions, InternalModuleFormat } from 'rolldown';
2
+ import { InputOptions, ExternalOption, ModuleFormat, OutputOptions, InternalModuleFormat } from 'rolldown';
3
3
  import { Options as Options$1 } from 'unplugin-isolated-decl';
4
4
  import { Options as Options$2 } from 'unplugin-unused';
5
5
 
@@ -20,40 +20,29 @@ type Sourcemap = boolean | "inline" | "hidden";
20
20
  */
21
21
  interface Options {
22
22
  entry?: InputOptions["input"];
23
- format?: ModuleFormat | ModuleFormat[];
24
- globalName?: string;
25
- plugins?: InputOptions["plugins"];
26
23
  external?: ExternalOption;
27
24
  noExternal?: Arrayable<string | RegExp> | ((id: string, importer: string | undefined) => boolean | null | undefined | void);
25
+ alias?: Record<string, string>;
26
+ /** @default 'node' */
27
+ platform?: "node" | "neutral" | "browser";
28
+ inputOptions?: InputOptions | ((options: InputOptions, format: ModuleFormat) => MaybePromise<InputOptions | void | null>);
29
+ format?: ModuleFormat | ModuleFormat[];
30
+ globalName?: string;
28
31
  outDir?: string;
29
- clean?: boolean | string[];
30
- silent?: boolean;
31
- config?: boolean | string;
32
32
  sourcemap?: Sourcemap;
33
- alias?: Record<string, string>;
34
- /** @default true */
35
- treeshake?: boolean;
33
+ clean?: boolean | string[];
36
34
  /** @default false */
37
35
  minify?: boolean;
38
36
  target?: string | string[];
39
37
  define?: Record<string, string>;
40
- /** @default 'node' */
41
- platform?: "node" | "neutral" | "browser";
42
38
  shims?: boolean;
43
- /**
44
- * Enable dts generation with `isolatedDeclarations` (experimental)
45
- */
46
- dts?: boolean | Options$1;
39
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: ModuleFormat) => MaybePromise<OutputOptions | void | null>);
47
40
  /** @default true */
48
- bundleDts?: boolean;
49
- /**
50
- * Enable unused dependencies check with `unplugin-unused`
51
- * Requires `unplugin-unused` to be installed.
52
- */
53
- unused?: boolean | Options$2;
41
+ treeshake?: boolean;
42
+ plugins?: InputOptions["plugins"];
43
+ silent?: boolean;
44
+ config?: boolean | string;
54
45
  watch?: boolean | string | string[];
55
- inputOptions?: InputOptions | ((options: InputOptions, format: ModuleFormat) => MaybePromise<InputOptions | void | null>);
56
- outputOptions?: OutputOptions | ((options: OutputOptions, format: ModuleFormat) => MaybePromise<OutputOptions | void | null>);
57
46
  onSuccess?: () => void | Promise<void>;
58
47
  /**
59
48
  * Skip bundling node_modules.
@@ -67,6 +56,22 @@ interface Options {
67
56
  */
68
57
  fixedExtension?: boolean;
69
58
  /**
59
+ * Reuse config from Vite or Vitest (experimental)
60
+ * @default false
61
+ */
62
+ fromVite?: boolean;
63
+ /**
64
+ * Enable dts generation with `isolatedDeclarations` (experimental)
65
+ */
66
+ dts?: boolean | Options$1;
67
+ /** @default true */
68
+ bundleDts?: boolean;
69
+ /**
70
+ * Enable unused dependencies check with `unplugin-unused`
71
+ * Requires `unplugin-unused` to be installed.
72
+ */
73
+ unused?: boolean | Options$2;
74
+ /**
70
75
  * Run publint after bundling.
71
76
  * Requires `publint` to be installed.
72
77
  */
@@ -75,12 +80,12 @@ interface Options {
75
80
  /**
76
81
  * Options without specifying config file path.
77
82
  */
78
- type Config = Arrayable<Omit<Options, "config">>;
83
+ type UserConfig = Arrayable<Omit<Options, "config">>;
79
84
  type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
80
85
  type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension">, {
81
86
  format: NormalizedFormat[]
82
87
  clean: string[] | false
83
88
  dts: false | Options$1
84
- }>, "config">;
89
+ }>, "config" | "fromVite">;
85
90
 
86
- export type { Config as C, Options as O, ResolvedOptions as R };
91
+ export type { Options as O, ResolvedOptions as R, UserConfig as U };
@@ -0,0 +1,6 @@
1
+
2
+ //#region package.json
3
+ var version = "0.6.2";
4
+
5
+ //#endregion
6
+ export { version };
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedOptions } from './options.d-CXI-XGhn.js';
1
+ import { R as ResolvedOptions } from './options.d-DY0J98cF.js';
2
2
  import { PackageJson } from 'pkg-types';
3
3
  import { Plugin } from 'rolldown';
4
4
  import 'publint';
package/dist/run.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { logger, setSilent } from "./logger-4bmpqibt.js";
2
- import { version } from "./package-Doir6ANF.js";
2
+ import { version } from "./package-CsxLeVcz.js";
3
3
  import process from "node:process";
4
4
  import { VERSION } from "rolldown";
5
5
  import { dim } from "ansis";
@@ -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 ${dim(`v${version}`)} powered by rolldown ${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-pZBdQXB2.js");
19
+ const { migrate } = await import("./migrate-StuSmFYP.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.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "An even faster bundler powered by Rolldown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -53,39 +53,40 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "ansis": "^3.15.0",
56
+ "ansis": "^3.17.0",
57
57
  "cac": "^6.7.14",
58
58
  "chokidar": "^4.0.3",
59
59
  "consola": "^3.4.0",
60
60
  "debug": "^4.4.0",
61
61
  "diff": "^7.0.0",
62
- "pkg-types": "^1.3.1",
62
+ "pkg-types": "^2.0.1",
63
63
  "rolldown": "^1.0.0-beta.3",
64
- "rollup": "^4.34.8",
64
+ "rollup": "^4.34.9",
65
65
  "rollup-plugin-dts": "^6.1.1",
66
- "tinyglobby": "^0.2.11",
67
- "unconfig": "^7.0.0",
68
- "unplugin-isolated-decl": "^0.11.2"
66
+ "tinyglobby": "^0.2.12",
67
+ "unconfig": "^7.2.0",
68
+ "unplugin-isolated-decl": "^0.12.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@sxzz/eslint-config": "^5.1.1",
71
+ "@sxzz/eslint-config": "^5.2.0",
72
72
  "@sxzz/prettier-config": "^2.2.0",
73
73
  "@sxzz/test-utils": "^0.5.1",
74
74
  "@types/debug": "^4.1.12",
75
75
  "@types/diff": "^7.0.1",
76
- "@types/node": "^22.13.4",
76
+ "@types/node": "^22.13.8",
77
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",
78
+ "eslint": "^9.21.0",
79
+ "oxc-transform": "^0.53.0",
80
+ "prettier": "^3.5.3",
81
+ "publint": "^0.3.7",
82
82
  "tinyexec": "^0.3.2",
83
- "tsup": "^8.3.6",
83
+ "tsup": "^8.4.0",
84
84
  "tsx": "^4.19.3",
85
- "typescript": "~5.7.3",
85
+ "typescript": "~5.8.2",
86
86
  "unplugin-ast": "^0.14.0",
87
- "unplugin-unused": "^0.4.1",
88
- "vitest": "^3.0.6"
87
+ "unplugin-unused": "^0.4.2",
88
+ "vite": "^6.2.0",
89
+ "vitest": "^3.0.7"
89
90
  },
90
91
  "engines": {
91
92
  "node": ">=18.0.0"
@@ -1,6 +0,0 @@
1
-
2
- //#region package.json
3
- var version = "0.6.0";
4
-
5
- //#endregion
6
- export { version };