tsdown 0.5.4 → 0.5.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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/{config.d-DWijXKYW.d.ts → config.d-zCyRCdco.d.ts} +13 -4
- package/dist/config.d.ts +2 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +46 -14
- package/dist/{logger-ByXVlJsC.js → logger-BV85twVD.js} +5 -1
- package/dist/run.js +3 -3
- package/package.json +12 -11
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright © 2024 三咲智子 Kevin Deng (https://github.com/sxzz)
|
|
3
|
+
Copyright © 2024-PRESENT 三咲智子 Kevin Deng (https://github.com/sxzz)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { E as External } from './plugins.d-DtLTz4jh.js';
|
|
2
|
+
import { Options as Options$3 } from 'publint';
|
|
2
3
|
import { InputOptions, ModuleFormat, OutputOptions, InternalModuleFormat } from 'rolldown';
|
|
3
4
|
import { Options as Options$1 } from 'unplugin-isolated-decl';
|
|
4
5
|
import { Options as Options$2 } from 'unplugin-unused';
|
|
@@ -57,16 +58,24 @@ interface Options {
|
|
|
57
58
|
* Skip bundling node_modules.
|
|
58
59
|
*/
|
|
59
60
|
skipNodeModulesBundle?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Use a fixed extension for output files.
|
|
63
|
+
* The extension will always be `.cjs` or `.mjs`.
|
|
64
|
+
* Otherwise, it will depend on the package type.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
fixedExtension?: boolean;
|
|
68
|
+
publint?: boolean | Options$3;
|
|
60
69
|
}
|
|
61
70
|
/**
|
|
62
71
|
* Options without specifying config file path.
|
|
63
72
|
*/
|
|
64
73
|
type Config = Arrayable<Omit<Options, "config">>;
|
|
65
74
|
type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
|
|
66
|
-
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "onSuccess" | "dts">, {
|
|
67
|
-
format: NormalizedFormat[]
|
|
68
|
-
clean: string[] | false
|
|
69
|
-
dts: false | Options$1
|
|
75
|
+
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "onSuccess" | "dts" | "fixedExtension">, {
|
|
76
|
+
format: NormalizedFormat[]
|
|
77
|
+
clean: string[] | false
|
|
78
|
+
dts: false | Options$1
|
|
70
79
|
}>, "config">;
|
|
71
80
|
|
|
72
81
|
/**
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { d as defineConfig } from './config.d-
|
|
1
|
+
export { d as defineConfig } from './config.d-zCyRCdco.js';
|
|
2
2
|
import './plugins.d-DtLTz4jh.js';
|
|
3
3
|
import 'pkg-types';
|
|
4
4
|
import 'rolldown';
|
|
5
|
+
import 'publint';
|
|
5
6
|
import 'unplugin-isolated-decl';
|
|
6
7
|
import 'unplugin-unused';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { O as Options, R as ResolvedOptions } from './config.d-
|
|
2
|
-
export { C as Config, d as defineConfig } from './config.d-
|
|
1
|
+
import { O as Options, R as ResolvedOptions } from './config.d-zCyRCdco.js';
|
|
2
|
+
export { C as Config, d as defineConfig } from './config.d-zCyRCdco.js';
|
|
3
3
|
import { ConsolaInstance } from 'consola';
|
|
4
4
|
import './plugins.d-DtLTz4jh.js';
|
|
5
5
|
import 'pkg-types';
|
|
6
6
|
import 'rolldown';
|
|
7
|
+
import 'publint';
|
|
7
8
|
import 'unplugin-isolated-decl';
|
|
8
9
|
import 'unplugin-unused';
|
|
9
10
|
|
|
@@ -15,7 +16,7 @@ declare const logger: ConsolaInstance;
|
|
|
15
16
|
/**
|
|
16
17
|
* Build with tsdown.
|
|
17
18
|
*/
|
|
18
|
-
declare function build(userOptions?:
|
|
19
|
+
declare function build(userOptions?: Options): Promise<void>;
|
|
19
20
|
declare const pkgRoot: string;
|
|
20
21
|
/**
|
|
21
22
|
* Build a single configuration, without watch and shortcuts features.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "./config-0LDjKwZ7.js";
|
|
2
|
-
import { debug, logger } from "./logger-
|
|
2
|
+
import { debug, logger, setSilent } from "./logger-BV85twVD.js";
|
|
3
3
|
import { ExternalPlugin } from "./external-QIv-o_HK.js";
|
|
4
4
|
import path, { dirname, normalize, sep } from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
@@ -14,6 +14,8 @@ import { glob } from "tinyglobby";
|
|
|
14
14
|
import { rollup } from "rollup";
|
|
15
15
|
import DtsPlugin from "rollup-plugin-dts";
|
|
16
16
|
import { readPackageJSON } from "pkg-types";
|
|
17
|
+
import { publint } from "publint";
|
|
18
|
+
import { formatMessage } from "publint/utils";
|
|
17
19
|
import readline from "node:readline";
|
|
18
20
|
import pc from "picocolors";
|
|
19
21
|
import { loadConfig } from "unconfig";
|
|
@@ -38,7 +40,7 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
38
40
|
const directories = filepath.split(sep, ancestor.length);
|
|
39
41
|
let index = 0;
|
|
40
42
|
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
41
|
-
else {
|
|
43
|
+
else {
|
|
42
44
|
ancestor = ancestor.slice(0, index);
|
|
43
45
|
break;
|
|
44
46
|
}
|
|
@@ -49,7 +51,7 @@ else {
|
|
|
49
51
|
|
|
50
52
|
//#endregion
|
|
51
53
|
//#region src/features/clean.ts
|
|
52
|
-
const debug$
|
|
54
|
+
const debug$2 = Debug("tsdown:clean");
|
|
53
55
|
async function cleanOutDir(cwd, patterns) {
|
|
54
56
|
const files = [];
|
|
55
57
|
if (await fsExists(cwd)) files.push(...(await readdir(cwd)).map((file) => path.resolve(cwd, file)));
|
|
@@ -59,7 +61,7 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
59
61
|
}));
|
|
60
62
|
logger.info("Cleaning output folder");
|
|
61
63
|
for (const file of files) {
|
|
62
|
-
debug$
|
|
64
|
+
debug$2("Removing", file);
|
|
63
65
|
await fsRemove(file);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -68,7 +70,7 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
68
70
|
//#region src/utils/general.ts
|
|
69
71
|
function toArray(val, defaultValue) {
|
|
70
72
|
if (Array.isArray(val)) return val;
|
|
71
|
-
else if (val == null) {
|
|
73
|
+
else if (val == null) {
|
|
72
74
|
if (defaultValue) return [defaultValue];
|
|
73
75
|
return [];
|
|
74
76
|
} else return [val];
|
|
@@ -97,7 +99,7 @@ async function bundleDts(options, jsExtension, format) {
|
|
|
97
99
|
const build$2 = await rollup({
|
|
98
100
|
input: dtsEntry,
|
|
99
101
|
onLog(level, log, defaultHandler) {
|
|
100
|
-
if (log.code !== "EMPTY_BUNDLE") defaultHandler(level, log);
|
|
102
|
+
if (log.code !== "EMPTY_BUNDLE" && log.code !== "UNRESOLVED_IMPORT") defaultHandler(level, log);
|
|
101
103
|
},
|
|
102
104
|
plugins: [DtsPlugin()]
|
|
103
105
|
});
|
|
@@ -131,15 +133,40 @@ function getPackageType(pkg) {
|
|
|
131
133
|
|
|
132
134
|
//#endregion
|
|
133
135
|
//#region src/features/output.ts
|
|
134
|
-
function resolveOutputExtension(pkg, format) {
|
|
136
|
+
function resolveOutputExtension(pkg, format, fixedExtension) {
|
|
135
137
|
const moduleType = getPackageType(pkg);
|
|
136
138
|
switch (format) {
|
|
137
|
-
case "es": return moduleType === "module" ? "js" : "mjs";
|
|
138
|
-
case "cjs": return moduleType === "module" ? "cjs" : "js";
|
|
139
|
+
case "es": return !fixedExtension && moduleType === "module" ? "js" : "mjs";
|
|
140
|
+
case "cjs": return fixedExtension || moduleType === "module" ? "cjs" : "js";
|
|
139
141
|
default: return "js";
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/features/publint.ts
|
|
147
|
+
const debug$1 = Debug("tsdown:publint");
|
|
148
|
+
async function publint$1(pkg) {
|
|
149
|
+
debug$1("Running publint");
|
|
150
|
+
const { messages } = await publint();
|
|
151
|
+
debug$1("Found %d issues", messages.length);
|
|
152
|
+
if (!messages.length) logger.success("No publint issues found");
|
|
153
|
+
let hasError = false;
|
|
154
|
+
for (const message of messages) {
|
|
155
|
+
hasError ||= message.type === "error";
|
|
156
|
+
const formattedMessage = formatMessage(message, pkg);
|
|
157
|
+
const logType = {
|
|
158
|
+
error: "error",
|
|
159
|
+
warning: "warn",
|
|
160
|
+
suggestion: "info"
|
|
161
|
+
}[message.type];
|
|
162
|
+
logger[logType](formattedMessage);
|
|
163
|
+
}
|
|
164
|
+
if (hasError) {
|
|
165
|
+
debug$1("Found errors, setting exit code to 1");
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
143
170
|
//#endregion
|
|
144
171
|
//#region src/features/shims.ts
|
|
145
172
|
function getShimsInject(format, platform) {
|
|
@@ -263,9 +290,10 @@ async function resolveOptions(options) {
|
|
|
263
290
|
...subConfig,
|
|
264
291
|
...options
|
|
265
292
|
};
|
|
266
|
-
let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, bundleDts: bundleDts$1 = true, unused = false, watch = false, shims = false, skipNodeModulesBundle = false } = subOptions;
|
|
293
|
+
let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, bundleDts: bundleDts$1 = true, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$2 = false } = subOptions;
|
|
267
294
|
entry = await resolveEntry(entry);
|
|
268
295
|
if (clean === true) clean = [];
|
|
296
|
+
if (publint$2 === true) publint$2 = {};
|
|
269
297
|
return {
|
|
270
298
|
...subOptions,
|
|
271
299
|
entry,
|
|
@@ -282,7 +310,8 @@ async function resolveOptions(options) {
|
|
|
282
310
|
unused,
|
|
283
311
|
watch,
|
|
284
312
|
shims,
|
|
285
|
-
skipNodeModulesBundle
|
|
313
|
+
skipNodeModulesBundle,
|
|
314
|
+
publint: publint$2
|
|
286
315
|
};
|
|
287
316
|
})), configFile];
|
|
288
317
|
}
|
|
@@ -358,10 +387,11 @@ async function mergeUserOptions(defaults, user, args) {
|
|
|
358
387
|
//#endregion
|
|
359
388
|
//#region src/index.ts
|
|
360
389
|
async function build(userOptions = {}) {
|
|
390
|
+
typeof userOptions.silent === "boolean" && setSilent(userOptions.silent);
|
|
361
391
|
debug("Loading config");
|
|
362
392
|
const [resolveds, configFile] = await resolveOptions(userOptions);
|
|
363
393
|
if (configFile) debug("Loaded config:", configFile);
|
|
364
|
-
else debug("No config file found");
|
|
394
|
+
else debug("No config file found");
|
|
365
395
|
const rebuilds = await Promise.all(resolveds.map(buildSingle));
|
|
366
396
|
const cleanCbs = [];
|
|
367
397
|
for (const [i, resolved] of resolveds.entries()) {
|
|
@@ -379,7 +409,7 @@ else debug("No config file found");
|
|
|
379
409
|
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
380
410
|
const pkgRoot = path.resolve(dirname$1, "..");
|
|
381
411
|
async function buildSingle(resolved) {
|
|
382
|
-
const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, onSuccess } = resolved;
|
|
412
|
+
const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = resolved;
|
|
383
413
|
if (clean) await cleanOutDir(outDir, clean);
|
|
384
414
|
const pkg = await readPackageJson(process.cwd());
|
|
385
415
|
await rebuild(true);
|
|
@@ -406,7 +436,7 @@ async function buildSingle(resolved) {
|
|
|
406
436
|
].filter((plugin) => !!plugin),
|
|
407
437
|
inject: { ...shims && getShimsInject(format$1, platform) }
|
|
408
438
|
}, resolved.inputOptions, [format$1]);
|
|
409
|
-
const extension = resolveOutputExtension(pkg, format$1);
|
|
439
|
+
const extension = resolveOutputExtension(pkg, format$1, fixedExtension);
|
|
410
440
|
const outputOptions = await mergeUserOptions({
|
|
411
441
|
format: format$1,
|
|
412
442
|
name: resolved.globalName,
|
|
@@ -422,6 +452,8 @@ async function buildSingle(resolved) {
|
|
|
422
452
|
});
|
|
423
453
|
if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension, format$1);
|
|
424
454
|
}));
|
|
455
|
+
if (resolved.publint) if (pkg) await publint$1(pkg);
|
|
456
|
+
else logger.warn("publint is enabled but package.json is not found");
|
|
425
457
|
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
|
426
458
|
await onSuccess?.();
|
|
427
459
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import process from "node:process";
|
|
1
2
|
import Debug from "debug";
|
|
2
3
|
import { consola } from "consola";
|
|
3
4
|
|
|
4
5
|
//#region src/utils/logger.ts
|
|
5
6
|
const logger = consola.withTag("tsdown");
|
|
6
7
|
const debug = Debug("tsdown");
|
|
8
|
+
function setSilent(silent) {
|
|
9
|
+
if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
//#endregion
|
|
9
|
-
export { debug, logger };
|
|
13
|
+
export { debug, logger, setSilent };
|
package/dist/run.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { logger } from "./logger-
|
|
1
|
+
import { logger, setSilent } from "./logger-BV85twVD.js";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { VERSION } from "rolldown";
|
|
4
4
|
import pc from "picocolors";
|
|
5
5
|
import { cac } from "cac";
|
|
6
6
|
|
|
7
7
|
//#region package.json
|
|
8
|
-
var version = "0.5.
|
|
8
|
+
var version = "0.5.6";
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/cli.ts
|
|
12
12
|
async function runCLI() {
|
|
13
13
|
const cli = cac("tsdown");
|
|
14
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("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("-w, --watch [path]", "Watch mode").action(async (input, flags) => {
|
|
15
|
-
|
|
15
|
+
setSilent(!!flags.silent);
|
|
16
16
|
logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${VERSION}`)}`);
|
|
17
17
|
const { build: build$1 } = await import("./index.js");
|
|
18
18
|
if (input.length > 0) flags.entry = input;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,30 +47,31 @@
|
|
|
47
47
|
"debug": "^4.4.0",
|
|
48
48
|
"picocolors": "^1.1.1",
|
|
49
49
|
"pkg-types": "^1.3.1",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
50
|
+
"publint": "^0.3.2",
|
|
51
|
+
"rolldown": "^1.0.0-beta.3",
|
|
52
|
+
"rollup": "^4.32.0",
|
|
52
53
|
"rollup-plugin-dts": "^6.1.1",
|
|
53
54
|
"tinyglobby": "^0.2.10",
|
|
54
55
|
"unconfig": "^0.6.1",
|
|
55
|
-
"unplugin-isolated-decl": "^0.10.
|
|
56
|
+
"unplugin-isolated-decl": "^0.10.6",
|
|
56
57
|
"unplugin-unused": "^0.3.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@sxzz/eslint-config": "^
|
|
60
|
+
"@sxzz/eslint-config": "^5.0.0-beta.2",
|
|
60
61
|
"@sxzz/prettier-config": "^2.1.0",
|
|
61
62
|
"@sxzz/test-utils": "^0.4.0",
|
|
62
63
|
"@types/debug": "^4.1.12",
|
|
63
|
-
"@types/node": "^22.10.
|
|
64
|
-
"bumpp": "^
|
|
65
|
-
"eslint": "^9.
|
|
66
|
-
"oxc-transform": "^0.
|
|
64
|
+
"@types/node": "^22.10.10",
|
|
65
|
+
"bumpp": "^10.0.1",
|
|
66
|
+
"eslint": "^9.19.0",
|
|
67
|
+
"oxc-transform": "^0.48.1",
|
|
67
68
|
"prettier": "^3.4.2",
|
|
68
69
|
"tinyexec": "^0.3.2",
|
|
69
|
-
"tsup": "^8.3.
|
|
70
|
+
"tsup": "^8.3.6",
|
|
70
71
|
"tsx": "^4.19.2",
|
|
71
72
|
"typescript": "~5.7.3",
|
|
72
73
|
"unplugin-ast": "^0.13.1",
|
|
73
|
-
"vitest": "^3.0.
|
|
74
|
+
"vitest": "^3.0.4"
|
|
74
75
|
},
|
|
75
76
|
"engines": {
|
|
76
77
|
"node": ">=18.0.0"
|