tsdown 0.21.0-beta.3 → 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.
@@ -0,0 +1,3 @@
1
+ import { n as buildWithConfigs, t as build } from "./build-Dd9GjMta.mjs";
2
+
3
+ export { build };
@@ -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 { a as globalLogger, c as importWithError, f as promiseWithResolvers, g as toArray, h as slash, s as debounce, t as LogLevels } from "./logger-JoV-m1IK.mjs";
4
- import { a as getPackageType, c as isGlobEntry, d as cleanChunks, f as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as defaultCssBundleName } from "./options-DX4QGCgI.mjs";
5
- import { a as getShimsInject, c as fsRemove, o as fsCopy, r as DepPlugin, u as lowestCommonAncestor } from "./format-GnNEnvb5.mjs";
6
- import { t as version } from "./package-BT9tRMs2.mjs";
7
- import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, t as WatchPlugin } from "./watch-Csmj95d-.mjs";
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";
@@ -12,7 +14,6 @@ import { bold, dim, green } from "ansis";
12
14
  import { createDebug } from "obug";
13
15
  const satisfies = __cjs_require("semver/functions/satisfies.js");
14
16
  import { glob, isDynamicPattern } from "tinyglobby";
15
- import { fileURLToPath, pathToFileURL } from "node:url";
16
17
  import readline from "node:readline";
17
18
  import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
18
19
  import { tmpdir } from "node:os";
@@ -381,7 +382,7 @@ async function bundleDone(bundleByPkg, bundle) {
381
382
  async function packTarball(packageJsonPath) {
382
383
  const pkgDir = path.dirname(packageJsonPath);
383
384
  const destination = await mkdtemp(path.join(tmpdir(), "tsdown-pack-"));
384
- const [{ detect }, { pack }] = await Promise.all([import("./detect-BX3saxQr.mjs"), import("./index-node-NuCvERba.mjs")]);
385
+ const [{ detect }, { pack }] = await Promise.all([import("./detect-CeWQMhKA.mjs"), import("./index-node-CDF8A25m.mjs")]);
385
386
  try {
386
387
  const detected = await detect({ cwd: pkgDir });
387
388
  if (detected?.name === "deno") throw new Error(`Cannot pack tarball for Deno projects at ${pkgDir}`);
@@ -419,378 +420,6 @@ function mergeInlinedDeps(bundles) {
419
420
  return result;
420
421
  }
421
422
 
422
- //#endregion
423
- //#region src/utils/lightningcss.ts
424
- /**
425
- * Converts esbuild target [^1] (which is also used by Rolldown [^2]) to Lightning CSS targets [^3].
426
- *
427
- * [^1]: https://esbuild.github.io/api/#target
428
- * [^2]: https://github.com/rolldown/rolldown/blob/v1.0.0-beta.8/packages/rolldown/src/binding.d.ts#L1429-L1431
429
- * [^3]: https://lightningcss.dev/transpilation.html
430
- */
431
- function esbuildTargetToLightningCSS(target) {
432
- let targets;
433
- const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
434
- for (const match of matches) {
435
- const browser = ESBUILD_LIGHTNINGCSS_MAPPING[match[1]];
436
- if (!browser) continue;
437
- const version = match[2];
438
- const versionInt = parseVersion(version);
439
- if (versionInt == null) continue;
440
- targets = targets || {};
441
- targets[browser] = versionInt;
442
- }
443
- return targets;
444
- }
445
- const TARGET_REGEX = /([a-z]+)(\d+(?:\.\d+)*)/g;
446
- const ESBUILD_LIGHTNINGCSS_MAPPING = {
447
- chrome: "chrome",
448
- edge: "edge",
449
- firefox: "firefox",
450
- ie: "ie",
451
- ios: "ios_saf",
452
- opera: "opera",
453
- safari: "safari"
454
- };
455
- function parseVersion(version) {
456
- const [major, minor = 0, patch = 0] = version.split("-")[0].split(".").map((v) => Number.parseInt(v, 10));
457
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) return null;
458
- return major << 16 | minor << 8 | patch;
459
- }
460
-
461
- //#endregion
462
- //#region src/features/css/lightningcss.ts
463
- async function transformWithLightningCSS(code, filename, target, lightningcssOptions) {
464
- const lightningcss = await importWithError("lightningcss");
465
- const targets = lightningcssOptions?.targets ?? (target ? esbuildTargetToLightningCSS(target) : void 0);
466
- if (!targets && !lightningcssOptions) return code;
467
- const result = lightningcss.transform({
468
- filename,
469
- code: new TextEncoder().encode(code),
470
- ...lightningcssOptions,
471
- targets
472
- });
473
- return new TextDecoder().decode(result.code);
474
- }
475
-
476
- //#endregion
477
- //#region src/features/css/preprocessors.ts
478
- const PREPROCESSOR_LANGS = {
479
- scss: "scss",
480
- sass: "sass",
481
- less: "less",
482
- styl: "styl",
483
- stylus: "stylus"
484
- };
485
- function getPreprocessorLang(filename) {
486
- return PREPROCESSOR_LANGS[path.extname(filename).slice(1)];
487
- }
488
- const CSS_LANGS_RE = /\.(?:css|less|sass|scss|styl|stylus)(?:$|\?)/;
489
- function isCssOrPreprocessor(filename) {
490
- return CSS_LANGS_RE.test(filename);
491
- }
492
- function compilePreprocessor(lang, code, filename, options) {
493
- switch (lang) {
494
- case "scss":
495
- case "sass": return compileSass(lang, code, filename, options);
496
- case "less": return compileLess(code, filename, options);
497
- case "styl":
498
- case "stylus": return compileStylus(code, filename, options);
499
- }
500
- }
501
- const cssUrlRE = /(?<!@import\s+)(?<=^|[^\w\-\u0080-\uFFFF])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/;
502
- const cssDataUriRE = /(?<=^|[^\w\-\u0080-\uFFFF])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/;
503
- const importCssRE = /@import\s+(?:url\()?('[^']+\.css'|"[^"]+\.css"|[^'"\s)]+\.css)/;
504
- /**
505
- * Rebase relative url() references in imported preprocessor files.
506
- * When a file is imported from a different directory, url() references
507
- * need to be adjusted relative to the root file.
508
- */
509
- async function rebaseUrls(file, rootFile, ignoreUrl) {
510
- file = path.resolve(file);
511
- const fileDir = path.dirname(file);
512
- const rootDir = path.dirname(rootFile);
513
- if (fileDir === rootDir) return { file };
514
- const content = await readFile(file, "utf8");
515
- const hasUrls = cssUrlRE.test(content);
516
- const hasDataUris = cssDataUriRE.test(content);
517
- const hasImportCss = importCssRE.test(content);
518
- if (!hasUrls && !hasDataUris && !hasImportCss) return { file };
519
- let rebased;
520
- const rebaseFn = (unquotedUrl, rawUrl) => {
521
- if (ignoreUrl?.(unquotedUrl, rawUrl)) return false;
522
- if (unquotedUrl[0] === "/") return unquotedUrl;
523
- const absolute = path.resolve(fileDir, unquotedUrl);
524
- return normalizePath(path.relative(rootDir, absolute));
525
- };
526
- if (hasImportCss) rebased = await rewriteImportCss(content, rebaseFn);
527
- if (hasUrls) rebased = await rewriteCssUrls(rebased || content, rebaseFn);
528
- if (hasDataUris) rebased = await rewriteCssDataUris(rebased || content, rebaseFn);
529
- return {
530
- file,
531
- contents: rebased
532
- };
533
- }
534
- async function asyncReplace(input, re, replacer) {
535
- let match;
536
- let remaining = input;
537
- let rewritten = "";
538
- while (match = re.exec(remaining)) {
539
- rewritten += remaining.slice(0, match.index);
540
- rewritten += await replacer(match);
541
- remaining = remaining.slice(match.index + match[0].length);
542
- }
543
- rewritten += remaining;
544
- return rewritten;
545
- }
546
- function rewriteCssUrls(css, replacer) {
547
- return asyncReplace(css, cssUrlRE, async (match) => {
548
- const [matched, rawUrl] = match;
549
- return await doUrlReplace(rawUrl.trim(), matched, replacer);
550
- });
551
- }
552
- function rewriteCssDataUris(css, replacer) {
553
- return asyncReplace(css, cssDataUriRE, async (match) => {
554
- const [matched, rawUrl] = match;
555
- return await doUrlReplace(rawUrl.trim(), matched, replacer, "data-uri");
556
- });
557
- }
558
- function rewriteImportCss(css, replacer) {
559
- return asyncReplace(css, importCssRE, async (match) => {
560
- const [matched, rawUrl] = match;
561
- return await doImportCSSReplace(rawUrl, matched, replacer);
562
- });
563
- }
564
- async function doUrlReplace(rawUrl, matched, replacer, funcName = "url") {
565
- let wrap = "";
566
- const first = rawUrl[0];
567
- if (first === `"` || first === `'`) {
568
- wrap = first;
569
- rawUrl = rawUrl.slice(1, -1);
570
- }
571
- const newUrl = await replacer(rawUrl, matched);
572
- if (typeof newUrl === "string") {
573
- if (wrap === "" && newUrl !== encodeURI(newUrl)) wrap = "\"";
574
- return `${funcName}(${wrap}${newUrl}${wrap})`;
575
- }
576
- return matched;
577
- }
578
- async function doImportCSSReplace(rawUrl, matched, replacer) {
579
- let wrap = "";
580
- const first = rawUrl[0];
581
- if (first === `"` || first === `'`) {
582
- wrap = first;
583
- rawUrl = rawUrl.slice(1, -1);
584
- }
585
- const newUrl = await replacer(rawUrl, matched);
586
- if (typeof newUrl === "string") return matched.replace(`${wrap}${rawUrl}${wrap}`, `${wrap}${newUrl}${wrap}`);
587
- return matched;
588
- }
589
- function normalizePath(id) {
590
- return id.replaceAll("\\", "/");
591
- }
592
- async function getSource(source, filename, additionalData, sep = "") {
593
- if (!additionalData) return source;
594
- if (typeof additionalData === "function") {
595
- const newContent = await additionalData(source, filename);
596
- if (typeof newContent === "string") return newContent;
597
- return newContent.content;
598
- }
599
- return additionalData + sep + source;
600
- }
601
- async function compileSass(lang, code, filename, options) {
602
- const sass = await loadSass();
603
- const preprocessorOpts = options?.scss ?? options?.sass ?? {};
604
- const data = await getSource(code, filename, preprocessorOpts.additionalData);
605
- const { additionalData: _, ...sassOptions } = preprocessorOpts;
606
- const skipRebaseUrls = (unquotedUrl, rawUrl) => {
607
- if (!(rawUrl[0] === "\"" || rawUrl[0] === "'") && unquotedUrl[0] === "$") return true;
608
- return unquotedUrl.startsWith("#{");
609
- };
610
- const result = await sass.compileStringAsync(data, {
611
- url: pathToFileURL(filename),
612
- sourceMap: false,
613
- syntax: lang === "sass" ? "indented" : "scss",
614
- importers: [{
615
- async canonicalize(url, context) {
616
- const importer = context.containingUrl ? fileURLToPath(context.containingUrl) : filename;
617
- const resolved = await tryResolveScss(url, path.dirname(importer));
618
- if (resolved) return pathToFileURL(resolved);
619
- return null;
620
- },
621
- async load(canonicalUrl) {
622
- const ext = path.extname(canonicalUrl.pathname);
623
- let syntax = "scss";
624
- if (ext === ".sass") syntax = "indented";
625
- else if (ext === ".css") syntax = "css";
626
- const result = await rebaseUrls(fileURLToPath(canonicalUrl), filename, skipRebaseUrls);
627
- return {
628
- contents: result.contents ?? await readFile(result.file, "utf8"),
629
- syntax,
630
- sourceMapUrl: canonicalUrl
631
- };
632
- }
633
- }, ...sassOptions.importers ?? []],
634
- ...sassOptions
635
- });
636
- return {
637
- code: result.css,
638
- deps: result.loadedUrls.filter((url) => url.protocol === "file:").map((url) => fileURLToPath(url))
639
- };
640
- }
641
- async function tryResolveScss(url, dir) {
642
- const { existsSync } = await import("node:fs");
643
- const extensions = [
644
- ".scss",
645
- ".sass",
646
- ".css"
647
- ];
648
- const prefixes = ["", "_"];
649
- if (extensions.some((ext) => url.endsWith(ext))) {
650
- for (const prefix of prefixes) {
651
- const file = path.resolve(dir, path.dirname(url), prefix + path.basename(url));
652
- if (existsSync(file)) return file;
653
- }
654
- return;
655
- }
656
- for (const ext of extensions) for (const prefix of prefixes) {
657
- const file = path.resolve(dir, path.dirname(url), prefix + path.basename(url) + ext);
658
- if (existsSync(file)) return file;
659
- }
660
- for (const ext of extensions) for (const prefix of prefixes) {
661
- const file = path.resolve(dir, url, `${prefix}index${ext}`);
662
- if (existsSync(file)) return file;
663
- }
664
- }
665
- let _sass;
666
- async function loadSass() {
667
- if (_sass) return _sass;
668
- try {
669
- _sass = await import("sass-embedded");
670
- return _sass;
671
- } catch {
672
- try {
673
- _sass = await import("sass");
674
- return _sass;
675
- } catch {
676
- throw new Error("Preprocessor dependency \"sass\" not found. Did you install it? Try `npm install -D sass`.");
677
- }
678
- }
679
- }
680
- async function compileLess(code, filename, options) {
681
- const less = await loadLess();
682
- const preprocessorOpts = options?.less ?? {};
683
- const data = await getSource(code, filename, preprocessorOpts.additionalData);
684
- const { additionalData: _, plugins = [], ...lessOptions } = preprocessorOpts;
685
- const result = await less.render(data, {
686
- paths: ["node_modules"],
687
- ...lessOptions,
688
- filename,
689
- plugins
690
- });
691
- return {
692
- code: result.css,
693
- deps: result.imports || []
694
- };
695
- }
696
- let _less;
697
- async function loadLess() {
698
- if (_less) return _less;
699
- try {
700
- _less = (await import("less")).default;
701
- return _less;
702
- } catch {
703
- throw new Error("Preprocessor dependency \"less\" not found. Did you install it? Try `npm install -D less`.");
704
- }
705
- }
706
- async function compileStylus(code, filename, options) {
707
- const stylus = await loadStylus();
708
- const preprocessorOpts = options?.styl ?? options?.stylus ?? {};
709
- const data = await getSource(code, filename, preprocessorOpts.additionalData, "\n");
710
- const { additionalData: _, define, ...stylusOptions } = preprocessorOpts;
711
- const ref = stylus(data, {
712
- paths: ["node_modules"],
713
- ...stylusOptions,
714
- filename
715
- });
716
- if (define) for (const key of Object.keys(define)) ref.define(key, define[key]);
717
- return new Promise((resolve, reject) => {
718
- ref.render((err, css) => {
719
- if (err) reject(/* @__PURE__ */ new Error(`[stylus] ${err.message}`));
720
- else resolve({
721
- code: css,
722
- deps: ref.deps()
723
- });
724
- });
725
- });
726
- }
727
- let _stylus;
728
- async function loadStylus() {
729
- if (_stylus) return _stylus;
730
- try {
731
- _stylus = (await import("stylus")).default;
732
- return _stylus;
733
- } catch {
734
- throw new Error("Preprocessor dependency \"stylus\" not found. Did you install it? Try `npm install -D stylus`.");
735
- }
736
- }
737
-
738
- //#endregion
739
- //#region src/features/css/plugin.ts
740
- function CssPlugin(config) {
741
- const styles = /* @__PURE__ */ new Map();
742
- const collectedCSS = [];
743
- const { splitting, fileName: mergedCssFileName } = config.css;
744
- return {
745
- name: "tsdown:css",
746
- buildStart() {
747
- styles.clear();
748
- collectedCSS.length = 0;
749
- },
750
- async load(id) {
751
- if (!isCssOrPreprocessor(id)) return;
752
- let code = await readFile(id, "utf8");
753
- const lang = getPreprocessorLang(id);
754
- if (lang) {
755
- const result = await compilePreprocessor(lang, code, id, config.css.preprocessorOptions);
756
- code = result.code;
757
- for (const dep of result.deps) this.addWatchFile(dep);
758
- }
759
- if (config.target || config.css.lightningcss) code = await transformWithLightningCSS(code, id, config.target, config.css.lightningcss);
760
- if (code.length > 0 && !code.endsWith("\n")) code += "\n";
761
- styles.set(id, code);
762
- return {
763
- code: "",
764
- moduleSideEffects: "no-treeshake",
765
- moduleType: "js"
766
- };
767
- },
768
- renderChunk(_code, chunk) {
769
- let chunkCSS = "";
770
- for (const id of Object.keys(chunk.modules)) if (styles.has(id)) chunkCSS += styles.get(id);
771
- if (!chunkCSS) return;
772
- if (splitting) {
773
- const cssAssetFileName = chunk.fileName.replace(/\.(m?js|cjs)$/, ".css");
774
- this.emitFile({
775
- type: "asset",
776
- fileName: cssAssetFileName,
777
- source: chunkCSS
778
- });
779
- } else collectedCSS.push(chunkCSS);
780
- },
781
- generateBundle() {
782
- if (splitting) return;
783
- const allCSS = collectedCSS.join("");
784
- if (allCSS) this.emitFile({
785
- type: "asset",
786
- fileName: mergedCssFileName,
787
- source: allCSS,
788
- originalFileName: defaultCssBundleName
789
- });
790
- }
791
- };
792
- }
793
-
794
423
  //#endregion
795
424
  //#region src/features/output.ts
796
425
  function resolveJsOutputExtension(packageType, format, fixedExtension) {
@@ -880,7 +509,14 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
880
509
  ...unused
881
510
  }));
882
511
  }
883
- plugins.push(CssPlugin(config), ShebangPlugin(logger, cwd, nameLabel, isDualFormat));
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));
884
520
  if (globImport) plugins.push(importGlobPlugin({ root: cwd }));
885
521
  }
886
522
  if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(config, cjsDts, isDualFormat));
@@ -1,4 +1,4 @@
1
- import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-BmbHkVac.mjs";
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-BmbHkVac.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-DlKWfqrY.mjs";
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
@@ -1,4 +1,4 @@
1
- import { t as mergeConfig } from "./options-DX4QGCgI.mjs";
1
+ import { t as mergeConfig } from "./options-DLWsyWjz.mjs";
2
2
 
3
3
  //#region src/config.ts
4
4
  function defineConfig(options) {
@@ -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,4 +1,4 @@
1
- import { g as toArray, p as resolveComma } from "./logger-JoV-m1IK.mjs";
1
+ import { s as resolveComma, u as toArray } from "./general-1LELSDyN.mjs";
2
2
  import { createDebug, enable, namespaces } from "obug";
3
3
 
4
4
  //#region src/features/debug.ts
@@ -1,4 +1,4 @@
1
- import { g as toArray, h as slash, l as matchPattern, m as resolveRegex } from "./logger-JoV-m1IK.mjs";
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
3
  import { access, cp, readFile, rm, stat } from "node:fs/promises";
4
4
  import path from "node:path";
@@ -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 { $ as Arrayable, A as RolldownContext, B as globalLogger, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, G as LightningCSSOptions, H as TsdownBundle, I as DepsConfig, J as SassPreprocessorOptions, K as PreprocessorOptions, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, Q as CopyOptionsFn, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CssOptions, V as RolldownChunk, W as LessPreprocessorOptions, X as CopyEntry, Y as StylusPreprocessorOptions, Z as CopyOptions, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, q as ResolvedCssOptions, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as Logger } from "./types-BmbHkVac.mjs";
2
- import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-DlKWfqrY.mjs";
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
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { a as globalLogger } from "./logger-JoV-m1IK.mjs";
2
- import { r as resolveUserConfig, t as mergeConfig } from "./options-DX4QGCgI.mjs";
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-DABfp5oc.mjs";
5
- import { t as enableDebug } from "./debug-dRN3JIZi.mjs";
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 { createRequire as __cjs_createRequire } from "node:module";
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, importWithError as c, pkgExists as d, promiseWithResolvers as f, toArray as g, slash as h, getNameLabel as i, matchPattern as l, resolveRegex as m, createLogger as n, prettyFormat as o, resolveComma as p, generateColor as r, debounce as s, LogLevels as t, noop as u };
131
+ export { globalLogger as a, getNameLabel as i, createLogger as n, prettyFormat as o, generateColor as r, LogLevels as t };
@@ -1,7 +1,9 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { a as globalLogger, c as importWithError, d as pkgExists, g as toArray, h as slash, i as getNameLabel, l as matchPattern, m as resolveRegex, n as createLogger, p as resolveComma, r as generateColor } from "./logger-JoV-m1IK.mjs";
4
- import { c as fsRemove, d as stripExtname, i as resolveDepsConfig, l as fsStat, n as formatBytes, s as fsExists, t as detectIndentation, u as lowestCommonAncestor } from "./format-GnNEnvb5.mjs";
3
+ import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-1LELSDyN.mjs";
4
+ import { c as fsRemove, d as stripExtname, i as resolveDepsConfig, l as fsStat, n as formatBytes, s as fsExists, t as detectIndentation, u as lowestCommonAncestor } from "./format-DlhdOGIw.mjs";
5
+ import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-C4Xhh0rW.mjs";
6
+ import { n as resolveCssOptions } from "./css-BGrvAa8p.mjs";
5
7
  import { mkdtemp, readFile, writeFile } from "node:fs/promises";
6
8
  import path from "node:path";
7
9
  import process, { env } from "node:process";
@@ -66,18 +68,6 @@ async function cleanChunks(outDir, chunks) {
66
68
  }));
67
69
  }
68
70
 
69
- //#endregion
70
- //#region src/features/css/index.ts
71
- const defaultCssBundleName = "style.css";
72
- function resolveCssOptions(options = {}) {
73
- return {
74
- splitting: options.splitting ?? false,
75
- fileName: options.fileName ?? defaultCssBundleName,
76
- preprocessorOptions: options.preprocessorOptions,
77
- lightningcss: options.lightningcss
78
- };
79
- }
80
-
81
71
  //#endregion
82
72
  //#region src/features/entry.ts
83
73
  async function resolveEntry(logger, entry, cwd, color, nameLabel) {
@@ -708,7 +698,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
708
698
  cjsDefault,
709
699
  clean,
710
700
  copy: publicDir || copy,
711
- css: resolveCssOptions(css),
701
+ css: resolveCssOptions(css, target),
712
702
  cwd,
713
703
  deps: depsConfig,
714
704
  devtools,
@@ -798,4 +788,4 @@ function filterConfig(filter, configCwd, name) {
798
788
  }
799
789
 
800
790
  //#endregion
801
- export { getPackageType as a, isGlobEntry as c, cleanChunks as d, cleanOutDir as f, loadConfigFile as i, toObjectEntry as l, mergeUserOptions as n, writeExports as o, resolveUserConfig as r, buildExe as s, mergeConfig as t, defaultCssBundleName as u };
791
+ export { getPackageType as a, isGlobEntry as c, cleanOutDir as d, loadConfigFile as i, toObjectEntry as l, mergeUserOptions as n, writeExports as o, resolveUserConfig as r, buildExe as s, mergeConfig as t, cleanChunks as u };
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.21.0-beta.4";
3
+
4
+ //#endregion
5
+ export { version as t };
@@ -0,0 +1,124 @@
1
+ import { t as defaultCssBundleName } from "./css-BGrvAa8p.mjs";
2
+ import { readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+
5
+ //#region src/features/css/pure-chunk.ts
6
+ /**
7
+ * Detect and remove "pure CSS chunks" — JS chunks that exist only because
8
+ * they imported CSS files. These chunks have no JS exports and all their
9
+ * modules are CSS. Following Vite's implementation.
10
+ */
11
+ function removePureCssChunks(bundle, styles) {
12
+ const pureCssChunkNames = [];
13
+ for (const [fileName, chunk] of Object.entries(bundle)) {
14
+ if (chunk.type !== "chunk") continue;
15
+ if (chunk.isEntry) continue;
16
+ if (chunk.exports.length > 0) continue;
17
+ const moduleIds = Object.keys(chunk.modules);
18
+ if (moduleIds.length === 0) continue;
19
+ if (!moduleIds.every((id) => styles.has(id))) continue;
20
+ pureCssChunkNames.push(fileName);
21
+ }
22
+ if (!pureCssChunkNames.length) return;
23
+ const replaceEmptyChunk = getEmptyChunkReplacer(pureCssChunkNames);
24
+ for (const file of Object.keys(bundle)) {
25
+ const chunk = bundle[file];
26
+ if (chunk.type !== "chunk") continue;
27
+ let chunkImportsPureCssChunk = false;
28
+ chunk.imports = chunk.imports.filter((importFile) => {
29
+ if (pureCssChunkNames.includes(importFile)) {
30
+ chunkImportsPureCssChunk = true;
31
+ return false;
32
+ }
33
+ return true;
34
+ });
35
+ if (chunkImportsPureCssChunk) chunk.code = replaceEmptyChunk(chunk.code);
36
+ }
37
+ for (const fileName of pureCssChunkNames) {
38
+ delete bundle[fileName];
39
+ delete bundle[`${fileName}.map`];
40
+ }
41
+ }
42
+ /**
43
+ * Create a replacer function that replaces import statements for pure CSS
44
+ * chunks with block comments of the same length, preserving source map offsets.
45
+ */
46
+ function getEmptyChunkReplacer(pureCssChunkNames) {
47
+ const emptyChunkFiles = pureCssChunkNames.map((file) => escapeRegex(path.basename(file))).join("|");
48
+ const emptyChunkRE = new RegExp(String.raw`\bimport\s*["'][^"']*(?:${emptyChunkFiles})["'];`, "g");
49
+ return (code) => code.replace(emptyChunkRE, (m) => {
50
+ return `/* empty css ${"".padEnd(m.length - 15)}*/`;
51
+ });
52
+ }
53
+ function escapeRegex(str) {
54
+ return str.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
55
+ }
56
+
57
+ //#endregion
58
+ //#region src/features/css/post.ts
59
+ function createCssPostHooks(config, styles) {
60
+ const collectedCSS = [];
61
+ return {
62
+ renderChunk(_code, chunk) {
63
+ let chunkCSS = "";
64
+ for (const id of Object.keys(chunk.modules)) {
65
+ const code = styles.get(id);
66
+ if (code) chunkCSS += code;
67
+ }
68
+ if (!chunkCSS) return;
69
+ if (chunkCSS.length > 0 && !chunkCSS.endsWith("\n")) chunkCSS += "\n";
70
+ if (config.css.splitting) {
71
+ const cssAssetFileName = chunk.fileName.replace(/\.(m?js|cjs)$/, ".css");
72
+ this.emitFile({
73
+ type: "asset",
74
+ fileName: cssAssetFileName,
75
+ source: chunkCSS
76
+ });
77
+ } else collectedCSS.push(chunkCSS);
78
+ },
79
+ generateBundle(_outputOptions, bundle) {
80
+ if (!config.css.splitting && collectedCSS.length > 0) {
81
+ const allCSS = collectedCSS.join("");
82
+ if (allCSS) this.emitFile({
83
+ type: "asset",
84
+ fileName: config.css.fileName,
85
+ source: allCSS,
86
+ originalFileName: defaultCssBundleName
87
+ });
88
+ collectedCSS.length = 0;
89
+ }
90
+ removePureCssChunks(bundle, styles);
91
+ }
92
+ };
93
+ }
94
+
95
+ //#endregion
96
+ //#region src/features/css/plugin.ts
97
+ const RE_CSS = /\.css(?:$|\?)/;
98
+ function CssPlugin(config) {
99
+ const styles = /* @__PURE__ */ new Map();
100
+ const postHooks = createCssPostHooks(config, styles);
101
+ return {
102
+ name: "tsdown:builtin-css",
103
+ buildStart() {
104
+ styles.clear();
105
+ },
106
+ load: {
107
+ filter: { id: RE_CSS },
108
+ async handler(id) {
109
+ let code = await readFile(id, "utf8");
110
+ if (code.length > 0 && !code.endsWith("\n")) code += "\n";
111
+ styles.set(id, code);
112
+ return {
113
+ code: "",
114
+ moduleSideEffects: "no-treeshake",
115
+ moduleType: "js"
116
+ };
117
+ }
118
+ },
119
+ ...postHooks
120
+ };
121
+ }
122
+
123
+ //#endregion
124
+ export { removePureCssChunks as a, getEmptyChunkReplacer as i, RE_CSS as n, createCssPostHooks as r, CssPlugin as t };
@@ -1,4 +1,4 @@
1
- import { F as DepPlugin, H as TsdownBundle, _ as ReportPlugin, z as Logger } from "./types-BmbHkVac.mjs";
1
+ import { F as DepPlugin, H as TsdownBundle, _ as ReportPlugin, z as Logger } from "./types-DmX8JP3Y.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/features/node-protocol.d.ts
package/dist/plugins.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as DepPlugin } from "./format-GnNEnvb5.mjs";
2
- import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-Csmj95d-.mjs";
1
+ import { r as DepPlugin } from "./format-DlhdOGIw.mjs";
2
+ import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-DoBIgnx3.mjs";
3
3
 
4
4
  export { DepPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
package/dist/run.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cjs_createRequire } from "node:module";
3
3
  const __cjs_require = __cjs_createRequire(import.meta.url);
4
- import { a as globalLogger } from "./logger-JoV-m1IK.mjs";
5
- import { t as version } from "./package-BT9tRMs2.mjs";
6
- import { t as enableDebug } from "./debug-dRN3JIZi.mjs";
4
+ import { a as globalLogger } from "./logger-C4Xhh0rW.mjs";
5
+ import { t as version } from "./package-DgL9kC53.mjs";
6
+ import { t as enableDebug } from "./debug-DtUr55Vs.mjs";
7
7
  import module from "node:module";
8
8
  import process from "node:process";
9
9
  import { dim, yellow } from "ansis";
@@ -21,7 +21,7 @@ cli.command("[...files]", "Bundle files", {
21
21
  }).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("--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) => {
22
22
  globalLogger.level = flags.logLevel || "info";
23
23
  globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
24
- const { build } = await import("./build-C4izfkd1.mjs");
24
+ const { build } = await import("./build-CY6c95FN.mjs");
25
25
  if (input.length > 0) flags.entry = input;
26
26
  await build(flags);
27
27
  });
@@ -2,7 +2,6 @@ import { BuildOptions, ChecksOptions, ExternalOption, InputOptions, InternalModu
2
2
  import { Hookable } from "hookable";
3
3
  import { Buffer } from "node:buffer";
4
4
  import { Options as DtsOptions } from "rolldown-plugin-dts";
5
- import { TransformOptions } from "lightningcss";
6
5
  import { StartOptions } from "@vitejs/devtools/cli-commands";
7
6
  import { ExeExtensionOptions } from "@tsdown/exe";
8
7
  import { CheckPackageOptions } from "@arethetypeswrong/core";
@@ -60,18 +59,70 @@ interface CssOptions {
60
59
  */
61
60
  fileName?: string;
62
61
  /**
63
- * Options for CSS preprocessors.
62
+ * Set the target environment for CSS syntax lowering.
63
+ * Accepts esbuild-style target strings (e.g., `'chrome99'`, `'safari16.2'`).
64
+ * Defaults to the top-level `target` option.
65
+ *
66
+ * Requires `@tsdown/css` to be installed.
67
+ *
68
+ * @see https://vite.dev/config/build-options#build-csstarget
69
+ */
70
+ target?: string | string[] | false;
71
+ /**
72
+ * Options for CSS preprocessors (Sass/Less/Stylus).
64
73
  *
65
74
  * In addition to options specific to each processor, `additionalData` option
66
75
  * can be used to inject extra code for each style content.
76
+ *
77
+ * Requires `@tsdown/css` to be installed.
67
78
  */
68
79
  preprocessorOptions?: PreprocessorOptions;
69
80
  /**
81
+ * Enable/disable CSS minification.
82
+ *
83
+ * Requires `@tsdown/css` to be installed.
84
+ *
85
+ * @default false
86
+ */
87
+ minify?: boolean;
88
+ /**
70
89
  * Lightning CSS options for CSS syntax lowering and transformations.
71
- * Requires `lightningcss` to be installed.
90
+ *
91
+ * Requires `@tsdown/css` to be installed.
72
92
  */
73
93
  lightningcss?: LightningCSSOptions;
94
+ /**
95
+ * PostCSS configuration.
96
+ *
97
+ * - `string`: Path to the directory to search for PostCSS config files.
98
+ * - `object`: Inline PostCSS options with optional `plugins` array.
99
+ * - Omitted: Auto-detect PostCSS config from the project root.
100
+ *
101
+ * Only used when `transformer` is `'postcss'` (default).
102
+ * Requires `postcss` and `@tsdown/css` to be installed.
103
+ *
104
+ * @see https://github.com/postcss/postcss
105
+ */
106
+ postcss?: PostCSSOptions;
107
+ /**
108
+ * CSS transformer to use. Controls how CSS is processed:
109
+ *
110
+ * - `'postcss'` (default): `@import` handled by `postcss-import`,
111
+ * PostCSS plugins applied, Lightning CSS used only for final
112
+ * targets/minify transform.
113
+ * - `'lightningcss'`: `@import` handled by Lightning CSS `bundleAsync()`,
114
+ * PostCSS is **not** used at all.
115
+ *
116
+ * Requires `@tsdown/css` to be installed.
117
+ *
118
+ * @default 'postcss'
119
+ * @see https://vite.dev/config/shared-options#css-transformer
120
+ */
121
+ transformer?: "postcss" | "lightningcss";
74
122
  }
123
+ type PostCSSOptions = string | (Record<string, any> & {
124
+ plugins?: any[];
125
+ });
75
126
  interface PreprocessorOptions {
76
127
  scss?: SassPreprocessorOptions;
77
128
  sass?: SassPreprocessorOptions;
@@ -101,13 +152,19 @@ interface StylusPreprocessorOptions {
101
152
  paths?: string[];
102
153
  [key: string]: any;
103
154
  }
104
- type LightningCSSOptions = Omit<TransformOptions<any>, "filename" | "code" | "minify" | "sourceMap" | "inputSourceMap">;
155
+ type LightningCSSOptions = Record<string, any>;
105
156
  interface ResolvedCssOptions {
157
+ transformer: "postcss" | "lightningcss";
106
158
  splitting: boolean;
107
159
  fileName: string;
160
+ minify: boolean;
161
+ target?: string[];
108
162
  preprocessorOptions?: PreprocessorOptions;
109
163
  lightningcss?: LightningCSSOptions;
164
+ postcss?: PostCSSOptions;
110
165
  }
166
+ declare const defaultCssBundleName = "style.css";
167
+ declare function resolveCssOptions(options?: CssOptions, topLevelTarget?: string[]): ResolvedCssOptions;
111
168
  //#endregion
112
169
  //#region src/utils/chunks.d.ts
113
170
  type RolldownChunk = (OutputChunk | OutputAsset) & {
@@ -1226,4 +1283,4 @@ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "from
1226
1283
  exe: false | ExeOptions;
1227
1284
  }>;
1228
1285
  //#endregion
1229
- export { Arrayable as $, RolldownContext as A, globalLogger as B, ChunkAddonObject as C, PackageJsonWithPath as D, OutExtensionObject as E, DepPlugin as F, LightningCSSOptions as G, TsdownBundle as H, DepsConfig as I, SassPreprocessorOptions as J, PreprocessorOptions as K, NoExternalFn as L, ExeOptions as M, SeaConfig as N, PackageType as O, DevtoolsOptions as P, CopyOptionsFn as Q, ResolvedDepsConfig as R, ChunkAddonFunction as S, OutExtensionFactory as T, CssOptions as U, RolldownChunk as V, LessPreprocessorOptions as W, CopyEntry as X, StylusPreprocessorOptions as Y, CopyOptions as Z, ReportPlugin as _, NormalizedFormat as a, AttwOptions as b, TreeshakingOptions as c, UserConfig as d, UserConfigExport as f, ReportOptions as g, Workspace as h, InlineConfig as i, TsdownHooks as j, BuildContext as k, TsdownInputOption as l, WithEnabled as m, DtsOptions as n, ResolvedConfig as o, UserConfigFn as p, ResolvedCssOptions as q, Format as r, Sourcemap as s, CIOption as t, UnusedOptions as u, PublintOptions as v, OutExtensionContext as w, ChunkAddon as x, ExportsOptions as y, Logger as z };
1286
+ export { defaultCssBundleName as $, RolldownContext as A, globalLogger as B, ChunkAddonObject as C, PackageJsonWithPath as D, OutExtensionObject as E, DepPlugin as F, LightningCSSOptions as G, TsdownBundle as H, DepsConfig as I, PreprocessorAdditionalDataResult as J, PostCSSOptions as K, NoExternalFn as L, ExeOptions as M, SeaConfig as N, PackageType as O, DevtoolsOptions as P, StylusPreprocessorOptions as Q, ResolvedDepsConfig as R, ChunkAddonFunction as S, OutExtensionFactory as T, CssOptions as U, RolldownChunk as V, LessPreprocessorOptions as W, ResolvedCssOptions as X, PreprocessorOptions as Y, SassPreprocessorOptions as Z, ReportPlugin as _, NormalizedFormat as a, AttwOptions as b, TreeshakingOptions as c, UserConfig as d, resolveCssOptions as et, UserConfigExport as f, ReportOptions as g, Workspace as h, InlineConfig as i, Arrayable as it, TsdownHooks as j, BuildContext as k, TsdownInputOption as l, WithEnabled as m, DtsOptions as n, CopyOptions as nt, ResolvedConfig as o, UserConfigFn as p, PreprocessorAdditionalData as q, Format as r, CopyOptionsFn as rt, Sourcemap as s, CIOption as t, CopyEntry as tt, UnusedOptions as u, PublintOptions as v, OutExtensionContext as w, ChunkAddon as x, ExportsOptions as y, Logger as z };
@@ -1,5 +1,6 @@
1
- import { g as toArray, o as prettyFormat, p as resolveComma, u as noop } from "./logger-JoV-m1IK.mjs";
2
- import { n as formatBytes, s as fsExists } from "./format-GnNEnvb5.mjs";
1
+ import { i as noop, s as resolveComma, u as toArray } from "./general-1LELSDyN.mjs";
2
+ import { n as formatBytes, s as fsExists } from "./format-DlhdOGIw.mjs";
3
+ import { o as prettyFormat } from "./logger-C4Xhh0rW.mjs";
3
4
  import { builtinModules } from "node:module";
4
5
  import { chmod } from "node:fs/promises";
5
6
  import path from "node:path";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsdown",
3
3
  "type": "module",
4
- "version": "0.21.0-beta.3",
4
+ "version": "0.21.0-beta.4",
5
5
  "description": "The Elegant Bundler for Libraries",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -17,6 +17,7 @@
17
17
  "exports": {
18
18
  ".": "./dist/index.mjs",
19
19
  "./config": "./dist/config.mjs",
20
+ "./css": "./dist/css.mjs",
20
21
  "./plugins": "./dist/plugins.mjs",
21
22
  "./run": "./dist/run.mjs",
22
23
  "./package.json": "./package.json",
@@ -48,23 +49,23 @@
48
49
  "peerDependencies": {
49
50
  "@arethetypeswrong/core": "^0.18.1",
50
51
  "@vitejs/devtools": "*",
51
- "lightningcss": "^1.29.0",
52
52
  "publint": "^0.3.0",
53
53
  "typescript": "^5.0.0",
54
54
  "unplugin-unused": "^0.5.0",
55
- "@tsdown/exe": "0.21.0-beta.3"
55
+ "@tsdown/exe": "0.21.0-beta.4",
56
+ "@tsdown/css": "0.21.0-beta.4"
56
57
  },
57
58
  "peerDependenciesMeta": {
58
59
  "@arethetypeswrong/core": {
59
60
  "optional": true
60
61
  },
61
- "@tsdown/exe": {
62
+ "@tsdown/css": {
62
63
  "optional": true
63
64
  },
64
- "@vitejs/devtools": {
65
+ "@tsdown/exe": {
65
66
  "optional": true
66
67
  },
67
- "lightningcss": {
68
+ "@vitejs/devtools": {
68
69
  "optional": true
69
70
  },
70
71
  "publint": {
@@ -87,54 +88,56 @@
87
88
  "obug": "^2.1.1",
88
89
  "picomatch": "^4.0.3",
89
90
  "rolldown": "1.0.0-rc.6",
90
- "rolldown-plugin-dts": "^0.22.2",
91
+ "rolldown-plugin-dts": "^0.22.3",
91
92
  "semver": "^7.7.4",
92
93
  "tinyexec": "^1.0.2",
93
94
  "tinyglobby": "^0.2.15",
94
95
  "tree-kill": "^1.2.2",
95
96
  "unconfig-core": "^7.5.0",
96
- "unrun": "^0.2.28"
97
+ "unrun": "^0.2.29"
98
+ },
99
+ "inlinedDependencies": {
100
+ "package-manager-detector": "1.6.0",
101
+ "@publint/pack": "0.1.4",
102
+ "is-in-ci": "2.0.0",
103
+ "pkg-types": "2.3.0"
97
104
  },
98
105
  "devDependencies": {
99
106
  "@arethetypeswrong/core": "^0.18.2",
100
107
  "@publint/pack": "^0.1.4",
101
- "@sxzz/eslint-config": "^7.8.2",
108
+ "@sxzz/eslint-config": "^7.8.3",
102
109
  "@sxzz/prettier-config": "^2.3.1",
103
110
  "@sxzz/test-utils": "^0.5.15",
104
- "@types/node": "^25.3.2",
111
+ "@types/node": "^25.3.3",
105
112
  "@types/picomatch": "^4.0.2",
106
113
  "@types/semver": "^7.7.1",
107
- "@typescript/native-preview": "7.0.0-dev.20260227.1",
108
- "@unocss/eslint-plugin": "^66.6.2",
114
+ "@typescript/native-preview": "7.0.0-dev.20260304.1",
115
+ "@unocss/eslint-plugin": "^66.6.5",
109
116
  "@vitejs/devtools": "^0.0.0-alpha.32",
110
117
  "@vitest/coverage-v8": "^4.0.18",
111
118
  "@vitest/ui": "^4.0.18",
112
119
  "@vueuse/core": "^14.2.1",
113
120
  "bumpp": "^10.4.1",
114
- "dedent": "^1.7.1",
121
+ "dedent": "^1.7.2",
115
122
  "eslint": "^10.0.2",
116
123
  "is-in-ci": "^2.0.0",
117
- "lightningcss": "^1.31.1",
118
124
  "memfs": "^4.56.10",
119
125
  "package-manager-detector": "^1.6.0",
120
126
  "pkg-types": "^2.3.0",
127
+ "postcss": "^8.5.8",
128
+ "postcss-import": "^16.1.1",
121
129
  "prettier": "^3.8.1",
122
- "publint": "^0.3.17",
123
- "rolldown-plugin-dts-snapshot": "^0.3.2",
130
+ "publint": "^0.3.18",
131
+ "rolldown-plugin-dts-snapshot": "^0.4.0",
124
132
  "rolldown-plugin-require-cjs": "^0.3.3",
125
133
  "typescript": "~5.9.3",
126
- "unocss": "^66.6.2",
134
+ "unocss": "^66.6.5",
127
135
  "unplugin-ast": "^0.16.0",
128
136
  "unplugin-unused": "^0.5.7",
129
137
  "vite": "^8.0.0-beta.15",
130
138
  "vitest": "^4.0.18",
131
- "@tsdown/exe": "0.21.0-beta.3"
132
- },
133
- "inlinedDependencies": {
134
- "package-manager-detector": "1.6.0",
135
- "@publint/pack": "0.1.4",
136
- "is-in-ci": "2.0.0",
137
- "pkg-types": "2.3.0"
139
+ "@tsdown/css": "0.21.0-beta.4",
140
+ "@tsdown/exe": "0.21.0-beta.4"
138
141
  },
139
142
  "prettier": "@sxzz/prettier-config",
140
143
  "scripts": {
@@ -1,3 +0,0 @@
1
- import { n as buildWithConfigs, t as build } from "./build-DABfp5oc.mjs";
2
-
3
- export { build };
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.21.0-beta.3";
3
-
4
- //#endregion
5
- export { version as t };