tsdown 0.2.4 → 0.2.6

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,2 +1,2 @@
1
- import type { Options } from '../options';
2
- export declare function resolveEntry(entry: Options['entry']): Promise<string[] | Record<string, string>>;
1
+ import type { Options } from "../options";
2
+ export declare function resolveEntry(entry: Options["entry"]): Promise<string[] | Record<string, string>>;
@@ -1,6 +1,6 @@
1
- import type { ResolvedOptions } from '../options';
2
- import type { PackageJson } from 'pkg-types';
3
- import type { InputOptions, Plugin } from 'rolldown';
4
- export type External = InputOptions['external'];
5
- export declare function ExternalPlugin(pkg: PackageJson | undefined, platform: ResolvedOptions['platform']): Plugin;
1
+ import type { ResolvedOptions } from "../options";
2
+ import type { PackageJson } from "pkg-types";
3
+ import type { InputOptions, Plugin } from "rolldown";
4
+ export type External = InputOptions["external"];
5
+ export declare function ExternalPlugin(pkg: PackageJson | undefined, platform: ResolvedOptions["platform"]): Plugin;
6
6
  export declare function getProductionDeps(pkg: PackageJson): Set<string>;
@@ -1,2 +1,2 @@
1
- import type { Format } from '../options';
2
- export declare function resolveOutputExtension(pkg: any, format: Format): 'mjs' | 'cjs' | 'js';
1
+ import type { Format } from "../options";
2
+ export declare function resolveOutputExtension(pkg: any, format: Format): "mjs" | "cjs" | "js";
@@ -1,2 +1,2 @@
1
- import type { ResolvedOptions } from '../options';
1
+ import type { ResolvedOptions } from "../options";
2
2
  export declare function watchBuild(options: ResolvedOptions, rebuild: () => void): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { type Options, type OptionsWithoutConfig } from './options';
1
+ import { type Options, type OptionsWithoutConfig } from "./options";
2
2
  export declare function build(userOptions?: Options): Promise<void>;
3
3
  export declare function defineConfig(options: OptionsWithoutConfig): OptionsWithoutConfig;
4
+ export type { Options, OptionsWithoutConfig };
package/dist/index.js CHANGED
@@ -144,7 +144,7 @@ async function normalizeOptions(options) {
144
144
  ...await loadConfigFile(options),
145
145
  ...options
146
146
  };
147
- let { entry, format = ["es"], plugins = [], external = [], clean = false, treeshake = true, platform = "node", outDir = "dist", dts = false, alias = {}, watch = false } = options;
147
+ let { entry, format = ["es"], plugins = [], external, clean = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, minify, alias, watch = false, inputOptions, outputOptions } = options;
148
148
  entry = await resolveEntry(entry);
149
149
  format = toArray(format, "es");
150
150
  if (clean === true) clean = [];
@@ -158,8 +158,12 @@ async function normalizeOptions(options) {
158
158
  alias,
159
159
  treeshake,
160
160
  platform,
161
+ sourcemap,
161
162
  dts,
162
- watch
163
+ minify,
164
+ watch,
165
+ inputOptions,
166
+ outputOptions
163
167
  };
164
168
  }
165
169
  async function loadConfigFile(options) {
@@ -203,7 +207,7 @@ async function loadConfigFile(options) {
203
207
  //#region src/index.ts
204
208
  async function build(userOptions = {}) {
205
209
  const resolved = await normalizeOptions(userOptions);
206
- const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, dts, watch } = resolved;
210
+ const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch } = resolved;
207
211
  if (clean) await cleanOutDir(outDir, clean);
208
212
  const pkg = await readPackageJson(process.cwd());
209
213
  let startTime = performance.now();
@@ -212,7 +216,8 @@ async function build(userOptions = {}) {
212
216
  external,
213
217
  resolve: { alias },
214
218
  treeshake,
215
- plugins: [ExternalPlugin(pkg, platform), dts && IsolatedDecl.rolldown(dts === true ? {} : dts), ...plugins,].filter((plugin) => !!plugin)
219
+ plugins: [ExternalPlugin(pkg, platform), dts && IsolatedDecl.rolldown(dts === true ? {} : dts), ...plugins,].filter((plugin) => !!plugin),
220
+ ...resolved.inputOptions
216
221
  };
217
222
  const build$1 = await rolldown(inputOptions);
218
223
  await writeBundle(true);
@@ -224,13 +229,20 @@ async function build(userOptions = {}) {
224
229
  }
225
230
  async function writeBundle(first) {
226
231
  if (!first) startTime = performance.now();
227
- await Promise.all(format.map((format$1) => {
232
+ await Promise.all(format.map(async (format$1) => {
228
233
  const extension = resolveOutputExtension(pkg, format$1);
229
- return build$1.write({
234
+ const outputOptions = {
230
235
  format: format$1,
236
+ sourcemap,
231
237
  dir: outDir,
238
+ minify,
232
239
  entryFileNames: `[name].${extension}`,
233
240
  chunkFileNames: `[name]-[hash].${extension}`
241
+ };
242
+ const userOutputOptions = typeof resolved.outputOptions === "function" ? await resolved.outputOptions(outputOptions, format$1) : resolved.outputOptions;
243
+ return await build$1.write({
244
+ ...outputOptions,
245
+ ...userOutputOptions
234
246
  });
235
247
  }));
236
248
  logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
package/dist/options.d.ts CHANGED
@@ -1,26 +1,30 @@
1
- import type { External } from './features/external';
2
- import type { InputOptions } from 'rolldown';
3
- import type { Options as IsolatedDeclOptions } from 'unplugin-isolated-decl';
4
- export type Format = 'es' | 'esm' | 'module' | 'cjs' | 'commonjs';
1
+ import type { External } from "./features/external";
2
+ import type { MarkPartial, MaybePromise, Overwrite } from "./utils/types";
3
+ import type { InputOptions, OutputOptions } from "rolldown";
4
+ import type { Options as IsolatedDeclOptions } from "unplugin-isolated-decl";
5
+ export type Format = "es" | "esm" | "module" | "cjs" | "commonjs";
6
+ export type Sourcemap = boolean | "inline" | "hidden";
5
7
  export interface Options {
6
- entry?: InputOptions['input'];
8
+ entry?: InputOptions["input"];
7
9
  format?: Format | Format[];
8
- plugins?: InputOptions['plugins'];
10
+ plugins?: InputOptions["plugins"];
9
11
  external?: External;
10
12
  outDir?: string;
11
13
  clean?: boolean | string[];
12
14
  config?: boolean | string;
15
+ sourcemap?: Sourcemap;
13
16
  alias?: Record<string, string>;
14
17
  treeshake?: boolean;
15
- platform?: 'node' | 'neutral';
18
+ minify?: boolean;
19
+ platform?: "node" | "neutral";
16
20
  dts?: boolean | IsolatedDeclOptions;
17
21
  watch?: boolean | string | string[];
22
+ inputOptions?: InputOptions;
23
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: Format) => MaybePromise<OutputOptions | void | null>);
18
24
  }
19
- export type OptionsWithoutConfig = Omit<Options, 'config'>;
20
- type Overwrite<T, U> = { [P in Exclude<keyof T, keyof U>] : T[P]} & U;
21
- export type ResolvedOptions = Omit<Overwrite<Required<Options>, {
25
+ export type OptionsWithoutConfig = Omit<Options, "config">;
26
+ export type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "inputOptions" | "outputOptions" | "minify" | "alias" | "external">, {
22
27
  format: Format[];
23
28
  clean: string[] | false;
24
- }>, 'config'>;
29
+ }>, "config">;
25
30
  export declare function normalizeOptions(options: Options): Promise<ResolvedOptions>;
26
- export {};
package/dist/plugins.d.ts CHANGED
@@ -1 +1 @@
1
- export { ExternalPlugin } from './features/external';
1
+ export { ExternalPlugin } from "./features/external";
package/dist/run.d.ts CHANGED
@@ -0,0 +1 @@
1
+ export {};
package/dist/run.js CHANGED
@@ -3,13 +3,13 @@ import { default as process } from "node:process";
3
3
  import { cac } from "cac";
4
4
 
5
5
  //#region package.json
6
- const version = "0.2.4";
6
+ const version = "0.2.6";
7
7
 
8
8
  //#endregion
9
9
  //#region src/cli.ts
10
10
  async function runCLI() {
11
11
  const cli = cac("tsdown");
12
- 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("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--platform <platform>", "Target platform", { default: "node" }).option("--watch", "Watch mode").action(async (input, flags) => {
12
+ 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("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--watch", "Watch mode").action(async (input, flags) => {
13
13
  logger.info(`tsdown v${version}`);
14
14
  const { build } = await import("./index.js");
15
15
  if (input.length > 0) flags.entry = input;
@@ -1,2 +1,2 @@
1
- import { type ConsolaInstance } from 'consola';
1
+ import { type ConsolaInstance } from "consola";
2
2
  export declare const logger: ConsolaInstance;
@@ -1,3 +1,3 @@
1
- import { type PackageJson } from 'pkg-types';
1
+ import { type PackageJson } from "pkg-types";
2
2
  export declare function readPackageJson(dir: string): Promise<PackageJson | undefined>;
3
- export declare function getPackageType(pkg: PackageJson | undefined): 'module' | 'commonjs';
3
+ export declare function getPackageType(pkg: PackageJson | undefined): "module" | "commonjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "An even faster bundler powered by Rolldown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,19 +46,19 @@
46
46
  "pkg-types": "^1.1.3",
47
47
  "rolldown": "nightly",
48
48
  "unconfig": "^0.5.5",
49
- "unplugin-isolated-decl": "^0.4.1"
49
+ "unplugin-isolated-decl": "^0.4.5"
50
50
  },
51
51
  "devDependencies": {
52
- "@sxzz/eslint-config": "^3.16.3",
52
+ "@sxzz/eslint-config": "^3.17.0",
53
53
  "@sxzz/prettier-config": "^2.0.2",
54
- "@types/node": "^20.14.14",
54
+ "@types/node": "^20.14.15",
55
55
  "bumpp": "^9.4.2",
56
- "eslint": "^9.8.0",
56
+ "eslint": "^9.9.0",
57
57
  "execa": "^9.3.0",
58
58
  "fdir": "^6.2.0",
59
59
  "prettier": "^3.3.3",
60
60
  "tsup": "^8.2.4",
61
- "tsx": "^4.16.5",
61
+ "tsx": "^4.17.0",
62
62
  "typescript": "~5.5.4",
63
63
  "vitest": "^2.0.5"
64
64
  },