@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.9
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,109 @@
|
|
|
1
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
2
|
+
import { invariant } from "../../utils/invariant.js";
|
|
3
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
+
import { parseCliArgs } from "../../utils/parse-cli-args.js";
|
|
5
|
+
class AbstractApplicationAdapter {
|
|
6
|
+
appConfig;
|
|
7
|
+
serverOptions;
|
|
8
|
+
cliArgs;
|
|
9
|
+
apiHandlers = [];
|
|
10
|
+
staticRoutes = [];
|
|
11
|
+
errorHandler;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.appConfig = options.appConfig;
|
|
14
|
+
this.serverOptions = options.serverOptions || {};
|
|
15
|
+
this.cliArgs = parseCliArgs();
|
|
16
|
+
if (options.clearOutput) {
|
|
17
|
+
this.clearDistFolder().catch((error) => {
|
|
18
|
+
appLogger.error("Error clearing dist folder", error);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async clearDistFolder(_filter = []) {
|
|
23
|
+
const distPath = this.appConfig.absolutePaths.distDir;
|
|
24
|
+
const distExists = fileSystem.exists(distPath);
|
|
25
|
+
if (!distExists) return;
|
|
26
|
+
try {
|
|
27
|
+
await fileSystem.removeAsync(distPath);
|
|
28
|
+
appLogger.debug(`Cleared dist folder: ${distPath}`);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
appLogger.error(`Error clearing dist folder: ${distPath}`, error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal method to add route handlers to the API handlers array
|
|
35
|
+
*/
|
|
36
|
+
addRouteHandler(path, method, handler, middleware, schema) {
|
|
37
|
+
invariant(
|
|
38
|
+
typeof path === "string",
|
|
39
|
+
`Invalid route path for ${method}: expected a string path starting with "/" but received ${Object.prototype.toString.call(path)}. If you're passing a prebuilt ApiHandler, use app.add(handler).`
|
|
40
|
+
);
|
|
41
|
+
invariant(
|
|
42
|
+
path.startsWith("/"),
|
|
43
|
+
`Invalid route path for ${method}: "${path}". Route paths must start with '/'.`
|
|
44
|
+
);
|
|
45
|
+
this.apiHandlers.push({
|
|
46
|
+
path,
|
|
47
|
+
method,
|
|
48
|
+
handler,
|
|
49
|
+
middleware,
|
|
50
|
+
schema
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get all registered API handlers
|
|
56
|
+
*/
|
|
57
|
+
getApiHandlers() {
|
|
58
|
+
return this.apiHandlers;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register a view for static generation at build time.
|
|
62
|
+
* The view must have staticPaths defined for dynamic routes.
|
|
63
|
+
*
|
|
64
|
+
* Uses a loader function to enable HMR in development.
|
|
65
|
+
*
|
|
66
|
+
* @param path - URL path pattern (e.g., '/posts/:slug')
|
|
67
|
+
* @param loader - A function that dynamically imports the eco.page view module
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* app.static('/login', () => import('./src/views/login.kita'))
|
|
71
|
+
* app.static('/posts/:slug', () => import('./src/views/post-view.kita'))
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
static(path, loader) {
|
|
75
|
+
this.staticRoutes.push({ path, loader });
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get all registered static routes
|
|
80
|
+
*/
|
|
81
|
+
getStaticRoutes() {
|
|
82
|
+
return this.staticRoutes;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Register a global error handler for all routes.
|
|
86
|
+
* Useful for logging, monitoring integration, and custom error formatting.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* app.onError(async (error, ctx) => {
|
|
91
|
+
* logger.error(error);
|
|
92
|
+
* return ctx.response.status(500).json({ error: 'Something went wrong' });
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
onError(handler) {
|
|
97
|
+
this.errorHandler = handler;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the registered error handler
|
|
102
|
+
*/
|
|
103
|
+
getErrorHandler() {
|
|
104
|
+
return this.errorHandler;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
AbstractApplicationAdapter
|
|
109
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the abstract router adapter class and its methods.
|
|
3
|
+
* It is designed to be extended by specific router adapters for different runtimes.
|
|
4
|
+
* The class provides methods for converting paths, creating route handlers,
|
|
5
|
+
* and adapting routes to the expected format of the runtime.
|
|
6
|
+
*
|
|
7
|
+
* @module RouterAdapter
|
|
8
|
+
*/
|
|
9
|
+
import type { Routes } from '../../internal-types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Abstract base class for router adapters across different runtimes
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class AbstractRouterAdapter<TRouteFormat = any> {
|
|
14
|
+
/**
|
|
15
|
+
* Convert a route path to the format expected by the runtime
|
|
16
|
+
*/
|
|
17
|
+
protected abstract convertPath(pathname: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Create a route handler compatible with the runtime
|
|
20
|
+
*/
|
|
21
|
+
protected abstract createRouteHandler(route: any): any;
|
|
22
|
+
/**
|
|
23
|
+
* Adapt framework routes to the format expected by the runtime
|
|
24
|
+
*/
|
|
25
|
+
abstract adaptRoutes(routes: Routes): TRouteFormat;
|
|
26
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the abstract server adapter class and its related types.
|
|
3
|
+
* It is designed to be extended by specific server adapters for different runtimes.
|
|
4
|
+
* The class provides methods for initializing the server, creating server options,
|
|
5
|
+
* building static files, and handling HTTP requests.
|
|
6
|
+
*
|
|
7
|
+
* @module ServerAdapter
|
|
8
|
+
*/
|
|
9
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
10
|
+
import type { ApiHandler } from '../../public-types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for all server adapters
|
|
13
|
+
*/
|
|
14
|
+
export interface ServerAdapterOptions {
|
|
15
|
+
appConfig: EcoPagesAppConfig;
|
|
16
|
+
apiHandlers?: ApiHandler<string, any>[];
|
|
17
|
+
options?: {
|
|
18
|
+
watch?: boolean;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
serveOptions?: Record<string, any>;
|
|
22
|
+
runtimeOrigin: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Base adapter result containing common functionalities
|
|
26
|
+
* across different runtime implementations
|
|
27
|
+
*/
|
|
28
|
+
export interface ServerAdapterResult {
|
|
29
|
+
getServerOptions: (options?: {
|
|
30
|
+
enableHmr?: boolean;
|
|
31
|
+
}) => any;
|
|
32
|
+
buildStatic: (options?: {
|
|
33
|
+
preview?: boolean;
|
|
34
|
+
}) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Abstract base class for server adapters across different runtimes
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class AbstractServerAdapter<TOptions extends ServerAdapterOptions = ServerAdapterOptions, TResult extends ServerAdapterResult = ServerAdapterResult> {
|
|
40
|
+
protected appConfig: EcoPagesAppConfig;
|
|
41
|
+
protected options: TOptions['options'];
|
|
42
|
+
protected serveOptions: TOptions['serveOptions'];
|
|
43
|
+
protected runtimeOrigin: string;
|
|
44
|
+
constructor(options: TOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Initialize the server adapter
|
|
47
|
+
*/
|
|
48
|
+
abstract initialize(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Create server options specific to the runtime
|
|
51
|
+
*/
|
|
52
|
+
abstract getServerOptions(options?: {
|
|
53
|
+
enableHmr?: boolean;
|
|
54
|
+
}): any;
|
|
55
|
+
/**
|
|
56
|
+
* Build static files for the application
|
|
57
|
+
*/
|
|
58
|
+
abstract buildStatic(options?: {
|
|
59
|
+
preview?: boolean;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Factory method to create a server adapter with runtime-specific functionality
|
|
63
|
+
*/
|
|
64
|
+
abstract createAdapter(): Promise<TResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Handle HTTP requests
|
|
67
|
+
*/
|
|
68
|
+
abstract handleRequest(request: Request): Promise<Response>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class AbstractServerAdapter {
|
|
2
|
+
appConfig;
|
|
3
|
+
options;
|
|
4
|
+
serveOptions;
|
|
5
|
+
runtimeOrigin;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.appConfig = options.appConfig;
|
|
8
|
+
this.options = options.options || {};
|
|
9
|
+
this.serveOptions = options.serveOptions || {};
|
|
10
|
+
this.runtimeOrigin = options.runtimeOrigin;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
AbstractServerAdapter
|
|
15
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ServerWebSocket } from 'bun';
|
|
2
|
+
import type { ClientBridgeEvent, IClientBridge } from '../../public-types';
|
|
3
|
+
type BunSocket = ServerWebSocket<unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Manages WebSocket subscribers and broadcasts development events.
|
|
6
|
+
* Bridges the gap between the server and the development client.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ClientBridge implements IClientBridge {
|
|
9
|
+
private subscribers;
|
|
10
|
+
subscribe(ws: BunSocket): void;
|
|
11
|
+
unsubscribe(ws: BunSocket): void;
|
|
12
|
+
/**
|
|
13
|
+
* Broadcast a raw event to all connected clients.
|
|
14
|
+
*/
|
|
15
|
+
broadcast(event: ClientBridgeEvent): void;
|
|
16
|
+
/**
|
|
17
|
+
* Trigger a full page reload on all connected clients.
|
|
18
|
+
*/
|
|
19
|
+
reload(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Broadcast a CSS update for hot stylesheet reload.
|
|
22
|
+
*/
|
|
23
|
+
cssUpdate(path: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Broadcast a JS module update for hot module replacement.
|
|
26
|
+
*/
|
|
27
|
+
update(path: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Broadcast an error message to connected clients.
|
|
30
|
+
*/
|
|
31
|
+
error(message: string): void;
|
|
32
|
+
get subscriberCount(): number;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class ClientBridge {
|
|
2
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
3
|
+
subscribe(ws) {
|
|
4
|
+
this.subscribers.add(ws);
|
|
5
|
+
}
|
|
6
|
+
unsubscribe(ws) {
|
|
7
|
+
this.subscribers.delete(ws);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Broadcast a raw event to all connected clients.
|
|
11
|
+
*/
|
|
12
|
+
broadcast(event) {
|
|
13
|
+
const payload = JSON.stringify(event);
|
|
14
|
+
for (const ws of this.subscribers) {
|
|
15
|
+
ws.send(payload);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Trigger a full page reload on all connected clients.
|
|
20
|
+
*/
|
|
21
|
+
reload() {
|
|
22
|
+
this.broadcast({ type: "reload" });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Broadcast a CSS update for hot stylesheet reload.
|
|
26
|
+
*/
|
|
27
|
+
cssUpdate(path) {
|
|
28
|
+
this.broadcast({ type: "css-update", path, timestamp: Date.now() });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Broadcast a JS module update for hot module replacement.
|
|
32
|
+
*/
|
|
33
|
+
update(path) {
|
|
34
|
+
this.broadcast({ type: "update", path, timestamp: Date.now() });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Broadcast an error message to connected clients.
|
|
38
|
+
*/
|
|
39
|
+
error(message) {
|
|
40
|
+
this.broadcast({ type: "error", message });
|
|
41
|
+
}
|
|
42
|
+
get subscriberCount() {
|
|
43
|
+
return this.subscribers.size;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
ClientBridge
|
|
48
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the implementation of the Bun application adapter for EcoPages.
|
|
3
|
+
* It extends the AbstractApplicationAdapter class and provides methods for handling
|
|
4
|
+
* HTTP requests, initializing the server adapter, and starting the Bun application server.
|
|
5
|
+
* The adapter is designed to work with the Bun runtime and provides a way to create
|
|
6
|
+
* EcoPages applications using Bun's features.
|
|
7
|
+
*
|
|
8
|
+
* @module EcopagesApp
|
|
9
|
+
*/
|
|
10
|
+
import type { Server } from 'bun';
|
|
11
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
12
|
+
import type { ApiHandlerContext, RouteGroupBuilder } from '../../public-types.js';
|
|
13
|
+
import { type ApplicationAdapterOptions } from '../abstract/application-adapter.js';
|
|
14
|
+
import { SharedApplicationAdapter } from '../shared/application-adapter.js';
|
|
15
|
+
import { type BunServerAdapterResult } from './server-adapter.js';
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for the Bun application adapter
|
|
18
|
+
*/
|
|
19
|
+
export interface EcopagesAppOptions extends ApplicationAdapterOptions {
|
|
20
|
+
appConfig: EcoPagesAppConfig;
|
|
21
|
+
serverOptions?: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Bun-specific route group builder that properly infers route params from path patterns.
|
|
25
|
+
* When you define a route like `/posts/:slug`, the handler context will have
|
|
26
|
+
* `ctx.params.slug` typed as `string`.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam WebSocketData - WebSocket data type for the server
|
|
29
|
+
* @typeParam TContext - Extended context type from middleware (e.g., `{ user: User }`)
|
|
30
|
+
*/
|
|
31
|
+
export type BunRouteGroupBuilder<WebSocketData = undefined, TContext extends ApiHandlerContext<Request, Server<WebSocketData>> = ApiHandlerContext<Request, Server<WebSocketData>>> = RouteGroupBuilder<Request, Server<WebSocketData>, TContext>;
|
|
32
|
+
/**
|
|
33
|
+
* Bun-specific application adapter implementation
|
|
34
|
+
* This class extends the {@link AbstractApplicationAdapter}
|
|
35
|
+
* and provides methods for handling HTTP requests and managing the server.
|
|
36
|
+
*/
|
|
37
|
+
export declare class EcopagesApp<WebSocketData = undefined> extends SharedApplicationAdapter<EcopagesAppOptions, Server<WebSocketData>, Request> {
|
|
38
|
+
serverAdapter: BunServerAdapterResult | undefined;
|
|
39
|
+
private server;
|
|
40
|
+
fetch(request: Request): Promise<Response>;
|
|
41
|
+
/**
|
|
42
|
+
* Complete the initialization of the server adapter by processing dynamic routes
|
|
43
|
+
* @param server The Bun server instance
|
|
44
|
+
*/
|
|
45
|
+
completeInitialization(server: Server<WebSocketData>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Initialize the Bun server adapter
|
|
48
|
+
*/
|
|
49
|
+
protected initializeServerAdapter(): Promise<BunServerAdapterResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Start the Bun application server
|
|
52
|
+
* @param options Optional settings
|
|
53
|
+
* @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
|
|
54
|
+
*/
|
|
55
|
+
start(): Promise<Server<WebSocketData> | void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Factory function to create a Bun application
|
|
59
|
+
*/
|
|
60
|
+
export declare function createApp<WebSocketData = undefined>(options: EcopagesAppOptions): Promise<EcopagesApp<WebSocketData>>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from "../../constants.js";
|
|
2
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
3
|
+
import { getBunRuntime } from "../../utils/runtime.js";
|
|
4
|
+
import {} from "../abstract/application-adapter.js";
|
|
5
|
+
import { SharedApplicationAdapter } from "../shared/application-adapter.js";
|
|
6
|
+
import { createBunServerAdapter } from "./server-adapter.js";
|
|
7
|
+
class EcopagesApp extends SharedApplicationAdapter {
|
|
8
|
+
serverAdapter;
|
|
9
|
+
server = null;
|
|
10
|
+
async fetch(request) {
|
|
11
|
+
if (!this.serverAdapter) {
|
|
12
|
+
this.serverAdapter = await this.initializeServerAdapter();
|
|
13
|
+
}
|
|
14
|
+
await this.serverAdapter.completeInitialization(this.server);
|
|
15
|
+
return this.serverAdapter.handleRequest(request);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Complete the initialization of the server adapter by processing dynamic routes
|
|
19
|
+
* @param server The Bun server instance
|
|
20
|
+
*/
|
|
21
|
+
async completeInitialization(server) {
|
|
22
|
+
if (!this.serverAdapter) {
|
|
23
|
+
throw new Error("Server adapter not initialized. Call start() first.");
|
|
24
|
+
}
|
|
25
|
+
await this.serverAdapter.completeInitialization(server);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the Bun server adapter
|
|
29
|
+
*/
|
|
30
|
+
async initializeServerAdapter() {
|
|
31
|
+
const { dev } = this.cliArgs;
|
|
32
|
+
const { port: cliPort, hostname: cliHostname } = this.cliArgs;
|
|
33
|
+
const envPort = process.env.ECOPAGES_PORT ? process.env.ECOPAGES_PORT : void 0;
|
|
34
|
+
const envHostname = process.env.ECOPAGES_HOSTNAME;
|
|
35
|
+
const preferredPort = cliPort ?? envPort ?? DEFAULT_ECOPAGES_PORT;
|
|
36
|
+
const preferredHostname = cliHostname ?? envHostname ?? DEFAULT_ECOPAGES_HOSTNAME;
|
|
37
|
+
appLogger.debug("initializeServerAdapter", {
|
|
38
|
+
dev,
|
|
39
|
+
cliPort,
|
|
40
|
+
cliHostname,
|
|
41
|
+
envPort,
|
|
42
|
+
envHostname,
|
|
43
|
+
preferredPort,
|
|
44
|
+
preferredHostname,
|
|
45
|
+
composedUrl: `http://${preferredHostname}:${preferredPort}`
|
|
46
|
+
});
|
|
47
|
+
return await createBunServerAdapter({
|
|
48
|
+
runtimeOrigin: `http://${preferredHostname}:${preferredPort}`,
|
|
49
|
+
appConfig: this.appConfig,
|
|
50
|
+
apiHandlers: this.apiHandlers,
|
|
51
|
+
staticRoutes: this.staticRoutes,
|
|
52
|
+
errorHandler: this.errorHandler,
|
|
53
|
+
options: { watch: dev },
|
|
54
|
+
serveOptions: {
|
|
55
|
+
port: preferredPort,
|
|
56
|
+
hostname: preferredHostname,
|
|
57
|
+
...this.serverOptions
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Start the Bun application server
|
|
63
|
+
* @param options Optional settings
|
|
64
|
+
* @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
|
|
65
|
+
*/
|
|
66
|
+
async start() {
|
|
67
|
+
if (!this.serverAdapter) {
|
|
68
|
+
this.serverAdapter = await this.initializeServerAdapter();
|
|
69
|
+
}
|
|
70
|
+
const { dev, preview, build } = this.cliArgs;
|
|
71
|
+
const requiresFetchRuntime = this.appConfig.integrations.some(
|
|
72
|
+
(integration) => integration.staticBuildStep === "fetch"
|
|
73
|
+
);
|
|
74
|
+
const canBuildWithoutRuntimeServer = (build || preview) && !requiresFetchRuntime;
|
|
75
|
+
if (canBuildWithoutRuntimeServer) {
|
|
76
|
+
appLogger.debugTime("Building static pages");
|
|
77
|
+
await this.serverAdapter.buildStatic({ preview });
|
|
78
|
+
appLogger.debugTimeEnd("Building static pages");
|
|
79
|
+
if (build) {
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const enableHmr = dev || !preview && !build;
|
|
85
|
+
const serverOptions = this.serverAdapter.getServerOptions({ enableHmr });
|
|
86
|
+
const bun = getBunRuntime();
|
|
87
|
+
if (!bun) {
|
|
88
|
+
throw new Error("Bun runtime is required for the Bun adapter");
|
|
89
|
+
}
|
|
90
|
+
const bunServer = bun.serve(serverOptions);
|
|
91
|
+
this.server = bunServer;
|
|
92
|
+
await this.serverAdapter.completeInitialization(this.server).catch((error) => {
|
|
93
|
+
appLogger.error(`Failed to complete initialization: ${error}`);
|
|
94
|
+
});
|
|
95
|
+
if (!this.server) {
|
|
96
|
+
throw new Error("Server failed to start");
|
|
97
|
+
}
|
|
98
|
+
appLogger.info(`Server running at http://${this.server.hostname}:${this.server.port}`);
|
|
99
|
+
if (build || preview) {
|
|
100
|
+
appLogger.debugTime("Building static pages");
|
|
101
|
+
await this.serverAdapter.buildStatic({ preview });
|
|
102
|
+
this.server.stop(true);
|
|
103
|
+
appLogger.debugTimeEnd("Building static pages");
|
|
104
|
+
if (build) {
|
|
105
|
+
process.exit(0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return this.server;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function createApp(options) {
|
|
112
|
+
return new EcopagesApp(options);
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
EcopagesApp,
|
|
116
|
+
createApp
|
|
117
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { WebSocketHandler } from 'bun';
|
|
2
|
+
import type { DefaultHmrContext, EcoPagesAppConfig, IHmrManager } from '../../internal-types';
|
|
3
|
+
import type { EcoBuildPlugin } from '../../build/build-types.js';
|
|
4
|
+
import { type HmrStrategy } from '../../hmr/hmr-strategy';
|
|
5
|
+
import type { ClientBridge } from './client-bridge';
|
|
6
|
+
import type { ClientBridgeEvent } from '../../public-types';
|
|
7
|
+
type BunSocketHandler = WebSocketHandler<unknown>;
|
|
8
|
+
export interface HmrManagerParams {
|
|
9
|
+
appConfig: EcoPagesAppConfig;
|
|
10
|
+
bridge: ClientBridge;
|
|
11
|
+
}
|
|
12
|
+
type HandleFileChangeOptions = {
|
|
13
|
+
broadcast?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Bun development HMR manager.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Bun shares the same public contract as the Node manager: page entrypoints are
|
|
20
|
+
* strict integration-owned registrations, while generic script assets use their
|
|
21
|
+
* own explicit registration path.
|
|
22
|
+
*/
|
|
23
|
+
export declare class HmrManager implements IHmrManager {
|
|
24
|
+
private static readonly entrypointRegistrationTimeoutMs;
|
|
25
|
+
readonly appConfig: EcoPagesAppConfig;
|
|
26
|
+
private readonly bridge;
|
|
27
|
+
/** Keep track of watchers */
|
|
28
|
+
private watchers;
|
|
29
|
+
/** entrypoint -> output path */
|
|
30
|
+
private watchedFiles;
|
|
31
|
+
private entrypointRegistrations;
|
|
32
|
+
private distDir;
|
|
33
|
+
private plugins;
|
|
34
|
+
private enabled;
|
|
35
|
+
private strategies;
|
|
36
|
+
private readonly entrypointRegistrar;
|
|
37
|
+
private readonly browserBundleService;
|
|
38
|
+
private readonly entrypointDependencyGraph;
|
|
39
|
+
private readonly runtimeSpecifierRegistry;
|
|
40
|
+
private readonly serverModuleTranspiler;
|
|
41
|
+
private wsHandler;
|
|
42
|
+
constructor({ appConfig, bridge }: HmrManagerParams);
|
|
43
|
+
/**
|
|
44
|
+
* Ensures the HMR output directory exists.
|
|
45
|
+
*
|
|
46
|
+
* This must not remove the directory because multiple app processes
|
|
47
|
+
* can share the same dist path during e2e runs.
|
|
48
|
+
*/
|
|
49
|
+
private cleanDistDir;
|
|
50
|
+
/**
|
|
51
|
+
* Returns whether the generic JS strategy may rebuild an entrypoint.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Integration-owned page entrypoints are excluded so a shared dependency
|
|
55
|
+
* invalidation cannot replace framework-owned browser output with a generic JS
|
|
56
|
+
* rebuild.
|
|
57
|
+
*/
|
|
58
|
+
private shouldJsStrategyProcessEntrypoint;
|
|
59
|
+
/**
|
|
60
|
+
* Initializes core HMR strategies.
|
|
61
|
+
* Strategies are evaluated in priority order (highest first).
|
|
62
|
+
*/
|
|
63
|
+
private initializeStrategies;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a custom HMR strategy.
|
|
66
|
+
* Used by integrations to provide framework-specific HMR handling.
|
|
67
|
+
* @param strategy - The HMR strategy to register
|
|
68
|
+
*/
|
|
69
|
+
registerStrategy(strategy: HmrStrategy): void;
|
|
70
|
+
setPlugins(plugins: EcoBuildPlugin[]): void;
|
|
71
|
+
setEnabled(enabled: boolean): void;
|
|
72
|
+
isEnabled(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Registers runtime bare-specifier mappings exposed by integrations.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* These mappings are consumed by framework-owned HMR strategies that preserve
|
|
78
|
+
* shared runtime imports in browser bundles. The registry stays generic so
|
|
79
|
+
* these mappings can later support broader import-map-style runtime features
|
|
80
|
+
* without moving integration semantics into core.
|
|
81
|
+
*/
|
|
82
|
+
registerSpecifierMap(map: Record<string, string>): void;
|
|
83
|
+
getWebSocketHandler(): BunSocketHandler;
|
|
84
|
+
/**
|
|
85
|
+
* Builds the client-side HMR runtime script.
|
|
86
|
+
*/
|
|
87
|
+
buildRuntime(): Promise<void>;
|
|
88
|
+
getRuntimePath(): string;
|
|
89
|
+
broadcast(event: ClientBridgeEvent): void;
|
|
90
|
+
handleFileChange(filePath: string, options?: HandleFileChangeOptions): Promise<void>;
|
|
91
|
+
getOutputUrl(entrypointPath: string): string | undefined;
|
|
92
|
+
getWatchedFiles(): Map<string, string>;
|
|
93
|
+
getSpecifierMap(): Map<string, string>;
|
|
94
|
+
getDistDir(): string;
|
|
95
|
+
getPlugins(): EcoBuildPlugin[];
|
|
96
|
+
getDefaultContext(): DefaultHmrContext;
|
|
97
|
+
private clearFailedEntrypointRegistration;
|
|
98
|
+
/**
|
|
99
|
+
* Registers one integration-owned page entrypoint.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* Concurrent callers share one in-flight registration. The registration is
|
|
103
|
+
* cleared from the dedupe map when it settles so later callers cannot inherit a
|
|
104
|
+
* stale promise.
|
|
105
|
+
*/
|
|
106
|
+
registerEntrypoint(entrypointPath: string): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Registers one generic script entrypoint.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* This explicit path keeps the page-entrypoint contract strict while still
|
|
112
|
+
* allowing generic script assets to use the fallback build path.
|
|
113
|
+
*/
|
|
114
|
+
registerScriptEntrypoint(entrypointPath: string): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Performs strict integration-owned registration for one normalized path.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* The manager reserves the output URL, removes any stale emitted file, runs
|
|
120
|
+
* strategy processing without broadcasting, and then verifies that the owning
|
|
121
|
+
* integration emitted the expected file.
|
|
122
|
+
*/
|
|
123
|
+
private emitStrictEntrypoint;
|
|
124
|
+
/**
|
|
125
|
+
* Performs registration for a generic script asset.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* Strategies get the first chance to emit output. If no output exists after
|
|
129
|
+
* that pass, Bun falls back to the generic browser build for this explicit
|
|
130
|
+
* script-only path.
|
|
131
|
+
*/
|
|
132
|
+
private emitScriptEntrypoint;
|
|
133
|
+
/**
|
|
134
|
+
* Stops active watchers and releases retained registration state.
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* Emitted `_hmr` files remain on disk because parallel app processes may share
|
|
138
|
+
* the same dist directory. The in-memory indexes are cleared so stale
|
|
139
|
+
* entrypoints and specifier maps cannot leak through a reused manager object.
|
|
140
|
+
*/
|
|
141
|
+
stop(): void;
|
|
142
|
+
}
|
|
143
|
+
export {};
|