@ecopages/core 0.2.0-alpha.4 → 0.2.0-alpha.6
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/README.md +213 -12
- package/package.json +100 -188
- package/src/adapters/README.md +39 -0
- package/src/adapters/bun/hmr-manager.test.ts +267 -0
- package/src/adapters/bun/hmr-manager.ts +181 -68
- package/src/adapters/bun/index.ts +1 -2
- package/src/adapters/bun/server-adapter.ts +41 -34
- package/src/adapters/bun/server-lifecycle.ts +40 -70
- package/src/adapters/index.ts +1 -1
- package/src/adapters/node/bootstrap-dependency-resolver.test.ts +282 -0
- package/src/adapters/node/bootstrap-dependency-resolver.ts +301 -0
- package/src/adapters/node/index.ts +7 -0
- package/src/adapters/node/node-client-bridge.test.ts +198 -0
- package/src/adapters/node/node-hmr-manager.test.ts +322 -0
- package/src/adapters/node/node-hmr-manager.ts +208 -116
- package/src/adapters/node/runtime-adapter.test.ts +868 -0
- package/src/adapters/node/runtime-adapter.ts +439 -0
- package/src/adapters/node/server-adapter.ts +31 -104
- package/src/adapters/node/static-content-server.test.ts +60 -0
- package/src/adapters/node/static-content-server.ts +36 -0
- package/src/adapters/node/write-runtime-manifest.ts +38 -0
- package/src/adapters/shared/api-response.test.ts +97 -0
- package/src/{define-api-handler.ts → adapters/shared/define-api-handler.ts} +1 -1
- package/src/adapters/shared/explicit-static-route-matcher.test.ts +381 -0
- package/src/adapters/shared/explicit-static-route-matcher.ts +7 -1
- package/src/adapters/shared/file-route-middleware-pipeline.test.ts +90 -0
- package/src/adapters/shared/file-route-middleware-pipeline.ts +6 -2
- package/src/adapters/shared/fs-server-response-factory.test.ts +187 -0
- package/src/adapters/shared/fs-server-response-matcher.test.ts +286 -0
- package/src/adapters/shared/fs-server-response-matcher.ts +17 -10
- package/src/adapters/shared/hmr-entrypoint-registrar.ts +149 -0
- package/src/adapters/shared/hmr-html-response.ts +52 -0
- package/src/adapters/shared/hmr-manager.contract.test.ts +196 -0
- package/src/adapters/shared/hmr-manager.dispatch.test.ts +220 -0
- package/src/adapters/shared/render-context.test.ts +146 -0
- package/src/adapters/shared/render-context.ts +21 -6
- package/src/adapters/shared/runtime-bootstrap.ts +79 -0
- package/src/adapters/shared/server-adapter.test.ts +77 -0
- package/src/adapters/shared/server-adapter.ts +51 -4
- package/src/adapters/shared/server-route-handler.test.ts +110 -0
- package/src/adapters/shared/server-route-handler.ts +5 -18
- package/src/adapters/shared/server-static-builder.test.ts +316 -0
- package/src/adapters/shared/server-static-builder.ts +92 -8
- package/src/build/README.md +101 -0
- package/src/build/build-adapter-serialization.test.ts +268 -0
- package/src/build/build-adapter.test.ts +815 -0
- package/src/build/build-adapter.ts +235 -6
- package/src/build/build-manifest.ts +54 -0
- package/src/build/dev-build-coordinator.ts +221 -0
- package/src/build/esbuild-build-adapter.ts +132 -83
- package/src/build/runtime-build-executor.ts +34 -0
- package/src/build/runtime-specifier-alias-plugin.test.ts +43 -0
- package/src/build/runtime-specifier-alias-plugin.ts +58 -0
- package/src/config/README.md +33 -0
- package/src/config/config-builder.test.ts +410 -0
- package/src/config/config-builder.ts +281 -49
- package/src/constants.ts +15 -0
- package/src/declarations.d.ts +18 -13
- package/src/eco/README.md +70 -16
- package/src/eco/component-render-context.ts +39 -17
- package/src/eco/eco.test.ts +678 -0
- package/src/eco/eco.ts +29 -8
- package/src/eco/eco.types.ts +20 -1
- package/src/eco/eco.utils.test.ts +124 -0
- package/src/eco/global-injector-map.test.ts +42 -0
- package/src/eco/lazy-injector-map.test.ts +66 -0
- package/src/eco/module-dependencies.test.ts +30 -0
- package/src/errors/http-error.test.ts +134 -0
- package/src/global/utils.test.ts +12 -0
- package/src/hmr/README.md +26 -0
- 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 +38 -7
- package/src/hmr/hmr-strategy.test.ts +124 -0
- package/src/hmr/hmr.postcss.test.e2e.ts +41 -0
- package/src/hmr/hmr.test.e2e.ts +29 -38
- package/src/hmr/strategies/js-hmr-strategy.test.ts +335 -0
- package/src/hmr/strategies/js-hmr-strategy.ts +115 -115
- package/src/index.ts +1 -1
- package/src/integrations/ghtml/ghtml-renderer.test.ts +63 -0
- package/src/integrations/ghtml/ghtml-renderer.ts +4 -1
- package/src/internal-types.ts +39 -19
- package/src/plugins/README.md +34 -0
- package/src/plugins/alias-resolver-plugin.test.ts +41 -0
- package/src/plugins/alias-resolver-plugin.ts +21 -3
- package/src/plugins/eco-component-meta-plugin.test.ts +380 -0
- package/src/plugins/eco-component-meta-plugin.ts +10 -3
- package/src/plugins/integration-plugin.test.ts +111 -0
- package/src/plugins/integration-plugin.ts +45 -3
- package/src/plugins/processor.test.ts +148 -0
- package/src/plugins/processor.ts +22 -2
- package/src/plugins/runtime-capability.ts +14 -0
- package/src/public-types.ts +73 -16
- package/src/route-renderer/GRAPH.md +16 -20
- package/src/route-renderer/README.md +8 -21
- package/src/route-renderer/component-graph/component-graph-executor.test.ts +41 -0
- package/src/route-renderer/component-graph/component-graph.test.ts +63 -0
- package/src/route-renderer/component-graph/component-marker.test.ts +73 -0
- package/src/route-renderer/component-graph/component-reference.ts +29 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.test.ts +135 -0
- package/src/route-renderer/{marker-graph-resolver.ts → component-graph/marker-graph-resolver.ts} +11 -9
- package/src/route-renderer/orchestration/integration-renderer.test.ts +936 -0
- package/src/route-renderer/{integration-renderer.ts → orchestration/integration-renderer.ts} +113 -19
- package/src/route-renderer/orchestration/render-execution.service.test.ts +97 -0
- package/src/route-renderer/{render-execution.service.ts → orchestration/render-execution.service.ts} +109 -37
- package/src/route-renderer/orchestration/render-preparation.service.test.ts +235 -0
- package/src/route-renderer/{render-preparation.service.ts → orchestration/render-preparation.service.ts} +127 -9
- package/src/route-renderer/page-loading/dependency-resolver.test.ts +345 -0
- package/src/route-renderer/{dependency-resolver.ts → page-loading/dependency-resolver.ts} +28 -12
- package/src/route-renderer/page-loading/page-module-loader.test.ts +96 -0
- package/src/route-renderer/{page-module-loader.ts → page-loading/page-module-loader.ts} +49 -21
- package/src/route-renderer/route-renderer.ts +36 -1
- package/src/router/README.md +26 -0
- package/src/router/client/link-intent.d.ts +53 -0
- package/src/router/client/link-intent.test.browser.ts +51 -0
- package/src/router/client/link-intent.ts +92 -0
- package/src/router/client/navigation-coordinator.test.ts +237 -0
- package/src/router/client/navigation-coordinator.ts +433 -0
- package/src/router/server/fs-router-scanner.test.ts +83 -0
- package/src/router/{fs-router-scanner.ts → server/fs-router-scanner.ts} +12 -10
- package/src/router/server/fs-router.test.ts +214 -0
- package/src/router/{fs-router.ts → server/fs-router.ts} +2 -2
- package/src/services/README.md +29 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +385 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/asset-processing.service.ts +101 -6
- package/src/services/assets/asset-processing-service/asset.factory.test.ts +63 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/asset.factory.ts +2 -2
- package/src/services/{asset-processing-service → assets/asset-processing-service}/assets.types.ts +2 -1
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +72 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.ts +95 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +67 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.ts +78 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/index.ts +2 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.interface.ts +1 -1
- package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +59 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-processor.ts +11 -5
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-script-processor.ts +17 -27
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +286 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/file-script.processor.ts +3 -3
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +227 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/node-module-script.processor.ts +5 -4
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +199 -0
- package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/file-stylesheet.processor.ts +4 -1
- package/src/services/assets/browser-bundle.service.test.ts +36 -0
- package/src/services/assets/browser-bundle.service.ts +53 -0
- package/src/services/cache/index.ts +3 -3
- package/src/services/cache/memory-cache-store.test.ts +225 -0
- package/src/services/cache/memory-cache-store.ts +1 -1
- package/src/services/cache/page-cache-service.test.ts +175 -0
- package/src/services/cache/page-cache-service.ts +3 -3
- package/src/services/cache/page-request-cache-coordinator.service.test.ts +79 -0
- package/src/services/{page-request-cache-coordinator.service.ts → cache/page-request-cache-coordinator.service.ts} +9 -6
- package/src/services/html/html-rewriter-provider.service.test.ts +183 -0
- package/src/services/html/html-rewriter-provider.service.ts +103 -0
- package/src/services/html/html-transformer.service.test.ts +378 -0
- package/src/services/html/html-transformer.service.ts +279 -0
- package/src/services/invalidation/development-invalidation.service.test.ts +77 -0
- package/src/services/invalidation/development-invalidation.service.ts +261 -0
- package/src/services/module-loading/app-server-module-transpiler.service.ts +52 -0
- package/src/services/module-loading/page-module-import.service.test.ts +253 -0
- package/src/services/module-loading/page-module-import.service.ts +200 -0
- package/src/services/module-loading/server-loader.service.test.ts +161 -0
- package/src/services/module-loading/server-loader.service.ts +130 -0
- package/src/services/module-loading/server-module-transpiler.service.test.ts +115 -0
- package/src/services/module-loading/server-module-transpiler.service.ts +105 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.test.ts +95 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.ts +101 -0
- package/src/services/runtime-state/dev-graph.service.ts +217 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.ts +136 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.ts +96 -0
- package/src/services/runtime-state/server-invalidation-state.service.ts +68 -0
- package/src/services/validation/schema-validation-service.test.ts +223 -0
- package/src/services/{schema-validation-service.ts → validation/schema-validation-service.ts} +1 -1
- package/src/static-site-generator/README.md +26 -0
- package/src/static-site-generator/static-site-generator.test.ts +307 -0
- package/src/static-site-generator/static-site-generator.ts +109 -6
- package/src/utils/deep-merge.test.ts +114 -0
- package/src/utils/invariant.test.ts +22 -0
- package/src/utils/path-utils.test.ts +15 -0
- package/src/utils/resolve-work-dir.ts +45 -0
- package/src/utils/server-utils.test.ts +38 -0
- package/src/watchers/project-watcher.integration.test.ts +337 -0
- package/src/watchers/project-watcher.test-helpers.ts +1 -1
- package/src/watchers/project-watcher.test.ts +678 -0
- package/src/watchers/project-watcher.ts +130 -111
- package/CHANGELOG.md +0 -91
- package/src/adapters/abstract/application-adapter.d.ts +0 -168
- package/src/adapters/abstract/application-adapter.js +0 -109
- package/src/adapters/abstract/router-adapter.d.ts +0 -26
- package/src/adapters/abstract/router-adapter.js +0 -5
- package/src/adapters/abstract/server-adapter.d.ts +0 -69
- package/src/adapters/abstract/server-adapter.js +0 -15
- package/src/adapters/bun/client-bridge.d.ts +0 -34
- package/src/adapters/bun/client-bridge.js +0 -48
- package/src/adapters/bun/create-app.d.ts +0 -60
- package/src/adapters/bun/create-app.js +0 -117
- package/src/adapters/bun/define-api-handler.d.ts +0 -61
- package/src/adapters/bun/define-api-handler.js +0 -15
- package/src/adapters/bun/define-api-handler.ts +0 -114
- package/src/adapters/bun/hmr-manager.d.ts +0 -85
- package/src/adapters/bun/hmr-manager.js +0 -240
- package/src/adapters/bun/index.d.ts +0 -3
- package/src/adapters/bun/index.js +0 -8
- package/src/adapters/bun/server-adapter.d.ts +0 -155
- package/src/adapters/bun/server-adapter.js +0 -368
- package/src/adapters/bun/server-lifecycle.d.ts +0 -52
- package/src/adapters/bun/server-lifecycle.js +0 -120
- package/src/adapters/index.d.ts +0 -6
- package/src/adapters/index.js +0 -14
- package/src/adapters/node/create-app.d.ts +0 -21
- package/src/adapters/node/create-app.js +0 -143
- package/src/adapters/node/index.d.ts +0 -4
- package/src/adapters/node/index.js +0 -8
- package/src/adapters/node/node-client-bridge.d.ts +0 -26
- package/src/adapters/node/node-client-bridge.js +0 -66
- package/src/adapters/node/node-hmr-manager.d.ts +0 -63
- package/src/adapters/node/node-hmr-manager.js +0 -237
- package/src/adapters/node/server-adapter.d.ts +0 -190
- package/src/adapters/node/server-adapter.js +0 -420
- package/src/adapters/node/static-content-server.d.ts +0 -24
- package/src/adapters/node/static-content-server.js +0 -166
- package/src/adapters/shared/api-response.d.ts +0 -52
- package/src/adapters/shared/api-response.js +0 -96
- package/src/adapters/shared/application-adapter.d.ts +0 -18
- package/src/adapters/shared/application-adapter.js +0 -90
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +0 -38
- package/src/adapters/shared/explicit-static-route-matcher.js +0 -100
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +0 -65
- package/src/adapters/shared/file-route-middleware-pipeline.js +0 -98
- package/src/adapters/shared/fs-server-response-factory.d.ts +0 -19
- package/src/adapters/shared/fs-server-response-factory.js +0 -97
- package/src/adapters/shared/fs-server-response-matcher.d.ts +0 -71
- package/src/adapters/shared/fs-server-response-matcher.js +0 -155
- package/src/adapters/shared/render-context.d.ts +0 -14
- package/src/adapters/shared/render-context.js +0 -69
- package/src/adapters/shared/server-adapter.d.ts +0 -87
- package/src/adapters/shared/server-adapter.js +0 -353
- package/src/adapters/shared/server-route-handler.d.ts +0 -89
- package/src/adapters/shared/server-route-handler.js +0 -120
- package/src/adapters/shared/server-static-builder.d.ts +0 -38
- package/src/adapters/shared/server-static-builder.js +0 -46
- package/src/build/build-adapter.d.ts +0 -74
- package/src/build/build-adapter.js +0 -54
- package/src/build/build-types.d.ts +0 -57
- package/src/build/build-types.js +0 -0
- package/src/build/esbuild-build-adapter.d.ts +0 -69
- package/src/build/esbuild-build-adapter.js +0 -390
- package/src/config/config-builder.d.ts +0 -227
- package/src/config/config-builder.js +0 -392
- package/src/constants.d.ts +0 -32
- package/src/constants.js +0 -21
- package/src/create-app.d.ts +0 -17
- package/src/create-app.js +0 -66
- package/src/define-api-handler.d.ts +0 -25
- package/src/define-api-handler.js +0 -15
- package/src/dev/sc-server.d.ts +0 -30
- package/src/dev/sc-server.js +0 -111
- package/src/eco/component-render-context.d.ts +0 -105
- package/src/eco/component-render-context.js +0 -77
- package/src/eco/eco.d.ts +0 -9
- package/src/eco/eco.js +0 -110
- package/src/eco/eco.types.d.ts +0 -170
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.utils.d.ts +0 -40
- package/src/eco/eco.utils.js +0 -40
- package/src/eco/global-injector-map.d.ts +0 -16
- package/src/eco/global-injector-map.js +0 -80
- package/src/eco/lazy-injector-map.d.ts +0 -8
- package/src/eco/lazy-injector-map.js +0 -70
- package/src/eco/module-dependencies.d.ts +0 -18
- package/src/eco/module-dependencies.js +0 -49
- package/src/errors/http-error.d.ts +0 -31
- package/src/errors/http-error.js +0 -50
- package/src/errors/index.d.ts +0 -2
- package/src/errors/index.js +0 -4
- package/src/errors/locals-access-error.d.ts +0 -4
- package/src/errors/locals-access-error.js +0 -9
- package/src/global/app-logger.d.ts +0 -2
- package/src/global/app-logger.js +0 -6
- package/src/hmr/client/hmr-runtime.d.ts +0 -10
- package/src/hmr/client/hmr-runtime.js +0 -86
- package/src/hmr/hmr-strategy.d.ts +0 -159
- package/src/hmr/hmr-strategy.js +0 -29
- package/src/hmr/hmr.test.e2e.d.ts +0 -1
- package/src/hmr/hmr.test.e2e.js +0 -50
- package/src/hmr/strategies/default-hmr-strategy.d.ts +0 -43
- package/src/hmr/strategies/default-hmr-strategy.js +0 -34
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -136
- package/src/hmr/strategies/js-hmr-strategy.js +0 -188
- package/src/index.browser.d.ts +0 -3
- package/src/index.browser.js +0 -4
- package/src/index.d.ts +0 -5
- package/src/index.js +0 -10
- package/src/integrations/ghtml/ghtml-renderer.d.ts +0 -15
- package/src/integrations/ghtml/ghtml-renderer.js +0 -60
- package/src/integrations/ghtml/ghtml.plugin.d.ts +0 -20
- package/src/integrations/ghtml/ghtml.plugin.js +0 -21
- package/src/internal-types.d.ts +0 -200
- package/src/internal-types.js +0 -0
- package/src/plugins/alias-resolver-plugin.d.ts +0 -2
- package/src/plugins/alias-resolver-plugin.js +0 -39
- package/src/plugins/eco-component-meta-plugin.d.ts +0 -95
- package/src/plugins/eco-component-meta-plugin.js +0 -157
- package/src/plugins/integration-plugin.d.ts +0 -102
- package/src/plugins/integration-plugin.js +0 -100
- package/src/plugins/processor.d.ts +0 -82
- package/src/plugins/processor.js +0 -122
- package/src/public-types.d.ts +0 -1098
- package/src/public-types.js +0 -0
- package/src/route-renderer/component-graph-executor.d.ts +0 -32
- package/src/route-renderer/component-graph-executor.js +0 -31
- package/src/route-renderer/component-graph.d.ts +0 -42
- package/src/route-renderer/component-graph.js +0 -72
- package/src/route-renderer/component-marker.d.ts +0 -52
- package/src/route-renderer/component-marker.js +0 -46
- package/src/route-renderer/dependency-resolver.d.ts +0 -24
- package/src/route-renderer/dependency-resolver.js +0 -428
- 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.d.ts +0 -339
- package/src/route-renderer/integration-renderer.js +0 -526
- package/src/route-renderer/marker-graph-resolver.d.ts +0 -76
- package/src/route-renderer/marker-graph-resolver.js +0 -93
- package/src/route-renderer/page-module-loader.d.ts +0 -61
- package/src/route-renderer/page-module-loader.js +0 -102
- package/src/route-renderer/render-execution.service.d.ts +0 -69
- package/src/route-renderer/render-execution.service.js +0 -91
- package/src/route-renderer/render-preparation.service.d.ts +0 -112
- package/src/route-renderer/render-preparation.service.js +0 -243
- package/src/route-renderer/route-renderer.d.ts +0 -26
- package/src/route-renderer/route-renderer.js +0 -68
- package/src/router/fs-router-scanner.d.ts +0 -41
- package/src/router/fs-router-scanner.js +0 -155
- package/src/router/fs-router.d.ts +0 -26
- package/src/router/fs-router.js +0 -100
- package/src/services/asset-processing-service/asset-processing.service.d.ts +0 -41
- package/src/services/asset-processing-service/asset-processing.service.js +0 -250
- package/src/services/asset-processing-service/asset.factory.d.ts +0 -17
- package/src/services/asset-processing-service/asset.factory.js +0 -82
- package/src/services/asset-processing-service/assets.types.d.ts +0 -88
- package/src/services/asset-processing-service/assets.types.js +0 -0
- package/src/services/asset-processing-service/index.d.ts +0 -3
- package/src/services/asset-processing-service/index.js +0 -3
- package/src/services/asset-processing-service/processor.interface.d.ts +0 -22
- package/src/services/asset-processing-service/processor.interface.js +0 -6
- package/src/services/asset-processing-service/processor.registry.d.ts +0 -8
- package/src/services/asset-processing-service/processor.registry.js +0 -15
- package/src/services/asset-processing-service/processors/base/base-processor.d.ts +0 -24
- package/src/services/asset-processing-service/processors/base/base-processor.js +0 -59
- package/src/services/asset-processing-service/processors/base/base-script-processor.d.ts +0 -16
- package/src/services/asset-processing-service/processors/base/base-script-processor.js +0 -80
- package/src/services/asset-processing-service/processors/index.d.ts +0 -5
- package/src/services/asset-processing-service/processors/index.js +0 -5
- package/src/services/asset-processing-service/processors/script/content-script.processor.d.ts +0 -5
- package/src/services/asset-processing-service/processors/script/content-script.processor.js +0 -57
- package/src/services/asset-processing-service/processors/script/file-script.processor.d.ts +0 -8
- package/src/services/asset-processing-service/processors/script/file-script.processor.js +0 -76
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.d.ts +0 -7
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.js +0 -74
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +0 -5
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +0 -25
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +0 -9
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +0 -63
- package/src/services/cache/cache.types.d.ts +0 -107
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/index.d.ts +0 -7
- package/src/services/cache/index.js +0 -7
- package/src/services/cache/memory-cache-store.d.ts +0 -42
- package/src/services/cache/memory-cache-store.js +0 -98
- package/src/services/cache/page-cache-service.d.ts +0 -70
- package/src/services/cache/page-cache-service.js +0 -152
- 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.d.ts +0 -75
- package/src/services/page-request-cache-coordinator.service.js +0 -107
- package/src/services/schema-validation-service.d.ts +0 -122
- package/src/services/schema-validation-service.js +0 -101
- package/src/services/validation/standard-schema.types.d.ts +0 -65
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -57
- package/src/static-site-generator/static-site-generator.js +0 -272
- package/src/utils/css.d.ts +0 -1
- package/src/utils/css.js +0 -7
- package/src/utils/deep-merge.d.ts +0 -14
- package/src/utils/deep-merge.js +0 -32
- package/src/utils/hash.d.ts +0 -1
- package/src/utils/hash.js +0 -7
- package/src/utils/html.d.ts +0 -1
- package/src/utils/html.js +0 -4
- package/src/utils/invariant.d.ts +0 -5
- package/src/utils/invariant.js +0 -11
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -24
- package/src/utils/parse-cli-args.d.ts +0 -24
- package/src/utils/parse-cli-args.js +0 -47
- package/src/utils/path-utils.module.d.ts +0 -5
- package/src/utils/path-utils.module.js +0 -14
- package/src/utils/runtime.d.ts +0 -11
- package/src/utils/runtime.js +0 -40
- package/src/utils/server-utils.module.d.ts +0 -19
- package/src/utils/server-utils.module.js +0 -56
- package/src/watchers/project-watcher.d.ts +0 -125
- package/src/watchers/project-watcher.js +0 -265
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -4
- package/src/watchers/project-watcher.test-helpers.js +0 -52
- /package/src/route-renderer/{component-graph-executor.ts → component-graph/component-graph-executor.ts} +0 -0
- /package/src/route-renderer/{component-graph.ts → component-graph/component-graph.ts} +0 -0
- /package/src/route-renderer/{component-marker.ts → component-graph/component-marker.ts} +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.registry.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/index.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/content-script.processor.ts +0 -0
- /package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/content-stylesheet.processor.ts +0 -0
package/src/utils/html.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { html } from 'ghtml';
|
package/src/utils/html.js
DELETED
package/src/utils/invariant.d.ts
DELETED
package/src/utils/invariant.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ApiHandlerContext } from '../public-types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a require function for validating and retrieving request locals.
|
|
4
|
-
* Supports both single key access and multiple keys with type safety.
|
|
5
|
-
*
|
|
6
|
-
* @param getLocals - Function that returns the current locals object
|
|
7
|
-
* @returns A require function that throws the onMissing response if keys are not found
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const require = createRequire(() => context.locals);
|
|
12
|
-
* const userId = require('userId', () => new Response('Unauthorized', { status: 401 }));
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare function createRequire(getLocals: () => Record<string, unknown>): ApiHandlerContext['require'];
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
function createRequire(getLocals) {
|
|
2
|
-
return (keyOrKeys, onMissing) => {
|
|
3
|
-
const locals = getLocals();
|
|
4
|
-
if (Array.isArray(keyOrKeys)) {
|
|
5
|
-
const result = {};
|
|
6
|
-
for (const key of keyOrKeys) {
|
|
7
|
-
const value2 = locals[key];
|
|
8
|
-
if (value2 === void 0 || value2 === null) {
|
|
9
|
-
throw onMissing();
|
|
10
|
-
}
|
|
11
|
-
result[key] = value2;
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
const value = locals[keyOrKeys];
|
|
16
|
-
if (value === void 0 || value === null) {
|
|
17
|
-
throw onMissing();
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
createRequire
|
|
24
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parsed command line arguments for the Ecopages server.
|
|
3
|
-
* @property preview - Whether to run in preview mode
|
|
4
|
-
* @property build - Whether to run a static build
|
|
5
|
-
* @property start - Whether to start the server
|
|
6
|
-
* @property dev - Whether to run in development mode
|
|
7
|
-
* @property port - Optional port number
|
|
8
|
-
* @property hostname - Optional hostname
|
|
9
|
-
* @property reactFastRefresh - Whether React Fast Refresh is enabled
|
|
10
|
-
*/
|
|
11
|
-
export type ReturnParseCliArgs = {
|
|
12
|
-
preview: boolean;
|
|
13
|
-
build: boolean;
|
|
14
|
-
start: boolean;
|
|
15
|
-
dev: boolean;
|
|
16
|
-
port?: number;
|
|
17
|
-
hostname?: string;
|
|
18
|
-
reactFastRefresh?: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Parses command line arguments for the server.
|
|
22
|
-
* It returns {@link ReturnParseCliArgs}
|
|
23
|
-
*/
|
|
24
|
-
export declare function parseCliArgs(): ReturnParseCliArgs;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from "node:util";
|
|
2
|
-
import { getRuntimeArgv } from "./runtime.js";
|
|
3
|
-
const ECOPAGES_BIN_FILES = ["ecopages.ts", "ecopages.js", "cli.js"];
|
|
4
|
-
const ECOPAGES_AVAILABLE_COMMANDS = ["dev", "build", "start", "preview"];
|
|
5
|
-
function parseCliArgs() {
|
|
6
|
-
const runtimeArgv = getRuntimeArgv();
|
|
7
|
-
const { values } = parseArgs({
|
|
8
|
-
args: runtimeArgv,
|
|
9
|
-
options: {
|
|
10
|
-
dev: { type: "boolean" },
|
|
11
|
-
preview: { type: "boolean" },
|
|
12
|
-
build: { type: "boolean" },
|
|
13
|
-
port: { type: "string" },
|
|
14
|
-
hostname: { type: "string" },
|
|
15
|
-
"react-fast-refresh": { type: "boolean" }
|
|
16
|
-
},
|
|
17
|
-
allowPositionals: true
|
|
18
|
-
});
|
|
19
|
-
let command = "";
|
|
20
|
-
const ecopagesIndex = runtimeArgv.findIndex((arg) => ECOPAGES_BIN_FILES.some((filename) => arg.endsWith(filename)));
|
|
21
|
-
const isAvailableCommand = ecopagesIndex !== -1;
|
|
22
|
-
if (isAvailableCommand) {
|
|
23
|
-
command = ecopagesIndex < runtimeArgv.length - 1 && ECOPAGES_AVAILABLE_COMMANDS.some((cmd) => {
|
|
24
|
-
return runtimeArgv[ecopagesIndex + 1] === cmd;
|
|
25
|
-
}) ? runtimeArgv[ecopagesIndex + 1] : "start";
|
|
26
|
-
}
|
|
27
|
-
const isStartCommand = command === "start" || !values.dev && !values.build && !values.preview;
|
|
28
|
-
const isDevCommand = command === "dev" || !!values.dev;
|
|
29
|
-
const isBuildCommand = command === "build" || !!values.build;
|
|
30
|
-
const isPreviewCommand = command === "preview" || !!values.preview;
|
|
31
|
-
const parsedCommandOptions = {
|
|
32
|
-
preview: isPreviewCommand,
|
|
33
|
-
build: isBuildCommand,
|
|
34
|
-
start: isStartCommand,
|
|
35
|
-
dev: isDevCommand,
|
|
36
|
-
port: values.port ? Number(values.port) : void 0,
|
|
37
|
-
hostname: values.hostname,
|
|
38
|
-
reactFastRefresh: values["react-fast-refresh"]
|
|
39
|
-
};
|
|
40
|
-
if (!process.env.NODE_ENV) {
|
|
41
|
-
process.env.NODE_ENV = isDevCommand ? "development" : "production";
|
|
42
|
-
}
|
|
43
|
-
return parsedCommandOptions;
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
parseCliArgs
|
|
47
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
function getEcoTemplateExtension(filePath) {
|
|
3
|
-
const { name, ext } = path.parse(filePath);
|
|
4
|
-
const nameParts = name.split(".");
|
|
5
|
-
const descriptor = nameParts.length > 1 ? nameParts.pop() : void 0;
|
|
6
|
-
const templateExtension = descriptor ? `.${descriptor}${ext}` : ext;
|
|
7
|
-
return templateExtension;
|
|
8
|
-
}
|
|
9
|
-
const PathUtils = {
|
|
10
|
-
getEcoTemplateExtension
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
PathUtils
|
|
14
|
-
};
|
package/src/utils/runtime.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const RUNTIME_ERRORS: {
|
|
2
|
-
readonly BUN_RUNTIME_REQUIRED: "Bun runtime is required";
|
|
3
|
-
};
|
|
4
|
-
type RuntimeBun = typeof Bun;
|
|
5
|
-
export declare function getBunRuntime(): RuntimeBun | undefined;
|
|
6
|
-
export declare function getRequiredBunRuntime(): RuntimeBun;
|
|
7
|
-
export declare function getRuntimeArgv(): string[];
|
|
8
|
-
export declare function isDevelopmentRuntime(): boolean;
|
|
9
|
-
export declare function isProductionRuntime(): boolean;
|
|
10
|
-
export declare function runtimeHash(content: string | Buffer<ArrayBufferLike>): number | bigint;
|
|
11
|
-
export {};
|
package/src/utils/runtime.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
const RUNTIME_ERRORS = {
|
|
3
|
-
BUN_RUNTIME_REQUIRED: "Bun runtime is required"
|
|
4
|
-
};
|
|
5
|
-
function getBunRuntime() {
|
|
6
|
-
return globalThis.Bun;
|
|
7
|
-
}
|
|
8
|
-
function getRequiredBunRuntime() {
|
|
9
|
-
const bun = getBunRuntime();
|
|
10
|
-
if (!bun) {
|
|
11
|
-
throw new Error(RUNTIME_ERRORS.BUN_RUNTIME_REQUIRED);
|
|
12
|
-
}
|
|
13
|
-
return bun;
|
|
14
|
-
}
|
|
15
|
-
function getRuntimeArgv() {
|
|
16
|
-
return process.argv;
|
|
17
|
-
}
|
|
18
|
-
function isDevelopmentRuntime() {
|
|
19
|
-
return process.env.NODE_ENV === "development";
|
|
20
|
-
}
|
|
21
|
-
function isProductionRuntime() {
|
|
22
|
-
return process.env.NODE_ENV === "production";
|
|
23
|
-
}
|
|
24
|
-
function runtimeHash(content) {
|
|
25
|
-
const bun = getBunRuntime();
|
|
26
|
-
if (bun) {
|
|
27
|
-
return bun.hash(content);
|
|
28
|
-
}
|
|
29
|
-
const hex = createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
30
|
-
return BigInt(`0x${hex}`);
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
RUNTIME_ERRORS,
|
|
34
|
-
getBunRuntime,
|
|
35
|
-
getRequiredBunRuntime,
|
|
36
|
-
getRuntimeArgv,
|
|
37
|
-
isDevelopmentRuntime,
|
|
38
|
-
isProductionRuntime,
|
|
39
|
-
runtimeHash
|
|
40
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the content type of a file based on its extension.
|
|
3
|
-
* @param file - The file name.
|
|
4
|
-
* @returns The content type.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getContentType: (file: string) => string;
|
|
7
|
-
/**
|
|
8
|
-
* Check if a file path has a known static file extension.
|
|
9
|
-
* @param file - The file name or path.
|
|
10
|
-
* @returns true if the extension is recognized.
|
|
11
|
-
*/
|
|
12
|
-
export declare const hasKnownExtension: (file: string) => boolean;
|
|
13
|
-
/**
|
|
14
|
-
* A module for server utilities.
|
|
15
|
-
*/
|
|
16
|
-
export declare const ServerUtils: {
|
|
17
|
-
getContentType: (file: string) => string;
|
|
18
|
-
hasKnownExtension: (file: string) => boolean;
|
|
19
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const ContentTypeMap = /* @__PURE__ */ new Map([
|
|
2
|
-
["jpg", "image/jpeg"],
|
|
3
|
-
["jpeg", "image/jpeg"],
|
|
4
|
-
["png", "image/png"],
|
|
5
|
-
["gif", "image/gif"],
|
|
6
|
-
["bmp", "image/bmp"],
|
|
7
|
-
["svg", "image/svg+xml"],
|
|
8
|
-
["tiff", "image/tiff"],
|
|
9
|
-
["webp", "image/webp"],
|
|
10
|
-
["avif", "image/avif"],
|
|
11
|
-
["ico", "image/x-icon"],
|
|
12
|
-
["mp3", "audio/mpeg"],
|
|
13
|
-
["ogg", "audio/ogg"],
|
|
14
|
-
["wav", "audio/wav"],
|
|
15
|
-
["mp4", "video/mp4"],
|
|
16
|
-
["webm", "video/webm"],
|
|
17
|
-
["ogv", "video/ogg"],
|
|
18
|
-
["mov", "video/quicktime"],
|
|
19
|
-
["txt", "text/plain"],
|
|
20
|
-
["html", "text/html"],
|
|
21
|
-
["css", "text/css"],
|
|
22
|
-
["js", "text/javascript"],
|
|
23
|
-
["mjs", "text/javascript"],
|
|
24
|
-
["json", "application/json"],
|
|
25
|
-
["map", "application/json"],
|
|
26
|
-
["xml", "application/xml"],
|
|
27
|
-
["webmanifest", "application/manifest+json"],
|
|
28
|
-
["wasm", "application/wasm"],
|
|
29
|
-
["csv", "text/csv"],
|
|
30
|
-
["ttf", "font/ttf"],
|
|
31
|
-
["woff", "font/woff"],
|
|
32
|
-
["woff2", "font/woff2"],
|
|
33
|
-
["otf", "font/otf"],
|
|
34
|
-
["eot", "application/vnd.ms-fontobject"],
|
|
35
|
-
["gz", "application/x-gzip"],
|
|
36
|
-
["zip", "application/zip"],
|
|
37
|
-
["pdf", "application/pdf"],
|
|
38
|
-
["doc", "application/msword"]
|
|
39
|
-
]);
|
|
40
|
-
const getContentType = (file) => {
|
|
41
|
-
const extension = file.split(".").pop() || "txt";
|
|
42
|
-
return ContentTypeMap.get(extension) || "text/plain";
|
|
43
|
-
};
|
|
44
|
-
const hasKnownExtension = (file) => {
|
|
45
|
-
const extension = file.split(".").pop();
|
|
46
|
-
return extension !== void 0 && ContentTypeMap.has(extension);
|
|
47
|
-
};
|
|
48
|
-
const ServerUtils = {
|
|
49
|
-
getContentType,
|
|
50
|
-
hasKnownExtension
|
|
51
|
-
};
|
|
52
|
-
export {
|
|
53
|
-
ServerUtils,
|
|
54
|
-
getContentType,
|
|
55
|
-
hasKnownExtension
|
|
56
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { type FSWatcher } from 'chokidar';
|
|
2
|
-
import type { EcoPagesAppConfig, IHmrManager, IClientBridge } from '../internal-types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for the ProjectWatcher
|
|
5
|
-
* @interface ProjectWatcherConfig
|
|
6
|
-
* @property {EcoPagesAppConfig} config - The application configuration
|
|
7
|
-
* @property {() => void} refreshRouterRoutesCallback - Callback to refresh router routes
|
|
8
|
-
* @property {IHmrManager} hmrManager - The HMR manager instance
|
|
9
|
-
* @property {ClientBridge} bridge - The client bridge instance
|
|
10
|
-
*/
|
|
11
|
-
export interface ProjectWatcherConfig {
|
|
12
|
-
config: EcoPagesAppConfig;
|
|
13
|
-
refreshRouterRoutesCallback: () => void;
|
|
14
|
-
hmrManager: IHmrManager;
|
|
15
|
-
bridge: IClientBridge;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* ProjectWatcher handles file system changes for hot module replacement (HMR).
|
|
19
|
-
* It uses chokidar to watch for file changes and triggers appropriate actions:
|
|
20
|
-
* - Uncaches modules when files change
|
|
21
|
-
* - Refreshes router routes for page files
|
|
22
|
-
* - Triggers HMR server reload
|
|
23
|
-
* - Handles processor-specific file changes
|
|
24
|
-
*
|
|
25
|
-
* The watcher uses chokidar's built-in debouncing through `awaitWriteFinish`
|
|
26
|
-
* to handle rapid file changes efficiently:
|
|
27
|
-
* - stabilityThreshold: 50ms - Time to wait for writes to stabilize
|
|
28
|
-
* - pollInterval: 50ms - Interval to poll for file changes
|
|
29
|
-
*
|
|
30
|
-
* @class ProjectWatcher
|
|
31
|
-
*/
|
|
32
|
-
export declare class ProjectWatcher {
|
|
33
|
-
/**
|
|
34
|
-
* Duplicate identical watcher events within this window are ignored.
|
|
35
|
-
*
|
|
36
|
-
* Some editors or save pipelines emit two near-identical filesystem change
|
|
37
|
-
* notifications for the same file. Ecopages should treat those as one logical
|
|
38
|
-
* update so HMR and route refresh work are not repeated unnecessarily.
|
|
39
|
-
*/
|
|
40
|
-
private static readonly duplicateChangeWindowMs;
|
|
41
|
-
private appConfig;
|
|
42
|
-
private refreshRouterRoutesCallback;
|
|
43
|
-
private hmrManager;
|
|
44
|
-
private bridge;
|
|
45
|
-
private watcher;
|
|
46
|
-
private lastHandledChange;
|
|
47
|
-
constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge }: ProjectWatcherConfig);
|
|
48
|
-
/**
|
|
49
|
-
* Uncaches modules in the source directory to ensure fresh imports.
|
|
50
|
-
* This is necessary for hot module replacement to work correctly.
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
private uncacheModules;
|
|
54
|
-
/**
|
|
55
|
-
* Handles public directory file changes by copying only the changed file.
|
|
56
|
-
* @param filePath - Absolute path of the changed file
|
|
57
|
-
*/
|
|
58
|
-
private handlePublicDirFileChange;
|
|
59
|
-
/**
|
|
60
|
-
* Handles file changes by uncaching modules, refreshing routes, and delegating appropriately.
|
|
61
|
-
* Follows 4-rule priority:
|
|
62
|
-
* 0. Public directory match? → copy file and reload
|
|
63
|
-
* 1. additionalWatchPaths match? → reload
|
|
64
|
-
* 2. Processor extension match? → processor handles (skip HMR)
|
|
65
|
-
* 3. Otherwise → HMR strategies
|
|
66
|
-
*
|
|
67
|
-
* Duplicate identical watcher events for the same file are coalesced within a
|
|
68
|
-
* short window before any of the priority rules run.
|
|
69
|
-
* @param rawPath - Path of the changed file
|
|
70
|
-
*/
|
|
71
|
-
private handleFileChange;
|
|
72
|
-
/**
|
|
73
|
-
* Checks if a file is in the public directory.
|
|
74
|
-
*/
|
|
75
|
-
private isPublicDirFile;
|
|
76
|
-
/**
|
|
77
|
-
* Checks if file path matches any additionalWatchPaths patterns.
|
|
78
|
-
*/
|
|
79
|
-
private matchesAdditionalWatchPaths;
|
|
80
|
-
/**
|
|
81
|
-
* Checks whether a file is watched by any processor, even if that processor
|
|
82
|
-
* does not own the file as a primary asset.
|
|
83
|
-
*/
|
|
84
|
-
private isWatchedByProcessor;
|
|
85
|
-
/**
|
|
86
|
-
* Checks if a file is handled by a processor.
|
|
87
|
-
* Processors that declare extensions own those file types.
|
|
88
|
-
*/
|
|
89
|
-
private isHandledByProcessor;
|
|
90
|
-
/**
|
|
91
|
-
* Triggers router refresh for page directory changes.
|
|
92
|
-
* This ensures the router is updated when pages are added or removed.
|
|
93
|
-
*
|
|
94
|
-
* @param {string} path - Path of the changed directory
|
|
95
|
-
*/
|
|
96
|
-
triggerRouterRefresh(path: string): void;
|
|
97
|
-
/**
|
|
98
|
-
* Handles and logs errors that occur during file watching.
|
|
99
|
-
*
|
|
100
|
-
* @param {unknown} error - The error to handle
|
|
101
|
-
*/
|
|
102
|
-
handleError(error: unknown): void;
|
|
103
|
-
/**
|
|
104
|
-
* Processes file changes for specific file extensions.
|
|
105
|
-
* Used by processors to handle their specific file types.
|
|
106
|
-
*
|
|
107
|
-
* @private
|
|
108
|
-
* @param {string} path - Path of the changed file
|
|
109
|
-
* @param {string[]} extensions - File extensions to process
|
|
110
|
-
* @param {(ctx: ProcessorWatchContext) => void} handler - Handler function for the file change
|
|
111
|
-
*/
|
|
112
|
-
private shouldProcess;
|
|
113
|
-
/**
|
|
114
|
-
* Creates and configures the file system watcher.
|
|
115
|
-
* This sets up:
|
|
116
|
-
* 1. Processor-specific file watching
|
|
117
|
-
* 2. Page file watching
|
|
118
|
-
* 3. Directory watching
|
|
119
|
-
* 4. Error handling
|
|
120
|
-
*
|
|
121
|
-
* Uses chokidar's built-in debouncing through `awaitWriteFinish` to handle
|
|
122
|
-
* rapid file changes efficiently.
|
|
123
|
-
*/
|
|
124
|
-
createWatcherSubscription(): Promise<FSWatcher>;
|
|
125
|
-
}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import chokidar, {} from "chokidar";
|
|
3
|
-
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
-
import { appLogger } from "../global/app-logger.js";
|
|
5
|
-
class ProjectWatcher {
|
|
6
|
-
/**
|
|
7
|
-
* Duplicate identical watcher events within this window are ignored.
|
|
8
|
-
*
|
|
9
|
-
* Some editors or save pipelines emit two near-identical filesystem change
|
|
10
|
-
* notifications for the same file. Ecopages should treat those as one logical
|
|
11
|
-
* update so HMR and route refresh work are not repeated unnecessarily.
|
|
12
|
-
*/
|
|
13
|
-
static duplicateChangeWindowMs = 150;
|
|
14
|
-
appConfig;
|
|
15
|
-
refreshRouterRoutesCallback;
|
|
16
|
-
hmrManager;
|
|
17
|
-
bridge;
|
|
18
|
-
watcher = null;
|
|
19
|
-
lastHandledChange = /* @__PURE__ */ new Map();
|
|
20
|
-
constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge }) {
|
|
21
|
-
this.appConfig = config;
|
|
22
|
-
this.refreshRouterRoutesCallback = refreshRouterRoutesCallback;
|
|
23
|
-
this.hmrManager = hmrManager;
|
|
24
|
-
this.bridge = bridge;
|
|
25
|
-
this.triggerRouterRefresh = this.triggerRouterRefresh.bind(this);
|
|
26
|
-
this.handleError = this.handleError.bind(this);
|
|
27
|
-
this.handleFileChange = this.handleFileChange.bind(this);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Uncaches modules in the source directory to ensure fresh imports.
|
|
31
|
-
* This is necessary for hot module replacement to work correctly.
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
uncacheModules() {
|
|
35
|
-
if (typeof require === "undefined") return;
|
|
36
|
-
const { srcDir, rootDir } = this.appConfig;
|
|
37
|
-
const regex = new RegExp(`${rootDir}/${srcDir}/.*`);
|
|
38
|
-
for (const key in require.cache) {
|
|
39
|
-
if (regex.test(key)) {
|
|
40
|
-
delete require.cache[key];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Handles public directory file changes by copying only the changed file.
|
|
46
|
-
* @param filePath - Absolute path of the changed file
|
|
47
|
-
*/
|
|
48
|
-
async handlePublicDirFileChange(filePath) {
|
|
49
|
-
try {
|
|
50
|
-
const relativePath = path.relative(this.appConfig.absolutePaths.publicDir, filePath);
|
|
51
|
-
const destPath = path.join(this.appConfig.absolutePaths.distDir, relativePath);
|
|
52
|
-
if (fileSystem.exists(filePath)) {
|
|
53
|
-
const destDir = path.dirname(destPath);
|
|
54
|
-
fileSystem.ensureDir(destDir);
|
|
55
|
-
await fileSystem.copyFileAsync(filePath, destPath);
|
|
56
|
-
}
|
|
57
|
-
this.bridge.reload();
|
|
58
|
-
} catch (error) {
|
|
59
|
-
appLogger.error(`Failed to copy public file: ${error instanceof Error ? error.message : String(error)}`);
|
|
60
|
-
this.bridge.reload();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Handles file changes by uncaching modules, refreshing routes, and delegating appropriately.
|
|
65
|
-
* Follows 4-rule priority:
|
|
66
|
-
* 0. Public directory match? → copy file and reload
|
|
67
|
-
* 1. additionalWatchPaths match? → reload
|
|
68
|
-
* 2. Processor extension match? → processor handles (skip HMR)
|
|
69
|
-
* 3. Otherwise → HMR strategies
|
|
70
|
-
*
|
|
71
|
-
* Duplicate identical watcher events for the same file are coalesced within a
|
|
72
|
-
* short window before any of the priority rules run.
|
|
73
|
-
* @param rawPath - Path of the changed file
|
|
74
|
-
*/
|
|
75
|
-
async handleFileChange(rawPath) {
|
|
76
|
-
const filePath = path.resolve(rawPath);
|
|
77
|
-
const now = Date.now();
|
|
78
|
-
const lastHandledAt = this.lastHandledChange.get(filePath);
|
|
79
|
-
if (lastHandledAt !== void 0 && now - lastHandledAt < ProjectWatcher.duplicateChangeWindowMs) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.lastHandledChange.set(filePath, now);
|
|
83
|
-
try {
|
|
84
|
-
if (this.isPublicDirFile(filePath)) {
|
|
85
|
-
await this.handlePublicDirFileChange(filePath);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
this.uncacheModules();
|
|
89
|
-
const isPageFile = filePath.startsWith(this.appConfig.absolutePaths.pagesDir);
|
|
90
|
-
if (isPageFile) {
|
|
91
|
-
this.refreshRouterRoutesCallback();
|
|
92
|
-
}
|
|
93
|
-
if (this.matchesAdditionalWatchPaths(filePath)) {
|
|
94
|
-
this.bridge.reload();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (this.isHandledByProcessor(filePath)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (this.isWatchedByProcessor(filePath) && !this.hmrManager.canHandleFileChange(filePath)) {
|
|
101
|
-
this.hmrManager.broadcast({ type: "layout-update" });
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
await this.hmrManager.handleFileChange(filePath);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
if (error instanceof Error) {
|
|
107
|
-
this.bridge.error(error.message);
|
|
108
|
-
this.handleError(error);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Checks if a file is in the public directory.
|
|
114
|
-
*/
|
|
115
|
-
isPublicDirFile(filePath) {
|
|
116
|
-
return filePath.startsWith(this.appConfig.absolutePaths.publicDir);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Checks if file path matches any additionalWatchPaths patterns.
|
|
120
|
-
*/
|
|
121
|
-
matchesAdditionalWatchPaths(filePath) {
|
|
122
|
-
const patterns = this.appConfig.additionalWatchPaths;
|
|
123
|
-
if (!patterns.length) return false;
|
|
124
|
-
for (const pattern of patterns) {
|
|
125
|
-
if (pattern.includes("*")) {
|
|
126
|
-
const ext = pattern.replace(/\*\*?\/\*/, "");
|
|
127
|
-
if (filePath.endsWith(ext)) return true;
|
|
128
|
-
} else {
|
|
129
|
-
if (filePath.endsWith(pattern) || filePath === path.resolve(pattern)) return true;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Checks whether a file is watched by any processor, even if that processor
|
|
136
|
-
* does not own the file as a primary asset.
|
|
137
|
-
*/
|
|
138
|
-
isWatchedByProcessor(filePath) {
|
|
139
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
140
|
-
const watchConfig = processor.getWatchConfig();
|
|
141
|
-
if (!watchConfig) continue;
|
|
142
|
-
const { extensions = [] } = watchConfig;
|
|
143
|
-
if (extensions.length && extensions.some((ext) => filePath.endsWith(ext))) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Checks if a file is handled by a processor.
|
|
151
|
-
* Processors that declare extensions own those file types.
|
|
152
|
-
*/
|
|
153
|
-
isHandledByProcessor(filePath) {
|
|
154
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
155
|
-
const capabilities = processor.getAssetCapabilities?.() ?? [];
|
|
156
|
-
if (capabilities.length > 0) {
|
|
157
|
-
const matchesConfiguredAsset = typeof processor.matchesFileFilter !== "function" || processor.matchesFileFilter(filePath);
|
|
158
|
-
if (matchesConfiguredAsset && capabilities.some((capability) => processor.canProcessAsset?.(capability.kind, filePath))) {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const watchConfig = processor.getWatchConfig();
|
|
164
|
-
if (!watchConfig) continue;
|
|
165
|
-
const { extensions = [] } = watchConfig;
|
|
166
|
-
if (extensions.length && extensions.some((ext) => filePath.endsWith(ext))) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Triggers router refresh for page directory changes.
|
|
174
|
-
* This ensures the router is updated when pages are added or removed.
|
|
175
|
-
*
|
|
176
|
-
* @param {string} path - Path of the changed directory
|
|
177
|
-
*/
|
|
178
|
-
triggerRouterRefresh(path2) {
|
|
179
|
-
const isPageDir = path2.startsWith(this.appConfig.absolutePaths.pagesDir);
|
|
180
|
-
if (isPageDir) {
|
|
181
|
-
this.refreshRouterRoutesCallback();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Handles and logs errors that occur during file watching.
|
|
186
|
-
*
|
|
187
|
-
* @param {unknown} error - The error to handle
|
|
188
|
-
*/
|
|
189
|
-
handleError(error) {
|
|
190
|
-
if (error instanceof Error) {
|
|
191
|
-
this.hmrManager.broadcast({ type: "error", message: error.message });
|
|
192
|
-
}
|
|
193
|
-
appLogger.error(`Watcher error: ${error}`);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Processes file changes for specific file extensions.
|
|
197
|
-
* Used by processors to handle their specific file types.
|
|
198
|
-
*
|
|
199
|
-
* @private
|
|
200
|
-
* @param {string} path - Path of the changed file
|
|
201
|
-
* @param {string[]} extensions - File extensions to process
|
|
202
|
-
* @param {(ctx: ProcessorWatchContext) => void} handler - Handler function for the file change
|
|
203
|
-
*/
|
|
204
|
-
shouldProcess(path2, extensions, handler) {
|
|
205
|
-
if (!extensions.length || extensions.some((ext) => path2.endsWith(ext))) {
|
|
206
|
-
handler({ path: path2, bridge: this.bridge });
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Creates and configures the file system watcher.
|
|
211
|
-
* This sets up:
|
|
212
|
-
* 1. Processor-specific file watching
|
|
213
|
-
* 2. Page file watching
|
|
214
|
-
* 3. Directory watching
|
|
215
|
-
* 4. Error handling
|
|
216
|
-
*
|
|
217
|
-
* Uses chokidar's built-in debouncing through `awaitWriteFinish` to handle
|
|
218
|
-
* rapid file changes efficiently.
|
|
219
|
-
*/
|
|
220
|
-
async createWatcherSubscription() {
|
|
221
|
-
if (!this.watcher) {
|
|
222
|
-
const processorPaths = [];
|
|
223
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
224
|
-
const watchConfig = processor.getWatchConfig();
|
|
225
|
-
if (!watchConfig) continue;
|
|
226
|
-
processorPaths.push(...watchConfig.paths);
|
|
227
|
-
}
|
|
228
|
-
if (fileSystem.exists(this.appConfig.absolutePaths.pagesDir)) {
|
|
229
|
-
processorPaths.push(this.appConfig.absolutePaths.pagesDir);
|
|
230
|
-
}
|
|
231
|
-
if (fileSystem.exists(this.appConfig.absolutePaths.publicDir)) {
|
|
232
|
-
processorPaths.push(this.appConfig.absolutePaths.publicDir);
|
|
233
|
-
}
|
|
234
|
-
if (this.appConfig.additionalWatchPaths.length) {
|
|
235
|
-
processorPaths.push(...this.appConfig.additionalWatchPaths);
|
|
236
|
-
}
|
|
237
|
-
this.watcher = chokidar.watch(processorPaths, {
|
|
238
|
-
ignoreInitial: true,
|
|
239
|
-
ignorePermissionErrors: true,
|
|
240
|
-
awaitWriteFinish: {
|
|
241
|
-
stabilityThreshold: 50,
|
|
242
|
-
pollInterval: 50
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
247
|
-
const watchConfig = processor.getWatchConfig();
|
|
248
|
-
if (!watchConfig) continue;
|
|
249
|
-
const { extensions = [], onCreate, onChange, onDelete, onError } = watchConfig;
|
|
250
|
-
if (onCreate) this.watcher.on("add", (path2) => this.shouldProcess(path2, extensions, onCreate));
|
|
251
|
-
if (onChange) this.watcher.on("change", (path2) => this.shouldProcess(path2, extensions, onChange));
|
|
252
|
-
if (onDelete) this.watcher.on("unlink", (path2) => this.shouldProcess(path2, extensions, onDelete));
|
|
253
|
-
if (onError) this.watcher.on("error", onError);
|
|
254
|
-
}
|
|
255
|
-
this.watcher.add(this.appConfig.absolutePaths.srcDir);
|
|
256
|
-
this.watcher.on("change", (path2) => this.handleFileChange(path2)).on("add", (path2) => {
|
|
257
|
-
this.handleFileChange(path2);
|
|
258
|
-
this.triggerRouterRefresh(path2);
|
|
259
|
-
}).on("addDir", (path2) => this.triggerRouterRefresh(path2)).on("unlink", (path2) => this.triggerRouterRefresh(path2)).on("unlinkDir", (path2) => this.triggerRouterRefresh(path2)).on("error", (error) => this.handleError(error));
|
|
260
|
-
return this.watcher;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
export {
|
|
264
|
-
ProjectWatcher
|
|
265
|
-
};
|