@absolutejs/absolute 0.19.0-beta.782 → 0.19.0-beta.783

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.
@@ -262,11 +262,14 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
262
262
  var exports_stylePreprocessor = {};
263
263
  __export(exports_stylePreprocessor, {
264
264
  stylePreprocessorPlugin: () => stylePreprocessorPlugin,
265
+ recordStyleOutput: () => recordStyleOutput,
265
266
  isStylePath: () => isStylePath,
266
267
  isStyleModulePath: () => isStyleModulePath,
267
268
  isPreprocessableStylePath: () => isPreprocessableStylePath,
268
269
  getStyleBaseName: () => getStyleBaseName,
269
270
  getCssOutputExtension: () => getCssOutputExtension,
271
+ forgetStyleEntry: () => forgetStyleEntry,
272
+ findStyleEntriesImporting: () => findStyleEntriesImporting,
270
273
  createSvelteStylePreprocessor: () => createSvelteStylePreprocessor,
271
274
  createStyleTransformConfig: () => createStyleTransformConfig,
272
275
  createStylePreprocessorPlugin: () => createStylePreprocessorPlugin,
@@ -274,10 +277,18 @@ __export(exports_stylePreprocessor, {
274
277
  compileStyleFileIfNeededSync: () => compileStyleFileIfNeededSync,
275
278
  compileStyleFileIfNeeded: () => compileStyleFileIfNeeded
276
279
  });
280
+ import { createHash } from "crypto";
277
281
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
278
282
  import { readFile } from "fs/promises";
279
283
  import { createRequire } from "module";
280
- import { dirname, extname, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
284
+ import {
285
+ dirname,
286
+ extname,
287
+ isAbsolute,
288
+ join as join2,
289
+ relative,
290
+ resolve as resolve2
291
+ } from "path";
281
292
  import { fileURLToPath } from "url";
282
293
  var CSS_EXTENSION_PATTERN, 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|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
283
294
  const normalized = filePathOrLanguage.toLowerCase();
@@ -290,7 +301,22 @@ var CSS_EXTENSION_PATTERN, STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTE
290
301
  if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
291
302
  return "stylus";
292
303
  return null;
293
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
304
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), throwPreprocessorError = (error, filePath, language) => {
305
+ if (!(error instanceof Error)) {
306
+ throw new Error(`${language} compile failed in ${filePath}: ${String(error)}`);
307
+ }
308
+ const detail = error;
309
+ const sassLine = detail.span?.start?.line;
310
+ const sassCol = detail.span?.start?.column;
311
+ const line = detail.line ?? sassLine;
312
+ const column = detail.column ?? sassCol;
313
+ const location = typeof line === "number" ? `:${line}${typeof column === "number" ? `:${column}` : ""}` : "";
314
+ const message = detail.formatted ?? detail.message;
315
+ const wrapped = new Error(`${language} compile failed in ${filePath}${location}
316
+ ${message}`);
317
+ wrapped.cause = error;
318
+ throw wrapped;
319
+ }, requireOptionalPeerSync = (specifier) => {
294
320
  try {
295
321
  return requireFromCwd(specifier);
296
322
  } catch {
@@ -329,7 +355,10 @@ var CSS_EXTENSION_PATTERN, STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTE
329
355
  }, getAliasEntries = (config) => {
330
356
  const tsconfig = readTsconfigAliases();
331
357
  return {
332
- aliases: [...normalizeAliasEntries(config?.aliases), ...tsconfig.aliases],
358
+ aliases: [
359
+ ...normalizeAliasEntries(config?.aliases),
360
+ ...tsconfig.aliases
361
+ ],
333
362
  baseUrl: tsconfig.baseUrl
334
363
  };
335
364
  }, aliasPatternToRegExp = (pattern) => new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("(.+)")}$`), resolveAliasTargets = (specifier, config) => {
@@ -490,7 +519,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
490
519
  ...postcssConfig.options
491
520
  });
492
521
  return result.css;
493
- }, createSassImporter = (entryFile, loadPaths, language, config) => ({
522
+ }, createSassImporter = (entryFile, loadPaths, language, config, deps) => ({
494
523
  canonicalize(specifier, options) {
495
524
  const fromDirectory = options.containingUrl ? dirname(fileURLToPath(options.containingUrl)) : dirname(entryFile);
496
525
  const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
@@ -498,6 +527,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
498
527
  },
499
528
  load(canonicalUrl) {
500
529
  const filePath = fileURLToPath(canonicalUrl);
530
+ deps?.add(filePath);
501
531
  const fileLanguage = getStyleLanguage(filePath);
502
532
  if (fileLanguage !== "scss" && fileLanguage !== "sass" && fileLanguage !== null)
503
533
  return null;
@@ -506,7 +536,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
506
536
  syntax: filePath.endsWith(".sass") ? "indented" : "scss"
507
537
  };
508
538
  }
509
- }), createLessFileManager = (entryFile, loadPaths, config) => ({
539
+ }), createLessFileManager = (entryFile, loadPaths, config, deps) => ({
510
540
  install(less, pluginManager) {
511
541
  const baseManager = new less.FileManager;
512
542
  const manager = Object.create(baseManager);
@@ -516,6 +546,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
516
546
  if (!resolved) {
517
547
  throw new Error(`Unable to resolve Less import "${filename}"`);
518
548
  }
549
+ deps?.add(resolved);
519
550
  return {
520
551
  contents: preprocessLoadedStyle(await readFile(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
521
552
  filename: resolved
@@ -523,7 +554,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
523
554
  };
524
555
  pluginManager.addFileManager(manager);
525
556
  }
526
- }), renderStylus = async (contents, filePath, loadPaths, options) => {
557
+ }), renderStylus = async (contents, filePath, loadPaths, options, deps) => {
527
558
  let stylus;
528
559
  try {
529
560
  const stylusModule = await importOptionalPeer("stylus");
@@ -540,15 +571,51 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
540
571
  for (const path of loadPaths)
541
572
  renderer.include(path);
542
573
  renderer.render((error, css) => {
543
- if (error)
574
+ if (error) {
544
575
  reject(error);
545
- else
546
- resolveCss(css ?? "");
576
+ return;
577
+ }
578
+ if (deps) {
579
+ const stylusDeps = renderer.deps?.();
580
+ if (Array.isArray(stylusDeps)) {
581
+ for (const dep of stylusDeps)
582
+ deps.add(resolve2(dep));
583
+ }
584
+ }
585
+ resolveCss(css ?? "");
547
586
  });
548
587
  });
588
+ }, styleDependencyGraph, styleOutputHashes, recordStyleDeps = (entry, deps) => {
589
+ const key = resolve2(entry);
590
+ const stripped = new Set;
591
+ for (const dep of deps) {
592
+ const resolved = resolve2(dep);
593
+ if (resolved !== key)
594
+ stripped.add(resolved);
595
+ }
596
+ styleDependencyGraph.set(key, stripped);
597
+ }, findStyleEntriesImporting = (changedPath) => {
598
+ const target = resolve2(changedPath);
599
+ const importers = [];
600
+ for (const [entry, deps] of styleDependencyGraph) {
601
+ if (deps.has(target))
602
+ importers.push(entry);
603
+ }
604
+ return importers;
605
+ }, recordStyleOutput = (entry, css) => {
606
+ const key = resolve2(entry);
607
+ const hash = createHash("sha1").update(css).digest("hex");
608
+ const previous = styleOutputHashes.get(key);
609
+ styleOutputHashes.set(key, hash);
610
+ return previous !== hash;
611
+ }, forgetStyleEntry = (entry) => {
612
+ const key = resolve2(entry);
613
+ styleDependencyGraph.delete(key);
614
+ styleOutputHashes.delete(key);
549
615
  }, compileStyleSource = async (filePath, source, languageHint, config) => {
550
616
  const language = getStyleLanguage(languageHint ?? filePath);
551
617
  const rawContents = source ?? await readFile(filePath, "utf-8");
618
+ const deps = new Set;
552
619
  if (language === "scss" || language === "sass") {
553
620
  const options = getSassOptions(config, language);
554
621
  const packageName = options.implementation ?? "sass";
@@ -560,16 +627,22 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
560
627
  }
561
628
  const contents = withAdditionalData(rawContents, options.additionalData);
562
629
  const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
563
- const result = sass.compileString(contents, {
564
- importers: [
565
- createSassImporter(filePath, loadPaths, language, config)
566
- ],
567
- loadPaths,
568
- style: "expanded",
569
- syntax: language === "sass" ? "indented" : "scss",
570
- url: new URL(`file://${filePath}`)
571
- });
572
- return runPostcss(result.css, filePath, config);
630
+ try {
631
+ const result = sass.compileString(contents, {
632
+ importers: [
633
+ createSassImporter(filePath, loadPaths, language, config, deps)
634
+ ],
635
+ loadPaths,
636
+ style: "expanded",
637
+ syntax: language === "sass" ? "indented" : "scss",
638
+ url: new URL(`file://${filePath}`)
639
+ });
640
+ const css = await runPostcss(result.css, filePath, config);
641
+ recordStyleDeps(filePath, deps);
642
+ return css;
643
+ } catch (error) {
644
+ throwPreprocessorError(error, filePath, language);
645
+ }
573
646
  }
574
647
  if (language === "less") {
575
648
  const options = getLessOptions(config);
@@ -585,22 +658,34 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
585
658
  throw missingDependencyError("less", filePath);
586
659
  const contents = withAdditionalData(rawContents, options.additionalData);
587
660
  const loadPaths = normalizeLoadPaths(filePath, options.paths);
588
- const result = await render(contents, {
589
- ...options.options ?? {},
590
- filename: filePath,
591
- paths: loadPaths,
592
- plugins: [
593
- ...options.options?.plugins ?? [],
594
- createLessFileManager(filePath, loadPaths, config)
595
- ]
596
- });
597
- return runPostcss(result.css, filePath, config);
661
+ try {
662
+ const result = await render(contents, {
663
+ ...options.options ?? {},
664
+ filename: filePath,
665
+ paths: loadPaths,
666
+ plugins: [
667
+ ...options.options?.plugins ?? [],
668
+ createLessFileManager(filePath, loadPaths, config, deps)
669
+ ]
670
+ });
671
+ const css = await runPostcss(result.css, filePath, config);
672
+ recordStyleDeps(filePath, deps);
673
+ return css;
674
+ } catch (error) {
675
+ throwPreprocessorError(error, filePath, "less");
676
+ }
598
677
  }
599
678
  if (language === "stylus") {
600
679
  const options = getStylusOptions(config);
601
680
  const loadPaths = normalizeLoadPaths(filePath, options.paths);
602
681
  const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
603
- return runPostcss(await renderStylus(contents, filePath, loadPaths, options), filePath, config);
682
+ try {
683
+ const css = await runPostcss(await renderStylus(contents, filePath, loadPaths, options, deps), filePath, config);
684
+ recordStyleDeps(filePath, deps);
685
+ return css;
686
+ } catch (error) {
687
+ throwPreprocessorError(error, filePath, "stylus");
688
+ }
604
689
  }
605
690
  return runPostcss(rawContents, filePath, config);
606
691
  }, createStylePreprocessorPlugin = (config) => ({
@@ -705,6 +790,8 @@ var init_stylePreprocessor = __esm(() => {
705
790
  importOptionalPeer = new Function("specifier", "return import(specifier)");
706
791
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
707
792
  requireFromCwd = createRequire(join2(process.cwd(), "package.json"));
793
+ styleDependencyGraph = new Map;
794
+ styleOutputHashes = new Map;
708
795
  stylePreprocessorPlugin = createStylePreprocessorPlugin();
709
796
  });
710
797
 
@@ -2703,5 +2790,5 @@ export {
2703
2790
  handleSveltePageRequest
2704
2791
  };
2705
2792
 
2706
- //# debugId=70300BF82AE3E5E164756E2164756E21
2793
+ //# debugId=3515420C1B0C38FC64756E2164756E21
2707
2794
  //# sourceMappingURL=server.js.map