@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.
@@ -359,10 +359,9 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
359
359
  });
360
360
 
361
361
  // src/build/stylePreprocessor.ts
362
- import { readFileSync as readFileSync2 } from "fs";
363
362
  import { readFile } from "fs/promises";
364
363
  import { createRequire } from "module";
365
- import { dirname, extname, join as join2 } from "path";
364
+ import { dirname, extname, join as join2, resolve as resolve2 } from "path";
366
365
  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) => {
367
366
  const normalized = filePathOrLanguage.toLowerCase();
368
367
  if (normalized === "scss" || normalized.endsWith(".scss"))
@@ -372,24 +371,29 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
372
371
  if (normalized === "less" || normalized.endsWith(".less"))
373
372
  return "less";
374
373
  return null;
375
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
376
- try {
377
- return requireFromCwd(specifier);
378
- } catch {
379
- return requireOptionalPeer(specifier);
380
- }
381
- }, compileStyleSource = async (filePath, source, languageHint) => {
374
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
375
+ dirname(filePath),
376
+ process.cwd(),
377
+ ...paths.map((path) => resolve2(process.cwd(), path))
378
+ ], getSassOptions = (config, language) => ({
379
+ ...config?.sass ?? {},
380
+ ...language === "scss" ? config?.scss ?? {} : {}
381
+ }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
382
+ ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
382
383
  const language = getStyleLanguage(languageHint ?? filePath);
383
- const contents = source ?? await readFile(filePath, "utf-8");
384
+ const rawContents = source ?? await readFile(filePath, "utf-8");
384
385
  if (language === "scss" || language === "sass") {
386
+ const options = getSassOptions(config, language);
387
+ const packageName = options.implementation ?? "sass";
385
388
  let sass;
386
389
  try {
387
- sass = await importOptionalPeer("sass");
390
+ sass = await importOptionalPeer(packageName);
388
391
  } catch {
389
- throw missingDependencyError("sass", filePath);
392
+ throw missingDependencyError(packageName, filePath);
390
393
  }
394
+ const contents = withAdditionalData(rawContents, options.additionalData);
391
395
  const result = sass.compileString(contents, {
392
- loadPaths: [dirname(filePath), process.cwd()],
396
+ loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
393
397
  style: "expanded",
394
398
  syntax: language === "sass" ? "indented" : "scss",
395
399
  url: new URL(`file://${filePath}`)
@@ -397,6 +401,7 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
397
401
  return result.css;
398
402
  }
399
403
  if (language === "less") {
404
+ const options = getLessOptions(config);
400
405
  let lessModule;
401
406
  try {
402
407
  lessModule = await importOptionalPeer("less");
@@ -407,14 +412,49 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
407
412
  const render = less?.render;
408
413
  if (!render)
409
414
  throw missingDependencyError("less", filePath);
415
+ const contents = withAdditionalData(rawContents, options.additionalData);
410
416
  const result = await render(contents, {
417
+ ...options.options ?? {},
411
418
  filename: filePath,
412
- paths: [dirname(filePath), process.cwd()]
419
+ paths: normalizeLoadPaths(filePath, options.paths)
413
420
  });
414
421
  return result.css;
415
422
  }
416
- return contents;
417
- }, stylePreprocessorPlugin, createSvelteStylePreprocessor = () => ({
423
+ return rawContents;
424
+ }, createStylePreprocessorPlugin = (config) => ({
425
+ name: "absolute-style-preprocessor",
426
+ setup(build) {
427
+ const cssModuleSources = new Map;
428
+ build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
429
+ namespace: "absolute-style-module",
430
+ path: path.slice("absolute-style-module:".length)
431
+ }));
432
+ build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
433
+ const sourcePath = cssModuleSources.get(path);
434
+ if (!sourcePath) {
435
+ throw new Error(`Unable to resolve CSS module source for ${path}`);
436
+ }
437
+ return {
438
+ contents: await compileStyleSource(sourcePath, undefined, undefined, config),
439
+ loader: "css"
440
+ };
441
+ });
442
+ build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
443
+ if (isStyleModulePath(path)) {
444
+ const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
445
+ cssModuleSources.set(cssModulePath, path);
446
+ return {
447
+ contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
448
+ loader: "js"
449
+ };
450
+ }
451
+ return {
452
+ contents: await compileStyleSource(path, undefined, undefined, config),
453
+ loader: "css"
454
+ };
455
+ });
456
+ }
457
+ }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
418
458
  style: async ({
419
459
  attributes,
420
460
  content,
@@ -425,35 +465,14 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
425
465
  return;
426
466
  const path = filename ?? `style.${language}`;
427
467
  return {
428
- code: await compileStyleSource(path, content, language)
468
+ code: await compileStyleSource(path, content, language, config)
429
469
  };
430
470
  }
431
- }), compileStyleFileIfNeeded = async (filePath) => {
471
+ }), compileStyleFileIfNeeded = async (filePath, config) => {
432
472
  if (!isPreprocessableStylePath(filePath)) {
433
473
  return readFile(filePath, "utf-8");
434
474
  }
435
- return compileStyleSource(filePath);
436
- }, compileStyleFileIfNeededSync = (filePath) => {
437
- const contents = readFileSync2(filePath, "utf-8");
438
- const language = getStyleLanguage(filePath);
439
- if (language === "scss" || language === "sass") {
440
- let sass;
441
- try {
442
- sass = requireOptionalPeerSync("sass");
443
- } catch {
444
- throw missingDependencyError("sass", filePath);
445
- }
446
- return sass.compileString(contents, {
447
- loadPaths: [dirname(filePath), process.cwd()],
448
- style: "expanded",
449
- syntax: language === "sass" ? "indented" : "scss",
450
- url: new URL(`file://${filePath}`)
451
- }).css;
452
- }
453
- if (language === "less") {
454
- 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.`);
455
- }
456
- return contents;
475
+ return compileStyleSource(filePath, undefined, undefined, config);
457
476
  };
458
477
  var init_stylePreprocessor = __esm(() => {
459
478
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
@@ -462,45 +481,12 @@ var init_stylePreprocessor = __esm(() => {
462
481
  importOptionalPeer = new Function("specifier", "return import(specifier)");
463
482
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
464
483
  requireFromCwd = createRequire(join2(process.cwd(), "package.json"));
465
- stylePreprocessorPlugin = {
466
- name: "absolute-style-preprocessor",
467
- setup(build) {
468
- const cssModuleSources = new Map;
469
- build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
470
- namespace: "absolute-style-module",
471
- path: path.slice("absolute-style-module:".length)
472
- }));
473
- build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
474
- const sourcePath = cssModuleSources.get(path);
475
- if (!sourcePath) {
476
- throw new Error(`Unable to resolve CSS module source for ${path}`);
477
- }
478
- return {
479
- contents: await compileStyleSource(sourcePath),
480
- loader: "css"
481
- };
482
- });
483
- build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
484
- if (isStyleModulePath(path)) {
485
- const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
486
- cssModuleSources.set(cssModulePath, path);
487
- return {
488
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
489
- loader: "js"
490
- };
491
- }
492
- return {
493
- contents: await compileStyleSource(path),
494
- loader: "css"
495
- };
496
- });
497
- }
498
- };
484
+ stylePreprocessorPlugin = createStylePreprocessorPlugin();
499
485
  });
500
486
 
501
487
  // src/core/svelteServerModule.ts
502
488
  import { mkdir, readdir } from "fs/promises";
503
- import { basename, dirname as dirname2, extname as extname2, join as join3, relative, resolve as resolve2 } from "path";
489
+ import { basename, dirname as dirname2, extname as extname2, join as join3, relative, resolve as resolve3 } from "path";
504
490
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
505
491
  const importPath = relative(dirname2(from), target).replace(/\\/g, "/");
506
492
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
@@ -548,7 +534,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
548
534
  if (!spec.startsWith(".")) {
549
535
  return null;
550
536
  }
551
- const basePath = resolve2(dirname2(from), spec);
537
+ const basePath = resolve3(dirname2(from), spec);
552
538
  const candidates = [
553
539
  basePath,
554
540
  `${basePath}.ts`,
@@ -580,7 +566,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
580
566
  if (!spec.startsWith(".")) {
581
567
  return null;
582
568
  }
583
- const explicitPath = resolve2(dirname2(from), spec);
569
+ const explicitPath = resolve3(dirname2(from), spec);
584
570
  if (extname2(explicitPath) === ".svelte") {
585
571
  return explicitPath;
586
572
  }
@@ -2315,5 +2301,5 @@ export {
2315
2301
  handleSveltePageRequest
2316
2302
  };
2317
2303
 
2318
- //# debugId=0CB1A571273FA18364756E2164756E21
2304
+ //# debugId=D579D2698295FC9764756E2164756E21
2319
2305
  //# sourceMappingURL=server.js.map