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