@absolutejs/absolute 0.19.0-beta.694 → 0.19.0-beta.695

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.
@@ -359,12 +359,27 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
359
359
  });
360
360
 
361
361
  // src/build/stylePreprocessor.ts
362
+ var exports_stylePreprocessor = {};
363
+ __export(exports_stylePreprocessor, {
364
+ stylePreprocessorPlugin: () => stylePreprocessorPlugin,
365
+ isStylePath: () => isStylePath,
366
+ isStyleModulePath: () => isStyleModulePath,
367
+ isPreprocessableStylePath: () => isPreprocessableStylePath,
368
+ getStyleBaseName: () => getStyleBaseName,
369
+ getCssOutputExtension: () => getCssOutputExtension,
370
+ createSvelteStylePreprocessor: () => createSvelteStylePreprocessor,
371
+ createStyleTransformConfig: () => createStyleTransformConfig,
372
+ createStylePreprocessorPlugin: () => createStylePreprocessorPlugin,
373
+ compileStyleSource: () => compileStyleSource,
374
+ compileStyleFileIfNeededSync: () => compileStyleFileIfNeededSync,
375
+ compileStyleFileIfNeeded: () => compileStyleFileIfNeeded
376
+ });
362
377
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
363
378
  import { readFile } from "fs/promises";
364
379
  import { createRequire } from "module";
365
380
  import { dirname, extname, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
366
381
  import { fileURLToPath } from "url";
367
- var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
382
+ var CSS_EXTENSION_PATTERN, STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
368
383
  const normalized = filePathOrLanguage.toLowerCase();
369
384
  if (normalized === "scss" || normalized.endsWith(".scss"))
370
385
  return "scss";
@@ -375,7 +390,13 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
375
390
  if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
376
391
  return "stylus";
377
392
  return null;
378
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
393
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
394
+ try {
395
+ return requireFromCwd(specifier);
396
+ } catch {
397
+ return requireOptionalPeer(specifier);
398
+ }
399
+ }, normalizeLoadPaths = (filePath, paths = []) => [
379
400
  dirname(filePath),
380
401
  process.cwd(),
381
402
  ...paths.map((path) => resolve2(process.cwd(), path))
@@ -504,8 +525,72 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
504
525
  }, getSassOptions = (config, language) => ({
505
526
  ...config?.sass ?? {},
506
527
  ...language === "scss" ? config?.scss ?? {} : {}
507
- }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
508
- ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
528
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, createStyleTransformConfig = (stylePreprocessors, postcss) => postcss === undefined ? stylePreprocessors : { ...stylePreprocessors ?? {}, postcss }, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
529
+ ${contents}` : contents, normalizePostcssModule = (mod) => {
530
+ if (mod && typeof mod === "object" && "default" in mod) {
531
+ return mod.default ?? mod;
532
+ }
533
+ return mod;
534
+ }, loadPostcssConfigFile = async (configPath) => {
535
+ const resolved = resolve2(process.cwd(), configPath);
536
+ const loaded = resolved.endsWith(".cjs") || resolved.endsWith(".cts") ? requireOptionalPeerSync(resolved) : await importOptionalPeer(`${new URL(`file://${resolved}`).href}?t=${Date.now()}`);
537
+ const config = normalizePostcssModule(loaded);
538
+ const value = typeof config === "function" ? await config({
539
+ cwd: process.cwd(),
540
+ env: "development"
541
+ }) : config;
542
+ return normalizePostcssModule(value) ?? {};
543
+ }, normalizePostcssPlugins = (plugins) => {
544
+ if (!plugins)
545
+ return [];
546
+ if (Array.isArray(plugins))
547
+ return plugins.filter(Boolean);
548
+ const resolved = [];
549
+ for (const [specifier, options] of Object.entries(plugins)) {
550
+ if (options === false)
551
+ continue;
552
+ const mod = normalizePostcssModule(requireOptionalPeerSync(specifier));
553
+ const plugin = typeof mod === "function" ? mod(options === true ? undefined : options) : mod;
554
+ if (plugin)
555
+ resolved.push(plugin);
556
+ }
557
+ return resolved;
558
+ }, resolvePostcssConfig = async (config) => {
559
+ const inlineConfig = config?.postcss;
560
+ if (!inlineConfig)
561
+ return null;
562
+ const fileConfig = inlineConfig.config ? await loadPostcssConfigFile(inlineConfig.config) : {};
563
+ const plugins = [
564
+ ...normalizePostcssPlugins(fileConfig.plugins),
565
+ ...normalizePostcssPlugins(inlineConfig.plugins)
566
+ ];
567
+ if (plugins.length === 0)
568
+ return null;
569
+ return {
570
+ options: {
571
+ ...fileConfig.options ?? {},
572
+ ...inlineConfig.options ?? {}
573
+ },
574
+ plugins
575
+ };
576
+ }, runPostcss = async (css, filePath, config) => {
577
+ const postcssConfig = await resolvePostcssConfig(config);
578
+ if (!postcssConfig)
579
+ return css;
580
+ let postcssModule;
581
+ try {
582
+ postcssModule = await importOptionalPeer("postcss");
583
+ } catch {
584
+ throw missingDependencyError("postcss", filePath);
585
+ }
586
+ const postcss = postcssModule.default ?? postcssModule;
587
+ const result = await postcss(postcssConfig.plugins).process(css, {
588
+ from: filePath,
589
+ map: false,
590
+ ...postcssConfig.options
591
+ });
592
+ return result.css;
593
+ }, createSassImporter = (entryFile, loadPaths, language, config) => ({
509
594
  canonicalize(specifier, options) {
510
595
  const fromDirectory = options.containingUrl ? dirname(fileURLToPath(options.containingUrl)) : dirname(entryFile);
511
596
  const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
@@ -584,7 +669,7 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
584
669
  syntax: language === "sass" ? "indented" : "scss",
585
670
  url: new URL(`file://${filePath}`)
586
671
  });
587
- return result.css;
672
+ return runPostcss(result.css, filePath, config);
588
673
  }
589
674
  if (language === "less") {
590
675
  const options = getLessOptions(config);
@@ -609,15 +694,15 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
609
694
  createLessFileManager(filePath, loadPaths, config)
610
695
  ]
611
696
  });
612
- return result.css;
697
+ return runPostcss(result.css, filePath, config);
613
698
  }
614
699
  if (language === "stylus") {
615
700
  const options = getStylusOptions(config);
616
701
  const loadPaths = normalizeLoadPaths(filePath, options.paths);
617
702
  const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
618
- return renderStylus(contents, filePath, loadPaths, options);
703
+ return runPostcss(await renderStylus(contents, filePath, loadPaths, options), filePath, config);
619
704
  }
620
- return rawContents;
705
+ return runPostcss(rawContents, filePath, config);
621
706
  }, createStylePreprocessorPlugin = (config) => ({
622
707
  name: "absolute-style-preprocessor",
623
708
  setup(build) {
@@ -653,6 +738,10 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
653
738
  loader: "css"
654
739
  };
655
740
  });
741
+ build.onLoad({ filter: CSS_EXTENSION_PATTERN }, async ({ path }) => ({
742
+ contents: await compileStyleSource(path, undefined, undefined, config),
743
+ loader: "css"
744
+ }));
656
745
  }
657
746
  }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
658
747
  style: async ({
@@ -670,11 +759,46 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
670
759
  }
671
760
  }), compileStyleFileIfNeeded = async (filePath, config) => {
672
761
  if (!isPreprocessableStylePath(filePath)) {
673
- return readFile(filePath, "utf-8");
762
+ return runPostcss(await readFile(filePath, "utf-8"), filePath, config);
674
763
  }
675
764
  return compileStyleSource(filePath, undefined, undefined, config);
676
- };
765
+ }, compileStyleFileIfNeededSync = (filePath, config) => {
766
+ const rawContents = readFileSync2(filePath, "utf-8");
767
+ const language = getStyleLanguage(filePath);
768
+ if (config?.postcss) {
769
+ throw new Error(`Unable to compile ${filePath}: PostCSS preprocessing is async-only.`);
770
+ }
771
+ if (language === "scss" || language === "sass") {
772
+ const options = getSassOptions(config, language);
773
+ const packageName = options.implementation ?? "sass";
774
+ let sass;
775
+ try {
776
+ sass = requireOptionalPeerSync(packageName);
777
+ } catch {
778
+ throw missingDependencyError(packageName, filePath);
779
+ }
780
+ const contents = withAdditionalData(rawContents, options.additionalData);
781
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
782
+ return sass.compileString(contents, {
783
+ importers: [
784
+ createSassImporter(filePath, loadPaths, language, config)
785
+ ],
786
+ loadPaths,
787
+ style: "expanded",
788
+ syntax: language === "sass" ? "indented" : "scss",
789
+ url: new URL(`file://${filePath}`)
790
+ }).css;
791
+ }
792
+ if (language === "less") {
793
+ throw new Error(`Unable to compile ${filePath}: Less styleUrl preprocessing is async-only. Import the Less file from a bundled entrypoint or use SCSS/CSS for Angular styleUrl.`);
794
+ }
795
+ if (language === "stylus") {
796
+ throw new Error(`Unable to compile ${filePath}: Stylus styleUrl preprocessing is async-only. Import the Stylus file from a bundled entrypoint or use SCSS/CSS for Angular styleUrl.`);
797
+ }
798
+ return rawContents;
799
+ }, getCssOutputExtension = (filePath) => isPreprocessableStylePath(filePath) ? ".css" : extname(filePath);
677
800
  var init_stylePreprocessor = __esm(() => {
801
+ CSS_EXTENSION_PATTERN = /\.css$/i;
678
802
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
679
803
  STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
680
804
  STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
@@ -2501,5 +2625,5 @@ export {
2501
2625
  handleSveltePageRequest
2502
2626
  };
2503
2627
 
2504
- //# debugId=B4B4A0E1AC4FA91264756E2164756E21
2628
+ //# debugId=C7312D0D59797E0964756E2164756E21
2505
2629
  //# sourceMappingURL=server.js.map