@ecopages/core 0.2.0-rc.7 → 0.2.0-rc.8

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.
Files changed (45) hide show
  1. package/package.json +27 -3
  2. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  3. package/src/adapters/bun/create-app.d.ts +4 -0
  4. package/src/adapters/bun/create-app.js +46 -31
  5. package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
  6. package/src/adapters/shared/runtime/server-adapter.js +9 -22
  7. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  8. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  9. package/src/eco/README.md +3 -1
  10. package/src/eco/lazy-injector-map.js +57 -41
  11. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  12. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  13. package/src/plugins/component-import-discovery.js +115 -77
  14. package/src/plugins/eco-component-meta-plugin.js +47 -30
  15. package/src/route-renderer/README.md +1 -0
  16. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  17. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  18. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  19. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +68 -0
  20. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +183 -0
  21. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +9 -0
  22. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +22 -0
  23. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  24. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  25. package/src/route-renderer/orchestration/integration-renderer.d.ts +3 -0
  26. package/src/route-renderer/orchestration/integration-renderer.js +31 -17
  27. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  28. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  29. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  30. package/src/route-renderer/page-loading/component-dependency-collection.js +95 -74
  31. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  32. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +0 -3
  33. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +37 -34
  34. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  35. package/src/router/README.md +2 -0
  36. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  37. package/src/services/module-loading/page-module-import.service.d.ts +6 -0
  38. package/src/services/module-loading/page-module-import.service.js +60 -27
  39. package/src/services/validation/schema-validation-service.d.ts +1 -0
  40. package/src/services/validation/schema-validation-service.js +23 -36
  41. package/src/static-site-generator/static-site-generator.d.ts +4 -0
  42. package/src/static-site-generator/static-site-generator.js +75 -48
  43. package/src/utils/parse-cli-args.js +29 -22
  44. package/src/watchers/project-watcher.d.ts +5 -0
  45. package/src/watchers/project-watcher.js +46 -32
@@ -30,6 +30,84 @@ function pushUniqueDependency(keys, key, dependencies, dependency) {
30
30
  function resolveDependencyPath(componentDir, pathUrl) {
31
31
  return path.isAbsolute(pathUrl) ? pathUrl : path.join(componentDir, pathUrl);
32
32
  }
33
+ function createLazyScriptRegistrar(config, lazyScriptsByConfig) {
34
+ return ({ lazy, lazyKey, fallbackUrl }) => {
35
+ let grouped = lazyScriptsByConfig.get(config);
36
+ if (!grouped) {
37
+ grouped = new Map();
38
+ lazyScriptsByConfig.set(config, grouped);
39
+ }
40
+ const triggerKey = getLazyTriggerKey(lazy);
41
+ const existing = grouped.get(triggerKey) ?? { lazy, scripts: [] };
42
+ existing.scripts.push({ lazyKey, fallbackUrl });
43
+ grouped.set(triggerKey, existing);
44
+ };
45
+ }
46
+ function recordExplicitAndInferredStyles(config, dir, context) {
47
+ const dependenciesConfig = config.dependencies;
48
+ const explicitStyles = dependenciesConfig?.stylesheets ?? [];
49
+ for (const style of explicitStyles) {
50
+ const src = typeof style === 'string' ? style : style.src;
51
+ if (src)
52
+ context.explicitStylePaths.add(resolveDependencyPath(dir, src));
53
+ }
54
+ for (const src of getInferredStylesheets(config)) {
55
+ context.inferredStyles.push({ dir, src });
56
+ }
57
+ return explicitStyles;
58
+ }
59
+ /**
60
+ * Recursively visits one component config and its declared child dependencies.
61
+ */
62
+ function collectComponentConfigDependencies(config, context) {
63
+ if (!config || context.visited.has(config))
64
+ return;
65
+ context.visited.add(config);
66
+ const file = getComponentIdentity(config)?.file;
67
+ if (!file)
68
+ return;
69
+ const dir = path.dirname(file);
70
+ const explicitStyles = recordExplicitAndInferredStyles(config, dir, context);
71
+ const dependenciesConfig = config.dependencies;
72
+ const registerLazyScript = createLazyScriptRegistrar(config, context.lazyScriptsByConfig);
73
+ collectDeclaredAssetEntries({
74
+ stylesheetEntries: explicitStyles,
75
+ scriptEntries: dependenciesConfig?.scripts ?? [],
76
+ componentDir: dir,
77
+ dependencies: context.dependencies,
78
+ stylesheetDependencyKeys: context.stylesheetDependencyKeys,
79
+ scriptDependencyKeys: context.scriptDependencyKeys,
80
+ resolveDependencyPath,
81
+ createModuleScriptAttributes,
82
+ pushUniqueDependency,
83
+ getInvalidStylesheetEntryMessage: () => context.errors.invalidStylesheetEntry,
84
+ getInvalidScriptEntryMessage: () => context.errors.invalidScriptEntry,
85
+ });
86
+ collectModuleDeclarations(context.modulesMap, dependenciesConfig?.modules, extractEcopagesVirtualImports(file));
87
+ collectLazyScriptEntries({
88
+ scriptEntries: dependenciesConfig?.scripts ?? [],
89
+ componentFile: file,
90
+ componentDir: dir,
91
+ integrationName: context.integrationName,
92
+ dependencies: context.dependencies,
93
+ lazyDependencyKeys: context.lazyDependencyKeys,
94
+ registerLazyScript,
95
+ resolveDependencyPath,
96
+ resolveLazyScripts: context.resolveLazyScripts,
97
+ createModuleScriptAttributes,
98
+ createEcopagesJsxLazyEntryName: context.createEcopagesJsxLazyEntryName,
99
+ pushUniqueDependency,
100
+ getLazyScriptMissingSrcMessage: () => context.errors.lazyScriptMissingSrc,
101
+ isEcopagesJsxIntegration: context.isEcopagesJsxIntegration,
102
+ });
103
+ for (const nestedComponent of dependenciesConfig?.components ?? []) {
104
+ if (!nestedComponent) {
105
+ continue;
106
+ }
107
+ assertEcoDeclaredComponent(nestedComponent, { parentComponentFile: file });
108
+ collectComponentConfigDependencies(nestedComponent.config, context);
109
+ }
110
+ }
33
111
  /**
34
112
  * Walks component dependency trees and collects declared assets, module declarations,
35
113
  * and lazy-script group metadata in one pass.
@@ -55,81 +133,24 @@ export function collectComponentDependencies(options) {
55
133
  const componentFile = getComponentIdentity(component)?.file;
56
134
  if (!componentFile)
57
135
  continue;
58
- const stylesheetDependencyKeys = new Set();
59
- const scriptDependencyKeys = new Set();
60
- const modulesMap = new Map();
61
- /**
62
- * Recursively visits one component config and its declared child dependencies.
63
- */
64
- const collect = (config) => {
65
- if (!config || visited.has(config))
66
- return;
67
- visited.add(config);
68
- const file = getComponentIdentity(config)?.file;
69
- if (!file)
70
- return;
71
- const dir = path.dirname(file);
72
- const dependenciesConfig = config.dependencies;
73
- const explicitStyles = dependenciesConfig?.stylesheets ?? [];
74
- for (const style of explicitStyles) {
75
- const src = typeof style === 'string' ? style : style.src;
76
- if (src)
77
- explicitStylePaths.add(resolveDependencyPath(dir, src));
78
- }
79
- for (const src of getInferredStylesheets(config))
80
- inferredStyles.push({ dir, src });
81
- const registerLazyScript = ({ lazy, lazyKey, fallbackUrl, }) => {
82
- let grouped = lazyScriptsByConfig.get(config);
83
- if (!grouped) {
84
- grouped = new Map();
85
- lazyScriptsByConfig.set(config, grouped);
86
- }
87
- const triggerKey = getLazyTriggerKey(lazy);
88
- const existing = grouped.get(triggerKey) ?? { lazy, scripts: [] };
89
- existing.scripts.push({ lazyKey, fallbackUrl });
90
- grouped.set(triggerKey, existing);
91
- };
92
- collectDeclaredAssetEntries({
93
- stylesheetEntries: explicitStyles,
94
- scriptEntries: dependenciesConfig?.scripts ?? [],
95
- componentDir: dir,
96
- dependencies,
97
- stylesheetDependencyKeys,
98
- scriptDependencyKeys,
99
- resolveDependencyPath,
100
- createModuleScriptAttributes,
101
- pushUniqueDependency,
102
- getInvalidStylesheetEntryMessage: () => errors.invalidStylesheetEntry,
103
- getInvalidScriptEntryMessage: () => errors.invalidScriptEntry,
104
- });
105
- collectModuleDeclarations(modulesMap, dependenciesConfig?.modules, extractEcopagesVirtualImports(file));
106
- collectLazyScriptEntries({
107
- scriptEntries: dependenciesConfig?.scripts ?? [],
108
- componentFile: file,
109
- componentDir: dir,
110
- integrationName,
111
- dependencies,
112
- lazyDependencyKeys,
113
- registerLazyScript,
114
- resolveDependencyPath,
115
- resolveLazyScripts,
116
- createModuleScriptAttributes,
117
- createEcopagesJsxLazyEntryName,
118
- pushUniqueDependency,
119
- getLazyScriptMissingSrcMessage: () => errors.lazyScriptMissingSrc,
120
- isEcopagesJsxIntegration,
121
- });
122
- if (dependenciesConfig?.components) {
123
- for (const nestedComponent of dependenciesConfig.components) {
124
- if (!nestedComponent) {
125
- continue;
126
- }
127
- assertEcoDeclaredComponent(nestedComponent, { parentComponentFile: file });
128
- collect(nestedComponent.config);
129
- }
130
- }
136
+ const collectionContext = {
137
+ integrationName,
138
+ resolveLazyScripts,
139
+ createEcopagesJsxLazyEntryName,
140
+ isEcopagesJsxIntegration,
141
+ errors,
142
+ dependencies,
143
+ lazyScriptsByConfig,
144
+ lazyDependencyKeys,
145
+ visited,
146
+ inferredStyles,
147
+ explicitStylePaths,
148
+ stylesheetDependencyKeys: new Set(),
149
+ scriptDependencyKeys: new Set(),
150
+ modulesMap: new Map(),
131
151
  };
132
- collect(component.config);
152
+ collectComponentConfigDependencies(component.config, collectionContext);
153
+ const { modulesMap } = collectionContext;
133
154
  dependencies.push(...Array.from(modulesMap.entries()).map(([from, importsSet]) => {
134
155
  const imports = importsSet ? Array.from(importsSet) : undefined;
135
156
  return AssetFactory.createContentScript({
@@ -4,6 +4,46 @@ import { parseModuleSource } from '../../cache/module-parse-cache.js';
4
4
  export function isBrowserEcopagesVirtualImport(specifier) {
5
5
  return specifier.startsWith('ecopages:') && !isContentServerVirtualModule(specifier);
6
6
  }
7
+ function getNamedImportFromSpecifier(spec) {
8
+ if (spec.type !== 'ImportSpecifier') {
9
+ return undefined;
10
+ }
11
+ let importedName = spec.local?.name;
12
+ if (spec.imported?.type === 'Identifier') {
13
+ importedName = spec.imported.name;
14
+ }
15
+ else if (spec.imported?.type === 'Literal') {
16
+ importedName = spec.imported.value;
17
+ }
18
+ return importedName;
19
+ }
20
+ function collectNamedImportsFromDeclaration(node) {
21
+ const namedImports = [];
22
+ for (const spec of node.specifiers ?? []) {
23
+ const importedName = getNamedImportFromSpecifier(spec);
24
+ if (importedName) {
25
+ namedImports.push(importedName);
26
+ }
27
+ }
28
+ return namedImports;
29
+ }
30
+ function recordVirtualImport(found, specifier, namedImports) {
31
+ if (found.get(specifier) === null) {
32
+ return;
33
+ }
34
+ if (namedImports.length === 0) {
35
+ found.set(specifier, null);
36
+ return;
37
+ }
38
+ const existing = found.get(specifier);
39
+ if (!existing) {
40
+ found.set(specifier, new Set(namedImports));
41
+ return;
42
+ }
43
+ for (const imported of namedImports) {
44
+ existing.add(imported);
45
+ }
46
+ }
7
47
  /**
8
48
  * Extracts runtime `ecopages:` virtual-module imports from a component source file.
9
49
  *
@@ -34,34 +74,7 @@ export function extractEcopagesVirtualImports(file) {
34
74
  const specifier = node.source?.value ?? '';
35
75
  if (!isBrowserEcopagesVirtualImport(specifier))
36
76
  continue;
37
- if (found.get(specifier) === null) {
38
- continue;
39
- }
40
- const namedImports = [];
41
- for (const spec of node.specifiers ?? []) {
42
- if (spec.type === 'ImportSpecifier') {
43
- let importedName = spec.local?.name;
44
- if (spec.imported?.type === 'Identifier') {
45
- importedName = spec.imported.name;
46
- }
47
- else if (spec.imported?.type === 'Literal') {
48
- importedName = spec.imported.value;
49
- }
50
- namedImports.push(importedName);
51
- }
52
- }
53
- if (namedImports.length === 0) {
54
- found.set(specifier, null);
55
- continue;
56
- }
57
- const existing = found.get(specifier);
58
- if (!existing) {
59
- found.set(specifier, new Set(namedImports));
60
- continue;
61
- }
62
- for (const imported of namedImports) {
63
- existing.add(imported);
64
- }
77
+ recordVirtualImport(found, specifier, collectNamedImportsFromDeclaration(node));
65
78
  }
66
79
  return Array.from(found.entries()).map(([from, importsSet]) => ({
67
80
  from,
@@ -34,9 +34,6 @@ export type CollectComponentConfigFilePathsOptions = {
34
34
  includeLayouts?: boolean;
35
35
  includeStylesheets?: boolean;
36
36
  };
37
- /**
38
- * Walks component configs and collects identity files, stylesheets, and discovered barrel hops.
39
- */
40
37
  export declare function collectComponentConfigFilePaths(components: ReadonlyArray<EcoComponent | Partial<EcoComponent> | undefined>, options?: CollectComponentConfigFilePathsOptions): Set<string>;
41
38
  /**
42
39
  * Collects source files that should invalidate a per-instance browser graph entry.
@@ -62,6 +62,42 @@ export function collectPageDependencyComponents(options) {
62
62
  /**
63
63
  * Walks component configs and collects identity files, stylesheets, and discovered barrel hops.
64
64
  */
65
+ function collectStylesheetPathsForConfig(config, resolvedOwnerFile, files) {
66
+ for (const style of config.dependencies?.stylesheets ?? []) {
67
+ const src = typeof style === 'string' ? style : style.src;
68
+ if (src)
69
+ files.add(path.resolve(path.dirname(resolvedOwnerFile), src));
70
+ }
71
+ for (const src of getInferredStylesheets(config)) {
72
+ files.add(path.resolve(path.dirname(resolvedOwnerFile), src));
73
+ }
74
+ }
75
+ function visitNestedComponentConfigFilePaths(config, options, visit) {
76
+ for (const dependency of config.dependencies?.components ?? []) {
77
+ visit(dependency?.config);
78
+ }
79
+ if (!options?.includeLayouts) {
80
+ return;
81
+ }
82
+ for (const layout of config.layouts ?? []) {
83
+ visit(layout?.config);
84
+ }
85
+ }
86
+ function visitComponentConfigFilePaths(config, options, files, visited, visit) {
87
+ const file = getComponentIdentity(config)?.file;
88
+ if (!file || !config || visited.has(config)) {
89
+ return;
90
+ }
91
+ visited.add(config);
92
+ files.add(path.resolve(file));
93
+ if (options?.includeStylesheets) {
94
+ collectStylesheetPathsForConfig(config, path.resolve(file), files);
95
+ }
96
+ for (const watchFile of getDiscoveredWatchFiles(config)) {
97
+ files.add(path.resolve(watchFile));
98
+ }
99
+ visitNestedComponentConfigFilePaths(config, options, visit);
100
+ }
65
101
  export function collectComponentConfigFilePaths(components, options) {
66
102
  const files = new Set();
67
103
  const visited = new Set();
@@ -69,40 +105,7 @@ export function collectComponentConfigFilePaths(components, options) {
69
105
  files.add(path.resolve(additionalPath));
70
106
  }
71
107
  const visit = (config) => {
72
- const file = getComponentIdentity(config)?.file;
73
- if (!file) {
74
- return;
75
- }
76
- if (!config) {
77
- return;
78
- }
79
- const resolved = path.resolve(file);
80
- if (visited.has(config)) {
81
- return;
82
- }
83
- visited.add(config);
84
- files.add(resolved);
85
- for (const style of options?.includeStylesheets ? (config.dependencies?.stylesheets ?? []) : []) {
86
- const src = typeof style === 'string' ? style : style.src;
87
- if (src)
88
- files.add(path.resolve(path.dirname(resolved), src));
89
- }
90
- if (options?.includeStylesheets) {
91
- for (const src of getInferredStylesheets(config)) {
92
- files.add(path.resolve(path.dirname(resolved), src));
93
- }
94
- }
95
- for (const watchFile of getDiscoveredWatchFiles(config)) {
96
- files.add(path.resolve(watchFile));
97
- }
98
- for (const dependency of config.dependencies?.components ?? []) {
99
- visit(dependency?.config);
100
- }
101
- if (options?.includeLayouts) {
102
- for (const layout of config.layouts ?? []) {
103
- visit(layout?.config);
104
- }
105
- }
108
+ visitComponentConfigFilePaths(config, options, files, visited, visit);
106
109
  };
107
110
  for (const component of components) {
108
111
  visit(component?.config);
@@ -127,25 +127,31 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
127
127
  bundleableScriptFilepaths: new Set(pageScriptImports),
128
128
  };
129
129
  }
130
+ function isBundledStylesheetDependency(dependency, plan) {
131
+ return (Boolean(plan.bundledStylesheet) &&
132
+ dependency.kind === 'stylesheet' &&
133
+ dependency.source === 'file' &&
134
+ plan.bundleableStyleFilepaths.has(dependency.filepath));
135
+ }
136
+ function isBundledScriptDependency(dependency, plan) {
137
+ return (Boolean(plan.bundledScript) &&
138
+ dependency.kind === 'script' &&
139
+ dependency.source === 'file' &&
140
+ plan.bundleableScriptFilepaths.has(dependency.filepath));
141
+ }
130
142
  function applyPageDependencyPackagingPlan(dependencies, plan) {
131
143
  const unifiedDependencies = [];
132
144
  let insertedStylesheet = false;
133
145
  let insertedScript = false;
134
146
  for (const dependency of dependencies) {
135
- if (plan.bundledStylesheet &&
136
- dependency.kind === 'stylesheet' &&
137
- dependency.source === 'file' &&
138
- plan.bundleableStyleFilepaths.has(dependency.filepath)) {
147
+ if (isBundledStylesheetDependency(dependency, plan)) {
139
148
  if (!insertedStylesheet) {
140
149
  unifiedDependencies.push(plan.bundledStylesheet);
141
150
  insertedStylesheet = true;
142
151
  }
143
152
  continue;
144
153
  }
145
- if (plan.bundledScript &&
146
- dependency.kind === 'script' &&
147
- dependency.source === 'file' &&
148
- plan.bundleableScriptFilepaths.has(dependency.filepath)) {
154
+ if (isBundledScriptDependency(dependency, plan)) {
149
155
  if (!insertedScript) {
150
156
  unifiedDependencies.push(plan.bundledScript);
151
157
  insertedScript = true;
@@ -114,6 +114,8 @@ import {
114
114
 
115
115
  This is separate from coordinator `subscribe()` events, which track runtime ownership rather than page lifecycle.
116
116
 
117
+ Scripts listening to client navigation events (`eco:after-swap`, `eco:page-load`) should be registered as client scripts (e.g., using `scripts: ['./component.script.ts']`) or guarded by `isServer` from `@ecopages/radiant/is-server` when used in Radiant projects where `document` is defined during SSR.
118
+
117
119
  ### Link Intent (`link-intent.ts`)
118
120
 
119
121
  Shared helpers for locating anchors and recovering stale navigation intent.
@@ -10,58 +10,61 @@ function getSuppressedSourceFilepaths(assets) {
10
10
  }
11
11
  return suppressed;
12
12
  }
13
+ function classifyProcessedAsset(asset, buckets) {
14
+ if (asset.inline) {
15
+ buckets.inlineAssets.push(asset);
16
+ return;
17
+ }
18
+ if (asset.packageRole === 'dynamic-chunk') {
19
+ buckets.dynamicChunks.push(asset);
20
+ return;
21
+ }
22
+ if (!buckets.pageScript && asset.packageRole === 'page-script') {
23
+ buckets.pageScript = asset;
24
+ return;
25
+ }
26
+ if (!buckets.pageStylesheet && asset.packageRole === 'page-style') {
27
+ buckets.pageStylesheet = asset;
28
+ return;
29
+ }
30
+ if (asset.packageRole === 'keep-separate' || asset.packageRole === 'runtime') {
31
+ buckets.separateAssets.push(asset);
32
+ return;
33
+ }
34
+ if (!buckets.pageScript && asset.kind === 'script' && !asset.excludeFromHtml) {
35
+ buckets.pageScript = asset;
36
+ return;
37
+ }
38
+ if (!buckets.pageStylesheet && asset.kind === 'stylesheet') {
39
+ buckets.pageStylesheet = asset;
40
+ return;
41
+ }
42
+ buckets.separateAssets.push(asset);
43
+ }
13
44
  export function createPagePackage(assets, options = {}) {
14
45
  const allAssets = [
15
46
  ...assets,
16
47
  ...(options.pageBrowserGraph?.entryAssets ?? []),
17
48
  ...(options.pageBrowserGraph?.chunkAssets ?? []),
18
49
  ];
19
- const inlineAssets = [];
20
- const separateAssets = [];
21
- const dynamicChunks = [];
22
- let pageScript;
23
- let pageStylesheet;
50
+ const buckets = {
51
+ inlineAssets: [],
52
+ separateAssets: [],
53
+ dynamicChunks: [],
54
+ };
24
55
  const suppressedSourceFilepaths = getSuppressedSourceFilepaths(allAssets);
25
56
  for (const asset of allAssets) {
26
- if (asset.inline) {
27
- inlineAssets.push(asset);
28
- continue;
29
- }
30
- if (asset.packageRole === 'dynamic-chunk') {
31
- dynamicChunks.push(asset);
32
- continue;
33
- }
34
- if (!pageScript && asset.packageRole === 'page-script') {
35
- pageScript = asset;
36
- continue;
37
- }
38
- if (!pageStylesheet && asset.packageRole === 'page-style') {
39
- pageStylesheet = asset;
40
- continue;
41
- }
42
- if (asset.packageRole === 'keep-separate' || asset.packageRole === 'runtime') {
43
- separateAssets.push(asset);
44
- continue;
45
- }
46
- if (!pageScript && asset.kind === 'script' && !asset.excludeFromHtml) {
47
- pageScript = asset;
48
- continue;
49
- }
50
- if (!pageStylesheet && asset.kind === 'stylesheet') {
51
- pageStylesheet = asset;
52
- continue;
53
- }
54
- separateAssets.push(asset);
57
+ classifyProcessedAsset(asset, buckets);
55
58
  }
56
59
  return {
57
60
  assets: allAssets,
58
61
  pageBrowserGraph: options.pageBrowserGraph,
59
62
  htmlAssets: allAssets.filter((asset) => shouldIncludeInHtml(asset, suppressedSourceFilepaths)),
60
- pageScript,
61
- pageStylesheet,
62
- inlineAssets,
63
- separateAssets,
64
- dynamicChunks,
63
+ pageScript: buckets.pageScript,
64
+ pageStylesheet: buckets.pageStylesheet,
65
+ inlineAssets: buckets.inlineAssets,
66
+ separateAssets: buckets.separateAssets,
67
+ dynamicChunks: buckets.dynamicChunks,
65
68
  };
66
69
  }
67
70
  function shouldIncludeInHtml(asset, suppressedSourceFilepaths) {
@@ -89,6 +89,12 @@ export declare class PageModuleImportService {
89
89
  * @returns The loaded module.
90
90
  */
91
91
  importModule<T = unknown>(options: PageModuleBuildImportOptions): Promise<T>;
92
+ private createRouteModuleBuildOptions;
93
+ private createRouteModuleCacheBuildOptions;
94
+ private tryLoadCachedRouteModuleBuild;
95
+ private tryLoadPagesUnifiedGraphModule;
96
+ private resolveCompiledRouteModuleOutput;
97
+ private importCompiledRouteModule;
92
98
  private loadModule;
93
99
  private getRouteModuleBuildCache;
94
100
  }
@@ -125,12 +125,8 @@ export class PageModuleImportService {
125
125
  fileHash,
126
126
  });
127
127
  }
128
- async loadModule(options) {
129
- const { filePath, fileHash, importCacheKey } = options;
130
- const { rootDir, outdir, splitting, externalPackages, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
131
- const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
132
- const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
133
- const preferredOutputPath = path.join(outdir, outputFileName);
128
+ createRouteModuleBuildOptions(options, outputNamingTemplate) {
129
+ const { filePath, rootDir, outdir, splitting, externalPackages } = options;
134
130
  const buildOptions = this.appConfig
135
131
  ? createServerBuildRequest(this.appConfig, {
136
132
  profile: 'route-module',
@@ -156,10 +152,17 @@ export class PageModuleImportService {
156
152
  root: rootDir,
157
153
  entrypoints: [filePath],
158
154
  };
159
- const cacheBuildOptions = {
160
- ...options,
155
+ return {
156
+ buildOptions,
161
157
  rootDir: buildOptions.root ?? rootDir,
162
158
  outdir: buildOptions.outdir ?? outdir,
159
+ };
160
+ }
161
+ createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash) {
162
+ return {
163
+ ...options,
164
+ rootDir: resolvedRootDir,
165
+ outdir: resolvedOutdir,
163
166
  splitting: buildOptions.splitting,
164
167
  externalPackages: buildOptions.externalPackages,
165
168
  jsx: buildOptions.jsx,
@@ -167,32 +170,36 @@ export class PageModuleImportService {
167
170
  sourceTransforms: buildOptions.sourceTransforms,
168
171
  fileHash,
169
172
  };
170
- const routeModuleBuildCache = this.getRouteModuleBuildCache(outdir);
171
- const cachedBuild = routeModuleBuildCache.lookup(cacheBuildOptions);
172
- if (cachedBuild) {
173
- const loadedModule = (await import(/* @vite-ignore */ pathToFileURL(cachedBuild.outputPath).href));
174
- recordPageModuleLoad('disk-cache-hit');
175
- return loadedModule;
173
+ }
174
+ async tryLoadCachedRouteModuleBuild(cacheBuildOptions, outdir) {
175
+ const cachedBuild = this.getRouteModuleBuildCache(outdir).lookup(cacheBuildOptions);
176
+ if (!cachedBuild) {
177
+ return undefined;
176
178
  }
177
- if (shouldBuildPagesUnifiedGraph() && this.appConfig && isPagesUnifiedGraphPage(filePath, this.appConfig)) {
178
- const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
179
- if (graphModule !== undefined) {
180
- recordPageModuleLoad('unified-graph');
181
- return graphModule;
182
- }
179
+ const loadedModule = (await import(/* @vite-ignore */ pathToFileURL(cachedBuild.outputPath).href));
180
+ recordPageModuleLoad('disk-cache-hit');
181
+ return loadedModule;
182
+ }
183
+ async tryLoadPagesUnifiedGraphModule(filePath) {
184
+ if (!shouldBuildPagesUnifiedGraph() || !this.appConfig || !isPagesUnifiedGraphPage(filePath, this.appConfig)) {
185
+ return undefined;
183
186
  }
184
- recordPageModuleBuildInvocation();
185
- const buildResult = await this.dependencies.buildModule(buildOptions, options.buildExecutor);
186
- recordPageModuleLoad('cold-build', buildResult.outputs.length);
187
- if (!buildResult.success) {
188
- const details = buildResult.logs.map((log) => log.message).join(' | ');
189
- throw new Error(transpileErrorMessage(details));
187
+ const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
188
+ if (graphModule === undefined) {
189
+ return undefined;
190
190
  }
191
+ recordPageModuleLoad('unified-graph');
192
+ return graphModule;
193
+ }
194
+ resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage) {
191
195
  const compiledOutput = buildResult.outputs.find((output) => output.path === preferredOutputPath)?.path ??
192
196
  buildResult.outputs.find((output) => /\.(?:[cm]?js)$/u.test(output.path))?.path;
193
197
  if (!compiledOutput) {
194
198
  throw new Error(noOutputMessage(filePath));
195
199
  }
200
+ return compiledOutput;
201
+ }
202
+ async importCompiledRouteModule(compiledOutput, filePath, fileHash, rootDir, buildResult, importCacheKey, cacheBuildOptions, outdir) {
196
203
  const dependencyModulePaths = resolveRouteModuleDependencyPaths(buildResult, filePath, rootDir);
197
204
  const dependencyHashes = this.dependencyHasher.createDependencyHashes(dependencyModulePaths);
198
205
  dependencyHashes[path.normalize(filePath)] = fileHash;
@@ -202,7 +209,7 @@ export class PageModuleImportService {
202
209
  cacheEntry.dependencyHashes = dependencyHashes;
203
210
  }
204
211
  }
205
- routeModuleBuildCache.recordBuild({
212
+ this.getRouteModuleBuildCache(outdir).recordBuild({
206
213
  ...cacheBuildOptions,
207
214
  outputPath: compiledOutput,
208
215
  dependencyModulePaths,
@@ -213,6 +220,32 @@ export class PageModuleImportService {
213
220
  }
214
221
  return (await import(/* @vite-ignore */ compiledOutputUrl.href));
215
222
  }
223
+ async loadModule(options) {
224
+ const { filePath, fileHash, importCacheKey } = options;
225
+ const { outdir, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
226
+ const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
227
+ const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
228
+ const preferredOutputPath = path.join(outdir, outputFileName);
229
+ const { buildOptions, rootDir: resolvedRootDir, outdir: resolvedOutdir, } = this.createRouteModuleBuildOptions(options, outputNamingTemplate);
230
+ const cacheBuildOptions = this.createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash);
231
+ const cachedModule = await this.tryLoadCachedRouteModuleBuild(cacheBuildOptions, resolvedOutdir);
232
+ if (cachedModule !== undefined) {
233
+ return cachedModule;
234
+ }
235
+ const unifiedGraphModule = await this.tryLoadPagesUnifiedGraphModule(filePath);
236
+ if (unifiedGraphModule !== undefined) {
237
+ return unifiedGraphModule;
238
+ }
239
+ recordPageModuleBuildInvocation();
240
+ const buildResult = await this.dependencies.buildModule(buildOptions, options.buildExecutor);
241
+ recordPageModuleLoad('cold-build', buildResult.outputs.length);
242
+ if (!buildResult.success) {
243
+ const details = buildResult.logs.map((log) => log.message).join(' | ');
244
+ throw new Error(transpileErrorMessage(details));
245
+ }
246
+ const compiledOutput = this.resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage);
247
+ return await this.importCompiledRouteModule(compiledOutput, filePath, fileHash, resolvedRootDir, buildResult, importCacheKey, cacheBuildOptions, resolvedOutdir);
248
+ }
216
249
  getRouteModuleBuildCache(outdir) {
217
250
  return getSharedRouteModuleBuildCache(outdir, this.appConfig);
218
251
  }
@@ -110,6 +110,7 @@ export declare class SchemaValidationService {
110
110
  * }
111
111
  * ```
112
112
  */
113
+ private validateRequestPart;
113
114
  validateRequest(source: ValidationSource, schemas: ValidationSchemas): Promise<ValidationResult<ValidatedData>>;
114
115
  /**
115
116
  * Validates a single value against a Standard Schema.