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

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,10 +857,12 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
857
857
  });
858
858
 
859
859
  // src/build/stylePreprocessor.ts
860
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
860
861
  import { readFile } from "fs/promises";
861
862
  import { createRequire } from "module";
862
- import { dirname as dirname2, extname, join as join3, resolve as resolve4 } from "path";
863
- 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)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
863
+ import { dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve as resolve4 } from "path";
864
+ 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) => {
864
866
  const normalized = filePathOrLanguage.toLowerCase();
865
867
  if (normalized === "scss" || normalized.endsWith(".scss"))
866
868
  return "scss";
@@ -868,16 +870,196 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
868
870
  return "sass";
869
871
  if (normalized === "less" || normalized.endsWith(".less"))
870
872
  return "less";
873
+ if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
874
+ return "stylus";
871
875
  return null;
872
876
  }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
873
877
  dirname2(filePath),
874
878
  process.cwd(),
875
879
  ...paths.map((path) => resolve4(process.cwd(), path))
876
- ], getSassOptions = (config, language) => ({
880
+ ], tsconfigAliasCache, stripJsonComments = (source) => source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1"), normalizeAliasEntries = (aliases) => Object.entries(aliases ?? {}).map(([pattern, value]) => ({
881
+ pattern,
882
+ replacements: Array.isArray(value) ? value : [value]
883
+ })), readTsconfigAliases = () => {
884
+ const cwd = process.cwd();
885
+ if (tsconfigAliasCache?.cwd === cwd)
886
+ return tsconfigAliasCache;
887
+ const tsconfigPath = resolve4(cwd, "tsconfig.json");
888
+ const empty = { aliases: [], baseUrl: cwd, cwd };
889
+ if (!existsSync4(tsconfigPath)) {
890
+ tsconfigAliasCache = empty;
891
+ return empty;
892
+ }
893
+ try {
894
+ const parsed = JSON.parse(stripJsonComments(readFileSync3(tsconfigPath, "utf-8")));
895
+ const compilerOptions = parsed.compilerOptions ?? {};
896
+ const baseUrl = resolve4(cwd, compilerOptions.baseUrl ?? ".");
897
+ tsconfigAliasCache = {
898
+ aliases: normalizeAliasEntries(compilerOptions.paths),
899
+ baseUrl,
900
+ cwd
901
+ };
902
+ } catch {
903
+ tsconfigAliasCache = empty;
904
+ }
905
+ return tsconfigAliasCache;
906
+ }, getAliasEntries = (config) => {
907
+ const tsconfig = readTsconfigAliases();
908
+ return {
909
+ aliases: [...normalizeAliasEntries(config?.aliases), ...tsconfig.aliases],
910
+ baseUrl: tsconfig.baseUrl
911
+ };
912
+ }, aliasPatternToRegExp = (pattern) => new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("(.+)")}$`), resolveAliasTargets = (specifier, config) => {
913
+ const { aliases, baseUrl } = getAliasEntries(config);
914
+ const targets = [];
915
+ for (const alias of aliases) {
916
+ const match = specifier.match(aliasPatternToRegExp(alias.pattern));
917
+ if (!match)
918
+ continue;
919
+ const wildcard = match[1] ?? "";
920
+ for (const replacement of alias.replacements) {
921
+ targets.push(resolve4(baseUrl, replacement.replace("*", wildcard)));
922
+ }
923
+ }
924
+ return targets;
925
+ }, getLanguageExtensions = (language) => {
926
+ if (language === "less")
927
+ return [".less", ".css"];
928
+ if (language === "stylus")
929
+ return [".styl", ".stylus", ".css"];
930
+ return [".scss", ".sass", ".css"];
931
+ }, getCandidatePaths = (basePath, language) => {
932
+ const ext = extname(basePath);
933
+ const paths = ext ? [basePath] : getLanguageExtensions(language).flatMap((extension) => [
934
+ `${basePath}${extension}`,
935
+ join3(basePath, `index${extension}`)
936
+ ]);
937
+ if (language === "scss" || language === "sass") {
938
+ return paths.flatMap((path) => {
939
+ const dir = dirname2(path);
940
+ const base = path.slice(dir.length + 1);
941
+ return [path, join3(dir, `_${base}`)];
942
+ });
943
+ }
944
+ return paths;
945
+ }, resolveImportPath = (specifier, fromDirectory, loadPaths, language, config) => {
946
+ const rawCandidates = [
947
+ ...resolveAliasTargets(specifier, config),
948
+ isAbsolute(specifier) ? specifier : resolve4(fromDirectory, specifier),
949
+ ...loadPaths.map((path) => resolve4(path, specifier))
950
+ ];
951
+ for (const candidate of rawCandidates.flatMap((path) => getCandidatePaths(path, language))) {
952
+ if (existsSync4(candidate))
953
+ return candidate;
954
+ }
955
+ return null;
956
+ }, isExternalCssUrl = (url) => /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i.test(url), splitCssUrl = (url) => {
957
+ const markerIndex = url.search(/[?#]/);
958
+ if (markerIndex === -1)
959
+ return { marker: "", path: url };
960
+ return {
961
+ marker: url.slice(markerIndex),
962
+ path: url.slice(0, markerIndex)
963
+ };
964
+ }, rebaseCssUrls = (contents, sourceFile, entryFile) => {
965
+ const sourceDir = dirname2(sourceFile);
966
+ const entryDir = dirname2(entryFile);
967
+ if (sourceDir === entryDir)
968
+ return contents;
969
+ return contents.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/gi, (match, quote, rawUrl) => {
970
+ const trimmedUrl = rawUrl.trim();
971
+ if (!trimmedUrl || isExternalCssUrl(trimmedUrl))
972
+ return match;
973
+ const { marker, path } = splitCssUrl(trimmedUrl);
974
+ const rebased = relative(entryDir, resolve4(sourceDir, path)).replace(/\\/g, "/");
975
+ const normalized = rebased.startsWith(".") ? rebased : `./${rebased}`;
976
+ const nextQuote = quote || '"';
977
+ return `url(${nextQuote}${normalized}${marker}${nextQuote})`;
978
+ });
979
+ }, rewriteAliasedStyleImports = (contents, sourceFile, loadPaths, language, config) => contents.replace(/(@(?:use|forward|import|require)\s+)(["'])([^"']+)\2/g, (match, prefix, quote, specifier) => {
980
+ if (specifier.startsWith(".") || isAbsolute(specifier) || isExternalCssUrl(specifier))
981
+ return match;
982
+ const resolved = resolveImportPath(specifier, dirname2(sourceFile), loadPaths, language, config);
983
+ return resolved ? `${prefix}${quote}${resolved}${quote}` : match;
984
+ }), preprocessLoadedStyle = (contents, sourceFile, entryFile, loadPaths = [], language, config) => {
985
+ const rebased = rebaseCssUrls(contents, sourceFile, entryFile);
986
+ return language ? rewriteAliasedStyleImports(rebased, sourceFile, loadPaths, language, config) : rebased;
987
+ }, extractCssModuleExports = (css) => {
988
+ const exports = {};
989
+ const nextCss = css.replace(/:export\s*\{([^}]*)\}/g, (_, body) => {
990
+ for (const declaration of body.split(";")) {
991
+ const separator = declaration.indexOf(":");
992
+ if (separator === -1)
993
+ continue;
994
+ const key = declaration.slice(0, separator).trim();
995
+ const value = declaration.slice(separator + 1).trim();
996
+ if (key && value)
997
+ exports[key] = value;
998
+ }
999
+ return "";
1000
+ });
1001
+ return { css: nextCss, exports };
1002
+ }, getSassOptions = (config, language) => ({
877
1003
  ...config?.sass ?? {},
878
1004
  ...language === "scss" ? config?.scss ?? {} : {}
879
- }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
880
- ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
1005
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
1006
+ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
1007
+ canonicalize(specifier, options) {
1008
+ const fromDirectory = options.containingUrl ? dirname2(fileURLToPath(options.containingUrl)) : dirname2(entryFile);
1009
+ const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
1010
+ return resolved ? new URL(`file://${resolved}`) : null;
1011
+ },
1012
+ load(canonicalUrl) {
1013
+ const filePath = fileURLToPath(canonicalUrl);
1014
+ const fileLanguage = getStyleLanguage(filePath);
1015
+ if (fileLanguage !== "scss" && fileLanguage !== "sass" && fileLanguage !== null)
1016
+ return null;
1017
+ return {
1018
+ contents: preprocessLoadedStyle(readFileSync3(filePath, "utf-8"), filePath, entryFile, loadPaths, language, config),
1019
+ syntax: filePath.endsWith(".sass") ? "indented" : "scss"
1020
+ };
1021
+ }
1022
+ }), createLessFileManager = (entryFile, loadPaths, config) => ({
1023
+ install(less, pluginManager) {
1024
+ const baseManager = new less.FileManager;
1025
+ const manager = Object.create(baseManager);
1026
+ manager.supports = (filename, currentDirectory) => Boolean(resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config));
1027
+ manager.loadFile = async (filename, currentDirectory) => {
1028
+ const resolved = resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config);
1029
+ if (!resolved) {
1030
+ throw new Error(`Unable to resolve Less import "${filename}"`);
1031
+ }
1032
+ return {
1033
+ contents: preprocessLoadedStyle(await readFile(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
1034
+ filename: resolved
1035
+ };
1036
+ };
1037
+ pluginManager.addFileManager(manager);
1038
+ }
1039
+ }), renderStylus = async (contents, filePath, loadPaths, options) => {
1040
+ let stylus;
1041
+ try {
1042
+ const stylusModule = await importOptionalPeer("stylus");
1043
+ stylus = stylusModule.default ?? stylusModule;
1044
+ } catch {
1045
+ throw missingDependencyError("stylus", filePath);
1046
+ }
1047
+ return new Promise((resolveCss, reject) => {
1048
+ const renderer = stylus(contents);
1049
+ renderer.set("filename", filePath);
1050
+ for (const [key, value] of Object.entries(options.options ?? {})) {
1051
+ renderer.set(key, value);
1052
+ }
1053
+ for (const path of loadPaths)
1054
+ renderer.include(path);
1055
+ renderer.render((error, css) => {
1056
+ if (error)
1057
+ reject(error);
1058
+ else
1059
+ resolveCss(css ?? "");
1060
+ });
1061
+ });
1062
+ }, compileStyleSource = async (filePath, source, languageHint, config) => {
881
1063
  const language = getStyleLanguage(languageHint ?? filePath);
882
1064
  const rawContents = source ?? await readFile(filePath, "utf-8");
883
1065
  if (language === "scss" || language === "sass") {
@@ -890,8 +1072,12 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
890
1072
  throw missingDependencyError(packageName, filePath);
891
1073
  }
892
1074
  const contents = withAdditionalData(rawContents, options.additionalData);
1075
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
893
1076
  const result = sass.compileString(contents, {
894
- loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
1077
+ importers: [
1078
+ createSassImporter(filePath, loadPaths, language, config)
1079
+ ],
1080
+ loadPaths,
895
1081
  style: "expanded",
896
1082
  syntax: language === "sass" ? "indented" : "scss",
897
1083
  url: new URL(`file://${filePath}`)
@@ -911,13 +1097,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
911
1097
  if (!render)
912
1098
  throw missingDependencyError("less", filePath);
913
1099
  const contents = withAdditionalData(rawContents, options.additionalData);
1100
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
914
1101
  const result = await render(contents, {
915
1102
  ...options.options ?? {},
916
1103
  filename: filePath,
917
- paths: normalizeLoadPaths(filePath, options.paths)
1104
+ paths: loadPaths,
1105
+ plugins: [
1106
+ ...options.options?.plugins ?? [],
1107
+ createLessFileManager(filePath, loadPaths, config)
1108
+ ]
918
1109
  });
919
1110
  return result.css;
920
1111
  }
1112
+ if (language === "stylus") {
1113
+ const options = getStylusOptions(config);
1114
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
1115
+ const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
1116
+ return renderStylus(contents, filePath, loadPaths, options);
1117
+ }
921
1118
  return rawContents;
922
1119
  }, createStylePreprocessorPlugin = (config) => ({
923
1120
  name: "absolute-style-preprocessor",
@@ -928,21 +1125,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
928
1125
  path: path.slice("absolute-style-module:".length)
929
1126
  }));
930
1127
  build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
931
- const sourcePath = cssModuleSources.get(path);
932
- if (!sourcePath) {
1128
+ const source = cssModuleSources.get(path);
1129
+ if (!source) {
933
1130
  throw new Error(`Unable to resolve CSS module source for ${path}`);
934
1131
  }
935
1132
  return {
936
- contents: await compileStyleSource(sourcePath, undefined, undefined, config),
1133
+ contents: source.css,
937
1134
  loader: "css"
938
1135
  };
939
1136
  });
940
1137
  build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
941
1138
  if (isStyleModulePath(path)) {
942
1139
  const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
943
- cssModuleSources.set(cssModulePath, path);
1140
+ const compiled = await compileStyleSource(path, undefined, undefined, config);
1141
+ const { css, exports } = extractCssModuleExports(compiled);
1142
+ cssModuleSources.set(cssModulePath, { css, exports });
1143
+ const exportSource = Object.keys(exports).length > 0 ? `import styles from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)}; export default Object.assign({}, styles, ${JSON.stringify(exports)});` : `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`;
944
1144
  return {
945
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
1145
+ contents: exportSource,
946
1146
  loader: "js"
947
1147
  };
948
1148
  }
@@ -973,9 +1173,9 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
973
1173
  return compileStyleSource(filePath, undefined, undefined, config);
974
1174
  };
975
1175
  var init_stylePreprocessor = __esm(() => {
976
- STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
977
- STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less)$/i;
978
- STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less)$/i;
1176
+ STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
1177
+ STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
1178
+ STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
979
1179
  importOptionalPeer = new Function("specifier", "return import(specifier)");
980
1180
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
981
1181
  requireFromCwd = createRequire(join3(process.cwd(), "package.json"));
@@ -984,9 +1184,9 @@ var init_stylePreprocessor = __esm(() => {
984
1184
 
985
1185
  // src/core/svelteServerModule.ts
986
1186
  import { mkdir, readdir } from "fs/promises";
987
- import { basename, dirname as dirname3, extname as extname2, join as join4, relative, resolve as resolve5 } from "path";
1187
+ import { basename, dirname as dirname3, extname as extname2, join as join4, relative as relative2, resolve as resolve5 } from "path";
988
1188
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
989
- const importPath = relative(dirname3(from), target).replace(/\\/g, "/");
1189
+ const importPath = relative2(dirname3(from), target).replace(/\\/g, "/");
990
1190
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
991
1191
  }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
992
1192
  for (const entry of entries) {
@@ -1050,7 +1250,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
1050
1250
  const foundIndex = existResults.indexOf(true);
1051
1251
  return foundIndex >= 0 ? candidates[foundIndex] ?? null : null;
1052
1252
  }, getCachedModulePath = (sourcePath) => {
1053
- const relativeSourcePath = relative(process.cwd(), sourcePath).replace(/\\/g, "/");
1253
+ const relativeSourcePath = relative2(process.cwd(), sourcePath).replace(/\\/g, "/");
1054
1254
  const normalizedSourcePath = relativeSourcePath.startsWith("..") ? sourcePath.replace(/[:\\/]/g, "_") : relativeSourcePath;
1055
1255
  return join4(serverCacheRoot, `${normalizedSourcePath}.server.js`);
1056
1256
  }, resolveSvelteImport = async (spec, from) => {
@@ -1425,5 +1625,5 @@ export {
1425
1625
  createIslandStore
1426
1626
  };
1427
1627
 
1428
- //# debugId=5850F97AA766FE9B64756E2164756E21
1628
+ //# debugId=DD3DA624C348BAAD64756E2164756E21
1429
1629
  //# sourceMappingURL=index.js.map