@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.
@@ -857,12 +857,27 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
857
857
  });
858
858
 
859
859
  // src/build/stylePreprocessor.ts
860
+ var exports_stylePreprocessor = {};
861
+ __export(exports_stylePreprocessor, {
862
+ stylePreprocessorPlugin: () => stylePreprocessorPlugin,
863
+ isStylePath: () => isStylePath,
864
+ isStyleModulePath: () => isStyleModulePath,
865
+ isPreprocessableStylePath: () => isPreprocessableStylePath,
866
+ getStyleBaseName: () => getStyleBaseName,
867
+ getCssOutputExtension: () => getCssOutputExtension,
868
+ createSvelteStylePreprocessor: () => createSvelteStylePreprocessor,
869
+ createStyleTransformConfig: () => createStyleTransformConfig,
870
+ createStylePreprocessorPlugin: () => createStylePreprocessorPlugin,
871
+ compileStyleSource: () => compileStyleSource,
872
+ compileStyleFileIfNeededSync: () => compileStyleFileIfNeededSync,
873
+ compileStyleFileIfNeeded: () => compileStyleFileIfNeeded
874
+ });
860
875
  import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
861
876
  import { readFile } from "fs/promises";
862
877
  import { createRequire } from "module";
863
878
  import { dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve as resolve4 } from "path";
864
879
  import { fileURLToPath } from "url";
865
- 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) => {
880
+ 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) => {
866
881
  const normalized = filePathOrLanguage.toLowerCase();
867
882
  if (normalized === "scss" || normalized.endsWith(".scss"))
868
883
  return "scss";
@@ -873,7 +888,13 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
873
888
  if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
874
889
  return "stylus";
875
890
  return null;
876
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
891
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
892
+ try {
893
+ return requireFromCwd(specifier);
894
+ } catch {
895
+ return requireOptionalPeer(specifier);
896
+ }
897
+ }, normalizeLoadPaths = (filePath, paths = []) => [
877
898
  dirname2(filePath),
878
899
  process.cwd(),
879
900
  ...paths.map((path) => resolve4(process.cwd(), path))
@@ -1002,8 +1023,72 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
1002
1023
  }, getSassOptions = (config, language) => ({
1003
1024
  ...config?.sass ?? {},
1004
1025
  ...language === "scss" ? config?.scss ?? {} : {}
1005
- }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
1006
- ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
1026
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, createStyleTransformConfig = (stylePreprocessors, postcss) => postcss === undefined ? stylePreprocessors : { ...stylePreprocessors ?? {}, postcss }, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
1027
+ ${contents}` : contents, normalizePostcssModule = (mod) => {
1028
+ if (mod && typeof mod === "object" && "default" in mod) {
1029
+ return mod.default ?? mod;
1030
+ }
1031
+ return mod;
1032
+ }, loadPostcssConfigFile = async (configPath) => {
1033
+ const resolved = resolve4(process.cwd(), configPath);
1034
+ const loaded = resolved.endsWith(".cjs") || resolved.endsWith(".cts") ? requireOptionalPeerSync(resolved) : await importOptionalPeer(`${new URL(`file://${resolved}`).href}?t=${Date.now()}`);
1035
+ const config = normalizePostcssModule(loaded);
1036
+ const value = typeof config === "function" ? await config({
1037
+ cwd: process.cwd(),
1038
+ env: "development"
1039
+ }) : config;
1040
+ return normalizePostcssModule(value) ?? {};
1041
+ }, normalizePostcssPlugins = (plugins) => {
1042
+ if (!plugins)
1043
+ return [];
1044
+ if (Array.isArray(plugins))
1045
+ return plugins.filter(Boolean);
1046
+ const resolved = [];
1047
+ for (const [specifier, options] of Object.entries(plugins)) {
1048
+ if (options === false)
1049
+ continue;
1050
+ const mod = normalizePostcssModule(requireOptionalPeerSync(specifier));
1051
+ const plugin = typeof mod === "function" ? mod(options === true ? undefined : options) : mod;
1052
+ if (plugin)
1053
+ resolved.push(plugin);
1054
+ }
1055
+ return resolved;
1056
+ }, resolvePostcssConfig = async (config) => {
1057
+ const inlineConfig = config?.postcss;
1058
+ if (!inlineConfig)
1059
+ return null;
1060
+ const fileConfig = inlineConfig.config ? await loadPostcssConfigFile(inlineConfig.config) : {};
1061
+ const plugins = [
1062
+ ...normalizePostcssPlugins(fileConfig.plugins),
1063
+ ...normalizePostcssPlugins(inlineConfig.plugins)
1064
+ ];
1065
+ if (plugins.length === 0)
1066
+ return null;
1067
+ return {
1068
+ options: {
1069
+ ...fileConfig.options ?? {},
1070
+ ...inlineConfig.options ?? {}
1071
+ },
1072
+ plugins
1073
+ };
1074
+ }, runPostcss = async (css, filePath, config) => {
1075
+ const postcssConfig = await resolvePostcssConfig(config);
1076
+ if (!postcssConfig)
1077
+ return css;
1078
+ let postcssModule;
1079
+ try {
1080
+ postcssModule = await importOptionalPeer("postcss");
1081
+ } catch {
1082
+ throw missingDependencyError("postcss", filePath);
1083
+ }
1084
+ const postcss = postcssModule.default ?? postcssModule;
1085
+ const result = await postcss(postcssConfig.plugins).process(css, {
1086
+ from: filePath,
1087
+ map: false,
1088
+ ...postcssConfig.options
1089
+ });
1090
+ return result.css;
1091
+ }, createSassImporter = (entryFile, loadPaths, language, config) => ({
1007
1092
  canonicalize(specifier, options) {
1008
1093
  const fromDirectory = options.containingUrl ? dirname2(fileURLToPath(options.containingUrl)) : dirname2(entryFile);
1009
1094
  const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
@@ -1082,7 +1167,7 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
1082
1167
  syntax: language === "sass" ? "indented" : "scss",
1083
1168
  url: new URL(`file://${filePath}`)
1084
1169
  });
1085
- return result.css;
1170
+ return runPostcss(result.css, filePath, config);
1086
1171
  }
1087
1172
  if (language === "less") {
1088
1173
  const options = getLessOptions(config);
@@ -1107,15 +1192,15 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
1107
1192
  createLessFileManager(filePath, loadPaths, config)
1108
1193
  ]
1109
1194
  });
1110
- return result.css;
1195
+ return runPostcss(result.css, filePath, config);
1111
1196
  }
1112
1197
  if (language === "stylus") {
1113
1198
  const options = getStylusOptions(config);
1114
1199
  const loadPaths = normalizeLoadPaths(filePath, options.paths);
1115
1200
  const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
1116
- return renderStylus(contents, filePath, loadPaths, options);
1201
+ return runPostcss(await renderStylus(contents, filePath, loadPaths, options), filePath, config);
1117
1202
  }
1118
- return rawContents;
1203
+ return runPostcss(rawContents, filePath, config);
1119
1204
  }, createStylePreprocessorPlugin = (config) => ({
1120
1205
  name: "absolute-style-preprocessor",
1121
1206
  setup(build) {
@@ -1151,6 +1236,10 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
1151
1236
  loader: "css"
1152
1237
  };
1153
1238
  });
1239
+ build.onLoad({ filter: CSS_EXTENSION_PATTERN }, async ({ path }) => ({
1240
+ contents: await compileStyleSource(path, undefined, undefined, config),
1241
+ loader: "css"
1242
+ }));
1154
1243
  }
1155
1244
  }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
1156
1245
  style: async ({
@@ -1168,11 +1257,46 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
1168
1257
  }
1169
1258
  }), compileStyleFileIfNeeded = async (filePath, config) => {
1170
1259
  if (!isPreprocessableStylePath(filePath)) {
1171
- return readFile(filePath, "utf-8");
1260
+ return runPostcss(await readFile(filePath, "utf-8"), filePath, config);
1172
1261
  }
1173
1262
  return compileStyleSource(filePath, undefined, undefined, config);
1174
- };
1263
+ }, compileStyleFileIfNeededSync = (filePath, config) => {
1264
+ const rawContents = readFileSync3(filePath, "utf-8");
1265
+ const language = getStyleLanguage(filePath);
1266
+ if (config?.postcss) {
1267
+ throw new Error(`Unable to compile ${filePath}: PostCSS preprocessing is async-only.`);
1268
+ }
1269
+ if (language === "scss" || language === "sass") {
1270
+ const options = getSassOptions(config, language);
1271
+ const packageName = options.implementation ?? "sass";
1272
+ let sass;
1273
+ try {
1274
+ sass = requireOptionalPeerSync(packageName);
1275
+ } catch {
1276
+ throw missingDependencyError(packageName, filePath);
1277
+ }
1278
+ const contents = withAdditionalData(rawContents, options.additionalData);
1279
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
1280
+ return sass.compileString(contents, {
1281
+ importers: [
1282
+ createSassImporter(filePath, loadPaths, language, config)
1283
+ ],
1284
+ loadPaths,
1285
+ style: "expanded",
1286
+ syntax: language === "sass" ? "indented" : "scss",
1287
+ url: new URL(`file://${filePath}`)
1288
+ }).css;
1289
+ }
1290
+ if (language === "less") {
1291
+ 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.`);
1292
+ }
1293
+ if (language === "stylus") {
1294
+ 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.`);
1295
+ }
1296
+ return rawContents;
1297
+ }, getCssOutputExtension = (filePath) => isPreprocessableStylePath(filePath) ? ".css" : extname(filePath);
1175
1298
  var init_stylePreprocessor = __esm(() => {
1299
+ CSS_EXTENSION_PATTERN = /\.css$/i;
1176
1300
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
1177
1301
  STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
1178
1302
  STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
@@ -1625,5 +1749,5 @@ export {
1625
1749
  createIslandStore
1626
1750
  };
1627
1751
 
1628
- //# debugId=DD3DA624C348BAAD64756E2164756E21
1752
+ //# debugId=26E37550F14CC1A964756E2164756E21
1629
1753
  //# sourceMappingURL=index.js.map