tsdown 0.12.9 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.12.9",
3
+ "version": "0.13.0-beta.1",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -74,8 +74,8 @@
74
74
  "diff": "^8.0.2",
75
75
  "empathic": "^2.0.0",
76
76
  "hookable": "^5.5.3",
77
- "rolldown": "^1.0.0-beta.19",
78
- "rolldown-plugin-dts": "^0.13.12",
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",
@@ -87,32 +87,33 @@
87
87
  "@sxzz/prettier-config": "^2.2.3",
88
88
  "@sxzz/test-utils": "^0.5.6",
89
89
  "@types/debug": "^4.1.12",
90
- "@types/node": "^24.0.4",
90
+ "@types/node": "^24.0.12",
91
91
  "@types/semver": "^7.7.0",
92
- "@unocss/eslint-plugin": "^66.2.3",
93
- "@vueuse/core": "^13.4.0",
92
+ "@unocss/eslint-plugin": "^66.3.3",
93
+ "@vueuse/core": "^13.5.0",
94
94
  "bumpp": "^10.2.0",
95
- "eslint": "^9.29.0",
95
+ "eslint": "^9.30.1",
96
96
  "lightningcss": "^1.30.1",
97
- "pkg-types": "^2.1.0",
98
- "prettier": "^3.6.0",
97
+ "oxc-minify": "^0.76.0",
98
+ "pkg-types": "^2.2.0",
99
+ "prettier": "^3.6.2",
99
100
  "publint": "^0.3.12",
100
101
  "tsx": "^4.20.3",
101
- "typedoc": "^0.28.5",
102
+ "typedoc": "^0.28.7",
102
103
  "typedoc-plugin-markdown": "^4.7.0",
103
104
  "typescript": "~5.8.3",
104
- "unocss": "^66.2.3",
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": "^1.6.3",
109
- "vitepress-plugin-group-icons": "^1.6.0",
110
- "vitepress-plugin-llms": "^1.5.1",
109
+ "vitepress": "^2.0.0-alpha.7",
110
+ "vitepress-plugin-group-icons": "^1.6.1",
111
+ "vitepress-plugin-llms": "^1.7.0",
111
112
  "vitest": "^3.2.4",
112
113
  "vue": "^3.5.17"
113
114
  },
114
115
  "engines": {
115
- "node": ">=18.0.0"
116
+ "node": ">=20.19.0"
116
117
  },
117
118
  "resolutions": {
118
119
  "rolldown": "catalog:prod",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.12.9";
3
-
4
- //#endregion
5
- export { version };
@@ -1,230 +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(nodeProtocolOption) {
100
- if (nodeProtocolOption === "strip") return {
101
- name: "tsdown:node-protocol:strip",
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
- const builtinModulesRegex = /* @__PURE__ */ new RegExp(`^(${builtinModules.join("|")})$`);
115
- return {
116
- name: "tsdown:node-protocol:add",
117
- resolveId: {
118
- order: "pre",
119
- filter: { id: builtinModulesRegex },
120
- handler(id) {
121
- return {
122
- id: `node:${id}`,
123
- external: true,
124
- moduleSideEffects: false
125
- };
126
- }
127
- }
128
- };
129
- }
130
-
131
- //#endregion
132
- //#region src/utils/format.ts
133
- function formatBytes(bytes) {
134
- if (bytes === Infinity) return void 0;
135
- return `${(bytes / 1e3).toFixed(2)} kB`;
136
- }
137
-
138
- //#endregion
139
- //#region src/features/report.ts
140
- const debug$1 = debug("tsdown:report");
141
- const brotliCompressAsync = promisify(brotliCompress);
142
- const gzipAsync = promisify(gzip);
143
- function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
144
- return {
145
- name: "tsdown:report",
146
- async writeBundle(outputOptions, bundle) {
147
- const outDir = path.relative(cwd, outputOptions.file ? path.resolve(cwd, outputOptions.file, "..") : path.resolve(cwd, outputOptions.dir));
148
- const sizes = [];
149
- for (const chunk of Object.values(bundle)) {
150
- const size = await calcSize(options, chunk);
151
- sizes.push(size);
152
- }
153
- const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
154
- const rawTextLength = Math.max(...sizes.map((size) => size.rawText.length));
155
- const gzipTextLength = Math.max(...sizes.map((size) => size.gzipText == null ? 0 : size.gzipText.length));
156
- const brotliTextLength = Math.max(...sizes.map((size) => size.brotliText == null ? 0 : size.brotliText.length));
157
- let totalRaw = 0;
158
- for (const size of sizes) {
159
- size.rawText = size.rawText.padStart(rawTextLength);
160
- size.gzipText = size.gzipText?.padStart(gzipTextLength);
161
- size.brotliText = size.brotliText?.padStart(brotliTextLength);
162
- totalRaw += size.raw;
163
- }
164
- sizes.sort((a, b) => {
165
- if (a.dts !== b.dts) return a.dts ? 1 : -1;
166
- if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
167
- return b.raw - a.raw;
168
- });
169
- const nameLabel = prettyName(name);
170
- const formatLabel = isMultiFormat && prettyFormat(cjsDts ? "cjs" : outputOptions.format);
171
- for (const size of sizes) {
172
- const filenameColor = size.dts ? green : noop;
173
- 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}`);
174
- }
175
- const totalSizeText = formatBytes(totalRaw);
176
- logger.info(nameLabel, formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
177
- }
178
- };
179
- }
180
- async function calcSize(options, chunk) {
181
- debug$1(`Calculating size for`, chunk.fileName);
182
- const content = chunk.type === "chunk" ? chunk.code : chunk.source;
183
- const raw = Buffer.byteLength(content, "utf8");
184
- debug$1("[size]", chunk.fileName, raw);
185
- let gzip$1 = Infinity;
186
- let brotli = Infinity;
187
- if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
188
- else {
189
- gzip$1 = (await gzipAsync(content)).length;
190
- debug$1("[gzip]", chunk.fileName, gzip$1);
191
- if (options.brotli) {
192
- brotli = (await brotliCompressAsync(content)).length;
193
- debug$1("[brotli]", chunk.fileName, brotli);
194
- }
195
- }
196
- return {
197
- filename: chunk.fileName,
198
- dts: RE_DTS.test(chunk.fileName),
199
- isEntry: chunk.type === "chunk" && chunk.isEntry,
200
- raw,
201
- rawText: formatBytes(raw),
202
- gzip: gzip$1,
203
- gzipText: formatBytes(gzip$1),
204
- brotli,
205
- brotliText: formatBytes(brotli)
206
- };
207
- }
208
-
209
- //#endregion
210
- //#region src/features/shebang.ts
211
- const RE_SHEBANG = /^#!.*/;
212
- function ShebangPlugin(cwd, name, isMultiFormat) {
213
- return {
214
- name: "tsdown:shebang",
215
- async writeBundle(options, bundle) {
216
- for (const chunk of Object.values(bundle)) {
217
- if (chunk.type !== "chunk" || !chunk.isEntry) continue;
218
- if (!RE_SHEBANG.test(chunk.code)) continue;
219
- const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
220
- if (await fsExists(filepath)) {
221
- logger.info(prettyName(name), isMultiFormat && prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
222
- await chmod(filepath, 493);
223
- }
224
- }
225
- }
226
- };
227
- }
228
-
229
- //#endregion
230
- export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsExists, fsRemove, fsStat, lowestCommonAncestor };