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

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.
@@ -2502,10 +2502,9 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
2502
2502
  });
2503
2503
 
2504
2504
  // src/build/stylePreprocessor.ts
2505
- import { readFileSync as readFileSync3 } from "fs";
2506
2505
  import { readFile } from "fs/promises";
2507
2506
  import { createRequire } from "module";
2508
- import { dirname as dirname2, extname, join as join3 } from "path";
2507
+ import { dirname as dirname2, extname, join as join3, resolve as resolve4 } from "path";
2509
2508
  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) => {
2510
2509
  const normalized = filePathOrLanguage.toLowerCase();
2511
2510
  if (normalized === "scss" || normalized.endsWith(".scss"))
@@ -2515,24 +2514,29 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2515
2514
  if (normalized === "less" || normalized.endsWith(".less"))
2516
2515
  return "less";
2517
2516
  return null;
2518
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
2519
- try {
2520
- return requireFromCwd(specifier);
2521
- } catch {
2522
- return requireOptionalPeer(specifier);
2523
- }
2524
- }, compileStyleSource = async (filePath, source, languageHint) => {
2517
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
2518
+ dirname2(filePath),
2519
+ process.cwd(),
2520
+ ...paths.map((path) => resolve4(process.cwd(), path))
2521
+ ], getSassOptions = (config, language) => ({
2522
+ ...config?.sass ?? {},
2523
+ ...language === "scss" ? config?.scss ?? {} : {}
2524
+ }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
2525
+ ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
2525
2526
  const language = getStyleLanguage(languageHint ?? filePath);
2526
- const contents = source ?? await readFile(filePath, "utf-8");
2527
+ const rawContents = source ?? await readFile(filePath, "utf-8");
2527
2528
  if (language === "scss" || language === "sass") {
2529
+ const options = getSassOptions(config, language);
2530
+ const packageName = options.implementation ?? "sass";
2528
2531
  let sass;
2529
2532
  try {
2530
- sass = await importOptionalPeer("sass");
2533
+ sass = await importOptionalPeer(packageName);
2531
2534
  } catch {
2532
- throw missingDependencyError("sass", filePath);
2535
+ throw missingDependencyError(packageName, filePath);
2533
2536
  }
2537
+ const contents = withAdditionalData(rawContents, options.additionalData);
2534
2538
  const result = sass.compileString(contents, {
2535
- loadPaths: [dirname2(filePath), process.cwd()],
2539
+ loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
2536
2540
  style: "expanded",
2537
2541
  syntax: language === "sass" ? "indented" : "scss",
2538
2542
  url: new URL(`file://${filePath}`)
@@ -2540,6 +2544,7 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2540
2544
  return result.css;
2541
2545
  }
2542
2546
  if (language === "less") {
2547
+ const options = getLessOptions(config);
2543
2548
  let lessModule;
2544
2549
  try {
2545
2550
  lessModule = await importOptionalPeer("less");
@@ -2550,14 +2555,49 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2550
2555
  const render = less?.render;
2551
2556
  if (!render)
2552
2557
  throw missingDependencyError("less", filePath);
2558
+ const contents = withAdditionalData(rawContents, options.additionalData);
2553
2559
  const result = await render(contents, {
2560
+ ...options.options ?? {},
2554
2561
  filename: filePath,
2555
- paths: [dirname2(filePath), process.cwd()]
2562
+ paths: normalizeLoadPaths(filePath, options.paths)
2556
2563
  });
2557
2564
  return result.css;
2558
2565
  }
2559
- return contents;
2560
- }, stylePreprocessorPlugin, createSvelteStylePreprocessor = () => ({
2566
+ return rawContents;
2567
+ }, createStylePreprocessorPlugin = (config) => ({
2568
+ name: "absolute-style-preprocessor",
2569
+ setup(build) {
2570
+ const cssModuleSources = new Map;
2571
+ build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
2572
+ namespace: "absolute-style-module",
2573
+ path: path.slice("absolute-style-module:".length)
2574
+ }));
2575
+ build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
2576
+ const sourcePath = cssModuleSources.get(path);
2577
+ if (!sourcePath) {
2578
+ throw new Error(`Unable to resolve CSS module source for ${path}`);
2579
+ }
2580
+ return {
2581
+ contents: await compileStyleSource(sourcePath, undefined, undefined, config),
2582
+ loader: "css"
2583
+ };
2584
+ });
2585
+ build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
2586
+ if (isStyleModulePath(path)) {
2587
+ const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
2588
+ cssModuleSources.set(cssModulePath, path);
2589
+ return {
2590
+ contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
2591
+ loader: "js"
2592
+ };
2593
+ }
2594
+ return {
2595
+ contents: await compileStyleSource(path, undefined, undefined, config),
2596
+ loader: "css"
2597
+ };
2598
+ });
2599
+ }
2600
+ }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
2561
2601
  style: async ({
2562
2602
  attributes,
2563
2603
  content,
@@ -2568,35 +2608,14 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2568
2608
  return;
2569
2609
  const path = filename ?? `style.${language}`;
2570
2610
  return {
2571
- code: await compileStyleSource(path, content, language)
2611
+ code: await compileStyleSource(path, content, language, config)
2572
2612
  };
2573
2613
  }
2574
- }), compileStyleFileIfNeeded = async (filePath) => {
2614
+ }), compileStyleFileIfNeeded = async (filePath, config) => {
2575
2615
  if (!isPreprocessableStylePath(filePath)) {
2576
2616
  return readFile(filePath, "utf-8");
2577
2617
  }
2578
- return compileStyleSource(filePath);
2579
- }, compileStyleFileIfNeededSync = (filePath) => {
2580
- const contents = readFileSync3(filePath, "utf-8");
2581
- const language = getStyleLanguage(filePath);
2582
- if (language === "scss" || language === "sass") {
2583
- let sass;
2584
- try {
2585
- sass = requireOptionalPeerSync("sass");
2586
- } catch {
2587
- throw missingDependencyError("sass", filePath);
2588
- }
2589
- return sass.compileString(contents, {
2590
- loadPaths: [dirname2(filePath), process.cwd()],
2591
- style: "expanded",
2592
- syntax: language === "sass" ? "indented" : "scss",
2593
- url: new URL(`file://${filePath}`)
2594
- }).css;
2595
- }
2596
- if (language === "less") {
2597
- 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.`);
2598
- }
2599
- return contents;
2618
+ return compileStyleSource(filePath, undefined, undefined, config);
2600
2619
  };
2601
2620
  var init_stylePreprocessor = __esm(() => {
2602
2621
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
@@ -2605,45 +2624,12 @@ var init_stylePreprocessor = __esm(() => {
2605
2624
  importOptionalPeer = new Function("specifier", "return import(specifier)");
2606
2625
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
2607
2626
  requireFromCwd = createRequire(join3(process.cwd(), "package.json"));
2608
- stylePreprocessorPlugin = {
2609
- name: "absolute-style-preprocessor",
2610
- setup(build) {
2611
- const cssModuleSources = new Map;
2612
- build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
2613
- namespace: "absolute-style-module",
2614
- path: path.slice("absolute-style-module:".length)
2615
- }));
2616
- build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
2617
- const sourcePath = cssModuleSources.get(path);
2618
- if (!sourcePath) {
2619
- throw new Error(`Unable to resolve CSS module source for ${path}`);
2620
- }
2621
- return {
2622
- contents: await compileStyleSource(sourcePath),
2623
- loader: "css"
2624
- };
2625
- });
2626
- build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
2627
- if (isStyleModulePath(path)) {
2628
- const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
2629
- cssModuleSources.set(cssModulePath, path);
2630
- return {
2631
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
2632
- loader: "js"
2633
- };
2634
- }
2635
- return {
2636
- contents: await compileStyleSource(path),
2637
- loader: "css"
2638
- };
2639
- });
2640
- }
2641
- };
2627
+ stylePreprocessorPlugin = createStylePreprocessorPlugin();
2642
2628
  });
2643
2629
 
2644
2630
  // src/core/svelteServerModule.ts
2645
2631
  import { mkdir, readdir } from "fs/promises";
2646
- import { basename as basename2, dirname as dirname3, extname as extname2, join as join4, relative, resolve as resolve4 } from "path";
2632
+ import { basename as basename2, dirname as dirname3, extname as extname2, join as join4, relative, resolve as resolve5 } from "path";
2647
2633
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
2648
2634
  const importPath = relative(dirname3(from), target).replace(/\\/g, "/");
2649
2635
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
@@ -2691,7 +2677,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2691
2677
  if (!spec.startsWith(".")) {
2692
2678
  return null;
2693
2679
  }
2694
- const basePath = resolve4(dirname3(from), spec);
2680
+ const basePath = resolve5(dirname3(from), spec);
2695
2681
  const candidates = [
2696
2682
  basePath,
2697
2683
  `${basePath}.ts`,
@@ -2723,7 +2709,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2723
2709
  if (!spec.startsWith(".")) {
2724
2710
  return null;
2725
2711
  }
2726
- const explicitPath = resolve4(dirname3(from), spec);
2712
+ const explicitPath = resolve5(dirname3(from), spec);
2727
2713
  if (extname2(explicitPath) === ".svelte") {
2728
2714
  return explicitPath;
2729
2715
  }
@@ -3116,5 +3102,5 @@ export {
3116
3102
  Island
3117
3103
  };
3118
3104
 
3119
- //# debugId=3679375434F4FCA864756E2164756E21
3105
+ //# debugId=03F71698475F88C764756E2164756E21
3120
3106
  //# sourceMappingURL=index.js.map