@absolutejs/absolute 0.19.0-beta.686 → 0.19.0-beta.688

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.
@@ -2501,11 +2501,120 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
2501
2501
  AWAIT_BLOCK_RE = /\{#await\s+([^}]+)\}([\s\S]*?)\{:then(?:\s+([A-Za-z_$][\w$]*))?\}([\s\S]*?)(?:\{:catch(?:\s+([A-Za-z_$][\w$]*))?\}([\s\S]*?))?\{\/await\}/g;
2502
2502
  });
2503
2503
 
2504
+ // src/build/stylePreprocessor.ts
2505
+ import { readFile } from "fs/promises";
2506
+ import { dirname as dirname2, extname } from "path";
2507
+ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, 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) => {
2508
+ const normalized = filePathOrLanguage.toLowerCase();
2509
+ if (normalized === "scss" || normalized.endsWith(".scss"))
2510
+ return "scss";
2511
+ if (normalized === "sass" || normalized.endsWith(".sass"))
2512
+ return "sass";
2513
+ if (normalized === "less" || normalized.endsWith(".less"))
2514
+ return "less";
2515
+ return null;
2516
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), compileStyleSource = async (filePath, source, languageHint) => {
2517
+ const language = getStyleLanguage(languageHint ?? filePath);
2518
+ const contents = source ?? await readFile(filePath, "utf-8");
2519
+ if (language === "scss" || language === "sass") {
2520
+ let sass;
2521
+ try {
2522
+ sass = await importOptionalPeer("sass");
2523
+ } catch {
2524
+ throw missingDependencyError("sass", filePath);
2525
+ }
2526
+ const result = sass.compileString(contents, {
2527
+ loadPaths: [dirname2(filePath), process.cwd()],
2528
+ style: "expanded",
2529
+ syntax: language === "sass" ? "indented" : "scss",
2530
+ url: new URL(`file://${filePath}`)
2531
+ });
2532
+ return result.css;
2533
+ }
2534
+ if (language === "less") {
2535
+ let lessModule;
2536
+ try {
2537
+ lessModule = await importOptionalPeer("less");
2538
+ } catch {
2539
+ throw missingDependencyError("less", filePath);
2540
+ }
2541
+ const less = lessModule.render ? lessModule : lessModule.default;
2542
+ const render = less?.render;
2543
+ if (!render)
2544
+ throw missingDependencyError("less", filePath);
2545
+ const result = await render(contents, {
2546
+ filename: filePath,
2547
+ paths: [dirname2(filePath), process.cwd()]
2548
+ });
2549
+ return result.css;
2550
+ }
2551
+ return contents;
2552
+ }, stylePreprocessorPlugin, createSvelteStylePreprocessor = () => ({
2553
+ style: async ({
2554
+ attributes,
2555
+ content,
2556
+ filename
2557
+ }) => {
2558
+ const language = typeof attributes.lang === "string" ? attributes.lang : typeof attributes.type === "string" ? attributes.type.replace(/^text\//, "") : null;
2559
+ if (!language || !STYLE_LANGUAGE_PATTERN.test(language))
2560
+ return;
2561
+ const path = filename ?? `style.${language}`;
2562
+ return {
2563
+ code: await compileStyleSource(path, content, language)
2564
+ };
2565
+ }
2566
+ }), compileStyleFileIfNeeded = async (filePath) => {
2567
+ if (!isPreprocessableStylePath(filePath)) {
2568
+ return readFile(filePath, "utf-8");
2569
+ }
2570
+ return compileStyleSource(filePath);
2571
+ };
2572
+ var init_stylePreprocessor = __esm(() => {
2573
+ STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
2574
+ STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less)$/i;
2575
+ STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less)$/i;
2576
+ importOptionalPeer = new Function("specifier", "return import(specifier)");
2577
+ stylePreprocessorPlugin = {
2578
+ name: "absolute-style-preprocessor",
2579
+ setup(build) {
2580
+ const cssModuleSources = new Map;
2581
+ build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
2582
+ namespace: "absolute-style-module",
2583
+ path: path.slice("absolute-style-module:".length)
2584
+ }));
2585
+ build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
2586
+ const sourcePath = cssModuleSources.get(path);
2587
+ if (!sourcePath) {
2588
+ throw new Error(`Unable to resolve CSS module source for ${path}`);
2589
+ }
2590
+ return {
2591
+ contents: await compileStyleSource(sourcePath),
2592
+ loader: "css"
2593
+ };
2594
+ });
2595
+ build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
2596
+ if (isStyleModulePath(path)) {
2597
+ const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
2598
+ cssModuleSources.set(cssModulePath, path);
2599
+ return {
2600
+ contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
2601
+ loader: "js"
2602
+ };
2603
+ }
2604
+ return {
2605
+ contents: await compileStyleSource(path),
2606
+ loader: "css"
2607
+ };
2608
+ });
2609
+ }
2610
+ };
2611
+ });
2612
+
2504
2613
  // src/core/svelteServerModule.ts
2505
2614
  import { mkdir, readdir } from "fs/promises";
2506
- import { basename as basename2, dirname as dirname2, extname, join as join3, relative, resolve as resolve4 } from "path";
2615
+ import { basename as basename2, dirname as dirname3, extname as extname2, join as join3, relative, resolve as resolve4 } from "path";
2507
2616
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
2508
- const importPath = relative(dirname2(from), target).replace(/\\/g, "/");
2617
+ const importPath = relative(dirname3(from), target).replace(/\\/g, "/");
2509
2618
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
2510
2619
  }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
2511
2620
  for (const entry of entries) {
@@ -2551,7 +2660,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2551
2660
  if (!spec.startsWith(".")) {
2552
2661
  return null;
2553
2662
  }
2554
- const basePath = resolve4(dirname2(from), spec);
2663
+ const basePath = resolve4(dirname3(from), spec);
2555
2664
  const candidates = [
2556
2665
  basePath,
2557
2666
  `${basePath}.ts`,
@@ -2583,8 +2692,8 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2583
2692
  if (!spec.startsWith(".")) {
2584
2693
  return null;
2585
2694
  }
2586
- const explicitPath = resolve4(dirname2(from), spec);
2587
- if (extname(explicitPath) === ".svelte") {
2695
+ const explicitPath = resolve4(dirname3(from), spec);
2696
+ if (extname2(explicitPath) === ".svelte") {
2588
2697
  return explicitPath;
2589
2698
  }
2590
2699
  const candidate = `${explicitPath}.svelte`;
@@ -2612,7 +2721,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2612
2721
  const { compile, preprocess } = await import("svelte/compiler");
2613
2722
  const loweredAwaitSource = lowerSvelteAwaitSlotSyntax(source);
2614
2723
  const loweredSource = lowerSvelteIslandSyntax(loweredAwaitSource.code, "server");
2615
- const preprocessed = await preprocess(loweredSource.code, {});
2724
+ const preprocessed = await preprocess(loweredSource.code, createSvelteStylePreprocessor());
2616
2725
  let transpiled = sourcePath.endsWith(".ts") || sourcePath.endsWith(".svelte.ts") ? transpiler.transformSync(preprocessed.code) : preprocessed.code;
2617
2726
  const childImportSpecs = Array.from(transpiled.matchAll(/from\s+['"]([^'"]+)['"]/g)).map((match) => match[1]).filter((value) => value !== undefined);
2618
2727
  const resolvedChildModules = await Promise.all(childImportSpecs.map((spec) => resolveSvelteImport(spec, resolutionSourcePath)));
@@ -2662,7 +2771,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2662
2771
  compiledCode = compiledCode.replaceAll(spec, resolvedModuleImport);
2663
2772
  }
2664
2773
  const compiledModulePath = getCachedModulePath(sourcePath);
2665
- await mkdir(dirname2(compiledModulePath), { recursive: true });
2774
+ await mkdir(dirname3(compiledModulePath), { recursive: true });
2666
2775
  await writeIfChanged(compiledModulePath, compiledCode);
2667
2776
  compiledModuleCache.set(sourcePath, compiledModulePath);
2668
2777
  return compiledModulePath;
@@ -2671,6 +2780,7 @@ var init_svelteServerModule = __esm(() => {
2671
2780
  init_resolvePackageImport();
2672
2781
  init_lowerIslandSyntax();
2673
2782
  init_lowerAwaitSlotSyntax();
2783
+ init_stylePreprocessor();
2674
2784
  serverCacheRoot = join3(process.cwd(), ".absolutejs", "islands", "svelte");
2675
2785
  compiledModuleCache = new Map;
2676
2786
  originalSourcePathCache = new Map;
@@ -2975,5 +3085,5 @@ export {
2975
3085
  Island
2976
3086
  };
2977
3087
 
2978
- //# debugId=C805D3719B3596C964756E2164756E21
3088
+ //# debugId=1229492736870B8F64756E2164756E21
2979
3089
  //# sourceMappingURL=index.js.map