tsdown 0.5.3 → 0.5.5

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.
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/config.ts
3
+ function defineConfig(options) {
4
+ return options;
5
+ }
6
+
7
+ //#endregion
8
+ export { defineConfig };
@@ -0,0 +1,77 @@
1
+ import { E as External } from './plugins.d-DtLTz4jh.js';
2
+ import { InputOptions, ModuleFormat, OutputOptions, InternalModuleFormat } from 'rolldown';
3
+ import { Options as Options$1 } from 'unplugin-isolated-decl';
4
+ import { Options as Options$2 } from 'unplugin-unused';
5
+
6
+ type Overwrite<
7
+ T,
8
+ U
9
+ > = Omit<T, keyof U> & U;
10
+ type MaybePromise<T> = T | Promise<T>;
11
+ type MarkPartial<
12
+ T,
13
+ K extends keyof T
14
+ > = Omit<Required<T>, K> & Partial<Pick<T, K>>;
15
+ type Arrayable<T> = T | T[];
16
+
17
+ type Sourcemap = boolean | "inline" | "hidden";
18
+ /**
19
+ * Options for tsdown.
20
+ */
21
+ interface Options {
22
+ entry?: InputOptions["input"];
23
+ format?: ModuleFormat | ModuleFormat[];
24
+ globalName?: string;
25
+ plugins?: InputOptions["plugins"];
26
+ external?: External;
27
+ outDir?: string;
28
+ clean?: boolean | string[];
29
+ silent?: boolean;
30
+ config?: boolean | string;
31
+ sourcemap?: Sourcemap;
32
+ alias?: Record<string, string>;
33
+ /** @default true */
34
+ treeshake?: boolean;
35
+ /** @default false */
36
+ minify?: boolean;
37
+ target?: string | string[];
38
+ define?: Record<string, string>;
39
+ /** @default 'node' */
40
+ platform?: "node" | "neutral" | "browser";
41
+ shims?: boolean;
42
+ /**
43
+ * Enable dts generation with `isolatedDeclarations` (experimental)
44
+ */
45
+ dts?: boolean | Options$1;
46
+ /** @default true */
47
+ bundleDts?: boolean;
48
+ /**
49
+ * Enable unused dependencies check with `unplugin-unused` (experimental)
50
+ */
51
+ unused?: boolean | Options$2;
52
+ watch?: boolean | string | string[];
53
+ inputOptions?: InputOptions | ((options: InputOptions, format: ModuleFormat) => MaybePromise<InputOptions | void | null>);
54
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: ModuleFormat) => MaybePromise<OutputOptions | void | null>);
55
+ onSuccess?: () => void | Promise<void>;
56
+ /**
57
+ * Skip bundling node_modules.
58
+ */
59
+ skipNodeModulesBundle?: boolean;
60
+ }
61
+ /**
62
+ * Options without specifying config file path.
63
+ */
64
+ type Config = Arrayable<Omit<Options, "config">>;
65
+ type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
66
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "onSuccess" | "dts">, {
67
+ format: NormalizedFormat[];
68
+ clean: string[] | false;
69
+ dts: false | Options$1;
70
+ }>, "config">;
71
+
72
+ /**
73
+ * Defines the configuration for tsdown.
74
+ */
75
+ declare function defineConfig(options: Config): Config;
76
+
77
+ export { type Config as C, type Options as O, type ResolvedOptions as R, defineConfig as d };
@@ -0,0 +1,6 @@
1
+ export { d as defineConfig } from './config.d-DWijXKYW.js';
2
+ import './plugins.d-DtLTz4jh.js';
3
+ import 'pkg-types';
4
+ import 'rolldown';
5
+ import 'unplugin-isolated-decl';
6
+ import 'unplugin-unused';
package/dist/config.js ADDED
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from "./config-0LDjKwZ7.js";
2
+
3
+ export { defineConfig };
@@ -0,0 +1,33 @@
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 };
package/dist/index.d.ts CHANGED
@@ -1,75 +1,11 @@
1
- import { E as External } from './plugins.d-CKHmQhmh.js';
2
- import { InputOptions, ModuleFormat, OutputOptions, InternalModuleFormat } from 'rolldown';
3
- import { Options as Options$1 } from 'unplugin-isolated-decl';
4
- import { Options as Options$2 } from 'unplugin-unused';
1
+ import { O as Options, R as ResolvedOptions } from './config.d-DWijXKYW.js';
2
+ export { C as Config, d as defineConfig } from './config.d-DWijXKYW.js';
5
3
  import { ConsolaInstance } from 'consola';
4
+ import './plugins.d-DtLTz4jh.js';
6
5
  import 'pkg-types';
7
-
8
- type Overwrite<
9
- T,
10
- U
11
- > = Omit<T, keyof U> & U;
12
- type MaybePromise<T> = T | Promise<T>;
13
- type MarkPartial<
14
- T,
15
- K extends keyof T
16
- > = Omit<Required<T>, K> & Partial<Pick<T, K>>;
17
- type Arrayable<T> = T | T[];
18
-
19
- type Sourcemap = boolean | "inline" | "hidden";
20
- /**
21
- * Options for tsdown.
22
- */
23
- interface Options {
24
- entry?: InputOptions["input"];
25
- format?: ModuleFormat | ModuleFormat[];
26
- globalName?: string;
27
- plugins?: InputOptions["plugins"];
28
- external?: External;
29
- outDir?: string;
30
- clean?: boolean | string[];
31
- silent?: boolean;
32
- config?: boolean | string;
33
- sourcemap?: Sourcemap;
34
- alias?: Record<string, string>;
35
- /** @default true */
36
- treeshake?: boolean;
37
- /** @default false */
38
- minify?: boolean;
39
- target?: string | string[];
40
- define?: Record<string, string>;
41
- /** @default 'node' */
42
- platform?: "node" | "neutral" | "browser";
43
- shims?: boolean;
44
- /**
45
- * Enable dts generation with `isolatedDeclarations` (experimental)
46
- */
47
- dts?: boolean | Options$1;
48
- /** @default true */
49
- bundleDts?: boolean;
50
- /**
51
- * Enable unused dependencies check with `unplugin-unused` (experimental)
52
- */
53
- unused?: boolean | Options$2;
54
- 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
- onSuccess?: () => void | Promise<void>;
58
- /**
59
- * Skip bundling node_modules.
60
- */
61
- skipNodeModulesBundle?: boolean;
62
- }
63
- /**
64
- * Options without specifying config file path.
65
- */
66
- type Config = Arrayable<Omit<Options, "config">>;
67
- type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
68
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "onSuccess" | "dts">, {
69
- format: NormalizedFormat[];
70
- clean: string[] | false;
71
- dts: false | Options$1;
72
- }>, "config">;
6
+ import 'rolldown';
7
+ import 'unplugin-isolated-decl';
8
+ import 'unplugin-unused';
73
9
 
74
10
  /**
75
11
  * Logger instance
@@ -79,7 +15,7 @@ declare const logger: ConsolaInstance;
79
15
  /**
80
16
  * Build with tsdown.
81
17
  */
82
- declare function build(userOptions?: Omit<Options, "silent">): Promise<void>;
18
+ declare function build(userOptions?: Options): Promise<void>;
83
19
  declare const pkgRoot: string;
84
20
  /**
85
21
  * Build a single configuration, without watch and shortcuts features.
@@ -87,9 +23,5 @@ declare const pkgRoot: string;
87
23
  * @param resolved Resolved options
88
24
  */
89
25
  declare function buildSingle(resolved: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
90
- /**
91
- * Defines the configuration for tsdown.
92
- */
93
- declare function defineConfig(options: Config): Config;
94
26
 
95
- export { type Config, type Options, build, buildSingle, defineConfig, logger, pkgRoot };
27
+ export { Options, build, buildSingle, logger, pkgRoot };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { debug, logger } from "./logger-Pk57TMWT.js";
2
- import { ExternalPlugin } from "./external-9r3oq3tH.js";
1
+ import { defineConfig } from "./config-0LDjKwZ7.js";
2
+ import { debug, logger, setSilent } from "./logger-BV85twVD.js";
3
+ import { ExternalPlugin } from "./external-QIv-o_HK.js";
3
4
  import path, { dirname, normalize, sep } from "node:path";
4
5
  import process from "node:process";
5
6
  import { fileURLToPath } from "node:url";
@@ -8,6 +9,7 @@ import { transformPlugin } from "rolldown/experimental";
8
9
  import { IsolatedDecl } from "unplugin-isolated-decl";
9
10
  import { Unused } from "unplugin-unused";
10
11
  import { access, readdir, rm, stat } from "node:fs/promises";
12
+ import Debug from "debug";
11
13
  import { glob } from "tinyglobby";
12
14
  import { rollup } from "rollup";
13
15
  import DtsPlugin from "rollup-plugin-dts";
@@ -47,6 +49,7 @@ else {
47
49
 
48
50
  //#endregion
49
51
  //#region src/features/clean.ts
52
+ const debug$1 = Debug("tsdown:clean");
50
53
  async function cleanOutDir(cwd, patterns) {
51
54
  const files = [];
52
55
  if (await fsExists(cwd)) files.push(...(await readdir(cwd)).map((file) => path.resolve(cwd, file)));
@@ -56,7 +59,7 @@ async function cleanOutDir(cwd, patterns) {
56
59
  }));
57
60
  logger.info("Cleaning output folder");
58
61
  for (const file of files) {
59
- debug("[clean]", "Removing", file);
62
+ debug$1("Removing", file);
60
63
  await fsRemove(file);
61
64
  }
62
65
  }
@@ -295,6 +298,7 @@ function normalizeFormat(format) {
295
298
  }
296
299
  });
297
300
  }
301
+ let loaded = false;
298
302
  async function loadConfigFile(options) {
299
303
  let { config: filePath } = options;
300
304
  if (filePath === false) return [[]];
@@ -309,6 +313,7 @@ async function loadConfigFile(options) {
309
313
  cwd = path.dirname(filePath);
310
314
  } else cwd = resolved;
311
315
  }
316
+ const nativeLoader = !loaded && process.features.typescript;
312
317
  const { config, sources } = await loadConfig({
313
318
  sources: overrideConfig ? [{
314
319
  files: filePath,
@@ -332,8 +337,12 @@ async function loadConfigFile(options) {
332
337
  }],
333
338
  cwd,
334
339
  defaults: {},
335
- importx: { loader: "bundle-require" }
336
- });
340
+ importx: {
341
+ loader: nativeLoader ? "native" : "bundle-require",
342
+ fallbackLoaders: [...nativeLoader ? ["bundle-require"] : [], "jiti"],
343
+ cache: loaded ? false : null
344
+ }
345
+ }).finally(() => loaded = true);
337
346
  if (sources.length > 0) logger.info(`Using tsdown config: ${pc.underline(sources.join(", "))}`);
338
347
  const file = sources[0];
339
348
  return [toArray(config), file];
@@ -349,6 +358,7 @@ async function mergeUserOptions(defaults, user, args) {
349
358
  //#endregion
350
359
  //#region src/index.ts
351
360
  async function build(userOptions = {}) {
361
+ typeof userOptions.silent === "boolean" && setSilent(userOptions.silent);
352
362
  debug("Loading config");
353
363
  const [resolveds, configFile] = await resolveOptions(userOptions);
354
364
  if (configFile) debug("Loaded config:", configFile);
@@ -386,7 +396,7 @@ async function buildSingle(resolved) {
386
396
  platform,
387
397
  define,
388
398
  plugins: [
389
- pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
399
+ (pkg || resolved.skipNodeModulesBundle) && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
390
400
  unused && Unused.rolldown(unused === true ? {} : unused),
391
401
  dts && IsolatedDecl.rolldown({
392
402
  ...dts,
@@ -417,9 +427,6 @@ async function buildSingle(resolved) {
417
427
  await onSuccess?.();
418
428
  }
419
429
  }
420
- function defineConfig(options) {
421
- return options;
422
- }
423
430
 
424
431
  //#endregion
425
432
  export { build, buildSingle, defineConfig, logger, pkgRoot };
@@ -1,9 +1,13 @@
1
- import { consola } from "consola";
1
+ import process from "node:process";
2
2
  import Debug from "debug";
3
+ import { consola } from "consola";
3
4
 
4
5
  //#region src/utils/logger.ts
5
6
  const logger = consola.withTag("tsdown");
6
7
  const debug = Debug("tsdown");
8
+ function setSilent(silent) {
9
+ if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
10
+ }
7
11
 
8
12
  //#endregion
9
- export { debug, logger };
13
+ export { debug, logger, setSilent };
@@ -2,6 +2,6 @@ import { PackageJson } from 'pkg-types';
2
2
  import { Plugin, InputOptions } from 'rolldown';
3
3
 
4
4
  type External = InputOptions["external"];
5
- declare function ExternalPlugin(pkg: PackageJson, skipNodeModulesBundle?: boolean): Plugin;
5
+ declare function ExternalPlugin(pkg?: PackageJson, skipNodeModulesBundle?: boolean): Plugin;
6
6
 
7
7
  export { type External as E, ExternalPlugin as a };
package/dist/plugins.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { a as ExternalPlugin } from './plugins.d-CKHmQhmh.js';
1
+ export { a as ExternalPlugin } from './plugins.d-DtLTz4jh.js';
2
2
  import 'pkg-types';
3
3
  import 'rolldown';
package/dist/plugins.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./logger-Pk57TMWT.js";
2
- import { ExternalPlugin } from "./external-9r3oq3tH.js";
1
+ import { ExternalPlugin } from "./external-QIv-o_HK.js";
3
2
 
4
3
  export { ExternalPlugin };
package/dist/run.js CHANGED
@@ -1,18 +1,18 @@
1
- import { logger } from "./logger-Pk57TMWT.js";
1
+ import { logger, setSilent } from "./logger-BV85twVD.js";
2
2
  import process from "node:process";
3
3
  import { VERSION } from "rolldown";
4
4
  import pc from "picocolors";
5
5
  import { cac } from "cac";
6
6
 
7
7
  //#region package.json
8
- var version = "0.5.3";
8
+ var version = "0.5.5";
9
9
 
10
10
  //#endregion
11
11
  //#region src/cli.ts
12
12
  async function runCLI() {
13
13
  const cli = cac("tsdown");
14
14
  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) => {
15
- if (!("CONSOLA_LEVEL" in process.env)) logger.level = flags.silent ? 0 : 3;
15
+ setSilent(!!flags.silent);
16
16
  logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${VERSION}`)}`);
17
17
  const { build: build$1 } = await import("./index.js");
18
18
  if (input.length > 0) flags.entry = input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "An even faster bundler powered by Rolldown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,6 +22,7 @@
22
22
  "types": "./dist/index.d.ts",
23
23
  "exports": {
24
24
  ".": "./dist/index.js",
25
+ "./config": "./dist/config.js",
25
26
  "./plugins": "./dist/plugins.js",
26
27
  "./package.json": "./package.json"
27
28
  },
@@ -42,34 +43,34 @@
42
43
  "dependencies": {
43
44
  "cac": "^6.7.14",
44
45
  "chokidar": "^4.0.3",
45
- "consola": "^3.3.3",
46
+ "consola": "^3.4.0",
46
47
  "debug": "^4.4.0",
47
48
  "picocolors": "^1.1.1",
48
- "pkg-types": "^1.3.0",
49
+ "pkg-types": "^1.3.1",
49
50
  "rolldown": "^1.0.0-beta.1",
50
- "rollup": "^4.29.1",
51
+ "rollup": "^4.31.0",
51
52
  "rollup-plugin-dts": "^6.1.1",
52
53
  "tinyglobby": "^0.2.10",
53
- "unconfig": "^0.6.0",
54
- "unplugin-isolated-decl": "^0.10.3",
54
+ "unconfig": "^0.6.1",
55
+ "unplugin-isolated-decl": "^0.10.5",
55
56
  "unplugin-unused": "^0.3.0"
56
57
  },
57
58
  "devDependencies": {
58
- "@sxzz/eslint-config": "^4.5.1",
59
- "@sxzz/prettier-config": "^2.0.2",
60
- "@sxzz/test-utils": "^0.3.11",
59
+ "@sxzz/eslint-config": "^4.6.0",
60
+ "@sxzz/prettier-config": "^2.1.0",
61
+ "@sxzz/test-utils": "^0.4.0",
61
62
  "@types/debug": "^4.1.12",
62
- "@types/node": "^22.10.2",
63
- "bumpp": "^9.9.2",
64
- "eslint": "^9.17.0",
65
- "oxc-transform": "^0.44.0",
63
+ "@types/node": "^22.10.7",
64
+ "bumpp": "^9.10.1",
65
+ "eslint": "^9.18.0",
66
+ "oxc-transform": "^0.47.1",
66
67
  "prettier": "^3.4.2",
67
68
  "tinyexec": "^0.3.2",
68
69
  "tsup": "^8.3.5",
69
70
  "tsx": "^4.19.2",
70
- "typescript": "~5.7.2",
71
+ "typescript": "~5.7.3",
71
72
  "unplugin-ast": "^0.13.1",
72
- "vitest": "^3.0.0-beta.3"
73
+ "vitest": "^3.0.2"
73
74
  },
74
75
  "engines": {
75
76
  "node": ">=18.0.0"
@@ -1,28 +0,0 @@
1
- import { debug } from "./logger-Pk57TMWT.js";
2
- import path from "node:path";
3
-
4
- //#region src/features/external.ts
5
- function ExternalPlugin(pkg, skipNodeModulesBundle) {
6
- const deps = Array.from(getProductionDeps(pkg));
7
- return {
8
- name: "tsdown:external",
9
- resolveId(id, importer, { isEntry }) {
10
- if (isEntry) return;
11
- let shouldExternal = skipNodeModulesBundle && !path.isAbsolute(id) && id[0] !== ".";
12
- shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
13
- if (shouldExternal) {
14
- debug("[external]", "External dependency:", id);
15
- return {
16
- id,
17
- external: true
18
- };
19
- }
20
- }
21
- };
22
- }
23
- function getProductionDeps(pkg) {
24
- return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
25
- }
26
-
27
- //#endregion
28
- export { ExternalPlugin };