@ecopages/core 0.2.0-alpha.1 → 0.2.0-alpha.10
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 +13 -70
- package/README.md +213 -12
- package/package.json +50 -18
- package/src/adapters/README.md +39 -0
- package/src/adapters/bun/hmr-manager.d.ts +77 -18
- package/src/adapters/bun/hmr-manager.js +159 -52
- package/src/adapters/bun/index.d.ts +1 -2
- package/src/adapters/bun/index.js +1 -1
- package/src/adapters/bun/server-adapter.js +35 -30
- package/src/adapters/bun/server-lifecycle.d.ts +24 -13
- package/src/adapters/bun/server-lifecycle.js +32 -60
- package/src/adapters/index.d.ts +1 -1
- package/src/adapters/index.js +1 -1
- 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/index.d.ts +2 -0
- package/src/adapters/node/index.js +3 -0
- package/src/adapters/node/node-hmr-manager.d.ts +87 -16
- package/src/adapters/node/node-hmr-manager.js +179 -88
- 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 +2 -31
- package/src/adapters/node/server-adapter.js +31 -93
- package/src/adapters/node/static-content-server.d.ts +36 -0
- package/src/adapters/node/static-content-server.js +28 -0
- package/src/adapters/node/write-runtime-manifest.d.ts +26 -0
- package/src/adapters/node/write-runtime-manifest.js +12 -0
- package/src/{define-api-handler.d.ts → adapters/shared/define-api-handler.d.ts} +1 -1
- package/src/adapters/shared/explicit-static-route-matcher.js +4 -1
- package/src/adapters/shared/file-route-middleware-pipeline.js +1 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +9 -5
- package/src/adapters/shared/fs-server-response-matcher.js +13 -8
- 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.js +3 -2
- 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 +12 -2
- package/src/adapters/shared/server-adapter.js +37 -4
- package/src/adapters/shared/server-route-handler.d.ts +1 -1
- package/src/adapters/shared/server-route-handler.js +4 -13
- package/src/adapters/shared/server-static-builder.d.ts +35 -3
- package/src/adapters/shared/server-static-builder.js +59 -6
- package/src/build/README.md +101 -0
- package/src/build/build-adapter.d.ts +114 -2
- package/src/build/build-adapter.js +119 -5
- package/src/build/build-manifest.d.ts +27 -0
- package/src/build/build-manifest.js +30 -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 +9 -6
- package/src/build/esbuild-build-adapter.js +103 -71
- 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/README.md +33 -0
- package/src/config/config-builder.d.ts +28 -17
- package/src/config/config-builder.js +221 -48
- package/src/constants.d.ts +13 -0
- package/src/constants.js +4 -0
- package/src/declarations.d.ts +18 -13
- package/src/eco/README.md +70 -16
- package/src/eco/component-render-context.d.ts +1 -1
- package/src/eco/component-render-context.js +26 -16
- package/src/eco/eco.js +16 -12
- package/src/eco/eco.types.d.ts +12 -4
- package/src/hmr/README.md +26 -0
- package/src/hmr/client/hmr-runtime.d.ts +1 -6
- package/src/hmr/client/hmr-runtime.js +30 -7
- 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.js +26 -33
- package/src/hmr/strategies/js-hmr-strategy.d.ts +45 -42
- package/src/hmr/strategies/js-hmr-strategy.js +70 -71
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/integrations/ghtml/ghtml-renderer.d.ts +1 -1
- package/src/integrations/ghtml/ghtml-renderer.js +3 -1
- package/src/internal-types.d.ts +39 -18
- package/src/plugins/README.md +34 -0
- package/src/plugins/alias-resolver-plugin.js +17 -3
- package/src/plugins/eco-component-meta-plugin.d.ts +2 -0
- package/src/plugins/eco-component-meta-plugin.js +1 -1
- package/src/plugins/integration-plugin.d.ts +38 -4
- package/src/plugins/integration-plugin.js +34 -1
- package/src/plugins/processor.d.ts +14 -1
- package/src/plugins/processor.js +15 -1
- package/src/plugins/runtime-capability.d.ts +9 -0
- package/src/public-types.d.ts +65 -10
- package/src/route-renderer/GRAPH.md +16 -20
- package/src/route-renderer/README.md +8 -21
- 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/{marker-graph-resolver.d.ts → component-graph/marker-graph-resolver.d.ts} +6 -5
- package/src/route-renderer/{marker-graph-resolver.js → component-graph/marker-graph-resolver.js} +10 -8
- package/src/route-renderer/{integration-renderer.d.ts → orchestration/integration-renderer.d.ts} +45 -12
- package/src/route-renderer/{integration-renderer.js → orchestration/integration-renderer.js} +79 -16
- package/src/route-renderer/{render-execution.service.d.ts → orchestration/render-execution.service.d.ts} +39 -5
- package/src/route-renderer/{render-execution.service.js → orchestration/render-execution.service.js} +58 -28
- package/src/route-renderer/{render-preparation.service.d.ts → orchestration/render-preparation.service.d.ts} +13 -4
- package/src/route-renderer/{render-preparation.service.js → orchestration/render-preparation.service.js} +92 -3
- package/src/route-renderer/{dependency-resolver.d.ts → page-loading/dependency-resolver.d.ts} +15 -4
- package/src/route-renderer/{dependency-resolver.js → page-loading/dependency-resolver.js} +18 -4
- package/src/route-renderer/page-loading/page-module-loader.d.ts +87 -0
- package/src/route-renderer/{page-module-loader.js → page-loading/page-module-loader.js} +36 -14
- package/src/route-renderer/route-renderer.d.ts +36 -1
- package/src/route-renderer/route-renderer.js +19 -0
- package/src/router/README.md +26 -0
- package/src/router/client/link-intent.d.ts +53 -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/{fs-router-scanner.d.ts → server/fs-router-scanner.d.ts} +3 -3
- package/src/router/{fs-router-scanner.js → server/fs-router-scanner.js} +8 -7
- package/src/router/{fs-router.d.ts → server/fs-router.d.ts} +1 -1
- package/src/router/{fs-router.js → server/fs-router.js} +1 -1
- package/src/services/README.md +29 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/asset-processing.service.js +88 -7
- package/src/services/{asset-processing-service → assets/asset-processing-service}/asset.factory.js +2 -2
- package/src/services/{asset-processing-service → assets/asset-processing-service}/assets.types.d.ts +2 -1
- 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/{asset-processing-service → assets/asset-processing-service}/index.d.ts +2 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/index.js +2 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.interface.d.ts +1 -1
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-processor.d.ts +1 -1
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-processor.js +9 -4
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-script-processor.d.ts +3 -2
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-script-processor.js +14 -22
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/file-script.processor.d.ts +1 -1
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/file-script.processor.js +2 -2
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/node-module-script.processor.js +5 -4
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/file-stylesheet.processor.js +4 -1
- package/src/services/assets/browser-bundle.service.d.ts +32 -0
- package/src/services/assets/browser-bundle.service.js +33 -0
- package/src/services/{page-request-cache-coordinator.service.d.ts → cache/page-request-cache-coordinator.service.d.ts} +2 -2
- package/src/services/{page-request-cache-coordinator.service.js → cache/page-request-cache-coordinator.service.js} +3 -1
- 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/{schema-validation-service.d.ts → validation/schema-validation-service.d.ts} +1 -1
- package/src/static-site-generator/README.md +26 -0
- package/src/static-site-generator/static-site-generator.d.ts +53 -1
- package/src/static-site-generator/static-site-generator.js +86 -5
- package/src/utils/resolve-work-dir.d.ts +11 -0
- package/src/utils/resolve-work-dir.js +31 -0
- package/src/watchers/project-watcher.d.ts +37 -21
- package/src/watchers/project-watcher.js +109 -66
- package/src/watchers/project-watcher.test-helpers.js +1 -0
- package/src/adapters/abstract/application-adapter.ts +0 -337
- package/src/adapters/abstract/router-adapter.ts +0 -30
- package/src/adapters/abstract/server-adapter.ts +0 -79
- package/src/adapters/bun/client-bridge.ts +0 -62
- package/src/adapters/bun/create-app.ts +0 -189
- package/src/adapters/bun/define-api-handler.d.ts +0 -61
- package/src/adapters/bun/define-api-handler.ts +0 -114
- package/src/adapters/bun/hmr-manager.ts +0 -281
- package/src/adapters/bun/index.ts +0 -3
- package/src/adapters/bun/server-adapter.ts +0 -492
- package/src/adapters/bun/server-lifecycle.ts +0 -154
- package/src/adapters/index.ts +0 -6
- package/src/adapters/node/create-app.ts +0 -179
- package/src/adapters/node/index.ts +0 -9
- package/src/adapters/node/node-client-bridge.ts +0 -79
- package/src/adapters/node/node-hmr-manager.ts +0 -271
- package/src/adapters/node/server-adapter.ts +0 -561
- package/src/adapters/node/static-content-server.ts +0 -203
- package/src/adapters/shared/api-response.ts +0 -104
- package/src/adapters/shared/application-adapter.ts +0 -199
- package/src/adapters/shared/explicit-static-route-matcher.ts +0 -134
- package/src/adapters/shared/file-route-middleware-pipeline.ts +0 -123
- package/src/adapters/shared/fs-server-response-factory.ts +0 -118
- package/src/adapters/shared/fs-server-response-matcher.ts +0 -198
- package/src/adapters/shared/render-context.ts +0 -105
- package/src/adapters/shared/server-adapter.ts +0 -442
- package/src/adapters/shared/server-route-handler.ts +0 -166
- package/src/adapters/shared/server-static-builder.ts +0 -82
- package/src/build/build-adapter.ts +0 -132
- package/src/build/build-types.ts +0 -83
- package/src/build/esbuild-build-adapter.ts +0 -510
- package/src/config/config-builder.ts +0 -474
- package/src/constants.ts +0 -39
- package/src/create-app.ts +0 -87
- package/src/define-api-handler.js +0 -15
- package/src/define-api-handler.ts +0 -66
- package/src/dev/sc-server.ts +0 -143
- package/src/eco/component-render-context.ts +0 -202
- package/src/eco/eco.ts +0 -221
- package/src/eco/eco.types.ts +0 -202
- package/src/eco/eco.utils.ts +0 -89
- package/src/eco/global-injector-map.ts +0 -112
- package/src/eco/lazy-injector-map.ts +0 -120
- package/src/eco/module-dependencies.ts +0 -75
- package/src/errors/http-error.ts +0 -72
- package/src/errors/index.ts +0 -2
- package/src/errors/locals-access-error.ts +0 -7
- package/src/global/app-logger.ts +0 -4
- 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/client/hmr-runtime.ts +0 -121
- package/src/hmr/hmr-strategy.ts +0 -172
- package/src/hmr/hmr.test.e2e.ts +0 -75
- package/src/hmr/strategies/default-hmr-strategy.ts +0 -60
- package/src/hmr/strategies/js-hmr-strategy.ts +0 -308
- package/src/index.browser.ts +0 -3
- package/src/index.ts +0 -5
- package/src/integrations/ghtml/ghtml-renderer.ts +0 -93
- package/src/integrations/ghtml/ghtml.plugin.ts +0 -32
- package/src/internal-types.ts +0 -212
- package/src/plugins/alias-resolver-plugin.ts +0 -45
- package/src/plugins/eco-component-meta-plugin.ts +0 -474
- package/src/plugins/integration-plugin.ts +0 -184
- package/src/plugins/processor.ts +0 -220
- package/src/public-types.ts +0 -1255
- package/src/route-renderer/component-graph-executor.ts +0 -84
- package/src/route-renderer/component-graph.ts +0 -159
- package/src/route-renderer/component-marker.ts +0 -117
- package/src/route-renderer/dependency-resolver.ts +0 -596
- package/src/route-renderer/html-post-processing.service.d.ts +0 -40
- package/src/route-renderer/html-post-processing.service.js +0 -86
- package/src/route-renderer/html-post-processing.service.ts +0 -103
- package/src/route-renderer/integration-renderer.ts +0 -696
- package/src/route-renderer/marker-graph-resolver.ts +0 -153
- package/src/route-renderer/page-module-loader.d.ts +0 -61
- package/src/route-renderer/page-module-loader.ts +0 -153
- package/src/route-renderer/render-execution.service.ts +0 -158
- package/src/route-renderer/render-preparation.service.ts +0 -358
- package/src/route-renderer/route-renderer.ts +0 -80
- package/src/router/fs-router-scanner.ts +0 -217
- package/src/router/fs-router.ts +0 -122
- package/src/services/asset-processing-service/asset-processing.service.d.ts +0 -41
- package/src/services/asset-processing-service/asset-processing.service.ts +0 -306
- package/src/services/asset-processing-service/asset.factory.ts +0 -105
- package/src/services/asset-processing-service/assets.types.ts +0 -112
- package/src/services/asset-processing-service/index.ts +0 -3
- package/src/services/asset-processing-service/processor.interface.ts +0 -27
- package/src/services/asset-processing-service/processor.registry.ts +0 -18
- package/src/services/asset-processing-service/processors/base/base-processor.ts +0 -76
- package/src/services/asset-processing-service/processors/base/base-script-processor.ts +0 -105
- package/src/services/asset-processing-service/processors/index.ts +0 -5
- package/src/services/asset-processing-service/processors/script/content-script.processor.ts +0 -66
- package/src/services/asset-processing-service/processors/script/file-script.processor.ts +0 -88
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts +0 -84
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +0 -27
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +0 -77
- package/src/services/cache/cache.types.ts +0 -126
- package/src/services/cache/index.ts +0 -18
- package/src/services/cache/memory-cache-store.ts +0 -130
- package/src/services/cache/page-cache-service.ts +0 -202
- package/src/services/html-transformer.service.d.ts +0 -50
- package/src/services/html-transformer.service.js +0 -163
- package/src/services/html-transformer.service.ts +0 -217
- package/src/services/page-module-import.service.d.ts +0 -37
- package/src/services/page-module-import.service.js +0 -88
- package/src/services/page-module-import.service.ts +0 -129
- package/src/services/page-request-cache-coordinator.service.ts +0 -128
- package/src/services/schema-validation-service.ts +0 -204
- package/src/services/validation/standard-schema.types.ts +0 -68
- package/src/static-site-generator/static-site-generator.ts +0 -359
- package/src/utils/css.ts +0 -5
- package/src/utils/deep-merge.ts +0 -47
- package/src/utils/hash.ts +0 -5
- package/src/utils/html.ts +0 -1
- package/src/utils/invariant.ts +0 -15
- package/src/utils/locals-utils.ts +0 -37
- package/src/utils/parse-cli-args.ts +0 -83
- package/src/utils/path-utils.module.ts +0 -14
- package/src/utils/runtime.ts +0 -44
- package/src/utils/server-utils.module.ts +0 -67
- package/src/watchers/project-watcher.test-helpers.ts +0 -40
- package/src/watchers/project-watcher.ts +0 -306
- /package/src/adapters/{bun → shared}/define-api-handler.js +0 -0
- /package/src/{services/asset-processing-service/assets.types.js → plugins/runtime-capability.js} +0 -0
- /package/src/route-renderer/{component-graph-executor.d.ts → component-graph/component-graph-executor.d.ts} +0 -0
- /package/src/route-renderer/{component-graph-executor.js → component-graph/component-graph-executor.js} +0 -0
- /package/src/route-renderer/{component-graph.d.ts → component-graph/component-graph.d.ts} +0 -0
- /package/src/route-renderer/{component-graph.js → component-graph/component-graph.js} +0 -0
- /package/src/route-renderer/{component-marker.d.ts → component-graph/component-marker.d.ts} +0 -0
- /package/src/route-renderer/{component-marker.js → component-graph/component-marker.js} +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/asset.factory.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.interface.js +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.registry.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.registry.js +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/index.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/index.js +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/content-script.processor.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/content-script.processor.js +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/node-module-script.processor.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/content-stylesheet.processor.d.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/content-stylesheet.processor.js +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/file-stylesheet.processor.d.ts +0 -0
- /package/src/services/{schema-validation-service.js → validation/schema-validation-service.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WebSocketHandler } from 'bun';
|
|
2
2
|
import type { DefaultHmrContext, EcoPagesAppConfig, IHmrManager } from '../../internal-types';
|
|
3
3
|
import type { EcoBuildPlugin } from '../../build/build-types.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type HmrStrategy } from '../../hmr/hmr-strategy';
|
|
5
5
|
import type { ClientBridge } from './client-bridge';
|
|
6
6
|
import type { ClientBridgeEvent } from '../../public-types';
|
|
7
7
|
type BunSocketHandler = WebSocketHandler<unknown>;
|
|
@@ -9,19 +9,35 @@ export interface HmrManagerParams {
|
|
|
9
9
|
appConfig: EcoPagesAppConfig;
|
|
10
10
|
bridge: ClientBridge;
|
|
11
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
|
+
*/
|
|
12
23
|
export declare class HmrManager implements IHmrManager {
|
|
24
|
+
private static readonly entrypointRegistrationTimeoutMs;
|
|
13
25
|
readonly appConfig: EcoPagesAppConfig;
|
|
14
26
|
private readonly bridge;
|
|
15
27
|
/** Keep track of watchers */
|
|
16
28
|
private watchers;
|
|
17
29
|
/** entrypoint -> output path */
|
|
18
30
|
private watchedFiles;
|
|
19
|
-
|
|
20
|
-
private specifierMap;
|
|
31
|
+
private entrypointRegistrations;
|
|
21
32
|
private distDir;
|
|
22
33
|
private plugins;
|
|
23
34
|
private enabled;
|
|
24
35
|
private strategies;
|
|
36
|
+
private readonly entrypointRegistrar;
|
|
37
|
+
private readonly browserBundleService;
|
|
38
|
+
private readonly entrypointDependencyGraph;
|
|
39
|
+
private readonly runtimeSpecifierRegistry;
|
|
40
|
+
private readonly serverModuleTranspiler;
|
|
25
41
|
private wsHandler;
|
|
26
42
|
constructor({ appConfig, bridge }: HmrManagerParams);
|
|
27
43
|
/**
|
|
@@ -31,6 +47,15 @@ export declare class HmrManager implements IHmrManager {
|
|
|
31
47
|
* can share the same dist path during e2e runs.
|
|
32
48
|
*/
|
|
33
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;
|
|
34
59
|
/**
|
|
35
60
|
* Initializes core HMR strategies.
|
|
36
61
|
* Strategies are evaluated in priority order (highest first).
|
|
@@ -46,9 +71,13 @@ export declare class HmrManager implements IHmrManager {
|
|
|
46
71
|
setEnabled(enabled: boolean): void;
|
|
47
72
|
isEnabled(): boolean;
|
|
48
73
|
/**
|
|
49
|
-
* Registers
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
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.
|
|
52
81
|
*/
|
|
53
82
|
registerSpecifierMap(map: Record<string, string>): void;
|
|
54
83
|
getWebSocketHandler(): BunSocketHandler;
|
|
@@ -58,27 +87,57 @@ export declare class HmrManager implements IHmrManager {
|
|
|
58
87
|
buildRuntime(): Promise<void>;
|
|
59
88
|
getRuntimePath(): string;
|
|
60
89
|
broadcast(event: ClientBridgeEvent): void;
|
|
61
|
-
|
|
62
|
-
* Handles file changes using registered HMR strategies.
|
|
63
|
-
* Strategies are evaluated in priority order until one matches.
|
|
64
|
-
* @param filePath - Absolute path to the changed file
|
|
65
|
-
*/
|
|
66
|
-
handleFileChange(filePath: string): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Registers a client entrypoint to be built and watched by Bun.
|
|
69
|
-
*/
|
|
90
|
+
handleFileChange(filePath: string, options?: HandleFileChangeOptions): Promise<void>;
|
|
70
91
|
getOutputUrl(entrypointPath: string): string | undefined;
|
|
71
92
|
getWatchedFiles(): Map<string, string>;
|
|
72
93
|
getSpecifierMap(): Map<string, string>;
|
|
73
94
|
getDistDir(): string;
|
|
74
95
|
getPlugins(): EcoBuildPlugin[];
|
|
75
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
|
+
*/
|
|
76
106
|
registerEntrypoint(entrypointPath: string): Promise<string>;
|
|
77
107
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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.
|
|
80
140
|
*/
|
|
81
|
-
private encodeDynamicSegments;
|
|
82
141
|
stop(): void;
|
|
83
142
|
}
|
|
84
143
|
export {};
|
|
@@ -1,29 +1,59 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { RESOLVED_ASSETS_DIR } from "../../constants";
|
|
4
|
-
import {
|
|
4
|
+
import { getAppBuildExecutor } from "../../build/build-adapter.js";
|
|
5
5
|
import { fileSystem } from "@ecopages/file-system";
|
|
6
|
+
import { HmrStrategyType } from "../../hmr/hmr-strategy";
|
|
6
7
|
import { DefaultHmrStrategy } from "../../hmr/strategies/default-hmr-strategy";
|
|
7
8
|
import { JsHmrStrategy } from "../../hmr/strategies/js-hmr-strategy";
|
|
8
9
|
import { appLogger } from "../../global/app-logger";
|
|
10
|
+
import { HmrEntrypointRegistrar } from "../shared/hmr-entrypoint-registrar.js";
|
|
11
|
+
import { BrowserBundleService } from "../../services/assets/browser-bundle.service.js";
|
|
12
|
+
import { getAppServerModuleTranspiler } from "../../services/module-loading/app-server-module-transpiler.service";
|
|
13
|
+
import {
|
|
14
|
+
getAppEntrypointDependencyGraph,
|
|
15
|
+
NoopEntrypointDependencyGraph,
|
|
16
|
+
setAppEntrypointDependencyGraph
|
|
17
|
+
} from "../../services/runtime-state/entrypoint-dependency-graph.service.js";
|
|
18
|
+
import { getAppRuntimeSpecifierRegistry } from "../../services/runtime-state/runtime-specifier-registry.service.js";
|
|
19
|
+
import { resolveInternalExecutionDir, resolveInternalWorkDir } from "../../utils/resolve-work-dir.js";
|
|
9
20
|
class HmrManager {
|
|
21
|
+
static entrypointRegistrationTimeoutMs = 4e3;
|
|
10
22
|
appConfig;
|
|
11
23
|
bridge;
|
|
12
24
|
/** Keep track of watchers */
|
|
13
25
|
watchers = /* @__PURE__ */ new Map();
|
|
14
26
|
/** entrypoint -> output path */
|
|
15
27
|
watchedFiles = /* @__PURE__ */ new Map();
|
|
16
|
-
|
|
17
|
-
specifierMap = /* @__PURE__ */ new Map();
|
|
28
|
+
entrypointRegistrations = /* @__PURE__ */ new Map();
|
|
18
29
|
distDir;
|
|
19
30
|
plugins = [];
|
|
20
31
|
enabled = true;
|
|
21
32
|
strategies = [];
|
|
33
|
+
entrypointRegistrar;
|
|
34
|
+
browserBundleService;
|
|
35
|
+
entrypointDependencyGraph;
|
|
36
|
+
runtimeSpecifierRegistry;
|
|
37
|
+
serverModuleTranspiler;
|
|
22
38
|
wsHandler;
|
|
23
39
|
constructor({ appConfig, bridge }) {
|
|
24
40
|
this.appConfig = appConfig;
|
|
25
41
|
this.bridge = bridge;
|
|
26
|
-
this.distDir = path.join(this.appConfig
|
|
42
|
+
this.distDir = path.join(resolveInternalWorkDir(this.appConfig), RESOLVED_ASSETS_DIR, "_hmr");
|
|
43
|
+
this.entrypointRegistrar = new HmrEntrypointRegistrar({
|
|
44
|
+
srcDir: this.appConfig.absolutePaths.srcDir,
|
|
45
|
+
distDir: this.distDir,
|
|
46
|
+
entrypointRegistrations: this.entrypointRegistrations,
|
|
47
|
+
watchedFiles: this.watchedFiles,
|
|
48
|
+
clearFailedRegistration: (entrypointPath) => this.clearFailedEntrypointRegistration(entrypointPath),
|
|
49
|
+
registrationTimeoutMs: HmrManager.entrypointRegistrationTimeoutMs
|
|
50
|
+
});
|
|
51
|
+
this.browserBundleService = new BrowserBundleService(appConfig);
|
|
52
|
+
const existingEntrypointDependencyGraph = getAppEntrypointDependencyGraph(appConfig);
|
|
53
|
+
this.entrypointDependencyGraph = existingEntrypointDependencyGraph instanceof NoopEntrypointDependencyGraph ? existingEntrypointDependencyGraph : new NoopEntrypointDependencyGraph();
|
|
54
|
+
setAppEntrypointDependencyGraph(this.appConfig, this.entrypointDependencyGraph);
|
|
55
|
+
this.runtimeSpecifierRegistry = getAppRuntimeSpecifierRegistry(this.appConfig);
|
|
56
|
+
this.serverModuleTranspiler = getAppServerModuleTranspiler(this.appConfig);
|
|
27
57
|
this.cleanDistDir();
|
|
28
58
|
this.initializeStrategies();
|
|
29
59
|
}
|
|
@@ -36,6 +66,27 @@ class HmrManager {
|
|
|
36
66
|
cleanDistDir() {
|
|
37
67
|
fileSystem.ensureDir(this.distDir);
|
|
38
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns whether the generic JS strategy may rebuild an entrypoint.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Integration-owned page entrypoints are excluded so a shared dependency
|
|
74
|
+
* invalidation cannot replace framework-owned browser output with a generic JS
|
|
75
|
+
* rebuild.
|
|
76
|
+
*/
|
|
77
|
+
shouldJsStrategyProcessEntrypoint(entrypointPath) {
|
|
78
|
+
return !this.strategies.some((strategy) => {
|
|
79
|
+
if (strategy.type !== HmrStrategyType.INTEGRATION || strategy.priority <= HmrStrategyType.SCRIPT) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return strategy.matches(entrypointPath);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
appLogger.error(error);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
39
90
|
/**
|
|
40
91
|
* Initializes core HMR strategies.
|
|
41
92
|
* Strategies are evaluated in priority order (highest first).
|
|
@@ -43,10 +94,16 @@ class HmrManager {
|
|
|
43
94
|
initializeStrategies() {
|
|
44
95
|
const jsContext = {
|
|
45
96
|
getWatchedFiles: () => this.watchedFiles,
|
|
46
|
-
getSpecifierMap: () => this.
|
|
97
|
+
getSpecifierMap: () => this.runtimeSpecifierRegistry.getAll(),
|
|
47
98
|
getDistDir: () => this.distDir,
|
|
48
99
|
getPlugins: () => this.plugins,
|
|
49
|
-
getSrcDir: () => this.appConfig.absolutePaths.srcDir
|
|
100
|
+
getSrcDir: () => this.appConfig.absolutePaths.srcDir,
|
|
101
|
+
getPagesDir: () => this.appConfig.absolutePaths.pagesDir,
|
|
102
|
+
getLayoutsDir: () => this.appConfig.absolutePaths.layoutsDir,
|
|
103
|
+
getTemplateExtensions: () => this.appConfig.templatesExt,
|
|
104
|
+
getBrowserBundleService: () => this.browserBundleService,
|
|
105
|
+
getEntrypointDependencyGraph: () => this.entrypointDependencyGraph,
|
|
106
|
+
shouldProcessEntrypoint: (entrypointPath) => this.shouldJsStrategyProcessEntrypoint(entrypointPath)
|
|
50
107
|
};
|
|
51
108
|
this.strategies = [new JsHmrStrategy(jsContext), new DefaultHmrStrategy()];
|
|
52
109
|
}
|
|
@@ -68,14 +125,16 @@ class HmrManager {
|
|
|
68
125
|
return this.enabled;
|
|
69
126
|
}
|
|
70
127
|
/**
|
|
71
|
-
* Registers
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
128
|
+
* Registers runtime bare-specifier mappings exposed by integrations.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* These mappings are consumed by framework-owned HMR strategies that preserve
|
|
132
|
+
* shared runtime imports in browser bundles. The registry stays generic so
|
|
133
|
+
* these mappings can later support broader import-map-style runtime features
|
|
134
|
+
* without moving integration semantics into core.
|
|
74
135
|
*/
|
|
75
136
|
registerSpecifierMap(map) {
|
|
76
|
-
|
|
77
|
-
this.specifierMap.set(specifier, url);
|
|
78
|
-
}
|
|
137
|
+
this.runtimeSpecifierRegistry.register(map);
|
|
79
138
|
}
|
|
80
139
|
getWebSocketHandler() {
|
|
81
140
|
const open = (ws) => {
|
|
@@ -100,12 +159,12 @@ class HmrManager {
|
|
|
100
159
|
*/
|
|
101
160
|
async buildRuntime() {
|
|
102
161
|
const runtimeSource = path.resolve(import.meta.dirname, "../../hmr/client/hmr-runtime.js");
|
|
103
|
-
const result = await
|
|
162
|
+
const result = await this.browserBundleService.bundle({
|
|
163
|
+
profile: "hmr-runtime",
|
|
104
164
|
entrypoints: [runtimeSource],
|
|
105
165
|
outdir: this.distDir,
|
|
106
166
|
naming: "_hmr_runtime.js",
|
|
107
167
|
minify: false,
|
|
108
|
-
...defaultBuildAdapter.getTranspileOptions("hmr-runtime"),
|
|
109
168
|
plugins: this.plugins
|
|
110
169
|
});
|
|
111
170
|
if (!result.success) {
|
|
@@ -121,18 +180,13 @@ class HmrManager {
|
|
|
121
180
|
);
|
|
122
181
|
this.bridge.broadcast(event);
|
|
123
182
|
}
|
|
124
|
-
|
|
125
|
-
* Handles file changes using registered HMR strategies.
|
|
126
|
-
* Strategies are evaluated in priority order until one matches.
|
|
127
|
-
* @param filePath - Absolute path to the changed file
|
|
128
|
-
*/
|
|
129
|
-
async handleFileChange(filePath) {
|
|
183
|
+
async handleFileChange(filePath, options = {}) {
|
|
130
184
|
const sorted = [...this.strategies].sort((a, b) => b.priority - a.priority);
|
|
131
185
|
const strategy = sorted.find((s) => {
|
|
132
186
|
try {
|
|
133
187
|
return s.matches(filePath);
|
|
134
188
|
} catch (err) {
|
|
135
|
-
appLogger.error(
|
|
189
|
+
appLogger.error(err);
|
|
136
190
|
return false;
|
|
137
191
|
}
|
|
138
192
|
});
|
|
@@ -142,7 +196,8 @@ class HmrManager {
|
|
|
142
196
|
}
|
|
143
197
|
appLogger.debug(`[HmrManager] Selected strategy: ${strategy.constructor.name}`);
|
|
144
198
|
const action = await strategy.process(filePath);
|
|
145
|
-
|
|
199
|
+
const shouldBroadcast = options.broadcast ?? true;
|
|
200
|
+
if (shouldBroadcast && action.type === "broadcast") {
|
|
146
201
|
if (action.events) {
|
|
147
202
|
for (const event of action.events) {
|
|
148
203
|
this.broadcast(event);
|
|
@@ -150,9 +205,6 @@ class HmrManager {
|
|
|
150
205
|
}
|
|
151
206
|
}
|
|
152
207
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Registers a client entrypoint to be built and watched by Bun.
|
|
155
|
-
*/
|
|
156
208
|
getOutputUrl(entrypointPath) {
|
|
157
209
|
return this.watchedFiles.get(entrypointPath);
|
|
158
210
|
}
|
|
@@ -160,7 +212,7 @@ class HmrManager {
|
|
|
160
212
|
return this.watchedFiles;
|
|
161
213
|
}
|
|
162
214
|
getSpecifierMap() {
|
|
163
|
-
return this.
|
|
215
|
+
return this.runtimeSpecifierRegistry.getAll();
|
|
164
216
|
}
|
|
165
217
|
getDistDir() {
|
|
166
218
|
return this.distDir;
|
|
@@ -171,55 +223,110 @@ class HmrManager {
|
|
|
171
223
|
getDefaultContext() {
|
|
172
224
|
return {
|
|
173
225
|
getWatchedFiles: () => this.watchedFiles,
|
|
174
|
-
getSpecifierMap: () => this.
|
|
226
|
+
getSpecifierMap: () => this.runtimeSpecifierRegistry.getAll(),
|
|
175
227
|
getDistDir: () => this.distDir,
|
|
176
228
|
getPlugins: () => this.plugins,
|
|
177
229
|
getSrcDir: () => this.appConfig.absolutePaths.srcDir,
|
|
178
230
|
getLayoutsDir: () => this.appConfig.absolutePaths.layoutsDir,
|
|
179
|
-
getPagesDir: () => this.appConfig.absolutePaths.pagesDir
|
|
231
|
+
getPagesDir: () => this.appConfig.absolutePaths.pagesDir,
|
|
232
|
+
getBuildExecutor: () => getAppBuildExecutor(this.appConfig),
|
|
233
|
+
getBrowserBundleService: () => this.browserBundleService,
|
|
234
|
+
importServerModule: async (filePath) => await this.serverModuleTranspiler.importModule({
|
|
235
|
+
filePath,
|
|
236
|
+
outdir: path.join(resolveInternalExecutionDir(this.appConfig), ".server-modules"),
|
|
237
|
+
externalPackages: true
|
|
238
|
+
})
|
|
180
239
|
};
|
|
181
240
|
}
|
|
241
|
+
clearFailedEntrypointRegistration(entrypointPath) {
|
|
242
|
+
this.watchedFiles.delete(entrypointPath);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Registers one integration-owned page entrypoint.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* Concurrent callers share one in-flight registration. The registration is
|
|
249
|
+
* cleared from the dedupe map when it settles so later callers cannot inherit a
|
|
250
|
+
* stale promise.
|
|
251
|
+
*/
|
|
182
252
|
async registerEntrypoint(entrypointPath) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
253
|
+
return await this.entrypointRegistrar.registerEntrypoint(entrypointPath, {
|
|
254
|
+
emit: async (normalizedEntrypoint, outputPath) => await this.emitStrictEntrypoint(normalizedEntrypoint, outputPath),
|
|
255
|
+
getMissingOutputError: (normalizedEntrypoint, outputPath) => new Error(
|
|
256
|
+
`[HMR] Integration failed to emit entrypoint ${normalizedEntrypoint} to ${outputPath}. Page entrypoints must be produced by their owning integration.`
|
|
257
|
+
)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Registers one generic script entrypoint.
|
|
262
|
+
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* This explicit path keeps the page-entrypoint contract strict while still
|
|
265
|
+
* allowing generic script assets to use the fallback build path.
|
|
266
|
+
*/
|
|
267
|
+
async registerScriptEntrypoint(entrypointPath) {
|
|
268
|
+
return await this.entrypointRegistrar.registerEntrypoint(entrypointPath, {
|
|
269
|
+
emit: async (normalizedEntrypoint, outputPath) => await this.emitScriptEntrypoint(normalizedEntrypoint, outputPath),
|
|
270
|
+
getMissingOutputError: (normalizedEntrypoint) => new Error(`[HMR] Failed to register script entrypoint: ${normalizedEntrypoint}`)
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Performs strict integration-owned registration for one normalized path.
|
|
275
|
+
*
|
|
276
|
+
* @remarks
|
|
277
|
+
* The manager reserves the output URL, removes any stale emitted file, runs
|
|
278
|
+
* strategy processing without broadcasting, and then verifies that the owning
|
|
279
|
+
* integration emitted the expected file.
|
|
280
|
+
*/
|
|
281
|
+
async emitStrictEntrypoint(entrypointPath, _outputPath) {
|
|
282
|
+
await this.handleFileChange(entrypointPath, { broadcast: false });
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Performs registration for a generic script asset.
|
|
286
|
+
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* Strategies get the first chance to emit output. If no output exists after
|
|
289
|
+
* that pass, Bun falls back to the generic browser build for this explicit
|
|
290
|
+
* script-only path.
|
|
291
|
+
*/
|
|
292
|
+
async emitScriptEntrypoint(entrypointPath, outputPath) {
|
|
293
|
+
const naming = path.relative(this.distDir, outputPath).split(path.sep).join("/");
|
|
294
|
+
await this.handleFileChange(entrypointPath, { broadcast: false });
|
|
195
295
|
if (!fileSystem.exists(outputPath)) {
|
|
196
|
-
const
|
|
296
|
+
const buildResult = await this.browserBundleService.bundle({
|
|
297
|
+
profile: "hmr-entrypoint",
|
|
197
298
|
entrypoints: [entrypointPath],
|
|
198
299
|
outdir: this.distDir,
|
|
199
|
-
naming
|
|
300
|
+
naming,
|
|
200
301
|
minify: false,
|
|
201
|
-
external: Array.from(this.specifierMap.keys()),
|
|
202
|
-
...defaultBuildAdapter.getTranspileOptions("hmr-entrypoint"),
|
|
203
302
|
plugins: this.plugins
|
|
204
303
|
});
|
|
205
|
-
if (!
|
|
206
|
-
appLogger.error(
|
|
304
|
+
if (!buildResult.success) {
|
|
305
|
+
appLogger.error(
|
|
306
|
+
`[HMR] Generic script entrypoint build failed for ${entrypointPath}:`,
|
|
307
|
+
buildResult.logs
|
|
308
|
+
);
|
|
207
309
|
}
|
|
208
310
|
}
|
|
209
|
-
return outputUrl;
|
|
210
311
|
}
|
|
211
312
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
313
|
+
* Stops active watchers and releases retained registration state.
|
|
314
|
+
*
|
|
315
|
+
* @remarks
|
|
316
|
+
* Emitted `_hmr` files remain on disk because parallel app processes may share
|
|
317
|
+
* the same dist directory. The in-memory indexes are cleared so stale
|
|
318
|
+
* entrypoints and specifier maps cannot leak through a reused manager object.
|
|
214
319
|
*/
|
|
215
|
-
encodeDynamicSegments(filepath) {
|
|
216
|
-
return filepath.replace(/\[([^\]]+)\]/g, "_$1_");
|
|
217
|
-
}
|
|
218
320
|
stop() {
|
|
321
|
+
this.entrypointRegistrations.clear();
|
|
219
322
|
for (const watcher of this.watchers.values()) {
|
|
220
323
|
watcher.close();
|
|
221
324
|
}
|
|
222
325
|
this.watchers.clear();
|
|
326
|
+
this.watchedFiles.clear();
|
|
327
|
+
this.runtimeSpecifierRegistry.clear();
|
|
328
|
+
this.entrypointDependencyGraph.reset();
|
|
329
|
+
this.plugins = [];
|
|
223
330
|
}
|
|
224
331
|
}
|
|
225
332
|
export {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { EcopagesApp, createApp } from './create-app.js';
|
|
2
|
-
export { defineApiHandler, defineGroupHandler } from '
|
|
3
|
-
export type { GroupHandler } from './define-api-handler.js';
|
|
2
|
+
export { defineApiHandler, defineGroupHandler, type GroupHandler } from '../shared/define-api-handler.js';
|
|
@@ -4,8 +4,14 @@ import { createRequire } from "../../utils/locals-utils.js";
|
|
|
4
4
|
import { fileSystem } from "@ecopages/file-system";
|
|
5
5
|
import { SharedServerAdapter } from "../shared/server-adapter.js";
|
|
6
6
|
import { ApiResponseBuilder } from "../shared/api-response.js";
|
|
7
|
+
import { installSharedRuntimeBuildExecutor } from "../shared/runtime-bootstrap.js";
|
|
7
8
|
import { ServerRouteHandler } from "../shared/server-route-handler.js";
|
|
8
9
|
import { ServerStaticBuilder } from "../shared/server-static-builder";
|
|
10
|
+
import {
|
|
11
|
+
injectHmrRuntimeIntoHtmlResponse,
|
|
12
|
+
isHtmlResponse,
|
|
13
|
+
shouldInjectHmrHtmlResponse
|
|
14
|
+
} from "../shared/hmr-html-response";
|
|
9
15
|
import { ClientBridge } from "./client-bridge";
|
|
10
16
|
import { HmrManager } from "./hmr-manager";
|
|
11
17
|
import { ServerLifecycle } from "./server-lifecycle.js";
|
|
@@ -52,14 +58,13 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
52
58
|
* Only injects in watch mode when HMR manager is enabled.
|
|
53
59
|
*/
|
|
54
60
|
shouldInjectHmrScript() {
|
|
55
|
-
return this.options?.watch === true
|
|
61
|
+
return shouldInjectHmrHtmlResponse(this.options?.watch === true, this.hmrManager);
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* Checks if a response contains HTML content.
|
|
59
65
|
*/
|
|
60
66
|
isHtmlResponse(response) {
|
|
61
|
-
|
|
62
|
-
return contentType !== null && contentType.startsWith("text/html");
|
|
67
|
+
return isHtmlResponse(response);
|
|
63
68
|
}
|
|
64
69
|
/**
|
|
65
70
|
* Injects HMR script into HTML responses in development mode.
|
|
@@ -67,16 +72,7 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
67
72
|
*/
|
|
68
73
|
async maybeInjectHmrScript(response) {
|
|
69
74
|
if (this.shouldInjectHmrScript() && this.isHtmlResponse(response)) {
|
|
70
|
-
|
|
71
|
-
const hmrScript = `<script type="module">import '/_hmr_runtime.js';<\/script>`;
|
|
72
|
-
const updatedHtml = html.replace(/<\/html>/i, `${hmrScript}</html>`);
|
|
73
|
-
const headers = new Headers(response.headers);
|
|
74
|
-
headers.delete("Content-Length");
|
|
75
|
-
return new Response(updatedHtml, {
|
|
76
|
-
status: response.status,
|
|
77
|
-
statusText: response.statusText,
|
|
78
|
-
headers
|
|
79
|
-
});
|
|
75
|
+
return injectHmrRuntimeIntoHtmlResponse(response);
|
|
80
76
|
}
|
|
81
77
|
return response;
|
|
82
78
|
}
|
|
@@ -85,6 +81,9 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
85
81
|
* Delegates to ServerLifecycle for setup.
|
|
86
82
|
*/
|
|
87
83
|
async initialize() {
|
|
84
|
+
installSharedRuntimeBuildExecutor(this.appConfig, {
|
|
85
|
+
development: this.options?.watch === true
|
|
86
|
+
});
|
|
88
87
|
this.bridge = this.bridgeFactory ?? new ClientBridge();
|
|
89
88
|
this.hmrManager = this.hmrManagerFactory ?? new HmrManager({ appConfig: this.appConfig, bridge: this.bridge });
|
|
90
89
|
this.lifecycle = this.lifecycleFactory ?? new ServerLifecycle({
|
|
@@ -97,7 +96,8 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
97
96
|
const staticBuilderOptions = {
|
|
98
97
|
appConfig: this.appConfig,
|
|
99
98
|
staticSiteGenerator: this.staticSiteGenerator,
|
|
100
|
-
serveOptions: this.serveOptions
|
|
99
|
+
serveOptions: this.serveOptions,
|
|
100
|
+
apiHandlers: this.apiHandlers
|
|
101
101
|
};
|
|
102
102
|
this.staticBuilder = this.staticBuilderFactory ? this.staticBuilderFactory(staticBuilderOptions) : new ServerStaticBuilder(staticBuilderOptions);
|
|
103
103
|
await this.lifecycle.initializePlugins({ watch: this.options?.watch });
|
|
@@ -106,22 +106,23 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
106
106
|
* Refreshes the router routes during watch mode.
|
|
107
107
|
*/
|
|
108
108
|
async refreshRouterRoutes() {
|
|
109
|
-
if (this.serverInstance
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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: () => {
|
|
113
117
|
const options = this.getServerOptions({ enableHmr: true });
|
|
114
118
|
this.serverInstance.reload(options);
|
|
115
119
|
appLogger.debug("Server routes updated with dynamic routes");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
120
|
+
},
|
|
121
|
+
onError: (error) => {
|
|
122
|
+
this.hmrManager.broadcast({ type: "error", message: error.message });
|
|
123
|
+
appLogger.error("Failed to refresh router routes:", error);
|
|
121
124
|
}
|
|
122
|
-
}
|
|
123
|
-
appLogger.error("Server instance is not available for reloading");
|
|
124
|
-
}
|
|
125
|
+
})();
|
|
125
126
|
}
|
|
126
127
|
async watch() {
|
|
127
128
|
await this.lifecycle.startWatching({
|
|
@@ -246,8 +247,10 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
246
247
|
*/
|
|
247
248
|
async buildStatic(options) {
|
|
248
249
|
if (!this.fullyInitialized) {
|
|
249
|
-
await this.
|
|
250
|
-
|
|
250
|
+
await this.initializeSharedRouteHandling({
|
|
251
|
+
staticRoutes: this.staticRoutes,
|
|
252
|
+
hmrManager: this.hmrManager
|
|
253
|
+
});
|
|
251
254
|
}
|
|
252
255
|
await this.staticBuilder.build(options, {
|
|
253
256
|
router: this.router,
|
|
@@ -278,8 +281,10 @@ class BunServerAdapter extends SharedServerAdapter {
|
|
|
278
281
|
async _performInitialization(server) {
|
|
279
282
|
this.serverInstance = server;
|
|
280
283
|
appLogger.debug("Completing server initialization with dynamic routes");
|
|
281
|
-
await this.
|
|
282
|
-
|
|
284
|
+
await this.initializeSharedRouteHandling({
|
|
285
|
+
staticRoutes: this.staticRoutes,
|
|
286
|
+
hmrManager: this.hmrManager
|
|
287
|
+
});
|
|
283
288
|
this.fullyInitialized = true;
|
|
284
289
|
if (this.options?.watch) await this.watch();
|
|
285
290
|
if (server && typeof server.reload === "function") {
|