@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
@@ -22,6 +22,11 @@ export declare function buildIslandHostAttributes(input: IslandHostAttributesInp
22
22
  export declare function componentRenderHasIslandBootstrap(assets: Array<{
23
23
  kind: string;
24
24
  }> | undefined): boolean;
25
+ type IslandHostRenderResult = {
26
+ canAttachAttributes: boolean;
27
+ integrationName: string;
28
+ rootAttributes?: Record<string, string>;
29
+ };
25
30
  /**
26
31
  * Stamps the render result's root as an Island Host when the component ships its own client script.
27
32
  *
@@ -29,14 +34,20 @@ export declare function componentRenderHasIslandBootstrap(assets: Array<{
29
34
  * and the Foreign Subtrees rendered inside it.
30
35
  * @remarks A component without scripts that wraps an island is not an island itself.
31
36
  */
32
- export declare function finalizeIslandComponentRender<T extends {
33
- canAttachAttributes: boolean;
34
- integrationName: string;
35
- rootAttributes?: Record<string, string>;
36
- }>(input: {
37
+ export declare function finalizeIslandComponentRender<T extends IslandHostRenderResult>(input: {
37
38
  integrationContext?: {
38
39
  componentInstanceId?: string;
39
40
  };
40
41
  }, result: T, ownAssets: Array<{
41
42
  kind: string;
42
43
  }> | undefined): T;
44
+ /**
45
+ * Stamps the render result's root as an Island Host when `shipsScript` says the component ships its own client
46
+ * script and the render carries a component instance id.
47
+ */
48
+ export declare function stampIslandHost<T extends IslandHostRenderResult>(input: {
49
+ integrationContext?: {
50
+ componentInstanceId?: string;
51
+ };
52
+ }, result: T, shipsScript: boolean): T;
53
+ export {};
@@ -49,8 +49,15 @@ export function componentRenderHasIslandBootstrap(assets) {
49
49
  * @remarks A component without scripts that wraps an island is not an island itself.
50
50
  */
51
51
  export function finalizeIslandComponentRender(input, result, ownAssets) {
52
+ return stampIslandHost(input, result, componentRenderHasIslandBootstrap(ownAssets));
53
+ }
54
+ /**
55
+ * Stamps the render result's root as an Island Host when `shipsScript` says the component ships its own client
56
+ * script and the render carries a component instance id.
57
+ */
58
+ export function stampIslandHost(input, result, shipsScript) {
52
59
  const componentInstanceId = input.integrationContext?.componentInstanceId;
53
- if (!componentInstanceId || !result.canAttachAttributes || !componentRenderHasIslandBootstrap(ownAssets)) {
60
+ if (!componentInstanceId || !result.canAttachAttributes || !shipsScript) {
54
61
  return result;
55
62
  }
56
63
  return {
@@ -1,4 +1,5 @@
1
1
  import { type StylesheetKinds } from './stylesheet-kinds.js';
2
+ import { type EcopagesVirtualImport } from './ecopages-virtual-imports.js';
2
3
  /**
3
4
  * Whether `program` calls `eco.page`, `eco.component`, `eco.layout` or `eco.html` anywhere.
4
5
  */
@@ -45,6 +46,14 @@ export type ModuleIndex = {
45
46
  * plugin for a module that no longer declares anything.
46
47
  */
47
48
  export declare function forgetDiscoveryOwner(projectRoot: string, ownerFile: string): void;
49
+ /**
50
+ * Drops what discovery from the declaration in `owner`, a real path, recorded as reached.
51
+ *
52
+ * @remarks
53
+ * The build plugin calls this with the module id the bundler reports, which is already a real path, so no
54
+ * path is resolved again.
55
+ */
56
+ export declare function forgetCanonicalDiscoveryOwner(projectRoot: string, owner: string): void;
48
57
  /**
49
58
  * Whether the latest discovery of some Eco declaration of the app at `projectRoot` walked into `file`.
50
59
  *
@@ -125,6 +134,8 @@ export type DiscoveredImports = {
125
134
  file: string;
126
135
  imported: string;
127
136
  }>;
137
+ /** The `ecopages:` virtual modules the declaring module imports itself. */
138
+ virtualImports: EcopagesVirtualImport[];
128
139
  watchFiles: string[];
129
140
  removals: Array<{
130
141
  start: number;
@@ -178,6 +189,8 @@ type PlainModuleWalk = {
178
189
  export type DiscoveryCache = {
179
190
  indexes: Map<string, ModuleIndex>;
180
191
  walks: Map<string, PlainModuleWalk>;
192
+ /** The module a bare import resolves to from a folder, or `null` when discovery does not follow it. */
193
+ packageModules: Map<string, string | null>;
181
194
  };
182
195
  export declare function createDiscoveryCache(): DiscoveryCache;
183
196
  /**
@@ -193,7 +206,7 @@ export declare function createDiscoveryCache(): DiscoveryCache;
193
206
  * every walked plain module are recorded in `watchFiles` so their edits invalidate caches. Each stylesheet is
194
207
  * listed once by real path, and `packageStylesheets` marks those a package import named.
195
208
  * `export *`, dynamic imports, namespace imports, packages that ship no CSS Module, and `.server` modules are not
196
- * followed.
209
+ * followed. `ownerFile` is a real path, as a bundler reports a module id, and every path discovery returns is one.
197
210
  */
198
211
  export declare function discoverComponentImports(program: unknown, ownerFile: string, projectRoot: string, options?: DiscoveryOptions): DiscoveredImports;
199
212
  export {};
@@ -4,6 +4,8 @@ import { parseModuleSource } from '../cache/module-parse-cache.js';
4
4
  import { CSS_MODULE_PROCESSOR_FIX, PLAIN_CSS_KINDS } from './stylesheet-kinds.js';
5
5
  import { contentHash } from '../utils/content-hash.js';
6
6
  import { findPackageRoot } from '../utils/package-path.js';
7
+ import { isServerOnlyModuleSpecifier } from '../utils/file-roles.js';
8
+ import { collectEcopagesVirtualImports } from './ecopages-virtual-imports.js';
7
9
  import { isBarePackageImportSpecifier, loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolvePackageModulePath, resolvePackageStylesheetPath, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
8
10
  function node(value) {
9
11
  return typeof value === 'object' && value !== null ? value : undefined;
@@ -55,9 +57,6 @@ export function declaresEcoFactory(program) {
55
57
  });
56
58
  return found;
57
59
  }
58
- function isServerSpecifier(source) {
59
- return /\.server(?:\.[cm]?[jt]sx?)?$/.test(source);
60
- }
61
60
  function isLocalSpecifier(source, pathPrefixes) {
62
61
  return source.startsWith('.') || matchesTsconfigPathPrefix(source, pathPrefixes);
63
62
  }
@@ -291,8 +290,17 @@ function reachIn(projectRoot) {
291
290
  * plugin for a module that no longer declares anything.
292
291
  */
293
292
  export function forgetDiscoveryOwner(projectRoot, ownerFile) {
293
+ forgetCanonicalDiscoveryOwner(projectRoot, canonicalFile(ownerFile));
294
+ }
295
+ /**
296
+ * Drops what discovery from the declaration in `owner`, a real path, recorded as reached.
297
+ *
298
+ * @remarks
299
+ * The build plugin calls this with the module id the bundler reports, which is already a real path, so no
300
+ * path is resolved again.
301
+ */
302
+ export function forgetCanonicalDiscoveryOwner(projectRoot, owner) {
294
303
  const reach = reachIn(projectRoot);
295
- const owner = canonicalFile(ownerFile);
296
304
  for (const module of reach.byOwner.get(owner) ?? []) {
297
305
  const owners = reach.byModule.get(module);
298
306
  owners?.delete(owner);
@@ -301,10 +309,9 @@ export function forgetDiscoveryOwner(projectRoot, ownerFile) {
301
309
  }
302
310
  reach.byOwner.delete(owner);
303
311
  }
304
- function recordDiscoveryOwner(projectRoot, ownerFile, modules) {
305
- forgetDiscoveryOwner(projectRoot, ownerFile);
312
+ function recordDiscoveryOwner(projectRoot, owner, modules) {
313
+ forgetCanonicalDiscoveryOwner(projectRoot, owner);
306
314
  const reach = reachIn(projectRoot);
307
- const owner = canonicalFile(ownerFile);
308
315
  const reached = new Set(modules);
309
316
  reach.byOwner.set(owner, reached);
310
317
  for (const module of reached) {
@@ -321,7 +328,7 @@ function recordDiscoveryOwner(projectRoot, ownerFile, modules) {
321
328
  * again once its build is transformed, so a plain module reached from a declaration is recorded in time.
322
329
  */
323
330
  export function isReachedByDiscovery(projectRoot, file) {
324
- return reachIn(projectRoot).byModule.has(canonicalFile(file));
331
+ return reachIn(projectRoot).byModule.has(file);
325
332
  }
326
333
  /**
327
334
  * Whether discovery has seen `file`, as a module a declaration walked into or as a declaration itself.
@@ -467,10 +474,12 @@ export function createUndeliverablePackageStylesheetError(projectRoot, importer,
467
474
  return new Error(`[ecopages] ${module}: ${JSON.stringify(source)} never reaches a Page, because no eco.page(), eco.layout(), eco.html() or eco.component() delivers the stylesheets a package module imports. List the stylesheet in eco.component({ dependencies: { stylesheets } }) of the component that uses the package.`);
468
475
  }
469
476
  export function createDiscoveryCache() {
470
- return { indexes: new Map(), walks: new Map() };
477
+ return { indexes: new Map(), walks: new Map(), packageModules: new Map() };
471
478
  }
472
479
  function resolveReexport(file, reexport, state) {
473
- if (!reexport || isServerSpecifier(reexport.source) || !isLocalSpecifier(reexport.source, state.pathPrefixes)) {
480
+ if (!reexport ||
481
+ isServerOnlyModuleSpecifier(reexport.source) ||
482
+ !isLocalSpecifier(reexport.source, state.pathPrefixes)) {
474
483
  return undefined;
475
484
  }
476
485
  const resolved = resolveProjectModulePath(state.projectRoot, file, reexport.source, { preserveBarrel: true });
@@ -495,7 +504,7 @@ function isFactoryExport(file, exportName, state, pending = new Set()) {
495
504
  return false;
496
505
  pending.add(visitKey);
497
506
  let result = false;
498
- if (!file.includes(`/node_modules/`) && !isServerSpecifier(file)) {
507
+ if (!file.includes(`/node_modules/`) && !isServerOnlyModuleSpecifier(file)) {
499
508
  const { factories, namedReexports } = indexModule(file, state.cache);
500
509
  if (factories.has(exportName)) {
501
510
  result = true;
@@ -599,11 +608,20 @@ function assertSameIntegration(importer, local, component, renderedNames, state)
599
608
  function followPackageImport(entry, importer, state) {
600
609
  if (!isInNodeModules(importer) && !isBarePackageImportSpecifier(entry.source, state.projectRoot))
601
610
  return undefined;
602
- return resolvePackageModule(importer, entry.source, state.stylesheets);
611
+ const cache = state.cache?.packageModules;
612
+ if (!cache)
613
+ return resolvePackageModule(importer, entry.source, state.stylesheets);
614
+ const key = `${path.dirname(importer)}\0${entry.source}`;
615
+ let module = cache.get(key);
616
+ if (module === undefined) {
617
+ module = resolvePackageModule(importer, entry.source, state.stylesheets) ?? null;
618
+ cache.set(key, module);
619
+ }
620
+ return module ?? undefined;
603
621
  }
604
622
  /** Whether `entry` imports a script module for its bindings or its side effects, not a stylesheet or a `.server` module. */
605
623
  function isScriptEdge(entry, state) {
606
- if (entry.attributed || state.stylesheets.isStylesheet(entry.source) || isServerSpecifier(entry.source))
624
+ if (entry.attributed || state.stylesheets.isStylesheet(entry.source) || isServerOnlyModuleSpecifier(entry.source))
607
625
  return false;
608
626
  return entry.sideEffectOnly || entry.bindings.length > 0;
609
627
  }
@@ -695,7 +713,7 @@ function walkPlainModule(file, state, inProgress) {
695
713
  return { walk, pending: new Set() };
696
714
  inProgress.add(file);
697
715
  const local = { ...state, resolved: new Map(), watchFiles: walk.watchFiles };
698
- walk.modules.add(canonicalFile(file));
716
+ walk.modules.add(file);
699
717
  walk.watchFiles.add(file);
700
718
  collectWalkStylesheets(file, index.imports, local, walk);
701
719
  const children = collectModuleEdges(file, index.imports, () => index.renderedNames, local, (binding, target) => {
@@ -766,7 +784,7 @@ function collectOwnStylesheets(imports, ownerFile, state, result) {
766
784
  * every walked plain module are recorded in `watchFiles` so their edits invalidate caches. Each stylesheet is
767
785
  * listed once by real path, and `packageStylesheets` marks those a package import named.
768
786
  * `export *`, dynamic imports, namespace imports, packages that ship no CSS Module, and `.server` modules are not
769
- * followed.
787
+ * followed. `ownerFile` is a real path, as a bundler reports a module id, and every path discovery returns is one.
770
788
  */
771
789
  export function discoverComponentImports(program, ownerFile, projectRoot, options = {}) {
772
790
  const result = {
@@ -775,6 +793,7 @@ export function discoverComponentImports(program, ownerFile, projectRoot, option
775
793
  plainModuleStylesheets: [],
776
794
  packageStylesheets: [],
777
795
  plainModuleComponents: [],
796
+ virtualImports: [],
778
797
  watchFiles: [],
779
798
  removals: [],
780
799
  };
@@ -790,6 +809,7 @@ export function discoverComponentImports(program, ownerFile, projectRoot, option
790
809
  watchFiles: new Set(),
791
810
  };
792
811
  const imports = collectStaticImports(program);
812
+ result.virtualImports = collectEcopagesVirtualImports(imports);
793
813
  const packageStylesheets = collectOwnStylesheets(imports, ownerFile, state, result);
794
814
  let renderedNames;
795
815
  const ownComponents = new Set();
@@ -805,7 +825,7 @@ export function discoverComponentImports(program, ownerFile, projectRoot, option
805
825
  modules: new Set(),
806
826
  watchFiles: new Set(),
807
827
  };
808
- const inProgress = new Set([canonicalFile(ownerFile)]);
828
+ const inProgress = new Set([ownerFile]);
809
829
  for (const file of plainModules) {
810
830
  const { walk } = walkPlainModule(file, state, inProgress);
811
831
  if (walk)
@@ -45,6 +45,8 @@ export type ComponentIdentityAttributionOptions = {
45
45
  discoveryCache?: DiscoveryCache;
46
46
  /** The stylesheets the build delivers; defaults to plain `.css`. */
47
47
  stylesheets?: StylesheetKinds;
48
+ /** The real path of `projectRoot`, when the caller already resolved it; resolved from `projectRoot` otherwise. */
49
+ canonicalProjectRoot?: string;
48
50
  };
49
51
  /**
50
52
  * Attributes real `eco.*()` factory calls with canonical component identity.
@@ -81,6 +83,9 @@ export declare function attributeMdxComponentIdentity(contents: string, filePath
81
83
  * discovery has reached it, and it never fails the reach check. A build can transform a
82
84
  * plain module before the declaration that imports it, so the check that a declaration reached each
83
85
  * module that lost a stylesheet import runs once the whole build is transformed.
86
+ *
87
+ * A transform id is the bundler's resolved module path, so symbolic links are already resolved and the app-root
88
+ * check compares it as it is.
84
89
  */
85
90
  export declare function createEcoComponentMetaPlugin(options: EcoComponentDirPluginOptions): EcoBuildPlugin;
86
91
  export default createEcoComponentMetaPlugin;
@@ -11,7 +11,7 @@ import { escapeRegExp } from '../utils/regex-escaping.js';
11
11
  import { toPackagePath } from '../utils/package-path.js';
12
12
  import { formatPackageStylesheetEntry } from '../eco/discovered-dependency-paths.js';
13
13
  import { toRootRelativePath } from '../utils/root-relative-path.js';
14
- import { collectStaticImports, createDiscoveryCache, createUndeliverableStylesheetError, declaresEcoFactory, forgetDiscoveryOwner, discoverComponentImports, isDeliveredStylesheetImport, isReachedByDiscovery, } from './component-import-discovery.js';
14
+ import { collectStaticImports, createDiscoveryCache, createUndeliverableStylesheetError, declaresEcoFactory, forgetCanonicalDiscoveryOwner, discoverComponentImports, isDeliveredStylesheetImport, isReachedByDiscovery, } from './component-import-discovery.js';
15
15
  import { loadTsconfigPathPrefixes } from './tsconfig-import-resolver.js';
16
16
  import { findIntegrationForFile } from './find-integration-for-file.js';
17
17
  function applySourceEdits(contents, edits, filePath, options = {}) {
@@ -42,11 +42,6 @@ function applySourceEdits(contents, edits, filePath, options = {}) {
42
42
  };
43
43
  return createMappedSourceTransformResult(contents, filePath, editSource);
44
44
  }
45
- /**
46
- * Matches the text of a side-effect import such as `import 'swiper/css'`, which can name a package stylesheet
47
- * without a `.css` suffix.
48
- */
49
- const SIDE_EFFECT_IMPORT = /(?:^|[;}\s])import\s*['"]/m;
50
45
  function isAstNode(value) {
51
46
  return typeof value === 'object' && value !== null;
52
47
  }
@@ -109,15 +104,18 @@ function walkEcoFactoryCalls(node, binding, visit) {
109
104
  * real module ids the bundler reports. A file not on disk, such as a virtual module, takes the real path of its
110
105
  * folder.
111
106
  */
112
- function createSourceKeyResolver(projectRoot) {
107
+ function createSourceKeyResolver(projectRoot, canonicalProjectRoot) {
113
108
  const toRealPath = (file) => {
114
109
  if (fileSystem.exists(file))
115
110
  return fileSystem.realpath(file);
116
111
  const dir = path.dirname(file);
117
112
  return fileSystem.exists(dir) ? path.join(fileSystem.realpath(dir), path.basename(file)) : path.resolve(file);
118
113
  };
119
- const realRoot = toRealPath(projectRoot);
120
- return (file) => toRootRelativePath(realRoot, toRealPath(file));
114
+ const realRoot = canonicalProjectRoot ?? toRealPath(projectRoot);
115
+ return {
116
+ toSourceKey: (file) => toRootRelativePath(realRoot, toRealPath(file)),
117
+ toCanonicalSourceKey: (file) => toRootRelativePath(realRoot, file),
118
+ };
121
119
  }
122
120
  /**
123
121
  * @remarks
@@ -213,6 +211,7 @@ function serializeDiscoveryArgument(discovered, toSourceKey, plainModuleComponen
213
211
  discovered.stylesheets.length === 0 &&
214
212
  discovered.plainModuleStylesheets.length === 0 &&
215
213
  discovered.plainModuleComponents.length === 0 &&
214
+ discovered.virtualImports.length === 0 &&
216
215
  discovered.watchFiles.length === 0)) {
217
216
  return '';
218
217
  }
@@ -233,7 +232,8 @@ function serializeDiscoveryArgument(discovered, toSourceKey, plainModuleComponen
233
232
  const watchFiles = discovered.watchFiles.length > 0
234
233
  ? `, watchFiles: ${JSON.stringify(discovered.watchFiles.map(toSourceKey))}`
235
234
  : '';
236
- return `, { components: () => [${components}], stylesheets: ${JSON.stringify(stylesheets)}${plain}${packages}${watchFiles} }`;
235
+ const virtualImports = discovered.virtualImports.length > 0 ? `, virtualImports: ${JSON.stringify(discovered.virtualImports)}` : '';
236
+ return `, { components: () => [${components}], stylesheets: ${JSON.stringify(stylesheets)}${plain}${packages}${virtualImports}${watchFiles} }`;
237
237
  }
238
238
  /**
239
239
  * Whether the component meta transform moves the side-effect stylesheet imports of `filePath`
@@ -281,10 +281,6 @@ function stripPlainModuleStylesheetImports(program, filePath, options) {
281
281
  }
282
282
  return edits;
283
283
  }
284
- /** A cheap pre-parse check: whether `contents` names a stylesheet extension or has a side-effect import. */
285
- function mayImportStylesheet(contents, stylesheets) {
286
- return (stylesheets.extensions.some((extension) => contents.includes(extension)) || SIDE_EFFECT_IMPORT.test(contents));
287
- }
288
284
  /**
289
285
  * Attributes real `eco.*()` factory calls with canonical component identity.
290
286
  *
@@ -302,7 +298,7 @@ export function attributeComponentIdentity(contents, filePath, options) {
302
298
  ? createJsxImportSourcePragma(jsxImportSource)
303
299
  : undefined;
304
300
  const mayDeclare = integration !== undefined && contents.includes('eco.');
305
- if (!mayDeclare && !mayImportStylesheet(contents, options.stylesheets ?? PLAIN_CSS_KINDS)) {
301
+ if (!mayDeclare && !contents.includes('import')) {
306
302
  return applySourceEdits(contents, [], filePath, { prepend: pragma });
307
303
  }
308
304
  let program;
@@ -313,7 +309,7 @@ export function attributeComponentIdentity(contents, filePath, options) {
313
309
  return applySourceEdits(contents, [], filePath, { prepend: pragma });
314
310
  }
315
311
  if (!mayDeclare || !declaresEcoFactory(program)) {
316
- forgetDiscoveryOwner(projectRoot, filePath);
312
+ forgetCanonicalDiscoveryOwner(projectRoot, filePath);
317
313
  const edits = options.stripPlainModuleStylesheets === false
318
314
  ? []
319
315
  : stripPlainModuleStylesheetImports(program, filePath, options);
@@ -321,8 +317,8 @@ export function attributeComponentIdentity(contents, filePath, options) {
321
317
  prepend: pragma,
322
318
  });
323
319
  }
324
- const toSourceKey = createSourceKeyResolver(projectRoot);
325
- const sourceKey = toSourceKey(filePath);
320
+ const { toCanonicalSourceKey } = createSourceKeyResolver(projectRoot, options.canonicalProjectRoot);
321
+ const sourceKey = toCanonicalSourceKey(filePath);
326
322
  const factoryArguments = [];
327
323
  const bindingOccurrences = new Map();
328
324
  walkEcoFactoryCalls(program, '', (node, binding) => {
@@ -351,7 +347,7 @@ export function attributeComponentIdentity(contents, filePath, options) {
351
347
  stylesheets: options.stylesheets,
352
348
  });
353
349
  const plainModuleImports = createPlainModuleComponentImports(discovered);
354
- const discoveryArgument = serializeDiscoveryArgument(discovered, toSourceKey, plainModuleImports.locals);
350
+ const discoveryArgument = serializeDiscoveryArgument(discovered, toCanonicalSourceKey, plainModuleImports.locals);
355
351
  const edits = factoryArguments.map((firstArgument) => ({
356
352
  start: firstArgument.start,
357
353
  end: firstArgument.end,
@@ -433,7 +429,7 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
433
429
  return { code: contents, map: previousMap };
434
430
  }
435
431
  const discovered = discoverComponentImports(program, filePath, projectRoot, { stylesheets });
436
- const toSourceKey = createSourceKeyResolver(projectRoot);
432
+ const { toSourceKey } = createSourceKeyResolver(projectRoot);
437
433
  const sourceKey = toSourceKey(filePath);
438
434
  const identityLiteral = createIdentityLiteral(sourceKey, sourceKey, integration);
439
435
  const plainModuleImports = createPlainModuleComponentImports(discovered);
@@ -477,6 +473,19 @@ function createComponentMetaFilter(config) {
477
473
  }
478
474
  return new RegExp(`(${extensions.map(escapeRegExp).join('|')})(\\?.*)?$`);
479
475
  }
476
+ /**
477
+ * Builds the test for whether a module's text can name a stylesheet of `kinds`.
478
+ *
479
+ * @remarks
480
+ * A module no Integration owns is only ever stripped of stylesheet imports, so one whose text names no
481
+ * stylesheet extension needs neither a parse nor the path checks that decide whether it is stripped. The
482
+ * test is a superset of `kinds.isStylesheet`, which compares lowercased names, so it never skips an import
483
+ * that would be stripped.
484
+ */
485
+ function createStylesheetMentionTest(kinds) {
486
+ const pattern = new RegExp(kinds.extensions.map(escapeRegExp).join('|'), 'i');
487
+ return (code) => pattern.test(code);
488
+ }
480
489
  /**
481
490
  * Creates the build plugin that attributes component identity in every Integration's script files and
482
491
  * removes the stylesheet imports discovery delivers from every local script module.
@@ -489,24 +498,31 @@ function createComponentMetaFilter(config) {
489
498
  * discovery has reached it, and it never fails the reach check. A build can transform a
490
499
  * plain module before the declaration that imports it, so the check that a declaration reached each
491
500
  * module that lost a stylesheet import runs once the whole build is transformed.
501
+ *
502
+ * A transform id is the bundler's resolved module path, so symbolic links are already resolved and the app-root
503
+ * check compares it as it is.
492
504
  */
493
505
  export function createEcoComponentMetaPlugin(options) {
494
506
  const { integrations, rootDir } = options.config;
495
507
  const integrationOf = (file) => findIntegrationForFile(integrations, file);
496
508
  const stylesheets = getStylesheetKinds(options.config);
509
+ const mentionsStylesheet = createStylesheetMentionTest(stylesheets);
497
510
  return {
498
511
  name: 'eco-component-identity-attribution',
499
512
  setup(build) {
500
513
  const strippedStylesheets = new Map();
501
514
  const discoveryCache = createDiscoveryCache();
502
- const appRoot = `${fileSystem.exists(rootDir) ? fileSystem.realpath(rootDir) : path.resolve(rootDir)}/`;
515
+ const canonicalRoot = fileSystem.exists(rootDir) ? fileSystem.realpath(rootDir) : path.resolve(rootDir);
516
+ const appRoot = `${canonicalRoot}/`;
503
517
  build.transform({ filter: /\.[cm]?[jt]sx?(\?.*)?$/ }, (code, rawId) => {
504
518
  const id = rawId.replace(/[?#].*$/, '');
505
519
  if (id.includes('/node_modules/')) {
506
520
  return { code };
507
521
  }
508
522
  const integration = findIntegrationForFile(integrations, id);
509
- const insideApp = (fileSystem.exists(id) ? fileSystem.realpath(id) : id).startsWith(appRoot);
523
+ if (!integration && !mentionsStylesheet(code))
524
+ return { code };
525
+ const insideApp = id.startsWith(appRoot);
510
526
  const stripPlainModuleStylesheets = insideApp || isReachedByDiscovery(rootDir, id);
511
527
  if (!integration && !stripPlainModuleStylesheets) {
512
528
  return { code };
@@ -514,6 +530,7 @@ export function createEcoComponentMetaPlugin(options) {
514
530
  return attributeComponentIdentity(code, id, {
515
531
  integration: integration?.name,
516
532
  projectRoot: rootDir,
533
+ canonicalProjectRoot: canonicalRoot,
517
534
  jsxImportSource: integration?.jsxImportSource,
518
535
  integrationOf,
519
536
  stripPlainModuleStylesheets,
@@ -0,0 +1,15 @@
1
+ import type { StaticImport } from './component-import-discovery.js';
2
+ /** One `ecopages:` virtual module a module imports, with its named imports or none for the namespace. */
3
+ export type EcopagesVirtualImport = {
4
+ from: string;
5
+ imports: string[] | undefined;
6
+ };
7
+ /**
8
+ * Lists the `ecopages:` virtual modules among a module's static imports, once each.
9
+ *
10
+ * @remarks
11
+ * Server-only ones are listed too; rendering leaves them out of the browser modules it declares.
12
+ * A module imported for its namespace, its default export or its side effects is listed without named imports,
13
+ * and that wins over named imports of the same module, so module generation imports the whole namespace.
14
+ */
15
+ export declare function collectEcopagesVirtualImports(imports: readonly StaticImport[]): EcopagesVirtualImport[];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Lists the `ecopages:` virtual modules among a module's static imports, once each.
3
+ *
4
+ * @remarks
5
+ * Server-only ones are listed too; rendering leaves them out of the browser modules it declares.
6
+ * A module imported for its namespace, its default export or its side effects is listed without named imports,
7
+ * and that wins over named imports of the same module, so module generation imports the whole namespace.
8
+ */
9
+ export function collectEcopagesVirtualImports(imports) {
10
+ const found = new Map();
11
+ for (const { source, bindings } of imports) {
12
+ if (!source.startsWith('ecopages:') || found.get(source) === null)
13
+ continue;
14
+ const named = bindings.filter(({ imported }) => imported !== 'default').map(({ imported }) => imported);
15
+ if (named.length === 0) {
16
+ found.set(source, null);
17
+ continue;
18
+ }
19
+ const known = found.get(source) ?? new Set();
20
+ for (const name of named)
21
+ known.add(name);
22
+ found.set(source, known);
23
+ }
24
+ return [...found].map(([from, names]) => ({ from, imports: names ? [...names] : undefined }));
25
+ }
@@ -98,7 +98,7 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
98
98
  * filenames.
99
99
  *
100
100
  * @remarks
101
- * An Integration whose Pages cannot export `staticPaths` or read params overrides it with
101
+ * An Integration whose Pages cannot declare `paths` or read params overrides it with
102
102
  * `false`, and route discovery then rejects those filenames instead of failing at render.
103
103
  * It describes the Integration, so it is a class member rather than a user option.
104
104
  */
@@ -33,7 +33,7 @@ export class IntegrationPlugin {
33
33
  * filenames.
34
34
  *
35
35
  * @remarks
36
- * An Integration whose Pages cannot export `staticPaths` or read params overrides it with
36
+ * An Integration whose Pages cannot declare `paths` or read params overrides it with
37
37
  * `false`, and route discovery then rejects those filenames instead of failing at render.
38
38
  * It describes the Integration, so it is a class member rather than a user option.
39
39
  */
@@ -62,6 +62,8 @@ export declare function resolveRelativeModulePath(fromFile: string, specifier: s
62
62
  *
63
63
  * @remarks
64
64
  * A query or hash on the specifier, such as a module variant, is not part of the file and is dropped.
65
+ * oxc-resolver returns native paths, so a result is converted to forward slashes like every other path core
66
+ * compares; it is already real, since the resolver follows symbolic links.
65
67
  */
66
68
  export declare function resolveProjectModulePath(projectRoot: string, fromFile: string, moduleSpecifier: string, options?: {
67
69
  preserveBarrel?: boolean;
@@ -300,6 +300,8 @@ export function resolveRelativeModulePath(fromFile, specifier) {
300
300
  *
301
301
  * @remarks
302
302
  * A query or hash on the specifier, such as a module variant, is not part of the file and is dropped.
303
+ * oxc-resolver returns native paths, so a result is converted to forward slashes like every other path core
304
+ * compares; it is already real, since the resolver follows symbolic links.
303
305
  */
304
306
  export function resolveProjectModulePath(projectRoot, fromFile, moduleSpecifier, options) {
305
307
  const specifier = moduleSpecifier.replace(/[?#].*$/u, '');
@@ -313,13 +315,13 @@ export function resolveProjectModulePath(projectRoot, fromFile, moduleSpecifier,
313
315
  if (resolver) {
314
316
  const result = resolver.sync(path.dirname(fromFile), specifier);
315
317
  if (result.path) {
316
- return options?.preserveBarrel
317
- ? fileSystem.realpath(result.path)
318
- : resolveAliasedBarrelTarget(fileSystem.realpath(result.path));
318
+ const resolved = path.fromNative(result.path);
319
+ return options?.preserveBarrel ? resolved : resolveAliasedBarrelTarget(resolved);
319
320
  }
320
321
  }
321
322
  if (isRelative) {
322
- return resolveRelativeModulePath(fromFile, specifier);
323
+ const relativePath = resolveRelativeModulePath(fromFile, specifier);
324
+ return relativePath && options?.preserveBarrel ? fileSystem.realpath(relativePath) : relativePath;
323
325
  }
324
326
  return undefined;
325
327
  }
@@ -380,5 +382,5 @@ const packageModuleResolver = new ResolverFactory({
380
382
  */
381
383
  export function resolvePackageModulePath(fromFile, specifier) {
382
384
  const result = packageModuleResolver.sync(path.dirname(fromFile), specifier);
383
- return result.path ? fileSystem.realpath(result.path) : undefined;
385
+ return result.path ? path.fromNative(result.path) : undefined;
384
386
  }
@@ -98,16 +98,17 @@ export class ErrorPageRenderer {
98
98
  throw new Error(`No route renderer available for __error__/${status}`);
99
99
  }
100
100
  const view = (await loader()).default;
101
- const { renderer, props: staticProps, view: renderableView, } = await prepareExplicitStaticRender({
101
+ const { renderer, props: hookProps, view: renderableView, } = await prepareExplicitStaticRender({
102
102
  routePath: `__error__/${status}`,
103
103
  view,
104
+ viewFile: loader.filePath,
104
105
  params: {},
105
106
  appConfig: this.appConfig,
106
107
  runtimeOrigin: this.appConfig.baseUrl,
107
108
  routeRendererFactory: this.routeRendererFactory,
108
109
  errors: ERROR_PAGE_RENDER_ERRORS,
109
110
  });
110
- const response = await renderer.renderExplicitView(renderableView, { ...staticProps, ...props }, { status });
111
+ const response = await renderer.renderExplicitView(renderableView, { ...hookProps, ...props }, { status });
111
112
  return { body: await response.text() };
112
113
  }
113
114
  getTemplatePath(kind) {
@@ -7,15 +7,20 @@ type ExplicitStaticRenderPreparationResult = {
7
7
  view: EcoFunctionComponent<Record<string, unknown>, any>;
8
8
  };
9
9
  /**
10
- * Resolves the renderer for one explicit view without reading its static props.
10
+ * Resolves the renderer for one explicit view without reading its `props` hook.
11
11
  *
12
12
  * @remarks
13
- * Static export planning calls this so a dynamic route whose `staticProps`
13
+ * Static export planning calls this so a dynamic route whose `props`
14
14
  * reads params is not invoked before a slug exists.
15
15
  */
16
16
  export declare function resolveExplicitViewRenderer(input: {
17
17
  routePath: string;
18
18
  view: EcoPageComponent<any>;
19
+ /** Source file the view was loaded from and the app root, when known; the view must declare its Page there. */
20
+ declaredIn?: {
21
+ file: string;
22
+ rootDir: string;
23
+ };
19
24
  routeRendererFactory: ExplicitViewRendererResolver;
20
25
  errors: {
21
26
  missingIntegration(routePath: string): string;
@@ -26,12 +31,14 @@ export declare function resolveExplicitViewRenderer(input: {
26
31
  view: EcoFunctionComponent<Record<string, unknown>, any>;
27
32
  };
28
33
  /**
29
- * Resolves the renderer and static props needed to render one explicit static
34
+ * Resolves the renderer and props needed to render one explicit static
30
35
  * view at runtime or during static generation.
31
36
  */
32
37
  export declare function prepareExplicitStaticRender(input: {
33
38
  routePath: string;
34
39
  view: EcoPageComponent<any>;
40
+ /** Source file the view was loaded from, when known. */
41
+ viewFile?: string;
35
42
  params: Record<string, string | string[]>;
36
43
  appConfig: EcoPagesAppConfig;
37
44
  runtimeOrigin: string;