tsdown 0.3.1 → 0.4.0
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/features/syntax-lowering.d.ts +2 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +31 -14
- package/dist/options.d.ts +2 -1
- package/dist/{external-9r3oq3tH.js → plugins-CVyS1B0c.js} +16 -1
- package/dist/plugins.d.ts +1 -0
- package/dist/plugins.js +2 -2
- package/dist/run.js +2 -2
- package/package.json +9 -9
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { debug, logger } from "./logger-Pk57TMWT.js";
|
|
2
|
-
import { ExternalPlugin } from "./
|
|
2
|
+
import { ExternalPlugin, SyntaxLoweringPlugin } from "./plugins-CVyS1B0c.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
5
|
import { IsolatedDecl } from "unplugin-isolated-decl";
|
|
@@ -69,16 +69,17 @@ function resolveOutputExtension(pkg, format) {
|
|
|
69
69
|
|
|
70
70
|
//#endregion
|
|
71
71
|
//#region src/features/shortcuts.ts
|
|
72
|
-
function shortcuts(
|
|
72
|
+
function shortcuts(restart) {
|
|
73
73
|
let actionRunning = false;
|
|
74
74
|
async function onInput(input) {
|
|
75
75
|
if (actionRunning) return;
|
|
76
76
|
const SHORTCUTS = [
|
|
77
77
|
{
|
|
78
78
|
key: "r",
|
|
79
|
-
description: "rebuild",
|
|
79
|
+
description: "reload config and rebuild",
|
|
80
80
|
action() {
|
|
81
|
-
|
|
81
|
+
rl.close();
|
|
82
|
+
restart();
|
|
82
83
|
}
|
|
83
84
|
},
|
|
84
85
|
{
|
|
@@ -92,8 +93,7 @@ function shortcuts(watcher, rebuild) {
|
|
|
92
93
|
key: "q",
|
|
93
94
|
description: "quit",
|
|
94
95
|
action() {
|
|
95
|
-
|
|
96
|
-
return watcher.close();
|
|
96
|
+
process$3.exit(0);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
];
|
|
@@ -260,12 +260,27 @@ async function loadConfigFile(options) {
|
|
|
260
260
|
//#region src/index.ts
|
|
261
261
|
async function build(userOptions = {}) {
|
|
262
262
|
debug("Loading config");
|
|
263
|
-
const [
|
|
263
|
+
const [resolveds, configFile] = await resolveOptions(userOptions);
|
|
264
264
|
if (configFile) debug("Loaded config:", configFile);
|
|
265
|
-
|
|
265
|
+
else debug("No config file found");
|
|
266
|
+
const contexts = await Promise.all(resolveds.map(buildSingle));
|
|
267
|
+
const cleanCbs = [];
|
|
268
|
+
for (const [i, resolved] of resolveds.entries()) {
|
|
269
|
+
const context = contexts[i];
|
|
270
|
+
if (!context) continue;
|
|
271
|
+
const watcher = await watchBuild(resolved, context.rebuild);
|
|
272
|
+
cleanCbs.push(async () => {
|
|
273
|
+
await watcher.close();
|
|
274
|
+
await contexts[i].close();
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (cleanCbs.length) shortcuts(async () => {
|
|
278
|
+
for (const clean of cleanCbs) await clean();
|
|
279
|
+
build(userOptions);
|
|
280
|
+
});
|
|
266
281
|
}
|
|
267
282
|
async function buildSingle(resolved) {
|
|
268
|
-
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, onSuccess } = resolved;
|
|
283
|
+
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, onSuccess } = resolved;
|
|
269
284
|
if (clean) await cleanOutDir(outDir, clean);
|
|
270
285
|
const pkg = await readPackageJson(process.cwd());
|
|
271
286
|
let startTime = performance.now();
|
|
@@ -279,7 +294,8 @@ async function buildSingle(resolved) {
|
|
|
279
294
|
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
280
295
|
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
281
296
|
dts && IsolatedDecl.rolldown(dts === true ? {} : dts),
|
|
282
|
-
|
|
297
|
+
target && SyntaxLoweringPlugin(target),
|
|
298
|
+
plugins
|
|
283
299
|
].filter((plugin) => !!plugin),
|
|
284
300
|
...resolved.inputOptions
|
|
285
301
|
};
|
|
@@ -302,10 +318,11 @@ async function buildSingle(resolved) {
|
|
|
302
318
|
};
|
|
303
319
|
}));
|
|
304
320
|
await writeBundle(true);
|
|
305
|
-
if (watch) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
321
|
+
if (watch) return {
|
|
322
|
+
rebuild: writeBundle,
|
|
323
|
+
close: () => build$1.close()
|
|
324
|
+
};
|
|
325
|
+
else await build$1.close();
|
|
309
326
|
async function writeBundle(first) {
|
|
310
327
|
if (!first) startTime = performance.now();
|
|
311
328
|
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">;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { debug } from "./logger-Pk57TMWT.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { transform } from "oxc-transform";
|
|
3
4
|
|
|
4
5
|
//#region src/features/external.ts
|
|
5
6
|
function ExternalPlugin(pkg, skipNodeModulesBundle) {
|
|
@@ -25,4 +26,18 @@ function getProductionDeps(pkg) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
//#endregion
|
|
28
|
-
|
|
29
|
+
//#region src/features/syntax-lowering.ts
|
|
30
|
+
function SyntaxLoweringPlugin(target) {
|
|
31
|
+
return {
|
|
32
|
+
name: "tsdown:syntax-lowering",
|
|
33
|
+
renderChunk(code, chunk, { sourcemap }) {
|
|
34
|
+
return transform(chunk.fileName, code, {
|
|
35
|
+
sourcemap: !!sourcemap,
|
|
36
|
+
target
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ExternalPlugin, SyntaxLoweringPlugin };
|
package/dist/plugins.d.ts
CHANGED
package/dist/plugins.js
CHANGED
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.0";
|
|
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.0",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,29 +43,29 @@
|
|
|
43
43
|
"chokidar": "^4.0.1",
|
|
44
44
|
"consola": "^3.2.3",
|
|
45
45
|
"debug": "^4.3.7",
|
|
46
|
+
"oxc-transform": "^0.38.0",
|
|
46
47
|
"picocolors": "^1.1.1",
|
|
47
48
|
"pkg-types": "^1.2.1",
|
|
48
49
|
"rolldown": "nightly",
|
|
49
50
|
"tinyglobby": "^0.2.10",
|
|
50
51
|
"unconfig": "^0.6.0",
|
|
51
|
-
"unplugin-isolated-decl": "^0.
|
|
52
|
+
"unplugin-isolated-decl": "^0.9.3",
|
|
52
53
|
"unplugin-unused": "^0.2.3"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@sxzz/eslint-config": "^4.
|
|
56
|
+
"@sxzz/eslint-config": "^4.5.1",
|
|
56
57
|
"@sxzz/prettier-config": "^2.0.2",
|
|
57
58
|
"@types/debug": "^4.1.12",
|
|
58
|
-
"@types/node": "^22.
|
|
59
|
+
"@types/node": "^22.10.1",
|
|
59
60
|
"bumpp": "^9.8.1",
|
|
60
|
-
"eslint": "^9.
|
|
61
|
+
"eslint": "^9.16.0",
|
|
61
62
|
"execa": "^9.5.1",
|
|
62
63
|
"fdir": "^6.4.2",
|
|
63
|
-
"
|
|
64
|
-
"prettier": "^3.3.3",
|
|
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"
|