tsdown 0.12.8 → 0.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-D_2fTM9-.d.mts → config-BHQdCemQ.d.mts} +23 -4
- package/dist/config.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -1035
- package/dist/{logger-CdK2zFTY.mjs → logger-6IV2T7t1.mjs} +1 -1
- package/dist/{migrate-D3HAtePC.mjs → migrate-OhQ7vqGh.mjs} +2 -2
- package/dist/package-DN14v3FV.mjs +5 -0
- package/dist/plugins.d.mts +2 -2
- package/dist/plugins.mjs +3 -2
- package/dist/run.mjs +3 -3
- package/dist/src-DfeORvyH.mjs +1256 -0
- package/package.json +27 -26
- package/dist/package-DRxdhN87.mjs +0 -5
- package/dist/plugins-qNZNAFcS.mjs +0 -215
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-beta.1",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"chokidar": "^4.0.3",
|
|
73
73
|
"debug": "^4.4.1",
|
|
74
74
|
"diff": "^8.0.2",
|
|
75
|
-
"empathic": "^
|
|
75
|
+
"empathic": "^2.0.0",
|
|
76
76
|
"hookable": "^5.5.3",
|
|
77
|
-
"rolldown": "1.0.0-beta.
|
|
78
|
-
"rolldown-plugin-dts": "^0.13.
|
|
77
|
+
"rolldown": "^1.0.0-beta.24",
|
|
78
|
+
"rolldown-plugin-dts": "^0.13.13",
|
|
79
79
|
"semver": "^7.7.2",
|
|
80
80
|
"tinyexec": "^1.0.1",
|
|
81
81
|
"tinyglobby": "^0.2.14",
|
|
@@ -83,36 +83,37 @@
|
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@arethetypeswrong/core": "^0.18.2",
|
|
86
|
-
"@
|
|
87
|
-
"@sxzz/
|
|
88
|
-
"@sxzz/prettier-config": "^2.2.1",
|
|
86
|
+
"@sxzz/eslint-config": "^7.0.4",
|
|
87
|
+
"@sxzz/prettier-config": "^2.2.3",
|
|
89
88
|
"@sxzz/test-utils": "^0.5.6",
|
|
90
89
|
"@types/debug": "^4.1.12",
|
|
91
|
-
"@types/node": "^24.0.
|
|
90
|
+
"@types/node": "^24.0.12",
|
|
92
91
|
"@types/semver": "^7.7.0",
|
|
93
|
-
"@unocss/eslint-plugin": "^66.
|
|
94
|
-
"@vueuse/core": "^13.
|
|
95
|
-
"bumpp": "^10.
|
|
96
|
-
"eslint": "^9.
|
|
92
|
+
"@unocss/eslint-plugin": "^66.3.3",
|
|
93
|
+
"@vueuse/core": "^13.5.0",
|
|
94
|
+
"bumpp": "^10.2.0",
|
|
95
|
+
"eslint": "^9.30.1",
|
|
97
96
|
"lightningcss": "^1.30.1",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
97
|
+
"oxc-minify": "^0.76.0",
|
|
98
|
+
"pkg-types": "^2.2.0",
|
|
99
|
+
"prettier": "^3.6.2",
|
|
100
100
|
"publint": "^0.3.12",
|
|
101
|
-
"
|
|
102
|
-
"typedoc
|
|
101
|
+
"tsx": "^4.20.3",
|
|
102
|
+
"typedoc": "^0.28.7",
|
|
103
|
+
"typedoc-plugin-markdown": "^4.7.0",
|
|
103
104
|
"typescript": "~5.8.3",
|
|
104
|
-
"unocss": "^66.
|
|
105
|
+
"unocss": "^66.3.3",
|
|
105
106
|
"unplugin-lightningcss": "^0.4.1",
|
|
106
107
|
"unplugin-unused": "^0.5.1",
|
|
107
108
|
"vite": "npm:rolldown-vite@latest",
|
|
108
|
-
"vitepress": "^
|
|
109
|
-
"vitepress-plugin-group-icons": "^1.6.
|
|
110
|
-
"vitepress-plugin-llms": "^1.
|
|
111
|
-
"vitest": "^3.2.
|
|
112
|
-
"vue": "^3.5.
|
|
109
|
+
"vitepress": "^2.0.0-alpha.7",
|
|
110
|
+
"vitepress-plugin-group-icons": "^1.6.1",
|
|
111
|
+
"vitepress-plugin-llms": "^1.7.0",
|
|
112
|
+
"vitest": "^3.2.4",
|
|
113
|
+
"vue": "^3.5.17"
|
|
113
114
|
},
|
|
114
115
|
"engines": {
|
|
115
|
-
"node": ">=
|
|
116
|
+
"node": ">=20.19.0"
|
|
116
117
|
},
|
|
117
118
|
"resolutions": {
|
|
118
119
|
"rolldown": "catalog:prod",
|
|
@@ -122,8 +123,8 @@
|
|
|
122
123
|
"scripts": {
|
|
123
124
|
"lint": "eslint --cache --max-warnings 0 .",
|
|
124
125
|
"lint:fix": "pnpm run lint --fix",
|
|
125
|
-
"build": "
|
|
126
|
-
"dev": "
|
|
126
|
+
"build": "tsx ./src/run.ts",
|
|
127
|
+
"dev": "tsx ./src/run.ts",
|
|
127
128
|
"test": "vitest",
|
|
128
129
|
"typecheck": "tsc --noEmit",
|
|
129
130
|
"format": "prettier --cache --write .",
|
|
@@ -131,6 +132,6 @@
|
|
|
131
132
|
"docs:dev": "vitepress dev docs",
|
|
132
133
|
"docs:build": "vitepress build docs",
|
|
133
134
|
"docs:preview": "vitepress preview docs",
|
|
134
|
-
"docs:generate": "
|
|
135
|
+
"docs:generate": "tsx ./docs/.vitepress/scripts/docs-generate.ts"
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { logger, noop, prettyFormat, prettyName, toArray } from "./logger-CdK2zFTY.mjs";
|
|
2
|
-
import { builtinModules } from "node:module";
|
|
3
|
-
import path, { dirname, normalize, sep } from "node:path";
|
|
4
|
-
import { bold, dim, green, underline } from "ansis";
|
|
5
|
-
import { access, chmod, cp, rm, stat } from "node:fs/promises";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import debug from "debug";
|
|
8
|
-
import { RE_DTS } from "rolldown-plugin-dts/filename";
|
|
9
|
-
import { Buffer } from "node:buffer";
|
|
10
|
-
import { brotliCompress, gzip } from "node:zlib";
|
|
11
|
-
|
|
12
|
-
//#region src/utils/fs.ts
|
|
13
|
-
function fsExists(path$1) {
|
|
14
|
-
return access(path$1).then(() => true, () => false);
|
|
15
|
-
}
|
|
16
|
-
function fsStat(path$1) {
|
|
17
|
-
return stat(path$1).catch(() => null);
|
|
18
|
-
}
|
|
19
|
-
function fsRemove(path$1) {
|
|
20
|
-
return rm(path$1, {
|
|
21
|
-
force: true,
|
|
22
|
-
recursive: true
|
|
23
|
-
}).catch(() => {});
|
|
24
|
-
}
|
|
25
|
-
function fsCopy(from, to) {
|
|
26
|
-
return cp(from, to, {
|
|
27
|
-
recursive: true,
|
|
28
|
-
force: true
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function lowestCommonAncestor(...filepaths) {
|
|
32
|
-
if (filepaths.length === 0) return "";
|
|
33
|
-
if (filepaths.length === 1) return dirname(filepaths[0]);
|
|
34
|
-
filepaths = filepaths.map(normalize);
|
|
35
|
-
const [first, ...rest] = filepaths;
|
|
36
|
-
let ancestor = first.split(sep);
|
|
37
|
-
for (const filepath of rest) {
|
|
38
|
-
const directories = filepath.split(sep, ancestor.length);
|
|
39
|
-
let index = 0;
|
|
40
|
-
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
41
|
-
else {
|
|
42
|
-
ancestor = ancestor.slice(0, index);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
ancestor = ancestor.slice(0, index);
|
|
46
|
-
}
|
|
47
|
-
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/features/external.ts
|
|
52
|
-
const debug$2 = debug("tsdown:external");
|
|
53
|
-
function ExternalPlugin(options) {
|
|
54
|
-
const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
|
|
55
|
-
return {
|
|
56
|
-
name: "tsdown:external",
|
|
57
|
-
async resolveId(id, importer, extraOptions) {
|
|
58
|
-
if (extraOptions.isEntry) return;
|
|
59
|
-
const { noExternal } = options;
|
|
60
|
-
if (typeof noExternal === "function" && noExternal(id, importer)) return;
|
|
61
|
-
if (noExternal) {
|
|
62
|
-
const noExternalPatterns = toArray(noExternal);
|
|
63
|
-
if (noExternalPatterns.some((pattern) => {
|
|
64
|
-
if (pattern instanceof RegExp) {
|
|
65
|
-
pattern.lastIndex = 0;
|
|
66
|
-
return pattern.test(id);
|
|
67
|
-
}
|
|
68
|
-
return id === pattern;
|
|
69
|
-
})) return;
|
|
70
|
-
}
|
|
71
|
-
let shouldExternal = false;
|
|
72
|
-
if (options.skipNodeModulesBundle) {
|
|
73
|
-
const resolved = await this.resolve(id, importer, extraOptions);
|
|
74
|
-
if (!resolved) return resolved;
|
|
75
|
-
shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
|
|
76
|
-
}
|
|
77
|
-
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
78
|
-
if (shouldExternal) {
|
|
79
|
-
debug$2("External dependency:", id);
|
|
80
|
-
return {
|
|
81
|
-
id,
|
|
82
|
-
external: shouldExternal,
|
|
83
|
-
moduleSideEffects: id.startsWith("node:") || builtinModules.includes(id) ? false : void 0
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function getProductionDeps(pkg) {
|
|
90
|
-
return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/features/node-protocol.ts
|
|
95
|
-
/**
|
|
96
|
-
* The `node:` protocol was added in Node.js v14.18.0.
|
|
97
|
-
* @see https://nodejs.org/api/esm.html#node-imports
|
|
98
|
-
*/
|
|
99
|
-
function NodeProtocolPlugin() {
|
|
100
|
-
return {
|
|
101
|
-
name: "tsdown:node-protocol",
|
|
102
|
-
resolveId: {
|
|
103
|
-
order: "pre",
|
|
104
|
-
filter: { id: /^node:/ },
|
|
105
|
-
handler(id) {
|
|
106
|
-
return {
|
|
107
|
-
id: id.slice(5),
|
|
108
|
-
external: true,
|
|
109
|
-
moduleSideEffects: false
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/utils/format.ts
|
|
118
|
-
function formatBytes(bytes) {
|
|
119
|
-
if (bytes === Infinity) return void 0;
|
|
120
|
-
return `${(bytes / 1e3).toFixed(2)} kB`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/features/report.ts
|
|
125
|
-
const debug$1 = debug("tsdown:report");
|
|
126
|
-
const brotliCompressAsync = promisify(brotliCompress);
|
|
127
|
-
const gzipAsync = promisify(gzip);
|
|
128
|
-
function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
|
|
129
|
-
return {
|
|
130
|
-
name: "tsdown:report",
|
|
131
|
-
async writeBundle(outputOptions, bundle) {
|
|
132
|
-
const outDir = path.relative(cwd, outputOptions.file ? path.resolve(cwd, outputOptions.file, "..") : path.resolve(cwd, outputOptions.dir));
|
|
133
|
-
const sizes = [];
|
|
134
|
-
for (const chunk of Object.values(bundle)) {
|
|
135
|
-
const size = await calcSize(options, chunk);
|
|
136
|
-
sizes.push(size);
|
|
137
|
-
}
|
|
138
|
-
const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
|
|
139
|
-
const rawTextLength = Math.max(...sizes.map((size) => size.rawText.length));
|
|
140
|
-
const gzipTextLength = Math.max(...sizes.map((size) => size.gzipText == null ? 0 : size.gzipText.length));
|
|
141
|
-
const brotliTextLength = Math.max(...sizes.map((size) => size.brotliText == null ? 0 : size.brotliText.length));
|
|
142
|
-
let totalRaw = 0;
|
|
143
|
-
for (const size of sizes) {
|
|
144
|
-
size.rawText = size.rawText.padStart(rawTextLength);
|
|
145
|
-
size.gzipText = size.gzipText?.padStart(gzipTextLength);
|
|
146
|
-
size.brotliText = size.brotliText?.padStart(brotliTextLength);
|
|
147
|
-
totalRaw += size.raw;
|
|
148
|
-
}
|
|
149
|
-
sizes.sort((a, b) => {
|
|
150
|
-
if (a.dts !== b.dts) return a.dts ? 1 : -1;
|
|
151
|
-
if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
|
|
152
|
-
return b.raw - a.raw;
|
|
153
|
-
});
|
|
154
|
-
const nameLabel = prettyName(name);
|
|
155
|
-
const formatLabel = isMultiFormat && prettyFormat(cjsDts ? "cjs" : outputOptions.format);
|
|
156
|
-
for (const size of sizes) {
|
|
157
|
-
const filenameColor = size.dts ? green : noop;
|
|
158
|
-
logger.info(nameLabel, formatLabel, dim(`${outDir}/`) + filenameColor((size.isEntry ? bold : noop)(size.filename)), ` `.repeat(filenameLength - size.filename.length), dim(size.rawText), size.gzipText && dim`│ gzip: ${size.gzipText}`, options.brotli && size.brotliText && dim`│ brotli: ${size.brotliText}`);
|
|
159
|
-
}
|
|
160
|
-
const totalSizeText = formatBytes(totalRaw);
|
|
161
|
-
logger.info(nameLabel, formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
async function calcSize(options, chunk) {
|
|
166
|
-
debug$1(`Calculating size for`, chunk.fileName);
|
|
167
|
-
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
168
|
-
const raw = Buffer.byteLength(content, "utf8");
|
|
169
|
-
debug$1("[size]", chunk.fileName, raw);
|
|
170
|
-
let gzip$1 = Infinity;
|
|
171
|
-
let brotli = Infinity;
|
|
172
|
-
if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
173
|
-
else {
|
|
174
|
-
gzip$1 = (await gzipAsync(content)).length;
|
|
175
|
-
debug$1("[gzip]", chunk.fileName, gzip$1);
|
|
176
|
-
if (options.brotli) {
|
|
177
|
-
brotli = (await brotliCompressAsync(content)).length;
|
|
178
|
-
debug$1("[brotli]", chunk.fileName, brotli);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
filename: chunk.fileName,
|
|
183
|
-
dts: RE_DTS.test(chunk.fileName),
|
|
184
|
-
isEntry: chunk.type === "chunk" && chunk.isEntry,
|
|
185
|
-
raw,
|
|
186
|
-
rawText: formatBytes(raw),
|
|
187
|
-
gzip: gzip$1,
|
|
188
|
-
gzipText: formatBytes(gzip$1),
|
|
189
|
-
brotli,
|
|
190
|
-
brotliText: formatBytes(brotli)
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/features/shebang.ts
|
|
196
|
-
const RE_SHEBANG = /^#!.*/;
|
|
197
|
-
function ShebangPlugin(cwd, name, isMultiFormat) {
|
|
198
|
-
return {
|
|
199
|
-
name: "tsdown:shebang",
|
|
200
|
-
async writeBundle(options, bundle) {
|
|
201
|
-
for (const chunk of Object.values(bundle)) {
|
|
202
|
-
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
203
|
-
if (!RE_SHEBANG.test(chunk.code)) continue;
|
|
204
|
-
const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
|
|
205
|
-
if (await fsExists(filepath)) {
|
|
206
|
-
logger.info(prettyName(name), isMultiFormat && prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
|
|
207
|
-
await chmod(filepath, 493);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
//#endregion
|
|
215
|
-
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsExists, fsRemove, fsStat, lowestCommonAncestor };
|