tsdown 0.14.1 → 0.15.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/LICENSE +1 -1
- package/README.md +17 -1
- package/client.d.ts +58 -0
- package/dist/{config-77IY7Jdj.d.mts → config-Dk5Fszoy.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{logger-CGMSjTLn.mjs → logger-C09npKHT.mjs} +3 -7
- package/dist/{migrate-ByqyzNKc.mjs → migrate-Di69B4rp.mjs} +12 -19
- package/dist/package-BCet0jau.mjs +5 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +2 -2
- package/dist/run.mjs +7 -7
- package/dist/{src-XtWW9dvn.mjs → src-DecVfDJY.mjs} +84 -89
- package/dist/{types-BMMC0pbr.d.mts → types-CrxW0Y6g.d.mts} +24 -17
- package/package.json +27 -33
- package/dist/package-hNMMm6hX.mjs +0 -5
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025-present VoidZero Inc. & Contributors
|
|
4
|
-
Copyright (c) 2024
|
|
4
|
+
Copyright (c) 2024 Kevin Deng (https://github.com/sxzz)
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
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/client.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
interface ImportGlobOptions<Eager extends boolean> {
|
|
2
|
+
/**
|
|
3
|
+
* Import as static or dynamic
|
|
4
|
+
*
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
eager?: Eager
|
|
8
|
+
/**
|
|
9
|
+
* Import only the specific named export. Set to `default` to import the default export.
|
|
10
|
+
*/
|
|
11
|
+
import?: string
|
|
12
|
+
/**
|
|
13
|
+
* Custom queries
|
|
14
|
+
*/
|
|
15
|
+
query?: string | Record<string, string | number | boolean>
|
|
16
|
+
/**
|
|
17
|
+
* Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
exhaustive?: boolean
|
|
22
|
+
/**
|
|
23
|
+
* Base path to resolve relative paths.
|
|
24
|
+
*/
|
|
25
|
+
base?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type GeneralImportGlobOptions = ImportGlobOptions<boolean>
|
|
29
|
+
|
|
30
|
+
interface KnownAsTypeMap {
|
|
31
|
+
raw: string
|
|
32
|
+
url: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface ImportGlobFunction {
|
|
36
|
+
/**
|
|
37
|
+
* Import a list of files with a glob pattern.
|
|
38
|
+
*
|
|
39
|
+
* Overload 1: Module generic provided, infer the type from `eager: false`
|
|
40
|
+
*/
|
|
41
|
+
<M>(
|
|
42
|
+
glob: string | string[],
|
|
43
|
+
options?: ImportGlobOptions<false>,
|
|
44
|
+
): Record<string, () => Promise<M>>
|
|
45
|
+
/**
|
|
46
|
+
* Import a list of files with a glob pattern.
|
|
47
|
+
*
|
|
48
|
+
* Overload 2: Module generic provided, infer the type from `eager: true`
|
|
49
|
+
*/
|
|
50
|
+
<M>(
|
|
51
|
+
glob: string | string[],
|
|
52
|
+
options: ImportGlobOptions<true>,
|
|
53
|
+
): Record<string, M>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ImportMeta {
|
|
57
|
+
glob: ImportGlobFunction
|
|
58
|
+
}
|
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-CrxW0Y6g.mjs";
|
|
2
|
+
import { defineConfig } from "./config-Dk5Fszoy.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-CrxW0Y6g.mjs";
|
|
2
|
+
import { defineConfig } from "./config-Dk5Fszoy.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-
|
|
3
|
-
import { globalLogger } from "./logger-
|
|
2
|
+
import { build, buildSingle, shimFile } from "./src-DecVfDJY.mjs";
|
|
3
|
+
import { globalLogger } from "./logger-C09npKHT.mjs";
|
|
4
4
|
|
|
5
5
|
export { build, buildSingle, defineConfig, globalLogger, shimFile };
|
|
@@ -45,10 +45,8 @@ const warnedMessages = /* @__PURE__ */ new Set();
|
|
|
45
45
|
function createLogger(level = "info", { customLogger, console = globalThis.console, failOnWarn = false } = {}) {
|
|
46
46
|
if (customLogger) return customLogger;
|
|
47
47
|
function output(type, msg) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const method = type === "info" ? "log" : type;
|
|
51
|
-
console[method](msg);
|
|
48
|
+
if (LogLevels[logger.level] < LogLevels[type]) return;
|
|
49
|
+
console[type === "info" ? "log" : type](msg);
|
|
52
50
|
}
|
|
53
51
|
const logger = {
|
|
54
52
|
level,
|
|
@@ -104,9 +102,7 @@ function generateColor(name = "default") {
|
|
|
104
102
|
let hash = 0;
|
|
105
103
|
for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
|
|
106
104
|
const hue = hash % 360;
|
|
107
|
-
|
|
108
|
-
const lightness = 55;
|
|
109
|
-
color = rgb(...hslToRgb(hue, saturation, lightness));
|
|
105
|
+
color = rgb(...hslToRgb(hue, 35, 55));
|
|
110
106
|
}
|
|
111
107
|
colors.set(name, color);
|
|
112
108
|
return color;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { globalLogger } from "./logger-
|
|
2
|
-
import { version } from "./package-
|
|
1
|
+
import { globalLogger } from "./logger-C09npKHT.mjs";
|
|
2
|
+
import { version } from "./package-BCet0jau.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";
|
|
@@ -17,8 +17,7 @@ async function migrate({ cwd, dryRun }) {
|
|
|
17
17
|
globalLogger.warn(`\n\nBefore proceeding, review the migration guide at ${underline`https://tsdown.dev/guide/migrate-from-tsup`}, as this process will modify your files.\nUncommitted changes will be lost. Use the ${green`--dry-run`} flag to preview changes without applying them.`);
|
|
18
18
|
const input = await rl.question(bold`Continue? (Y/n) `);
|
|
19
19
|
rl.close();
|
|
20
|
-
|
|
21
|
-
if (!confirm) {
|
|
20
|
+
if (!(input.toLowerCase() === "y" || input === "")) {
|
|
22
21
|
globalLogger.error("Migration cancelled.");
|
|
23
22
|
process.exitCode = 1;
|
|
24
23
|
return;
|
|
@@ -33,6 +32,11 @@ async function migrate({ cwd, dryRun }) {
|
|
|
33
32
|
process.exitCode = 1;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
35
|
+
const DEP_FIELDS = {
|
|
36
|
+
dependencies: `^${version}`,
|
|
37
|
+
devDependencies: `^${version}`,
|
|
38
|
+
peerDependencies: "*"
|
|
39
|
+
};
|
|
36
40
|
async function migratePackageJson(dryRun) {
|
|
37
41
|
if (!existsSync("package.json")) {
|
|
38
42
|
globalLogger.error("No package.json found");
|
|
@@ -40,22 +44,11 @@ async function migratePackageJson(dryRun) {
|
|
|
40
44
|
}
|
|
41
45
|
const pkgRaw = await readFile("package.json", "utf-8");
|
|
42
46
|
let pkg = JSON.parse(pkgRaw);
|
|
43
|
-
const semver = `^${version}`;
|
|
44
47
|
let found = false;
|
|
45
|
-
if (pkg
|
|
46
|
-
globalLogger.info(
|
|
48
|
+
for (const [field, semver] of Object.entries(DEP_FIELDS)) if (pkg[field]?.tsup) {
|
|
49
|
+
globalLogger.info(`Migrating \`${field}\` to tsdown.`);
|
|
47
50
|
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", "*");
|
|
51
|
+
pkg[field] = renameKey(pkg[field], "tsup", "tsdown", semver);
|
|
59
52
|
}
|
|
60
53
|
if (pkg.scripts) {
|
|
61
54
|
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
@@ -73,7 +66,7 @@ async function migratePackageJson(dryRun) {
|
|
|
73
66
|
globalLogger.warn("No tsup-related fields found in package.json");
|
|
74
67
|
return false;
|
|
75
68
|
}
|
|
76
|
-
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
69
|
+
const pkgStr = `${JSON.stringify(pkg, null, pkgRaw.includes(" ") ? " " : 2)}\n`;
|
|
77
70
|
if (dryRun) {
|
|
78
71
|
const { createPatch } = await import("diff");
|
|
79
72
|
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-
|
|
3
|
-
import "./logger-
|
|
2
|
+
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-DecVfDJY.mjs";
|
|
3
|
+
import "./logger-C09npKHT.mjs";
|
|
4
4
|
|
|
5
5
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { globalLogger, resolveComma, toArray } from "./logger-
|
|
3
|
-
import { version } from "./package-
|
|
2
|
+
import { globalLogger, resolveComma, toArray } from "./logger-C09npKHT.mjs";
|
|
3
|
+
import { version } from "./package-BCet0jau.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-Di69B4rp.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();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-
|
|
1
|
+
import { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-C09npKHT.mjs";
|
|
2
2
|
import { builtinModules } from "node:module";
|
|
3
3
|
import path, { dirname, normalize, sep } from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
@@ -11,12 +11,13 @@ 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";
|
|
18
18
|
import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
|
|
19
19
|
import { createHooks } from "hookable";
|
|
20
|
+
import { importGlobPlugin } from "rolldown/experimental";
|
|
20
21
|
import minVersion from "semver/ranges/min-version.js";
|
|
21
22
|
import { up } from "empathic/find";
|
|
22
23
|
import { up as up$1 } from "empathic/package";
|
|
@@ -66,7 +67,7 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
66
67
|
|
|
67
68
|
//#endregion
|
|
68
69
|
//#region src/features/attw.ts
|
|
69
|
-
const debug$
|
|
70
|
+
const debug$8 = debug("tsdown:attw");
|
|
70
71
|
const exec$1 = promisify(child_process.exec);
|
|
71
72
|
/**
|
|
72
73
|
* ATTW profiles.
|
|
@@ -93,8 +94,7 @@ function formatProblem(problem) {
|
|
|
93
94
|
case "CJSResolvesToESM": return ` ⚡ CJS resolves to ESM${resolutionKind}${entrypoint}`;
|
|
94
95
|
case "NamedExports": {
|
|
95
96
|
const missingExports = problem.missing?.length > 0 ? ` Missing: ${problem.missing.join(", ")}` : "";
|
|
96
|
-
|
|
97
|
-
return ` 📤 Named exports problem${allMissing}${missingExports}\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
|
|
97
|
+
return ` 📤 Named exports problem${problem.isMissingAllNamed ? " (all named exports missing)" : ""}${missingExports}\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
|
|
98
98
|
}
|
|
99
99
|
case "FallbackCondition": return ` 🎯 Fallback condition used${resolutionKind}${entrypoint}`;
|
|
100
100
|
case "FalseExportDefault": return ` 🎭 False export default\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
|
|
@@ -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$8("Running attw check");
|
|
117
117
|
const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
|
|
118
118
|
let attwCore;
|
|
119
119
|
try {
|
|
@@ -139,15 +139,14 @@ async function attw(options) {
|
|
|
139
139
|
return true;
|
|
140
140
|
});
|
|
141
141
|
if (problems.length) {
|
|
142
|
-
const
|
|
143
|
-
const problemMessage = `Are the types wrong problems found:\n${problemList}`;
|
|
142
|
+
const problemMessage = `Are the types wrong problems found:\n${problems.map(formatProblem).join("\n")}`;
|
|
144
143
|
if (level === "error") throw new Error(problemMessage);
|
|
145
144
|
options.logger.warn(problemMessage);
|
|
146
145
|
}
|
|
147
146
|
} else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
148
147
|
} catch (error) {
|
|
149
148
|
options.logger.error("ATTW check failed:", error);
|
|
150
|
-
debug$
|
|
149
|
+
debug$8("Found errors, setting exit code to 1");
|
|
151
150
|
process.exitCode = 1;
|
|
152
151
|
} finally {
|
|
153
152
|
await fsRemove(tempDir);
|
|
@@ -163,16 +162,15 @@ async function attw(options) {
|
|
|
163
162
|
*/
|
|
164
163
|
function warnLegacyCJS(config) {
|
|
165
164
|
if (!config.format.includes("cjs") || !config.target) return;
|
|
166
|
-
|
|
165
|
+
if (config.target.some((t) => {
|
|
167
166
|
const version = coerce(t.split("node")[1]);
|
|
168
167
|
return version && satisfies(version, ">=23.0.0 || >=22.12.0");
|
|
169
|
-
});
|
|
170
|
-
if (legacy) config.logger.warnOnce("We recommend using the ESM format instead of CommonJS.\nThe ESM format is compatible with modern platforms and runtimes, and most new libraries are now distributed only in ESM format.\nLearn more at https://nodejs.org/en/learn/modules/publishing-a-package#how-did-we-get-here");
|
|
168
|
+
})) config.logger.warnOnce("We recommend using the ESM format instead of CommonJS.\nThe ESM format is compatible with modern platforms and runtimes, and most new libraries are now distributed only in ESM format.\nLearn more at https://nodejs.org/en/learn/modules/publishing-a-package#how-did-we-get-here");
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
//#endregion
|
|
174
172
|
//#region src/features/clean.ts
|
|
175
|
-
const debug$
|
|
173
|
+
const debug$7 = debug("tsdown:clean");
|
|
176
174
|
const RE_LAST_SLASH = /[/\\]$/;
|
|
177
175
|
async function cleanOutDir(configs) {
|
|
178
176
|
const removes = /* @__PURE__ */ new Set();
|
|
@@ -184,18 +182,15 @@ async function cleanOutDir(configs) {
|
|
|
184
182
|
onlyFiles: false
|
|
185
183
|
});
|
|
186
184
|
const normalizedOutDir = config.outDir.replace(RE_LAST_SLASH, "");
|
|
187
|
-
for (const file of files)
|
|
188
|
-
const normalizedFile = file.replace(RE_LAST_SLASH, "");
|
|
189
|
-
if (normalizedFile !== normalizedOutDir) removes.add(file);
|
|
190
|
-
}
|
|
185
|
+
for (const file of files) if (file.replace(RE_LAST_SLASH, "") !== normalizedOutDir) removes.add(file);
|
|
191
186
|
}
|
|
192
187
|
if (!removes.size) return;
|
|
193
188
|
globalLogger.info(`Cleaning ${removes.size} files`);
|
|
194
189
|
await Promise.all([...removes].map(async (file) => {
|
|
195
|
-
debug$
|
|
190
|
+
debug$7("Removing", file);
|
|
196
191
|
await fsRemove(file);
|
|
197
192
|
}));
|
|
198
|
-
debug$
|
|
193
|
+
debug$7("Removed %d files", removes.size);
|
|
199
194
|
}
|
|
200
195
|
function resolveClean(clean, outDir, cwd) {
|
|
201
196
|
if (clean === true) clean = [slash(outDir)];
|
|
@@ -263,10 +258,7 @@ async function generateExports(pkg, outDir, chunks, { devExports, all, customExp
|
|
|
263
258
|
else main = distFile;
|
|
264
259
|
else if (format === "es") if (isDts) esmTypes = distFile;
|
|
265
260
|
else module$1 = distFile;
|
|
266
|
-
} else {
|
|
267
|
-
const isDirIndex = name.endsWith("/index");
|
|
268
|
-
name = isDirIndex ? `./${name.slice(0, -6)}` : `./${name}`;
|
|
269
|
-
}
|
|
261
|
+
} else name = name.endsWith("/index") ? `./${name.slice(0, -6)}` : `./${name}`;
|
|
270
262
|
let subExport = exportsMap.get(name);
|
|
271
263
|
if (!subExport) {
|
|
272
264
|
subExport = {};
|
|
@@ -326,6 +318,18 @@ function exportMeta(exports, all) {
|
|
|
326
318
|
if (all) exports["./*"] = "./*";
|
|
327
319
|
else exports["./package.json"] = "./package.json";
|
|
328
320
|
}
|
|
321
|
+
function hasExportsTypes(pkg) {
|
|
322
|
+
const exports = pkg?.exports;
|
|
323
|
+
if (!exports) return false;
|
|
324
|
+
if (typeof exports === "object" && exports !== null && !Array.isArray(exports)) {
|
|
325
|
+
if ("types" in exports) return true;
|
|
326
|
+
if ("." in exports) {
|
|
327
|
+
const mainExport = exports["."];
|
|
328
|
+
if (typeof mainExport === "object" && mainExport !== null && "types" in mainExport) return true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
329
333
|
|
|
330
334
|
//#endregion
|
|
331
335
|
//#region src/features/hooks.ts
|
|
@@ -333,19 +337,18 @@ async function createHooks$1(options) {
|
|
|
333
337
|
const hooks = createHooks();
|
|
334
338
|
if (typeof options.hooks === "object") hooks.addHooks(options.hooks);
|
|
335
339
|
else if (typeof options.hooks === "function") await options.hooks(hooks);
|
|
336
|
-
const context = {
|
|
337
|
-
options,
|
|
338
|
-
hooks
|
|
339
|
-
};
|
|
340
340
|
return {
|
|
341
341
|
hooks,
|
|
342
|
-
context
|
|
342
|
+
context: {
|
|
343
|
+
options,
|
|
344
|
+
hooks
|
|
345
|
+
}
|
|
343
346
|
};
|
|
344
347
|
}
|
|
345
348
|
|
|
346
349
|
//#endregion
|
|
347
350
|
//#region src/features/publint.ts
|
|
348
|
-
const debug$
|
|
351
|
+
const debug$6 = debug("tsdown:publint");
|
|
349
352
|
async function publint(options) {
|
|
350
353
|
if (!options.publint) return;
|
|
351
354
|
if (!options.pkg) {
|
|
@@ -353,11 +356,11 @@ async function publint(options) {
|
|
|
353
356
|
return;
|
|
354
357
|
}
|
|
355
358
|
const t = performance.now();
|
|
356
|
-
debug$
|
|
359
|
+
debug$6("Running publint");
|
|
357
360
|
const { publint: publint$1 } = await import("publint");
|
|
358
361
|
const { formatMessage } = await import("publint/utils");
|
|
359
362
|
const { messages } = await publint$1(options.publint === true ? {} : options.publint);
|
|
360
|
-
debug$
|
|
363
|
+
debug$6("Found %d issues", messages.length);
|
|
361
364
|
if (!messages.length) options.logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
362
365
|
let hasError = false;
|
|
363
366
|
for (const message of messages) {
|
|
@@ -371,7 +374,7 @@ async function publint(options) {
|
|
|
371
374
|
options.logger[logType](formattedMessage);
|
|
372
375
|
}
|
|
373
376
|
if (hasError) {
|
|
374
|
-
debug$
|
|
377
|
+
debug$6("Found errors, setting exit code to 1");
|
|
375
378
|
process.exitCode = 1;
|
|
376
379
|
}
|
|
377
380
|
}
|
|
@@ -482,11 +485,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, name) {
|
|
|
482
485
|
|
|
483
486
|
//#endregion
|
|
484
487
|
//#region src/utils/package.ts
|
|
485
|
-
const debug$
|
|
488
|
+
const debug$5 = debug("tsdown:package");
|
|
486
489
|
async function readPackageJson(dir) {
|
|
487
490
|
const packageJsonPath = up$1({ cwd: dir });
|
|
488
491
|
if (!packageJsonPath) return;
|
|
489
|
-
debug$
|
|
492
|
+
debug$5("Reading package.json:", packageJsonPath);
|
|
490
493
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
491
494
|
return {
|
|
492
495
|
...JSON.parse(contents),
|
|
@@ -577,8 +580,7 @@ async function loadConfigFile(options, workspace) {
|
|
|
577
580
|
],
|
|
578
581
|
parser: loaded || !nativeTS ? "auto" : async (filepath) => {
|
|
579
582
|
const mod = await import(pathToFileURL(filepath).href);
|
|
580
|
-
|
|
581
|
-
return config$1;
|
|
583
|
+
return mod.default || mod;
|
|
582
584
|
}
|
|
583
585
|
}, {
|
|
584
586
|
files: "package.json",
|
|
@@ -602,7 +604,7 @@ async function loadConfigFile(options, workspace) {
|
|
|
602
604
|
|
|
603
605
|
//#endregion
|
|
604
606
|
//#region src/options/index.ts
|
|
605
|
-
const debug$
|
|
607
|
+
const debug$4 = debug("tsdown:options");
|
|
606
608
|
const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
607
609
|
"**/node_modules/**",
|
|
608
610
|
"**/dist/**",
|
|
@@ -610,20 +612,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
|
610
612
|
"**/t?(e)mp/**"
|
|
611
613
|
];
|
|
612
614
|
async function resolveOptions(options) {
|
|
613
|
-
debug$
|
|
615
|
+
debug$4("options %O", options);
|
|
614
616
|
const { configs: rootConfigs, file } = await loadConfigFile(options);
|
|
615
617
|
const files = [];
|
|
616
618
|
if (file) {
|
|
617
619
|
files.push(file);
|
|
618
|
-
debug$
|
|
619
|
-
debug$
|
|
620
|
-
} else debug$
|
|
620
|
+
debug$4("loaded root config file %s", file);
|
|
621
|
+
debug$4("root configs %O", rootConfigs);
|
|
622
|
+
} else debug$4("no root config file found");
|
|
621
623
|
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
622
624
|
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
|
|
623
625
|
if (workspaceFiles) files.push(...workspaceFiles);
|
|
624
626
|
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
|
|
625
627
|
}))).flat();
|
|
626
|
-
debug$
|
|
628
|
+
debug$4("resolved configs %O", configs);
|
|
627
629
|
return {
|
|
628
630
|
configs,
|
|
629
631
|
files
|
|
@@ -664,25 +666,24 @@ async function resolveWorkspace(config, options) {
|
|
|
664
666
|
if (packages.length === 0) throw new Error("No packages matched the filters");
|
|
665
667
|
}
|
|
666
668
|
const files = [];
|
|
667
|
-
const configs = (await Promise.all(packages.map(async (cwd) => {
|
|
668
|
-
debug$3("loading workspace config %s", cwd);
|
|
669
|
-
const { configs: configs$1, file } = await loadConfigFile({
|
|
670
|
-
...options,
|
|
671
|
-
config: workspaceConfig,
|
|
672
|
-
cwd
|
|
673
|
-
}, cwd);
|
|
674
|
-
if (file) {
|
|
675
|
-
debug$3("loaded workspace config file %s", file);
|
|
676
|
-
files.push(file);
|
|
677
|
-
} else debug$3("no workspace config file found in %s", cwd);
|
|
678
|
-
return configs$1.map((config$1) => ({
|
|
679
|
-
...normalized,
|
|
680
|
-
cwd,
|
|
681
|
-
...config$1
|
|
682
|
-
}));
|
|
683
|
-
}))).flat();
|
|
684
669
|
return {
|
|
685
|
-
configs
|
|
670
|
+
configs: (await Promise.all(packages.map(async (cwd) => {
|
|
671
|
+
debug$4("loading workspace config %s", cwd);
|
|
672
|
+
const { configs, file } = await loadConfigFile({
|
|
673
|
+
...options,
|
|
674
|
+
config: workspaceConfig,
|
|
675
|
+
cwd
|
|
676
|
+
}, cwd);
|
|
677
|
+
if (file) {
|
|
678
|
+
debug$4("loaded workspace config file %s", file);
|
|
679
|
+
files.push(file);
|
|
680
|
+
} else debug$4("no workspace config file found in %s", cwd);
|
|
681
|
+
return configs.map((config$1) => ({
|
|
682
|
+
...normalized,
|
|
683
|
+
cwd,
|
|
684
|
+
...config$1
|
|
685
|
+
}));
|
|
686
|
+
}))).flat(),
|
|
686
687
|
files
|
|
687
688
|
};
|
|
688
689
|
}
|
|
@@ -693,13 +694,14 @@ async function resolveConfig(userConfig) {
|
|
|
693
694
|
failOnWarn
|
|
694
695
|
});
|
|
695
696
|
if (typeof bundle === "boolean") logger.warn("`bundle` option is deprecated. Use `unbundle` instead.");
|
|
697
|
+
if (removeNodeProtocol && nodeProtocol) throw new TypeError("`removeNodeProtocol` is deprecated. Please only use `nodeProtocol` instead.");
|
|
696
698
|
nodeProtocol = nodeProtocol ?? (removeNodeProtocol ? "strip" : false);
|
|
697
699
|
outDir = path.resolve(cwd, outDir);
|
|
698
700
|
clean = resolveClean(clean, outDir, cwd);
|
|
699
701
|
const pkg = await readPackageJson(cwd);
|
|
700
702
|
if (workspace) name ||= pkg?.name;
|
|
701
703
|
entry = await resolveEntry(logger, entry, cwd, name);
|
|
702
|
-
if (dts == null) dts = !!(pkg?.types || pkg?.typings);
|
|
704
|
+
if (dts == null) dts = !!(pkg?.types || pkg?.typings || hasExportsTypes(pkg));
|
|
703
705
|
target = resolveTarget(logger, target, pkg, name);
|
|
704
706
|
tsconfig = await resolveTsconfig(logger, tsconfig, cwd, name);
|
|
705
707
|
if (typeof external === "string") external = resolveRegex(external);
|
|
@@ -723,7 +725,7 @@ async function resolveConfig(userConfig) {
|
|
|
723
725
|
if (typeof ignore === "string") return path.resolve(cwd, ignore);
|
|
724
726
|
return ignore;
|
|
725
727
|
});
|
|
726
|
-
|
|
728
|
+
return {
|
|
727
729
|
...userConfig,
|
|
728
730
|
entry,
|
|
729
731
|
plugins,
|
|
@@ -759,7 +761,6 @@ async function resolveConfig(userConfig) {
|
|
|
759
761
|
nodeProtocol,
|
|
760
762
|
cjsDefault
|
|
761
763
|
};
|
|
762
|
-
return config;
|
|
763
764
|
}
|
|
764
765
|
async function mergeUserOptions(defaults, user, args) {
|
|
765
766
|
const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
|
|
@@ -771,7 +772,7 @@ async function mergeUserOptions(defaults, user, args) {
|
|
|
771
772
|
|
|
772
773
|
//#endregion
|
|
773
774
|
//#region src/features/external.ts
|
|
774
|
-
const debug$
|
|
775
|
+
const debug$3 = debug("tsdown:external");
|
|
775
776
|
function ExternalPlugin(options) {
|
|
776
777
|
const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
|
|
777
778
|
return {
|
|
@@ -782,8 +783,7 @@ function ExternalPlugin(options) {
|
|
|
782
783
|
const { noExternal } = options;
|
|
783
784
|
if (typeof noExternal === "function" && noExternal(id, importer)) return;
|
|
784
785
|
if (noExternal) {
|
|
785
|
-
|
|
786
|
-
if (noExternalPatterns.some((pattern) => {
|
|
786
|
+
if (toArray(noExternal).some((pattern) => {
|
|
787
787
|
if (pattern instanceof RegExp) {
|
|
788
788
|
pattern.lastIndex = 0;
|
|
789
789
|
return pattern.test(id);
|
|
@@ -799,7 +799,7 @@ function ExternalPlugin(options) {
|
|
|
799
799
|
}
|
|
800
800
|
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
801
801
|
if (shouldExternal) {
|
|
802
|
-
debug$
|
|
802
|
+
debug$3("External dependency:", id);
|
|
803
803
|
return {
|
|
804
804
|
id,
|
|
805
805
|
external: shouldExternal,
|
|
@@ -824,8 +824,7 @@ function getProductionDeps(pkg) {
|
|
|
824
824
|
*/
|
|
825
825
|
function esbuildTargetToLightningCSS(target) {
|
|
826
826
|
let targets;
|
|
827
|
-
const
|
|
828
|
-
const matches = [...targetString.matchAll(TARGET_REGEX)];
|
|
827
|
+
const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
|
|
829
828
|
for (const match of matches) {
|
|
830
829
|
const name = match[1];
|
|
831
830
|
const browser = ESBUILD_LIGHTNINGCSS_MAPPING[name];
|
|
@@ -866,6 +865,7 @@ async function LightningCSSPlugin(options) {
|
|
|
866
865
|
|
|
867
866
|
//#endregion
|
|
868
867
|
//#region src/features/node-protocol.ts
|
|
868
|
+
const modulesWithoutProtocol = builtinModules.filter((mod) => !mod.startsWith("node:"));
|
|
869
869
|
/**
|
|
870
870
|
* The `node:` protocol was added in Node.js v14.18.0.
|
|
871
871
|
* @see https://nodejs.org/api/esm.html#node-imports
|
|
@@ -875,7 +875,7 @@ function NodeProtocolPlugin(nodeProtocolOption) {
|
|
|
875
875
|
name: "tsdown:node-protocol:strip",
|
|
876
876
|
resolveId: {
|
|
877
877
|
order: "pre",
|
|
878
|
-
filter: { id:
|
|
878
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^node:(${modulesWithoutProtocol.join("|")})$`) },
|
|
879
879
|
handler(id) {
|
|
880
880
|
return {
|
|
881
881
|
id: id.slice(5),
|
|
@@ -885,12 +885,11 @@ function NodeProtocolPlugin(nodeProtocolOption) {
|
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
};
|
|
888
|
-
const builtinModulesRegex = /* @__PURE__ */ new RegExp(`^(${builtinModules.join("|")})$`);
|
|
889
888
|
return {
|
|
890
889
|
name: "tsdown:node-protocol:add",
|
|
891
890
|
resolveId: {
|
|
892
891
|
order: "pre",
|
|
893
|
-
filter: { id:
|
|
892
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^(${modulesWithoutProtocol.join("|")})$`) },
|
|
894
893
|
handler(id) {
|
|
895
894
|
return {
|
|
896
895
|
id: `node:${id}`,
|
|
@@ -956,7 +955,7 @@ function formatBytes(bytes) {
|
|
|
956
955
|
|
|
957
956
|
//#endregion
|
|
958
957
|
//#region src/features/report.ts
|
|
959
|
-
const debug$
|
|
958
|
+
const debug$2 = debug("tsdown:report");
|
|
960
959
|
const brotliCompressAsync = promisify(brotliCompress);
|
|
961
960
|
const gzipAsync = promisify(gzip);
|
|
962
961
|
function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
|
|
@@ -997,19 +996,19 @@ function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
|
|
|
997
996
|
};
|
|
998
997
|
}
|
|
999
998
|
async function calcSize(options, chunk) {
|
|
1000
|
-
debug$
|
|
999
|
+
debug$2(`Calculating size for`, chunk.fileName);
|
|
1001
1000
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
1002
1001
|
const raw = Buffer.byteLength(content, "utf8");
|
|
1003
|
-
debug$
|
|
1002
|
+
debug$2("[size]", chunk.fileName, raw);
|
|
1004
1003
|
let gzip$1 = Infinity;
|
|
1005
1004
|
let brotli = Infinity;
|
|
1006
|
-
if (raw > (options.maxCompressSize ?? 1e6)) debug$
|
|
1005
|
+
if (raw > (options.maxCompressSize ?? 1e6)) debug$2(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
1007
1006
|
else {
|
|
1008
1007
|
gzip$1 = (await gzipAsync(content)).length;
|
|
1009
|
-
debug$
|
|
1008
|
+
debug$2("[gzip]", chunk.fileName, gzip$1);
|
|
1010
1009
|
if (options.brotli) {
|
|
1011
1010
|
brotli = (await brotliCompressAsync(content)).length;
|
|
1012
|
-
debug$
|
|
1011
|
+
debug$2("[brotli]", chunk.fileName, brotli);
|
|
1013
1012
|
}
|
|
1014
1013
|
}
|
|
1015
1014
|
return {
|
|
@@ -1056,7 +1055,7 @@ function getShimsInject(format, platform) {
|
|
|
1056
1055
|
|
|
1057
1056
|
//#endregion
|
|
1058
1057
|
//#region src/features/rolldown.ts
|
|
1059
|
-
const debug =
|
|
1058
|
+
const debug$1 = debug("tsdown:rolldown");
|
|
1060
1059
|
async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
|
|
1061
1060
|
const inputOptions = await resolveInputOptions(config, format, cjsDts, isMultiFormat);
|
|
1062
1061
|
const outputOptions = await resolveOutputOptions(inputOptions, config, format, cjsDts);
|
|
@@ -1064,7 +1063,7 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
|
|
|
1064
1063
|
...inputOptions,
|
|
1065
1064
|
output: outputOptions
|
|
1066
1065
|
};
|
|
1067
|
-
debug("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
|
|
1066
|
+
debug$1("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
|
|
1068
1067
|
return rolldownConfig;
|
|
1069
1068
|
}
|
|
1070
1069
|
async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
@@ -1091,18 +1090,16 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
1091
1090
|
plugins.push(Unused.rolldown(unused === true ? {} : unused));
|
|
1092
1091
|
}
|
|
1093
1092
|
if (target) plugins.push(RuntimeHelperCheckPlugin(logger, target), await LightningCSSPlugin({ target }));
|
|
1094
|
-
plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat));
|
|
1093
|
+
plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat), importGlobPlugin());
|
|
1095
1094
|
}
|
|
1096
1095
|
if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(report, logger, cwd, cjsDts, name, isMultiFormat));
|
|
1097
1096
|
if (!cjsDts) plugins.push(userPlugins);
|
|
1098
|
-
|
|
1097
|
+
return await mergeUserOptions({
|
|
1099
1098
|
input: entry,
|
|
1100
1099
|
cwd,
|
|
1101
1100
|
external,
|
|
1102
|
-
resolve: {
|
|
1103
|
-
|
|
1104
|
-
tsconfigFilename: tsconfig || void 0
|
|
1105
|
-
},
|
|
1101
|
+
resolve: { alias },
|
|
1102
|
+
tsconfig: tsconfig || void 0,
|
|
1106
1103
|
treeshake,
|
|
1107
1104
|
platform: cjsDts || format === "cjs" ? "node" : platform,
|
|
1108
1105
|
define: {
|
|
@@ -1123,12 +1120,11 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
1123
1120
|
defaultHandler(level, log);
|
|
1124
1121
|
} : void 0
|
|
1125
1122
|
}, config.inputOptions, [format, { cjsDts }]);
|
|
1126
|
-
return inputOptions;
|
|
1127
1123
|
}
|
|
1128
1124
|
async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
1129
1125
|
const { entry, outDir, sourcemap, minify, unbundle, banner, footer, cjsDefault } = config;
|
|
1130
1126
|
const [entryFileNames, chunkFileNames] = resolveChunkFilename(config, inputOptions, format);
|
|
1131
|
-
|
|
1127
|
+
return await mergeUserOptions({
|
|
1132
1128
|
format: cjsDts ? "es" : format,
|
|
1133
1129
|
name: config.globalName,
|
|
1134
1130
|
sourcemap,
|
|
@@ -1142,7 +1138,6 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
|
1142
1138
|
banner: resolveChunkAddon(banner, format),
|
|
1143
1139
|
footer: resolveChunkAddon(footer, format)
|
|
1144
1140
|
}, config.outputOptions, [format, { cjsDts }]);
|
|
1145
|
-
return outputOptions;
|
|
1146
1141
|
}
|
|
1147
1142
|
|
|
1148
1143
|
//#endregion
|
|
@@ -209,8 +209,9 @@ interface Options {
|
|
|
209
209
|
*
|
|
210
210
|
* Determines the JavaScript version or runtime(s) for which the code should be compiled.
|
|
211
211
|
* If not set, defaults to the value of `engines.node` in your project's `package.json`.
|
|
212
|
+
* If no `engines.node` field exists, no syntax transformations are applied.
|
|
212
213
|
*
|
|
213
|
-
* Accepts a single target (e.g., `'es2020'`, `'node18'`)
|
|
214
|
+
* Accepts a single target (e.g., `'es2020'`, `'node18'`), an array of targets, or `false` to disable all transformations.
|
|
214
215
|
*
|
|
215
216
|
* @see {@link https://tsdown.dev/options/target#supported-targets} for a list of valid targets and more details.
|
|
216
217
|
*
|
|
@@ -225,6 +226,12 @@ interface Options {
|
|
|
225
226
|
* // Target multiple environments
|
|
226
227
|
* { "target": ["node18", "es2020"] }
|
|
227
228
|
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```jsonc
|
|
232
|
+
* // Disable all syntax transformations
|
|
233
|
+
* { "target": false }
|
|
234
|
+
* ```
|
|
228
235
|
*/
|
|
229
236
|
target?: string | string[] | false;
|
|
230
237
|
/**
|
|
@@ -245,6 +252,15 @@ interface Options {
|
|
|
245
252
|
* @default true
|
|
246
253
|
*/
|
|
247
254
|
treeshake?: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Sets how input files are processed.
|
|
257
|
+
* For example, use 'js' to treat files as JavaScript or 'base64' for images.
|
|
258
|
+
* Lets you import or require files like images or fonts.
|
|
259
|
+
* @example
|
|
260
|
+
* ```json
|
|
261
|
+
* { '.jpg': 'asset', '.png': 'base64' }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
248
264
|
loader?: ModuleTypes;
|
|
249
265
|
/**
|
|
250
266
|
* If enabled, strips the `node:` protocol prefix from import source.
|
|
@@ -258,9 +274,9 @@ interface Options {
|
|
|
258
274
|
*/
|
|
259
275
|
removeNodeProtocol?: boolean;
|
|
260
276
|
/**
|
|
261
|
-
* - If true
|
|
262
|
-
* - If 'strip'
|
|
263
|
-
* - If false
|
|
277
|
+
* - If `true`, add `node:` prefix to built-in modules.
|
|
278
|
+
* - If `'strip'`, strips the `node:` protocol prefix from import source.
|
|
279
|
+
* - If `false`, does not modify the import source.
|
|
264
280
|
*
|
|
265
281
|
* @default false
|
|
266
282
|
*
|
|
@@ -275,15 +291,6 @@ interface Options {
|
|
|
275
291
|
*/
|
|
276
292
|
nodeProtocol?: "strip" | boolean;
|
|
277
293
|
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
294
|
inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat, context: {
|
|
288
295
|
cjsDts: boolean;
|
|
289
296
|
}) => Awaitable<InputOptions | void | null>);
|
|
@@ -392,11 +399,11 @@ interface Options {
|
|
|
392
399
|
*/
|
|
393
400
|
onSuccess?: string | ((config: ResolvedOptions, signal: AbortSignal) => void | Promise<void>);
|
|
394
401
|
/**
|
|
395
|
-
*
|
|
402
|
+
* Enables generation of TypeScript declaration files (`.d.ts`).
|
|
396
403
|
*
|
|
397
|
-
* By default, this
|
|
398
|
-
* - If the `types` field is present
|
|
399
|
-
* -
|
|
404
|
+
* By default, this option is auto-detected based on your project's `package.json`:
|
|
405
|
+
* - If the `types` field is present, or if the main `exports` contains a `types` entry, declaration file generation is enabled by default.
|
|
406
|
+
* - Otherwise, declaration file generation is disabled by default.
|
|
400
407
|
*/
|
|
401
408
|
dts?: boolean | DtsOptions;
|
|
402
409
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/rolldown/tsdown.git"
|
|
14
14
|
},
|
|
15
|
-
"author": "
|
|
15
|
+
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
16
16
|
"funding": "https://github.com/sponsors/sxzz",
|
|
17
17
|
"files": [
|
|
18
|
+
"client.d.ts",
|
|
18
19
|
"dist",
|
|
19
20
|
"esm-shims.js"
|
|
20
21
|
],
|
|
@@ -26,7 +27,8 @@
|
|
|
26
27
|
"./config": "./dist/config.mjs",
|
|
27
28
|
"./plugins": "./dist/plugins.mjs",
|
|
28
29
|
"./run": "./dist/run.mjs",
|
|
29
|
-
"./package.json": "./package.json"
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
"./client": "./client.d.ts"
|
|
30
32
|
},
|
|
31
33
|
"typesVersions": {
|
|
32
34
|
"*": {
|
|
@@ -75,44 +77,36 @@
|
|
|
75
77
|
"empathic": "^2.0.0",
|
|
76
78
|
"hookable": "^5.5.3",
|
|
77
79
|
"rolldown": "latest",
|
|
78
|
-
"rolldown-plugin-dts": "^0.
|
|
80
|
+
"rolldown-plugin-dts": "^0.16.1",
|
|
79
81
|
"semver": "^7.7.2",
|
|
80
82
|
"tinyexec": "^1.0.1",
|
|
81
|
-
"tinyglobby": "^0.2.
|
|
83
|
+
"tinyglobby": "^0.2.15",
|
|
82
84
|
"tree-kill": "^1.2.2",
|
|
83
|
-
"unconfig": "^7.3.
|
|
85
|
+
"unconfig": "^7.3.3"
|
|
84
86
|
},
|
|
85
87
|
"devDependencies": {
|
|
86
88
|
"@arethetypeswrong/core": "^0.18.2",
|
|
87
|
-
"@sxzz/eslint-config": "^7.1.
|
|
88
|
-
"@sxzz/prettier-config": "^2.2.
|
|
89
|
-
"@sxzz/test-utils": "^0.5.
|
|
89
|
+
"@sxzz/eslint-config": "^7.1.4",
|
|
90
|
+
"@sxzz/prettier-config": "^2.2.4",
|
|
91
|
+
"@sxzz/test-utils": "^0.5.10",
|
|
90
92
|
"@types/debug": "^4.1.12",
|
|
91
|
-
"@types/node": "^24.
|
|
92
|
-
"@types/semver": "^7.7.
|
|
93
|
-
"@unocss/eslint-plugin": "^66.
|
|
94
|
-
"@vueuse/core": "^13.
|
|
95
|
-
"bumpp": "^10.2.
|
|
96
|
-
"eslint": "^9.
|
|
93
|
+
"@types/node": "^24.3.1",
|
|
94
|
+
"@types/semver": "^7.7.1",
|
|
95
|
+
"@unocss/eslint-plugin": "^66.5.1",
|
|
96
|
+
"@vueuse/core": "^13.9.0",
|
|
97
|
+
"bumpp": "^10.2.3",
|
|
98
|
+
"eslint": "^9.35.0",
|
|
97
99
|
"lightningcss": "^1.30.1",
|
|
98
|
-
"
|
|
99
|
-
"pkg-types": "^2.2.0",
|
|
100
|
+
"pkg-types": "^2.3.0",
|
|
100
101
|
"prettier": "^3.6.2",
|
|
101
102
|
"publint": "^0.3.12",
|
|
102
|
-
"tsx": "^4.20.
|
|
103
|
-
"typedoc": "^0.28.10",
|
|
104
|
-
"typedoc-plugin-markdown": "^4.8.0",
|
|
105
|
-
"typedoc-vitepress-theme": "^1.1.2",
|
|
103
|
+
"tsx": "^4.20.5",
|
|
106
104
|
"typescript": "~5.9.2",
|
|
107
|
-
"unocss": "^66.
|
|
108
|
-
"unplugin-lightningcss": "^0.4.
|
|
109
|
-
"unplugin-unused": "^0.5.
|
|
105
|
+
"unocss": "^66.5.1",
|
|
106
|
+
"unplugin-lightningcss": "^0.4.2",
|
|
107
|
+
"unplugin-unused": "^0.5.2",
|
|
110
108
|
"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"
|
|
109
|
+
"vitest": "^3.2.4"
|
|
116
110
|
},
|
|
117
111
|
"engines": {
|
|
118
112
|
"node": ">=20.19.0"
|
|
@@ -127,9 +121,9 @@
|
|
|
127
121
|
"typecheck": "tsc --noEmit",
|
|
128
122
|
"format": "prettier --cache --write .",
|
|
129
123
|
"release": "bumpp",
|
|
130
|
-
"docs:dev": "
|
|
131
|
-
"docs:build": "
|
|
132
|
-
"docs:preview": "
|
|
133
|
-
"docs:generate": "
|
|
124
|
+
"docs:dev": "pnpm -C docs run dev",
|
|
125
|
+
"docs:build": "pnpm -C docs run build",
|
|
126
|
+
"docs:preview": "pnpm -C docs run preview",
|
|
127
|
+
"docs:generate": "pnpm -C docs run generate"
|
|
134
128
|
}
|
|
135
129
|
}
|