@ecopages/core 0.3.0 → 0.3.2

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 (201) hide show
  1. package/README.md +2 -2
  2. package/package.json +3 -3
  3. package/src/adapters/node/create-app.d.ts +40 -11
  4. package/src/adapters/node/create-app.js +95 -69
  5. package/src/adapters/node/dev-session.js +0 -1
  6. package/src/adapters/node/http-request-bridge.d.ts +4 -0
  7. package/src/adapters/node/http-request-bridge.js +9 -1
  8. package/src/adapters/node/runtime-host.d.ts +28 -6
  9. package/src/adapters/node/runtime-host.js +35 -9
  10. package/src/adapters/node/server-adapter.d.ts +10 -35
  11. package/src/adapters/node/server-adapter.js +21 -58
  12. package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
  13. package/src/adapters/shared/hmr/hmr-manager.js +58 -70
  14. package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
  15. package/src/adapters/shared/http/api-request-pipeline.js +7 -7
  16. package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
  17. package/src/adapters/shared/http/dist-file-handler.js +172 -0
  18. package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
  19. package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
  20. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
  21. package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
  22. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
  23. package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
  24. package/src/adapters/shared/runtime/port-manager.js +19 -30
  25. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
  26. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
  27. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
  28. package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
  29. package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
  30. package/src/adapters/shared/runtime/server-static-builder.js +3 -3
  31. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
  32. package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
  33. package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
  34. package/src/assets/app-browser-client-build.js +1 -2
  35. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
  36. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
  37. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
  38. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
  39. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
  40. package/src/assets/browser-asset-output.d.ts +19 -0
  41. package/src/assets/browser-asset-output.js +30 -0
  42. package/src/assets/hashed-browser-asset.d.ts +8 -6
  43. package/src/assets/hashed-browser-asset.js +8 -6
  44. package/src/build/build-adapter.d.ts +2 -19
  45. package/src/build/build-adapter.js +0 -21
  46. package/src/build/build-graph.js +2 -2
  47. package/src/build/cache/cache-keys.d.ts +0 -3
  48. package/src/build/cache/cache-keys.js +0 -14
  49. package/src/build/cache/pages-unified-graph-build.js +2 -17
  50. package/src/build/contracts/build-contracts.d.ts +0 -3
  51. package/src/build/preserve-import-meta-transform.js +2 -2
  52. package/src/build/rolldown/app-package-declarations.js +3 -3
  53. package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
  54. package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
  55. package/src/build/rolldown/rolldown-build-adapter.js +1 -2
  56. package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
  57. package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
  58. package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
  59. package/src/build/runtime/build-queue.d.ts +8 -13
  60. package/src/build/runtime/build-queue.js +6 -17
  61. package/src/build/server/app-module-loader.service.d.ts +1 -1
  62. package/src/build/server/app-module-loader.service.js +0 -2
  63. package/src/build/server/page-module-import.service.d.ts +2 -3
  64. package/src/build/server/page-module-import.service.js +3 -4
  65. package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
  66. package/src/build/server-bundle-deploy-manifest.js +15 -1
  67. package/src/build/server-bundle-publication.js +4 -5
  68. package/src/build.d.ts +2 -2
  69. package/src/build.js +2 -2
  70. package/src/config/assembly/app-runtime.d.ts +2 -2
  71. package/src/config/assembly/app-runtime.js +2 -2
  72. package/src/config/assembly/finalize-config.d.ts +4 -4
  73. package/src/config/assembly/finalize-config.js +4 -5
  74. package/src/config/config-module-files.js +2 -3
  75. package/src/config/internal-types.d.ts +0 -7
  76. package/src/config/user-config-types.d.ts +0 -4
  77. package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
  78. package/src/diagnostics/request-pipeline-metrics.js +4 -4
  79. package/src/diagnostics/startup-trace.js +2 -5
  80. package/src/errors/http-error.d.ts +2 -2
  81. package/src/errors/http-error.js +4 -4
  82. package/src/hmr/client/hmr-runtime.js +16 -7
  83. package/src/hmr/client/module-update.d.ts +7 -0
  84. package/src/hmr/client/module-update.js +21 -4
  85. package/src/hmr/hmr-strategy.d.ts +0 -3
  86. package/src/hmr/hmr-strategy.js +0 -3
  87. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
  88. package/src/hmr/strategies/js-hmr-strategy.js +3 -6
  89. package/src/html-pages/html-page-module-scripts.js +4 -3
  90. package/src/html-pages/html-page-renderer.js +2 -3
  91. package/src/plugins/alias-resolver-cache.d.ts +4 -3
  92. package/src/plugins/alias-resolver-cache.js +4 -3
  93. package/src/plugins/component-import-discovery.js +4 -4
  94. package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
  95. package/src/plugins/eco-component-meta-plugin.js +66 -10
  96. package/src/plugins/foreign-jsx-override-plugin.js +4 -3
  97. package/src/plugins/tsconfig-import-resolver.js +12 -12
  98. package/src/route-renderer/error-pages/default-error-pages.js +2 -1
  99. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
  100. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
  101. package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
  102. package/src/route-renderer/orchestration/integration-renderer.js +13 -14
  103. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
  104. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
  105. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
  106. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
  107. package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
  108. package/src/route-renderer/page-loading/page-module-loader.js +1 -1
  109. package/src/route-renderer/route-renderer.d.ts +2 -5
  110. package/src/route-renderer/route-renderer.js +2 -4
  111. package/src/router/client/link-navigation-policy.d.ts +4 -1
  112. package/src/router/client/link-navigation-policy.js +20 -6
  113. package/src/router/server/route-registry.d.ts +0 -1
  114. package/src/router/server/route-registry.js +3 -13
  115. package/src/router/server/segment-path-matcher.d.ts +12 -0
  116. package/src/router/server/segment-path-matcher.js +30 -0
  117. package/src/static-site-generator/static-site-generator.d.ts +0 -5
  118. package/src/static-site-generator/static-site-generator.js +2 -15
  119. package/src/types/contracts.d.ts +17 -27
  120. package/src/types/public-types.d.ts +1 -1
  121. package/src/utils/format-error-chain.d.ts +9 -0
  122. package/src/utils/format-error-chain.js +20 -0
  123. package/src/utils/invariant.d.ts +6 -1
  124. package/src/utils/invariant.js +7 -2
  125. package/src/watchers/project-watcher.d.ts +20 -1
  126. package/src/watchers/project-watcher.js +40 -9
  127. package/src/watchers/workspace-package-watch-roots.js +5 -5
  128. package/src/adapters/README.md +0 -58
  129. package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
  130. package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
  131. package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
  132. package/src/adapters/shared/runtime/runtime-host.js +0 -1
  133. package/src/assets/README.md +0 -35
  134. package/src/build/README.md +0 -298
  135. package/src/build/server/README.md +0 -50
  136. package/src/cache/README.md +0 -5
  137. package/src/client/README.md +0 -5
  138. package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
  139. package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
  140. package/src/client/scroll.test.browser.d.ts +0 -1
  141. package/src/client/scroll.test.browser.js +0 -31
  142. package/src/client/view-transitions.test.browser.d.ts +0 -1
  143. package/src/client/view-transitions.test.browser.js +0 -53
  144. package/src/config/README.md +0 -58
  145. package/src/config/constants.d.ts +0 -1
  146. package/src/config/constants.js +0 -1
  147. package/src/dev/README.md +0 -61
  148. package/src/dev/invalidation/README.md +0 -11
  149. package/src/dev-toolbar/README.md +0 -66
  150. package/src/diagnostics/README.md +0 -11
  151. package/src/eco/README.md +0 -776
  152. package/src/errors/README.md +0 -5
  153. package/src/global/README.md +0 -5
  154. package/src/hmr/README.md +0 -64
  155. package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
  156. package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
  157. package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
  158. package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
  159. package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
  160. package/src/hmr/entrypoint-dependency-graph.js +0 -27
  161. package/src/hmr/hmr-file-change-prep.d.ts +0 -9
  162. package/src/hmr/hmr-file-change-prep.js +0 -11
  163. package/src/html/README.md +0 -15
  164. package/src/html-pages/README.md +0 -104
  165. package/src/islands/README.md +0 -44
  166. package/src/page-cache/README.md +0 -17
  167. package/src/plugins/README.md +0 -53
  168. package/src/route-renderer/GRAPH.md +0 -142
  169. package/src/route-renderer/README.md +0 -160
  170. package/src/route-renderer/error-pages/README.md +0 -11
  171. package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
  172. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
  173. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
  174. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
  175. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
  176. package/src/router/README.md +0 -160
  177. package/src/router/client/link-intent.test.browser.d.ts +0 -1
  178. package/src/router/client/link-intent.test.browser.js +0 -33
  179. package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
  180. package/src/router/client/link-navigation-policy.test.browser.js +0 -142
  181. package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
  182. package/src/router/client/navigation-commit.test.browser.js +0 -116
  183. package/src/router/client/navigation-document.test.browser.d.ts +0 -1
  184. package/src/router/client/navigation-document.test.browser.js +0 -77
  185. package/src/router/client/navigation-head.test.browser.d.ts +0 -1
  186. package/src/router/client/navigation-head.test.browser.js +0 -101
  187. package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
  188. package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
  189. package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
  190. package/src/router/client/navigation-view-transition.test.browser.js +0 -189
  191. package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
  192. package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
  193. package/src/static-site-generator/README.md +0 -67
  194. package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
  195. package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
  196. package/src/types/README.md +0 -5
  197. package/src/utils/README.md +0 -7
  198. package/src/validation/README.md +0 -9
  199. package/src/watchers/README.md +0 -15
  200. package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
  201. package/src/watchers/project-watcher.test-helpers.js +0 -108
@@ -21,7 +21,6 @@ export class ServerRequestPipeline {
21
21
  appConfig;
22
22
  runtime;
23
23
  watchMode;
24
- clientAbortDetector = () => false;
25
24
  router;
26
25
  fileSystemResponseMatcher;
27
26
  routeRendererFactory;
@@ -29,14 +28,12 @@ export class ServerRequestPipeline {
29
28
  apiRequestPipeline = new ApiRequestPipeline({
30
29
  getRenderContext: () => this.getRenderContext(),
31
30
  getCacheService: () => this.getCacheService(),
32
- isClientAbort: (error) => this.clientAbortDetector(error),
33
31
  });
34
32
  sharedPageCacheService;
35
33
  constructor(options) {
36
34
  this.appConfig = options.appConfig;
37
35
  this.runtime = options.runtime;
38
36
  this.watchMode = options.watch ?? false;
39
- this.clientAbortDetector = options.isClientAbortError ?? (() => false);
40
37
  }
41
38
  /** Renders one declared path inside the request build scope for a DevSession prewarm. */
42
39
  async renderDevPrewarmPath(pathname, runtimeOrigin) {
@@ -56,7 +53,6 @@ export class ServerRequestPipeline {
56
53
  }
57
54
  this.routeRendererFactory = new RouteRendererFactory({
58
55
  appConfig: this.appConfig,
59
- runtime: this.runtime,
60
56
  });
61
57
  }
62
58
  createWatchRefreshCallback(options) {
@@ -82,7 +78,7 @@ export class ServerRequestPipeline {
82
78
  /**
83
79
  * Scans the filesystem and dynamically constructs the Route Registry.
84
80
  *
85
- * This process runs identically across both Bun and Node wrappers. It analyzes the configured pages
81
+ * It analyzes the configured pages
86
82
  * directory, building a map of all available UI routes and API endpoints.
87
83
  * The resulting `RouteRegistry` instance becomes the central nervous system for mapping WinterCG incoming
88
84
  * Web Requests (`Request`) to their corresponding internal execution paths.
@@ -62,12 +62,12 @@ export declare class ServerStaticBuilder {
62
62
  */
63
63
  private prepareExportDirectory;
64
64
  /**
65
- * Empties `dist/`, copies the public directory into it and sets the Processors and Integrations up.
65
+ * Empties `dist/`, copies the public directory into it and sets the Processors up.
66
66
  *
67
67
  * @remarks
68
68
  * Call it before the router reads any Page, so a Page module that resolves what a Processor generates in
69
- * `setup()` finds it. The next {@link build} then skips this work once; a build without a prior call prepares
70
- * the export itself.
69
+ * `setup()` finds it. Integrations are set up later, when the static site generator starts rendering. The next
70
+ * {@link build} then skips this work once; a build without a prior call prepares the export itself.
71
71
  */
72
72
  prepareExport(): Promise<void>;
73
73
  private refreshRuntimeAssets;
@@ -54,12 +54,12 @@ export class ServerStaticBuilder {
54
54
  fileSystem.ensureDir(path.join(exportDir, RESOLVED_ASSETS_DIR));
55
55
  }
56
56
  /**
57
- * Empties `dist/`, copies the public directory into it and sets the Processors and Integrations up.
57
+ * Empties `dist/`, copies the public directory into it and sets the Processors up.
58
58
  *
59
59
  * @remarks
60
60
  * Call it before the router reads any Page, so a Page module that resolves what a Processor generates in
61
- * `setup()` finds it. The next {@link build} then skips this work once; a build without a prior call prepares
62
- * the export itself.
61
+ * `setup()` finds it. Integrations are set up later, when the static site generator starts rendering. The next
62
+ * {@link build} then skips this work once; a build without a prior call prepares the export itself.
63
63
  */
64
64
  async prepareExport() {
65
65
  this.prepareExportDirectory();
@@ -1,6 +1,7 @@
1
1
  import { WebSocketServer } from 'ws';
2
2
  import { HttpError } from '../../../errors/http-error.js';
3
3
  import { appLogger } from '../../../global/app-logger.js';
4
+ import { parseSearchParams } from '../../../router/server/parse-search-params.js';
4
5
  import { findWebSocketRoute } from './ws-pattern-matcher.js';
5
6
  import { createEcopagesSocket, invokeWebSocketHandlerHook, toWebSocketCloseInfo } from './websocket-lifecycle.js';
6
7
  const attachedUpgradeServers = new WeakSet();
@@ -112,7 +113,7 @@ export function attachNodeHttpWebSocketUpgrades(server, options) {
112
113
  return;
113
114
  }
114
115
  userWss.handleUpgrade(req, socket, head, (ws) => {
115
- const search = Object.fromEntries(url.searchParams.entries());
116
+ const search = parseSearchParams(url.searchParams);
116
117
  void setupNodeWebSocketConnection(ws, wsMatch, req, options.runtimeOrigin, search).catch((error) => {
117
118
  appLogger.error(`[WS:${wsMatch.kind}] unexpected error:`, error);
118
119
  ws.close(1011, 'internal error');
@@ -1,8 +1,8 @@
1
- import type { EcopagesSocket, WebSocketCloseInfo } from '../../../types/contracts.js';
1
+ import type { EcopagesSocket, PageQuery, WebSocketCloseInfo } from '../../../types/contracts.js';
2
2
  /**
3
3
  * @remarks
4
- * Bun and Node expose different raw socket types but share the same
5
- * {@link OutgoingWebSocketMessage} contract. Adapters supply only `send`/`close`;
4
+ * Adapters expose their raw socket through the
5
+ * {@link OutgoingWebSocketMessage} contract and supply only `send`/`close`;
6
6
  * {@link createEcopagesSocket} owns message normalization and stream forwarding.
7
7
  */
8
8
  export interface WebSocketSendTransport {
@@ -11,13 +11,12 @@ export interface WebSocketSendTransport {
11
11
  }
12
12
  /**
13
13
  * @remarks
14
- * Bun and Node adapters previously duplicated outgoing-message dispatch and
15
- * stream forwarding; this is the shared implementation both transports delegate to.
14
+ * Owns outgoing-message dispatch and stream forwarding for every transport.
16
15
  */
17
16
  export declare function createEcopagesSocket<TContext, TParams extends Record<string, string>>(transport: WebSocketSendTransport, meta: {
18
17
  kind: string;
19
18
  params: TParams;
20
- search: Record<string, string>;
19
+ search: PageQuery;
21
20
  context: TContext;
22
21
  }): EcopagesSocket<TContext, TParams>;
23
22
  export declare function toWebSocketCloseInfo(code: number, reason: string): WebSocketCloseInfo;
@@ -18,8 +18,7 @@ function sendOutgoingMessage(transport, message) {
18
18
  }
19
19
  /**
20
20
  * @remarks
21
- * Bun and Node adapters previously duplicated outgoing-message dispatch and
22
- * stream forwarding; this is the shared implementation both transports delegate to.
21
+ * Owns outgoing-message dispatch and stream forwarding for every transport.
23
22
  */
24
23
  export function createEcopagesSocket(transport, meta) {
25
24
  return {
@@ -1,6 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { contentHash } from '../utils/content-hash.js';
3
- import { realpathSync } from 'node:fs';
4
3
  import path from 'node:path';
5
4
  import { fileSystem } from '@ecopages/file-system';
6
5
  import { getBuildEntryOutput, collectBuildEntryInputPaths } from '../build/build-graph.js';
@@ -380,7 +379,7 @@ function collectHtmlScriptUrls(appConfig, result, htmlEntryNames) {
380
379
  for (const [script, entryName] of htmlEntryNames) {
381
380
  const output = getBuildEntryOutput(result, entryName, appConfig.rootDir);
382
381
  if (output) {
383
- urls.set(realpathSync(script), `/${path.relative(appConfig.absolutePaths.distDir, output).split(path.sep).join('/')}`);
382
+ urls.set(fileSystem.realpath(script), `/${path.relative(appConfig.absolutePaths.distDir, output).split(path.sep).join('/')}`);
384
383
  }
385
384
  }
386
385
  return urls;
@@ -1,5 +1,5 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { ResolverFactory } from 'oxc-resolver';
5
5
  import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-resolver.js';
@@ -43,12 +43,12 @@ function resolveLegacyPackageModuleEntry(options) {
43
43
  }
44
44
  try {
45
45
  const packageJsonPath = options.requireFromRoot.resolve(`${packageRoot}/package.json`);
46
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
46
+ const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
47
47
  if (packageJson.exports !== undefined || typeof packageJson.module !== 'string') {
48
48
  return undefined;
49
49
  }
50
50
  const modulePath = path.resolve(path.dirname(packageJsonPath), packageJson.module);
51
- return fs.existsSync(modulePath) ? modulePath : undefined;
51
+ return fileSystem.exists(modulePath) ? modulePath : undefined;
52
52
  }
53
53
  catch {
54
54
  return undefined;
@@ -92,7 +92,7 @@ export function resolveBrowserRuntimeEntryPath(options) {
92
92
  : resolvedPath.endsWith('.cts')
93
93
  ? `${resolvedPath.slice(0, -4)}.ts`
94
94
  : undefined;
95
- return esmSibling && fs.existsSync(esmSibling) ? esmSibling : resolvedPath;
95
+ return esmSibling && fileSystem.exists(esmSibling) ? esmSibling : resolvedPath;
96
96
  }
97
97
  catch {
98
98
  return undefined;
@@ -142,8 +142,8 @@ export function resolveBrowserRuntimeEntryImport(options) {
142
142
  export function inferBrowserRuntimeDefaultExportPolicy(options) {
143
143
  const { specifier, requireFromRoot, rootDir } = options;
144
144
  const entryPath = resolveBrowserRuntimeEntryPath({ specifier, requireFromRoot, rootDir });
145
- if (entryPath && fs.existsSync(entryPath)) {
146
- const source = fs.readFileSync(entryPath, 'utf8');
145
+ if (entryPath && fileSystem.exists(entryPath)) {
146
+ const source = fileSystem.readFileSync(entryPath);
147
147
  if (ESM_DEFAULT_EXPORT.test(source)) {
148
148
  return 'emit-default';
149
149
  }
@@ -171,10 +171,10 @@ export function inferBrowserRuntimeDefaultExportPolicy(options) {
171
171
  * files does not emit named ESM bindings such as `jsx`.
172
172
  */
173
173
  export function browserRuntimeEntryHasEsmExports(entryPath) {
174
- if (!entryPath || !fs.existsSync(entryPath)) {
174
+ if (!entryPath || !fileSystem.exists(entryPath)) {
175
175
  return true;
176
176
  }
177
- const source = fs.readFileSync(entryPath, 'utf8');
177
+ const source = fileSystem.readFileSync(entryPath);
178
178
  return ESM_DEFAULT_EXPORT.test(source) || ESM_NAMED_EXPORT.test(source);
179
179
  }
180
180
  /**
@@ -1,5 +1,5 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { createRequire } from 'node:module';
4
4
  import { DEFAULT_ECOPAGES_WORK_DIR } from '../../constants.js';
5
5
  import { browserRuntimeEntryHasEsmExports, inferBrowserRuntimeDefaultExportPolicy, listBrowserRuntimeCjsExportNames, resolveBrowserRuntimeEntryImport, resolveBrowserRuntimeEntryPath, } from './browser-runtime-entry-resolution.js';
@@ -23,7 +23,7 @@ export function createBrowserRuntimeEntryModule(options) {
23
23
  const rootDir = options.rootDir ?? process.cwd();
24
24
  const workDir = options.workDir ?? path.join(rootDir, DEFAULT_ECOPAGES_WORK_DIR);
25
25
  const artifactsDir = path.join(workDir, '.browser-runtime-entries', options.cacheDirName ?? 'ecopages-browser-runtime');
26
- fs.mkdirSync(artifactsDir, { recursive: true });
26
+ fileSystem.ensureDir(artifactsDir);
27
27
  const requireFromRoot = createRequire(path.join(rootDir, 'package.json'));
28
28
  const seenExports = new Set();
29
29
  const statements = [];
@@ -60,8 +60,8 @@ export function createBrowserRuntimeEntryModule(options) {
60
60
  }
61
61
  }
62
62
  const content = statements.join('\n');
63
- if (!fs.existsSync(filePath) || fs.readFileSync(filePath, 'utf-8') !== content) {
64
- fs.writeFileSync(filePath, content, 'utf-8');
63
+ if (!fileSystem.exists(filePath) || fileSystem.readFileSync(filePath) !== content) {
64
+ fileSystem.write(filePath, content);
65
65
  }
66
66
  return filePath;
67
67
  }
@@ -21,11 +21,14 @@ export declare class FileScriptProcessor extends BaseScriptProcessor<FileScriptA
21
21
  processGrouped(deps: FileScriptAsset[]): Promise<ProcessedAsset[]>;
22
22
  /**
23
23
  * @remarks
24
- * With HMR active, bundled scripts are built and watched by the HMR manager, which emits ES
25
- * modules. In production, `bundle: false` scripts are written under a hash of their bytes.
26
- * In development they are copied to their source-relative path so HMR can refresh them.
27
- * `classic` scripts are compiled on their own as classic scripts. Vendor runtimes keep their
28
- * stable names.
24
+ * With HMR active, a bundled script is built and watched by the HMR manager, which emits an ES
25
+ * module and serves the dev-transform URL. In production, a `bundle: false` script is written
26
+ * under a hash of its bytes. In development, a non-classic `bundle: false` file inside `srcDir`
27
+ * is copied to its source-relative path. A classic script inside `srcDir` is compiled and written
28
+ * under that path with a `.js` name. A file outside `srcDir` has no such path that stays inside
29
+ * `dist`: an unbundled or classic script is written under a content hash, and a bundled script
30
+ * is emitted in `dist/assets` under the bundler's `[name]-[hash]` name. Vendor runtimes inside
31
+ * `src` keep their stable names.
29
32
  */
30
33
  process(dep: FileScriptAsset): Promise<ProcessedAsset>;
31
34
  private processWithHmr;
@@ -33,9 +36,10 @@ export declare class FileScriptProcessor extends BaseScriptProcessor<FileScriptA
33
36
  private processBundledScript;
34
37
  /**
35
38
  * @remarks
36
- * The output keeps the source path and name, with a TypeScript extension turned into `.js`, as a
37
- * copied classic `.js` does. A second source file for the same output is rejected while the first
38
- * still exists, so a last write cannot silently win.
39
+ * The output keeps the source path and name when the file is inside `srcDir`, with a TypeScript
40
+ * extension turned into `.js`, as a copied classic `.js` does. A file outside `srcDir` is written
41
+ * under a content hash in `dist/assets`. A second source file for the same output is rejected while
42
+ * the first still exists, so a last write cannot silently win.
39
43
  *
40
44
  * @throws When the file cannot be a classic script, or another existing file is emitted to its output.
41
45
  */
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
- import { RESOLVED_ASSETS_DIR } from '../../../../constants.js';
3
2
  import { fileSystem } from '@ecopages/file-system';
3
+ import { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
4
4
  import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
5
5
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
6
6
  import { classicScriptOutputName, compileClassicScript } from './classic-script-compiler.js';
@@ -50,11 +50,14 @@ export class FileScriptProcessor extends BaseScriptProcessor {
50
50
  }
51
51
  /**
52
52
  * @remarks
53
- * With HMR active, bundled scripts are built and watched by the HMR manager, which emits ES
54
- * modules. In production, `bundle: false` scripts are written under a hash of their bytes.
55
- * In development they are copied to their source-relative path so HMR can refresh them.
56
- * `classic` scripts are compiled on their own as classic scripts. Vendor runtimes keep their
57
- * stable names.
53
+ * With HMR active, a bundled script is built and watched by the HMR manager, which emits an ES
54
+ * module and serves the dev-transform URL. In production, a `bundle: false` script is written
55
+ * under a hash of its bytes. In development, a non-classic `bundle: false` file inside `srcDir`
56
+ * is copied to its source-relative path. A classic script inside `srcDir` is compiled and written
57
+ * under that path with a `.js` name. A file outside `srcDir` has no such path that stays inside
58
+ * `dist`: an unbundled or classic script is written under a content hash, and a bundled script
59
+ * is emitted in `dist/assets` under the bundler's `[name]-[hash]` name. Vendor runtimes inside
60
+ * `src` keep their stable names.
58
61
  */
59
62
  async process(dep) {
60
63
  const hmrManager = this.getActiveHmrManager();
@@ -84,13 +87,15 @@ export class FileScriptProcessor extends BaseScriptProcessor {
84
87
  };
85
88
  }
86
89
  processUnbundledScript(dep, content) {
87
- const outFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
90
+ const outFilepath = sourceRelativeBrowserAssetPath(this.appConfig.absolutePaths.srcDir, dep.filepath);
88
91
  const output = dep.classic ? this.emitClassicScript(dep, outFilepath, content.toString()) : undefined;
89
92
  let filepath = output?.filepath;
90
93
  if (!dep.classic && !dep.inline) {
91
- if (dep.packageRole === 'runtime' || !this.isProduction) {
92
- filepath = path.join(this.getAssetsDir(), outFilepath);
93
- fileSystem.copyFile(dep.filepath, filepath);
94
+ if (outFilepath && (dep.packageRole === 'runtime' || !this.isProduction)) {
95
+ const destination = path.join(this.getAssetsDir(), outFilepath);
96
+ assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, destination);
97
+ fileSystem.copyFile(dep.filepath, destination);
98
+ filepath = destination;
94
99
  }
95
100
  else {
96
101
  filepath = writeHashedBrowserAsset({
@@ -114,12 +119,17 @@ export class FileScriptProcessor extends BaseScriptProcessor {
114
119
  };
115
120
  }
116
121
  async processBundledScript(dep) {
117
- const relativeFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
118
- const outdirPath = path.join(this.appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR, relativeFilepath);
122
+ const relativeFilepath = sourceRelativeBrowserAssetPath(this.appConfig.absolutePaths.srcDir, dep.filepath);
123
+ const outdir = relativeFilepath
124
+ ? path.dirname(path.join(this.getAssetsDir(), relativeFilepath))
125
+ : this.getAssetsDir();
126
+ if (relativeFilepath) {
127
+ assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, outdir);
128
+ }
119
129
  const bundlerOptions = this.getBundlerOptions(dep);
120
130
  const bundledOutput = await this.bundleScript({
121
131
  entrypoint: dep.filepath,
122
- outdir: path.dirname(outdirPath),
132
+ outdir,
123
133
  minify: this.isProduction,
124
134
  ...bundlerOptions,
125
135
  plugins: bundlerOptions.plugins,
@@ -139,9 +149,10 @@ export class FileScriptProcessor extends BaseScriptProcessor {
139
149
  }
140
150
  /**
141
151
  * @remarks
142
- * The output keeps the source path and name, with a TypeScript extension turned into `.js`, as a
143
- * copied classic `.js` does. A second source file for the same output is rejected while the first
144
- * still exists, so a last write cannot silently win.
152
+ * The output keeps the source path and name when the file is inside `srcDir`, with a TypeScript
153
+ * extension turned into `.js`, as a copied classic `.js` does. A file outside `srcDir` is written
154
+ * under a content hash in `dist/assets`. A second source file for the same output is rejected while
155
+ * the first still exists, so a last write cannot silently win.
145
156
  *
146
157
  * @throws When the file cannot be a classic script, or another existing file is emitted to its output.
147
158
  */
@@ -153,7 +164,16 @@ export class FileScriptProcessor extends BaseScriptProcessor {
153
164
  if (dep.inline) {
154
165
  return { code: compiled.code };
155
166
  }
167
+ if (!outFilepath) {
168
+ const filepath = writeHashedBrowserAsset({
169
+ bytes: compiled.code,
170
+ directory: this.getAssetsDir(),
171
+ extension: '.js',
172
+ });
173
+ return { code: compiled.code, filepath };
174
+ }
156
175
  const filepath = path.join(this.getAssetsDir(), classicScriptOutputName(outFilepath));
176
+ assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, filepath);
157
177
  const other = this.classicScriptSources.get(filepath);
158
178
  if (other !== undefined && other !== dep.filepath && fileSystem.exists(other)) {
159
179
  throw new Error(`${dep.filepath} and ${other} are both emitted as ${filepath}. Rename one of them.`);
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
+ import { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
3
4
  import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
4
5
  import { BaseProcessor } from '../base/base-processor.js';
5
6
  import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
@@ -13,14 +14,18 @@ export class FileStylesheetProcessor extends BaseProcessor {
13
14
  const processedContent = await applyStylesheetProcessors(this.appConfig, rawContent, dep.filepath);
14
15
  let filepath;
15
16
  if (!dep.inline) {
16
- filepath = this.isProduction
17
- ? writeHashedBrowserAsset({
17
+ const relativePath = sourceRelativeBrowserAssetPath(this.appConfig.absolutePaths.srcDir, dep.filepath);
18
+ const directory = this.getAssetsDir();
19
+ if (this.isProduction || !relativePath) {
20
+ filepath = writeHashedBrowserAsset({
18
21
  bytes: processedContent,
19
- directory: this.getAssetsDir(),
22
+ directory,
20
23
  extension: '.css',
21
- })
22
- : path.join(this.getAssetsDir(), path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath));
23
- if (!this.isProduction) {
24
+ });
25
+ }
26
+ else {
27
+ filepath = path.join(directory, relativePath);
28
+ assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, filepath);
24
29
  fileSystem.ensureDir(path.dirname(filepath));
25
30
  fileSystem.write(filepath, processedContent);
26
31
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Source-relative path of a file inside `srcDir`.
3
+ *
4
+ * @remarks
5
+ * `path.relative` from `srcDir` to a file outside it starts with `..`. Joining
6
+ * that onto `dist` writes the asset outside the build. Callers then emit the file
7
+ * in `dist/assets`: a bundled script under the bundler's `[name]-[hash]` name, and
8
+ * an unbundled script or stylesheet under a content hash.
9
+ */
10
+ export declare function sourceRelativeBrowserAssetPath(srcDir: string, filepath: string): string | undefined;
11
+ /**
12
+ * Throws when a browser output is not inside `distDir`.
13
+ *
14
+ * @remarks
15
+ * The public URL and the gzip pass already skip a file outside `dist`. A write
16
+ * that appends a source-relative path uses the same check, so the file is not
17
+ * created there either.
18
+ */
19
+ export declare function assertBrowserOutputInsideDist(distDir: string, outputPath: string): void;
@@ -0,0 +1,30 @@
1
+ import path from 'node:path';
2
+ import { isPathInside } from '../utils/path-containment.js';
3
+ /**
4
+ * Source-relative path of a file inside `srcDir`.
5
+ *
6
+ * @remarks
7
+ * `path.relative` from `srcDir` to a file outside it starts with `..`. Joining
8
+ * that onto `dist` writes the asset outside the build. Callers then emit the file
9
+ * in `dist/assets`: a bundled script under the bundler's `[name]-[hash]` name, and
10
+ * an unbundled script or stylesheet under a content hash.
11
+ */
12
+ export function sourceRelativeBrowserAssetPath(srcDir, filepath) {
13
+ if (!isPathInside(filepath, srcDir))
14
+ return undefined;
15
+ const relativePath = path.relative(srcDir, filepath);
16
+ return relativePath === '' ? undefined : relativePath;
17
+ }
18
+ /**
19
+ * Throws when a browser output is not inside `distDir`.
20
+ *
21
+ * @remarks
22
+ * The public URL and the gzip pass already skip a file outside `dist`. A write
23
+ * that appends a source-relative path uses the same check, so the file is not
24
+ * created there either.
25
+ */
26
+ export function assertBrowserOutputInsideDist(distDir, outputPath) {
27
+ if (!isPathInside(outputPath, distDir)) {
28
+ throw new Error(`Refusing to write ${outputPath} outside ${distDir}`);
29
+ }
30
+ }
@@ -9,14 +9,16 @@ export declare function recordHashedBrowserAsset(filePath: string): void;
9
9
  export declare function isHashedBrowserAsset(filePath: string): boolean;
10
10
  export declare function forgetHashedBrowserAsset(filePath: string): void;
11
11
  /**
12
- * Writes a production browser asset under a name derived from a hash of its
13
- * final bytes, and returns that path.
12
+ * Writes a browser asset under a name derived from a hash of its final bytes,
13
+ * and returns that path.
14
14
  *
15
15
  * @remarks
16
- * The same bytes always produce the same name, so an unchanged stylesheet keeps
17
- * its URL and a quality or source change gets a new URL. Development keeps
18
- * source-relative names so CSS HMR can refresh the same href. Vendor runtimes
19
- * keep their own stable names and must not go through this helper.
16
+ * The same bytes always produce the same name, so an unchanged file keeps its URL
17
+ * and a content change gets a new URL. Callers use it for production assets, and
18
+ * for a source file outside `srcDir` in development, because a source-relative
19
+ * path would leave `dist`. A file inside `srcDir` keeps its source-relative name
20
+ * in development so CSS HMR can refresh the same href. A vendor runtime inside
21
+ * `src` keeps its stable name and does not use this helper.
20
22
  */
21
23
  export declare function writeHashedBrowserAsset(options: {
22
24
  bytes: string | Buffer;
@@ -77,14 +77,16 @@ function normalizeExtension(extension) {
77
77
  return extension.startsWith('.') ? extension : `.${extension}`;
78
78
  }
79
79
  /**
80
- * Writes a production browser asset under a name derived from a hash of its
81
- * final bytes, and returns that path.
80
+ * Writes a browser asset under a name derived from a hash of its final bytes,
81
+ * and returns that path.
82
82
  *
83
83
  * @remarks
84
- * The same bytes always produce the same name, so an unchanged stylesheet keeps
85
- * its URL and a quality or source change gets a new URL. Development keeps
86
- * source-relative names so CSS HMR can refresh the same href. Vendor runtimes
87
- * keep their own stable names and must not go through this helper.
84
+ * The same bytes always produce the same name, so an unchanged file keeps its URL
85
+ * and a content change gets a new URL. Callers use it for production assets, and
86
+ * for a source file outside `srcDir` in development, because a source-relative
87
+ * path would leave `dist`. A file inside `srcDir` keeps its source-relative name
88
+ * in development so CSS HMR can refresh the same href. A vendor runtime inside
89
+ * `src` keeps its stable name and does not use this helper.
88
90
  */
89
91
  export function writeHashedBrowserAsset(options) {
90
92
  const buffer = typeof options.bytes === 'string' ? Buffer.from(options.bytes) : options.bytes;
@@ -9,25 +9,8 @@
9
9
  * - `BuildExecutor` — the runtime-facing facade; the app's `BuildQueue`,
10
10
  * stored on `AppRuntime.buildQueue`, implements it.
11
11
  */
12
- import { type BuildAdapter, type BuildOwnership } from './contracts/build-contracts.js';
13
- export type { BuildAdapter, BuildFormat, BuildChunk, BuildDependencyGraph, BuildExecutor, BuildFailure, BuildLog, BuildOptions, BuildOutput, BuildOwnership, BuildResult, BuildSourcemap, BuildSuccess, BuildTarget, BuildTranspileOptions, BuildEnvironment, } from './contracts/build-contracts.js';
12
+ import { type BuildAdapter } from './contracts/build-contracts.js';
13
+ export type { BuildAdapter, BuildFormat, BuildChunk, BuildDependencyGraph, BuildExecutor, BuildFailure, BuildLog, BuildOptions, BuildOutput, BuildResult, BuildSourcemap, BuildSuccess, BuildTarget, BuildTranspileOptions, BuildEnvironment, } from './contracts/build-contracts.js';
14
14
  /** Constructs the Rolldown build adapter. */
15
15
  export declare function createBuildAdapter(): BuildAdapter;
16
- /** The shared default-bundler backend instance. */
17
- export declare const defaultRolldownBuildAdapter: BuildAdapter;
18
- /**
19
- * Global default build adapter.
20
- *
21
- * @remarks
22
- * Resolves to the bundled default-bundler adapter. App-aware code reads `requireAppRuntime(appConfig).buildAdapter`.
23
- */
24
- export declare const defaultBuildAdapter: BuildAdapter;
25
- /** Resolves the default build adapter. */
26
- export declare function getDefaultBuildAdapter(): BuildAdapter;
27
- /**
28
- * Reads the {@link BuildOwnership} declared on a {@link BuildAdapter}.
29
- *
30
- * @param buildAdapter - When `undefined`, defaults to `'rolldown'`.
31
- */
32
- export declare function getBuildAdapterOwnership(buildAdapter: BuildAdapter | undefined): BuildOwnership;
33
16
  export { ensureIntegrationRuntimeReady, sealAppBuildManifest, setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './app-build-manifest-runtime.js';
@@ -15,25 +15,4 @@ import { createRolldownBuildAdapter } from './rolldown/rolldown-build-adapter.js
15
15
  export function createBuildAdapter() {
16
16
  return createRolldownBuildAdapter();
17
17
  }
18
- /** The shared default-bundler backend instance. */
19
- export const defaultRolldownBuildAdapter = createBuildAdapter();
20
- /**
21
- * Global default build adapter.
22
- *
23
- * @remarks
24
- * Resolves to the bundled default-bundler adapter. App-aware code reads `requireAppRuntime(appConfig).buildAdapter`.
25
- */
26
- export const defaultBuildAdapter = defaultRolldownBuildAdapter;
27
- /** Resolves the default build adapter. */
28
- export function getDefaultBuildAdapter() {
29
- return defaultRolldownBuildAdapter;
30
- }
31
- /**
32
- * Reads the {@link BuildOwnership} declared on a {@link BuildAdapter}.
33
- *
34
- * @param buildAdapter - When `undefined`, defaults to `'rolldown'`.
35
- */
36
- export function getBuildAdapterOwnership(buildAdapter) {
37
- return buildAdapter?.ownership ?? 'rolldown';
38
- }
39
18
  export { ensureIntegrationRuntimeReady, sealAppBuildManifest, setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './app-build-manifest-runtime.js';
@@ -1,9 +1,9 @@
1
- import { existsSync, realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  function tryRealpath(filePath) {
5
5
  try {
6
- return existsSync(filePath) ? realpathSync(filePath) : undefined;
6
+ return fileSystem.exists(filePath) ? fileSystem.realpath(filePath) : undefined;
7
7
  }
8
8
  catch {
9
9
  return undefined;
@@ -1,7 +1,4 @@
1
1
  import type { EcoBuildPlugin } from '../contracts/build-types.js';
2
- import type { BuildOptions } from '../contracts/build-contracts.js';
3
- /** Stable fingerprint for JSX options used in build and in-process cache keys. */
4
- export declare function createJsxCacheKey(jsx: BuildOptions['jsx']): string;
5
2
  /**
6
3
  * Stable fingerprint for ordered build plugins: each name, its environments and its
7
4
  * {@link EcoBuildPlugin.cacheKey}.
@@ -1,17 +1,3 @@
1
- /** Stable fingerprint for JSX options used in build and in-process cache keys. */
2
- export function createJsxCacheKey(jsx) {
3
- if (!jsx) {
4
- return 'jsx:default';
5
- }
6
- return JSON.stringify({
7
- development: jsx.development ?? false,
8
- factory: jsx.factory ?? null,
9
- fragment: jsx.fragment ?? null,
10
- importSource: jsx.importSource ?? null,
11
- runtime: jsx.runtime ?? null,
12
- sideEffects: jsx.sideEffects ?? null,
13
- });
14
- }
15
1
  /**
16
2
  * Stable fingerprint for ordered build plugins: each name, its environments and its
17
3
  * {@link EcoBuildPlugin.cacheKey}.