tsdown 0.14.0 → 0.14.2
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/README.md +17 -1
- package/dist/{config-77IY7Jdj.d.mts → config-DwMASPo6.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{migrate-BCQUL2Gs.mjs → migrate-DQpxfr1J.mjs} +10 -16
- package/dist/package-DOwY1eta.mjs +5 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +1 -1
- package/dist/run.d.mts +1 -1
- package/dist/run.mjs +8 -7
- package/dist/{src-D_PDH4ZS.mjs → src-BhIGOkxO.mjs} +50 -43
- package/dist/{types-BMMC0pbr.d.mts → types-cXo_SNGd.d.mts} +13 -13
- package/package.json +20 -28
- package/dist/cli-BwOoKKTM.mjs +0 -46
- package/dist/cli.d.mts +0 -4
- package/dist/cli.mjs +0 -5
- package/dist/config-DsBEbB6I.mjs +0 -7
- package/dist/logger-YArsxPto.mjs +0 -144
- package/dist/migrate-Cl62m5IG.mjs +0 -126
- package/dist/migrate.d.mts +0 -10
- package/dist/migrate.mjs +0 -126
- package/dist/package-DOiAuQ-5.mjs +0 -5
- package/dist/package-DwljelGW.mjs +0 -5
- package/dist/package-TDRl9aMv.mjs +0 -5
- package/dist/src-D6AiyRka.mjs +0 -1329
- package/dist/src-lmHdfLhi.mjs +0 -1335
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
<img src="./docs/public/og-image.svg" alt="tsdown" width="100%" /><br>
|
|
2
2
|
|
|
3
|
-
# tsdown
|
|
3
|
+
# tsdown
|
|
4
|
+
|
|
5
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
6
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
7
|
+
[![Unit Test][unit-test-src]][unit-test-href]
|
|
8
|
+
[![tsdown Starter StackBlitz][tsdown-starter-stackblitz-src]][tsdown-starter-stackblitz-href]
|
|
4
9
|
|
|
5
10
|
✨ The elegant bundler for libraries powered by [Rolldown](https://github.com/rolldown/rolldown).
|
|
6
11
|
|
|
@@ -53,3 +58,14 @@ This project also partially contains code derived or copied from the following p
|
|
|
53
58
|
## Licenses
|
|
54
59
|
|
|
55
60
|
This project is licensed under the [MIT License](LICENSE).
|
|
61
|
+
|
|
62
|
+
<!-- Badges -->
|
|
63
|
+
|
|
64
|
+
[npm-version-src]: https://img.shields.io/npm/v/tsdown.svg
|
|
65
|
+
[npm-version-href]: https://npmjs.com/package/tsdown
|
|
66
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/tsdown
|
|
67
|
+
[npm-downloads-href]: https://www.npmcharts.com/compare/tsdown?interval=30
|
|
68
|
+
[unit-test-src]: https://github.com/rolldown/tsdown/actions/workflows/unit-test.yml/badge.svg
|
|
69
|
+
[unit-test-href]: https://github.com/rolldown/tsdown/actions/workflows/unit-test.yml
|
|
70
|
+
[tsdown-starter-stackblitz-src]: https://developer.stackblitz.com/img/open_in_stackblitz_small.svg
|
|
71
|
+
[tsdown-starter-stackblitz-href]: https://stackblitz.com/github/rolldown/tsdown-starter-stackblitz
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { UserConfig, UserConfigFn } from "./types-
|
|
2
|
-
import { defineConfig } from "./config-
|
|
1
|
+
import { UserConfig, UserConfigFn } from "./types-cXo_SNGd.mjs";
|
|
2
|
+
import { defineConfig } from "./config-DwMASPo6.mjs";
|
|
3
3
|
export { UserConfig, UserConfigFn, defineConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, UserConfig, UserConfigFn, Workspace, globalLogger } from "./types-
|
|
2
|
-
import { defineConfig } from "./config-
|
|
1
|
+
import { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, UserConfig, UserConfigFn, Workspace, globalLogger } from "./types-cXo_SNGd.mjs";
|
|
2
|
+
import { defineConfig } from "./config-DwMASPo6.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "./config-CCGWF4al.mjs";
|
|
2
|
-
import { build, buildSingle, shimFile } from "./src-
|
|
2
|
+
import { build, buildSingle, shimFile } from "./src-BhIGOkxO.mjs";
|
|
3
3
|
import { globalLogger } from "./logger-CGMSjTLn.mjs";
|
|
4
4
|
|
|
5
5
|
export { build, buildSingle, defineConfig, globalLogger, shimFile };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { globalLogger } from "./logger-CGMSjTLn.mjs";
|
|
2
|
-
import { version } from "./package-
|
|
2
|
+
import { version } from "./package-DOwY1eta.mjs";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { bold, green, underline } from "ansis";
|
|
5
5
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
@@ -33,6 +33,11 @@ async function migrate({ cwd, dryRun }) {
|
|
|
33
33
|
process.exitCode = 1;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
const DEP_FIELDS = {
|
|
37
|
+
dependencies: `^${version}`,
|
|
38
|
+
devDependencies: `^${version}`,
|
|
39
|
+
peerDependencies: "*"
|
|
40
|
+
};
|
|
36
41
|
async function migratePackageJson(dryRun) {
|
|
37
42
|
if (!existsSync("package.json")) {
|
|
38
43
|
globalLogger.error("No package.json found");
|
|
@@ -40,22 +45,11 @@ async function migratePackageJson(dryRun) {
|
|
|
40
45
|
}
|
|
41
46
|
const pkgRaw = await readFile("package.json", "utf-8");
|
|
42
47
|
let pkg = JSON.parse(pkgRaw);
|
|
43
|
-
const semver = `^${version}`;
|
|
44
48
|
let found = false;
|
|
45
|
-
if (pkg
|
|
46
|
-
globalLogger.info(
|
|
49
|
+
for (const [field, semver] of Object.entries(DEP_FIELDS)) if (pkg[field]?.tsup) {
|
|
50
|
+
globalLogger.info(`Migrating \`${field}\` to tsdown.`);
|
|
47
51
|
found = true;
|
|
48
|
-
pkg
|
|
49
|
-
}
|
|
50
|
-
if (pkg.devDependencies?.tsup) {
|
|
51
|
-
globalLogger.info("Migrating `devDependencies` to tsdown.");
|
|
52
|
-
found = true;
|
|
53
|
-
pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
|
|
54
|
-
}
|
|
55
|
-
if (pkg.peerDependencies?.tsup) {
|
|
56
|
-
globalLogger.info("Migrating `peerDependencies` to tsdown.");
|
|
57
|
-
found = true;
|
|
58
|
-
pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
|
|
52
|
+
pkg[field] = renameKey(pkg[field], "tsup", "tsdown", semver);
|
|
59
53
|
}
|
|
60
54
|
if (pkg.scripts) {
|
|
61
55
|
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
@@ -73,7 +67,7 @@ async function migratePackageJson(dryRun) {
|
|
|
73
67
|
globalLogger.warn("No tsup-related fields found in package.json");
|
|
74
68
|
return false;
|
|
75
69
|
}
|
|
76
|
-
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
70
|
+
const pkgStr = `${JSON.stringify(pkg, null, pkgRaw.includes(" ") ? " " : 2)}\n`;
|
|
77
71
|
if (dryRun) {
|
|
78
72
|
const { createPatch } = await import("diff");
|
|
79
73
|
globalLogger.info("[dry-run] package.json:");
|
package/dist/plugins.d.mts
CHANGED
package/dist/plugins.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./config-CCGWF4al.mjs";
|
|
2
|
-
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-
|
|
2
|
+
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-BhIGOkxO.mjs";
|
|
3
3
|
import "./logger-CGMSjTLn.mjs";
|
|
4
4
|
|
|
5
5
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/run.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { globalLogger, resolveComma, toArray } from "./logger-CGMSjTLn.mjs";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-DOwY1eta.mjs";
|
|
4
4
|
import module from "node:module";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { dim } from "ansis";
|
|
7
7
|
import { VERSION } from "rolldown";
|
|
8
|
-
import
|
|
8
|
+
import Debug from "debug";
|
|
9
9
|
import { cac } from "cac";
|
|
10
10
|
|
|
11
11
|
//#region src/cli.ts
|
|
@@ -22,7 +22,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
22
22
|
await build$1(flags);
|
|
23
23
|
});
|
|
24
24
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
25
|
-
const { migrate } = await import("./migrate-
|
|
25
|
+
const { migrate } = await import("./migrate-DQpxfr1J.mjs");
|
|
26
26
|
await migrate(args);
|
|
27
27
|
});
|
|
28
28
|
async function runCLI() {
|
|
@@ -31,10 +31,10 @@ async function runCLI() {
|
|
|
31
31
|
let namespace;
|
|
32
32
|
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
33
33
|
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
34
|
-
const enabled =
|
|
34
|
+
const enabled = Debug.disable();
|
|
35
35
|
if (enabled) namespace += `,${enabled}`;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
Debug.enable(namespace);
|
|
37
|
+
Debug("tsdown:debug")("Debugging enabled", namespace);
|
|
38
38
|
}
|
|
39
39
|
try {
|
|
40
40
|
await cli.runMatchedCommand();
|
|
@@ -51,4 +51,5 @@ try {
|
|
|
51
51
|
} catch {}
|
|
52
52
|
runCLI();
|
|
53
53
|
|
|
54
|
-
//#endregion
|
|
54
|
+
//#endregion
|
|
55
|
+
export { };
|
|
@@ -11,7 +11,7 @@ import child_process from "node:child_process";
|
|
|
11
11
|
import { access, chmod, cp, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
|
-
import
|
|
14
|
+
import Debug from "debug";
|
|
15
15
|
import coerce from "semver/functions/coerce.js";
|
|
16
16
|
import satisfies from "semver/functions/satisfies.js";
|
|
17
17
|
import { glob } from "tinyglobby";
|
|
@@ -66,7 +66,7 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
68
|
//#region src/features/attw.ts
|
|
69
|
-
const debug$
|
|
69
|
+
const debug$7 = Debug("tsdown:attw");
|
|
70
70
|
const exec$1 = promisify(child_process.exec);
|
|
71
71
|
/**
|
|
72
72
|
* ATTW profiles.
|
|
@@ -113,7 +113,7 @@ async function attw(options) {
|
|
|
113
113
|
}
|
|
114
114
|
const { profile = "strict", level = "warn",...attwOptions } = options.attw === true ? {} : options.attw;
|
|
115
115
|
const t = performance.now();
|
|
116
|
-
debug$
|
|
116
|
+
debug$7("Running attw check");
|
|
117
117
|
const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
|
|
118
118
|
let attwCore;
|
|
119
119
|
try {
|
|
@@ -147,7 +147,7 @@ async function attw(options) {
|
|
|
147
147
|
} else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
148
148
|
} catch (error) {
|
|
149
149
|
options.logger.error("ATTW check failed:", error);
|
|
150
|
-
debug$
|
|
150
|
+
debug$7("Found errors, setting exit code to 1");
|
|
151
151
|
process.exitCode = 1;
|
|
152
152
|
} finally {
|
|
153
153
|
await fsRemove(tempDir);
|
|
@@ -172,7 +172,7 @@ function warnLegacyCJS(config) {
|
|
|
172
172
|
|
|
173
173
|
//#endregion
|
|
174
174
|
//#region src/features/clean.ts
|
|
175
|
-
const debug$
|
|
175
|
+
const debug$6 = Debug("tsdown:clean");
|
|
176
176
|
const RE_LAST_SLASH = /[/\\]$/;
|
|
177
177
|
async function cleanOutDir(configs) {
|
|
178
178
|
const removes = /* @__PURE__ */ new Set();
|
|
@@ -181,8 +181,7 @@ async function cleanOutDir(configs) {
|
|
|
181
181
|
const files = await glob(config.clean, {
|
|
182
182
|
cwd: config.cwd,
|
|
183
183
|
absolute: true,
|
|
184
|
-
onlyFiles: false
|
|
185
|
-
expandDirectories: false
|
|
184
|
+
onlyFiles: false
|
|
186
185
|
});
|
|
187
186
|
const normalizedOutDir = config.outDir.replace(RE_LAST_SLASH, "");
|
|
188
187
|
for (const file of files) {
|
|
@@ -193,10 +192,10 @@ async function cleanOutDir(configs) {
|
|
|
193
192
|
if (!removes.size) return;
|
|
194
193
|
globalLogger.info(`Cleaning ${removes.size} files`);
|
|
195
194
|
await Promise.all([...removes].map(async (file) => {
|
|
196
|
-
debug$
|
|
195
|
+
debug$6("Removing", file);
|
|
197
196
|
await fsRemove(file);
|
|
198
197
|
}));
|
|
199
|
-
debug$
|
|
198
|
+
debug$6("Removed %d files", removes.size);
|
|
200
199
|
}
|
|
201
200
|
function resolveClean(clean, outDir, cwd) {
|
|
202
201
|
if (clean === true) clean = [slash(outDir)];
|
|
@@ -327,6 +326,18 @@ function exportMeta(exports, all) {
|
|
|
327
326
|
if (all) exports["./*"] = "./*";
|
|
328
327
|
else exports["./package.json"] = "./package.json";
|
|
329
328
|
}
|
|
329
|
+
function hasExportsTypes(pkg) {
|
|
330
|
+
const exports = pkg?.exports;
|
|
331
|
+
if (!exports) return false;
|
|
332
|
+
if (typeof exports === "object" && exports !== null && !Array.isArray(exports)) {
|
|
333
|
+
if ("types" in exports) return true;
|
|
334
|
+
if ("." in exports) {
|
|
335
|
+
const mainExport = exports["."];
|
|
336
|
+
if (typeof mainExport === "object" && mainExport !== null && "types" in mainExport) return true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
330
341
|
|
|
331
342
|
//#endregion
|
|
332
343
|
//#region src/features/hooks.ts
|
|
@@ -346,7 +357,7 @@ async function createHooks$1(options) {
|
|
|
346
357
|
|
|
347
358
|
//#endregion
|
|
348
359
|
//#region src/features/publint.ts
|
|
349
|
-
const debug$
|
|
360
|
+
const debug$5 = Debug("tsdown:publint");
|
|
350
361
|
async function publint(options) {
|
|
351
362
|
if (!options.publint) return;
|
|
352
363
|
if (!options.pkg) {
|
|
@@ -354,11 +365,11 @@ async function publint(options) {
|
|
|
354
365
|
return;
|
|
355
366
|
}
|
|
356
367
|
const t = performance.now();
|
|
357
|
-
debug$
|
|
368
|
+
debug$5("Running publint");
|
|
358
369
|
const { publint: publint$1 } = await import("publint");
|
|
359
370
|
const { formatMessage } = await import("publint/utils");
|
|
360
371
|
const { messages } = await publint$1(options.publint === true ? {} : options.publint);
|
|
361
|
-
debug$
|
|
372
|
+
debug$5("Found %d issues", messages.length);
|
|
362
373
|
if (!messages.length) options.logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
363
374
|
let hasError = false;
|
|
364
375
|
for (const message of messages) {
|
|
@@ -372,7 +383,7 @@ async function publint(options) {
|
|
|
372
383
|
options.logger[logType](formattedMessage);
|
|
373
384
|
}
|
|
374
385
|
if (hasError) {
|
|
375
|
-
debug$
|
|
386
|
+
debug$5("Found errors, setting exit code to 1");
|
|
376
387
|
process.exitCode = 1;
|
|
377
388
|
}
|
|
378
389
|
}
|
|
@@ -483,11 +494,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, name) {
|
|
|
483
494
|
|
|
484
495
|
//#endregion
|
|
485
496
|
//#region src/utils/package.ts
|
|
486
|
-
const debug$
|
|
497
|
+
const debug$4 = Debug("tsdown:package");
|
|
487
498
|
async function readPackageJson(dir) {
|
|
488
499
|
const packageJsonPath = up$1({ cwd: dir });
|
|
489
500
|
if (!packageJsonPath) return;
|
|
490
|
-
debug$
|
|
501
|
+
debug$4("Reading package.json:", packageJsonPath);
|
|
491
502
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
492
503
|
return {
|
|
493
504
|
...JSON.parse(contents),
|
|
@@ -603,7 +614,7 @@ async function loadConfigFile(options, workspace) {
|
|
|
603
614
|
|
|
604
615
|
//#endregion
|
|
605
616
|
//#region src/options/index.ts
|
|
606
|
-
const debug$
|
|
617
|
+
const debug$3 = Debug("tsdown:options");
|
|
607
618
|
const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
608
619
|
"**/node_modules/**",
|
|
609
620
|
"**/dist/**",
|
|
@@ -611,20 +622,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
|
611
622
|
"**/t?(e)mp/**"
|
|
612
623
|
];
|
|
613
624
|
async function resolveOptions(options) {
|
|
614
|
-
debug$
|
|
625
|
+
debug$3("options %O", options);
|
|
615
626
|
const { configs: rootConfigs, file } = await loadConfigFile(options);
|
|
616
627
|
const files = [];
|
|
617
628
|
if (file) {
|
|
618
629
|
files.push(file);
|
|
619
|
-
debug$
|
|
620
|
-
debug$
|
|
621
|
-
} else debug$
|
|
630
|
+
debug$3("loaded root config file %s", file);
|
|
631
|
+
debug$3("root configs %O", rootConfigs);
|
|
632
|
+
} else debug$3("no root config file found");
|
|
622
633
|
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
623
634
|
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
|
|
624
635
|
if (workspaceFiles) files.push(...workspaceFiles);
|
|
625
636
|
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
|
|
626
637
|
}))).flat();
|
|
627
|
-
debug$
|
|
638
|
+
debug$3("resolved configs %O", configs);
|
|
628
639
|
return {
|
|
629
640
|
configs,
|
|
630
641
|
files
|
|
@@ -644,14 +655,12 @@ async function resolveWorkspace(config, options) {
|
|
|
644
655
|
if (workspace === true) workspace = {};
|
|
645
656
|
else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
|
|
646
657
|
let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
|
|
647
|
-
if (packages === "auto") packages = (await glob({
|
|
648
|
-
patterns: "**/package.json",
|
|
658
|
+
if (packages === "auto") packages = (await glob("**/package.json", {
|
|
649
659
|
ignore: exclude,
|
|
650
660
|
cwd: rootCwd,
|
|
651
661
|
expandDirectories: false
|
|
652
662
|
})).filter((file) => file !== "package.json").map((file) => slash(path.resolve(rootCwd, file, "..")));
|
|
653
|
-
else packages = (await glob({
|
|
654
|
-
patterns: packages,
|
|
663
|
+
else packages = (await glob(packages, {
|
|
655
664
|
ignore: exclude,
|
|
656
665
|
cwd: rootCwd,
|
|
657
666
|
onlyDirectories: true,
|
|
@@ -668,16 +677,16 @@ async function resolveWorkspace(config, options) {
|
|
|
668
677
|
}
|
|
669
678
|
const files = [];
|
|
670
679
|
const configs = (await Promise.all(packages.map(async (cwd) => {
|
|
671
|
-
debug$
|
|
680
|
+
debug$3("loading workspace config %s", cwd);
|
|
672
681
|
const { configs: configs$1, file } = await loadConfigFile({
|
|
673
682
|
...options,
|
|
674
683
|
config: workspaceConfig,
|
|
675
684
|
cwd
|
|
676
685
|
}, cwd);
|
|
677
686
|
if (file) {
|
|
678
|
-
debug$
|
|
687
|
+
debug$3("loaded workspace config file %s", file);
|
|
679
688
|
files.push(file);
|
|
680
|
-
} else debug$
|
|
689
|
+
} else debug$3("no workspace config file found in %s", cwd);
|
|
681
690
|
return configs$1.map((config$1) => ({
|
|
682
691
|
...normalized,
|
|
683
692
|
cwd,
|
|
@@ -702,7 +711,7 @@ async function resolveConfig(userConfig) {
|
|
|
702
711
|
const pkg = await readPackageJson(cwd);
|
|
703
712
|
if (workspace) name ||= pkg?.name;
|
|
704
713
|
entry = await resolveEntry(logger, entry, cwd, name);
|
|
705
|
-
if (dts == null) dts = !!(pkg?.types || pkg?.typings);
|
|
714
|
+
if (dts == null) dts = !!(pkg?.types || pkg?.typings || hasExportsTypes(pkg));
|
|
706
715
|
target = resolveTarget(logger, target, pkg, name);
|
|
707
716
|
tsconfig = await resolveTsconfig(logger, tsconfig, cwd, name);
|
|
708
717
|
if (typeof external === "string") external = resolveRegex(external);
|
|
@@ -774,7 +783,7 @@ async function mergeUserOptions(defaults, user, args) {
|
|
|
774
783
|
|
|
775
784
|
//#endregion
|
|
776
785
|
//#region src/features/external.ts
|
|
777
|
-
const debug$
|
|
786
|
+
const debug$2 = Debug("tsdown:external");
|
|
778
787
|
function ExternalPlugin(options) {
|
|
779
788
|
const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
|
|
780
789
|
return {
|
|
@@ -802,7 +811,7 @@ function ExternalPlugin(options) {
|
|
|
802
811
|
}
|
|
803
812
|
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
804
813
|
if (shouldExternal) {
|
|
805
|
-
debug$
|
|
814
|
+
debug$2("External dependency:", id);
|
|
806
815
|
return {
|
|
807
816
|
id,
|
|
808
817
|
external: shouldExternal,
|
|
@@ -959,7 +968,7 @@ function formatBytes(bytes) {
|
|
|
959
968
|
|
|
960
969
|
//#endregion
|
|
961
970
|
//#region src/features/report.ts
|
|
962
|
-
const debug$
|
|
971
|
+
const debug$1 = Debug("tsdown:report");
|
|
963
972
|
const brotliCompressAsync = promisify(brotliCompress);
|
|
964
973
|
const gzipAsync = promisify(gzip);
|
|
965
974
|
function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
|
|
@@ -1000,19 +1009,19 @@ function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
|
|
|
1000
1009
|
};
|
|
1001
1010
|
}
|
|
1002
1011
|
async function calcSize(options, chunk) {
|
|
1003
|
-
debug$
|
|
1012
|
+
debug$1(`Calculating size for`, chunk.fileName);
|
|
1004
1013
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
1005
1014
|
const raw = Buffer.byteLength(content, "utf8");
|
|
1006
|
-
debug$
|
|
1015
|
+
debug$1("[size]", chunk.fileName, raw);
|
|
1007
1016
|
let gzip$1 = Infinity;
|
|
1008
1017
|
let brotli = Infinity;
|
|
1009
|
-
if (raw > (options.maxCompressSize ?? 1e6)) debug$
|
|
1018
|
+
if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
1010
1019
|
else {
|
|
1011
1020
|
gzip$1 = (await gzipAsync(content)).length;
|
|
1012
|
-
debug$
|
|
1021
|
+
debug$1("[gzip]", chunk.fileName, gzip$1);
|
|
1013
1022
|
if (options.brotli) {
|
|
1014
1023
|
brotli = (await brotliCompressAsync(content)).length;
|
|
1015
|
-
debug$
|
|
1024
|
+
debug$1("[brotli]", chunk.fileName, brotli);
|
|
1016
1025
|
}
|
|
1017
1026
|
}
|
|
1018
1027
|
return {
|
|
@@ -1059,7 +1068,7 @@ function getShimsInject(format, platform) {
|
|
|
1059
1068
|
|
|
1060
1069
|
//#endregion
|
|
1061
1070
|
//#region src/features/rolldown.ts
|
|
1062
|
-
const debug
|
|
1071
|
+
const debug = Debug("tsdown:rolldown");
|
|
1063
1072
|
async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
|
|
1064
1073
|
const inputOptions = await resolveInputOptions(config, format, cjsDts, isMultiFormat);
|
|
1065
1074
|
const outputOptions = await resolveOutputOptions(inputOptions, config, format, cjsDts);
|
|
@@ -1067,7 +1076,7 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
|
|
|
1067
1076
|
...inputOptions,
|
|
1068
1077
|
output: outputOptions
|
|
1069
1078
|
};
|
|
1070
|
-
debug
|
|
1079
|
+
debug("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
|
|
1071
1080
|
return rolldownConfig;
|
|
1072
1081
|
}
|
|
1073
1082
|
async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
@@ -1102,10 +1111,8 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
1102
1111
|
input: entry,
|
|
1103
1112
|
cwd,
|
|
1104
1113
|
external,
|
|
1105
|
-
resolve: {
|
|
1106
|
-
|
|
1107
|
-
tsconfigFilename: tsconfig || void 0
|
|
1108
|
-
},
|
|
1114
|
+
resolve: { alias },
|
|
1115
|
+
tsconfig: tsconfig || void 0,
|
|
1109
1116
|
treeshake,
|
|
1110
1117
|
platform: cjsDts || format === "cjs" ? "node" : platform,
|
|
1111
1118
|
define: {
|
|
@@ -245,6 +245,15 @@ interface Options {
|
|
|
245
245
|
* @default true
|
|
246
246
|
*/
|
|
247
247
|
treeshake?: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Sets how input files are processed.
|
|
250
|
+
* For example, use 'js' to treat files as JavaScript or 'base64' for images.
|
|
251
|
+
* Lets you import or require files like images or fonts.
|
|
252
|
+
* @example
|
|
253
|
+
* ```json
|
|
254
|
+
* { '.jpg': 'asset', '.png': 'base64' }
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
248
257
|
loader?: ModuleTypes;
|
|
249
258
|
/**
|
|
250
259
|
* If enabled, strips the `node:` protocol prefix from import source.
|
|
@@ -275,15 +284,6 @@ interface Options {
|
|
|
275
284
|
*/
|
|
276
285
|
nodeProtocol?: "strip" | boolean;
|
|
277
286
|
plugins?: InputOptions["plugins"];
|
|
278
|
-
/**
|
|
279
|
-
* Sets how input files are processed.
|
|
280
|
-
* For example, use 'js' to treat files as JavaScript or 'base64' for images.
|
|
281
|
-
* Lets you import or require files like images or fonts.
|
|
282
|
-
* @example
|
|
283
|
-
* ```json
|
|
284
|
-
* { '.jpg': 'asset', '.png': 'base64' }
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
287
|
inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat, context: {
|
|
288
288
|
cjsDts: boolean;
|
|
289
289
|
}) => Awaitable<InputOptions | void | null>);
|
|
@@ -392,11 +392,11 @@ interface Options {
|
|
|
392
392
|
*/
|
|
393
393
|
onSuccess?: string | ((config: ResolvedOptions, signal: AbortSignal) => void | Promise<void>);
|
|
394
394
|
/**
|
|
395
|
-
*
|
|
395
|
+
* Enables generation of TypeScript declaration files (`.d.ts`).
|
|
396
396
|
*
|
|
397
|
-
* By default, this
|
|
398
|
-
* - If the `types` field is present
|
|
399
|
-
* -
|
|
397
|
+
* By default, this option is auto-detected based on your project's `package.json`:
|
|
398
|
+
* - If the `types` field is present, or if the main `exports` contains a `types` entry, declaration file generation is enabled by default.
|
|
399
|
+
* - Otherwise, declaration file generation is disabled by default.
|
|
400
400
|
*/
|
|
401
401
|
dts?: boolean | DtsOptions;
|
|
402
402
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -75,44 +75,36 @@
|
|
|
75
75
|
"empathic": "^2.0.0",
|
|
76
76
|
"hookable": "^5.5.3",
|
|
77
77
|
"rolldown": "latest",
|
|
78
|
-
"rolldown-plugin-dts": "^0.15.
|
|
78
|
+
"rolldown-plugin-dts": "^0.15.8",
|
|
79
79
|
"semver": "^7.7.2",
|
|
80
80
|
"tinyexec": "^1.0.1",
|
|
81
81
|
"tinyglobby": "^0.2.14",
|
|
82
82
|
"tree-kill": "^1.2.2",
|
|
83
|
-
"unconfig": "^7.3.
|
|
83
|
+
"unconfig": "^7.3.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@arethetypeswrong/core": "^0.18.2",
|
|
87
|
-
"@sxzz/eslint-config": "^7.1.
|
|
88
|
-
"@sxzz/prettier-config": "^2.2.
|
|
89
|
-
"@sxzz/test-utils": "^0.5.
|
|
87
|
+
"@sxzz/eslint-config": "^7.1.4",
|
|
88
|
+
"@sxzz/prettier-config": "^2.2.4",
|
|
89
|
+
"@sxzz/test-utils": "^0.5.10",
|
|
90
90
|
"@types/debug": "^4.1.12",
|
|
91
|
-
"@types/node": "^24.
|
|
91
|
+
"@types/node": "^24.3.0",
|
|
92
92
|
"@types/semver": "^7.7.0",
|
|
93
93
|
"@unocss/eslint-plugin": "^66.4.2",
|
|
94
|
-
"@vueuse/core": "^13.
|
|
95
|
-
"bumpp": "^10.2.
|
|
96
|
-
"eslint": "^9.
|
|
94
|
+
"@vueuse/core": "^13.7.0",
|
|
95
|
+
"bumpp": "^10.2.3",
|
|
96
|
+
"eslint": "^9.34.0",
|
|
97
97
|
"lightningcss": "^1.30.1",
|
|
98
|
-
"
|
|
99
|
-
"pkg-types": "^2.2.0",
|
|
98
|
+
"pkg-types": "^2.3.0",
|
|
100
99
|
"prettier": "^3.6.2",
|
|
101
100
|
"publint": "^0.3.12",
|
|
102
|
-
"tsx": "^4.20.
|
|
103
|
-
"typedoc": "^0.28.9",
|
|
104
|
-
"typedoc-plugin-markdown": "^4.8.0",
|
|
105
|
-
"typedoc-vitepress-theme": "^1.1.2",
|
|
101
|
+
"tsx": "^4.20.5",
|
|
106
102
|
"typescript": "~5.9.2",
|
|
107
103
|
"unocss": "^66.4.2",
|
|
108
|
-
"unplugin-lightningcss": "^0.4.
|
|
109
|
-
"unplugin-unused": "^0.5.
|
|
104
|
+
"unplugin-lightningcss": "^0.4.2",
|
|
105
|
+
"unplugin-unused": "^0.5.2",
|
|
110
106
|
"vite": "npm:rolldown-vite@latest",
|
|
111
|
-
"
|
|
112
|
-
"vitepress-plugin-group-icons": "^1.6.2",
|
|
113
|
-
"vitepress-plugin-llms": "^1.7.2",
|
|
114
|
-
"vitest": "^3.2.4",
|
|
115
|
-
"vue": "^3.5.18"
|
|
107
|
+
"vitest": "^3.2.4"
|
|
116
108
|
},
|
|
117
109
|
"engines": {
|
|
118
110
|
"node": ">=20.19.0"
|
|
@@ -126,10 +118,10 @@
|
|
|
126
118
|
"test": "vitest",
|
|
127
119
|
"typecheck": "tsc --noEmit",
|
|
128
120
|
"format": "prettier --cache --write .",
|
|
129
|
-
"release": "bumpp
|
|
130
|
-
"docs:dev": "
|
|
131
|
-
"docs:build": "
|
|
132
|
-
"docs:preview": "
|
|
133
|
-
"docs:generate": "
|
|
121
|
+
"release": "bumpp",
|
|
122
|
+
"docs:dev": "pnpm -C docs run dev",
|
|
123
|
+
"docs:build": "pnpm -C docs run build",
|
|
124
|
+
"docs:preview": "pnpm -C docs run preview",
|
|
125
|
+
"docs:generate": "pnpm -C docs run generate"
|
|
134
126
|
}
|
|
135
127
|
}
|
package/dist/cli-BwOoKKTM.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { version } from "./package-DwljelGW.mjs";
|
|
2
|
-
import { globalLogger, resolveComma, toArray } from "./logger-YArsxPto.mjs";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import { dim } from "ansis";
|
|
5
|
-
import { cac } from "cac";
|
|
6
|
-
import debug from "debug";
|
|
7
|
-
import { VERSION } from "rolldown";
|
|
8
|
-
|
|
9
|
-
//#region src/cli.ts
|
|
10
|
-
const cli = cac("tsdown");
|
|
11
|
-
cli.help().version(version);
|
|
12
|
-
cli.command("[...files]", "Bundle files", {
|
|
13
|
-
ignoreOptionDefaultValue: true,
|
|
14
|
-
allowUnknownOptions: true
|
|
15
|
-
}).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).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").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in 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").option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
16
|
-
globalLogger.level = flags.logLevel || (flags.silent ? "silent" : "info");
|
|
17
|
-
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
18
|
-
const { build: build$1 } = await import("./index.mjs");
|
|
19
|
-
if (input.length > 0) flags.entry = input;
|
|
20
|
-
await build$1(flags);
|
|
21
|
-
});
|
|
22
|
-
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
23
|
-
const { migrate } = await import("./migrate.mjs");
|
|
24
|
-
await migrate(args);
|
|
25
|
-
});
|
|
26
|
-
async function runCLI() {
|
|
27
|
-
cli.parse(process.argv, { run: false });
|
|
28
|
-
if (cli.options.debug) {
|
|
29
|
-
let namespace;
|
|
30
|
-
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
31
|
-
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
32
|
-
const enabled = debug.disable();
|
|
33
|
-
if (enabled) namespace += `,${enabled}`;
|
|
34
|
-
debug.enable(namespace);
|
|
35
|
-
debug("tsdown:debug")("Debugging enabled", namespace);
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
await cli.runMatchedCommand();
|
|
39
|
-
} catch (error) {
|
|
40
|
-
globalLogger.error(error);
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
export { runCLI };
|