@absolutejs/absolute 0.19.0-beta.1004 → 0.19.0-beta.1006

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.
@@ -1,4 +1,5 @@
1
1
  import type { SFCDescriptor } from '@vue/compiler-sfc';
2
+ import { type ParsedVueSpaRoute } from './parseVueSpaRoutes';
2
3
  import type { StylePreprocessorConfig } from '../../types/build';
3
4
  export type VueChangeType = 'style-only' | 'template-only' | 'script' | 'full';
4
5
  export declare const vueHmrMetadata: Map<string, {
@@ -17,4 +18,5 @@ export declare const compileVue: (entryPoints: string[], vueRootDir: string, isD
17
18
  vueCssPaths: string[];
18
19
  vueIndexPaths: string[];
19
20
  vueServerPaths: string[];
21
+ vueSpaRoutesBySource: Map<string, ParsedVueSpaRoute[]>;
20
22
  }>;
@@ -0,0 +1,20 @@
1
+ /** Extract SPA child routes from a Vue page's source.
2
+ *
3
+ * Looks for `export const routes = defineRoutes([ ... ])` and parses
4
+ * each entry's `{ path, component: () => import('./X.vue') }` shape
5
+ * into a `{ path, importPath }` pair. The result drives the per-route
6
+ * CSS side-manifest emitted in `core/build.ts` so the SSR handler can
7
+ * inline the matched child route's compiled CSS (see
8
+ * `utils/spaRouteCss.ts` for the runtime side).
9
+ *
10
+ * Regex-based on purpose: the supported shape is single-statement
11
+ * array-of-object-literals, which is the only form `defineRoutes` is
12
+ * documented to take. AST parsing would catch a few exotic edge cases
13
+ * but adds a dependency on every page compile; the failure mode of a
14
+ * miss is "child route CSS isn't inlined for that route", same as
15
+ * pre-feature behaviour, so a loose regex is the right trade-off. */
16
+ export type ParsedVueSpaRoute = {
17
+ path: string;
18
+ importPath: string;
19
+ };
20
+ export declare const parseVueSpaRoutes: (source: string) => ParsedVueSpaRoute[];
@@ -0,0 +1,4 @@
1
+ /** Resolve the matched SPA child route's compiled CSS for a request.
2
+ * Returns the CSS text (possibly empty) so the page handler can
3
+ * inline it alongside the parent page's own sibling CSS. */
4
+ export declare const resolveSpaChildCss: (siblingJsPath: string | undefined, requestUrl: string | undefined) => Promise<string>;
package/dist/vue/index.js CHANGED
@@ -2084,7 +2084,7 @@ __export(exports_stylePreprocessor, {
2084
2084
  });
2085
2085
  import { createHash } from "crypto";
2086
2086
  import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
2087
- import { readFile } from "fs/promises";
2087
+ import { readFile as readFile2 } from "fs/promises";
2088
2088
  import { createRequire } from "module";
2089
2089
  import {
2090
2090
  dirname as dirname3,
@@ -2353,7 +2353,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2353
2353
  }
2354
2354
  deps?.add(resolved);
2355
2355
  return {
2356
- contents: preprocessLoadedStyle(await readFile(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
2356
+ contents: preprocessLoadedStyle(await readFile2(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
2357
2357
  filename: resolved
2358
2358
  };
2359
2359
  };
@@ -2425,7 +2425,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2425
2425
  styleOutputHashes.delete(key);
2426
2426
  }, compileStyleSource = async (filePath, source, languageHint, config) => {
2427
2427
  const language = getStyleLanguage(languageHint ?? filePath);
2428
- const rawContents = source ?? await readFile(filePath, "utf-8");
2428
+ const rawContents = source ?? await readFile2(filePath, "utf-8");
2429
2429
  const deps = new Set;
2430
2430
  if (language === "scss" || language === "sass") {
2431
2431
  const options = getSassOptions(config, language);
@@ -2583,7 +2583,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2583
2583
  }
2584
2584
  const nextVisited = new Set(visited);
2585
2585
  nextVisited.add(fullPath);
2586
- const imported = await readFile(fullPath, "utf-8");
2586
+ const imported = await readFile2(fullPath, "utf-8");
2587
2587
  parts.push(await resolveCssImportsAsync(imported, dirname3(fullPath), nextVisited));
2588
2588
  cursor = end;
2589
2589
  }
@@ -2591,7 +2591,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2591
2591
  return parts.join("");
2592
2592
  }, compileStyleFileIfNeeded = async (filePath, config) => {
2593
2593
  if (!isPreprocessableStylePath(filePath)) {
2594
- const raw = await readFile(filePath, "utf-8");
2594
+ const raw = await readFile2(filePath, "utf-8");
2595
2595
  const processed = await runPostcss(raw, filePath, config);
2596
2596
  return resolveCssImportsAsync(processed, dirname3(filePath), new Set([filePath]));
2597
2597
  }
@@ -3649,6 +3649,82 @@ var injectInlineCss = (headTag, css) => {
3649
3649
  return headTag.replace("</head>", `${styleBlock}</head>`);
3650
3650
  };
3651
3651
 
3652
+ // src/utils/spaRouteCss.ts
3653
+ import { readFile } from "fs/promises";
3654
+ var sideManifestCache = new Map;
3655
+ var readSideManifest = async (sideManifestPath) => {
3656
+ const cached = sideManifestCache.get(sideManifestPath);
3657
+ if (cached !== undefined)
3658
+ return cached;
3659
+ try {
3660
+ const raw = await readFile(sideManifestPath, "utf-8");
3661
+ const parsed = JSON.parse(raw);
3662
+ const routes = Array.isArray(parsed) ? parsed : [];
3663
+ sideManifestCache.set(sideManifestPath, routes);
3664
+ return routes;
3665
+ } catch {
3666
+ sideManifestCache.set(sideManifestPath, []);
3667
+ return [];
3668
+ }
3669
+ };
3670
+ var compilePathToRegExp = (pattern) => {
3671
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
3672
+ const withParams = escaped.replace(/:([a-zA-Z_$][a-zA-Z0-9_$]*)/g, "[^/]+").replace(/\\\*/g, ".*");
3673
+ return new RegExp(`^${withParams}$`);
3674
+ };
3675
+ var routeMatchers = new Map;
3676
+ var matcherFor = (pattern) => {
3677
+ const cached = routeMatchers.get(pattern);
3678
+ if (cached !== undefined)
3679
+ return cached;
3680
+ const compiled = compilePathToRegExp(pattern);
3681
+ routeMatchers.set(pattern, compiled);
3682
+ return compiled;
3683
+ };
3684
+ var findMatchingRoute = (routes, pathname) => {
3685
+ for (const route of routes) {
3686
+ if (matcherFor(route.path).test(pathname))
3687
+ return route;
3688
+ }
3689
+ return null;
3690
+ };
3691
+ var childCssCache = new Map;
3692
+ var readChildCss = async (cssPath) => {
3693
+ if (!cssPath)
3694
+ return "";
3695
+ const cached = childCssCache.get(cssPath);
3696
+ if (cached !== undefined)
3697
+ return cached;
3698
+ try {
3699
+ const css = await readFile(cssPath, "utf-8");
3700
+ childCssCache.set(cssPath, css);
3701
+ return css;
3702
+ } catch {
3703
+ childCssCache.set(cssPath, "");
3704
+ return "";
3705
+ }
3706
+ };
3707
+ var resolveSpaChildCss = async (siblingJsPath, requestUrl) => {
3708
+ if (!siblingJsPath || !requestUrl)
3709
+ return "";
3710
+ const sideManifestPath = siblingJsPath.replace(/\.js$/, ".spa.json");
3711
+ if (sideManifestPath === siblingJsPath)
3712
+ return "";
3713
+ const routes = await readSideManifest(sideManifestPath);
3714
+ if (routes.length === 0)
3715
+ return "";
3716
+ let pathname;
3717
+ try {
3718
+ pathname = new URL(requestUrl).pathname;
3719
+ } catch {
3720
+ pathname = requestUrl.split("?")[0] ?? requestUrl;
3721
+ }
3722
+ const matched = findMatchingRoute(routes, pathname);
3723
+ if (!matched)
3724
+ return "";
3725
+ return readChildCss(matched.cssPath);
3726
+ };
3727
+
3652
3728
  // src/core/islandPageContext.ts
3653
3729
  init_constants();
3654
3730
  var BOOTSTRAP_MANIFEST_KEY = "BootstrapClient";
@@ -4329,8 +4405,11 @@ var handleVuePageRequest = async (input) => {
4329
4405
  const userHeadTag = input.headTag ?? "<head></head>";
4330
4406
  const resolvedOptions = input;
4331
4407
  const resolvedPagePath = input.pagePath;
4332
- const siblingCss = await readSiblingCss(resolvedPagePath);
4333
- const resolvedHeadTag = injectInlineCss(userHeadTag, siblingCss);
4408
+ const [siblingCss, spaChildCss] = await Promise.all([
4409
+ readSiblingCss(resolvedPagePath),
4410
+ resolveSpaChildCss(resolvedPagePath, input.request?.url)
4411
+ ]);
4412
+ const resolvedHeadTag = injectInlineCss(injectInlineCss(userHeadTag, siblingCss), spaChildCss);
4334
4413
  const maybeProps = input.props;
4335
4414
  const clientMode = input.client ?? "auto";
4336
4415
  const resolvedIndexPath = input.indexPath;
@@ -4824,5 +4903,5 @@ export {
4824
4903
  Image
4825
4904
  };
4826
4905
 
4827
- //# debugId=11F1676B8E6878B264756E2164756E21
4906
+ //# debugId=18CB27AA3E1D0B6F64756E2164756E21
4828
4907
  //# sourceMappingURL=index.js.map