@ecopages/core 0.8.0 → 0.9.0

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 (145) hide show
  1. package/README.md +2 -2
  2. package/package.json +14 -4
  3. package/src/adapters/node/create-app.d.ts +1 -1
  4. package/src/adapters/node/create-app.js +1 -1
  5. package/src/adapters/node/server-adapter.d.ts +1 -0
  6. package/src/adapters/node/server-adapter.js +4 -1
  7. package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
  8. package/src/adapters/shared/hmr/hmr-manager.js +8 -4
  9. package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
  10. package/src/adapters/shared/http/api-request-pipeline.js +16 -11
  11. package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
  12. package/src/adapters/shared/runtime/render-context.d.ts +2 -0
  13. package/src/adapters/shared/runtime/render-context.js +4 -0
  14. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
  15. package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
  16. package/src/adapters/shared/runtime/server-static-builder.js +4 -1
  17. package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
  18. package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
  19. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
  20. package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
  21. package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
  22. package/src/assets/app-browser-client-build.js +3 -0
  23. package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
  24. package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
  25. package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
  26. package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
  27. package/src/build/build-graph.d.ts +19 -2
  28. package/src/build/build-graph.js +19 -18
  29. package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
  30. package/src/build/cache/pages-unified-graph-build.js +14 -51
  31. package/src/build/cache/server-module-entries.d.ts +5 -9
  32. package/src/build/cache/server-module-entries.js +5 -58
  33. package/src/build/contracts/build-contracts.d.ts +15 -0
  34. package/src/build/contracts.d.ts +1 -1
  35. package/src/build/contracts.js +1 -1
  36. package/src/build/production-asset-ledger.d.ts +1 -1
  37. package/src/build/production-asset-ledger.js +4 -2
  38. package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
  39. package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
  40. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
  41. package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
  42. package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
  43. package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
  44. package/src/build/server/server-modules-manifest.d.ts +6 -1
  45. package/src/build/server/server-modules-manifest.js +10 -1
  46. package/src/build/server/view-reference.d.ts +9 -0
  47. package/src/build/server/view-reference.js +11 -0
  48. package/src/build.d.ts +2 -1
  49. package/src/build.js +2 -1
  50. package/src/cli.d.ts +14 -0
  51. package/src/cli.js +14 -0
  52. package/src/config/assembly/app-runtime.d.ts +13 -0
  53. package/src/config/assembly/app-runtime.js +2 -0
  54. package/src/config/assembly/finalize-config.js +13 -8
  55. package/src/config/internal-types.d.ts +0 -12
  56. package/src/config/resolve-eco-config-path.d.ts +2 -0
  57. package/src/config/resolve-eco-config-path.js +2 -1
  58. package/src/config/server-config-bundle.d.ts +0 -1
  59. package/src/config/server-config-bundle.js +1 -1
  60. package/src/config/user-config-types.d.ts +0 -12
  61. package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
  62. package/src/dev/invalidation/development-invalidation.service.js +1 -11
  63. package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
  64. package/src/eco/discovered-dependencies.d.ts +5 -0
  65. package/src/eco/discovered-dependencies.js +9 -0
  66. package/src/eco/eco.browser.js +5 -5
  67. package/src/eco/eco.js +24 -5
  68. package/src/eco/migration-docs.d.ts +7 -0
  69. package/src/eco/migration-docs.js +7 -0
  70. package/src/hmr/client/hmr-runtime.js +1 -1
  71. package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
  72. package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
  73. package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
  74. package/src/html/html-rewriter.d.ts +9 -7
  75. package/src/html/html-rewriter.js +26 -41
  76. package/src/html/html-transformer.service.d.ts +2 -2
  77. package/src/html/html-transformer.service.js +21 -15
  78. package/src/html-pages/html-page-module-scripts.js +2 -1
  79. package/src/html-pages/html-pages.plugin.d.ts +1 -1
  80. package/src/html-pages/html-pages.plugin.js +1 -1
  81. package/src/integration.d.ts +1 -1
  82. package/src/integration.js +1 -1
  83. package/src/islands/island-host.d.ts +16 -5
  84. package/src/islands/island-host.js +8 -1
  85. package/src/plugins/component-import-discovery.d.ts +14 -1
  86. package/src/plugins/component-import-discovery.js +36 -16
  87. package/src/plugins/eco-component-meta-plugin.d.ts +5 -0
  88. package/src/plugins/eco-component-meta-plugin.js +39 -22
  89. package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
  90. package/src/plugins/ecopages-virtual-imports.js +25 -0
  91. package/src/plugins/integration-plugin.d.ts +1 -1
  92. package/src/plugins/integration-plugin.js +1 -1
  93. package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
  94. package/src/plugins/tsconfig-import-resolver.js +7 -5
  95. package/src/route-renderer/error-pages/error-page-renderer.js +3 -2
  96. package/src/route-renderer/explicit-view-render-preparation.d.ts +10 -3
  97. package/src/route-renderer/explicit-view-render-preparation.js +14 -8
  98. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
  99. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
  100. package/src/route-renderer/orchestration/integration-renderer.d.ts +39 -10
  101. package/src/route-renderer/orchestration/integration-renderer.js +74 -38
  102. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +32 -11
  103. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +68 -61
  104. package/src/route-renderer/page-declaration.d.ts +25 -0
  105. package/src/route-renderer/page-declaration.js +39 -0
  106. package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
  107. package/src/route-renderer/page-loading/component-declarations.js +77 -0
  108. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
  109. package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
  110. package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
  111. package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
  112. package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
  113. package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
  114. package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
  115. package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
  116. package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
  117. package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
  118. package/src/route-renderer/page-loading/page-module-loader.d.ts +10 -11
  119. package/src/route-renderer/page-loading/page-module-loader.js +30 -30
  120. package/src/router/server/pages-dir.d.ts +7 -0
  121. package/src/router/server/pages-dir.js +7 -0
  122. package/src/router/server/route-registry.d.ts +22 -10
  123. package/src/router/server/route-registry.js +54 -23
  124. package/src/router/server/segment-path-matcher.d.ts +29 -5
  125. package/src/router/server/segment-path-matcher.js +22 -19
  126. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
  127. package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
  128. package/src/static-site-generator/static-site-generator.d.ts +17 -1
  129. package/src/static-site-generator/static-site-generator.js +46 -12
  130. package/src/types/contracts.d.ts +28 -28
  131. package/src/types/eco-api-types.d.ts +17 -12
  132. package/src/types/public-types.d.ts +1 -1
  133. package/src/utils/file-roles.d.ts +48 -0
  134. package/src/utils/file-roles.js +85 -0
  135. package/src/utils/node-builtin.d.ts +10 -0
  136. package/src/utils/node-builtin.js +13 -0
  137. package/src/watchers/project-watcher.js +2 -2
  138. package/src/build/contracts/server-only-specifier.d.ts +0 -8
  139. package/src/build/contracts/server-only-specifier.js +0 -11
  140. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
  141. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
  142. package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
  143. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
  144. package/src/utils/endpoint-file-extensions.d.ts +0 -11
  145. package/src/utils/endpoint-file-extensions.js +0 -13
@@ -2,11 +2,11 @@ import { path } from '@ecopages/file-system/path';
2
2
  import { resolveAssetProcessingIntegration } from '../../assets/asset-processing-service/asset-processing-integration.js';
3
3
  import { prepareAssetDependencies } from '../../assets/asset-processing-service/asset-processing.service.js';
4
4
  import { isBundleableScript } from '../../assets/asset-processing-service/bundleable-script.js';
5
- import { contentHash } from '../../utils/content-hash.js';
6
- import { isProductionRuntime } from '../../utils/runtime.js';
7
5
  import { AssetFactory } from '../../assets/asset-processing-service/index.js';
8
6
  import { buildResolvedLazyTriggers } from './lazy-trigger-planning.js';
9
7
  import { collectComponentDependencies } from './component-dependency-collection.js';
8
+ import { ComponentDeclarationStore } from './component-declarations.js';
9
+ import { getComponentOwner } from '../../eco/component-identity.js';
10
10
  import { packagePageDependencies } from './page-dependency-bundling.js';
11
11
  import { getStylesheetKinds } from '../../plugins/stylesheet-kinds.js';
12
12
  import { getResolvedLazyTriggers, setPendingLazyClientAssets, setResolvedLazyTriggers, } from '../../eco/component-internal-state.js';
@@ -32,36 +32,14 @@ function resolveLazyScripts(appConfig, componentDir, scripts) {
32
32
  return resolvedPaths.join(',');
33
33
  }
34
34
  const pendingLazyGroupsByConfig = new WeakMap();
35
- const MAX_PROCESSED_DEPENDENCY_CACHE_ENTRIES = 128;
36
- function copyProcessedAssets(assets) {
37
- return assets.map((asset) => {
38
- const copy = { ...asset };
39
- if (asset.attributes) {
40
- copy.attributes = { ...asset.attributes };
41
- }
42
- if (asset.groupedBundle) {
43
- copy.groupedBundle = { ...asset.groupedBundle };
44
- }
45
- if (asset.bundledSourceFilepaths) {
46
- copy.bundledSourceFilepaths = [...asset.bundledSourceFilepaths];
47
- }
48
- return copy;
49
- });
50
- }
51
35
  function isLazyClientScript(dep) {
52
36
  return dep.kind === 'script' && Boolean(dep.attributes?.['data-eco-lazy-key']);
53
37
  }
54
- function createEcopagesJsxLazyEntryName(integrationName, key) {
55
- return `ecopages-${integrationName}-lazy-${contentHash(key, 16)}`;
56
- }
57
38
  export class DependencyResolverService {
58
39
  appConfig;
59
40
  assetProcessingService;
60
41
  assetProcessingIntegration;
61
- shouldCacheProcessedDependencies;
62
- processedDependenciesCache = new Map();
63
- componentCacheIds = new WeakMap();
64
- nextComponentCacheId = 0;
42
+ declarations;
65
43
  getAssetProcessingIntegration(name) {
66
44
  return resolveAssetProcessingIntegration(name, this.assetProcessingIntegration, this.appConfig.integrations);
67
45
  }
@@ -73,11 +51,19 @@ export class DependencyResolverService {
73
51
  * dependency collection, lazy trigger grouping, and processed-asset generation
74
52
  * can evolve without changing renderer implementations.
75
53
  */
76
- constructor(appConfig, assetProcessingService, shouldCacheProcessedDependencies = isProductionRuntime, assetProcessingIntegration) {
54
+ constructor(appConfig, assetProcessingService, assetProcessingIntegration) {
77
55
  this.appConfig = appConfig;
78
56
  this.assetProcessingService = assetProcessingService;
79
- this.shouldCacheProcessedDependencies = shouldCacheProcessedDependencies;
80
57
  this.assetProcessingIntegration = assetProcessingIntegration;
58
+ this.declarations = new ComponentDeclarationStore({
59
+ rootDir: appConfig.rootDir,
60
+ resolveLazyScripts: (componentDir, scripts) => this.resolveLazyScripts(componentDir, scripts),
61
+ errors: {
62
+ invalidStylesheetEntry: DEPENDENCY_ERRORS.INVALID_STYLESHEET_ENTRY,
63
+ invalidScriptEntry: DEPENDENCY_ERRORS.INVALID_SCRIPT_ENTRY,
64
+ lazyScriptMissingSrc: DEPENDENCY_ERRORS.LAZY_SCRIPT_MISSING_SRC,
65
+ },
66
+ });
81
67
  }
82
68
  /**
83
69
  * Resolves one dependency path relative to the component that declared it.
@@ -106,9 +92,13 @@ export class DependencyResolverService {
106
92
  }
107
93
  /**
108
94
  * Processes dependencies from a component list that already came from a prepared graph walk.
95
+ *
96
+ * @remarks
97
+ * With `declarationOrder`, the result follows the order of the collected dependencies, as the asset ledger
98
+ * records them (see {@link AssetProcessingService.processDependenciesInDeclarationOrder}).
109
99
  */
110
- async processPreparedComponentDependencies(components, integrationName) {
111
- return this.processPreparedDependencies(components, integrationName, true);
100
+ async processPreparedComponentDependencies(components, integrationName, declarationOrder = false) {
101
+ return this.processPreparedDependencies(components, integrationName, true, declarationOrder);
112
102
  }
113
103
  /**
114
104
  * Returns the scripts that processing `components` would bundle, without processing anything.
@@ -118,7 +108,7 @@ export class DependencyResolverService {
118
108
  * up in `AppRuntime.processedAssets`. The production prebuild hands them to the app-wide browser build.
119
109
  */
120
110
  collectBundleableScripts(components, integrationName, skipNestedComponents) {
121
- const { dependencies } = this.collectDependencies(components, integrationName, false, skipNestedComponents);
111
+ const { dependencies } = this.collectDependencies(components, integrationName, skipNestedComponents);
122
112
  const eagerDeps = this.packageDependencies(dependencies, integrationName).filter((dep) => !isLazyClientScript(dep));
123
113
  return prepareAssetDependencies(eagerDeps, this.getAssetProcessingIntegration(integrationName), this.appConfig.rootDir).filter(isBundleableScript);
124
114
  }
@@ -129,50 +119,30 @@ export class DependencyResolverService {
129
119
  packageDependencies(dependencies, integrationName) {
130
120
  return packagePageDependencies(dependencies, integrationName, this.bundlesPageDependencies(integrationName), this.appConfig.rootDir, getStylesheetKinds(this.appConfig));
131
121
  }
132
- /** Collects lazy client entries from prepared graph nodes without processing eager assets. */
122
+ /**
123
+ * Collects lazy client entries from prepared graph nodes without processing eager assets.
124
+ *
125
+ * @remarks Nodes without lazy scripts hold no lazy entries, so a list without any is not collected.
126
+ */
133
127
  prepareLazyClientDependencies(components, integrationName) {
134
- const { dependencies, lazyScriptsByConfig } = this.collectDependencies(components, integrationName, false, true);
128
+ const declaresLazyScripts = components.some((component) => component?.config && (this.declarations.get(component.config)?.lazyScripts.length ?? 0) > 0);
129
+ if (!declaresLazyScripts)
130
+ return [];
131
+ const { dependencies, lazyScriptsByConfig } = this.collectDependencies(components, integrationName, true);
135
132
  const lazyDependencies = dependencies.filter(isLazyClientScript);
136
133
  this.storePendingLazyClientDependencies(lazyScriptsByConfig, lazyDependencies);
137
134
  return lazyDependencies;
138
135
  }
139
- async processPreparedDependencies(components, integrationName, skipNestedComponents) {
140
- const { dependencies, lazyScriptsByConfig } = this.collectDependencies(components, integrationName, false, skipNestedComponents);
136
+ async processPreparedDependencies(components, integrationName, skipNestedComponents, declarationOrder = false) {
137
+ const { dependencies, lazyScriptsByConfig } = this.collectDependencies(components, integrationName, skipNestedComponents);
141
138
  const packagedDependencies = this.packageDependencies(dependencies, integrationName);
142
139
  const lazyDeps = packagedDependencies.filter(isLazyClientScript);
143
140
  const eagerDeps = packagedDependencies.filter((dep) => !isLazyClientScript(dep));
144
141
  this.storePendingLazyClientDependencies(lazyScriptsByConfig, lazyDeps);
145
- if (!this.shouldCacheProcessedDependencies()) {
146
- return this.assetProcessingService.processDependencies(eagerDeps, this.getAssetProcessingIntegration(integrationName));
147
- }
148
- const cacheKey = this.getProcessedDependenciesCacheKey(components, integrationName, skipNestedComponents, this.bundlesPageDependencies(integrationName));
149
- if (!cacheKey) {
150
- return this.assetProcessingService.processDependencies(eagerDeps, this.getAssetProcessingIntegration(integrationName));
151
- }
152
- let pending = this.processedDependenciesCache.get(cacheKey);
153
- if (pending) {
154
- this.processedDependenciesCache.delete(cacheKey);
155
- this.processedDependenciesCache.set(cacheKey, pending);
156
- }
157
- else {
158
- pending = this.assetProcessingService.processDependencies(eagerDeps, this.getAssetProcessingIntegration(integrationName));
159
- this.processedDependenciesCache.set(cacheKey, pending);
160
- if (this.processedDependenciesCache.size > MAX_PROCESSED_DEPENDENCY_CACHE_ENTRIES) {
161
- const oldestKey = this.processedDependenciesCache.keys().next().value;
162
- if (oldestKey !== undefined) {
163
- this.processedDependenciesCache.delete(oldestKey);
164
- }
165
- }
166
- }
167
- try {
168
- return copyProcessedAssets(await pending);
169
- }
170
- catch (error) {
171
- if (this.processedDependenciesCache.get(cacheKey) === pending) {
172
- this.processedDependenciesCache.delete(cacheKey);
173
- }
174
- throw error;
175
- }
142
+ const integration = this.getAssetProcessingIntegration(integrationName);
143
+ return declarationOrder
144
+ ? this.assetProcessingService.processDependenciesInDeclarationOrder(eagerDeps, integration)
145
+ : this.assetProcessingService.processDependencies(eagerDeps, integration);
176
146
  }
177
147
  storePendingLazyClientDependencies(lazyScriptsByConfig, lazyDependencies) {
178
148
  for (const [config, lazyGroupsMap] of lazyScriptsByConfig) {
@@ -184,26 +154,6 @@ export class DependencyResolverService {
184
154
  }));
185
155
  }
186
156
  }
187
- getProcessedDependenciesCacheKey(components, integrationName, skipNestedComponents, bundlesPageDependencies) {
188
- const componentIds = [];
189
- for (const component of components) {
190
- if (!component) {
191
- continue;
192
- }
193
- if (typeof component.resolveDependencies ===
194
- 'function') {
195
- return undefined;
196
- }
197
- const cacheIdentity = component.config ?? component;
198
- let componentId = this.componentCacheIds.get(cacheIdentity);
199
- if (componentId === undefined) {
200
- componentId = ++this.nextComponentCacheId;
201
- this.componentCacheIds.set(cacheIdentity, componentId);
202
- }
203
- componentIds.push(componentId);
204
- }
205
- return JSON.stringify([integrationName, skipNestedComponents, bundlesPageDependencies, componentIds]);
206
- }
207
157
  /**
208
158
  * Resolves pending lazy triggers from processed grouped-build URLs.
209
159
  *
@@ -256,25 +206,34 @@ export class DependencyResolverService {
256
206
  return triggers;
257
207
  }
258
208
  /**
259
- * Collects the unprocessed asset declarations of `components`, excluding Foreign Children and their descendants.
209
+ * Whether `component` ships a browser script of its own, which makes its render an Island Host.
210
+ *
211
+ * @remarks
212
+ * It reads the declarations of the component and of its nested components of the same Integration, excluding
213
+ * Foreign Children: a component without scripts that wraps an island is not an island itself.
260
214
  */
261
- collectOwnComponentDependencies(components, integrationName) {
262
- return this.collectDependencies(components, integrationName, true).dependencies;
263
- }
264
- collectDependencies(components, integrationName, excludeForeignChildren, skipNestedComponents = false) {
215
+ componentShipsScript(component, integrationName) {
216
+ const visited = new Set();
217
+ const shipsScript = (config, isRoot) => {
218
+ if (!config || visited.has(config))
219
+ return false;
220
+ visited.add(config);
221
+ if (!isRoot && getComponentOwner(config, integrationName) !== integrationName)
222
+ return false;
223
+ const declarations = this.declarations.get(config);
224
+ if (!declarations)
225
+ return false;
226
+ return (declarations.declaresScript ||
227
+ (config.dependencies?.components ?? []).some((child) => shipsScript(child?.config, false)));
228
+ };
229
+ return shipsScript(component.config, true);
230
+ }
231
+ collectDependencies(components, integrationName, skipNestedComponents = false) {
265
232
  return collectComponentDependencies({
266
233
  components,
267
234
  integrationName,
268
- rootDir: this.appConfig.rootDir,
269
- excludeForeignChildren,
235
+ declarations: this.declarations,
270
236
  skipNestedComponents,
271
- resolveLazyScripts: (componentDir, scripts) => this.resolveLazyScripts(componentDir, scripts),
272
- createEcopagesJsxLazyEntryName,
273
- errors: {
274
- invalidStylesheetEntry: DEPENDENCY_ERRORS.INVALID_STYLESHEET_ENTRY,
275
- invalidScriptEntry: DEPENDENCY_ERRORS.INVALID_SCRIPT_ENTRY,
276
- lazyScriptMissingSrc: DEPENDENCY_ERRORS.LAZY_SCRIPT_MISSING_SRC,
277
- },
278
237
  });
279
238
  }
280
239
  }
@@ -4,46 +4,39 @@ type LazyScriptRef = {
4
4
  lazyKey: string;
5
5
  fallbackUrl?: string;
6
6
  };
7
- /**
8
- * Lazy scripts grouped by one trigger declaration.
9
- */
7
+ /** The lazy scripts of one component that share a trigger. */
10
8
  export type LazyGroup = {
11
9
  lazy: DependencyLazyTrigger;
12
10
  scripts: LazyScriptRef[];
13
11
  };
14
12
  /**
15
- * Callback used to record one normalized lazy-script registration.
13
+ * One lazy script a component declares.
14
+ *
15
+ * @remarks
16
+ * Its client entry is named for the Integration that owns the component, which collection supplies, so the
17
+ * entry is created then from `entryHash`.
16
18
  */
17
- export type RegisterLazyScript = (input: {
19
+ export type DeclaredLazyScript = LazyScriptRef & {
18
20
  lazy: DependencyLazyTrigger;
19
- lazyKey: string;
20
- fallbackUrl?: string;
21
- }) => void;
22
- type CollectLazyEntriesOptions = {
21
+ /** Dedupes the entry within a collection pass. */
22
+ key: string;
23
+ entryHash: string;
24
+ createAsset(entryName: string): AssetDefinition;
25
+ };
26
+ type DeclareLazyScriptEntriesOptions = {
23
27
  scriptEntries: Array<string | EcoComponentScriptEntry>;
24
- /**
25
- * The app root. Lazy keys and entry names hash paths relative to it, so they match between the build and a
26
- * moved `ecopages start`.
27
- */
28
28
  rootDir: string;
29
29
  componentFile: string;
30
30
  componentDir: string;
31
- integrationName: string;
32
- dependencies: AssetDefinition[];
33
- lazyDependencyKeys: Set<string>;
34
- registerLazyScript: RegisterLazyScript;
35
- resolveDependencyPath: (componentDir: string, pathUrl: string) => string;
36
31
  resolveLazyScripts: (componentDir: string, scripts: string[]) => string;
37
- createModuleScriptAttributes: (attributes?: Record<string, string>) => Record<string, string>;
38
- createEcopagesJsxLazyEntryName: (integrationName: string, key: string) => string;
39
- pushUniqueDependency: (keys: Set<string>, key: string, dependencies: AssetDefinition[], dependency: AssetDefinition) => boolean;
40
- getLazyScriptMissingSrcMessage: () => string;
32
+ lazyScriptMissingSrcMessage: string;
41
33
  };
42
34
  /**
43
- * Collects lazy script dependency entries and emits their hidden bundle inputs.
35
+ * Normalizes a component's lazy script declarations into hidden app browser client entries.
44
36
  *
45
- * This helper also reports the trigger-to-script relationship back to the caller so
46
- * later stages can build the lazy-trigger manifest without reparsing dependency config.
37
+ * @remarks
38
+ * Each entry carries a `data-eco-lazy-key`, from the component file and its content or from the source and its
39
+ * trigger, so it does not depend on declaration order.
47
40
  */
48
- export declare function collectLazyScriptEntries(options: CollectLazyEntriesOptions): void;
41
+ export declare function declareLazyScriptEntries(options: DeclareLazyScriptEntriesOptions): DeclaredLazyScript[];
49
42
  export {};
@@ -2,75 +2,64 @@ import { APP_BROWSER_CLIENT_BUNDLE_ID, AssetFactory, createAppBrowserClientEntry
2
2
  import { contentHash } from '../../utils/content-hash.js';
3
3
  import { toRootRelativePath } from '../../utils/root-relative-path.js';
4
4
  import { getLazyTriggerKey } from './lazy-trigger-planning.js';
5
- function isDependencyEntryObject(entry) {
6
- return typeof entry === 'object' && entry !== null;
5
+ import { createModuleScriptAttributes, resolveDeclaredPath } from './declared-asset-collection.js';
6
+ function declareContentLazyScript(entry, index, options) {
7
+ const { lazy, content, attributes } = entry;
8
+ const lazyKey = `lazy:${contentHash(`${toRootRelativePath(options.rootDir, options.componentFile)}:entry:${index}:${content}`, 16)}`;
9
+ const key = `lazy:entry:content:${getLazyTriggerKey(lazy)}:${content}:${JSON.stringify(attributes ?? {})}`;
10
+ return {
11
+ lazy,
12
+ lazyKey,
13
+ key,
14
+ entryHash: contentHash(key, 16),
15
+ createAsset: (entryName) => AssetFactory.createContentScript({
16
+ position: 'head',
17
+ name: entryName,
18
+ content,
19
+ excludeFromHtml: true,
20
+ bundle: true,
21
+ groupedBundle: { id: APP_BROWSER_CLIENT_BUNDLE_ID, entryName },
22
+ attributes: { ...createModuleScriptAttributes(attributes), 'data-eco-lazy-key': lazyKey },
23
+ }),
24
+ };
7
25
  }
8
- function getDependencyEntrySrcOrThrow(entry, errorMessage) {
9
- if (!entry.src) {
10
- throw new Error(errorMessage);
11
- }
12
- return entry.src;
26
+ function declareFileLazyScript(entry, options) {
27
+ const { lazy, attributes } = entry;
28
+ if (!entry.src)
29
+ throw new Error(options.lazyScriptMissingSrcMessage);
30
+ const importPath = resolveDeclaredPath(options.componentDir, entry.src);
31
+ const sourceKey = toRootRelativePath(options.rootDir, importPath);
32
+ const triggerKey = getLazyTriggerKey(lazy);
33
+ const lazyKey = `lazy:${contentHash(`${sourceKey}:${triggerKey}`, 16)}`;
34
+ return {
35
+ lazy,
36
+ lazyKey,
37
+ fallbackUrl: options.resolveLazyScripts(options.componentDir, [entry.src]).split(',')[0] ?? '',
38
+ key: `lazy:entry:file:${triggerKey}:${importPath}:${JSON.stringify(attributes ?? {})}`,
39
+ entryHash: contentHash(`${sourceKey}:${triggerKey}`, 16),
40
+ createAsset: (entryName) => createAppBrowserClientEntry({
41
+ entryName,
42
+ importPath,
43
+ attributes: { ...createModuleScriptAttributes(attributes), 'data-eco-lazy-key': lazyKey },
44
+ }),
45
+ };
13
46
  }
14
47
  /**
15
- * Collects lazy script dependency entries and emits their hidden bundle inputs.
48
+ * Normalizes a component's lazy script declarations into hidden app browser client entries.
16
49
  *
17
- * This helper also reports the trigger-to-script relationship back to the caller so
18
- * later stages can build the lazy-trigger manifest without reparsing dependency config.
50
+ * @remarks
51
+ * Each entry carries a `data-eco-lazy-key`, from the component file and its content or from the source and its
52
+ * trigger, so it does not depend on declaration order.
19
53
  */
20
- export function collectLazyScriptEntries(options) {
21
- const { scriptEntries, rootDir, componentFile, componentDir, integrationName, dependencies, lazyDependencyKeys, registerLazyScript, resolveDependencyPath, resolveLazyScripts, createModuleScriptAttributes, createEcopagesJsxLazyEntryName, pushUniqueDependency, getLazyScriptMissingSrcMessage, } = options;
22
- for (const [index, scriptEntry] of scriptEntries.entries()) {
23
- if (!isDependencyEntryObject(scriptEntry) || !scriptEntry.lazy) {
24
- continue;
25
- }
26
- const lazy = scriptEntry.lazy;
27
- const content = scriptEntry.content;
28
- const src = scriptEntry.src;
29
- const attributes = scriptEntry.attributes;
30
- if (content) {
31
- const lazyKey = `lazy:${contentHash(`${toRootRelativePath(rootDir, componentFile)}:entry:${index}:${content}`, 16)}`;
32
- const depKey = `lazy:entry:content:${getLazyTriggerKey(lazy)}:${content}:${JSON.stringify(attributes ?? {})}`;
33
- const lazyEntryName = createEcopagesJsxLazyEntryName(integrationName, depKey);
34
- pushUniqueDependency(lazyDependencyKeys, depKey, dependencies, AssetFactory.createContentScript({
35
- position: 'head',
36
- name: lazyEntryName,
37
- content,
38
- excludeFromHtml: true,
39
- bundle: true,
40
- groupedBundle: {
41
- id: APP_BROWSER_CLIENT_BUNDLE_ID,
42
- entryName: lazyEntryName,
43
- },
44
- attributes: {
45
- ...createModuleScriptAttributes(attributes),
46
- 'data-eco-lazy-key': lazyKey,
47
- },
48
- }));
49
- registerLazyScript({
50
- lazy,
51
- lazyKey,
52
- });
54
+ export function declareLazyScriptEntries(options) {
55
+ const declared = [];
56
+ for (const [index, entry] of options.scriptEntries.entries()) {
57
+ if (typeof entry !== 'object' || entry === null || !entry.lazy)
53
58
  continue;
54
- }
55
- const script = src ?? getDependencyEntrySrcOrThrow(scriptEntry, getLazyScriptMissingSrcMessage());
56
- const resolvedPath = resolveDependencyPath(componentDir, script);
57
- const sourceKey = toRootRelativePath(rootDir, resolvedPath);
58
- const fallbackUrl = resolveLazyScripts(componentDir, [script]).split(',')[0] ?? '';
59
- const lazyKey = `lazy:${contentHash(`${sourceKey}:${getLazyTriggerKey(lazy)}`, 16)}`;
60
- const lazyEntryName = createEcopagesJsxLazyEntryName(integrationName, `${sourceKey}:${getLazyTriggerKey(lazy)}`);
61
- const depKey = `lazy:entry:file:${getLazyTriggerKey(lazy)}:${resolvedPath}:${JSON.stringify(attributes ?? {})}`;
62
- pushUniqueDependency(lazyDependencyKeys, depKey, dependencies, createAppBrowserClientEntry({
63
- entryName: lazyEntryName,
64
- importPath: resolvedPath,
65
- attributes: {
66
- ...createModuleScriptAttributes(attributes),
67
- 'data-eco-lazy-key': lazyKey,
68
- },
69
- }));
70
- registerLazyScript({
71
- lazy,
72
- lazyKey,
73
- fallbackUrl,
74
- });
59
+ const lazyEntry = entry;
60
+ declared.push(lazyEntry.content
61
+ ? declareContentLazyScript({ ...lazyEntry, content: lazyEntry.content }, index, options)
62
+ : declareFileLazyScript(lazyEntry, options));
75
63
  }
64
+ return declared;
76
65
  }
@@ -1,5 +1,19 @@
1
- import type { EcopagesVirtualImport } from './ecopages-virtual-imports.js';
1
+ import type { EcopagesVirtualImport } from '../../plugins/ecopages-virtual-imports.js';
2
+ /** One module a component's browser scripts import, with its named imports or none for the namespace. */
3
+ export type ModuleDeclaration = {
4
+ from: string;
5
+ imports?: string[];
6
+ };
7
+ /** Whether a browser script can import the `ecopages:` virtual module `specifier`. */
8
+ export declare function isBrowserEcopagesVirtualImport(specifier: string): boolean;
2
9
  /**
3
- * Combines explicit config module declarations with auto-detected `ecopages:` imports.
10
+ * Merges one module declaration into the aggregated map, preserving the wildcard
11
+ * import semantics represented by `null`.
4
12
  */
5
- export declare function collectModuleDeclarations(modulesMap: Map<string, Set<string> | null>, declaredModules: unknown, autoVirtualImports: EcopagesVirtualImport[]): void;
13
+ export declare function mergeModuleDeclaration(modulesMap: Map<string, Set<string> | null>, declaration: ModuleDeclaration): void;
14
+ /**
15
+ * Lists the modules a component declares in `modules`, then the `ecopages:` virtual modules its module imports.
16
+ *
17
+ * @remarks A server-only `ecopages:` module is left out of both.
18
+ */
19
+ export declare function declareModules(declaredModules: unknown, autoVirtualImports: readonly EcopagesVirtualImport[]): ModuleDeclaration[];
@@ -1,5 +1,9 @@
1
1
  import { normalizeModuleDeclarations } from '../../eco/module-dependencies.js';
2
- import { isBrowserEcopagesVirtualImport } from './ecopages-virtual-imports.js';
2
+ import { isContentServerVirtualModule } from '../../build/contracts/content-virtual-modules.js';
3
+ /** Whether a browser script can import the `ecopages:` virtual module `specifier`. */
4
+ export function isBrowserEcopagesVirtualImport(specifier) {
5
+ return specifier.startsWith('ecopages:') && !isContentServerVirtualModule(specifier);
6
+ }
3
7
  /**
4
8
  * Narrows arbitrary config input onto the declared module string array shape.
5
9
  */
@@ -13,7 +17,7 @@ function getDeclaredModules(value) {
13
17
  * Merges one module declaration into the aggregated map, preserving the wildcard
14
18
  * import semantics represented by `null`.
15
19
  */
16
- function mergeModuleDeclaration(modulesMap, declaration) {
20
+ export function mergeModuleDeclaration(modulesMap, declaration) {
17
21
  const existing = modulesMap.get(declaration.from);
18
22
  if (!declaration.imports || declaration.imports.length === 0) {
19
23
  modulesMap.set(declaration.from, null);
@@ -29,16 +33,13 @@ function mergeModuleDeclaration(modulesMap, declaration) {
29
33
  modulesMap.set(declaration.from, merged);
30
34
  }
31
35
  /**
32
- * Combines explicit config module declarations with auto-detected `ecopages:` imports.
36
+ * Lists the modules a component declares in `modules`, then the `ecopages:` virtual modules its module imports.
37
+ *
38
+ * @remarks A server-only `ecopages:` module is left out of both.
33
39
  */
34
- export function collectModuleDeclarations(modulesMap, declaredModules, autoVirtualImports) {
35
- for (const declaration of normalizeModuleDeclarations(getDeclaredModules(declaredModules))) {
36
- if (declaration.from.startsWith('ecopages:') && !isBrowserEcopagesVirtualImport(declaration.from)) {
37
- continue;
38
- }
39
- mergeModuleDeclaration(modulesMap, declaration);
40
- }
41
- for (const declaration of autoVirtualImports) {
42
- mergeModuleDeclaration(modulesMap, declaration);
43
- }
40
+ export function declareModules(declaredModules, autoVirtualImports) {
41
+ return [
42
+ ...normalizeModuleDeclarations(getDeclaredModules(declaredModules)).filter((declaration) => !declaration.from.startsWith('ecopages:') || isBrowserEcopagesVirtualImport(declaration.from)),
43
+ ...autoVirtualImports.filter((declaration) => isBrowserEcopagesVirtualImport(declaration.from)),
44
+ ];
44
45
  }
@@ -1,4 +1,4 @@
1
- import type { EcoPageFile, GetMetadata, GetMetadataContext, GetStaticProps, PageMetadataProps, RouteRendererOptions, EcoPageComponent } from '../../types/contracts.js';
1
+ import type { EcoPageFile, GetMetadata, GetMetadataContext, GetProps, PageMetadataProps, RouteRendererOptions, EcoPageComponent } from '../../types/contracts.js';
2
2
  import type { EcoPagesAppConfig } from '../../config/internal-types.js';
3
3
  /**
4
4
  * Loads route page modules and normalizes their data hooks for rendering.
@@ -27,14 +27,14 @@ export declare class PageModuleLoaderService {
27
27
  bypassCache?: boolean;
28
28
  }): Promise<EcoPageFile>;
29
29
  /**
30
- * Executes the page's static-props hook with Ecopages runtime context.
30
+ * Executes the page's `props` hook with Ecopages runtime context.
31
31
  *
32
32
  * @remarks
33
- * Pages without a static-props hook still return a normalized empty props
33
+ * Pages without a `props` hook still return a normalized empty props
34
34
  * object so downstream render preparation does not branch on hook presence.
35
35
  */
36
- getStaticPropsForPage(options: {
37
- getStaticProps?: GetStaticProps<Record<string, unknown>>;
36
+ getPropsForPage(options: {
37
+ getProps?: GetProps<Record<string, unknown>>;
38
38
  params?: RouteRendererOptions['params'];
39
39
  }): Promise<{
40
40
  props: Record<string, unknown>;
@@ -73,7 +73,7 @@ export declare class PageModuleLoaderService {
73
73
  }): Promise<{
74
74
  module: EcoPageFile;
75
75
  Page: EcoPageFile['default'] | EcoPageComponent<any>;
76
- getStaticProps?: GetStaticProps<Record<string, unknown>>;
76
+ getProps?: GetProps<Record<string, unknown>>;
77
77
  getMetadata?: GetMetadata;
78
78
  integrationSpecificProps: Record<string, unknown>;
79
79
  }>;
@@ -81,14 +81,13 @@ export declare class PageModuleLoaderService {
81
81
  * Resolves the page data needed by the render pipeline.
82
82
  *
83
83
  * @remarks
84
- * Static props are resolved first because page metadata may depend on those
85
- * props. This preserves the same ordering whether data hooks are declared as
86
- * component statics or module exports. Props passed with the render win over
87
- * static props and are visible to metadata; `skipStaticProps` drops the hook.
84
+ * The `props` hook runs first because page metadata may depend on its result.
85
+ * Props passed with the render win over the hook's props and are visible to
86
+ * metadata; `skipPropsHook` drops the hook.
88
87
  */
89
88
  resolvePageData(options: {
90
89
  pageModule: {
91
- getStaticProps?: GetStaticProps<Record<string, unknown>>;
90
+ getProps?: GetProps<Record<string, unknown>>;
92
91
  getMetadata?: GetMetadata;
93
92
  };
94
93
  routeOptions: RouteRendererOptions;