@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,27 +0,0 @@
|
|
|
1
|
-
import type { IHmrManager } from '../../internal-types';
|
|
2
|
-
import type { AssetDefinition, ProcessedAsset } from './assets.types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Base interface for asset processors.
|
|
6
|
-
* Processors transform asset definitions into processed assets.
|
|
7
|
-
*/
|
|
8
|
-
export interface AssetProcessor<T extends AssetDefinition = AssetDefinition> {
|
|
9
|
-
process(asset: T): Promise<ProcessedAsset>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Interface for processors that support HMR (Hot Module Replacement).
|
|
14
|
-
* These processors can receive an HMR manager to enable hot reloading capabilities.
|
|
15
|
-
*/
|
|
16
|
-
export interface HmrAwareProcessor extends AssetProcessor {
|
|
17
|
-
setHmrManager(hmrManager: IHmrManager): void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Type guard to check if a processor supports HMR.
|
|
22
|
-
* @param processor - The processor to check
|
|
23
|
-
* @returns True if the processor implements HmrAwareProcessor
|
|
24
|
-
*/
|
|
25
|
-
export function isHmrAware(processor: AssetProcessor): processor is HmrAwareProcessor {
|
|
26
|
-
return 'setHmrManager' in processor && typeof (processor as HmrAwareProcessor).setHmrManager === 'function';
|
|
27
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AssetKind, AssetSource } from './assets.types';
|
|
2
|
-
import type { BaseProcessor } from './processors/base/base-processor';
|
|
3
|
-
|
|
4
|
-
export class ProcessorRegistry {
|
|
5
|
-
private processors = new Map<`${AssetKind}-${AssetSource}`, BaseProcessor<any>>();
|
|
6
|
-
|
|
7
|
-
register(kind: AssetKind, variant: AssetSource, processor: BaseProcessor<any>) {
|
|
8
|
-
this.processors.set(`${kind}-${variant}`, processor);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
getProcessor(kind: AssetKind, variant: AssetSource): BaseProcessor<any> | undefined {
|
|
12
|
-
return this.processors.get(`${kind}-${variant}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getAllProcessors(): Map<`${AssetKind}-${AssetSource}`, BaseProcessor<any>> {
|
|
16
|
-
return this.processors;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { RESOLVED_ASSETS_DIR } from '../../../../constants.ts';
|
|
3
|
-
import type { EcoPagesAppConfig } from '../../../../internal-types.ts';
|
|
4
|
-
import { rapidhash } from '../../../../utils/hash.ts';
|
|
5
|
-
import { isDevelopmentRuntime, isProductionRuntime } from '../../../../utils/runtime.ts';
|
|
6
|
-
import type { BaseAsset, ProcessedAsset } from '../../assets.types.ts';
|
|
7
|
-
|
|
8
|
-
export abstract class BaseProcessor<T extends BaseAsset> {
|
|
9
|
-
protected appConfig: EcoPagesAppConfig;
|
|
10
|
-
/**
|
|
11
|
-
* Cache for processed assets to avoid reprocessing the same asset multiple times.
|
|
12
|
-
* The cache key is a combination of the asset name and its hash.
|
|
13
|
-
* The cache value is the processed asset.
|
|
14
|
-
*/
|
|
15
|
-
protected cache: Map<string, ProcessedAsset> = new Map();
|
|
16
|
-
|
|
17
|
-
constructor({ appConfig }: { appConfig: EcoPagesAppConfig }) {
|
|
18
|
-
this.appConfig = appConfig;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get isDevelopment(): boolean {
|
|
22
|
-
return isDevelopmentRuntime();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get isProduction(): boolean {
|
|
26
|
-
return isProductionRuntime();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
abstract process(dep: T): Promise<ProcessedAsset>;
|
|
30
|
-
|
|
31
|
-
protected getAssetsDir(): string {
|
|
32
|
-
return path.join(this.appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected writeCacheFile(key: string, path: ProcessedAsset): void {
|
|
36
|
-
this.cache.set(key, path);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected getCacheFile(key: string): ProcessedAsset | undefined {
|
|
40
|
-
return this.cache.get(key);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
protected hasCacheFile(key: string): boolean {
|
|
44
|
-
return this.cache.has(key);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected generateHash(content: string): string {
|
|
48
|
-
return rapidhash(content).toString();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected buildCacheKey(identifier: string, contentHash: string, dep: T): string {
|
|
52
|
-
const attrsHash = dep.attributes ? this.generateHash(JSON.stringify(dep.attributes)) : '';
|
|
53
|
-
const position = dep.position ?? '';
|
|
54
|
-
return `${identifier}:${contentHash}:${position}:${attrsHash}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected getOrProcess(
|
|
58
|
-
cacheKey: string,
|
|
59
|
-
processFn: () => ProcessedAsset | Promise<ProcessedAsset>,
|
|
60
|
-
): Promise<ProcessedAsset> {
|
|
61
|
-
if (this.hasCacheFile(cacheKey)) {
|
|
62
|
-
return Promise.resolve(this.getCacheFile(cacheKey) as ProcessedAsset);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const result = processFn();
|
|
66
|
-
if (result instanceof Promise) {
|
|
67
|
-
return result.then((asset) => {
|
|
68
|
-
this.writeCacheFile(cacheKey, asset);
|
|
69
|
-
return asset;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.writeCacheFile(cacheKey, result);
|
|
74
|
-
return Promise.resolve(result);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { appLogger } from '../../../../global/app-logger';
|
|
2
|
-
import type { EcoPagesAppConfig } from '../../../../internal-types';
|
|
3
|
-
import { defaultBuildAdapter } from '../../../../build/build-adapter.ts';
|
|
4
|
-
import type { EcoBuildPlugin } from '../../../../build/build-types.ts';
|
|
5
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import type { ScriptAsset } from '../../assets.types';
|
|
8
|
-
import { BaseProcessor } from './base-processor';
|
|
9
|
-
|
|
10
|
-
export abstract class BaseScriptProcessor<T extends ScriptAsset> extends BaseProcessor<T> {
|
|
11
|
-
constructor({ appConfig }: { appConfig: EcoPagesAppConfig }) {
|
|
12
|
-
super({ appConfig });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
protected shouldBundle(dep: T): boolean {
|
|
16
|
-
return dep.bundle !== false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
protected getBundlerOptions(dep: T): Record<string, any> {
|
|
20
|
-
return dep.bundleOptions || {};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected collectBuildPlugins(): EcoBuildPlugin[] {
|
|
24
|
-
const plugins: EcoBuildPlugin[] = [];
|
|
25
|
-
|
|
26
|
-
if (this.appConfig.processors?.size) {
|
|
27
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
28
|
-
if (processor.buildPlugins) {
|
|
29
|
-
plugins.push(...processor.buildPlugins);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (this.appConfig.loaders?.size) {
|
|
35
|
-
plugins.push(...this.appConfig.loaders.values());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return plugins;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected async bundleScript({
|
|
42
|
-
entrypoint,
|
|
43
|
-
outdir,
|
|
44
|
-
plugins: additionalPlugins,
|
|
45
|
-
...rest
|
|
46
|
-
}: {
|
|
47
|
-
entrypoint: string;
|
|
48
|
-
outdir: string;
|
|
49
|
-
} & ScriptAsset['bundleOptions']): Promise<string> {
|
|
50
|
-
const buildPlugins = this.collectBuildPlugins();
|
|
51
|
-
const allPlugins = additionalPlugins ? [...additionalPlugins, ...buildPlugins] : buildPlugins;
|
|
52
|
-
|
|
53
|
-
const build = await defaultBuildAdapter.build({
|
|
54
|
-
entrypoints: [entrypoint],
|
|
55
|
-
outdir,
|
|
56
|
-
root: this.appConfig.rootDir,
|
|
57
|
-
...defaultBuildAdapter.getTranspileOptions('browser-script'),
|
|
58
|
-
splitting: true,
|
|
59
|
-
naming: '[name]-[hash].[ext]',
|
|
60
|
-
plugins: allPlugins,
|
|
61
|
-
...rest,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (!build.success) {
|
|
65
|
-
for (const log of build.logs) {
|
|
66
|
-
appLogger.debug(log.message, log);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const entryBaseName = path.parse(entrypoint).name;
|
|
71
|
-
const entryOutput = build.outputs
|
|
72
|
-
.map((output) => output.path)
|
|
73
|
-
.find((outputPath) => path.basename(outputPath) === `${entryBaseName}.js`);
|
|
74
|
-
|
|
75
|
-
if (entryOutput) {
|
|
76
|
-
return entryOutput;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const nonVendorOutput = build.outputs
|
|
80
|
-
.map((output) => output.path)
|
|
81
|
-
.find((outputPath) => !path.basename(outputPath).startsWith('vendors'));
|
|
82
|
-
|
|
83
|
-
if (nonVendorOutput) {
|
|
84
|
-
return nonVendorOutput;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const primaryOutput = build.outputs[0]?.path;
|
|
88
|
-
if (primaryOutput) {
|
|
89
|
-
return primaryOutput;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const namedFallbackOutput = path.join(outdir, `${entryBaseName}.js`);
|
|
93
|
-
if (fileSystem.exists(namedFallbackOutput)) {
|
|
94
|
-
return namedFallbackOutput;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const fallbackOutput = path.join(outdir, 'entry_0.js');
|
|
98
|
-
if (fileSystem.exists(fallbackOutput)) {
|
|
99
|
-
return fallbackOutput;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const logMessage = build.logs.map((log) => log.message).join(' | ');
|
|
103
|
-
throw new Error(`No build output generated for ${entrypoint}${logMessage ? `: ${logMessage}` : ''}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * from './script/content-script.processor';
|
|
2
|
-
export * from './script/file-script.processor';
|
|
3
|
-
export * from './script/node-module-script.processor';
|
|
4
|
-
export * from './stylesheet/content-stylesheet.processor';
|
|
5
|
-
export * from './stylesheet/file-stylesheet.processor';
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import type { ContentScriptAsset, ProcessedAsset } from '../../assets.types';
|
|
4
|
-
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
5
|
-
|
|
6
|
-
export class ContentScriptProcessor extends BaseScriptProcessor<ContentScriptAsset> {
|
|
7
|
-
async process(dep: ContentScriptAsset): Promise<ProcessedAsset> {
|
|
8
|
-
const hash = this.generateHash(dep.content);
|
|
9
|
-
const filename = dep.name ? `${dep.name}.js` : `script-${hash}.js`;
|
|
10
|
-
const shouldBundle = this.shouldBundle(dep);
|
|
11
|
-
|
|
12
|
-
const filepath = path.join(this.getAssetsDir(), 'scripts', filename);
|
|
13
|
-
|
|
14
|
-
if (!shouldBundle) {
|
|
15
|
-
if (!dep.inline) fileSystem.write(filepath, dep.content);
|
|
16
|
-
const unbundledProcessedAsset: ProcessedAsset = {
|
|
17
|
-
filepath,
|
|
18
|
-
content: dep.inline ? dep.content : undefined,
|
|
19
|
-
kind: 'script',
|
|
20
|
-
position: dep.position,
|
|
21
|
-
attributes: dep.attributes,
|
|
22
|
-
inline: dep.inline,
|
|
23
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
this.writeCacheFile(filename, unbundledProcessedAsset);
|
|
27
|
-
return unbundledProcessedAsset;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (dep.content) {
|
|
31
|
-
const tempDir = this.appConfig.absolutePaths.distDir;
|
|
32
|
-
fileSystem.ensureDir(tempDir);
|
|
33
|
-
const tempFileName = path.join(
|
|
34
|
-
tempDir,
|
|
35
|
-
`${path.parse(filename).name}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp.js`,
|
|
36
|
-
);
|
|
37
|
-
fileSystem.write(tempFileName, dep.content);
|
|
38
|
-
|
|
39
|
-
const bundledFilePath = await this.bundleScript({
|
|
40
|
-
entrypoint: tempFileName,
|
|
41
|
-
outdir: this.getAssetsDir(),
|
|
42
|
-
minify: this.isProduction,
|
|
43
|
-
naming: `${path.parse(filename).name}-[hash].[ext]`,
|
|
44
|
-
...this.getBundlerOptions(dep),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const processedAsset: ProcessedAsset = {
|
|
48
|
-
filepath: bundledFilePath,
|
|
49
|
-
content: dep.inline ? fileSystem.readFileSync(bundledFilePath).toString() : undefined,
|
|
50
|
-
kind: 'script',
|
|
51
|
-
position: dep.position,
|
|
52
|
-
attributes: dep.attributes,
|
|
53
|
-
inline: dep.inline,
|
|
54
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
fileSystem.remove(tempFileName);
|
|
58
|
-
|
|
59
|
-
this.writeCacheFile(filename, processedAsset);
|
|
60
|
-
|
|
61
|
-
return processedAsset;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
throw new Error('No content found for script asset');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { RESOLVED_ASSETS_DIR } from '../../../../constants';
|
|
3
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
4
|
-
import type { IHmrManager } from '../../../../internal-types';
|
|
5
|
-
import type { FileScriptAsset, ProcessedAsset } from '../../assets.types';
|
|
6
|
-
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
7
|
-
|
|
8
|
-
export class FileScriptProcessor extends BaseScriptProcessor<FileScriptAsset> {
|
|
9
|
-
private hmrManager?: IHmrManager;
|
|
10
|
-
|
|
11
|
-
setHmrManager(hmrManager: IHmrManager) {
|
|
12
|
-
this.hmrManager = hmrManager;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async process(dep: FileScriptAsset): Promise<ProcessedAsset> {
|
|
16
|
-
/**
|
|
17
|
-
* If HMR Manager is active, delegate build/watch to it.
|
|
18
|
-
*/
|
|
19
|
-
if (this.hmrManager?.isEnabled() && !dep.inline) {
|
|
20
|
-
const outputUrl = await this.hmrManager.registerEntrypoint(dep.filepath);
|
|
21
|
-
return {
|
|
22
|
-
filepath: dep.filepath,
|
|
23
|
-
srcUrl: outputUrl,
|
|
24
|
-
kind: 'script',
|
|
25
|
-
position: dep.position,
|
|
26
|
-
attributes: dep.attributes,
|
|
27
|
-
inline: false,
|
|
28
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const content = fileSystem.readFileSync(dep.filepath);
|
|
33
|
-
const shouldBundle = this.shouldBundle(dep);
|
|
34
|
-
const configHash = this.generateHash(
|
|
35
|
-
JSON.stringify({
|
|
36
|
-
bundle: shouldBundle,
|
|
37
|
-
minify: shouldBundle && this.isProduction,
|
|
38
|
-
opts: dep.bundleOptions,
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
const cachekey = `${this.buildCacheKey(dep.filepath, this.generateHash(content), dep)}:${configHash}`;
|
|
42
|
-
|
|
43
|
-
return this.getOrProcess(cachekey, async () => {
|
|
44
|
-
if (!shouldBundle) {
|
|
45
|
-
const outFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
|
|
46
|
-
let filepath: string | undefined;
|
|
47
|
-
|
|
48
|
-
if (!dep.inline) {
|
|
49
|
-
filepath = path.join(this.getAssetsDir(), outFilepath);
|
|
50
|
-
fileSystem.copyFile(dep.filepath, filepath);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
filepath,
|
|
55
|
-
content,
|
|
56
|
-
kind: 'script',
|
|
57
|
-
position: dep.position,
|
|
58
|
-
attributes: dep.attributes,
|
|
59
|
-
inline: dep.inline,
|
|
60
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const relativeFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
|
|
65
|
-
const outdirPath = path.join(this.appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR, relativeFilepath);
|
|
66
|
-
const outdirDirname = path.dirname(outdirPath);
|
|
67
|
-
const bundlerOptions = this.getBundlerOptions(dep);
|
|
68
|
-
|
|
69
|
-
const bundledFilePath = await this.bundleScript({
|
|
70
|
-
entrypoint: dep.filepath,
|
|
71
|
-
outdir: outdirDirname,
|
|
72
|
-
minify: this.isProduction,
|
|
73
|
-
...bundlerOptions,
|
|
74
|
-
plugins: bundlerOptions.plugins,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
filepath: bundledFilePath,
|
|
79
|
-
content: dep.inline ? fileSystem.readFileSync(bundledFilePath).toString() : undefined,
|
|
80
|
-
kind: 'script',
|
|
81
|
-
position: dep.position,
|
|
82
|
-
attributes: dep.attributes,
|
|
83
|
-
inline: dep.inline,
|
|
84
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import { defaultBuildAdapter } from '../../../../build/build-adapter.ts';
|
|
4
|
-
import type { NodeModuleScriptAsset } from '../../assets.types';
|
|
5
|
-
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
6
|
-
|
|
7
|
-
export class NodeModuleScriptProcessor extends BaseScriptProcessor<NodeModuleScriptAsset> {
|
|
8
|
-
async process(dep: NodeModuleScriptAsset) {
|
|
9
|
-
const modulePath = this.resolveModulePath(dep.importPath, this.appConfig.rootDir);
|
|
10
|
-
const moduleName = path.basename(modulePath);
|
|
11
|
-
const filename = dep.name ?? `nm-${moduleName}`;
|
|
12
|
-
const configHash = this.generateHash(
|
|
13
|
-
JSON.stringify({ inline: dep.inline, minify: !dep.inline && this.isProduction, opts: dep.bundleOptions }),
|
|
14
|
-
);
|
|
15
|
-
const cachekey = `${this.buildCacheKey(filename, this.generateHash(modulePath), dep)}:${configHash}`;
|
|
16
|
-
|
|
17
|
-
return this.getOrProcess(cachekey, async () => {
|
|
18
|
-
if (dep.inline) {
|
|
19
|
-
const content = fileSystem.readFileAsBuffer(modulePath).toString();
|
|
20
|
-
return {
|
|
21
|
-
content,
|
|
22
|
-
kind: dep.kind,
|
|
23
|
-
position: dep.position,
|
|
24
|
-
attributes: dep.attributes,
|
|
25
|
-
inline: true,
|
|
26
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const outdir = path.join(this.getAssetsDir(), 'vendors');
|
|
31
|
-
|
|
32
|
-
const filePath = await this.bundleScript({
|
|
33
|
-
entrypoint: modulePath,
|
|
34
|
-
outdir: outdir,
|
|
35
|
-
minify: this.isProduction,
|
|
36
|
-
naming: dep.name ? `${dep.name}-[hash].[ext]` : '[name]-[hash].[ext]',
|
|
37
|
-
...this.getBundlerOptions(dep),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
filepath: filePath,
|
|
42
|
-
kind: dep.kind,
|
|
43
|
-
position: dep.position,
|
|
44
|
-
attributes: dep.attributes,
|
|
45
|
-
inline: dep.inline,
|
|
46
|
-
excludeFromHtml: dep.excludeFromHtml,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private resolveModulePath(importPath: string, rootDir: string): string {
|
|
52
|
-
if (path.isAbsolute(importPath) && fileSystem.exists(importPath)) {
|
|
53
|
-
return importPath;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
return defaultBuildAdapter.resolve(importPath, rootDir);
|
|
58
|
-
} catch {
|
|
59
|
-
return this.resolveModulePathFallback(importPath, rootDir);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private resolveModulePathFallback(importPath: string, rootDir: string, maxDepth = 5): string {
|
|
64
|
-
let currentDir = rootDir;
|
|
65
|
-
let remainingDepth = maxDepth;
|
|
66
|
-
|
|
67
|
-
while (remainingDepth >= 0) {
|
|
68
|
-
const modulePath = path.join(currentDir, 'node_modules', importPath);
|
|
69
|
-
if (fileSystem.exists(modulePath)) {
|
|
70
|
-
return modulePath;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const parentDir = path.dirname(currentDir);
|
|
74
|
-
if (parentDir === currentDir) {
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
currentDir = parentDir;
|
|
79
|
-
remainingDepth -= 1;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
throw new Error(`Could not resolve module '${importPath}' from '${rootDir}'`);
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import type { ContentStylesheetAsset, ProcessedAsset } from '../../assets.types';
|
|
4
|
-
import { BaseProcessor } from '../base/base-processor';
|
|
5
|
-
|
|
6
|
-
export class ContentStylesheetProcessor extends BaseProcessor<ContentStylesheetAsset> {
|
|
7
|
-
async process(dep: ContentStylesheetAsset): Promise<ProcessedAsset> {
|
|
8
|
-
const hash = this.generateHash(dep.content);
|
|
9
|
-
const filename = `style-${hash}.css`;
|
|
10
|
-
const cachekey = this.buildCacheKey(filename, hash, dep);
|
|
11
|
-
|
|
12
|
-
return this.getOrProcess(cachekey, () => {
|
|
13
|
-
const filepath = path.join(this.getAssetsDir(), 'styles', filename);
|
|
14
|
-
|
|
15
|
-
if (!dep.inline) fileSystem.write(filepath, dep.content);
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
filepath: dep.inline ? undefined : filepath,
|
|
19
|
-
content: dep.inline ? dep.content : undefined,
|
|
20
|
-
kind: 'stylesheet',
|
|
21
|
-
position: dep.position,
|
|
22
|
-
attributes: dep.attributes,
|
|
23
|
-
inline: dep.inline,
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import type { FileStylesheetAsset, ProcessedAsset } from '../../assets.types';
|
|
4
|
-
import { BaseProcessor } from '../base/base-processor';
|
|
5
|
-
|
|
6
|
-
export class FileStylesheetProcessor extends BaseProcessor<FileStylesheetAsset> {
|
|
7
|
-
private static readonly PROCESSABLE_STYLESHEET_EXTENSIONS = new Set(['.css', '.scss', '.sass', '.less']);
|
|
8
|
-
|
|
9
|
-
getStyleContent = (srcUrl: string): Buffer => {
|
|
10
|
-
return fileSystem.readFileAsBuffer(srcUrl);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
private isProcessableStylesheet(filepath: string): boolean {
|
|
14
|
-
return FileStylesheetProcessor.PROCESSABLE_STYLESHEET_EXTENSIONS.has(path.extname(filepath));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private async applyStylesheetProcessors(content: string, filepath: string): Promise<string> {
|
|
18
|
-
if (!this.isProcessableStylesheet(filepath)) {
|
|
19
|
-
return content;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let transformedContent = content;
|
|
23
|
-
|
|
24
|
-
for (const processor of this.appConfig.processors.values()) {
|
|
25
|
-
const hasCapabilities = processor.getAssetCapabilities().length > 0;
|
|
26
|
-
const canProcessStylesheet = processor.canProcessAsset('stylesheet', filepath);
|
|
27
|
-
|
|
28
|
-
if (!canProcessStylesheet && (hasCapabilities || !processor.getName().includes('postcss'))) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!processor.matchesFileFilter(filepath)) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const result = await processor.process(transformedContent, filepath);
|
|
37
|
-
|
|
38
|
-
if (typeof result === 'string') {
|
|
39
|
-
transformedContent = result;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (result instanceof Buffer) {
|
|
44
|
-
transformedContent = result.toString();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return transformedContent;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async process(dep: FileStylesheetAsset): Promise<ProcessedAsset> {
|
|
52
|
-
const buffer = this.getStyleContent(dep.filepath);
|
|
53
|
-
const rawContent = buffer.toString();
|
|
54
|
-
const processedContent = await this.applyStylesheetProcessors(rawContent, dep.filepath);
|
|
55
|
-
const hash = this.generateHash(processedContent);
|
|
56
|
-
const cachekey = this.buildCacheKey(dep.filepath, hash, dep);
|
|
57
|
-
|
|
58
|
-
return this.getOrProcess(cachekey, () => {
|
|
59
|
-
const filepath = path.join(this.getAssetsDir(), path.relative(this.appConfig.srcDir, dep.filepath));
|
|
60
|
-
const outputBuffer = Buffer.from(processedContent);
|
|
61
|
-
|
|
62
|
-
if (!dep.inline) {
|
|
63
|
-
fileSystem.ensureDir(path.dirname(filepath));
|
|
64
|
-
fileSystem.write(filepath, outputBuffer);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
filepath: filepath,
|
|
69
|
-
content: dep.inline ? processedContent : undefined,
|
|
70
|
-
kind: 'stylesheet',
|
|
71
|
-
position: dep.position,
|
|
72
|
-
attributes: dep.attributes,
|
|
73
|
-
inline: dep.inline,
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|