tsdown 0.5.1 → 0.5.3
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/index.js +65 -63
- package/dist/run.js +1 -1
- package/package.json +15 -14
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { debug, logger } from "./logger-Pk57TMWT.js";
|
|
2
2
|
import { ExternalPlugin } from "./external-9r3oq3tH.js";
|
|
3
|
-
import path, { dirname, normalize, sep
|
|
4
|
-
import process
|
|
3
|
+
import path, { dirname, normalize, sep } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { build as build$1 } from "rolldown";
|
|
7
7
|
import { transformPlugin } from "rolldown/experimental";
|
|
@@ -13,12 +13,18 @@ import { rollup } from "rollup";
|
|
|
13
13
|
import DtsPlugin from "rollup-plugin-dts";
|
|
14
14
|
import { readPackageJSON } from "pkg-types";
|
|
15
15
|
import readline from "node:readline";
|
|
16
|
-
import pc
|
|
16
|
+
import pc from "picocolors";
|
|
17
17
|
import { loadConfig } from "unconfig";
|
|
18
18
|
|
|
19
19
|
//#region src/utils/fs.ts
|
|
20
|
-
function fsExists(path$
|
|
21
|
-
return access(path$
|
|
20
|
+
function fsExists(path$1) {
|
|
21
|
+
return access(path$1).then(() => true, () => false);
|
|
22
|
+
}
|
|
23
|
+
function fsRemove(path$1) {
|
|
24
|
+
return rm(path$1, {
|
|
25
|
+
force: true,
|
|
26
|
+
recursive: true
|
|
27
|
+
}).catch(() => {});
|
|
22
28
|
}
|
|
23
29
|
function lowestCommonAncestor(...filepaths) {
|
|
24
30
|
if (filepaths.length === 0) return "";
|
|
@@ -43,7 +49,7 @@ else {
|
|
|
43
49
|
//#region src/features/clean.ts
|
|
44
50
|
async function cleanOutDir(cwd, patterns) {
|
|
45
51
|
const files = [];
|
|
46
|
-
if (await fsExists(cwd)) files.push(...(await readdir(cwd)).map((file) => path
|
|
52
|
+
if (await fsExists(cwd)) files.push(...(await readdir(cwd)).map((file) => path.resolve(cwd, file)));
|
|
47
53
|
if (patterns.length) files.push(...await glob(patterns, {
|
|
48
54
|
cwd,
|
|
49
55
|
absolute: true
|
|
@@ -51,20 +57,40 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
51
57
|
logger.info("Cleaning output folder");
|
|
52
58
|
for (const file of files) {
|
|
53
59
|
debug("[clean]", "Removing", file);
|
|
54
|
-
await
|
|
55
|
-
force: true,
|
|
56
|
-
recursive: true
|
|
57
|
-
});
|
|
60
|
+
await fsRemove(file);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils/general.ts
|
|
66
|
+
function toArray(val, defaultValue) {
|
|
67
|
+
if (Array.isArray(val)) return val;
|
|
68
|
+
else if (val == null) {
|
|
69
|
+
if (defaultValue) return [defaultValue];
|
|
70
|
+
return [];
|
|
71
|
+
} else return [val];
|
|
72
|
+
}
|
|
73
|
+
function debounce(fn, wait) {
|
|
74
|
+
let timeout;
|
|
75
|
+
return function(...args) {
|
|
76
|
+
if (timeout) clearTimeout(timeout);
|
|
77
|
+
timeout = setTimeout(() => {
|
|
78
|
+
timeout = undefined;
|
|
79
|
+
fn.apply(this, args);
|
|
80
|
+
}, wait);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
61
84
|
//#endregion
|
|
62
85
|
//#region src/features/dts.ts
|
|
63
86
|
const TEMP_DTS_DIR = ".tsdown-types";
|
|
64
|
-
|
|
87
|
+
function getTempDtsDir(format) {
|
|
88
|
+
return `${TEMP_DTS_DIR}-${format}`;
|
|
89
|
+
}
|
|
90
|
+
async function bundleDts(options, jsExtension, format) {
|
|
65
91
|
const ext = jsExtension.replace("j", "t");
|
|
66
|
-
const dtsOutDir = path
|
|
67
|
-
const dtsEntry = Object.fromEntries(Object.keys(options.entry).map((key) => [key, path
|
|
92
|
+
const dtsOutDir = path.resolve(options.outDir, getTempDtsDir(format));
|
|
93
|
+
const dtsEntry = Object.fromEntries(Object.keys(options.entry).map((key) => [key, path.resolve(dtsOutDir, `${key}.d.${ext}`)]));
|
|
68
94
|
const build$2 = await rollup({
|
|
69
95
|
input: dtsEntry,
|
|
70
96
|
onLog(level, log, defaultHandler) {
|
|
@@ -74,22 +100,19 @@ async function bundleDts(options, jsExtension) {
|
|
|
74
100
|
});
|
|
75
101
|
let outDir = options.outDir;
|
|
76
102
|
const extraOutdir = options.dts.extraOutdir;
|
|
77
|
-
if (extraOutdir) outDir = path
|
|
103
|
+
if (extraOutdir) outDir = path.resolve(outDir, extraOutdir);
|
|
78
104
|
await build$2.write({
|
|
79
105
|
dir: outDir,
|
|
80
106
|
format: "es",
|
|
81
107
|
entryFileNames: `[name].d.${ext}`
|
|
82
108
|
});
|
|
83
|
-
await
|
|
84
|
-
recursive: true,
|
|
85
|
-
force: true
|
|
86
|
-
});
|
|
109
|
+
await fsRemove(dtsOutDir);
|
|
87
110
|
}
|
|
88
111
|
|
|
89
112
|
//#endregion
|
|
90
113
|
//#region src/utils/package.ts
|
|
91
114
|
async function readPackageJson(dir) {
|
|
92
|
-
const packageJsonPath = path
|
|
115
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
93
116
|
const exists = await fsExists(packageJsonPath);
|
|
94
117
|
if (!exists) return;
|
|
95
118
|
debug("Reading package.json:", packageJsonPath);
|
|
@@ -118,7 +141,7 @@ function resolveOutputExtension(pkg, format) {
|
|
|
118
141
|
//#region src/features/shims.ts
|
|
119
142
|
function getShimsInject(format, platform) {
|
|
120
143
|
if (format === "es" && platform === "node") {
|
|
121
|
-
const shimFile = path
|
|
144
|
+
const shimFile = path.resolve(pkgRoot, "esm-shims.js");
|
|
122
145
|
return {
|
|
123
146
|
__dirname: [shimFile, "__dirname"],
|
|
124
147
|
__filename: [shimFile, "__filename"]
|
|
@@ -152,7 +175,7 @@ function shortcuts(restart) {
|
|
|
152
175
|
key: "q",
|
|
153
176
|
description: "quit",
|
|
154
177
|
action() {
|
|
155
|
-
process
|
|
178
|
+
process.exit(0);
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
];
|
|
@@ -163,7 +186,7 @@ function shortcuts(restart) {
|
|
|
163
186
|
if (loggedKeys.has(shortcut$1.key)) continue;
|
|
164
187
|
loggedKeys.add(shortcut$1.key);
|
|
165
188
|
if (shortcut$1.action == null) continue;
|
|
166
|
-
logger.info(pc
|
|
189
|
+
logger.info(pc.dim(" press ") + pc.bold(`${shortcut$1.key} + enter`) + pc.dim(` to ${shortcut$1.description}`));
|
|
167
190
|
}
|
|
168
191
|
return;
|
|
169
192
|
}
|
|
@@ -173,37 +196,17 @@ function shortcuts(restart) {
|
|
|
173
196
|
await shortcut.action();
|
|
174
197
|
actionRunning = false;
|
|
175
198
|
}
|
|
176
|
-
const rl = readline.createInterface({ input: process
|
|
199
|
+
const rl = readline.createInterface({ input: process.stdin });
|
|
177
200
|
rl.on("line", onInput);
|
|
178
201
|
}
|
|
179
202
|
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/utils/general.ts
|
|
182
|
-
function toArray(val, defaultValue) {
|
|
183
|
-
if (Array.isArray(val)) return val;
|
|
184
|
-
else if (val == null) {
|
|
185
|
-
if (defaultValue) return [defaultValue];
|
|
186
|
-
return [];
|
|
187
|
-
} else return [val];
|
|
188
|
-
}
|
|
189
|
-
function debounce(fn, wait) {
|
|
190
|
-
let timeout;
|
|
191
|
-
return function(...args) {
|
|
192
|
-
if (timeout) clearTimeout(timeout);
|
|
193
|
-
timeout = setTimeout(() => {
|
|
194
|
-
timeout = undefined;
|
|
195
|
-
fn.apply(this, args);
|
|
196
|
-
}, wait);
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
203
|
//#endregion
|
|
201
204
|
//#region src/features/watch.ts
|
|
202
205
|
const endsWithPackageJson = /[\\/]package\.json$/;
|
|
203
206
|
async function watchBuild(options, configFile, rebuild, restart) {
|
|
204
207
|
const { watch } = await import("chokidar");
|
|
205
208
|
const debouncedRebuild = debounce(rebuild, 100);
|
|
206
|
-
const files = toArray(typeof options.watch === "boolean" ? process
|
|
209
|
+
const files = toArray(typeof options.watch === "boolean" ? process.cwd() : options.watch);
|
|
207
210
|
logger.info(`Watching for changes in ${files.join(", ")}`);
|
|
208
211
|
if (configFile) files.push(configFile);
|
|
209
212
|
const watcher = watch(files, {
|
|
@@ -233,7 +236,7 @@ async function resolveEntry(entry) {
|
|
|
233
236
|
const objectEntry = await toObjectEntry(entry);
|
|
234
237
|
const entries = Object.values(objectEntry);
|
|
235
238
|
if (entries.length === 0) throw new Error(`Cannot find entry: ${JSON.stringify(entry)}`);
|
|
236
|
-
logger.info(`entry: ${pc
|
|
239
|
+
logger.info(`entry: ${pc.blue(entries.join(", "))}`);
|
|
237
240
|
return objectEntry;
|
|
238
241
|
}
|
|
239
242
|
async function toObjectEntry(entry) {
|
|
@@ -242,8 +245,8 @@ async function toObjectEntry(entry) {
|
|
|
242
245
|
const resolvedEntry = await glob(entry);
|
|
243
246
|
const base = lowestCommonAncestor(...resolvedEntry);
|
|
244
247
|
return Object.fromEntries(resolvedEntry.map((file) => {
|
|
245
|
-
const relative = path
|
|
246
|
-
return [relative.slice(0, relative.length - path
|
|
248
|
+
const relative = path.relative(base, file);
|
|
249
|
+
return [relative.slice(0, relative.length - path.extname(relative).length), file];
|
|
247
250
|
}));
|
|
248
251
|
}
|
|
249
252
|
|
|
@@ -265,7 +268,7 @@ async function resolveOptions(options) {
|
|
|
265
268
|
entry,
|
|
266
269
|
plugins,
|
|
267
270
|
format: normalizeFormat(format),
|
|
268
|
-
outDir: path
|
|
271
|
+
outDir: path.resolve(outDir),
|
|
269
272
|
clean,
|
|
270
273
|
silent,
|
|
271
274
|
treeshake,
|
|
@@ -295,15 +298,15 @@ function normalizeFormat(format) {
|
|
|
295
298
|
async function loadConfigFile(options) {
|
|
296
299
|
let { config: filePath } = options;
|
|
297
300
|
if (filePath === false) return [[]];
|
|
298
|
-
let cwd = process
|
|
301
|
+
let cwd = process.cwd();
|
|
299
302
|
let overrideConfig = false;
|
|
300
303
|
let stats;
|
|
301
304
|
if (typeof filePath === "string" && (stats = await stat(filePath).catch(() => null))) {
|
|
302
|
-
const resolved = path
|
|
305
|
+
const resolved = path.resolve(filePath);
|
|
303
306
|
if (stats.isFile()) {
|
|
304
307
|
overrideConfig = true;
|
|
305
308
|
filePath = resolved;
|
|
306
|
-
cwd = path
|
|
309
|
+
cwd = path.dirname(filePath);
|
|
307
310
|
} else cwd = resolved;
|
|
308
311
|
}
|
|
309
312
|
const { config, sources } = await loadConfig({
|
|
@@ -374,16 +377,6 @@ async function buildSingle(resolved) {
|
|
|
374
377
|
if (watch) return () => rebuild();
|
|
375
378
|
async function rebuild(first) {
|
|
376
379
|
const startTime = performance.now();
|
|
377
|
-
const plugins = [
|
|
378
|
-
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
379
|
-
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
380
|
-
dts && IsolatedDecl.rolldown({
|
|
381
|
-
...dts,
|
|
382
|
-
extraOutdir: resolved.bundleDts ? TEMP_DTS_DIR : dts.extraOutdir
|
|
383
|
-
}),
|
|
384
|
-
target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
|
|
385
|
-
userPlugins
|
|
386
|
-
].filter((plugin) => !!plugin);
|
|
387
380
|
await Promise.all(format.map(async (format$1) => {
|
|
388
381
|
const inputOptions = await mergeUserOptions({
|
|
389
382
|
input: entry,
|
|
@@ -392,7 +385,16 @@ async function buildSingle(resolved) {
|
|
|
392
385
|
treeshake,
|
|
393
386
|
platform,
|
|
394
387
|
define,
|
|
395
|
-
plugins
|
|
388
|
+
plugins: [
|
|
389
|
+
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
390
|
+
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
391
|
+
dts && IsolatedDecl.rolldown({
|
|
392
|
+
...dts,
|
|
393
|
+
extraOutdir: resolved.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
|
|
394
|
+
}),
|
|
395
|
+
target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
|
|
396
|
+
userPlugins
|
|
397
|
+
].filter((plugin) => !!plugin),
|
|
396
398
|
inject: { ...shims && getShimsInject(format$1, platform) }
|
|
397
399
|
}, resolved.inputOptions, [format$1]);
|
|
398
400
|
const extension = resolveOutputExtension(pkg, format$1);
|
|
@@ -409,7 +411,7 @@ async function buildSingle(resolved) {
|
|
|
409
411
|
...inputOptions,
|
|
410
412
|
output: outputOptions
|
|
411
413
|
});
|
|
412
|
-
if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension);
|
|
414
|
+
if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension, format$1);
|
|
413
415
|
}));
|
|
414
416
|
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
|
415
417
|
await onSuccess?.();
|
package/dist/run.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,34 +41,35 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cac": "^6.7.14",
|
|
44
|
-
"chokidar": "^4.0.
|
|
45
|
-
"consola": "^3.
|
|
44
|
+
"chokidar": "^4.0.3",
|
|
45
|
+
"consola": "^3.3.3",
|
|
46
46
|
"debug": "^4.4.0",
|
|
47
47
|
"picocolors": "^1.1.1",
|
|
48
|
-
"pkg-types": "^1.
|
|
49
|
-
"rolldown": "
|
|
50
|
-
"rollup": "^4.
|
|
48
|
+
"pkg-types": "^1.3.0",
|
|
49
|
+
"rolldown": "^1.0.0-beta.1",
|
|
50
|
+
"rollup": "^4.29.1",
|
|
51
51
|
"rollup-plugin-dts": "^6.1.1",
|
|
52
52
|
"tinyglobby": "^0.2.10",
|
|
53
53
|
"unconfig": "^0.6.0",
|
|
54
|
-
"unplugin-isolated-decl": "^0.10.
|
|
55
|
-
"unplugin-unused": "^0.
|
|
54
|
+
"unplugin-isolated-decl": "^0.10.3",
|
|
55
|
+
"unplugin-unused": "^0.3.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@sxzz/eslint-config": "^4.5.1",
|
|
59
59
|
"@sxzz/prettier-config": "^2.0.2",
|
|
60
60
|
"@sxzz/test-utils": "^0.3.11",
|
|
61
61
|
"@types/debug": "^4.1.12",
|
|
62
|
-
"@types/node": "^22.10.
|
|
63
|
-
"bumpp": "^9.9.
|
|
64
|
-
"eslint": "^9.
|
|
65
|
-
"oxc-transform": "^0.
|
|
62
|
+
"@types/node": "^22.10.2",
|
|
63
|
+
"bumpp": "^9.9.2",
|
|
64
|
+
"eslint": "^9.17.0",
|
|
65
|
+
"oxc-transform": "^0.44.0",
|
|
66
66
|
"prettier": "^3.4.2",
|
|
67
|
-
"tinyexec": "^0.3.
|
|
67
|
+
"tinyexec": "^0.3.2",
|
|
68
68
|
"tsup": "^8.3.5",
|
|
69
69
|
"tsx": "^4.19.2",
|
|
70
70
|
"typescript": "~5.7.2",
|
|
71
|
-
"
|
|
71
|
+
"unplugin-ast": "^0.13.1",
|
|
72
|
+
"vitest": "^3.0.0-beta.3"
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|
|
74
75
|
"node": ">=18.0.0"
|