tsdown 0.3.1 → 0.4.1
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/features/shortcuts.d.ts +1 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +31 -13
- package/dist/options.d.ts +2 -1
- package/dist/run.js +2 -2
- package/package.json +10 -10
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { FSWatcher } from "chokidar";
|
|
2
1
|
export interface Shortcut {
|
|
3
2
|
key: string;
|
|
4
3
|
description: string;
|
|
5
4
|
action: () => void | Promise<void>;
|
|
6
5
|
}
|
|
7
|
-
export declare function shortcuts(
|
|
6
|
+
export declare function shortcuts(restart: () => void): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,14 @@ import { logger } from "./utils/logger.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function build(userOptions?: Omit<Options, "silent">): Promise<void>;
|
|
7
7
|
/**
|
|
8
|
-
* Build a single configuration.
|
|
8
|
+
* Build a single configuration, without watch and shortcuts features.
|
|
9
9
|
*
|
|
10
10
|
* @param resolved Resolved options
|
|
11
11
|
*/
|
|
12
|
-
export declare function buildSingle(resolved: ResolvedOptions): Promise<
|
|
12
|
+
export declare function buildSingle(resolved: ResolvedOptions): Promise<{
|
|
13
|
+
rebuild: () => Promise<void>;
|
|
14
|
+
close: () => Promise<void>;
|
|
15
|
+
} | undefined>;
|
|
13
16
|
/**
|
|
14
17
|
* Defines the configuration for tsdown.
|
|
15
18
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { debug, logger } from "./logger-Pk57TMWT.js";
|
|
|
2
2
|
import { ExternalPlugin } from "./external-9r3oq3tH.js";
|
|
3
3
|
import process, { default as process$1, default as process$2, default as process$3 } from "node:process";
|
|
4
4
|
import { rolldown } from "rolldown";
|
|
5
|
+
import { transformPlugin } from "rolldown/experimental";
|
|
5
6
|
import { IsolatedDecl } from "unplugin-isolated-decl";
|
|
6
7
|
import { Unused } from "unplugin-unused";
|
|
7
8
|
import { access, readdir, rm, stat } from "node:fs/promises";
|
|
@@ -69,16 +70,17 @@ function resolveOutputExtension(pkg, format) {
|
|
|
69
70
|
|
|
70
71
|
//#endregion
|
|
71
72
|
//#region src/features/shortcuts.ts
|
|
72
|
-
function shortcuts(
|
|
73
|
+
function shortcuts(restart) {
|
|
73
74
|
let actionRunning = false;
|
|
74
75
|
async function onInput(input) {
|
|
75
76
|
if (actionRunning) return;
|
|
76
77
|
const SHORTCUTS = [
|
|
77
78
|
{
|
|
78
79
|
key: "r",
|
|
79
|
-
description: "rebuild",
|
|
80
|
+
description: "reload config and rebuild",
|
|
80
81
|
action() {
|
|
81
|
-
|
|
82
|
+
rl.close();
|
|
83
|
+
restart();
|
|
82
84
|
}
|
|
83
85
|
},
|
|
84
86
|
{
|
|
@@ -92,8 +94,7 @@ function shortcuts(watcher, rebuild) {
|
|
|
92
94
|
key: "q",
|
|
93
95
|
description: "quit",
|
|
94
96
|
action() {
|
|
95
|
-
|
|
96
|
-
return watcher.close();
|
|
97
|
+
process$3.exit(0);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
];
|
|
@@ -260,12 +261,27 @@ async function loadConfigFile(options) {
|
|
|
260
261
|
//#region src/index.ts
|
|
261
262
|
async function build(userOptions = {}) {
|
|
262
263
|
debug("Loading config");
|
|
263
|
-
const [
|
|
264
|
+
const [resolveds, configFile] = await resolveOptions(userOptions);
|
|
264
265
|
if (configFile) debug("Loaded config:", configFile);
|
|
265
|
-
|
|
266
|
+
else debug("No config file found");
|
|
267
|
+
const contexts = await Promise.all(resolveds.map(buildSingle));
|
|
268
|
+
const cleanCbs = [];
|
|
269
|
+
for (const [i, resolved] of resolveds.entries()) {
|
|
270
|
+
const context = contexts[i];
|
|
271
|
+
if (!context) continue;
|
|
272
|
+
const watcher = await watchBuild(resolved, context.rebuild);
|
|
273
|
+
cleanCbs.push(async () => {
|
|
274
|
+
await watcher.close();
|
|
275
|
+
await contexts[i].close();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (cleanCbs.length) shortcuts(async () => {
|
|
279
|
+
for (const clean of cleanCbs) await clean();
|
|
280
|
+
build(userOptions);
|
|
281
|
+
});
|
|
266
282
|
}
|
|
267
283
|
async function buildSingle(resolved) {
|
|
268
|
-
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, onSuccess } = resolved;
|
|
284
|
+
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, onSuccess } = resolved;
|
|
269
285
|
if (clean) await cleanOutDir(outDir, clean);
|
|
270
286
|
const pkg = await readPackageJson(process.cwd());
|
|
271
287
|
let startTime = performance.now();
|
|
@@ -279,7 +295,8 @@ async function buildSingle(resolved) {
|
|
|
279
295
|
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
280
296
|
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
281
297
|
dts && IsolatedDecl.rolldown(dts === true ? {} : dts),
|
|
282
|
-
|
|
298
|
+
target && transformPlugin({ target: typeof target === "string" ? target : target.join(",") }),
|
|
299
|
+
plugins
|
|
283
300
|
].filter((plugin) => !!plugin),
|
|
284
301
|
...resolved.inputOptions
|
|
285
302
|
};
|
|
@@ -302,10 +319,11 @@ async function buildSingle(resolved) {
|
|
|
302
319
|
};
|
|
303
320
|
}));
|
|
304
321
|
await writeBundle(true);
|
|
305
|
-
if (watch) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
322
|
+
if (watch) return {
|
|
323
|
+
rebuild: writeBundle,
|
|
324
|
+
close: () => build$1.close()
|
|
325
|
+
};
|
|
326
|
+
else await build$1.close();
|
|
309
327
|
async function writeBundle(first) {
|
|
310
328
|
if (!first) startTime = performance.now();
|
|
311
329
|
await Promise.all(outputOptions.map((outputOptions$1) => build$1.write(outputOptions$1)));
|
package/dist/options.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface Options {
|
|
|
23
23
|
treeshake?: boolean;
|
|
24
24
|
/** @default false */
|
|
25
25
|
minify?: boolean;
|
|
26
|
+
target?: string | string[];
|
|
26
27
|
/** @default 'node' */
|
|
27
28
|
platform?: "node" | "neutral" | "browser";
|
|
28
29
|
/**
|
|
@@ -47,7 +48,7 @@ export interface Options {
|
|
|
47
48
|
*/
|
|
48
49
|
export type Config = Arrayable<Omit<Options, "config">>;
|
|
49
50
|
export type ResolvedConfig = Extract<Config, any[]>;
|
|
50
|
-
export type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "alias" | "external" | "onSuccess">, {
|
|
51
|
+
export type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "alias" | "external" | "onSuccess">, {
|
|
51
52
|
format: ModuleFormat[];
|
|
52
53
|
clean: string[] | false;
|
|
53
54
|
}>, "config">;
|
package/dist/run.js
CHANGED
|
@@ -5,13 +5,13 @@ import pc from "picocolors";
|
|
|
5
5
|
import { cac } from "cac";
|
|
6
6
|
|
|
7
7
|
//#region package.json
|
|
8
|
-
|
|
8
|
+
var version = "0.4.1";
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/cli.ts
|
|
12
12
|
async function runCLI() {
|
|
13
13
|
const cli = cac("tsdown");
|
|
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("--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("--platform <platform>", "Target platform", { default: "node" }).option("-w, --watch", "Watch mode").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("--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("--platform <platform>", "Target platform", { default: "node" }).option("-w, --watch", "Watch mode").action(async (input, flags) => {
|
|
15
15
|
if (!("CONSOLA_LEVEL" in process.env)) logger.level = flags.silent ? 0 : 3;
|
|
16
16
|
logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${rolldownVersion}`)}`);
|
|
17
17
|
const { build } = await import("./index.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,27 +45,27 @@
|
|
|
45
45
|
"debug": "^4.3.7",
|
|
46
46
|
"picocolors": "^1.1.1",
|
|
47
47
|
"pkg-types": "^1.2.1",
|
|
48
|
-
"rolldown": "
|
|
48
|
+
"rolldown": "0.15.0-snapshot-993c4a1-20241205003858",
|
|
49
49
|
"tinyglobby": "^0.2.10",
|
|
50
50
|
"unconfig": "^0.6.0",
|
|
51
|
-
"unplugin-isolated-decl": "^0.
|
|
51
|
+
"unplugin-isolated-decl": "^0.9.3",
|
|
52
52
|
"unplugin-unused": "^0.2.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@sxzz/eslint-config": "^4.
|
|
55
|
+
"@sxzz/eslint-config": "^4.5.1",
|
|
56
56
|
"@sxzz/prettier-config": "^2.0.2",
|
|
57
57
|
"@types/debug": "^4.1.12",
|
|
58
|
-
"@types/node": "^22.
|
|
58
|
+
"@types/node": "^22.10.1",
|
|
59
59
|
"bumpp": "^9.8.1",
|
|
60
|
-
"eslint": "^9.
|
|
60
|
+
"eslint": "^9.16.0",
|
|
61
61
|
"execa": "^9.5.1",
|
|
62
62
|
"fdir": "^6.4.2",
|
|
63
|
-
"oxc-transform": "^0.
|
|
64
|
-
"prettier": "^3.
|
|
63
|
+
"oxc-transform": "^0.39.0",
|
|
64
|
+
"prettier": "^3.4.2",
|
|
65
65
|
"tsup": "^8.3.5",
|
|
66
66
|
"tsx": "^4.19.2",
|
|
67
|
-
"typescript": "~5.
|
|
68
|
-
"vitest": "^2.
|
|
67
|
+
"typescript": "~5.7.2",
|
|
68
|
+
"vitest": "^2.2.0-beta.2"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=18.0.0"
|