tsdown 0.9.5 → 0.9.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.
- package/dist/{config.d-_qPbb_88.d.ts → config.d-DOpadTUl.d.ts} +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -5
- package/dist/{migrate-C2JwD44Q.js → migrate-B7KTdsUd.js} +1 -1
- package/dist/{options.d-v--gMr_a.d.ts → options.d-VgsCNgLk.d.ts} +27 -6
- package/dist/package-B1O-I_4B.js +5 -0
- package/dist/{plugins-x9xHcxDm.js → plugins-DU1CCXkW.js} +39 -23
- package/dist/plugins.d.ts +1 -5
- package/dist/plugins.js +1 -1
- package/dist/run.js +2 -2
- package/package.json +2 -2
- package/dist/package-CIVaynpa.js +0 -5
package/dist/config.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig } from "./options.d-
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config.d-
|
|
1
|
+
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig } from "./options.d-VgsCNgLk.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config.d-DOpadTUl.js";
|
|
3
3
|
import Debug from "debug";
|
|
4
4
|
import { ConsolaInstance } from "consola";
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "./config-yiJy1jd0.js";
|
|
2
|
-
import { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray } from "./plugins-
|
|
2
|
+
import { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson, resolveComma, toArray } from "./plugins-DU1CCXkW.js";
|
|
3
3
|
import { debug, logger, setSilent } from "./logger-Dt3D6T-U.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
@@ -238,7 +238,7 @@ async function resolveOptions(options) {
|
|
|
238
238
|
...subConfig,
|
|
239
239
|
...options
|
|
240
240
|
};
|
|
241
|
-
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, tsconfig, report = true } = subOptions;
|
|
241
|
+
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, tsconfig, report = true, target } = subOptions;
|
|
242
242
|
entry = await resolveEntry(entry, cwd);
|
|
243
243
|
if (clean === true) clean = [];
|
|
244
244
|
if (publint$1 === true) publint$1 = {};
|
|
@@ -274,6 +274,7 @@ async function resolveOptions(options) {
|
|
|
274
274
|
entry,
|
|
275
275
|
plugins,
|
|
276
276
|
format: normalizeFormat(format),
|
|
277
|
+
target: target ? resolveComma(toArray(target)) : void 0,
|
|
277
278
|
outDir: path.resolve(outDir),
|
|
278
279
|
clean,
|
|
279
280
|
silent,
|
|
@@ -281,6 +282,7 @@ async function resolveOptions(options) {
|
|
|
281
282
|
platform,
|
|
282
283
|
sourcemap,
|
|
283
284
|
dts: dts === true ? {} : dts,
|
|
285
|
+
report: report === true ? {} : report,
|
|
284
286
|
unused,
|
|
285
287
|
watch,
|
|
286
288
|
shims,
|
|
@@ -288,8 +290,7 @@ async function resolveOptions(options) {
|
|
|
288
290
|
publint: publint$1,
|
|
289
291
|
alias,
|
|
290
292
|
tsconfig,
|
|
291
|
-
cwd
|
|
292
|
-
report
|
|
293
|
+
cwd
|
|
293
294
|
};
|
|
294
295
|
return config;
|
|
295
296
|
}));
|
|
@@ -438,6 +439,8 @@ async function buildSingle(config) {
|
|
|
438
439
|
let hasErrors = false;
|
|
439
440
|
await Promise.all(formats.map(async (format) => {
|
|
440
441
|
try {
|
|
442
|
+
const formatLabel = prettyFormat(format);
|
|
443
|
+
logger.info(formatLabel, "Build start");
|
|
441
444
|
const buildOptions = await getBuildOptions(config, pkg, format);
|
|
442
445
|
await hooks.callHook("build:before", {
|
|
443
446
|
...context,
|
|
@@ -499,7 +502,7 @@ async function getBuildOptions(config, pkg, format, cjsDts) {
|
|
|
499
502
|
}));
|
|
500
503
|
plugins.push(ShebangPlugin(cwd));
|
|
501
504
|
}
|
|
502
|
-
if (report) plugins.push(ReportPlugin(cwd, cjsDts));
|
|
505
|
+
if (report) plugins.push(ReportPlugin(report, cwd, cjsDts));
|
|
503
506
|
plugins.push(userPlugins);
|
|
504
507
|
const inputOptions = await mergeUserOptions({
|
|
505
508
|
input: entry,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions } from "rolldown";
|
|
1
|
+
import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions, Plugin } from "rolldown";
|
|
2
2
|
import { Hookable } from "hookable";
|
|
3
3
|
import { Options } from "publint";
|
|
4
4
|
import { Options as Options$1 } from "rolldown-plugin-dts";
|
|
@@ -54,6 +54,24 @@ interface OutExtensionObject {
|
|
|
54
54
|
}
|
|
55
55
|
type OutExtensionFactory = (ctx: OutExtensionContext) => OutExtensionObject;
|
|
56
56
|
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/features/report.d.ts
|
|
59
|
+
interface ReportOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Enable/disable brotli-compressed size reporting.
|
|
62
|
+
* Compressing large output files can be slow, so disabling this may increase build performance for large projects.
|
|
63
|
+
*
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
brotli?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Skip reporting compressed size for files larger than this size.
|
|
69
|
+
* @default 1_000_000 // 1MB
|
|
70
|
+
*/
|
|
71
|
+
maxCompressSize?: number;
|
|
72
|
+
}
|
|
73
|
+
declare function ReportPlugin(options: ReportOptions, cwd: string, cjsDts?: boolean): Plugin;
|
|
74
|
+
|
|
57
75
|
//#endregion
|
|
58
76
|
//#region src/utils/types.d.ts
|
|
59
77
|
type Overwrite<
|
|
@@ -70,6 +88,8 @@ type Arrayable<T> = T | T[];
|
|
|
70
88
|
//#endregion
|
|
71
89
|
//#region src/options.d.ts
|
|
72
90
|
type Sourcemap = boolean | "inline" | "hidden";
|
|
91
|
+
type Format = Exclude<ModuleFormat, "experimental-app">;
|
|
92
|
+
type NormalizedFormat = Exclude<InternalModuleFormat, "app">;
|
|
73
93
|
/**
|
|
74
94
|
* Options for tsdown.
|
|
75
95
|
*/
|
|
@@ -83,7 +103,7 @@ interface Options$3 {
|
|
|
83
103
|
platform?: "node" | "neutral" | "browser";
|
|
84
104
|
inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat) => Awaitable<InputOptions | void | null>);
|
|
85
105
|
/** @default 'es' */
|
|
86
|
-
format?:
|
|
106
|
+
format?: Format | Format[];
|
|
87
107
|
globalName?: string;
|
|
88
108
|
/** @default 'dist' */
|
|
89
109
|
outDir?: string;
|
|
@@ -148,21 +168,22 @@ interface Options$3 {
|
|
|
148
168
|
* Enable size reporting after bundling.
|
|
149
169
|
* @default true
|
|
150
170
|
*/
|
|
151
|
-
report?: boolean;
|
|
171
|
+
report?: boolean | ReportOptions;
|
|
152
172
|
hooks?: Partial<TsdownHooks> | ((hooks: Hookable<TsdownHooks>) => Awaitable<void>);
|
|
153
173
|
}
|
|
154
174
|
/**
|
|
155
175
|
* Options without specifying config file path.
|
|
156
176
|
*/
|
|
157
177
|
type UserConfig = Arrayable<Omit<Options$3, "config">>;
|
|
158
|
-
type
|
|
159
|
-
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension" | "outExtensions" | "hooks">, {
|
|
178
|
+
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks">, {
|
|
160
179
|
format: NormalizedFormat[]
|
|
180
|
+
target?: string[]
|
|
161
181
|
clean: string[] | false
|
|
162
182
|
dts: false | Options$1
|
|
183
|
+
report: false | ReportOptions
|
|
163
184
|
tsconfig: string | false
|
|
164
185
|
cwd: string
|
|
165
186
|
}>, "config" | "fromVite">;
|
|
166
187
|
|
|
167
188
|
//#endregion
|
|
168
|
-
export { BuildContext, Options$3 as Options, ResolvedOptions, TsdownHooks, UserConfig };
|
|
189
|
+
export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownHooks, UserConfig };
|
|
@@ -46,6 +46,9 @@ function toArray(val, defaultValue) {
|
|
|
46
46
|
return [];
|
|
47
47
|
} else return [val];
|
|
48
48
|
}
|
|
49
|
+
function resolveComma(arr) {
|
|
50
|
+
return arr.flatMap((format) => format.split(","));
|
|
51
|
+
}
|
|
49
52
|
function debounce(fn, wait) {
|
|
50
53
|
let timeout;
|
|
51
54
|
return function(...args) {
|
|
@@ -56,6 +59,7 @@ function debounce(fn, wait) {
|
|
|
56
59
|
}, wait);
|
|
57
60
|
};
|
|
58
61
|
}
|
|
62
|
+
const noop = (v) => v;
|
|
59
63
|
|
|
60
64
|
//#endregion
|
|
61
65
|
//#region src/features/external.ts
|
|
@@ -113,7 +117,7 @@ function getPackageType(pkg) {
|
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
function normalizeFormat(format) {
|
|
116
|
-
return toArray(format, "es").map((format$1) => {
|
|
120
|
+
return resolveComma(toArray(format, "es")).map((format$1) => {
|
|
117
121
|
switch (format$1) {
|
|
118
122
|
case "es":
|
|
119
123
|
case "esm":
|
|
@@ -125,18 +129,23 @@ function normalizeFormat(format) {
|
|
|
125
129
|
});
|
|
126
130
|
}
|
|
127
131
|
function prettyFormat(format) {
|
|
132
|
+
const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
|
|
133
|
+
let formatText;
|
|
128
134
|
switch (format) {
|
|
129
|
-
case "es":
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
case "es":
|
|
136
|
+
formatText = "ESM";
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
formatText = format.toUpperCase();
|
|
140
|
+
break;
|
|
134
141
|
}
|
|
142
|
+
return formatColor(`[${formatText}]`);
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
//#endregion
|
|
138
146
|
//#region src/utils/format.ts
|
|
139
147
|
function formatBytes(bytes) {
|
|
148
|
+
if (bytes === Infinity) return "too large";
|
|
140
149
|
const numberFormatter = new Intl.NumberFormat("en", {
|
|
141
150
|
maximumFractionDigits: 2,
|
|
142
151
|
minimumFractionDigits: 2
|
|
@@ -147,18 +156,17 @@ function formatBytes(bytes) {
|
|
|
147
156
|
//#endregion
|
|
148
157
|
//#region src/features/report.ts
|
|
149
158
|
const debug$1 = Debug("tsdown:report");
|
|
150
|
-
const noop = (v) => v;
|
|
151
159
|
const brotliCompressAsync = promisify(brotliCompress);
|
|
152
160
|
const gzipAsync = promisify(gzip);
|
|
153
161
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
154
|
-
function ReportPlugin(cwd, cjsDts) {
|
|
162
|
+
function ReportPlugin(options, cwd, cjsDts) {
|
|
155
163
|
return {
|
|
156
164
|
name: "tsdown:report",
|
|
157
|
-
async writeBundle(
|
|
158
|
-
const outDir = path.relative(cwd,
|
|
165
|
+
async writeBundle(outputOptions, bundle) {
|
|
166
|
+
const outDir = path.relative(cwd, outputOptions.file ? path.resolve(cwd, outputOptions.file, "..") : path.resolve(cwd, outputOptions.dir));
|
|
159
167
|
const sizes = [];
|
|
160
168
|
for (const chunk of Object.values(bundle)) {
|
|
161
|
-
const size = await calcSize(chunk);
|
|
169
|
+
const size = await calcSize(options, chunk);
|
|
162
170
|
sizes.push(size);
|
|
163
171
|
}
|
|
164
172
|
const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
|
|
@@ -175,26 +183,34 @@ function ReportPlugin(cwd, cjsDts) {
|
|
|
175
183
|
sizes.sort((a, b) => {
|
|
176
184
|
if (a.dts !== b.dts) return a.dts ? 1 : -1;
|
|
177
185
|
if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
|
|
178
|
-
return b.
|
|
186
|
+
return b.raw - a.raw;
|
|
179
187
|
});
|
|
180
|
-
const
|
|
181
|
-
const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
|
|
182
|
-
const formatText = formatColor(`[${prettyFormat(format)}]`);
|
|
188
|
+
const formatLabel = prettyFormat(cjsDts ? "cjs" : outputOptions.format);
|
|
183
189
|
for (const size of sizes) {
|
|
184
190
|
const filenameColor = size.dts ? green : noop;
|
|
185
|
-
logger.info(
|
|
191
|
+
logger.info(formatLabel, dim(`${outDir}/`) + filenameColor((size.isEntry ? bold : noop)(size.filename)), ` `.repeat(filenameLength - size.filename.length), dim`${size.rawText} │ gzip: ${size.gzipText}`, options.brotli ? dim` │ brotli: ${size.brotliText}` : "");
|
|
186
192
|
}
|
|
187
193
|
const totalSizeText = formatBytes(totalRaw);
|
|
188
|
-
logger.info(
|
|
194
|
+
logger.info(formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
|
|
189
195
|
}
|
|
190
196
|
};
|
|
191
197
|
}
|
|
192
|
-
async function calcSize(chunk) {
|
|
193
|
-
debug$1(`Calculating size for
|
|
198
|
+
async function calcSize(options, chunk) {
|
|
199
|
+
debug$1(`Calculating size for`, chunk.fileName);
|
|
194
200
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
195
201
|
const raw = Buffer.byteLength(content, "utf8");
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
debug$1("[size]", chunk.fileName, raw);
|
|
203
|
+
let gzip$1 = Infinity;
|
|
204
|
+
let brotli = Infinity;
|
|
205
|
+
if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
206
|
+
else {
|
|
207
|
+
gzip$1 = (await gzipAsync(content)).length;
|
|
208
|
+
debug$1("[gzip]", chunk.fileName, gzip$1);
|
|
209
|
+
if (options.brotli) {
|
|
210
|
+
brotli = (await brotliCompressAsync(content)).length;
|
|
211
|
+
debug$1("[brotli]", chunk.fileName, brotli);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
198
214
|
return {
|
|
199
215
|
filename: chunk.fileName,
|
|
200
216
|
dts: RE_DTS.test(chunk.fileName),
|
|
@@ -220,7 +236,7 @@ function ShebangPlugin(cwd) {
|
|
|
220
236
|
if (!RE_SHEBANG.test(chunk.code)) continue;
|
|
221
237
|
const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
|
|
222
238
|
if (await fsExists(filepath)) {
|
|
223
|
-
logger.info(`Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
|
|
239
|
+
logger.info(prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
|
|
224
240
|
await chmod(filepath, 493);
|
|
225
241
|
}
|
|
226
242
|
}
|
|
@@ -229,4 +245,4 @@ function ShebangPlugin(cwd) {
|
|
|
229
245
|
}
|
|
230
246
|
|
|
231
247
|
//#endregion
|
|
232
|
-
export { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray };
|
|
248
|
+
export { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson, resolveComma, toArray };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedOptions } from "./options.d-
|
|
1
|
+
import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./options.d-VgsCNgLk.js";
|
|
2
2
|
import { Plugin } from "rolldown";
|
|
3
3
|
import { PackageJson } from "pkg-types";
|
|
4
4
|
|
|
@@ -9,9 +9,5 @@ declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Pl
|
|
|
9
9
|
//#region src/features/shebang.d.ts
|
|
10
10
|
declare function ShebangPlugin(cwd: string): Plugin;
|
|
11
11
|
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/features/report.d.ts
|
|
14
|
-
declare function ReportPlugin(cwd: string, cjsDts?: boolean): Plugin;
|
|
15
|
-
|
|
16
12
|
//#endregion
|
|
17
13
|
export { ExternalPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/plugins.js
CHANGED
package/dist/run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { logger, setSilent } from "./logger-Dt3D6T-U.js";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-B1O-I_4B.js";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { dim } from "ansis";
|
|
6
6
|
import { VERSION } from "rolldown";
|
|
@@ -17,7 +17,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
|
|
|
17
17
|
await build$1(flags);
|
|
18
18
|
});
|
|
19
19
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
20
|
-
const { migrate } = await import("./migrate-
|
|
20
|
+
const { migrate } = await import("./migrate-B7KTdsUd.js");
|
|
21
21
|
await migrate(args);
|
|
22
22
|
});
|
|
23
23
|
async function runCLI() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"diff": "^7.0.0",
|
|
63
63
|
"find-up-simple": "^1.0.1",
|
|
64
64
|
"hookable": "^5.5.3",
|
|
65
|
-
"rolldown": "1.0.0-beta.8-commit.
|
|
65
|
+
"rolldown": "1.0.0-beta.8-commit.2686eb1",
|
|
66
66
|
"rolldown-plugin-dts": "^0.8.3",
|
|
67
67
|
"tinyexec": "^1.0.1",
|
|
68
68
|
"tinyglobby": "^0.2.13",
|