@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.
@@ -358,11 +358,120 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
358
358
  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;
359
359
  });
360
360
 
361
+ // src/build/stylePreprocessor.ts
362
+ import { readFile } from "fs/promises";
363
+ import { dirname, extname } from "path";
364
+ 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) => {
365
+ const normalized = filePathOrLanguage.toLowerCase();
366
+ if (normalized === "scss" || normalized.endsWith(".scss"))
367
+ return "scss";
368
+ if (normalized === "sass" || normalized.endsWith(".sass"))
369
+ return "sass";
370
+ if (normalized === "less" || normalized.endsWith(".less"))
371
+ return "less";
372
+ return null;
373
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), compileStyleSource = async (filePath, source, languageHint) => {
374
+ const language = getStyleLanguage(languageHint ?? filePath);
375
+ const contents = source ?? await readFile(filePath, "utf-8");
376
+ if (language === "scss" || language === "sass") {
377
+ let sass;
378
+ try {
379
+ sass = await importOptionalPeer("sass");
380
+ } catch {
381
+ throw missingDependencyError("sass", filePath);
382
+ }
383
+ const result = sass.compileString(contents, {
384
+ loadPaths: [dirname(filePath), process.cwd()],
385
+ style: "expanded",
386
+ syntax: language === "sass" ? "indented" : "scss",
387
+ url: new URL(`file://${filePath}`)
388
+ });
389
+ return result.css;
390
+ }
391
+ if (language === "less") {
392
+ let lessModule;
393
+ try {
394
+ lessModule = await importOptionalPeer("less");
395
+ } catch {
396
+ throw missingDependencyError("less", filePath);
397
+ }
398
+ const less = lessModule.render ? lessModule : lessModule.default;
399
+ const render = less?.render;
400
+ if (!render)
401
+ throw missingDependencyError("less", filePath);
402
+ const result = await render(contents, {
403
+ filename: filePath,
404
+ paths: [dirname(filePath), process.cwd()]
405
+ });
406
+ return result.css;
407
+ }
408
+ return contents;
409
+ }, stylePreprocessorPlugin, createSvelteStylePreprocessor = () => ({
410
+ style: async ({
411
+ attributes,
412
+ content,
413
+ filename
414
+ }) => {
415
+ const language = typeof attributes.lang === "string" ? attributes.lang : typeof attributes.type === "string" ? attributes.type.replace(/^text\//, "") : null;
416
+ if (!language || !STYLE_LANGUAGE_PATTERN.test(language))
417
+ return;
418
+ const path = filename ?? `style.${language}`;
419
+ return {
420
+ code: await compileStyleSource(path, content, language)
421
+ };
422
+ }
423
+ }), compileStyleFileIfNeeded = async (filePath) => {
424
+ if (!isPreprocessableStylePath(filePath)) {
425
+ return readFile(filePath, "utf-8");
426
+ }
427
+ return compileStyleSource(filePath);
428
+ };
429
+ var init_stylePreprocessor = __esm(() => {
430
+ STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
431
+ STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less)$/i;
432
+ STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less)$/i;
433
+ importOptionalPeer = new Function("specifier", "return import(specifier)");
434
+ stylePreprocessorPlugin = {
435
+ name: "absolute-style-preprocessor",
436
+ setup(build) {
437
+ const cssModuleSources = new Map;
438
+ build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
439
+ namespace: "absolute-style-module",
440
+ path: path.slice("absolute-style-module:".length)
441
+ }));
442
+ build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
443
+ const sourcePath = cssModuleSources.get(path);
444
+ if (!sourcePath) {
445
+ throw new Error(`Unable to resolve CSS module source for ${path}`);
446
+ }
447
+ return {
448
+ contents: await compileStyleSource(sourcePath),
449
+ loader: "css"
450
+ };
451
+ });
452
+ build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
453
+ if (isStyleModulePath(path)) {
454
+ const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
455
+ cssModuleSources.set(cssModulePath, path);
456
+ return {
457
+ contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
458
+ loader: "js"
459
+ };
460
+ }
461
+ return {
462
+ contents: await compileStyleSource(path),
463
+ loader: "css"
464
+ };
465
+ });
466
+ }
467
+ };
468
+ });
469
+
361
470
  // src/core/svelteServerModule.ts
362
471
  import { mkdir, readdir } from "fs/promises";
363
- import { basename, dirname, extname, join as join2, relative, resolve as resolve2 } from "path";
472
+ import { basename, dirname as dirname2, extname as extname2, join as join2, relative, resolve as resolve2 } from "path";
364
473
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
365
- const importPath = relative(dirname(from), target).replace(/\\/g, "/");
474
+ const importPath = relative(dirname2(from), target).replace(/\\/g, "/");
366
475
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
367
476
  }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
368
477
  for (const entry of entries) {
@@ -408,7 +517,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
408
517
  if (!spec.startsWith(".")) {
409
518
  return null;
410
519
  }
411
- const basePath = resolve2(dirname(from), spec);
520
+ const basePath = resolve2(dirname2(from), spec);
412
521
  const candidates = [
413
522
  basePath,
414
523
  `${basePath}.ts`,
@@ -440,8 +549,8 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
440
549
  if (!spec.startsWith(".")) {
441
550
  return null;
442
551
  }
443
- const explicitPath = resolve2(dirname(from), spec);
444
- if (extname(explicitPath) === ".svelte") {
552
+ const explicitPath = resolve2(dirname2(from), spec);
553
+ if (extname2(explicitPath) === ".svelte") {
445
554
  return explicitPath;
446
555
  }
447
556
  const candidate = `${explicitPath}.svelte`;
@@ -469,7 +578,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
469
578
  const { compile, preprocess } = await import("svelte/compiler");
470
579
  const loweredAwaitSource = lowerSvelteAwaitSlotSyntax(source);
471
580
  const loweredSource = lowerSvelteIslandSyntax(loweredAwaitSource.code, "server");
472
- const preprocessed = await preprocess(loweredSource.code, {});
581
+ const preprocessed = await preprocess(loweredSource.code, createSvelteStylePreprocessor());
473
582
  let transpiled = sourcePath.endsWith(".ts") || sourcePath.endsWith(".svelte.ts") ? transpiler.transformSync(preprocessed.code) : preprocessed.code;
474
583
  const childImportSpecs = Array.from(transpiled.matchAll(/from\s+['"]([^'"]+)['"]/g)).map((match) => match[1]).filter((value) => value !== undefined);
475
584
  const resolvedChildModules = await Promise.all(childImportSpecs.map((spec) => resolveSvelteImport(spec, resolutionSourcePath)));
@@ -519,7 +628,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
519
628
  compiledCode = compiledCode.replaceAll(spec, resolvedModuleImport);
520
629
  }
521
630
  const compiledModulePath = getCachedModulePath(sourcePath);
522
- await mkdir(dirname(compiledModulePath), { recursive: true });
631
+ await mkdir(dirname2(compiledModulePath), { recursive: true });
523
632
  await writeIfChanged(compiledModulePath, compiledCode);
524
633
  compiledModuleCache.set(sourcePath, compiledModulePath);
525
634
  return compiledModulePath;
@@ -528,6 +637,7 @@ var init_svelteServerModule = __esm(() => {
528
637
  init_resolvePackageImport();
529
638
  init_lowerIslandSyntax();
530
639
  init_lowerAwaitSlotSyntax();
640
+ init_stylePreprocessor();
531
641
  serverCacheRoot = join2(process.cwd(), ".absolutejs", "islands", "svelte");
532
642
  compiledModuleCache = new Map;
533
643
  originalSourcePathCache = new Map;
@@ -2174,5 +2284,5 @@ export {
2174
2284
  handleSveltePageRequest
2175
2285
  };
2176
2286
 
2177
- //# debugId=77CA5EACF46CA16F64756E2164756E21
2287
+ //# debugId=64AFD80FA876A91264756E2164756E21
2178
2288
  //# sourceMappingURL=server.js.map