tsdown 0.21.7 → 0.21.9
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/{build-DU-BFLB1.mjs → build-OX8uszs6.mjs} +48 -55
- package/dist/{config-BJiwtsMo.d.mts → config-CuK0i1Bc.d.mts} +2 -2
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/{format-_3CEX8E7.mjs → format-CajNSstg.mjs} +2 -11
- package/dist/index-DraNj4FA.d.mts +331 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +3 -3
- package/dist/internal.d.mts +5 -2
- package/dist/internal.mjs +2 -1
- package/dist/{options-j2tUAf6W.mjs → options-8hmVMssn.mjs} +99 -56
- package/dist/{package-CBgnLfjl.mjs → package-JOXUdJGa.mjs} +1 -1
- package/dist/plugins.d.mts +3 -3
- package/dist/plugins.mjs +2 -2
- package/dist/run.mjs +4 -4
- package/dist/target-s30wya8e.mjs +37 -0
- package/dist/{types-DD-uKQPn.d.mts → types-BZNNnDKc.d.mts} +69 -307
- package/dist/{watch-ZJbRq-K8.mjs → watch-D6EGzM6P.mjs} +3 -3
- package/package.json +30 -29
- package/dist/logger-DLaktdLm.d.mts +0 -30
- /package/dist/{debug-BmAPbhgA.mjs → debug-CLlnG64L.mjs} +0 -0
- /package/dist/{detect-h8ZFBH96.mjs → detect-DN3DXXYt.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as buildWithConfigs, t as build } from "./build-
|
|
2
|
-
import { r as resolveUserConfig, t as mergeConfig } from "./options-
|
|
1
|
+
import { n as buildWithConfigs, t as build } from "./build-OX8uszs6.mjs";
|
|
2
|
+
import { r as resolveUserConfig, t as mergeConfig } from "./options-8hmVMssn.mjs";
|
|
3
3
|
import { a as globalLogger } from "./logger-uV8l1UFa.mjs";
|
|
4
4
|
import { defineConfig } from "./config.mjs";
|
|
5
|
-
import { t as enableDebug } from "./debug-
|
|
5
|
+
import { t as enableDebug } from "./debug-CLlnG64L.mjs";
|
|
6
6
|
import * as Rolldown from "rolldown";
|
|
7
7
|
export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as Overwrite, r as Logger, s as MarkPartial } from "./index-DraNj4FA.mjs";
|
|
2
2
|
|
|
3
|
+
//#region src/features/target.d.ts
|
|
4
|
+
declare function expandBaselineTarget(targets: string[]): string[];
|
|
5
|
+
//#endregion
|
|
3
6
|
//#region src/utils/fs.d.ts
|
|
4
7
|
declare function fsExists(path: string): Promise<boolean>;
|
|
5
8
|
declare function fsRemove(path: string): Promise<void>;
|
|
@@ -9,4 +12,4 @@ declare function toArray<T>(val: T | T[] | null | undefined, defaultValue?: T):
|
|
|
9
12
|
declare function resolveComma<T extends string>(arr: T[]): T[];
|
|
10
13
|
declare function importWithError<T>(moduleName: string): Promise<T>;
|
|
11
14
|
//#endregion
|
|
12
|
-
export { type Logger, type MarkPartial, type Overwrite, fsExists, fsRemove, importWithError, resolveComma, toArray };
|
|
15
|
+
export { type Logger, type MarkPartial, type Overwrite, expandBaselineTarget, fsExists, fsRemove, importWithError, resolveComma, toArray };
|
package/dist/internal.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { n as fsExists, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
2
2
|
import { n as importWithError, s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
|
|
3
|
-
|
|
3
|
+
import { t as expandBaselineTarget } from "./target-s30wya8e.mjs";
|
|
4
|
+
export { expandBaselineTarget, fsExists, fsRemove, importWithError, resolveComma, toArray };
|
|
@@ -3,7 +3,8 @@ const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
|
3
3
|
import { a as lowestCommonAncestor, i as fsStat, n as fsExists, o as stripExtname, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
4
4
|
import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
|
|
5
5
|
import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-uV8l1UFa.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { r as resolveDepsConfig, t as formatBytes } from "./format-CajNSstg.mjs";
|
|
7
|
+
import { n as resolveTarget } from "./target-s30wya8e.mjs";
|
|
7
8
|
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
import process, { env } from "node:process";
|
|
@@ -17,11 +18,11 @@ import { tmpdir } from "node:os";
|
|
|
17
18
|
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
18
19
|
import { x } from "tinyexec";
|
|
19
20
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
20
|
-
|
|
21
|
+
import { isDeepStrictEqual } from "node:util";
|
|
21
22
|
import { up } from "empathic/find";
|
|
22
23
|
import { up as up$1 } from "empathic/package";
|
|
23
24
|
import { pathToFileURL } from "node:url";
|
|
24
|
-
import { init, isSupported } from "import-without-cache";
|
|
25
|
+
import { depsStore, init, isSupported } from "import-without-cache";
|
|
25
26
|
import { createConfigCoreLoader } from "unconfig-core";
|
|
26
27
|
//#region node_modules/.pnpm/is-in-ci@2.0.0/node_modules/is-in-ci/index.js
|
|
27
28
|
const check = (key) => key in env && env[key] !== "0" && env[key] !== "false";
|
|
@@ -231,32 +232,61 @@ async function buildSingleExe(config, bundledFile, outputFile, executable, targe
|
|
|
231
232
|
config.logger.success(config.nameLabel, `Built executable: ${red(path.relative(config.cwd, outputPath))}`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
232
233
|
}
|
|
233
234
|
//#endregion
|
|
235
|
+
//#region src/utils/json.ts
|
|
236
|
+
function writeJsonFile(filePath, content) {
|
|
237
|
+
let originalText;
|
|
238
|
+
let originalJson = void 0;
|
|
239
|
+
let originalIndent = 2;
|
|
240
|
+
let originalEOL = "\n";
|
|
241
|
+
let originalHasTrailingNewline = false;
|
|
242
|
+
try {
|
|
243
|
+
originalText = readFileSync(filePath, "utf8");
|
|
244
|
+
originalJson = JSON.parse(originalText);
|
|
245
|
+
originalIndent = detectIndentation(originalText);
|
|
246
|
+
if (originalText.includes("\r\n")) originalEOL = "\r\n";
|
|
247
|
+
if (originalText.endsWith("\n")) originalHasTrailingNewline = true;
|
|
248
|
+
} catch {}
|
|
249
|
+
if (originalJson && (isDeepStrictEqual(originalJson, content) || JSON.stringify(originalJson) === JSON.stringify(content))) return;
|
|
250
|
+
let jsonString = JSON.stringify(content, null, originalIndent);
|
|
251
|
+
if (originalEOL !== "\n") jsonString = jsonString.replaceAll("\n", originalEOL);
|
|
252
|
+
if (originalHasTrailingNewline) jsonString += originalEOL;
|
|
253
|
+
if (originalText === jsonString) return;
|
|
254
|
+
writeFileSync(filePath, jsonString, "utf8");
|
|
255
|
+
}
|
|
256
|
+
function detectIndentation(jsonText) {
|
|
257
|
+
const lines = jsonText.split(/\r?\n/);
|
|
258
|
+
for (const line of lines) {
|
|
259
|
+
const match = line.match(/^(\s+)\S/);
|
|
260
|
+
if (!match) continue;
|
|
261
|
+
if (match[1].includes(" ")) return " ";
|
|
262
|
+
return match[1].length;
|
|
263
|
+
}
|
|
264
|
+
return 2;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
234
267
|
//#region src/features/pkg/exports.ts
|
|
235
268
|
async function writeExports(options, chunks, inlinedDeps) {
|
|
236
269
|
const { pkg } = options;
|
|
237
|
-
const { publishExports, bin, ...generated } = await generateExports(pkg, chunks, options, inlinedDeps);
|
|
270
|
+
const { publishExports, publishBin, bin, ...generated } = await generateExports(pkg, chunks, options, inlinedDeps);
|
|
238
271
|
const updatedPkg = {
|
|
239
272
|
...pkg,
|
|
240
273
|
...generated,
|
|
241
274
|
...bin === void 0 ? {} : { bin },
|
|
242
275
|
packageJsonPath: void 0
|
|
243
276
|
};
|
|
244
|
-
if (publishExports) {
|
|
277
|
+
if (publishExports || publishBin) {
|
|
245
278
|
updatedPkg.publishConfig ||= {};
|
|
246
|
-
updatedPkg.publishConfig.exports = publishExports;
|
|
279
|
+
if (publishExports) updatedPkg.publishConfig.exports = publishExports;
|
|
280
|
+
if (publishBin) updatedPkg.publishConfig.bin = publishBin;
|
|
247
281
|
}
|
|
248
|
-
|
|
249
|
-
let contents = JSON.stringify(updatedPkg, null, detectIndentation(original));
|
|
250
|
-
if (original.includes("\r\n")) contents = contents.replaceAll("\n", "\r\n");
|
|
251
|
-
if (original.endsWith("\n")) contents += "\n";
|
|
252
|
-
if (contents !== original) writeFileSync(pkg.packageJsonPath, contents, "utf8");
|
|
282
|
+
writeJsonFile(pkg.packageJsonPath, updatedPkg);
|
|
253
283
|
}
|
|
254
284
|
function shouldExclude(fileName, exclude) {
|
|
255
285
|
if (!exclude?.length) return false;
|
|
256
286
|
return matchPattern(fileName, exclude);
|
|
257
287
|
}
|
|
258
288
|
async function generateExports(pkg, chunks, options, inlinedDeps) {
|
|
259
|
-
let { exports: { devExports, all, packageJson = true, exclude, customExports, legacy, inlinedDependencies: emitInlinedDeps = true, bin }, css, logger, cwd } = options;
|
|
289
|
+
let { exports: { devExports, all, packageJson = true, exclude, customExports, legacy, extensions, inlinedDependencies: emitInlinedDeps = true, bin }, css, logger, cwd } = options;
|
|
260
290
|
const pkgRoot = path.dirname(pkg.packageJsonPath);
|
|
261
291
|
let main, module, cjsTypes, esmTypes;
|
|
262
292
|
const exportsMap = /* @__PURE__ */ new Map();
|
|
@@ -288,6 +318,7 @@ async function generateExports(pkg, chunks, options, inlinedDeps) {
|
|
|
288
318
|
else module = distFile;
|
|
289
319
|
} else if (name.endsWith("/index")) name = `./${name.slice(0, -6)}`;
|
|
290
320
|
else name = `./${name}`;
|
|
321
|
+
if (extensions && name !== ".") name = `${name}.js`;
|
|
291
322
|
let subExport = exportsMap.get(name);
|
|
292
323
|
if (!subExport) {
|
|
293
324
|
subExport = {};
|
|
@@ -330,12 +361,15 @@ async function generateExports(pkg, chunks, options, inlinedDeps) {
|
|
|
330
361
|
isPublish: true
|
|
331
362
|
});
|
|
332
363
|
}
|
|
364
|
+
const binResult = generateBin(bin, !!devExports, pkg, chunks, pkgRoot, logger, cwd);
|
|
365
|
+
const publishBin = devExports && binResult ? generateBin(bin, false, pkg, chunks, pkgRoot, logger, cwd) : void 0;
|
|
333
366
|
return {
|
|
334
367
|
main: legacy ? main || module || pkg.main : void 0,
|
|
335
368
|
module: legacy ? module || pkg.module : void 0,
|
|
336
369
|
types: legacy ? cjsTypes || esmTypes || pkg.types : pkg.types,
|
|
337
370
|
exports,
|
|
338
|
-
bin:
|
|
371
|
+
bin: binResult,
|
|
372
|
+
publishBin,
|
|
339
373
|
inlinedDependencies: emitInlinedDeps ? inlinedDeps : void 0,
|
|
340
374
|
publishExports
|
|
341
375
|
};
|
|
@@ -378,7 +412,7 @@ function hasExportsTypes(pkg) {
|
|
|
378
412
|
return false;
|
|
379
413
|
}
|
|
380
414
|
const RE_SHEBANG = /^#!.*/;
|
|
381
|
-
function generateBin(bin, pkg, chunks, pkgRoot, logger, cwd) {
|
|
415
|
+
function generateBin(bin, devExports, pkg, chunks, pkgRoot, logger, cwd) {
|
|
382
416
|
if (!bin) return;
|
|
383
417
|
if (bin === true || typeof bin === "string") {
|
|
384
418
|
if (!pkg.name) throw new Error("Package name is required when using string form for `bin`");
|
|
@@ -395,7 +429,7 @@ function generateBin(bin, pkg, chunks, pkgRoot, logger, cwd) {
|
|
|
395
429
|
if (seen.has(chunk.facadeModuleId)) continue;
|
|
396
430
|
seen.add(chunk.facadeModuleId);
|
|
397
431
|
if (detected) throw new Error("Multiple entry chunks with shebangs found. Use `exports.bin: { name: \"./src/file.ts\" }` to specify which one to use.");
|
|
398
|
-
detected = join(pkgRoot, chunk.outDir, slash(chunk.fileName));
|
|
432
|
+
detected = devExports ? `./${slash(path.relative(pkgRoot, chunk.facadeModuleId))}` : join(pkgRoot, chunk.outDir, slash(chunk.fileName));
|
|
399
433
|
}
|
|
400
434
|
}
|
|
401
435
|
if (detected == null) {
|
|
@@ -407,16 +441,20 @@ function generateBin(bin, pkg, chunks, pkgRoot, logger, cwd) {
|
|
|
407
441
|
if (typeof bin === "string") {
|
|
408
442
|
const match = findChunkBySource(bin);
|
|
409
443
|
if (!match) throw new Error(`Could not find output chunk for bin entry "${bin}"`);
|
|
410
|
-
return { [binName]: match };
|
|
444
|
+
return { [binName]: devExports ? normalizeSource(bin) : match };
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
447
|
const result = {};
|
|
414
448
|
for (const [cmdName, sourcePath] of Object.entries(bin)) {
|
|
415
449
|
const match = findChunkBySource(sourcePath);
|
|
416
450
|
if (!match) throw new Error(`Could not find output chunk for bin entry "${cmdName}": "${sourcePath}"`);
|
|
417
|
-
result[cmdName] = match;
|
|
451
|
+
result[cmdName] = devExports ? normalizeSource(sourcePath) : match;
|
|
418
452
|
}
|
|
419
453
|
return result;
|
|
454
|
+
function normalizeSource(sourcePath) {
|
|
455
|
+
const resolved = path.resolve(cwd, sourcePath);
|
|
456
|
+
return `./${slash(path.relative(pkgRoot, resolved))}`;
|
|
457
|
+
}
|
|
420
458
|
function findChunkBySource(sourcePath) {
|
|
421
459
|
const resolved = path.resolve(cwd, sourcePath);
|
|
422
460
|
for (const format of ["es", "cjs"]) {
|
|
@@ -447,26 +485,12 @@ function join(pkgRoot, outDir, fileName) {
|
|
|
447
485
|
return `${outDirRelative ? `./${outDirRelative}` : "."}/${fileName}`;
|
|
448
486
|
}
|
|
449
487
|
//#endregion
|
|
450
|
-
//#region src/features/
|
|
451
|
-
function
|
|
452
|
-
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
else return;
|
|
457
|
-
}
|
|
458
|
-
if (typeof target === "number") throw new TypeError(`Invalid target: ${target}`);
|
|
459
|
-
const targets = resolveComma(toArray(target));
|
|
460
|
-
if (targets.length) logger.info(nameLabel, `target${targets.length > 1 ? "s" : ""}: ${color(targets.join(", "))}`);
|
|
461
|
-
return targets;
|
|
462
|
-
}
|
|
463
|
-
function resolvePackageTarget(pkg) {
|
|
464
|
-
const nodeVersion = pkg?.engines?.node;
|
|
465
|
-
if (!nodeVersion) return;
|
|
466
|
-
const nodeMinVersion = minVersion(nodeVersion);
|
|
467
|
-
if (!nodeMinVersion) return;
|
|
468
|
-
if (nodeMinVersion.version === "0.0.0") return;
|
|
469
|
-
return `node${nodeMinVersion.version}`;
|
|
488
|
+
//#region src/features/plugin.ts
|
|
489
|
+
async function flattenPlugins(plugins) {
|
|
490
|
+
const awaited = await plugins;
|
|
491
|
+
if (!awaited) return [];
|
|
492
|
+
if (Array.isArray(awaited)) return (await Promise.all(awaited.map(flattenPlugins))).flat();
|
|
493
|
+
return [awaited];
|
|
470
494
|
}
|
|
471
495
|
//#endregion
|
|
472
496
|
//#region src/features/tsconfig.ts
|
|
@@ -547,14 +571,17 @@ async function loadViteConfig(prefix, cwd, configLoader) {
|
|
|
547
571
|
cwd
|
|
548
572
|
}).load(true);
|
|
549
573
|
if (!result) return;
|
|
550
|
-
|
|
574
|
+
let { config: [exported, deps], source } = result;
|
|
551
575
|
globalLogger.info(`Using Vite config: ${underline(source)}`);
|
|
552
|
-
|
|
553
|
-
if (typeof
|
|
576
|
+
exported = await exported;
|
|
577
|
+
if (typeof exported === "function") exported = await exported({
|
|
554
578
|
command: "build",
|
|
555
579
|
mode: "production"
|
|
556
580
|
});
|
|
557
|
-
return
|
|
581
|
+
return {
|
|
582
|
+
config: exported,
|
|
583
|
+
deps
|
|
584
|
+
};
|
|
558
585
|
}
|
|
559
586
|
const configPrefix = "tsdown.config";
|
|
560
587
|
async function loadConfigFile(inlineConfig, workspace, rootConfig) {
|
|
@@ -602,8 +629,9 @@ async function loadConfigFile(inlineConfig, workspace, rootConfig) {
|
|
|
602
629
|
}).load(true);
|
|
603
630
|
let exported = [];
|
|
604
631
|
let file;
|
|
632
|
+
let deps;
|
|
605
633
|
if (result) {
|
|
606
|
-
({config: exported, source: file} = result);
|
|
634
|
+
({config: [exported, deps], source: file} = result);
|
|
607
635
|
globalLogger.info(`config file: ${underline(file)}`, loader === "native" ? "" : `(${loader})`);
|
|
608
636
|
exported = await exported;
|
|
609
637
|
if (typeof exported === "function") exported = await exported(inlineConfig, {
|
|
@@ -619,7 +647,7 @@ async function loadConfigFile(inlineConfig, workspace, rootConfig) {
|
|
|
619
647
|
...config,
|
|
620
648
|
cwd: config.cwd ? path.resolve(cwd, config.cwd) : cwd
|
|
621
649
|
})),
|
|
622
|
-
|
|
650
|
+
deps
|
|
623
651
|
};
|
|
624
652
|
}
|
|
625
653
|
const isBun = !!process.versions.bun;
|
|
@@ -636,31 +664,30 @@ function createParser(loader) {
|
|
|
636
664
|
if (basename === configPrefix || isPkgJson || basename.endsWith(".json")) {
|
|
637
665
|
const contents = await readFile(filepath, "utf8");
|
|
638
666
|
const parsed = JSON.parse(contents);
|
|
639
|
-
|
|
640
|
-
return parsed;
|
|
667
|
+
return [isPkgJson ? parsed?.tsdown : parsed, new Set([filepath])];
|
|
641
668
|
}
|
|
642
|
-
|
|
643
|
-
return unrunImport(filepath);
|
|
669
|
+
return (loader === "native" ? nativeImport : unrunImport)(filepath);
|
|
644
670
|
};
|
|
645
671
|
}
|
|
646
672
|
async function nativeImport(id) {
|
|
673
|
+
const deps = new Set([id]);
|
|
647
674
|
const url = pathToFileURL(id);
|
|
648
675
|
const importAttributes = Object.create(null);
|
|
649
676
|
if (isSupported) {
|
|
650
677
|
importAttributes.cache = "no";
|
|
651
678
|
init({ skipNodeModules: true });
|
|
652
679
|
} else if (!isBun) url.searchParams.set("no-cache", crypto.randomUUID());
|
|
653
|
-
const mod = await import(url.href, { with: importAttributes }).catch((error) => {
|
|
680
|
+
const mod = await depsStore.run(deps, () => import(url.href, { with: importAttributes }).catch((error) => {
|
|
654
681
|
if (error?.message?.includes?.("Cannot find module")) throw new Error(`Failed to load the config file. Try setting the --config-loader CLI flag to \`unrun\`.\n\n${error.message}`, { cause: error });
|
|
655
682
|
if (typeof error?.stack === "string" && error.stack.includes("node:internal/modules/esm/translators")) throw new Error(`Failed to load the config file due to a known Node.js bug. Try setting the --config-loader CLI flag to \`unrun\` or upgrading Node.js to v24.11.1 or later.\n\n${error.message}`, { cause: error });
|
|
656
683
|
throw error;
|
|
657
|
-
});
|
|
658
|
-
return mod.default || mod;
|
|
684
|
+
}));
|
|
685
|
+
return [mod.default || mod, deps];
|
|
659
686
|
}
|
|
660
687
|
async function unrunImport(id) {
|
|
661
688
|
const { unrun } = await import("unrun");
|
|
662
|
-
const { module } = await unrun({ path: pathToFileURL(id).href });
|
|
663
|
-
return module;
|
|
689
|
+
const { module, dependencies } = await unrun({ path: pathToFileURL(id).href });
|
|
690
|
+
return [module, new Set(dependencies)];
|
|
664
691
|
}
|
|
665
692
|
//#endregion
|
|
666
693
|
//#region src/config/options.ts
|
|
@@ -672,7 +699,14 @@ const parseEnv = process.getBuiltinModule("node:util").parseEnv;
|
|
|
672
699
|
* **Internal API, not for public use**
|
|
673
700
|
* @private
|
|
674
701
|
*/
|
|
675
|
-
async function resolveUserConfig(userConfig, inlineConfig) {
|
|
702
|
+
async function resolveUserConfig(userConfig, inlineConfig, configDeps) {
|
|
703
|
+
{
|
|
704
|
+
const flat = await flattenPlugins(userConfig.plugins);
|
|
705
|
+
for (const plugin of flat) {
|
|
706
|
+
const result = await plugin.tsdownConfig?.(userConfig, inlineConfig);
|
|
707
|
+
if (result) userConfig = mergeConfig(userConfig, result);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
676
710
|
let { entry, format, plugins = [], clean = true, logLevel = "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, root, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, css, injectStyle, fixedExtension = platform === "node", devtools = false, write = true, exe = false } = userConfig;
|
|
677
711
|
const pkg = await readPackageJson(cwd);
|
|
678
712
|
if (workspace) name ||= pkg?.name;
|
|
@@ -737,16 +771,19 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
737
771
|
...env
|
|
738
772
|
};
|
|
739
773
|
debug(`Environment variables: %O`, env);
|
|
774
|
+
configDeps = new Set(configDeps);
|
|
740
775
|
if (fromVite) {
|
|
741
776
|
const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd, inlineConfig.configLoader);
|
|
742
777
|
if (viteUserConfig) {
|
|
743
|
-
const
|
|
778
|
+
const { config, deps } = viteUserConfig;
|
|
779
|
+
deps?.forEach((dep) => configDeps.add(dep));
|
|
780
|
+
const viteAlias = config.resolve?.alias;
|
|
744
781
|
if (Array.isArray(viteAlias)) throw new TypeError("Unsupported resolve.alias in Vite config. Use object instead of array");
|
|
745
782
|
if (viteAlias) alias = {
|
|
746
783
|
...alias,
|
|
747
784
|
...viteAlias
|
|
748
785
|
};
|
|
749
|
-
if (
|
|
786
|
+
if (config.plugins) plugins = [config.plugins, plugins];
|
|
750
787
|
}
|
|
751
788
|
}
|
|
752
789
|
ignoreWatch = toArray(ignoreWatch).map((ignore) => {
|
|
@@ -766,6 +803,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
766
803
|
attw,
|
|
767
804
|
cjsDefault,
|
|
768
805
|
clean,
|
|
806
|
+
configDeps,
|
|
769
807
|
copy: publicDir || copy,
|
|
770
808
|
css,
|
|
771
809
|
cwd,
|
|
@@ -804,7 +842,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
804
842
|
};
|
|
805
843
|
if (exe) validateSea(config);
|
|
806
844
|
const objectFormat = typeof format === "object" && !Array.isArray(format);
|
|
807
|
-
|
|
845
|
+
const resolvedConfigs = (objectFormat ? Object.keys(format) : resolveComma(toArray(format, "esm"))).map((fmt, idx) => {
|
|
808
846
|
const once = idx === 0;
|
|
809
847
|
const overrides = objectFormat ? format[fmt] : void 0;
|
|
810
848
|
return {
|
|
@@ -815,6 +853,11 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
815
853
|
...overrides
|
|
816
854
|
};
|
|
817
855
|
});
|
|
856
|
+
for (const resolved of resolvedConfigs) {
|
|
857
|
+
const finalPlugins = await flattenPlugins(resolved.plugins);
|
|
858
|
+
for (const plugin of finalPlugins) await plugin.tsdownConfigResolved?.(resolved);
|
|
859
|
+
}
|
|
860
|
+
return resolvedConfigs;
|
|
818
861
|
}
|
|
819
862
|
/** filter env variables by prefixes */
|
|
820
863
|
function filterEnv(envDict, envPrefixes) {
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { r as Logger } from "./index-DraNj4FA.mjs";
|
|
2
|
+
import { H as TsdownBundle, R as DepsPlugin, _ as ReportPlugin } from "./types-BZNNnDKc.mjs";
|
|
3
3
|
import { Plugin } from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/features/node-protocol.d.ts
|
|
@@ -13,7 +13,7 @@ declare function NodeProtocolPlugin(nodeProtocolOption: "strip" | true): Plugin;
|
|
|
13
13
|
declare function ShebangPlugin(logger: Logger, cwd: string, nameLabel?: string, isDualFormat?: boolean): Plugin;
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/features/watch.d.ts
|
|
16
|
-
declare function WatchPlugin(
|
|
16
|
+
declare function WatchPlugin(configDeps: Set<string>, {
|
|
17
17
|
config,
|
|
18
18
|
chunks
|
|
19
19
|
}: TsdownBundle): Plugin;
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-
|
|
1
|
+
import { n as DepsPlugin } from "./format-CajNSstg.mjs";
|
|
2
|
+
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-D6EGzM6P.mjs";
|
|
3
3
|
export { DepsPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
3
3
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
4
|
import { a as globalLogger } from "./logger-uV8l1UFa.mjs";
|
|
5
|
-
import { t as version } from "./package-
|
|
6
|
-
import { t as enableDebug } from "./debug-
|
|
5
|
+
import { t as version } from "./package-JOXUdJGa.mjs";
|
|
6
|
+
import { t as enableDebug } from "./debug-CLlnG64L.mjs";
|
|
7
7
|
import module from "node:module";
|
|
8
8
|
import process from "node:process";
|
|
9
9
|
import { blue, hex, yellow } from "ansis";
|
|
@@ -20,7 +20,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
20
20
|
}).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).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("--deps.never-bundle <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").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("--no-write", "Disable writing files to disk, incompatible with watch mode").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("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).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("--root <dir>", "Root directory of input files").option("--exe", "Bundle as executable").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
21
21
|
globalLogger.level = flags.logLevel || "info";
|
|
22
22
|
globalLogger.info(`${blue`tsdown v${version}`} powered by ${hex("#ff7e17")`rolldown v${VERSION}`}`);
|
|
23
|
-
const { build } = await import("./build-
|
|
23
|
+
const { build } = await import("./build-OX8uszs6.mjs").then((n) => n.r);
|
|
24
24
|
if (input.length > 0) flags.entry = input;
|
|
25
25
|
await build(flags);
|
|
26
26
|
});
|
|
@@ -54,7 +54,7 @@ async function runCLI() {
|
|
|
54
54
|
}
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/run.ts
|
|
57
|
-
if (lt(process.version, "22.18.0")) console.warn(yellow`[tsdown] Node.js ${process.version} is deprecated. Support will be removed in the next minor release. Please upgrade to Node.js
|
|
57
|
+
if (!process.versions.bun && lt(process.version, "22.18.0")) console.warn(yellow`[tsdown] Node.js ${process.version} is deprecated. Support will be removed in the next minor release. Please upgrade to Node.js v22.18.0 or later.`);
|
|
58
58
|
try {
|
|
59
59
|
module.enableCompileCache?.();
|
|
60
60
|
} catch {}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
+
import { s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
|
|
4
|
+
const minVersion = __cjs_require("semver/ranges/min-version.js");
|
|
5
|
+
//#region src/features/target.ts
|
|
6
|
+
const BASELINE_WIDELY_AVAILABLE_TARGET = [
|
|
7
|
+
"chrome111",
|
|
8
|
+
"edge111",
|
|
9
|
+
"firefox114",
|
|
10
|
+
"safari16.4",
|
|
11
|
+
"ios16.4"
|
|
12
|
+
];
|
|
13
|
+
function expandBaselineTarget(targets) {
|
|
14
|
+
return targets.flatMap((t) => t === "baseline-widely-available" ? BASELINE_WIDELY_AVAILABLE_TARGET : t);
|
|
15
|
+
}
|
|
16
|
+
function resolveTarget(logger, target, color, pkg, nameLabel) {
|
|
17
|
+
if (target === false) return;
|
|
18
|
+
if (target == null) {
|
|
19
|
+
const pkgTarget = resolvePackageTarget(pkg);
|
|
20
|
+
if (pkgTarget) target = pkgTarget;
|
|
21
|
+
else return;
|
|
22
|
+
}
|
|
23
|
+
if (typeof target === "number") throw new TypeError(`Invalid target: ${target}`);
|
|
24
|
+
const targets = expandBaselineTarget(resolveComma(toArray(target)));
|
|
25
|
+
if (targets.length) logger.info(nameLabel, `target${targets.length > 1 ? "s" : ""}: ${color(targets.join(", "))}`);
|
|
26
|
+
return targets;
|
|
27
|
+
}
|
|
28
|
+
function resolvePackageTarget(pkg) {
|
|
29
|
+
const nodeVersion = pkg?.engines?.node;
|
|
30
|
+
if (!nodeVersion) return;
|
|
31
|
+
const nodeMinVersion = minVersion(nodeVersion);
|
|
32
|
+
if (!nodeMinVersion) return;
|
|
33
|
+
if (nodeMinVersion.version === "0.0.0") return;
|
|
34
|
+
return `node${nodeMinVersion.version}`;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { resolveTarget as n, expandBaselineTarget as t };
|