tsdown 0.8.0-beta.1 → 0.8.0-beta.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright © 2024-PRESENT 三咲智子 Kevin Deng (https://github.com/sxzz)
3
+ Copyright (c) 2024-present VoidZero Inc. & Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # tsdown [![npm](https://img.shields.io/npm/v/tsdown.svg)](https://npmjs.com/package/tsdown) [![Unit Test](https://github.com/sxzz/tsdown/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/tsdown/actions/workflows/unit-test.yml) [![JSR](https://jsr.io/badges/@sxzz/tsdown)](https://jsr.io/@sxzz/tsdown)
1
+ # tsdown [![npm](https://img.shields.io/npm/v/tsdown.svg)](https://npmjs.com/package/tsdown) [![Unit Test](https://github.com/rolldown/tsdown/actions/workflows/unit-test.yml/badge.svg)](https://github.com/rolldown/tsdown/actions/workflows/unit-test.yml) [![JSR](https://jsr.io/badges/@sxzz/tsdown)](https://jsr.io/@sxzz/tsdown)
2
2
 
3
3
  ⚡️ An even faster bundler powered by [Rolldown](https://github.com/rolldown/rolldown).
4
4
 
5
5
  ## Features
6
6
 
7
7
  - 🚀 **Blazing fast**: Build and generate `.d.ts` powered by Oxc and Rolldown, incredibly fast!
8
- - ♻️ **Powerful ecosystem**: Support Rollup / Rolldown / Vite / unplugin plugins.
8
+ - ♻️ **Powerful ecosystem**: Support Rollup / Rolldown / unplugin plugins, and some Vite plugins.
9
9
  - 📦 **Out-of-box**: Support reusing configurations from Vite or Vitest.
10
10
  - 🔄 **Seamless migration**: Compatible with tsup's main options and features, ensuring a smooth transition.
11
11
 
@@ -50,6 +50,6 @@ This project also partially contains code derived or copied from [tsup](https://
50
50
  </a>
51
51
  </p>
52
52
 
53
- ## License
53
+ ## Licenses
54
54
 
55
- [MIT](./LICENSE) License © 2024-PRESENT [三咲智子 Kevin Deng](https://github.com/sxzz)
55
+ This project is licensed under the [MIT License](LICENSE).
@@ -1,10 +1,10 @@
1
- import { UserConfig } from "./options.d-qCI8h4Ee.js";
1
+ import { UserConfig } from "./options.d-C08fnFhO.js";
2
2
 
3
- //#region dist/.tsdown-types-es/config.d.ts
3
+ //#region src/config.d.ts
4
4
  /**
5
5
  * Defines the configuration for tsdown.
6
6
  */
7
7
  declare function defineConfig(options: UserConfig): UserConfig;
8
8
 
9
9
  //#endregion
10
- export { defineConfig };
10
+ export { defineConfig as defineConfig$1 };
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./options.d-qCI8h4Ee.js";
2
- import { defineConfig } from "./config.d-C4M__C8G.js";
1
+ import "./options.d-C08fnFhO.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-DBmaLxob.js";
3
3
 
4
4
  export { defineConfig };
@@ -0,0 +1,63 @@
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 = void 0;
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
+ const RE_DTS = /\.d\.[cm]?ts$/;
26
+ function ExternalPlugin(options, pkg) {
27
+ const deps = pkg && Array.from(getProductionDeps(pkg));
28
+ return {
29
+ name: "tsdown:external",
30
+ async resolveId(id, importer, { isEntry }) {
31
+ if (isEntry) return;
32
+ if (importer && RE_DTS.test(importer)) return;
33
+ const { noExternal } = options;
34
+ if (typeof noExternal === "function" && noExternal(id, importer)) return;
35
+ if (noExternal) {
36
+ const noExternalPatterns = toArray(noExternal);
37
+ if (noExternalPatterns.some((pattern) => {
38
+ return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
39
+ })) return;
40
+ }
41
+ let shouldExternal = false;
42
+ if (options.skipNodeModulesBundle) {
43
+ const resolved = await this.resolve(id);
44
+ if (!resolved) return;
45
+ shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
46
+ }
47
+ if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
48
+ if (shouldExternal) {
49
+ debug("External dependency:", id);
50
+ return {
51
+ id,
52
+ external: shouldExternal
53
+ };
54
+ }
55
+ }
56
+ };
57
+ }
58
+ function getProductionDeps(pkg) {
59
+ return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
60
+ }
61
+
62
+ //#endregion
63
+ export { ExternalPlugin, debounce, toArray };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,20 @@
1
- import { Options, ResolvedOptions, UserConfig } from "./options.d-qCI8h4Ee.js";
2
- import { defineConfig } from "./config.d-C4M__C8G.js";
1
+ import { Options, ResolvedOptions, UserConfig } from "./options.d-C08fnFhO.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-DBmaLxob.js";
3
+ import Debug from "debug";
3
4
  import { ConsolaInstance } from "consola";
4
- import "debug";
5
5
 
6
- //#region dist/.tsdown-types-es/utils/logger.d.ts
6
+ //#region src/utils/logger.d.ts
7
7
  /**
8
8
  * Logger instance
9
9
  */
10
10
  declare const logger: ConsolaInstance;
11
11
 
12
12
  //#endregion
13
- //#region dist/.tsdown-types-es/index.d.ts
13
+ //#region src/index.d.ts
14
14
  /**
15
15
  * Build with tsdown.
16
16
  */
17
17
  declare function build(userOptions?: Options): Promise<void>;
18
- /**
19
- * Build a single configuration, without watch and shortcuts features.
20
- *
21
- * @param config Resolved options
22
- */
23
18
  declare const pkgRoot: string;
24
19
  /**
25
20
  * Build a single configuration, without watch and shortcuts features.
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { defineConfig } from "./config-0LDjKwZ7.js";
2
- import { ExternalPlugin, bundleDts, debounce, fsExists, fsRemove, getTempDtsDir, lowestCommonAncestor, toArray } from "./external-DZHHBSOL.js";
3
- import { debug, logger, setSilent } from "./logger-9p9U7Sx7.js";
4
- import path from "node:path";
2
+ import { debug, logger, setSilent } from "./logger-4bmpqibt.js";
3
+ import { ExternalPlugin, debounce, toArray } from "./external-DvQ4QDcG.js";
4
+ import path, { dirname, normalize, sep } from "node:path";
5
5
  import process from "node:process";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { build as build$1 } from "rolldown";
8
8
  import { transformPlugin } from "rolldown/experimental";
9
- import { readFile, readdir, stat } from "node:fs/promises";
9
+ import { exec } from "tinyexec";
10
+ import { access, readFile, readdir, rm, stat } from "node:fs/promises";
10
11
  import Debug from "debug";
11
12
  import { glob } from "tinyglobby";
12
13
  import { findUp } from "find-up-simple";
@@ -14,6 +15,36 @@ import readline from "node:readline";
14
15
  import { blue, bold, dim, underline } from "ansis";
15
16
  import { loadConfig } from "unconfig";
16
17
 
18
+ //#region src/utils/fs.ts
19
+ function fsExists(path$1) {
20
+ return access(path$1).then(() => true, () => false);
21
+ }
22
+ function fsRemove(path$1) {
23
+ return rm(path$1, {
24
+ force: true,
25
+ recursive: true
26
+ }).catch(() => {});
27
+ }
28
+ function lowestCommonAncestor(...filepaths) {
29
+ if (filepaths.length === 0) return "";
30
+ if (filepaths.length === 1) return dirname(filepaths[0]);
31
+ filepaths = filepaths.map(normalize);
32
+ const [first, ...rest] = filepaths;
33
+ let ancestor = first.split(sep);
34
+ for (const filepath of rest) {
35
+ const directories = filepath.split(sep, ancestor.length);
36
+ let index = 0;
37
+ for (const directory of directories) if (directory === ancestor[index]) index += 1;
38
+ else {
39
+ ancestor = ancestor.slice(0, index);
40
+ break;
41
+ }
42
+ ancestor = ancestor.slice(0, index);
43
+ }
44
+ return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
45
+ }
46
+
47
+ //#endregion
17
48
  //#region src/features/clean.ts
18
49
  const debug$2 = Debug("tsdown:clean");
19
50
  async function cleanOutDir(cwd, patterns) {
@@ -221,11 +252,10 @@ async function resolveOptions(options) {
221
252
  ...subConfig,
222
253
  ...options
223
254
  };
224
- 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;
255
+ let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias } = subOptions;
225
256
  entry = await resolveEntry(entry);
226
257
  if (clean === true) clean = [];
227
258
  if (publint$1 === true) publint$1 = {};
228
- if (bundleDts$1 === true) bundleDts$1 = {};
229
259
  if (fromVite) {
230
260
  const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd);
231
261
  if (viteUserConfig) {
@@ -247,7 +277,6 @@ async function resolveOptions(options) {
247
277
  platform,
248
278
  sourcemap,
249
279
  dts: dts === true ? {} : dts,
250
- bundleDts: bundleDts$1,
251
280
  unused,
252
281
  watch,
253
282
  shims,
@@ -380,53 +409,20 @@ async function build(userOptions = {}) {
380
409
  const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
381
410
  const pkgRoot = path.resolve(dirname$1, "..");
382
411
  async function buildSingle(config) {
383
- const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = config;
412
+ const { entry, external, plugins: userPlugins, outDir, format: formats, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = config;
413
+ let onSuccessCleanup;
384
414
  const pkg = await readPackageJson(process.cwd());
385
415
  await rebuild(true);
386
416
  if (watch) return () => rebuild();
387
417
  async function rebuild(first) {
388
418
  const startTime = performance.now();
419
+ onSuccessCleanup?.();
389
420
  if (clean) await cleanOutDir(outDir, clean);
390
421
  let hasErrors = false;
391
- await Promise.all(format.map(async (format$1) => {
392
- const inputOptions = await mergeUserOptions({
393
- input: entry,
394
- external,
395
- resolve: { alias },
396
- treeshake,
397
- platform,
398
- define,
399
- plugins: [
400
- (pkg || config.skipNodeModulesBundle) && ExternalPlugin(config, pkg),
401
- unused && (await import("unplugin-unused")).Unused.rolldown(unused === true ? {} : unused),
402
- dts && (await import("unplugin-isolated-decl")).IsolatedDecl.rolldown({
403
- ...dts,
404
- extraOutdir: config.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
405
- }),
406
- !!target && transformPlugin({
407
- target: target && (typeof target === "string" ? target : target.join(",")),
408
- exclude: /\.d\.[cm]?ts$/
409
- }),
410
- userPlugins
411
- ],
412
- inject: { ...shims && getShimsInject(format$1, platform) }
413
- }, config.inputOptions, [format$1]);
414
- const extension = resolveOutputExtension(pkg, format$1, fixedExtension);
415
- const outputOptions = await mergeUserOptions({
416
- format: format$1,
417
- name: config.globalName,
418
- sourcemap,
419
- dir: outDir,
420
- minify,
421
- entryFileNames: `[name].${extension}`,
422
- chunkFileNames: `[name]-[hash].${extension}`
423
- }, config.outputOptions, [format$1]);
422
+ await Promise.all(formats.map(async (format) => {
424
423
  try {
425
- await build$1({
426
- ...inputOptions,
427
- output: outputOptions
428
- });
429
- if (config.dts && config.bundleDts) await bundleDts(config, extension, format$1);
424
+ await build$1(await getBuildOptions(format));
425
+ if (format === "cjs" && dts) await build$1(await getBuildOptions(format, true));
430
426
  } catch (error) {
431
427
  if (watch) {
432
428
  logger.error(error);
@@ -440,7 +436,61 @@ async function buildSingle(config) {
440
436
  if (config.publint) if (pkg) await publint(pkg);
441
437
  else logger.warn("publint is enabled but package.json is not found");
442
438
  logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
443
- await onSuccess?.(config);
439
+ if (typeof onSuccess === "string") {
440
+ const p = exec(onSuccess, [], { nodeOptions: {
441
+ shell: true,
442
+ stdio: "inherit"
443
+ } });
444
+ p.then(({ exitCode }) => {
445
+ if (exitCode) process.exitCode = exitCode;
446
+ });
447
+ onSuccessCleanup = () => p.kill("SIGTERM");
448
+ } else await onSuccess?.(config);
449
+ }
450
+ async function getBuildOptions(format, cjsDts) {
451
+ const extension = resolveOutputExtension(pkg, format, fixedExtension);
452
+ const plugins = [];
453
+ if (pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config, pkg));
454
+ if (unused && !cjsDts) {
455
+ const { Unused } = await import("unplugin-unused");
456
+ plugins.push(Unused.rolldown(unused === true ? {} : unused));
457
+ }
458
+ if (dts) {
459
+ const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
460
+ if (format === "es") plugins.push(dtsPlugin(dts));
461
+ else if (cjsDts) plugins.push(dtsPlugin({
462
+ ...dts,
463
+ emitDtsOnly: true
464
+ }));
465
+ }
466
+ if (target && !cjsDts) plugins.push(transformPlugin({
467
+ target: target && (typeof target === "string" ? target : target.join(",")),
468
+ exclude: /\.d\.[cm]?ts$/
469
+ }));
470
+ plugins.push(userPlugins);
471
+ const inputOptions = await mergeUserOptions({
472
+ input: entry,
473
+ external,
474
+ resolve: { alias },
475
+ treeshake,
476
+ platform,
477
+ define,
478
+ plugins,
479
+ inject: { ...shims && !cjsDts && getShimsInject(format, platform) }
480
+ }, config.inputOptions, [format]);
481
+ const outputOptions = await mergeUserOptions({
482
+ format: cjsDts ? "es" : format,
483
+ name: config.globalName,
484
+ sourcemap,
485
+ dir: outDir,
486
+ minify,
487
+ entryFileNames: `[name].${extension}`,
488
+ chunkFileNames: `[name]-[hash].${extension}`
489
+ }, config.outputOptions, [format]);
490
+ return {
491
+ ...inputOptions,
492
+ output: outputOptions
493
+ };
444
494
  }
445
495
  }
446
496
 
@@ -1,4 +1,4 @@
1
- import { version } from "./package-DIC6v_iz.js";
1
+ import { version } from "./package-BP-GE3SJ.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,15 +1,14 @@
1
- import { Options } from "publint";
2
1
  import { ExternalOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions } from "rolldown";
3
- import { CompilerOptions } from "typescript";
4
- import { Options as Options$1 } from "unplugin-isolated-decl";
2
+ import { Options } from "publint";
3
+ import { Options as Options$1 } from "rolldown-plugin-dts";
5
4
  import { Options as Options$2 } from "unplugin-unused";
6
5
 
7
- //#region dist/.tsdown-types-es/utils/types.d.ts
6
+ //#region src/utils/types.d.ts
8
7
  type Overwrite<
9
8
  T,
10
9
  U
11
10
  > = Omit<T, keyof U> & U;
12
- type MaybePromise<T> = T | Promise<T>;
11
+ type Awaitable<T> = T | Promise<T>;
13
12
  type MarkPartial<
14
13
  T,
15
14
  K extends keyof T
@@ -17,15 +16,8 @@ type MarkPartial<
17
16
  type Arrayable<T> = T | T[];
18
17
 
19
18
  //#endregion
20
- //#region dist/.tsdown-types-es/options.d.ts
21
- /** Resolve external types used in dts files from node_modules */
19
+ //#region src/options.d.ts
22
20
  type Sourcemap = boolean | "inline" | "hidden";
23
- /** Resolve external types used in dts files from node_modules */
24
- interface BundleDtsOptions {
25
- /** Resolve external types used in dts files from node_modules */
26
- resolve?: boolean | (string | RegExp)[];
27
- compilerOptions?: CompilerOptions;
28
- }
29
21
  /**
30
22
  * Options for tsdown.
31
23
  */
@@ -36,7 +28,7 @@ interface Options$3 {
36
28
  alias?: Record<string, string>;
37
29
  /** @default 'node' */
38
30
  platform?: "node" | "neutral" | "browser";
39
- inputOptions?: InputOptions | ((options: InputOptions, format: ModuleFormat) => MaybePromise<InputOptions | void | null>);
31
+ inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat) => Awaitable<InputOptions | void | null>);
40
32
  format?: ModuleFormat | ModuleFormat[];
41
33
  globalName?: string;
42
34
  outDir?: string;
@@ -47,14 +39,17 @@ interface Options$3 {
47
39
  target?: string | string[];
48
40
  define?: Record<string, string>;
49
41
  shims?: boolean;
50
- outputOptions?: OutputOptions | ((options: OutputOptions, format: ModuleFormat) => MaybePromise<OutputOptions | void | null>);
42
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: NormalizedFormat) => Awaitable<OutputOptions | void | null>);
51
43
  /** @default true */
52
44
  treeshake?: boolean;
53
45
  plugins?: InputOptions["plugins"];
54
46
  silent?: boolean;
55
47
  config?: boolean | string;
56
48
  watch?: boolean | string | string[];
57
- onSuccess?: (config: ResolvedOptions) => void | Promise<void>;
49
+ /**
50
+ * You can specify command to be executed after a successful build, specially useful for Watch mode
51
+ */
52
+ onSuccess?: string | ((config: ResolvedOptions) => void | Promise<void>);
58
53
  /**
59
54
  * Skip bundling node_modules.
60
55
  */
@@ -76,11 +71,6 @@ interface Options$3 {
76
71
  */
77
72
  dts?: boolean | Options$1;
78
73
  /**
79
- * Bundle dts files (experimental)
80
- * @default true
81
- */
82
- bundleDts?: boolean | BundleDtsOptions;
83
- /**
84
74
  * Enable unused dependencies check with `unplugin-unused`
85
75
  * Requires `unplugin-unused` to be installed.
86
76
  */
@@ -100,7 +90,6 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inp
100
90
  format: NormalizedFormat[]
101
91
  clean: string[] | false
102
92
  dts: false | Options$1
103
- bundleDts: false | BundleDtsOptions
104
93
  }>, "config" | "fromVite">;
105
94
 
106
95
  //#endregion
@@ -0,0 +1,6 @@
1
+
2
+ //#region package.json
3
+ var version = "0.8.0-beta.3";
4
+
5
+ //#endregion
6
+ export { version };
package/dist/plugins.d.ts CHANGED
@@ -1,13 +1,9 @@
1
- import { ResolvedOptions } from "./options.d-qCI8h4Ee.js";
1
+ import { ResolvedOptions } from "./options.d-C08fnFhO.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
5
- //#region dist/.tsdown-types-es/features/external.d.ts
5
+ //#region src/features/external.d.ts
6
6
  declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Plugin;
7
7
 
8
8
  //#endregion
9
- //#region dist/.tsdown-types-es/features/dts.d.ts
10
- declare function ResolveDtsPlugin(resolveOnly?: Array<string | RegExp>): Plugin;
11
-
12
- //#endregion
13
- export { ExternalPlugin, ResolveDtsPlugin };
9
+ export { ExternalPlugin };
package/dist/plugins.js CHANGED
@@ -1,3 +1,3 @@
1
- import { ExternalPlugin, ResolveDtsPlugin } from "./external-DZHHBSOL.js";
1
+ import { ExternalPlugin } from "./external-DvQ4QDcG.js";
2
2
 
3
- export { ExternalPlugin, ResolveDtsPlugin };
3
+ export { ExternalPlugin };
package/dist/run.js CHANGED
@@ -1,5 +1,5 @@
1
- import { logger, setSilent } from "./logger-9p9U7Sx7.js";
2
- import { version } from "./package-DIC6v_iz.js";
1
+ import { logger, setSilent } from "./logger-4bmpqibt.js";
2
+ import { version } from "./package-BP-GE3SJ.js";
3
3
  import process from "node:process";
4
4
  import { VERSION } from "rolldown";
5
5
  import { dim } from "ansis";
@@ -8,7 +8,7 @@ import { cac } from "cac";
8
8
  //#region src/cli.ts
9
9
  const cli = cac("tsdown");
10
10
  cli.help().version(version);
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").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").action(async (input, flags) => {
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("--dts", "Generate dts files", { default: false }).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").action(async (input, flags) => {
12
12
  setSilent(!!flags.silent);
13
13
  logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
14
14
  const { build: build$1 } = await import("./index.js");
@@ -16,7 +16,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
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-B8vI88KN.js");
19
+ const { migrate } = await import("./migrate-CgK5TG_a.js");
20
20
  await migrate(args);
21
21
  });
22
22
  async function runCLI() {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.8.0-beta.1",
3
+ "version": "0.8.0-beta.3",
4
4
  "description": "An even faster bundler powered by Rolldown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/sxzz/tsdown#readme",
7
+ "homepage": "https://github.com/rolldown/tsdown#readme",
8
8
  "bugs": {
9
- "url": "https://github.com/sxzz/tsdown/issues"
9
+ "url": "https://github.com/rolldown/tsdown/issues"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/sxzz/tsdown.git"
13
+ "url": "git+https://github.com/rolldown/tsdown.git"
14
14
  },
15
15
  "author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
16
16
  "funding": "https://github.com/sponsors/sxzz",
@@ -39,7 +39,8 @@
39
39
  "tsdown": "./bin/tsdown.js"
40
40
  },
41
41
  "publishConfig": {
42
- "access": "public"
42
+ "access": "public",
43
+ "tag": "beta"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "publint": "^0.3.0",
@@ -61,12 +62,11 @@
61
62
  "debug": "^4.4.0",
62
63
  "diff": "^7.0.0",
63
64
  "find-up-simple": "^1.0.1",
64
- "oxc-resolver": "^5.1.1",
65
65
  "rolldown": "^1.0.0-beta.7",
66
- "rolldown-plugin-dts": "^0.1.0",
66
+ "rolldown-plugin-dts": "^0.4.0",
67
+ "tinyexec": "^1.0.1",
67
68
  "tinyglobby": "^0.2.12",
68
- "unconfig": "^7.3.1",
69
- "unplugin-isolated-decl": "^0.13.6"
69
+ "unconfig": "^7.3.1"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@sxzz/eslint-config": "^6.1.1",
@@ -74,20 +74,19 @@
74
74
  "@sxzz/test-utils": "^0.5.4",
75
75
  "@types/debug": "^4.1.12",
76
76
  "@types/diff": "^7.0.2",
77
- "@types/node": "^22.14.0",
77
+ "@types/node": "^22.14.1",
78
78
  "bumpp": "^10.1.0",
79
79
  "eslint": "^9.24.0",
80
- "oxc-transform": "^0.62.0",
80
+ "oxc-transform": "^0.63.0",
81
81
  "pkg-types": "^2.1.0",
82
82
  "prettier": "^3.5.3",
83
- "publint": "^0.3.10",
84
- "tinyexec": "^1.0.1",
83
+ "publint": "^0.3.12",
85
84
  "tsup": "^8.4.0",
86
85
  "tsx": "^4.19.3",
87
86
  "typescript": "~5.8.3",
88
- "unplugin-ast": "^0.14.4",
87
+ "unplugin-ast": "^0.14.6",
89
88
  "unplugin-unused": "^0.4.4",
90
- "vite": "^6.2.5",
89
+ "vite": "^6.2.6",
91
90
  "vitest": "^3.1.1"
92
91
  },
93
92
  "engines": {
@@ -1,178 +0,0 @@
1
- import path, { dirname, normalize, sep } from "node:path";
2
- import process from "node:process";
3
- import { build } from "rolldown";
4
- import { access, rm } from "node:fs/promises";
5
- import Debug from "debug";
6
- import { ResolverFactory } from "oxc-resolver";
7
- import { dts } from "rolldown-plugin-dts";
8
-
9
- //#region src/utils/fs.ts
10
- function fsExists(path$1) {
11
- return access(path$1).then(() => true, () => false);
12
- }
13
- function fsRemove(path$1) {
14
- return rm(path$1, {
15
- force: true,
16
- recursive: true
17
- }).catch(() => {});
18
- }
19
- function lowestCommonAncestor(...filepaths) {
20
- if (filepaths.length === 0) return "";
21
- if (filepaths.length === 1) return dirname(filepaths[0]);
22
- filepaths = filepaths.map(normalize);
23
- const [first, ...rest] = filepaths;
24
- let ancestor = first.split(sep);
25
- for (const filepath of rest) {
26
- const directories = filepath.split(sep, ancestor.length);
27
- let index = 0;
28
- for (const directory of directories) if (directory === ancestor[index]) index += 1;
29
- else {
30
- ancestor = ancestor.slice(0, index);
31
- break;
32
- }
33
- ancestor = ancestor.slice(0, index);
34
- }
35
- return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
36
- }
37
-
38
- //#endregion
39
- //#region src/utils/general.ts
40
- function toArray(val, defaultValue) {
41
- if (Array.isArray(val)) return val;
42
- else if (val == null) {
43
- if (defaultValue) return [defaultValue];
44
- return [];
45
- } else return [val];
46
- }
47
- function debounce(fn, wait) {
48
- let timeout;
49
- return function(...args) {
50
- if (timeout) clearTimeout(timeout);
51
- timeout = setTimeout(() => {
52
- timeout = void 0;
53
- fn.apply(this, args);
54
- }, wait);
55
- };
56
- }
57
-
58
- //#endregion
59
- //#region src/features/dts.ts
60
- const debug$1 = Debug("tsdown:dts");
61
- const TEMP_DTS_DIR = ".tsdown-types";
62
- function getTempDtsDir(format) {
63
- return `${TEMP_DTS_DIR}-${format}`;
64
- }
65
- async function bundleDts(options, jsExtension, format) {
66
- debug$1("Bundle dts for %s", format);
67
- const { dts: dts$1, bundleDts: bundleDts$1 } = options;
68
- const ext = jsExtension.replace("j", "t");
69
- const dtsOutDir = path.resolve(options.outDir, getTempDtsDir(format));
70
- const dtsEntry = Object.fromEntries(Object.keys(options.entry).map((key) => [key, path.resolve(dtsOutDir, `${key}.d.${ext}`)]));
71
- let outDir = options.outDir;
72
- if (dts$1.extraOutdir) outDir = path.resolve(outDir, dts$1.extraOutdir);
73
- await build({
74
- input: dtsEntry,
75
- onLog(level, log, defaultHandler) {
76
- if (log.code !== "EMPTY_BUNDLE" && log.code !== "UNRESOLVED_IMPORT") defaultHandler(level, log);
77
- },
78
- plugins: [bundleDts$1.resolve && ResolveDtsPlugin(bundleDts$1.resolve !== true ? bundleDts$1.resolve : void 0), dts()],
79
- output: {
80
- dir: outDir,
81
- entryFileNames: `[name].d.${ext}`,
82
- chunkFileNames: `[name]-[hash].d.${ext}`
83
- }
84
- });
85
- await fsRemove(dtsOutDir);
86
- debug$1("Bundle dts done for %s", format);
87
- }
88
- let resolver;
89
- function ResolveDtsPlugin(resolveOnly) {
90
- return {
91
- name: "resolve-dts",
92
- buildStart() {
93
- resolver ||= new ResolverFactory({
94
- mainFields: ["types"],
95
- conditionNames: [
96
- "types",
97
- "typings",
98
- "import",
99
- "require"
100
- ],
101
- extensions: [
102
- ".d.ts",
103
- ".d.mts",
104
- ".d.cts",
105
- ".ts",
106
- ".mts",
107
- ".cts"
108
- ],
109
- modules: ["node_modules", "node_modules/@types"]
110
- });
111
- },
112
- async resolveId(id, importer) {
113
- if (id[0] === "." || path.isAbsolute(id)) return;
114
- if (/\0/.test(id)) return;
115
- if (resolveOnly) {
116
- const shouldResolve = resolveOnly.some((value) => {
117
- if (typeof value === "string") return value === id;
118
- return value.test(id);
119
- });
120
- if (!shouldResolve) {
121
- debug$1("skipped by matching resolveOnly: %s", id);
122
- return;
123
- }
124
- }
125
- const directory = importer ? path.dirname(importer) : process.cwd();
126
- debug$1("Resolving:", id, "from:", directory);
127
- const { path: resolved } = await resolver.async(directory, id);
128
- if (!resolved) return;
129
- debug$1("Resolved:", resolved);
130
- if (/[cm]?jsx?$/.test(resolved)) {
131
- const dts$1 = resolved.replace(/\.([cm]?)jsx?$/, ".d.$1ts");
132
- return await fsExists(dts$1) ? dts$1 : void 0;
133
- }
134
- return resolved;
135
- }
136
- };
137
- }
138
-
139
- //#endregion
140
- //#region src/features/external.ts
141
- const debug = Debug("tsdown:external");
142
- function ExternalPlugin(options, pkg) {
143
- const deps = pkg && Array.from(getProductionDeps(pkg));
144
- return {
145
- name: "tsdown:external",
146
- async resolveId(id, importer, { isEntry }) {
147
- if (isEntry) return;
148
- const { noExternal } = options;
149
- if (typeof noExternal === "function" && noExternal(id, importer)) return;
150
- if (noExternal) {
151
- const noExternalPatterns = toArray(noExternal);
152
- if (noExternalPatterns.some((pattern) => {
153
- return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
154
- })) return;
155
- }
156
- let shouldExternal = false;
157
- if (options.skipNodeModulesBundle) {
158
- const resolved = await this.resolve(id);
159
- if (!resolved) return;
160
- shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
161
- }
162
- if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
163
- if (shouldExternal) {
164
- debug("External dependency:", id);
165
- return {
166
- id,
167
- external: shouldExternal
168
- };
169
- }
170
- }
171
- };
172
- }
173
- function getProductionDeps(pkg) {
174
- return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
175
- }
176
-
177
- //#endregion
178
- export { ExternalPlugin, ResolveDtsPlugin, bundleDts, debounce, fsExists, fsRemove, getTempDtsDir, lowestCommonAncestor, toArray };
@@ -1,6 +0,0 @@
1
-
2
- //#region package.json
3
- var version = "0.8.0-beta.1";
4
-
5
- //#endregion
6
- export { version };
File without changes