@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/package.json +212 -92
- package/src/adapters/abstract/application-adapter.d.ts +168 -0
- package/src/adapters/abstract/application-adapter.js +109 -0
- package/src/adapters/abstract/router-adapter.d.ts +26 -0
- package/src/adapters/abstract/router-adapter.js +5 -0
- package/src/adapters/abstract/server-adapter.d.ts +69 -0
- package/src/adapters/abstract/server-adapter.js +15 -0
- package/src/adapters/bun/client-bridge.d.ts +34 -0
- package/src/adapters/bun/client-bridge.js +48 -0
- package/src/adapters/bun/create-app.d.ts +60 -0
- package/src/adapters/bun/create-app.js +117 -0
- package/src/adapters/bun/hmr-manager.d.ts +143 -0
- package/src/adapters/bun/hmr-manager.js +334 -0
- package/src/adapters/bun/index.d.ts +2 -0
- package/src/adapters/bun/index.js +8 -0
- package/src/adapters/bun/server-adapter.d.ts +155 -0
- package/src/adapters/bun/server-adapter.js +373 -0
- package/src/adapters/bun/server-lifecycle.d.ts +63 -0
- package/src/adapters/bun/server-lifecycle.js +92 -0
- package/src/adapters/index.d.ts +6 -0
- package/src/adapters/index.js +14 -0
- package/src/adapters/node/bootstrap-dependency-resolver.d.ts +44 -0
- package/src/adapters/node/bootstrap-dependency-resolver.js +172 -0
- package/src/adapters/node/create-app.d.ts +21 -0
- package/src/adapters/node/create-app.js +143 -0
- package/src/adapters/node/index.d.ts +6 -0
- package/src/adapters/node/index.js +11 -0
- package/src/adapters/node/node-client-bridge.d.ts +26 -0
- package/src/adapters/node/node-client-bridge.js +66 -0
- package/src/adapters/node/node-hmr-manager.d.ts +133 -0
- package/src/adapters/node/node-hmr-manager.js +312 -0
- package/src/adapters/node/runtime-adapter.d.ts +46 -0
- package/src/adapters/node/runtime-adapter.js +306 -0
- package/src/adapters/node/server-adapter.d.ts +161 -0
- package/src/adapters/node/server-adapter.js +358 -0
- package/src/adapters/node/static-content-server.d.ts +60 -0
- package/src/adapters/node/static-content-server.js +194 -0
- package/src/adapters/node/write-runtime-manifest.d.ts +26 -0
- package/src/adapters/node/write-runtime-manifest.js +12 -0
- package/src/adapters/shared/api-response.d.ts +52 -0
- package/src/adapters/shared/api-response.js +96 -0
- package/src/adapters/shared/application-adapter.d.ts +18 -0
- package/src/adapters/shared/application-adapter.js +90 -0
- package/src/adapters/shared/define-api-handler.d.ts +25 -0
- package/src/adapters/shared/define-api-handler.js +15 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
- package/src/adapters/shared/explicit-static-route-matcher.js +103 -0
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
- package/src/adapters/shared/file-route-middleware-pipeline.js +99 -0
- package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
- package/src/adapters/shared/fs-server-response-factory.js +97 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +75 -0
- package/src/adapters/shared/fs-server-response-matcher.js +160 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +55 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.js +87 -0
- package/src/adapters/shared/hmr-html-response.d.ts +22 -0
- package/src/adapters/shared/hmr-html-response.js +32 -0
- package/src/adapters/shared/render-context.d.ts +14 -0
- package/src/adapters/shared/render-context.js +70 -0
- package/src/adapters/shared/runtime-bootstrap.d.ts +38 -0
- package/src/adapters/shared/runtime-bootstrap.js +43 -0
- package/src/adapters/shared/server-adapter.d.ts +97 -0
- package/src/adapters/shared/server-adapter.js +386 -0
- package/src/adapters/shared/server-route-handler.d.ts +89 -0
- package/src/adapters/shared/server-route-handler.js +111 -0
- package/src/adapters/shared/server-static-builder.d.ts +70 -0
- package/src/adapters/shared/server-static-builder.js +99 -0
- package/src/build/build-adapter.d.ts +186 -0
- package/src/build/build-adapter.js +168 -0
- package/src/build/build-manifest.d.ts +27 -0
- package/src/build/build-manifest.js +30 -0
- package/src/build/build-types.d.ts +57 -0
- package/src/build/build-types.js +0 -0
- package/src/build/dev-build-coordinator.d.ts +74 -0
- package/src/build/dev-build-coordinator.js +161 -0
- package/src/build/esbuild-build-adapter.d.ts +72 -0
- package/src/build/esbuild-build-adapter.js +422 -0
- package/src/build/runtime-build-executor.d.ts +13 -0
- package/src/build/runtime-build-executor.js +20 -0
- package/src/build/runtime-specifier-alias-plugin.d.ts +15 -0
- package/src/build/runtime-specifier-alias-plugin.js +31 -0
- package/src/config/config-builder.d.ts +238 -0
- package/src/config/config-builder.js +565 -0
- package/src/constants.d.ts +45 -0
- package/src/constants.js +25 -0
- package/src/create-app.d.ts +17 -0
- package/src/create-app.js +66 -0
- package/src/dev/sc-server.d.ts +30 -0
- package/src/dev/sc-server.js +111 -0
- package/src/eco/component-render-context.d.ts +105 -0
- package/src/eco/component-render-context.js +87 -0
- package/src/eco/eco.d.ts +9 -0
- package/src/eco/eco.js +114 -0
- package/src/eco/eco.types.d.ts +178 -0
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.utils.d.ts +40 -0
- package/src/eco/eco.utils.js +40 -0
- package/src/eco/global-injector-map.d.ts +16 -0
- package/src/eco/global-injector-map.js +80 -0
- package/src/eco/lazy-injector-map.d.ts +8 -0
- package/src/eco/lazy-injector-map.js +70 -0
- package/src/eco/module-dependencies.d.ts +18 -0
- package/src/eco/module-dependencies.js +49 -0
- package/src/errors/http-error.d.ts +31 -0
- package/src/errors/http-error.js +50 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +4 -0
- package/src/errors/locals-access-error.d.ts +4 -0
- package/src/errors/locals-access-error.js +9 -0
- package/src/global/app-logger.d.ts +2 -0
- package/src/global/app-logger.js +6 -0
- package/src/hmr/client/hmr-runtime.d.ts +5 -0
- package/src/hmr/client/hmr-runtime.js +109 -0
- package/src/hmr/hmr-strategy.d.ts +159 -0
- package/src/hmr/hmr-strategy.js +29 -0
- package/src/hmr/hmr.postcss.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.postcss.test.e2e.js +31 -0
- package/src/hmr/hmr.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.test.e2e.js +43 -0
- package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
- package/src/hmr/strategies/default-hmr-strategy.js +34 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +139 -0
- package/src/hmr/strategies/js-hmr-strategy.js +178 -0
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +4 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +10 -0
- package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
- package/src/integrations/ghtml/ghtml-renderer.js +62 -0
- package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
- package/src/integrations/ghtml/ghtml.plugin.js +21 -0
- package/src/internal-types.d.ts +221 -0
- package/src/internal-types.js +0 -0
- package/src/plugins/alias-resolver-plugin.d.ts +2 -0
- package/src/plugins/alias-resolver-plugin.js +53 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +97 -0
- package/src/plugins/eco-component-meta-plugin.js +157 -0
- package/src/plugins/integration-plugin.d.ts +136 -0
- package/src/plugins/integration-plugin.js +133 -0
- package/src/plugins/processor.d.ts +95 -0
- package/src/plugins/processor.js +136 -0
- package/src/plugins/runtime-capability.d.ts +9 -0
- package/src/plugins/runtime-capability.js +0 -0
- package/src/public-types.d.ts +1149 -0
- package/src/public-types.js +0 -0
- package/src/route-renderer/component-graph/component-graph-executor.d.ts +32 -0
- package/src/route-renderer/component-graph/component-graph-executor.js +31 -0
- package/src/route-renderer/component-graph/component-graph.d.ts +42 -0
- package/src/route-renderer/component-graph/component-graph.js +72 -0
- package/src/route-renderer/component-graph/component-marker.d.ts +52 -0
- package/src/route-renderer/component-graph/component-marker.js +46 -0
- package/src/route-renderer/component-graph/component-reference.d.ts +10 -0
- package/src/route-renderer/component-graph/component-reference.js +19 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +77 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.js +95 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +372 -0
- package/src/route-renderer/orchestration/integration-renderer.js +589 -0
- package/src/route-renderer/orchestration/render-execution.service.d.ts +103 -0
- package/src/route-renderer/orchestration/render-execution.service.js +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.js +332 -0
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +35 -0
- package/src/route-renderer/page-loading/dependency-resolver.js +442 -0
- package/src/route-renderer/page-loading/page-module-loader.d.ts +87 -0
- package/src/route-renderer/page-loading/page-module-loader.js +124 -0
- package/src/route-renderer/route-renderer.d.ts +61 -0
- package/src/route-renderer/route-renderer.js +87 -0
- package/src/router/client/link-intent.js +34 -0
- package/src/router/client/link-intent.test.browser.d.ts +1 -0
- package/src/router/client/link-intent.test.browser.js +43 -0
- package/src/router/client/navigation-coordinator.d.ts +149 -0
- package/src/router/client/navigation-coordinator.js +215 -0
- package/src/router/server/fs-router-scanner.d.ts +41 -0
- package/src/router/server/fs-router-scanner.js +156 -0
- package/src/router/server/fs-router.d.ts +26 -0
- package/src/router/server/fs-router.js +100 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.js +331 -0
- package/src/services/assets/asset-processing-service/asset.factory.d.ts +17 -0
- package/src/services/assets/asset-processing-service/asset.factory.js +82 -0
- package/src/services/assets/asset-processing-service/assets.types.d.ts +89 -0
- package/src/services/assets/asset-processing-service/assets.types.js +0 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +55 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +48 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +20 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +41 -0
- package/src/services/assets/asset-processing-service/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/index.js +5 -0
- package/src/services/assets/asset-processing-service/processor.interface.d.ts +22 -0
- package/src/services/assets/asset-processing-service/processor.interface.js +6 -0
- package/src/services/assets/asset-processing-service/processor.registry.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processor.registry.js +15 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +24 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.js +64 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +17 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +72 -0
- package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/index.js +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +57 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +76 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +75 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +66 -0
- package/src/services/assets/browser-bundle.service.d.ts +32 -0
- package/src/services/assets/browser-bundle.service.js +33 -0
- package/src/services/cache/cache.types.d.ts +107 -0
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/index.d.ts +7 -0
- package/src/services/cache/index.js +7 -0
- package/src/services/cache/memory-cache-store.d.ts +42 -0
- package/src/services/cache/memory-cache-store.js +98 -0
- package/src/services/cache/page-cache-service.d.ts +70 -0
- package/src/services/cache/page-cache-service.js +152 -0
- package/src/services/cache/page-request-cache-coordinator.service.d.ts +75 -0
- package/src/services/cache/page-request-cache-coordinator.service.js +109 -0
- package/src/services/html/html-rewriter-provider.service.d.ts +37 -0
- package/src/services/html/html-rewriter-provider.service.js +65 -0
- package/src/services/html/html-transformer.service.d.ts +77 -0
- package/src/services/html/html-transformer.service.js +221 -0
- package/src/services/invalidation/development-invalidation.service.d.ts +74 -0
- package/src/services/invalidation/development-invalidation.service.js +189 -0
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +16 -0
- package/src/services/module-loading/app-server-module-transpiler.service.js +34 -0
- package/src/services/module-loading/page-module-import.service.d.ts +71 -0
- package/src/services/module-loading/page-module-import.service.js +132 -0
- package/src/services/module-loading/server-loader.service.d.ts +96 -0
- package/src/services/module-loading/server-loader.service.js +32 -0
- package/src/services/module-loading/server-module-transpiler.service.d.ts +69 -0
- package/src/services/module-loading/server-module-transpiler.service.js +61 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.d.ts +35 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.js +60 -0
- package/src/services/runtime-state/dev-graph.service.d.ts +118 -0
- package/src/services/runtime-state/dev-graph.service.js +162 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +41 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +69 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.js +37 -0
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +26 -0
- package/src/services/runtime-state/server-invalidation-state.service.js +35 -0
- package/src/services/validation/schema-validation-service.d.ts +122 -0
- package/src/services/validation/schema-validation-service.js +101 -0
- package/src/services/validation/standard-schema.types.d.ts +65 -0
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/static-site-generator/static-site-generator.d.ts +109 -0
- package/src/static-site-generator/static-site-generator.js +353 -0
- package/src/utils/css.d.ts +1 -0
- package/src/utils/css.js +7 -0
- package/src/utils/deep-merge.d.ts +14 -0
- package/src/utils/deep-merge.js +32 -0
- package/src/utils/hash.d.ts +1 -0
- package/src/utils/hash.js +7 -0
- package/src/utils/html.d.ts +1 -0
- package/src/utils/html.js +4 -0
- package/src/utils/invariant.d.ts +5 -0
- package/src/utils/invariant.js +11 -0
- package/src/utils/locals-utils.d.ts +15 -0
- package/src/utils/locals-utils.js +24 -0
- package/src/utils/parse-cli-args.d.ts +24 -0
- package/src/utils/parse-cli-args.js +47 -0
- package/src/utils/path-utils.module.d.ts +5 -0
- package/src/utils/path-utils.module.js +14 -0
- package/src/utils/resolve-work-dir.d.ts +11 -0
- package/src/utils/resolve-work-dir.js +31 -0
- package/src/utils/runtime.d.ts +11 -0
- package/src/utils/runtime.js +40 -0
- package/src/utils/server-utils.module.d.ts +19 -0
- package/src/utils/server-utils.module.js +56 -0
- package/src/watchers/project-watcher.d.ts +136 -0
- package/src/watchers/project-watcher.js +281 -0
- package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
- package/src/watchers/project-watcher.test-helpers.js +52 -0
- package/src/adapters/bun/hmr-manager.test.ts +0 -267
- package/src/adapters/node/bootstrap-dependency-resolver.test.ts +0 -282
- package/src/adapters/node/node-client-bridge.test.ts +0 -198
- package/src/adapters/node/node-hmr-manager.test.ts +0 -322
- package/src/adapters/node/runtime-adapter.test.ts +0 -868
- package/src/adapters/node/static-content-server.test.ts +0 -60
- package/src/adapters/shared/api-response.test.ts +0 -97
- package/src/adapters/shared/explicit-static-route-matcher.test.ts +0 -381
- package/src/adapters/shared/file-route-middleware-pipeline.test.ts +0 -90
- package/src/adapters/shared/fs-server-response-factory.test.ts +0 -187
- package/src/adapters/shared/fs-server-response-matcher.test.ts +0 -286
- package/src/adapters/shared/hmr-manager.contract.test.ts +0 -196
- package/src/adapters/shared/hmr-manager.dispatch.test.ts +0 -220
- package/src/adapters/shared/render-context.test.ts +0 -146
- package/src/adapters/shared/server-adapter.test.ts +0 -77
- package/src/adapters/shared/server-route-handler.test.ts +0 -110
- package/src/adapters/shared/server-static-builder.test.ts +0 -316
- package/src/build/build-adapter-serialization.test.ts +0 -268
- package/src/build/build-adapter.test.ts +0 -815
- package/src/build/runtime-specifier-alias-plugin.test.ts +0 -43
- package/src/config/config-builder.test.ts +0 -410
- package/src/eco/eco.test.ts +0 -678
- package/src/eco/eco.utils.test.ts +0 -124
- package/src/eco/global-injector-map.test.ts +0 -42
- package/src/eco/lazy-injector-map.test.ts +0 -66
- package/src/eco/module-dependencies.test.ts +0 -30
- package/src/errors/http-error.test.ts +0 -134
- package/src/global/utils.test.ts +0 -12
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
- package/src/hmr/hmr-strategy.test.ts +0 -124
- package/src/hmr/strategies/js-hmr-strategy.test.ts +0 -335
- package/src/integrations/ghtml/ghtml-renderer.test.ts +0 -63
- package/src/plugins/alias-resolver-plugin.test.ts +0 -41
- package/src/plugins/eco-component-meta-plugin.test.ts +0 -380
- package/src/plugins/integration-plugin.test.ts +0 -111
- package/src/plugins/processor.test.ts +0 -148
- package/src/route-renderer/component-graph/component-graph-executor.test.ts +0 -41
- package/src/route-renderer/component-graph/component-graph.test.ts +0 -63
- package/src/route-renderer/component-graph/component-marker.test.ts +0 -73
- package/src/route-renderer/component-graph/marker-graph-resolver.test.ts +0 -135
- package/src/route-renderer/orchestration/integration-renderer.test.ts +0 -936
- package/src/route-renderer/orchestration/render-execution.service.test.ts +0 -97
- package/src/route-renderer/orchestration/render-preparation.service.test.ts +0 -235
- package/src/route-renderer/page-loading/dependency-resolver.test.ts +0 -345
- package/src/route-renderer/page-loading/page-module-loader.test.ts +0 -96
- package/src/router/client/navigation-coordinator.test.ts +0 -237
- package/src/router/server/fs-router-scanner.test.ts +0 -83
- package/src/router/server/fs-router.test.ts +0 -214
- package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +0 -385
- package/src/services/assets/asset-processing-service/asset.factory.test.ts +0 -63
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +0 -72
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +0 -67
- package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +0 -59
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +0 -286
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +0 -227
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +0 -199
- package/src/services/assets/browser-bundle.service.test.ts +0 -36
- package/src/services/cache/memory-cache-store.test.ts +0 -225
- package/src/services/cache/page-cache-service.test.ts +0 -175
- package/src/services/cache/page-request-cache-coordinator.service.test.ts +0 -79
- package/src/services/html/html-rewriter-provider.service.test.ts +0 -183
- package/src/services/html/html-transformer.service.test.ts +0 -378
- package/src/services/invalidation/development-invalidation.service.test.ts +0 -77
- package/src/services/module-loading/page-module-import.service.test.ts +0 -253
- package/src/services/module-loading/server-loader.service.test.ts +0 -161
- package/src/services/module-loading/server-module-transpiler.service.test.ts +0 -115
- package/src/services/runtime-manifest/node-runtime-manifest.service.test.ts +0 -95
- package/src/services/validation/schema-validation-service.test.ts +0 -223
- package/src/static-site-generator/static-site-generator.test.ts +0 -307
- package/src/utils/deep-merge.test.ts +0 -114
- package/src/utils/invariant.test.ts +0 -22
- package/src/utils/path-utils.test.ts +0 -15
- package/src/utils/server-utils.test.ts +0 -38
- package/src/watchers/project-watcher.integration.test.ts +0 -337
- package/src/watchers/project-watcher.test.ts +0 -678
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
2
|
+
import { HttpError } from "../../errors/http-error.js";
|
|
3
|
+
import { createRequire } from "../../utils/locals-utils.js";
|
|
4
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
5
|
+
import { SharedServerAdapter } from "../shared/server-adapter.js";
|
|
6
|
+
import { ApiResponseBuilder } from "../shared/api-response.js";
|
|
7
|
+
import { installSharedRuntimeBuildExecutor } from "../shared/runtime-bootstrap.js";
|
|
8
|
+
import { ServerRouteHandler } from "../shared/server-route-handler.js";
|
|
9
|
+
import { ServerStaticBuilder } from "../shared/server-static-builder";
|
|
10
|
+
import {
|
|
11
|
+
injectHmrRuntimeIntoHtmlResponse,
|
|
12
|
+
isHtmlResponse,
|
|
13
|
+
shouldInjectHmrHtmlResponse
|
|
14
|
+
} from "../shared/hmr-html-response";
|
|
15
|
+
import { ClientBridge } from "./client-bridge";
|
|
16
|
+
import { HmrManager } from "./hmr-manager";
|
|
17
|
+
import { ServerLifecycle } from "./server-lifecycle.js";
|
|
18
|
+
class BunServerAdapter extends SharedServerAdapter {
|
|
19
|
+
apiHandlers;
|
|
20
|
+
staticRoutes;
|
|
21
|
+
errorHandler;
|
|
22
|
+
bridge;
|
|
23
|
+
lifecycle;
|
|
24
|
+
hmrManager;
|
|
25
|
+
initializationPromise = null;
|
|
26
|
+
fullyInitialized = false;
|
|
27
|
+
lifecycleFactory;
|
|
28
|
+
staticBuilderFactory;
|
|
29
|
+
routeHandlerFactory;
|
|
30
|
+
hmrManagerFactory;
|
|
31
|
+
bridgeFactory;
|
|
32
|
+
constructor({
|
|
33
|
+
appConfig,
|
|
34
|
+
runtimeOrigin,
|
|
35
|
+
serveOptions,
|
|
36
|
+
apiHandlers,
|
|
37
|
+
staticRoutes,
|
|
38
|
+
errorHandler,
|
|
39
|
+
options,
|
|
40
|
+
lifecycle,
|
|
41
|
+
staticBuilderFactory,
|
|
42
|
+
routeHandlerFactory,
|
|
43
|
+
hmrManager,
|
|
44
|
+
bridge
|
|
45
|
+
}) {
|
|
46
|
+
super({ appConfig, runtimeOrigin, serveOptions, options });
|
|
47
|
+
this.apiHandlers = apiHandlers || [];
|
|
48
|
+
this.staticRoutes = staticRoutes || [];
|
|
49
|
+
this.errorHandler = errorHandler;
|
|
50
|
+
this.lifecycleFactory = lifecycle;
|
|
51
|
+
this.staticBuilderFactory = staticBuilderFactory;
|
|
52
|
+
this.routeHandlerFactory = routeHandlerFactory;
|
|
53
|
+
this.hmrManagerFactory = hmrManager;
|
|
54
|
+
this.bridgeFactory = bridge;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Determines if HMR script should be injected.
|
|
58
|
+
* Only injects in watch mode when HMR manager is enabled.
|
|
59
|
+
*/
|
|
60
|
+
shouldInjectHmrScript() {
|
|
61
|
+
return shouldInjectHmrHtmlResponse(this.options?.watch === true, this.hmrManager);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a response contains HTML content.
|
|
65
|
+
*/
|
|
66
|
+
isHtmlResponse(response) {
|
|
67
|
+
return isHtmlResponse(response);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Injects HMR script into HTML responses in development mode.
|
|
71
|
+
* Ensures explicit API handlers that return HTML get auto-reload capability.
|
|
72
|
+
*/
|
|
73
|
+
async maybeInjectHmrScript(response) {
|
|
74
|
+
if (this.shouldInjectHmrScript() && this.isHtmlResponse(response)) {
|
|
75
|
+
return injectHmrRuntimeIntoHtmlResponse(response);
|
|
76
|
+
}
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Initializes the server adapter's core components.
|
|
81
|
+
* Delegates to ServerLifecycle for setup.
|
|
82
|
+
*/
|
|
83
|
+
async initialize() {
|
|
84
|
+
installSharedRuntimeBuildExecutor(this.appConfig, {
|
|
85
|
+
development: this.options?.watch === true
|
|
86
|
+
});
|
|
87
|
+
this.bridge = this.bridgeFactory ?? new ClientBridge();
|
|
88
|
+
this.hmrManager = this.hmrManagerFactory ?? new HmrManager({ appConfig: this.appConfig, bridge: this.bridge });
|
|
89
|
+
this.lifecycle = this.lifecycleFactory ?? new ServerLifecycle({
|
|
90
|
+
appConfig: this.appConfig,
|
|
91
|
+
runtimeOrigin: this.runtimeOrigin,
|
|
92
|
+
hmrManager: this.hmrManager,
|
|
93
|
+
bridge: this.bridge
|
|
94
|
+
});
|
|
95
|
+
this.staticSiteGenerator = await this.lifecycle.initialize();
|
|
96
|
+
const staticBuilderOptions = {
|
|
97
|
+
appConfig: this.appConfig,
|
|
98
|
+
staticSiteGenerator: this.staticSiteGenerator,
|
|
99
|
+
serveOptions: this.serveOptions,
|
|
100
|
+
apiHandlers: this.apiHandlers
|
|
101
|
+
};
|
|
102
|
+
this.staticBuilder = this.staticBuilderFactory ? this.staticBuilderFactory(staticBuilderOptions) : new ServerStaticBuilder(staticBuilderOptions);
|
|
103
|
+
await this.lifecycle.initializePlugins({ watch: this.options?.watch });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Refreshes the router routes during watch mode.
|
|
107
|
+
*/
|
|
108
|
+
async refreshRouterRoutes() {
|
|
109
|
+
if (!this.serverInstance || typeof this.serverInstance.reload !== "function") {
|
|
110
|
+
appLogger.error("Server instance is not available for reloading");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
await this.createSharedWatchRefreshCallback({
|
|
114
|
+
staticRoutes: this.staticRoutes,
|
|
115
|
+
hmrManager: this.hmrManager,
|
|
116
|
+
onRoutesReady: () => {
|
|
117
|
+
const options = this.getServerOptions({ enableHmr: true });
|
|
118
|
+
this.serverInstance.reload(options);
|
|
119
|
+
appLogger.debug("Server routes updated with dynamic routes");
|
|
120
|
+
},
|
|
121
|
+
onError: (error) => {
|
|
122
|
+
this.hmrManager.broadcast({ type: "error", message: error.message });
|
|
123
|
+
appLogger.error("Failed to refresh router routes:", error);
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
}
|
|
127
|
+
async watch() {
|
|
128
|
+
await this.lifecycle.startWatching({
|
|
129
|
+
refreshRouterRoutesCallback: this.refreshRouterRoutes.bind(this)
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves the current server options, optionally enabling HMR.
|
|
134
|
+
* If HMR is enabled, modifies fetch to handle WebSocket upgrades and serve HMR runtime.
|
|
135
|
+
* Ensures original fetch logic is preserved and called for non-HMR requests.
|
|
136
|
+
* @param options.enableHmr Whether to enable Hot Module Replacement
|
|
137
|
+
*/
|
|
138
|
+
getServerOptions({ enableHmr = false } = {}) {
|
|
139
|
+
appLogger.debug(`[BunServerAdapter] getServerOptions called with enableHmr: ${enableHmr}`);
|
|
140
|
+
const serverOptions = this.buildServerSettings();
|
|
141
|
+
if (enableHmr) {
|
|
142
|
+
const originalFetch = serverOptions.fetch;
|
|
143
|
+
const hmrHandler = this.hmrManager.getWebSocketHandler();
|
|
144
|
+
const hmrManager = this.hmrManager;
|
|
145
|
+
serverOptions.development = true;
|
|
146
|
+
serverOptions.websocket = hmrHandler;
|
|
147
|
+
serverOptions.fetch = async function(request, _server) {
|
|
148
|
+
const url = new URL(request.url);
|
|
149
|
+
appLogger.debug(`[HMR] Request: ${url.pathname}`);
|
|
150
|
+
if (url.pathname === "/_hmr") {
|
|
151
|
+
const success = this.upgrade(request, {
|
|
152
|
+
data: void 0
|
|
153
|
+
});
|
|
154
|
+
if (success) return;
|
|
155
|
+
return new Response("WebSocket upgrade failed", { status: 400 });
|
|
156
|
+
}
|
|
157
|
+
if (url.pathname === "/_hmr_runtime.js") {
|
|
158
|
+
appLogger.debug(`[HMR] Serving runtime from ${hmrManager.getRuntimePath()}`);
|
|
159
|
+
return new Response(fileSystem.readFileAsBuffer(hmrManager.getRuntimePath()), {
|
|
160
|
+
headers: { "Content-Type": "application/javascript" }
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
let response;
|
|
164
|
+
if (originalFetch) {
|
|
165
|
+
const res = await originalFetch.call(this, request, this);
|
|
166
|
+
response = res instanceof Response ? res : new Response("Not Found", { status: 404 });
|
|
167
|
+
} else {
|
|
168
|
+
response = new Response("Not Found", { status: 404 });
|
|
169
|
+
}
|
|
170
|
+
return response;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return serverOptions;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Helper method to retrieve and parse the request body.
|
|
177
|
+
* Handles JSON and plain text content types.
|
|
178
|
+
* For FormData (multipart/form-data, x-www-form-urlencoded), use ctx.request.formData() directly.
|
|
179
|
+
* Returns undefined for unsupported content types.
|
|
180
|
+
*/
|
|
181
|
+
async retrieveBodyFromRequest(request) {
|
|
182
|
+
const contentType = request.headers.get("Content-Type") || "";
|
|
183
|
+
if (contentType.includes("application/json")) {
|
|
184
|
+
return await request.json();
|
|
185
|
+
}
|
|
186
|
+
if (contentType.includes("text/plain")) {
|
|
187
|
+
return await request.text();
|
|
188
|
+
}
|
|
189
|
+
return void 0;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates complete server configuration with request handling.
|
|
193
|
+
* @returns Server options ready for Bun.serve()
|
|
194
|
+
*/
|
|
195
|
+
buildServerSettings() {
|
|
196
|
+
const serverOptions = { ...this.serveOptions };
|
|
197
|
+
const handleNoMatch = this.handleNoMatch.bind(this);
|
|
198
|
+
const waitForInit = this.waitForInitialization.bind(this);
|
|
199
|
+
const handleReq = this.handleRequest.bind(this);
|
|
200
|
+
const errorHandler = this.errorHandler;
|
|
201
|
+
const getCacheService = () => this.getCacheService();
|
|
202
|
+
const getRenderContext = () => this.getRenderContext();
|
|
203
|
+
appLogger.debug(`[BunServerAdapter] Building server settings`);
|
|
204
|
+
const finalOptions = {
|
|
205
|
+
...serverOptions,
|
|
206
|
+
async fetch(request, _server) {
|
|
207
|
+
try {
|
|
208
|
+
await waitForInit();
|
|
209
|
+
return await handleReq(request);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (error instanceof Response) return error;
|
|
212
|
+
if (errorHandler) {
|
|
213
|
+
try {
|
|
214
|
+
const locals = {};
|
|
215
|
+
const context = {
|
|
216
|
+
request,
|
|
217
|
+
params: {},
|
|
218
|
+
response: new ApiResponseBuilder(),
|
|
219
|
+
server: _server,
|
|
220
|
+
locals,
|
|
221
|
+
require: createRequire(() => locals),
|
|
222
|
+
services: {
|
|
223
|
+
cache: getCacheService()
|
|
224
|
+
},
|
|
225
|
+
...getRenderContext()
|
|
226
|
+
};
|
|
227
|
+
return await errorHandler(error, context);
|
|
228
|
+
} catch (handlerError) {
|
|
229
|
+
appLogger.error(`[ecopages] Error in custom error handler: ${handlerError}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (error instanceof HttpError) return error.toResponse();
|
|
233
|
+
appLogger.error(`[ecopages] Error handling request: ${error}`);
|
|
234
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
error(error) {
|
|
238
|
+
appLogger.error(`[ecopages] Error handling request: ${error}`);
|
|
239
|
+
return handleNoMatch(new Request("http://localhost"));
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return finalOptions;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generates a static build of the site for deployment.
|
|
246
|
+
* @param options.preview - If true, starts a preview server after build
|
|
247
|
+
*/
|
|
248
|
+
async buildStatic(options) {
|
|
249
|
+
if (!this.fullyInitialized) {
|
|
250
|
+
await this.initializeSharedRouteHandling({
|
|
251
|
+
staticRoutes: this.staticRoutes,
|
|
252
|
+
hmrManager: this.hmrManager
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
await this.staticBuilder.build(options, {
|
|
256
|
+
router: this.router,
|
|
257
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
258
|
+
staticRoutes: this.staticRoutes
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Initializes the server with dynamic routes after server creation.
|
|
263
|
+
* Must be called before handling any requests.
|
|
264
|
+
* @param server - The Bun server instance
|
|
265
|
+
*/
|
|
266
|
+
async completeInitialization(server) {
|
|
267
|
+
if (this.fullyInitialized) {
|
|
268
|
+
if (server && !this.serverInstance) {
|
|
269
|
+
this.serverInstance = server;
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!this.initializationPromise) {
|
|
274
|
+
this.initializationPromise = this._performInitialization(server ?? null);
|
|
275
|
+
}
|
|
276
|
+
return this.initializationPromise;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Performs complete server setup including routing, watchers, and HMR.
|
|
280
|
+
*/
|
|
281
|
+
async _performInitialization(server) {
|
|
282
|
+
this.serverInstance = server;
|
|
283
|
+
appLogger.debug("Completing server initialization with dynamic routes");
|
|
284
|
+
await this.initializeSharedRouteHandling({
|
|
285
|
+
staticRoutes: this.staticRoutes,
|
|
286
|
+
hmrManager: this.hmrManager
|
|
287
|
+
});
|
|
288
|
+
this.fullyInitialized = true;
|
|
289
|
+
if (this.options?.watch) await this.watch();
|
|
290
|
+
if (server && typeof server.reload === "function") {
|
|
291
|
+
const updatedOptions = this.getServerOptions(this.options?.watch ? { enableHmr: true } : void 0);
|
|
292
|
+
server.reload(updatedOptions);
|
|
293
|
+
appLogger.debug("Server routes updated with dynamic routes");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Creates and initializes the Bun server adapter.
|
|
298
|
+
* @returns Configured adapter with server methods
|
|
299
|
+
*/
|
|
300
|
+
async createAdapter() {
|
|
301
|
+
await this.initialize();
|
|
302
|
+
return {
|
|
303
|
+
getServerOptions: this.getServerOptions.bind(this),
|
|
304
|
+
buildStatic: this.buildStatic.bind(this),
|
|
305
|
+
completeInitialization: this.completeInitialization.bind(this),
|
|
306
|
+
handleRequest: this.handleRequest.bind(this)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Handles HTTP requests by passing them securely to the shared core router adapter.
|
|
311
|
+
*/
|
|
312
|
+
async handleRequest(request) {
|
|
313
|
+
const response = await this.handleSharedRequest(request, {
|
|
314
|
+
apiHandlers: this.apiHandlers,
|
|
315
|
+
errorHandler: this.errorHandler,
|
|
316
|
+
serverInstance: this.serverInstance,
|
|
317
|
+
hmrManager: this.hmrManager
|
|
318
|
+
});
|
|
319
|
+
return await this.maybeInjectHmrScript(response);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Ensures server initialization completes before request handling.
|
|
323
|
+
* Prevents race conditions during startup.
|
|
324
|
+
*/
|
|
325
|
+
async waitForInitialization() {
|
|
326
|
+
if (this.fullyInitialized) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (this.initializationPromise) {
|
|
330
|
+
return this.initializationPromise;
|
|
331
|
+
}
|
|
332
|
+
throw new Error("Server not initialized. Call completeInitialization() first.");
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Handles HTTP requests from the router adapter.
|
|
336
|
+
*/
|
|
337
|
+
async handleResponse(request) {
|
|
338
|
+
await this.waitForInitialization();
|
|
339
|
+
return this.routeHandler.handleResponse(request);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Handles requests that do not match any routes.
|
|
343
|
+
*/
|
|
344
|
+
async handleNoMatch(request) {
|
|
345
|
+
await this.waitForInitialization();
|
|
346
|
+
return this.routeHandler.handleNoMatch(request);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function createBunServerAdapter(params) {
|
|
350
|
+
const runtimeOrigin = params.runtimeOrigin ?? `http://${params.serveOptions.hostname || "localhost"}:${params.serveOptions.port || 3e3}`;
|
|
351
|
+
const bridge = params.bridge ?? new ClientBridge();
|
|
352
|
+
const hmrManager = params.hmrManager ?? new HmrManager({ appConfig: params.appConfig, bridge });
|
|
353
|
+
const lifecycle = params.lifecycle ?? new ServerLifecycle({
|
|
354
|
+
appConfig: params.appConfig,
|
|
355
|
+
runtimeOrigin,
|
|
356
|
+
hmrManager,
|
|
357
|
+
bridge
|
|
358
|
+
});
|
|
359
|
+
const adapter = new BunServerAdapter({
|
|
360
|
+
...params,
|
|
361
|
+
runtimeOrigin,
|
|
362
|
+
bridge,
|
|
363
|
+
hmrManager,
|
|
364
|
+
lifecycle,
|
|
365
|
+
staticBuilderFactory: params.staticBuilderFactory ?? ((opts) => new ServerStaticBuilder(opts)),
|
|
366
|
+
routeHandlerFactory: params.routeHandlerFactory ?? ((p) => new ServerRouteHandler(p))
|
|
367
|
+
});
|
|
368
|
+
return adapter.createAdapter();
|
|
369
|
+
}
|
|
370
|
+
export {
|
|
371
|
+
BunServerAdapter,
|
|
372
|
+
createBunServerAdapter
|
|
373
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../internal-types';
|
|
2
|
+
import type { EcoBuildPlugin } from '../../build/build-types.js';
|
|
3
|
+
import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator';
|
|
4
|
+
import type { ClientBridge } from './client-bridge';
|
|
5
|
+
import type { HmrManager } from './hmr-manager';
|
|
6
|
+
export interface WatcherCallbacks {
|
|
7
|
+
refreshRouterRoutesCallback: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface ServerLifecycleParams {
|
|
10
|
+
appConfig: EcoPagesAppConfig;
|
|
11
|
+
runtimeOrigin: string;
|
|
12
|
+
hmrManager: HmrManager;
|
|
13
|
+
bridge: ClientBridge;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Coordinates Bun-runtime server startup side effects for one app instance.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* This class keeps runtime-only concerns together: build-runtime bootstrapping,
|
|
20
|
+
* Bun loader registration, public asset preparation, plugin setup, and file
|
|
21
|
+
* watching. Core config/build state is expected to already be finalized before
|
|
22
|
+
* this lifecycle runs.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ServerLifecycle {
|
|
25
|
+
private readonly appConfig;
|
|
26
|
+
private readonly hmrManager;
|
|
27
|
+
private readonly bridge;
|
|
28
|
+
private readonly runtimeOrigin;
|
|
29
|
+
private staticSiteGenerator;
|
|
30
|
+
constructor({ appConfig, runtimeOrigin, hmrManager, bridge }: ServerLifecycleParams);
|
|
31
|
+
/**
|
|
32
|
+
* Initializes the runtime services that Bun startup depends on.
|
|
33
|
+
*
|
|
34
|
+
* @returns The static-site generator instance reused by the adapter.
|
|
35
|
+
*/
|
|
36
|
+
initialize(): Promise<StaticSiteGenerator>;
|
|
37
|
+
/**
|
|
38
|
+
* Registers config-owned build loaders with Bun's runtime plugin API.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Bun remains responsible only for transport-level plugin registration here.
|
|
42
|
+
* Loader ownership and composition were already finalized during config build.
|
|
43
|
+
*/
|
|
44
|
+
setupLoaders(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Runs runtime-only processor and integration setup for this Bun app session.
|
|
47
|
+
*
|
|
48
|
+
* @param options.watch Whether watch mode is enabled.
|
|
49
|
+
* @returns The browser build plugins visible to HMR after runtime setup.
|
|
50
|
+
*/
|
|
51
|
+
initializePlugins(options?: {
|
|
52
|
+
watch?: boolean;
|
|
53
|
+
}): Promise<EcoBuildPlugin[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Starts file watching and wires change events back into the adapter refresh
|
|
56
|
+
* callback.
|
|
57
|
+
*/
|
|
58
|
+
startWatching(callbacks: WatcherCallbacks): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the static-site generator created during initialization.
|
|
61
|
+
*/
|
|
62
|
+
getStaticSiteGenerator(): StaticSiteGenerator;
|
|
63
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getBunRuntime } from "../../utils/runtime.js";
|
|
2
|
+
import { appLogger } from "../../global/app-logger";
|
|
3
|
+
import { StaticSiteGenerator } from "../../static-site-generator/static-site-generator";
|
|
4
|
+
import {
|
|
5
|
+
bindSharedRuntimeHmrManager,
|
|
6
|
+
initializeSharedRuntimePlugins,
|
|
7
|
+
prepareSharedRuntimePublicDir,
|
|
8
|
+
startSharedProjectWatching
|
|
9
|
+
} from "../shared/runtime-bootstrap.js";
|
|
10
|
+
class ServerLifecycle {
|
|
11
|
+
appConfig;
|
|
12
|
+
hmrManager;
|
|
13
|
+
bridge;
|
|
14
|
+
runtimeOrigin;
|
|
15
|
+
staticSiteGenerator;
|
|
16
|
+
constructor({ appConfig, runtimeOrigin, hmrManager, bridge }) {
|
|
17
|
+
this.appConfig = appConfig;
|
|
18
|
+
this.runtimeOrigin = runtimeOrigin;
|
|
19
|
+
this.hmrManager = hmrManager;
|
|
20
|
+
this.bridge = bridge;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the runtime services that Bun startup depends on.
|
|
24
|
+
*
|
|
25
|
+
* @returns The static-site generator instance reused by the adapter.
|
|
26
|
+
*/
|
|
27
|
+
async initialize() {
|
|
28
|
+
this.staticSiteGenerator = new StaticSiteGenerator({ appConfig: this.appConfig });
|
|
29
|
+
await this.hmrManager.buildRuntime();
|
|
30
|
+
this.setupLoaders();
|
|
31
|
+
prepareSharedRuntimePublicDir(this.appConfig);
|
|
32
|
+
return this.staticSiteGenerator;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Registers config-owned build loaders with Bun's runtime plugin API.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Bun remains responsible only for transport-level plugin registration here.
|
|
39
|
+
* Loader ownership and composition were already finalized during config build.
|
|
40
|
+
*/
|
|
41
|
+
setupLoaders() {
|
|
42
|
+
const loaders = this.appConfig.loaders;
|
|
43
|
+
for (const loader of loaders.values()) {
|
|
44
|
+
getBunRuntime()?.plugin(loader);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs runtime-only processor and integration setup for this Bun app session.
|
|
49
|
+
*
|
|
50
|
+
* @param options.watch Whether watch mode is enabled.
|
|
51
|
+
* @returns The browser build plugins visible to HMR after runtime setup.
|
|
52
|
+
*/
|
|
53
|
+
async initializePlugins(options) {
|
|
54
|
+
try {
|
|
55
|
+
const hmrEnabled = !!options?.watch;
|
|
56
|
+
this.hmrManager.setEnabled(hmrEnabled);
|
|
57
|
+
await initializeSharedRuntimePlugins({
|
|
58
|
+
appConfig: this.appConfig,
|
|
59
|
+
runtimeOrigin: this.runtimeOrigin,
|
|
60
|
+
hmrManager: this.hmrManager,
|
|
61
|
+
onRuntimePlugin: (plugin) => {
|
|
62
|
+
getBunRuntime()?.plugin(plugin);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return bindSharedRuntimeHmrManager(this.appConfig, this.hmrManager);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
appLogger.error(`Failed to initialize plugins: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Starts file watching and wires change events back into the adapter refresh
|
|
73
|
+
* callback.
|
|
74
|
+
*/
|
|
75
|
+
async startWatching(callbacks) {
|
|
76
|
+
await startSharedProjectWatching({
|
|
77
|
+
appConfig: this.appConfig,
|
|
78
|
+
refreshRouterRoutesCallback: callbacks.refreshRouterRoutesCallback,
|
|
79
|
+
hmrManager: this.hmrManager,
|
|
80
|
+
bridge: this.bridge
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the static-site generator created during initialization.
|
|
85
|
+
*/
|
|
86
|
+
getStaticSiteGenerator() {
|
|
87
|
+
return this.staticSiteGenerator;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
ServerLifecycle
|
|
92
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { EcopagesApp, createApp } from './bun/create-app.js';
|
|
2
|
+
export { defineApiHandler, defineGroupHandler, type GroupHandler } from './shared/define-api-handler.js';
|
|
3
|
+
export { NodeServerAdapter, createNodeServerAdapter } from './node/server-adapter.js';
|
|
4
|
+
export { EcopagesApp as NodeAdapterEcopagesApp, createNodeApp } from './node/create-app.js';
|
|
5
|
+
export type { NodeServerAdapterParams, NodeServerAdapterResult } from './node/server-adapter.js';
|
|
6
|
+
export type { EcopagesAppOptions as NodeEcopagesAppOptions } from './node/create-app.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EcopagesApp, createApp } from "./bun/create-app.js";
|
|
2
|
+
import { defineApiHandler, defineGroupHandler } from "./shared/define-api-handler.js";
|
|
3
|
+
import { NodeServerAdapter, createNodeServerAdapter } from "./node/server-adapter.js";
|
|
4
|
+
import { EcopagesApp as EcopagesApp2, createNodeApp } from "./node/create-app.js";
|
|
5
|
+
export {
|
|
6
|
+
EcopagesApp,
|
|
7
|
+
EcopagesApp2 as NodeAdapterEcopagesApp,
|
|
8
|
+
NodeServerAdapter,
|
|
9
|
+
createApp,
|
|
10
|
+
createNodeApp,
|
|
11
|
+
createNodeServerAdapter,
|
|
12
|
+
defineApiHandler,
|
|
13
|
+
defineGroupHandler
|
|
14
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin } from '../../build/build-types.js';
|
|
2
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
3
|
+
import type { NodeRuntimeManifest } from '../../services/runtime-manifest/node-runtime-manifest.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Returns the runtime-local node_modules directory used by the Node thin-host
|
|
6
|
+
* bootstrap output.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getNodeRuntimeNodeModulesDir(manifest: NodeRuntimeManifest): string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the app-local node_modules directory used by framework-owned Node
|
|
11
|
+
* bootstrap loads outside the thin-host manifest path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAppRuntimeNodeModulesDir(appConfig: Pick<EcoPagesAppConfig, 'rootDir' | 'workDir' | 'absolutePaths'>): string;
|
|
14
|
+
export interface NodeBootstrapResolutionOptions {
|
|
15
|
+
projectDir: string;
|
|
16
|
+
runtimeNodeModulesDir: string;
|
|
17
|
+
preserveImportMetaPaths?: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds the user-facing error for Bun-native imports that cannot run on the
|
|
21
|
+
* Node thin-host bootstrap path.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getNodeUnsupportedBuiltinError(specifier: string, importer?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves one bare specifier encountered while bundling Node thin-host
|
|
26
|
+
* bootstrap modules.
|
|
27
|
+
*
|
|
28
|
+
* Workspace-owned `@ecopages/*` packages stay in the bundle graph so Node does
|
|
29
|
+
* not execute their source files directly. Third-party packages stay external,
|
|
30
|
+
* but are linked into the runtime-local `node_modules` tree so the generated
|
|
31
|
+
* bootstrap output resolves them from a deterministic location.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveNodeBootstrapDependency(args: Pick<EcoBuildOnResolveArgs, 'path' | 'importer'>, options: NodeBootstrapResolutionOptions): EcoBuildOnResolveResult | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Creates the bootstrap-time resolver plugin used by the Node thin-host
|
|
36
|
+
* adapter for config and entry module loading.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createNodeBootstrapPlugin(options: NodeBootstrapResolutionOptions): EcoBuildPlugin;
|
|
39
|
+
/**
|
|
40
|
+
* Creates the standard Node bootstrap plugin for one finalized app config.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createAppNodeBootstrapPlugin(appConfig: Pick<EcoPagesAppConfig, 'rootDir' | 'workDir' | 'absolutePaths'>, options?: {
|
|
43
|
+
preserveImportMetaPaths?: string[];
|
|
44
|
+
}): EcoBuildPlugin;
|