tsdown 0.21.0-beta.2 → 0.21.0-beta.4
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-CY6c95FN.mjs +3 -0
- package/dist/{build-BjQ7Rt90.mjs → build-Dd9GjMta.mjs} +40 -143
- package/dist/{config-BHswT60K.d.mts → config-CB5uSdbf.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/css-BGrvAa8p.mjs +23 -0
- package/dist/css.d.mts +29 -0
- package/dist/css.mjs +4 -0
- package/dist/{debug-BUVkFfEZ.mjs → debug-DtUr55Vs.mjs} +1 -1
- package/dist/{format-J6JPSe_8.mjs → format-DlhdOGIw.mjs} +33 -17
- package/dist/general-1LELSDyN.mjs +75 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/{logger-JoV-m1IK.mjs → logger-C4Xhh0rW.mjs} +2 -74
- package/dist/{options-eWdmaqEa.mjs → options-DLWsyWjz.mjs} +59 -30
- package/dist/package-DgL9kC53.mjs +5 -0
- package/dist/plugin-Bzpx14BV.mjs +124 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +2 -2
- package/dist/run.mjs +9 -5
- package/dist/{types-CfT5JZgs.d.mts → types-DmX8JP3Y.d.mts} +138 -17
- package/dist/{watch-CqXGVrf6.mjs → watch-DoBIgnx3.mjs} +3 -2
- package/package.json +34 -21
- package/dist/build-2oRq4mfQ.mjs +0 -3
- package/dist/package-DC_1qnJd.mjs +0 -5
- /package/dist/{detect-CCATtVj7.mjs → detect-CeWQMhKA.mjs} +0 -0
- /package/dist/{index-node-ShM0x2b6.mjs → index-node-CDF8A25m.mjs} +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
import { a as getPackageType, c as
|
|
5
|
-
import { a as getShimsInject, c as fsRemove, o as fsCopy, r as DepPlugin, u as lowestCommonAncestor } from "./format-
|
|
6
|
-
import { t as
|
|
7
|
-
import {
|
|
3
|
+
import { l as slash, n as importWithError, o as promiseWithResolvers, t as debounce, u as toArray } from "./general-1LELSDyN.mjs";
|
|
4
|
+
import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as cleanChunks } from "./options-DLWsyWjz.mjs";
|
|
5
|
+
import { a as getShimsInject, c as fsRemove, o as fsCopy, r as DepPlugin, u as lowestCommonAncestor } from "./format-DlhdOGIw.mjs";
|
|
6
|
+
import { a as globalLogger, t as LogLevels } from "./logger-C4Xhh0rW.mjs";
|
|
7
|
+
import { t as CssPlugin } from "./plugin-Bzpx14BV.mjs";
|
|
8
|
+
import { t as version } from "./package-DgL9kC53.mjs";
|
|
9
|
+
import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, t as WatchPlugin } from "./watch-DoBIgnx3.mjs";
|
|
8
10
|
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
9
11
|
import path from "node:path";
|
|
10
12
|
import process from "node:process";
|
|
@@ -195,7 +197,8 @@ function executeOnSuccess(config) {
|
|
|
195
197
|
if (typeof config.onSuccess === "string") {
|
|
196
198
|
const p = exec(config.onSuccess, [], { nodeOptions: {
|
|
197
199
|
shell: true,
|
|
198
|
-
stdio: "inherit"
|
|
200
|
+
stdio: "inherit",
|
|
201
|
+
cwd: config.cwd
|
|
199
202
|
} });
|
|
200
203
|
p.then(({ exitCode }) => {
|
|
201
204
|
if (exitCode) process.exitCode = exitCode;
|
|
@@ -355,12 +358,13 @@ async function bundleDone(bundleByPkg, bundle) {
|
|
|
355
358
|
if (exportsConfigs.length) {
|
|
356
359
|
if (exportsConfigs.length > 1) throw new Error(`Conflicting exports options for package at ${pkg.packageJsonPath}. Please merge them:\n${exportsConfigs.map((config) => `- ${formatWithOptions({ colors: true }, config.exports)}`).join("\n")}`);
|
|
357
360
|
const chunks = {};
|
|
361
|
+
const inlinedDeps = mergeInlinedDeps(ctx.bundles);
|
|
358
362
|
for (const bundle of ctx.bundles) {
|
|
359
363
|
if (!bundle.config.exports) continue;
|
|
360
364
|
chunks[bundle.config.format] ||= [];
|
|
361
365
|
chunks[bundle.config.format].push(...bundle.chunks);
|
|
362
366
|
}
|
|
363
|
-
await writeExports(exportsConfigs[0], chunks);
|
|
367
|
+
await writeExports(exportsConfigs[0], chunks, inlinedDeps);
|
|
364
368
|
}
|
|
365
369
|
const publintConfigs = dedupeConfigs(configs, "publint");
|
|
366
370
|
const attwConfigs = dedupeConfigs(configs, "attw");
|
|
@@ -378,7 +382,7 @@ async function bundleDone(bundleByPkg, bundle) {
|
|
|
378
382
|
async function packTarball(packageJsonPath) {
|
|
379
383
|
const pkgDir = path.dirname(packageJsonPath);
|
|
380
384
|
const destination = await mkdtemp(path.join(tmpdir(), "tsdown-pack-"));
|
|
381
|
-
const [{ detect }, { pack }] = await Promise.all([import("./detect-
|
|
385
|
+
const [{ detect }, { pack }] = await Promise.all([import("./detect-CeWQMhKA.mjs"), import("./index-node-CDF8A25m.mjs")]);
|
|
382
386
|
try {
|
|
383
387
|
const detected = await detect({ cwd: pkgDir });
|
|
384
388
|
if (detected?.name === "deno") throw new Error(`Cannot pack tarball for Deno projects at ${pkgDir}`);
|
|
@@ -404,135 +408,16 @@ function dedupeConfigs(configs, key) {
|
|
|
404
408
|
if (results.length === 0) return [filtered[0]];
|
|
405
409
|
return results;
|
|
406
410
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
*
|
|
413
|
-
* [^1]: https://esbuild.github.io/api/#target
|
|
414
|
-
* [^2]: https://github.com/rolldown/rolldown/blob/v1.0.0-beta.8/packages/rolldown/src/binding.d.ts#L1429-L1431
|
|
415
|
-
* [^3]: https://lightningcss.dev/transpilation.html
|
|
416
|
-
*/
|
|
417
|
-
function esbuildTargetToLightningCSS(target) {
|
|
418
|
-
let targets;
|
|
419
|
-
const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
|
|
420
|
-
for (const match of matches) {
|
|
421
|
-
const browser = ESBUILD_LIGHTNINGCSS_MAPPING[match[1]];
|
|
422
|
-
if (!browser) continue;
|
|
423
|
-
const version = match[2];
|
|
424
|
-
const versionInt = parseVersion(version);
|
|
425
|
-
if (versionInt == null) continue;
|
|
426
|
-
targets = targets || {};
|
|
427
|
-
targets[browser] = versionInt;
|
|
411
|
+
function mergeInlinedDeps(bundles) {
|
|
412
|
+
const merged = /* @__PURE__ */ new Map();
|
|
413
|
+
for (const bundle of bundles) for (const [pkgName, versions] of bundle.inlinedDeps) {
|
|
414
|
+
if (!merged.has(pkgName)) merged.set(pkgName, /* @__PURE__ */ new Set());
|
|
415
|
+
for (const v of versions) merged.get(pkgName).add(v);
|
|
428
416
|
}
|
|
429
|
-
return
|
|
430
|
-
}
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
chrome: "chrome",
|
|
434
|
-
edge: "edge",
|
|
435
|
-
firefox: "firefox",
|
|
436
|
-
ie: "ie",
|
|
437
|
-
ios: "ios_saf",
|
|
438
|
-
opera: "opera",
|
|
439
|
-
safari: "safari"
|
|
440
|
-
};
|
|
441
|
-
function parseVersion(version) {
|
|
442
|
-
const [major, minor = 0, patch = 0] = version.split("-")[0].split(".").map((v) => Number.parseInt(v, 10));
|
|
443
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) return null;
|
|
444
|
-
return major << 16 | minor << 8 | patch;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
//#endregion
|
|
448
|
-
//#region src/features/css/lightningcss.ts
|
|
449
|
-
async function LightningCSSPlugin(options) {
|
|
450
|
-
const LightningCSS = await import("unplugin-lightningcss/rolldown").catch(() => void 0);
|
|
451
|
-
if (!LightningCSS) return;
|
|
452
|
-
const targets = options.target && esbuildTargetToLightningCSS(options.target);
|
|
453
|
-
if (!targets) return;
|
|
454
|
-
return LightningCSS.default({ options: { targets } });
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
//#endregion
|
|
458
|
-
//#region src/features/css/splitting.ts
|
|
459
|
-
/**
|
|
460
|
-
* CSS Code Split Plugin
|
|
461
|
-
*
|
|
462
|
-
* When css.splitting is false, this plugin merges all CSS files into a single file.
|
|
463
|
-
* When css.splitting is true (default), CSS code splitting is preserved.
|
|
464
|
-
* Based on Vite's implementation.
|
|
465
|
-
*/
|
|
466
|
-
function CssCodeSplitPlugin(config) {
|
|
467
|
-
const { splitting, fileName } = config.css;
|
|
468
|
-
if (splitting) return;
|
|
469
|
-
return {
|
|
470
|
-
name: "tsdown:css:splitting",
|
|
471
|
-
generateBundle(_outputOptions, bundle) {
|
|
472
|
-
const chunks = Object.values(bundle);
|
|
473
|
-
const cssAssets = /* @__PURE__ */ new Map();
|
|
474
|
-
for (const asset of chunks) if (asset.type === "asset" && typeof asset.source === "string" && RE_CSS.test(fileName)) cssAssets.set(asset.fileName, asset.source);
|
|
475
|
-
if (!cssAssets.size) return;
|
|
476
|
-
const chunkCSSMap = /* @__PURE__ */ new Map();
|
|
477
|
-
for (const chunk of chunks) {
|
|
478
|
-
if (chunk.type !== "chunk") continue;
|
|
479
|
-
for (const moduleId of chunk.moduleIds) if (RE_CSS.test(moduleId)) {
|
|
480
|
-
if (!chunkCSSMap.has(chunk.fileName)) chunkCSSMap.set(chunk.fileName, []);
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
for (const cssFileName of cssAssets.keys()) {
|
|
485
|
-
const cssBaseName = normalizeCssFileName(cssFileName);
|
|
486
|
-
for (const chunkFileName of chunkCSSMap.keys()) if (normalizeChunkFileName(chunkFileName) === cssBaseName || chunkFileName.startsWith(`${cssBaseName}-`)) {
|
|
487
|
-
chunkCSSMap.get(chunkFileName).push(cssFileName);
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
let extractedCss = "";
|
|
492
|
-
const collected = /* @__PURE__ */ new Set();
|
|
493
|
-
const dynamicImports = /* @__PURE__ */ new Set();
|
|
494
|
-
function collect(chunk) {
|
|
495
|
-
if (!chunk || chunk.type !== "chunk" || collected.has(chunk)) return;
|
|
496
|
-
collected.add(chunk);
|
|
497
|
-
chunk.imports.forEach((importName) => {
|
|
498
|
-
collect(bundle[importName]);
|
|
499
|
-
});
|
|
500
|
-
chunk.dynamicImports.forEach((importName) => {
|
|
501
|
-
dynamicImports.add(importName);
|
|
502
|
-
});
|
|
503
|
-
const files = chunkCSSMap.get(chunk.fileName);
|
|
504
|
-
if (files && files.length > 0) for (const filename of files) extractedCss += cssAssets.get(filename) ?? "";
|
|
505
|
-
}
|
|
506
|
-
for (const chunk of chunks) if (chunk.type === "chunk" && chunk.isEntry) collect(chunk);
|
|
507
|
-
for (const chunkName of dynamicImports) collect(bundle[chunkName]);
|
|
508
|
-
if (extractedCss) {
|
|
509
|
-
for (const fileName of cssAssets.keys()) delete bundle[fileName];
|
|
510
|
-
this.emitFile({
|
|
511
|
-
type: "asset",
|
|
512
|
-
source: extractedCss,
|
|
513
|
-
fileName,
|
|
514
|
-
originalFileName: defaultCssBundleName
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
const RE_CSS_HASH = /-[\w-]+\.css$/;
|
|
521
|
-
const RE_CHUNK_HASH = /-[\w-]+\.(m?js|cjs)$/;
|
|
522
|
-
const RE_CHUNK_EXT = /\.(m?js|cjs)$/;
|
|
523
|
-
/**
|
|
524
|
-
* Normalize CSS file name by removing hash pattern and extension.
|
|
525
|
-
* e.g., "async-DcjEOEdU.css" -> "async"
|
|
526
|
-
*/
|
|
527
|
-
function normalizeCssFileName(cssFileName) {
|
|
528
|
-
return cssFileName.replace(RE_CSS_HASH, "").replace(RE_CSS, "");
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Normalize chunk file name by removing hash pattern and extension.
|
|
532
|
-
* e.g., "async-CvIfFAic.mjs" -> "async"
|
|
533
|
-
*/
|
|
534
|
-
function normalizeChunkFileName(chunkFileName) {
|
|
535
|
-
return chunkFileName.replace(RE_CHUNK_HASH, "").replace(RE_CHUNK_EXT, "");
|
|
417
|
+
if (!merged.size) return void 0;
|
|
418
|
+
const result = {};
|
|
419
|
+
for (const [pkgName, versions] of merged) result[pkgName] = versions.size === 1 ? [...versions][0] : [...versions].toSorted();
|
|
420
|
+
return result;
|
|
536
421
|
}
|
|
537
422
|
|
|
538
423
|
//#endregion
|
|
@@ -602,7 +487,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
602
487
|
const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, deps: { neverBundle }, devtools, dts, entry, env, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch } = config;
|
|
603
488
|
const plugins = [];
|
|
604
489
|
if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
|
|
605
|
-
if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepPlugin(config));
|
|
490
|
+
if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepPlugin(config, bundle));
|
|
606
491
|
if (dts) {
|
|
607
492
|
const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
|
|
608
493
|
const options = {
|
|
@@ -624,10 +509,14 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
624
509
|
...unused
|
|
625
510
|
}));
|
|
626
511
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
512
|
+
let cssPlugin;
|
|
513
|
+
try {
|
|
514
|
+
const { CssPlugin: AdvancedCssPlugin } = await import("@tsdown/css");
|
|
515
|
+
cssPlugin = AdvancedCssPlugin(config);
|
|
516
|
+
} catch {
|
|
517
|
+
cssPlugin = CssPlugin(config);
|
|
518
|
+
}
|
|
519
|
+
plugins.push(cssPlugin, ShebangPlugin(logger, cwd, nameLabel, isDualFormat));
|
|
631
520
|
if (globImport) plugins.push(importGlobPlugin({ root: cwd }));
|
|
632
521
|
}
|
|
633
522
|
if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(config, cjsDts, isDualFormat));
|
|
@@ -661,7 +550,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
661
550
|
logLevel: logger.level === "error" ? "silent" : logger.level,
|
|
662
551
|
onLog(level, log, defaultHandler) {
|
|
663
552
|
if (cjsDefault && log.code === "MIXED_EXPORT") return;
|
|
664
|
-
if (logger.options?.failOnWarn && level === "warn") defaultHandler("error", log);
|
|
553
|
+
if (logger.options?.failOnWarn && level === "warn" && log.code !== "PLUGIN_TIMINGS") defaultHandler("error", log);
|
|
665
554
|
defaultHandler(level, log);
|
|
666
555
|
},
|
|
667
556
|
devtools: devtools || void 0,
|
|
@@ -841,6 +730,7 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
841
730
|
const bundle = {
|
|
842
731
|
chunks,
|
|
843
732
|
config,
|
|
733
|
+
inlinedDeps: /* @__PURE__ */ new Map(),
|
|
844
734
|
async [asyncDispose]() {
|
|
845
735
|
debouncedPostBuild.cancel();
|
|
846
736
|
ab?.abort();
|
|
@@ -863,7 +753,7 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
863
753
|
function handleWatcher(watcher) {
|
|
864
754
|
const changedFile = [];
|
|
865
755
|
let hasError = false;
|
|
866
|
-
watcher.on("change", (id, event) => {
|
|
756
|
+
watcher.on("change", async (id, event) => {
|
|
867
757
|
if (event.event === "update") {
|
|
868
758
|
changedFile.push(id);
|
|
869
759
|
debouncedPostBuild.cancel();
|
|
@@ -873,6 +763,13 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
873
763
|
globalLogger.info(`Reload config: ${id}, restarting...`);
|
|
874
764
|
restart();
|
|
875
765
|
}
|
|
766
|
+
if ((event.event === "create" || event.event === "delete") && config.rawEntry && isGlobEntry(config.rawEntry)) {
|
|
767
|
+
const newEntry = await toObjectEntry(config.rawEntry, config.cwd);
|
|
768
|
+
if (Object.keys(config.entry).toSorted().join("\0") !== Object.keys(newEntry).toSorted().join("\0")) {
|
|
769
|
+
globalLogger.info("Entry files changed, restarting...");
|
|
770
|
+
restart();
|
|
771
|
+
}
|
|
772
|
+
}
|
|
876
773
|
});
|
|
877
774
|
watcher.on("event", async (event) => {
|
|
878
775
|
switch (event.code) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-DmX8JP3Y.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/config/options.d.ts
|
|
4
4
|
/**
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-DmX8JP3Y.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-CB5uSdbf.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { s as resolveComma, u as toArray } from "./general-1LELSDyN.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/features/css/index.ts
|
|
4
|
+
const defaultCssBundleName = "style.css";
|
|
5
|
+
function resolveCssOptions(options = {}, topLevelTarget) {
|
|
6
|
+
let cssTarget;
|
|
7
|
+
if (options.target === false) cssTarget = void 0;
|
|
8
|
+
else if (options.target == null) cssTarget = topLevelTarget;
|
|
9
|
+
else cssTarget = resolveComma(toArray(options.target));
|
|
10
|
+
return {
|
|
11
|
+
transformer: options.transformer ?? "postcss",
|
|
12
|
+
splitting: options.splitting ?? false,
|
|
13
|
+
fileName: options.fileName ?? defaultCssBundleName,
|
|
14
|
+
minify: options.minify ?? false,
|
|
15
|
+
target: cssTarget,
|
|
16
|
+
preprocessorOptions: options.preprocessorOptions,
|
|
17
|
+
lightningcss: options.lightningcss,
|
|
18
|
+
postcss: options.postcss
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { resolveCssOptions as n, defaultCssBundleName as t };
|
package/dist/css.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { $ as defaultCssBundleName, G as LightningCSSOptions, J as PreprocessorAdditionalDataResult, K as PostCSSOptions, Q as StylusPreprocessorOptions, U as CssOptions, W as LessPreprocessorOptions, X as ResolvedCssOptions, Y as PreprocessorOptions, Z as SassPreprocessorOptions, et as resolveCssOptions, q as PreprocessorAdditionalData, s as Sourcemap } from "./types-DmX8JP3Y.mjs";
|
|
2
|
+
import { OutputAsset, OutputChunk, Plugin } from "rolldown";
|
|
3
|
+
|
|
4
|
+
//#region src/features/css/plugin.d.ts
|
|
5
|
+
declare const RE_CSS: RegExp;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/features/css/post.d.ts
|
|
8
|
+
type CssStyles = Map<string, string>;
|
|
9
|
+
declare function createCssPostHooks(config: {
|
|
10
|
+
css: {
|
|
11
|
+
splitting: boolean;
|
|
12
|
+
fileName: string;
|
|
13
|
+
};
|
|
14
|
+
}, styles: CssStyles): Pick<Required<Plugin>, "renderChunk" | "generateBundle">;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/features/css/pure-chunk.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Detect and remove "pure CSS chunks" — JS chunks that exist only because
|
|
19
|
+
* they imported CSS files. These chunks have no JS exports and all their
|
|
20
|
+
* modules are CSS. Following Vite's implementation.
|
|
21
|
+
*/
|
|
22
|
+
declare function removePureCssChunks(bundle: Record<string, OutputChunk | OutputAsset>, styles: CssStyles): void;
|
|
23
|
+
/**
|
|
24
|
+
* Create a replacer function that replaces import statements for pure CSS
|
|
25
|
+
* chunks with block comments of the same length, preserving source map offsets.
|
|
26
|
+
*/
|
|
27
|
+
declare function getEmptyChunkReplacer(pureCssChunkNames: string[]): (code: string) => string;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { type CssOptions, type CssStyles, type LessPreprocessorOptions, type LightningCSSOptions, type PostCSSOptions, type PreprocessorAdditionalData, type PreprocessorAdditionalDataResult, type PreprocessorOptions, RE_CSS, type ResolvedCssOptions, type SassPreprocessorOptions, type Sourcemap, type StylusPreprocessorOptions, createCssPostHooks, defaultCssBundleName, getEmptyChunkReplacer, removePureCssChunks, resolveCssOptions };
|
package/dist/css.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as resolveCssOptions, t as defaultCssBundleName } from "./css-BGrvAa8p.mjs";
|
|
2
|
+
import { a as removePureCssChunks, i as getEmptyChunkReplacer, n as RE_CSS, r as createCssPostHooks } from "./plugin-Bzpx14BV.mjs";
|
|
3
|
+
|
|
4
|
+
export { RE_CSS, createCssPostHooks, defaultCssBundleName, getEmptyChunkReplacer, removePureCssChunks, resolveCssOptions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as resolveRegex, l as slash, r as matchPattern, u as toArray } from "./general-1LELSDyN.mjs";
|
|
2
2
|
import { isBuiltin } from "node:module";
|
|
3
|
-
import { access, cp, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { access, cp, readFile, rm, stat } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { blue, underline, yellow } from "ansis";
|
|
6
6
|
import { createDebug } from "obug";
|
|
@@ -100,7 +100,25 @@ function resolveDepsConfig(config, logger) {
|
|
|
100
100
|
skipNodeModulesBundle
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
async function parseBundledDep(moduleId) {
|
|
104
|
+
const slashed = slash(moduleId);
|
|
105
|
+
const lastNmIdx = slashed.lastIndexOf("/node_modules/");
|
|
106
|
+
if (lastNmIdx === -1) return;
|
|
107
|
+
const parts = slashed.slice(lastNmIdx + 14).split("/");
|
|
108
|
+
let name;
|
|
109
|
+
if (parts[0][0] === "@") name = `${parts[0]}/${parts[1]}`;
|
|
110
|
+
else name = parts[0];
|
|
111
|
+
const root = slashed.slice(0, lastNmIdx + 14 + name.length);
|
|
112
|
+
try {
|
|
113
|
+
const json = JSON.parse(await readFile(path.join(root, "package.json"), "utf8"));
|
|
114
|
+
return {
|
|
115
|
+
name,
|
|
116
|
+
pkgName: json.name,
|
|
117
|
+
version: json.version
|
|
118
|
+
};
|
|
119
|
+
} catch {}
|
|
120
|
+
}
|
|
121
|
+
function DepPlugin({ pkg, deps: { alwaysBundle, onlyAllowBundle, skipNodeModulesBundle }, logger, nameLabel }, tsdownBundle) {
|
|
104
122
|
const deps = pkg && Array.from(getProductionDeps(pkg));
|
|
105
123
|
return {
|
|
106
124
|
name: "tsdown:external",
|
|
@@ -118,32 +136,30 @@ function DepPlugin({ pkg, deps: { alwaysBundle, onlyAllowBundle: inlineOnly, ski
|
|
|
118
136
|
};
|
|
119
137
|
}
|
|
120
138
|
},
|
|
121
|
-
generateBundle:
|
|
139
|
+
generateBundle: {
|
|
122
140
|
order: "post",
|
|
123
|
-
handler(options, bundle) {
|
|
141
|
+
async handler(options, bundle) {
|
|
124
142
|
const deps = /* @__PURE__ */ new Set();
|
|
125
143
|
const importers = /* @__PURE__ */ new Map();
|
|
126
144
|
for (const chunk of Object.values(bundle)) {
|
|
127
145
|
if (chunk.type === "asset") continue;
|
|
128
146
|
for (const id of chunk.moduleIds) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
else dep = parts[0];
|
|
135
|
-
deps.add(dep);
|
|
147
|
+
const parsed = await parseBundledDep(id);
|
|
148
|
+
if (!parsed) continue;
|
|
149
|
+
deps.add(parsed.name);
|
|
150
|
+
if (!tsdownBundle.inlinedDeps.has(parsed.pkgName)) tsdownBundle.inlinedDeps.set(parsed.pkgName, /* @__PURE__ */ new Set());
|
|
151
|
+
tsdownBundle.inlinedDeps.get(parsed.pkgName).add(parsed.version);
|
|
136
152
|
const module = this.getModuleInfo(id);
|
|
137
|
-
if (module) importers.set(
|
|
153
|
+
if (module) importers.set(parsed.name, new Set([...module.importers, ...importers.get(parsed.name) || []]));
|
|
138
154
|
}
|
|
139
155
|
}
|
|
140
156
|
debug("found deps in bundle: %o", deps);
|
|
141
|
-
if (
|
|
142
|
-
const errors = Array.from(deps).filter((dep) => !matchPattern(dep,
|
|
157
|
+
if (onlyAllowBundle) {
|
|
158
|
+
const errors = Array.from(deps).filter((dep) => !matchPattern(dep, onlyAllowBundle)).map((dep) => `${yellow(dep)} is located in ${blue`node_modules`} but is not included in ${blue`deps.onlyAllowBundle`} option.\nTo fix this, either add it to ${blue`deps.onlyAllowBundle`}, declare it as a production or peer dependency in your package.json, or externalize it manually.\nImported by\n${[...importers.get(dep) || []].map((s) => `- ${underline(s)}`).join("\n")}`);
|
|
143
159
|
if (errors.length) this.error(errors.join("\n\n"));
|
|
144
|
-
const unusedPatterns =
|
|
160
|
+
const unusedPatterns = onlyAllowBundle.filter((pattern) => !Array.from(deps).some((dep) => matchPattern(dep, [pattern])));
|
|
145
161
|
if (unusedPatterns.length) logger.info(nameLabel, `The following entries in ${blue`deps.onlyAllowBundle`} are not used in the bundle:\n${unusedPatterns.map((pattern) => `- ${yellow(pattern)}`).join("\n")}\nConsider removing them to keep your configuration clean.`);
|
|
146
|
-
} else if (deps.size) logger.info(nameLabel, `Hint: consider adding ${blue`deps.onlyAllowBundle`} option to avoid unintended bundling of dependencies, or set ${blue`deps.onlyAllowBundle: false`} to disable this hint.\nSee more at ${underline`https://tsdown.dev/options/dependencies#deps-onlyallowbundle`}\nDetected dependencies in bundle:\n${Array.from(deps).map((dep) => `- ${blue(dep)}`).join("\n")}`);
|
|
162
|
+
} else if (onlyAllowBundle == null && deps.size) logger.info(nameLabel, `Hint: consider adding ${blue`deps.onlyAllowBundle`} option to avoid unintended bundling of dependencies, or set ${blue`deps.onlyAllowBundle: false`} to disable this hint.\nSee more at ${underline`https://tsdown.dev/options/dependencies#deps-onlyallowbundle`}\nDetected dependencies in bundle:\n${Array.from(deps).map((dep) => `- ${blue(dep)}`).join("\n")}`);
|
|
147
163
|
}
|
|
148
164
|
}
|
|
149
165
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
const picomatch = __cjs_require("picomatch");
|
|
6
|
+
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/utils/general.ts
|
|
12
|
+
function toArray(val, defaultValue) {
|
|
13
|
+
if (Array.isArray(val)) return val;
|
|
14
|
+
else if (val == null) {
|
|
15
|
+
if (defaultValue) return [defaultValue];
|
|
16
|
+
return [];
|
|
17
|
+
} else return [val];
|
|
18
|
+
}
|
|
19
|
+
function resolveComma(arr) {
|
|
20
|
+
return arr.flatMap((format) => format.split(","));
|
|
21
|
+
}
|
|
22
|
+
function resolveRegex(str) {
|
|
23
|
+
if (typeof str === "string" && str.length > 2 && str[0] === "/" && str.at(-1) === "/") return new RegExp(str.slice(1, -1));
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
26
|
+
function slash(string) {
|
|
27
|
+
return string.replaceAll("\\", "/");
|
|
28
|
+
}
|
|
29
|
+
const noop = (v) => v;
|
|
30
|
+
function matchPattern(id, patterns) {
|
|
31
|
+
return patterns.some((pattern) => {
|
|
32
|
+
if (pattern instanceof RegExp) {
|
|
33
|
+
pattern.lastIndex = 0;
|
|
34
|
+
return pattern.test(id);
|
|
35
|
+
}
|
|
36
|
+
return id === pattern || picomatch(pattern)(id);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function pkgExists(moduleName) {
|
|
40
|
+
try {
|
|
41
|
+
import.meta.resolve(moduleName);
|
|
42
|
+
return true;
|
|
43
|
+
} catch {}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
async function importWithError(moduleName, resolvePaths) {
|
|
47
|
+
let resolved;
|
|
48
|
+
if (resolvePaths) resolved = pathToFileURL(__require.resolve(moduleName, { paths: resolvePaths })).href;
|
|
49
|
+
try {
|
|
50
|
+
return await import(resolved || moduleName);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error(`Failed to import module "${moduleName}". Please ensure it is installed.`, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function promiseWithResolvers() {
|
|
56
|
+
let resolve;
|
|
57
|
+
return {
|
|
58
|
+
promise: new Promise((res) => {
|
|
59
|
+
resolve = res;
|
|
60
|
+
}),
|
|
61
|
+
resolve
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function debounce(fn, delay) {
|
|
65
|
+
let timer;
|
|
66
|
+
const debounced = (...args) => {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
69
|
+
};
|
|
70
|
+
debounced.cancel = () => clearTimeout(timer);
|
|
71
|
+
return debounced;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { pkgExists as a, resolveRegex as c, noop as i, slash as l, importWithError as n, promiseWithResolvers as o, matchPattern as r, resolveComma as s, debounce as t, toArray as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { A as RolldownContext, B as globalLogger, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, G as LightningCSSOptions, H as TsdownBundle, I as DepsConfig, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, Q as StylusPreprocessorOptions, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CssOptions, V as RolldownChunk, W as LessPreprocessorOptions, X as ResolvedCssOptions, Y as PreprocessorOptions, Z as SassPreprocessorOptions, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, it as Arrayable, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, nt as CopyOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, rt as CopyOptionsFn, s as Sourcemap, t as CIOption, tt as CopyEntry, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as Logger } from "./types-DmX8JP3Y.mjs";
|
|
2
|
+
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-CB5uSdbf.mjs";
|
|
3
3
|
import * as Rolldown from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/build.d.ts
|
|
@@ -18,4 +18,4 @@ declare function buildWithConfigs(configs: ResolvedConfig[], configFiles: string
|
|
|
18
18
|
//#region src/features/debug.d.ts
|
|
19
19
|
declare function enableDebug(debug?: boolean | Arrayable<string>): void;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DepsConfig, DevtoolsOptions, DtsOptions, ExeOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, ResolvedDepsConfig, Rolldown, RolldownChunk, RolldownContext, SeaConfig, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
|
21
|
+
export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DepsConfig, DevtoolsOptions, DtsOptions, ExeOptions, ExportsOptions, Format, InlineConfig, LessPreprocessorOptions, LightningCSSOptions, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PreprocessorOptions, PublintOptions, ReportOptions, ResolvedConfig, ResolvedCssOptions, ResolvedDepsConfig, Rolldown, RolldownChunk, RolldownContext, SassPreprocessorOptions, SeaConfig, Sourcemap, StylusPreprocessorOptions, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { r as resolveUserConfig, t as mergeConfig } from "./options-DLWsyWjz.mjs";
|
|
2
|
+
import { a as globalLogger } from "./logger-C4Xhh0rW.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { n as buildWithConfigs, t as build } from "./build-
|
|
5
|
-
import { t as enableDebug } from "./debug-
|
|
4
|
+
import { n as buildWithConfigs, t as build } from "./build-Dd9GjMta.mjs";
|
|
5
|
+
import { t as enableDebug } from "./debug-DtUr55Vs.mjs";
|
|
6
6
|
import * as Rolldown from "rolldown";
|
|
7
7
|
|
|
8
8
|
export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
|
@@ -1,80 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import { createRequire } from "node:module";
|
|
1
|
+
import { i as noop } from "./general-1LELSDyN.mjs";
|
|
4
2
|
import process from "node:process";
|
|
5
3
|
import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
const picomatch = __cjs_require("picomatch");
|
|
8
4
|
import readline from "node:readline";
|
|
9
5
|
|
|
10
|
-
//#region \0rolldown/runtime.js
|
|
11
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/utils/general.ts
|
|
15
|
-
function toArray(val, defaultValue) {
|
|
16
|
-
if (Array.isArray(val)) return val;
|
|
17
|
-
else if (val == null) {
|
|
18
|
-
if (defaultValue) return [defaultValue];
|
|
19
|
-
return [];
|
|
20
|
-
} else return [val];
|
|
21
|
-
}
|
|
22
|
-
function resolveComma(arr) {
|
|
23
|
-
return arr.flatMap((format) => format.split(","));
|
|
24
|
-
}
|
|
25
|
-
function resolveRegex(str) {
|
|
26
|
-
if (typeof str === "string" && str.length > 2 && str[0] === "/" && str.at(-1) === "/") return new RegExp(str.slice(1, -1));
|
|
27
|
-
return str;
|
|
28
|
-
}
|
|
29
|
-
function slash(string) {
|
|
30
|
-
return string.replaceAll("\\", "/");
|
|
31
|
-
}
|
|
32
|
-
const noop = (v) => v;
|
|
33
|
-
function matchPattern(id, patterns) {
|
|
34
|
-
return patterns.some((pattern) => {
|
|
35
|
-
if (pattern instanceof RegExp) {
|
|
36
|
-
pattern.lastIndex = 0;
|
|
37
|
-
return pattern.test(id);
|
|
38
|
-
}
|
|
39
|
-
return id === pattern || picomatch(pattern)(id);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function pkgExists(moduleName) {
|
|
43
|
-
try {
|
|
44
|
-
import.meta.resolve(moduleName);
|
|
45
|
-
return true;
|
|
46
|
-
} catch {}
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
async function importWithError(moduleName, resolvePaths) {
|
|
50
|
-
let resolved;
|
|
51
|
-
if (resolvePaths) resolved = pathToFileURL(__require.resolve(moduleName, { paths: resolvePaths })).href;
|
|
52
|
-
try {
|
|
53
|
-
return await import(resolved || moduleName);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
throw new Error(`Failed to import module "${moduleName}". Please ensure it is installed.`, { cause: error });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function promiseWithResolvers() {
|
|
59
|
-
let resolve;
|
|
60
|
-
return {
|
|
61
|
-
promise: new Promise((res) => {
|
|
62
|
-
resolve = res;
|
|
63
|
-
}),
|
|
64
|
-
resolve
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function debounce(fn, delay) {
|
|
68
|
-
let timer;
|
|
69
|
-
const debounced = (...args) => {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
timer = setTimeout(() => fn(...args), delay);
|
|
72
|
-
};
|
|
73
|
-
debounced.cancel = () => clearTimeout(timer);
|
|
74
|
-
return debounced;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
6
|
//#region src/utils/logger.ts
|
|
79
7
|
const LogLevels = {
|
|
80
8
|
silent: 0,
|
|
@@ -200,4 +128,4 @@ function hue2rgb(p, q, t) {
|
|
|
200
128
|
}
|
|
201
129
|
|
|
202
130
|
//#endregion
|
|
203
|
-
export { globalLogger as a,
|
|
131
|
+
export { globalLogger as a, getNameLabel as i, createLogger as n, prettyFormat as o, generateColor as r, LogLevels as t };
|