tsdown 0.9.5 → 0.9.7
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-jKttq4Nu.d.ts} +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/general-C06aMSSY.js +38 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +37 -18
- package/dist/{migrate-C2JwD44Q.js → migrate-Cr0H4OLK.js} +1 -1
- package/dist/{options.d-v--gMr_a.d.ts → options.d-DVjImwcI.d.ts} +38 -6
- package/dist/package-B5RDOoPA.js +5 -0
- package/dist/{plugins-x9xHcxDm.js → plugins-BcuTSrGE.js} +42 -49
- package/dist/plugins.d.ts +1 -5
- package/dist/plugins.js +2 -2
- package/dist/run.js +18 -4
- package/package.json +3 -3
- package/dist/logger-Dt3D6T-U.js +0 -16
- package/dist/package-CIVaynpa.js +0 -5
package/dist/config.d.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { consola } from "consola";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/logger.ts
|
|
5
|
+
/**
|
|
6
|
+
* Logger instance
|
|
7
|
+
*/
|
|
8
|
+
const logger = consola.withTag("tsdown");
|
|
9
|
+
function setSilent(silent) {
|
|
10
|
+
if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/utils/general.ts
|
|
15
|
+
function toArray(val, defaultValue) {
|
|
16
|
+
if (Array.isArray(val)) return val;
|
|
17
|
+
else if (val == null) {
|
|
18
|
+
if (defaultValue) return [defaultValue];
|
|
19
|
+
return [];
|
|
20
|
+
} else return [val];
|
|
21
|
+
}
|
|
22
|
+
function resolveComma(arr) {
|
|
23
|
+
return arr.flatMap((format) => format.split(","));
|
|
24
|
+
}
|
|
25
|
+
function debounce(fn, wait) {
|
|
26
|
+
let timeout;
|
|
27
|
+
return function(...args) {
|
|
28
|
+
if (timeout) clearTimeout(timeout);
|
|
29
|
+
timeout = setTimeout(() => {
|
|
30
|
+
timeout = void 0;
|
|
31
|
+
fn.apply(this, args);
|
|
32
|
+
}, wait);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const noop = (v) => v;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { debounce, logger, noop, resolveComma, setSilent, toArray };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig } from "./options.d-
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config.d-
|
|
3
|
-
import Debug from "debug";
|
|
1
|
+
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig } from "./options.d-DVjImwcI.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config.d-jKttq4Nu.js";
|
|
4
3
|
import { ConsolaInstance } from "consola";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/logger.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { defineConfig } from "./config-yiJy1jd0.js";
|
|
2
|
-
import { ExternalPlugin, ReportPlugin, ShebangPlugin,
|
|
3
|
-
import {
|
|
2
|
+
import { ExternalPlugin, ReportPlugin, ShebangPlugin, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson } from "./plugins-BcuTSrGE.js";
|
|
3
|
+
import { debounce, logger, resolveComma, setSilent, toArray } from "./general-C06aMSSY.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { blue, bold, dim, green, underline } from "ansis";
|
|
8
|
+
import Debug from "debug";
|
|
8
9
|
import { build as build$1 } from "rolldown";
|
|
9
10
|
import { transformPlugin } from "rolldown/experimental";
|
|
10
11
|
import { exec } from "tinyexec";
|
|
11
12
|
import { readdir, stat } from "node:fs/promises";
|
|
12
|
-
import Debug from "debug";
|
|
13
13
|
import { glob } from "tinyglobby";
|
|
14
14
|
import { createHooks } from "hookable";
|
|
15
|
-
import { findUp } from "find-up-simple";
|
|
16
15
|
import readline from "node:readline";
|
|
17
16
|
import { loadConfig } from "unconfig";
|
|
17
|
+
import { up } from "empathic/find";
|
|
18
18
|
|
|
19
19
|
//#region src/features/clean.ts
|
|
20
20
|
const debug$2 = Debug("tsdown:clean");
|
|
@@ -175,11 +175,13 @@ function shortcuts(restart) {
|
|
|
175
175
|
//#region src/features/watch.ts
|
|
176
176
|
const endsWithPackageJson = /[\\/]package\.json$/;
|
|
177
177
|
async function watchBuild(options, configFile, rebuild, restart) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const files = toArray(typeof options.watch === "boolean" ?
|
|
178
|
+
const cwd = process.cwd();
|
|
179
|
+
if (typeof options.watch === "boolean" && options.outDir === cwd) throw new Error("Watch is enabled, but output directory is the same as the current working directory.Please specify a different watch directory using `watch` option,or set `outDir` to a different directory.");
|
|
180
|
+
const files = toArray(typeof options.watch === "boolean" ? cwd : options.watch);
|
|
181
181
|
logger.info(`Watching for changes in ${files.join(", ")}`);
|
|
182
182
|
if (configFile) files.push(configFile);
|
|
183
|
+
const { watch } = await import("chokidar");
|
|
184
|
+
const debouncedRebuild = debounce(rebuild, 100);
|
|
183
185
|
const watcher = watch(files, {
|
|
184
186
|
ignoreInitial: true,
|
|
185
187
|
ignorePermissionErrors: true,
|
|
@@ -224,8 +226,8 @@ async function toObjectEntry(entry, cwd) {
|
|
|
224
226
|
|
|
225
227
|
//#endregion
|
|
226
228
|
//#region src/utils/tsconfig.ts
|
|
227
|
-
|
|
228
|
-
return
|
|
229
|
+
function findTsconfig(cwd, name = "tsconfig.json") {
|
|
230
|
+
return up(name, { cwd }) || false;
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
//#endregion
|
|
@@ -238,14 +240,14 @@ async function resolveOptions(options) {
|
|
|
238
240
|
...subConfig,
|
|
239
241
|
...options
|
|
240
242
|
};
|
|
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;
|
|
243
|
+
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, env = {} } = subOptions;
|
|
242
244
|
entry = await resolveEntry(entry, cwd);
|
|
243
245
|
if (clean === true) clean = [];
|
|
244
246
|
if (publint$1 === true) publint$1 = {};
|
|
245
247
|
if (tsconfig !== false) {
|
|
246
248
|
if (tsconfig === true || tsconfig == null) {
|
|
247
249
|
const isSet = tsconfig;
|
|
248
|
-
tsconfig =
|
|
250
|
+
tsconfig = findTsconfig(cwd);
|
|
249
251
|
if (isSet && !tsconfig) logger.warn(`No tsconfig found in \`${cwd}\``);
|
|
250
252
|
} else {
|
|
251
253
|
const tsconfigPath = path.resolve(cwd, tsconfig);
|
|
@@ -254,7 +256,7 @@ async function resolveOptions(options) {
|
|
|
254
256
|
logger.warn(`tsconfig \`${tsconfig}\` doesn't exist`);
|
|
255
257
|
tsconfig = false;
|
|
256
258
|
} else {
|
|
257
|
-
tsconfig =
|
|
259
|
+
tsconfig = findTsconfig(cwd, tsconfig);
|
|
258
260
|
if (!tsconfig) logger.warn(`No \`${tsconfig}\` found in \`${cwd}\``);
|
|
259
261
|
}
|
|
260
262
|
}
|
|
@@ -274,6 +276,7 @@ async function resolveOptions(options) {
|
|
|
274
276
|
entry,
|
|
275
277
|
plugins,
|
|
276
278
|
format: normalizeFormat(format),
|
|
279
|
+
target: target ? resolveComma(toArray(target)) : void 0,
|
|
277
280
|
outDir: path.resolve(outDir),
|
|
278
281
|
clean,
|
|
279
282
|
silent,
|
|
@@ -281,6 +284,7 @@ async function resolveOptions(options) {
|
|
|
281
284
|
platform,
|
|
282
285
|
sourcemap,
|
|
283
286
|
dts: dts === true ? {} : dts,
|
|
287
|
+
report: report === true ? {} : report,
|
|
284
288
|
unused,
|
|
285
289
|
watch,
|
|
286
290
|
shims,
|
|
@@ -289,7 +293,7 @@ async function resolveOptions(options) {
|
|
|
289
293
|
alias,
|
|
290
294
|
tsconfig,
|
|
291
295
|
cwd,
|
|
292
|
-
|
|
296
|
+
env
|
|
293
297
|
};
|
|
294
298
|
return config;
|
|
295
299
|
}));
|
|
@@ -393,6 +397,7 @@ async function mergeUserOptions(defaults, user, args) {
|
|
|
393
397
|
|
|
394
398
|
//#endregion
|
|
395
399
|
//#region src/index.ts
|
|
400
|
+
const debug = Debug("tsdown:config");
|
|
396
401
|
/**
|
|
397
402
|
* Build with tsdown.
|
|
398
403
|
*/
|
|
@@ -400,8 +405,12 @@ async function build(userOptions = {}) {
|
|
|
400
405
|
if (typeof userOptions.silent === "boolean") setSilent(userOptions.silent);
|
|
401
406
|
debug("Loading config");
|
|
402
407
|
const { configs, file: configFile } = await resolveOptions(userOptions);
|
|
403
|
-
if (configFile)
|
|
404
|
-
|
|
408
|
+
if (configFile) {
|
|
409
|
+
debug("Loaded config:", configFile);
|
|
410
|
+
configs.forEach((config) => {
|
|
411
|
+
debug("using resolved config: %O", config);
|
|
412
|
+
});
|
|
413
|
+
} else debug("No config file found");
|
|
405
414
|
const rebuilds = await Promise.all(configs.map(buildSingle));
|
|
406
415
|
const cleanCbs = [];
|
|
407
416
|
for (const [i, config] of configs.entries()) {
|
|
@@ -438,6 +447,8 @@ async function buildSingle(config) {
|
|
|
438
447
|
let hasErrors = false;
|
|
439
448
|
await Promise.all(formats.map(async (format) => {
|
|
440
449
|
try {
|
|
450
|
+
const formatLabel = prettyFormat(format);
|
|
451
|
+
logger.info(formatLabel, "Build start");
|
|
441
452
|
const buildOptions = await getBuildOptions(config, pkg, format);
|
|
442
453
|
await hooks.callHook("build:before", {
|
|
443
454
|
...context,
|
|
@@ -472,7 +483,7 @@ async function buildSingle(config) {
|
|
|
472
483
|
}
|
|
473
484
|
}
|
|
474
485
|
async function getBuildOptions(config, pkg, format, cjsDts) {
|
|
475
|
-
const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report } = config;
|
|
486
|
+
const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env } = config;
|
|
476
487
|
const plugins = [];
|
|
477
488
|
if (pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config, pkg));
|
|
478
489
|
if (dts) {
|
|
@@ -499,7 +510,7 @@ async function getBuildOptions(config, pkg, format, cjsDts) {
|
|
|
499
510
|
}));
|
|
500
511
|
plugins.push(ShebangPlugin(cwd));
|
|
501
512
|
}
|
|
502
|
-
if (report) plugins.push(ReportPlugin(cwd, cjsDts));
|
|
513
|
+
if (report) plugins.push(ReportPlugin(report, cwd, cjsDts));
|
|
503
514
|
plugins.push(userPlugins);
|
|
504
515
|
const inputOptions = await mergeUserOptions({
|
|
505
516
|
input: entry,
|
|
@@ -511,7 +522,15 @@ async function getBuildOptions(config, pkg, format, cjsDts) {
|
|
|
511
522
|
},
|
|
512
523
|
treeshake,
|
|
513
524
|
platform,
|
|
514
|
-
define
|
|
525
|
+
define: {
|
|
526
|
+
...define,
|
|
527
|
+
...Object.keys(env).reduce((acc, key) => {
|
|
528
|
+
const value = JSON.stringify(env[key]);
|
|
529
|
+
acc[`process.env.${key}`] = value;
|
|
530
|
+
acc[`import.meta.env.${key}`] = value;
|
|
531
|
+
return acc;
|
|
532
|
+
}, Object.create(null))
|
|
533
|
+
},
|
|
515
534
|
plugins,
|
|
516
535
|
inject: { ...shims && !cjsDts && getShimsInject(format, platform) }
|
|
517
536
|
}, config.inputOptions, [format]);
|
|
@@ -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,33 @@ interface Options$3 {
|
|
|
148
168
|
* Enable size reporting after bundling.
|
|
149
169
|
* @default true
|
|
150
170
|
*/
|
|
151
|
-
report?: boolean;
|
|
171
|
+
report?: boolean | ReportOptions;
|
|
172
|
+
/**
|
|
173
|
+
* Compile-time env variables.
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* {
|
|
177
|
+
* "DEBUG": true,
|
|
178
|
+
* "NODE_ENV": "production"
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
env?: Record<string, any>;
|
|
152
183
|
hooks?: Partial<TsdownHooks> | ((hooks: Hookable<TsdownHooks>) => Awaitable<void>);
|
|
153
184
|
}
|
|
154
185
|
/**
|
|
155
186
|
* Options without specifying config file path.
|
|
156
187
|
*/
|
|
157
188
|
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">, {
|
|
189
|
+
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks">, {
|
|
160
190
|
format: NormalizedFormat[]
|
|
191
|
+
target?: string[]
|
|
161
192
|
clean: string[] | false
|
|
162
193
|
dts: false | Options$1
|
|
194
|
+
report: false | ReportOptions
|
|
163
195
|
tsconfig: string | false
|
|
164
196
|
cwd: string
|
|
165
197
|
}>, "config" | "fromVite">;
|
|
166
198
|
|
|
167
199
|
//#endregion
|
|
168
|
-
export { BuildContext, Options$3 as Options, ResolvedOptions, TsdownHooks, UserConfig };
|
|
200
|
+
export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownHooks, UserConfig };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger, noop, resolveComma, toArray } from "./general-C06aMSSY.js";
|
|
2
2
|
import path, { dirname, normalize, sep } from "node:path";
|
|
3
3
|
import { blue, bold, dim, green, underline, yellow } from "ansis";
|
|
4
|
-
import { access, chmod, readFile, rm } from "node:fs/promises";
|
|
5
4
|
import Debug from "debug";
|
|
6
|
-
import {
|
|
5
|
+
import { access, chmod, readFile, rm } from "node:fs/promises";
|
|
6
|
+
import { up } from "empathic/package";
|
|
7
7
|
import { Buffer } from "node:buffer";
|
|
8
8
|
import { promisify } from "node:util";
|
|
9
9
|
import { brotliCompress, gzip } from "node:zlib";
|
|
@@ -37,26 +37,6 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
37
37
|
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/utils/general.ts
|
|
42
|
-
function toArray(val, defaultValue) {
|
|
43
|
-
if (Array.isArray(val)) return val;
|
|
44
|
-
else if (val == null) {
|
|
45
|
-
if (defaultValue) return [defaultValue];
|
|
46
|
-
return [];
|
|
47
|
-
} else return [val];
|
|
48
|
-
}
|
|
49
|
-
function debounce(fn, wait) {
|
|
50
|
-
let timeout;
|
|
51
|
-
return function(...args) {
|
|
52
|
-
if (timeout) clearTimeout(timeout);
|
|
53
|
-
timeout = setTimeout(() => {
|
|
54
|
-
timeout = void 0;
|
|
55
|
-
fn.apply(this, args);
|
|
56
|
-
}, wait);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
40
|
//#endregion
|
|
61
41
|
//#region src/features/external.ts
|
|
62
42
|
const debug$2 = Debug("tsdown:external");
|
|
@@ -99,10 +79,11 @@ function getProductionDeps(pkg) {
|
|
|
99
79
|
|
|
100
80
|
//#endregion
|
|
101
81
|
//#region src/utils/package.ts
|
|
82
|
+
const debug$1 = Debug("tsdown:package");
|
|
102
83
|
async function readPackageJson(dir) {
|
|
103
|
-
const packageJsonPath =
|
|
84
|
+
const packageJsonPath = up({ cwd: dir });
|
|
104
85
|
if (!packageJsonPath) return;
|
|
105
|
-
debug("Reading package.json:", packageJsonPath);
|
|
86
|
+
debug$1("Reading package.json:", packageJsonPath);
|
|
106
87
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
107
88
|
return JSON.parse(contents);
|
|
108
89
|
}
|
|
@@ -113,7 +94,7 @@ function getPackageType(pkg) {
|
|
|
113
94
|
}
|
|
114
95
|
}
|
|
115
96
|
function normalizeFormat(format) {
|
|
116
|
-
return toArray(format, "es").map((format$1) => {
|
|
97
|
+
return resolveComma(toArray(format, "es")).map((format$1) => {
|
|
117
98
|
switch (format$1) {
|
|
118
99
|
case "es":
|
|
119
100
|
case "esm":
|
|
@@ -125,18 +106,23 @@ function normalizeFormat(format) {
|
|
|
125
106
|
});
|
|
126
107
|
}
|
|
127
108
|
function prettyFormat(format) {
|
|
109
|
+
const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
|
|
110
|
+
let formatText;
|
|
128
111
|
switch (format) {
|
|
129
|
-
case "es":
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
112
|
+
case "es":
|
|
113
|
+
formatText = "ESM";
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
formatText = format.toUpperCase();
|
|
117
|
+
break;
|
|
134
118
|
}
|
|
119
|
+
return formatColor(`[${formatText}]`);
|
|
135
120
|
}
|
|
136
121
|
|
|
137
122
|
//#endregion
|
|
138
123
|
//#region src/utils/format.ts
|
|
139
124
|
function formatBytes(bytes) {
|
|
125
|
+
if (bytes === Infinity) return "too large";
|
|
140
126
|
const numberFormatter = new Intl.NumberFormat("en", {
|
|
141
127
|
maximumFractionDigits: 2,
|
|
142
128
|
minimumFractionDigits: 2
|
|
@@ -146,19 +132,18 @@ function formatBytes(bytes) {
|
|
|
146
132
|
|
|
147
133
|
//#endregion
|
|
148
134
|
//#region src/features/report.ts
|
|
149
|
-
const debug
|
|
150
|
-
const noop = (v) => v;
|
|
135
|
+
const debug = Debug("tsdown:report");
|
|
151
136
|
const brotliCompressAsync = promisify(brotliCompress);
|
|
152
137
|
const gzipAsync = promisify(gzip);
|
|
153
138
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
154
|
-
function ReportPlugin(cwd, cjsDts) {
|
|
139
|
+
function ReportPlugin(options, cwd, cjsDts) {
|
|
155
140
|
return {
|
|
156
141
|
name: "tsdown:report",
|
|
157
|
-
async writeBundle(
|
|
158
|
-
const outDir = path.relative(cwd,
|
|
142
|
+
async writeBundle(outputOptions, bundle) {
|
|
143
|
+
const outDir = path.relative(cwd, outputOptions.file ? path.resolve(cwd, outputOptions.file, "..") : path.resolve(cwd, outputOptions.dir));
|
|
159
144
|
const sizes = [];
|
|
160
145
|
for (const chunk of Object.values(bundle)) {
|
|
161
|
-
const size = await calcSize(chunk);
|
|
146
|
+
const size = await calcSize(options, chunk);
|
|
162
147
|
sizes.push(size);
|
|
163
148
|
}
|
|
164
149
|
const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
|
|
@@ -175,26 +160,34 @@ function ReportPlugin(cwd, cjsDts) {
|
|
|
175
160
|
sizes.sort((a, b) => {
|
|
176
161
|
if (a.dts !== b.dts) return a.dts ? 1 : -1;
|
|
177
162
|
if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
|
|
178
|
-
return b.
|
|
163
|
+
return b.raw - a.raw;
|
|
179
164
|
});
|
|
180
|
-
const
|
|
181
|
-
const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
|
|
182
|
-
const formatText = formatColor(`[${prettyFormat(format)}]`);
|
|
165
|
+
const formatLabel = prettyFormat(cjsDts ? "cjs" : outputOptions.format);
|
|
183
166
|
for (const size of sizes) {
|
|
184
167
|
const filenameColor = size.dts ? green : noop;
|
|
185
|
-
logger.info(
|
|
168
|
+
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
169
|
}
|
|
187
170
|
const totalSizeText = formatBytes(totalRaw);
|
|
188
|
-
logger.info(
|
|
171
|
+
logger.info(formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
|
|
189
172
|
}
|
|
190
173
|
};
|
|
191
174
|
}
|
|
192
|
-
async function calcSize(chunk) {
|
|
193
|
-
debug
|
|
175
|
+
async function calcSize(options, chunk) {
|
|
176
|
+
debug(`Calculating size for`, chunk.fileName);
|
|
194
177
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
195
178
|
const raw = Buffer.byteLength(content, "utf8");
|
|
196
|
-
|
|
197
|
-
|
|
179
|
+
debug("[size]", chunk.fileName, raw);
|
|
180
|
+
let gzip$1 = Infinity;
|
|
181
|
+
let brotli = Infinity;
|
|
182
|
+
if (raw > (options.maxCompressSize ?? 1e6)) debug(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
183
|
+
else {
|
|
184
|
+
gzip$1 = (await gzipAsync(content)).length;
|
|
185
|
+
debug("[gzip]", chunk.fileName, gzip$1);
|
|
186
|
+
if (options.brotli) {
|
|
187
|
+
brotli = (await brotliCompressAsync(content)).length;
|
|
188
|
+
debug("[brotli]", chunk.fileName, brotli);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
198
191
|
return {
|
|
199
192
|
filename: chunk.fileName,
|
|
200
193
|
dts: RE_DTS.test(chunk.fileName),
|
|
@@ -220,7 +213,7 @@ function ShebangPlugin(cwd) {
|
|
|
220
213
|
if (!RE_SHEBANG.test(chunk.code)) continue;
|
|
221
214
|
const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
|
|
222
215
|
if (await fsExists(filepath)) {
|
|
223
|
-
logger.info(`Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
|
|
216
|
+
logger.info(prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
|
|
224
217
|
await chmod(filepath, 493);
|
|
225
218
|
}
|
|
226
219
|
}
|
|
@@ -229,4 +222,4 @@ function ShebangPlugin(cwd) {
|
|
|
229
222
|
}
|
|
230
223
|
|
|
231
224
|
//#endregion
|
|
232
|
-
export { ExternalPlugin, ReportPlugin, ShebangPlugin,
|
|
225
|
+
export { ExternalPlugin, ReportPlugin, ShebangPlugin, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson };
|
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-DVjImwcI.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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalPlugin, ReportPlugin, ShebangPlugin } from "./plugins-
|
|
2
|
-
import "./
|
|
1
|
+
import { ExternalPlugin, ReportPlugin, ShebangPlugin } from "./plugins-BcuTSrGE.js";
|
|
2
|
+
import "./general-C06aMSSY.js";
|
|
3
3
|
|
|
4
4
|
export { ExternalPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { logger, setSilent } from "./
|
|
3
|
-
import { version } from "./package-
|
|
2
|
+
import { logger, resolveComma, setSilent, toArray } from "./general-C06aMSSY.js";
|
|
3
|
+
import { version } from "./package-B5RDOoPA.js";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { dim } from "ansis";
|
|
6
|
+
import Debug from "debug";
|
|
6
7
|
import { VERSION } from "rolldown";
|
|
8
|
+
import module from "node:module";
|
|
7
9
|
import { cac } from "cac";
|
|
8
10
|
|
|
9
11
|
//#region src/cli.ts
|
|
10
12
|
const cli = cac("tsdown");
|
|
11
13
|
cli.help().version(version);
|
|
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("--external <module>", "Mark dependencies as external").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").option("--report", "Size report", { default: true }).action(async (input, flags) => {
|
|
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("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [scope]", "Show debug logs").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").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").action(async (input, flags) => {
|
|
13
15
|
setSilent(!!flags.silent);
|
|
14
16
|
logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
15
17
|
const { build: build$1 } = await import("./index.js");
|
|
@@ -17,11 +19,20 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
|
|
|
17
19
|
await build$1(flags);
|
|
18
20
|
});
|
|
19
21
|
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-
|
|
22
|
+
const { migrate } = await import("./migrate-Cr0H4OLK.js");
|
|
21
23
|
await migrate(args);
|
|
22
24
|
});
|
|
23
25
|
async function runCLI() {
|
|
24
26
|
cli.parse(process.argv, { run: false });
|
|
27
|
+
if (cli.options.debug) {
|
|
28
|
+
let namespace;
|
|
29
|
+
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
30
|
+
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
31
|
+
const enabled = Debug.disable();
|
|
32
|
+
if (enabled) namespace += `,${enabled}`;
|
|
33
|
+
Debug.enable(namespace);
|
|
34
|
+
Debug("tsdown:debug")("Debugging enabled", namespace);
|
|
35
|
+
}
|
|
25
36
|
try {
|
|
26
37
|
await cli.runMatchedCommand();
|
|
27
38
|
} catch (error) {
|
|
@@ -32,6 +43,9 @@ async function runCLI() {
|
|
|
32
43
|
|
|
33
44
|
//#endregion
|
|
34
45
|
//#region src/run.ts
|
|
46
|
+
try {
|
|
47
|
+
module.enableCompileCache?.();
|
|
48
|
+
} catch {}
|
|
35
49
|
runCLI();
|
|
36
50
|
|
|
37
51
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"consola": "^3.4.2",
|
|
61
61
|
"debug": "^4.4.0",
|
|
62
62
|
"diff": "^7.0.0",
|
|
63
|
-
"
|
|
63
|
+
"empathic": "^1.0.0",
|
|
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",
|
package/dist/logger-Dt3D6T-U.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import Debug from "debug";
|
|
3
|
-
import { consola } from "consola";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/logger.ts
|
|
6
|
-
/**
|
|
7
|
-
* Logger instance
|
|
8
|
-
*/
|
|
9
|
-
const logger = consola.withTag("tsdown");
|
|
10
|
-
const debug = Debug("tsdown");
|
|
11
|
-
function setSilent(silent) {
|
|
12
|
-
if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { debug, logger, setSilent };
|