@ecopages/core 0.2.0-alpha.1
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 +89 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/package.json +279 -0
- package/src/adapters/abstract/application-adapter.d.ts +168 -0
- package/src/adapters/abstract/application-adapter.js +109 -0
- package/src/adapters/abstract/application-adapter.ts +337 -0
- package/src/adapters/abstract/router-adapter.d.ts +26 -0
- package/src/adapters/abstract/router-adapter.js +5 -0
- package/src/adapters/abstract/router-adapter.ts +30 -0
- package/src/adapters/abstract/server-adapter.d.ts +69 -0
- package/src/adapters/abstract/server-adapter.js +15 -0
- package/src/adapters/abstract/server-adapter.ts +79 -0
- package/src/adapters/bun/client-bridge.d.ts +34 -0
- package/src/adapters/bun/client-bridge.js +48 -0
- package/src/adapters/bun/client-bridge.ts +62 -0
- package/src/adapters/bun/create-app.d.ts +60 -0
- package/src/adapters/bun/create-app.js +117 -0
- package/src/adapters/bun/create-app.ts +189 -0
- package/src/adapters/bun/define-api-handler.d.ts +61 -0
- package/src/adapters/bun/define-api-handler.js +15 -0
- package/src/adapters/bun/define-api-handler.ts +114 -0
- package/src/adapters/bun/hmr-manager.d.ts +84 -0
- package/src/adapters/bun/hmr-manager.js +227 -0
- package/src/adapters/bun/hmr-manager.ts +281 -0
- package/src/adapters/bun/index.d.ts +3 -0
- package/src/adapters/bun/index.js +8 -0
- package/src/adapters/bun/index.ts +3 -0
- package/src/adapters/bun/server-adapter.d.ts +155 -0
- package/src/adapters/bun/server-adapter.js +368 -0
- package/src/adapters/bun/server-adapter.ts +492 -0
- package/src/adapters/bun/server-lifecycle.d.ts +52 -0
- package/src/adapters/bun/server-lifecycle.js +120 -0
- package/src/adapters/bun/server-lifecycle.ts +154 -0
- package/src/adapters/index.d.ts +6 -0
- package/src/adapters/index.js +14 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/node/create-app.d.ts +21 -0
- package/src/adapters/node/create-app.js +143 -0
- package/src/adapters/node/create-app.ts +179 -0
- package/src/adapters/node/index.d.ts +4 -0
- package/src/adapters/node/index.js +8 -0
- package/src/adapters/node/index.ts +9 -0
- package/src/adapters/node/node-client-bridge.d.ts +26 -0
- package/src/adapters/node/node-client-bridge.js +66 -0
- package/src/adapters/node/node-client-bridge.ts +79 -0
- package/src/adapters/node/node-hmr-manager.d.ts +62 -0
- package/src/adapters/node/node-hmr-manager.js +221 -0
- package/src/adapters/node/node-hmr-manager.ts +271 -0
- package/src/adapters/node/server-adapter.d.ts +190 -0
- package/src/adapters/node/server-adapter.js +420 -0
- package/src/adapters/node/server-adapter.ts +561 -0
- package/src/adapters/node/static-content-server.d.ts +24 -0
- package/src/adapters/node/static-content-server.js +166 -0
- package/src/adapters/node/static-content-server.ts +203 -0
- package/src/adapters/shared/api-response.d.ts +52 -0
- package/src/adapters/shared/api-response.js +96 -0
- package/src/adapters/shared/api-response.ts +104 -0
- package/src/adapters/shared/application-adapter.d.ts +18 -0
- package/src/adapters/shared/application-adapter.js +90 -0
- package/src/adapters/shared/application-adapter.ts +199 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
- package/src/adapters/shared/explicit-static-route-matcher.js +100 -0
- package/src/adapters/shared/explicit-static-route-matcher.ts +134 -0
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
- package/src/adapters/shared/file-route-middleware-pipeline.js +98 -0
- package/src/adapters/shared/file-route-middleware-pipeline.ts +123 -0
- package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
- package/src/adapters/shared/fs-server-response-factory.js +97 -0
- package/src/adapters/shared/fs-server-response-factory.ts +118 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +71 -0
- package/src/adapters/shared/fs-server-response-matcher.js +155 -0
- package/src/adapters/shared/fs-server-response-matcher.ts +198 -0
- package/src/adapters/shared/render-context.d.ts +14 -0
- package/src/adapters/shared/render-context.js +69 -0
- package/src/adapters/shared/render-context.ts +105 -0
- package/src/adapters/shared/server-adapter.d.ts +87 -0
- package/src/adapters/shared/server-adapter.js +353 -0
- package/src/adapters/shared/server-adapter.ts +442 -0
- package/src/adapters/shared/server-route-handler.d.ts +89 -0
- package/src/adapters/shared/server-route-handler.js +120 -0
- package/src/adapters/shared/server-route-handler.ts +166 -0
- package/src/adapters/shared/server-static-builder.d.ts +38 -0
- package/src/adapters/shared/server-static-builder.js +46 -0
- package/src/adapters/shared/server-static-builder.ts +82 -0
- package/src/build/build-adapter.d.ts +74 -0
- package/src/build/build-adapter.js +54 -0
- package/src/build/build-adapter.ts +132 -0
- package/src/build/build-types.d.ts +57 -0
- package/src/build/build-types.js +0 -0
- package/src/build/build-types.ts +83 -0
- package/src/build/esbuild-build-adapter.d.ts +69 -0
- package/src/build/esbuild-build-adapter.js +390 -0
- package/src/build/esbuild-build-adapter.ts +510 -0
- package/src/config/config-builder.d.ts +227 -0
- package/src/config/config-builder.js +392 -0
- package/src/config/config-builder.ts +474 -0
- package/src/constants.d.ts +32 -0
- package/src/constants.js +21 -0
- package/src/constants.ts +39 -0
- package/src/create-app.d.ts +17 -0
- package/src/create-app.js +66 -0
- package/src/create-app.ts +87 -0
- package/src/declarations.d.ts +26 -0
- package/src/define-api-handler.d.ts +25 -0
- package/src/define-api-handler.js +15 -0
- package/src/define-api-handler.ts +66 -0
- package/src/dev/sc-server.d.ts +30 -0
- package/src/dev/sc-server.js +111 -0
- package/src/dev/sc-server.ts +143 -0
- package/src/eco/README.md +636 -0
- package/src/eco/component-render-context.d.ts +105 -0
- package/src/eco/component-render-context.js +77 -0
- package/src/eco/component-render-context.ts +202 -0
- package/src/eco/eco.d.ts +9 -0
- package/src/eco/eco.js +110 -0
- package/src/eco/eco.ts +221 -0
- package/src/eco/eco.types.d.ts +170 -0
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.types.ts +202 -0
- package/src/eco/eco.utils.d.ts +40 -0
- package/src/eco/eco.utils.js +40 -0
- package/src/eco/eco.utils.ts +89 -0
- package/src/eco/global-injector-map.d.ts +16 -0
- package/src/eco/global-injector-map.js +80 -0
- package/src/eco/global-injector-map.ts +112 -0
- package/src/eco/lazy-injector-map.d.ts +8 -0
- package/src/eco/lazy-injector-map.js +70 -0
- package/src/eco/lazy-injector-map.ts +120 -0
- package/src/eco/module-dependencies.d.ts +18 -0
- package/src/eco/module-dependencies.js +49 -0
- package/src/eco/module-dependencies.ts +75 -0
- package/src/env.d.ts +20 -0
- package/src/errors/http-error.d.ts +31 -0
- package/src/errors/http-error.js +50 -0
- package/src/errors/http-error.ts +72 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +4 -0
- package/src/errors/index.ts +2 -0
- package/src/errors/locals-access-error.d.ts +4 -0
- package/src/errors/locals-access-error.js +9 -0
- package/src/errors/locals-access-error.ts +7 -0
- package/src/global/app-logger.d.ts +2 -0
- package/src/global/app-logger.js +6 -0
- package/src/global/app-logger.ts +4 -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.d.ts +10 -0
- package/src/hmr/client/hmr-runtime.js +86 -0
- package/src/hmr/client/hmr-runtime.ts +121 -0
- package/src/hmr/hmr-strategy.d.ts +159 -0
- package/src/hmr/hmr-strategy.js +29 -0
- package/src/hmr/hmr-strategy.ts +172 -0
- package/src/hmr/hmr.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.test.e2e.js +50 -0
- package/src/hmr/hmr.test.e2e.ts +75 -0
- package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
- package/src/hmr/strategies/default-hmr-strategy.js +34 -0
- package/src/hmr/strategies/default-hmr-strategy.ts +60 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +136 -0
- package/src/hmr/strategies/js-hmr-strategy.js +179 -0
- package/src/hmr/strategies/js-hmr-strategy.ts +308 -0
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +4 -0
- package/src/index.browser.ts +3 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +10 -0
- package/src/index.ts +5 -0
- package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
- package/src/integrations/ghtml/ghtml-renderer.js +60 -0
- package/src/integrations/ghtml/ghtml-renderer.ts +93 -0
- package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
- package/src/integrations/ghtml/ghtml.plugin.js +21 -0
- package/src/integrations/ghtml/ghtml.plugin.ts +32 -0
- package/src/internal-types.d.ts +200 -0
- package/src/internal-types.js +0 -0
- package/src/internal-types.ts +212 -0
- package/src/plugins/alias-resolver-plugin.d.ts +2 -0
- package/src/plugins/alias-resolver-plugin.js +39 -0
- package/src/plugins/alias-resolver-plugin.ts +45 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +95 -0
- package/src/plugins/eco-component-meta-plugin.js +157 -0
- package/src/plugins/eco-component-meta-plugin.ts +474 -0
- package/src/plugins/integration-plugin.d.ts +102 -0
- package/src/plugins/integration-plugin.js +100 -0
- package/src/plugins/integration-plugin.ts +184 -0
- package/src/plugins/processor.d.ts +82 -0
- package/src/plugins/processor.js +122 -0
- package/src/plugins/processor.ts +220 -0
- package/src/public-types.d.ts +1094 -0
- package/src/public-types.js +0 -0
- package/src/public-types.ts +1255 -0
- package/src/route-renderer/GRAPH.md +387 -0
- package/src/route-renderer/README.md +135 -0
- package/src/route-renderer/component-graph-executor.d.ts +32 -0
- package/src/route-renderer/component-graph-executor.js +31 -0
- package/src/route-renderer/component-graph-executor.ts +84 -0
- package/src/route-renderer/component-graph.d.ts +42 -0
- package/src/route-renderer/component-graph.js +72 -0
- package/src/route-renderer/component-graph.ts +159 -0
- package/src/route-renderer/component-marker.d.ts +52 -0
- package/src/route-renderer/component-marker.js +46 -0
- package/src/route-renderer/component-marker.ts +117 -0
- package/src/route-renderer/dependency-resolver.d.ts +24 -0
- package/src/route-renderer/dependency-resolver.js +428 -0
- package/src/route-renderer/dependency-resolver.ts +596 -0
- package/src/route-renderer/html-post-processing.service.d.ts +40 -0
- package/src/route-renderer/html-post-processing.service.js +86 -0
- package/src/route-renderer/html-post-processing.service.ts +103 -0
- package/src/route-renderer/integration-renderer.d.ts +339 -0
- package/src/route-renderer/integration-renderer.js +526 -0
- package/src/route-renderer/integration-renderer.ts +696 -0
- package/src/route-renderer/marker-graph-resolver.d.ts +76 -0
- package/src/route-renderer/marker-graph-resolver.js +93 -0
- package/src/route-renderer/marker-graph-resolver.ts +153 -0
- package/src/route-renderer/page-module-loader.d.ts +61 -0
- package/src/route-renderer/page-module-loader.js +102 -0
- package/src/route-renderer/page-module-loader.ts +153 -0
- package/src/route-renderer/render-execution.service.d.ts +69 -0
- package/src/route-renderer/render-execution.service.js +91 -0
- package/src/route-renderer/render-execution.service.ts +158 -0
- package/src/route-renderer/render-preparation.service.d.ts +112 -0
- package/src/route-renderer/render-preparation.service.js +243 -0
- package/src/route-renderer/render-preparation.service.ts +358 -0
- package/src/route-renderer/route-renderer.d.ts +26 -0
- package/src/route-renderer/route-renderer.js +68 -0
- package/src/route-renderer/route-renderer.ts +80 -0
- package/src/router/fs-router-scanner.d.ts +41 -0
- package/src/router/fs-router-scanner.js +155 -0
- package/src/router/fs-router-scanner.ts +217 -0
- package/src/router/fs-router.d.ts +26 -0
- package/src/router/fs-router.js +100 -0
- package/src/router/fs-router.ts +122 -0
- package/src/services/asset-processing-service/asset-processing.service.d.ts +41 -0
- package/src/services/asset-processing-service/asset-processing.service.js +250 -0
- package/src/services/asset-processing-service/asset-processing.service.ts +306 -0
- package/src/services/asset-processing-service/asset.factory.d.ts +17 -0
- package/src/services/asset-processing-service/asset.factory.js +82 -0
- package/src/services/asset-processing-service/asset.factory.ts +105 -0
- package/src/services/asset-processing-service/assets.types.d.ts +88 -0
- package/src/services/asset-processing-service/assets.types.js +0 -0
- package/src/services/asset-processing-service/assets.types.ts +112 -0
- package/src/services/asset-processing-service/index.d.ts +3 -0
- package/src/services/asset-processing-service/index.js +3 -0
- package/src/services/asset-processing-service/index.ts +3 -0
- package/src/services/asset-processing-service/processor.interface.d.ts +22 -0
- package/src/services/asset-processing-service/processor.interface.js +6 -0
- package/src/services/asset-processing-service/processor.interface.ts +27 -0
- package/src/services/asset-processing-service/processor.registry.d.ts +8 -0
- package/src/services/asset-processing-service/processor.registry.js +15 -0
- package/src/services/asset-processing-service/processor.registry.ts +18 -0
- package/src/services/asset-processing-service/processors/base/base-processor.d.ts +24 -0
- package/src/services/asset-processing-service/processors/base/base-processor.js +59 -0
- package/src/services/asset-processing-service/processors/base/base-processor.ts +76 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.d.ts +16 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.js +80 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.ts +105 -0
- package/src/services/asset-processing-service/processors/index.d.ts +5 -0
- package/src/services/asset-processing-service/processors/index.js +5 -0
- package/src/services/asset-processing-service/processors/index.ts +5 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.js +57 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.ts +66 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.js +76 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.ts +88 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.js +74 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts +84 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +27 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +63 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +77 -0
- package/src/services/cache/cache.types.d.ts +107 -0
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/cache.types.ts +126 -0
- package/src/services/cache/index.d.ts +7 -0
- package/src/services/cache/index.js +7 -0
- package/src/services/cache/index.ts +18 -0
- package/src/services/cache/memory-cache-store.d.ts +42 -0
- package/src/services/cache/memory-cache-store.js +98 -0
- package/src/services/cache/memory-cache-store.ts +130 -0
- package/src/services/cache/page-cache-service.d.ts +70 -0
- package/src/services/cache/page-cache-service.js +152 -0
- package/src/services/cache/page-cache-service.ts +202 -0
- package/src/services/html-transformer.service.d.ts +50 -0
- package/src/services/html-transformer.service.js +163 -0
- package/src/services/html-transformer.service.ts +217 -0
- package/src/services/page-module-import.service.d.ts +37 -0
- package/src/services/page-module-import.service.js +88 -0
- package/src/services/page-module-import.service.ts +129 -0
- package/src/services/page-request-cache-coordinator.service.d.ts +75 -0
- package/src/services/page-request-cache-coordinator.service.js +107 -0
- package/src/services/page-request-cache-coordinator.service.ts +128 -0
- package/src/services/schema-validation-service.d.ts +122 -0
- package/src/services/schema-validation-service.js +101 -0
- package/src/services/schema-validation-service.ts +204 -0
- package/src/services/validation/standard-schema.types.d.ts +65 -0
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/services/validation/standard-schema.types.ts +68 -0
- package/src/static-site-generator/static-site-generator.d.ts +57 -0
- package/src/static-site-generator/static-site-generator.js +272 -0
- package/src/static-site-generator/static-site-generator.ts +359 -0
- package/src/utils/css.d.ts +1 -0
- package/src/utils/css.js +7 -0
- package/src/utils/css.ts +5 -0
- package/src/utils/deep-merge.d.ts +14 -0
- package/src/utils/deep-merge.js +32 -0
- package/src/utils/deep-merge.ts +47 -0
- package/src/utils/hash.d.ts +1 -0
- package/src/utils/hash.js +7 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/html.d.ts +1 -0
- package/src/utils/html.js +4 -0
- package/src/utils/html.ts +1 -0
- package/src/utils/invariant.d.ts +5 -0
- package/src/utils/invariant.js +11 -0
- package/src/utils/invariant.ts +15 -0
- package/src/utils/locals-utils.d.ts +15 -0
- package/src/utils/locals-utils.js +24 -0
- package/src/utils/locals-utils.ts +37 -0
- package/src/utils/parse-cli-args.d.ts +24 -0
- package/src/utils/parse-cli-args.js +47 -0
- package/src/utils/parse-cli-args.ts +83 -0
- package/src/utils/path-utils.module.d.ts +5 -0
- package/src/utils/path-utils.module.js +14 -0
- package/src/utils/path-utils.module.ts +14 -0
- package/src/utils/runtime.d.ts +11 -0
- package/src/utils/runtime.js +40 -0
- package/src/utils/runtime.ts +44 -0
- package/src/utils/server-utils.module.d.ts +19 -0
- package/src/utils/server-utils.module.js +56 -0
- package/src/utils/server-utils.module.ts +67 -0
- package/src/watchers/project-watcher.d.ts +120 -0
- package/src/watchers/project-watcher.js +238 -0
- package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
- package/src/watchers/project-watcher.test-helpers.js +51 -0
- package/src/watchers/project-watcher.test-helpers.ts +40 -0
- package/src/watchers/project-watcher.ts +306 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { RESOLVED_ASSETS_DIR, RESOLVED_ASSETS_VENDORS_DIR } from '../../constants';
|
|
2
|
+
import { deepMerge } from '../../utils/deep-merge';
|
|
3
|
+
import type {
|
|
4
|
+
ContentScriptAsset,
|
|
5
|
+
ContentStylesheetAsset,
|
|
6
|
+
FileScriptAsset,
|
|
7
|
+
FileStylesheetAsset,
|
|
8
|
+
InlineContentScriptAsset,
|
|
9
|
+
InlineContentStylesheetAsset,
|
|
10
|
+
InlineFileScriptAsset,
|
|
11
|
+
JsonScriptAsset,
|
|
12
|
+
NodeModuleScriptAsset,
|
|
13
|
+
} from './assets.types';
|
|
14
|
+
|
|
15
|
+
type CreateAssetOptions<T> = Omit<T, 'kind' | 'source' | 'inline'>;
|
|
16
|
+
|
|
17
|
+
export class AssetFactory {
|
|
18
|
+
static readonly RESOLVED_ASSETS_DIR = RESOLVED_ASSETS_DIR;
|
|
19
|
+
static readonly RESOLVED_ASSETS_VENDORS_DIR = RESOLVED_ASSETS_VENDORS_DIR;
|
|
20
|
+
|
|
21
|
+
static createContentScript(options: CreateAssetOptions<ContentScriptAsset>): ContentScriptAsset {
|
|
22
|
+
return {
|
|
23
|
+
kind: 'script',
|
|
24
|
+
source: 'content',
|
|
25
|
+
position: options.position || 'body',
|
|
26
|
+
...options,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static createInlineContentScript(options: CreateAssetOptions<InlineContentScriptAsset>): InlineContentScriptAsset {
|
|
31
|
+
return {
|
|
32
|
+
...AssetFactory.createContentScript(options),
|
|
33
|
+
inline: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static createFileScript(options: CreateAssetOptions<FileScriptAsset>): FileScriptAsset {
|
|
38
|
+
return {
|
|
39
|
+
kind: 'script',
|
|
40
|
+
source: 'file',
|
|
41
|
+
position: options.position || 'body',
|
|
42
|
+
...options,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static createInlineFileScript(options: CreateAssetOptions<InlineFileScriptAsset>): InlineFileScriptAsset {
|
|
47
|
+
return {
|
|
48
|
+
...AssetFactory.createFileScript(options),
|
|
49
|
+
inline: true,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static createNodeModuleScript(options: CreateAssetOptions<NodeModuleScriptAsset>): NodeModuleScriptAsset {
|
|
54
|
+
return {
|
|
55
|
+
kind: 'script',
|
|
56
|
+
source: 'node-module',
|
|
57
|
+
position: options.position || 'body',
|
|
58
|
+
...options,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static createInlineNodeModuleScript(options: CreateAssetOptions<NodeModuleScriptAsset>): NodeModuleScriptAsset {
|
|
63
|
+
return {
|
|
64
|
+
...AssetFactory.createNodeModuleScript(options),
|
|
65
|
+
inline: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static createJsonScript(options: CreateAssetOptions<JsonScriptAsset>): JsonScriptAsset {
|
|
70
|
+
return {
|
|
71
|
+
kind: 'script',
|
|
72
|
+
source: 'content',
|
|
73
|
+
attributes: deepMerge(options.attributes, { type: 'application/json' }),
|
|
74
|
+
position: options.position || 'body',
|
|
75
|
+
...options,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static createContentStylesheet(options: CreateAssetOptions<ContentStylesheetAsset>): ContentStylesheetAsset {
|
|
80
|
+
return {
|
|
81
|
+
kind: 'stylesheet',
|
|
82
|
+
source: 'content',
|
|
83
|
+
position: 'head',
|
|
84
|
+
...options,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static createInlineContentStylesheet(
|
|
89
|
+
options: CreateAssetOptions<InlineContentStylesheetAsset>,
|
|
90
|
+
): InlineContentStylesheetAsset {
|
|
91
|
+
return {
|
|
92
|
+
...AssetFactory.createContentStylesheet(options),
|
|
93
|
+
inline: true,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static createFileStylesheet(options: CreateAssetOptions<FileStylesheetAsset>): FileStylesheetAsset {
|
|
98
|
+
return {
|
|
99
|
+
kind: 'stylesheet',
|
|
100
|
+
source: 'file',
|
|
101
|
+
position: options.position || 'head',
|
|
102
|
+
...options,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { EcoBuildPlugin } from '../../build/build-types.js';
|
|
2
|
+
export type AssetSource = 'content' | 'file' | 'node-module';
|
|
3
|
+
export type AssetKind = 'script' | 'stylesheet';
|
|
4
|
+
export type AssetPosition = 'head' | 'body';
|
|
5
|
+
export interface BaseAsset {
|
|
6
|
+
kind: AssetKind;
|
|
7
|
+
source: AssetSource;
|
|
8
|
+
attributes?: Record<string, string>;
|
|
9
|
+
position?: AssetPosition;
|
|
10
|
+
}
|
|
11
|
+
export interface ScriptAsset extends BaseAsset {
|
|
12
|
+
kind: 'script';
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
bundle?: boolean;
|
|
15
|
+
bundleOptions?: {
|
|
16
|
+
minify?: boolean;
|
|
17
|
+
external?: string[];
|
|
18
|
+
naming?: string;
|
|
19
|
+
plugins?: EcoBuildPlugin[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Whether to exclude this asset from the HTML output.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
excludeFromHtml?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface StylesheetAsset extends BaseAsset {
|
|
28
|
+
kind: 'stylesheet';
|
|
29
|
+
inline?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ContentScriptAsset extends ScriptAsset {
|
|
32
|
+
source: 'content';
|
|
33
|
+
content: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface InlineContentScriptAsset extends ContentScriptAsset {
|
|
37
|
+
inline: true;
|
|
38
|
+
}
|
|
39
|
+
export interface ContentStylesheetAsset extends StylesheetAsset {
|
|
40
|
+
source: 'content';
|
|
41
|
+
content: string;
|
|
42
|
+
}
|
|
43
|
+
export interface InlineContentStylesheetAsset extends ContentStylesheetAsset {
|
|
44
|
+
inline: true;
|
|
45
|
+
}
|
|
46
|
+
export interface FileScriptAsset extends ScriptAsset {
|
|
47
|
+
source: 'file';
|
|
48
|
+
filepath: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface InlineFileScriptAsset extends FileScriptAsset {
|
|
52
|
+
inline: true;
|
|
53
|
+
}
|
|
54
|
+
export interface FileStylesheetAsset extends StylesheetAsset {
|
|
55
|
+
source: 'file';
|
|
56
|
+
filepath: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface InlineFileStylesheetAsset extends FileStylesheetAsset {
|
|
60
|
+
inline: true;
|
|
61
|
+
}
|
|
62
|
+
export interface NodeModuleScriptAsset extends ScriptAsset {
|
|
63
|
+
kind: 'script';
|
|
64
|
+
source: 'node-module';
|
|
65
|
+
importPath: string;
|
|
66
|
+
name?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface InlineNodeModuleScriptAsset extends NodeModuleScriptAsset {
|
|
69
|
+
inline: true;
|
|
70
|
+
}
|
|
71
|
+
export interface InlineNodeModuleScriptAsset extends NodeModuleScriptAsset {
|
|
72
|
+
inline: true;
|
|
73
|
+
}
|
|
74
|
+
export interface JsonScriptAsset extends ScriptAsset {
|
|
75
|
+
source: 'content';
|
|
76
|
+
content: string;
|
|
77
|
+
}
|
|
78
|
+
export type ProcessedAsset = {
|
|
79
|
+
filepath?: string;
|
|
80
|
+
srcUrl?: string;
|
|
81
|
+
content?: string;
|
|
82
|
+
kind: AssetKind;
|
|
83
|
+
position?: AssetPosition;
|
|
84
|
+
attributes?: Record<string, string>;
|
|
85
|
+
inline?: boolean;
|
|
86
|
+
excludeFromHtml?: boolean;
|
|
87
|
+
};
|
|
88
|
+
export type AssetDefinition = ContentScriptAsset | FileScriptAsset | NodeModuleScriptAsset | JsonScriptAsset | ContentStylesheetAsset | FileStylesheetAsset;
|
|
File without changes
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { EcoBuildPlugin } from '../../build/build-types.ts';
|
|
2
|
+
|
|
3
|
+
export type AssetSource = 'content' | 'file' | 'node-module';
|
|
4
|
+
export type AssetKind = 'script' | 'stylesheet';
|
|
5
|
+
export type AssetPosition = 'head' | 'body';
|
|
6
|
+
|
|
7
|
+
export interface BaseAsset {
|
|
8
|
+
kind: AssetKind;
|
|
9
|
+
source: AssetSource;
|
|
10
|
+
attributes?: Record<string, string>;
|
|
11
|
+
position?: AssetPosition;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ScriptAsset extends BaseAsset {
|
|
15
|
+
kind: 'script';
|
|
16
|
+
inline?: boolean;
|
|
17
|
+
bundle?: boolean;
|
|
18
|
+
bundleOptions?: {
|
|
19
|
+
minify?: boolean;
|
|
20
|
+
external?: string[];
|
|
21
|
+
naming?: string;
|
|
22
|
+
plugins?: EcoBuildPlugin[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Whether to exclude this asset from the HTML output.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
excludeFromHtml?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface StylesheetAsset extends BaseAsset {
|
|
32
|
+
kind: 'stylesheet';
|
|
33
|
+
inline?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ContentScriptAsset extends ScriptAsset {
|
|
37
|
+
source: 'content';
|
|
38
|
+
content: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface InlineContentScriptAsset extends ContentScriptAsset {
|
|
43
|
+
inline: true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ContentStylesheetAsset extends StylesheetAsset {
|
|
47
|
+
source: 'content';
|
|
48
|
+
content: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface InlineContentStylesheetAsset extends ContentStylesheetAsset {
|
|
52
|
+
inline: true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface FileScriptAsset extends ScriptAsset {
|
|
56
|
+
source: 'file';
|
|
57
|
+
filepath: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface InlineFileScriptAsset extends FileScriptAsset {
|
|
62
|
+
inline: true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface FileStylesheetAsset extends StylesheetAsset {
|
|
66
|
+
source: 'file';
|
|
67
|
+
filepath: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface InlineFileStylesheetAsset extends FileStylesheetAsset {
|
|
72
|
+
inline: true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface NodeModuleScriptAsset extends ScriptAsset {
|
|
76
|
+
kind: 'script';
|
|
77
|
+
source: 'node-module';
|
|
78
|
+
importPath: string;
|
|
79
|
+
name?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface InlineNodeModuleScriptAsset extends NodeModuleScriptAsset {
|
|
83
|
+
inline: true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface InlineNodeModuleScriptAsset extends NodeModuleScriptAsset {
|
|
87
|
+
inline: true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface JsonScriptAsset extends ScriptAsset {
|
|
91
|
+
source: 'content';
|
|
92
|
+
content: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type ProcessedAsset = {
|
|
96
|
+
filepath?: string;
|
|
97
|
+
srcUrl?: string;
|
|
98
|
+
content?: string;
|
|
99
|
+
kind: AssetKind;
|
|
100
|
+
position?: AssetPosition;
|
|
101
|
+
attributes?: Record<string, string>;
|
|
102
|
+
inline?: boolean;
|
|
103
|
+
excludeFromHtml?: boolean;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type AssetDefinition =
|
|
107
|
+
| ContentScriptAsset
|
|
108
|
+
| FileScriptAsset
|
|
109
|
+
| NodeModuleScriptAsset
|
|
110
|
+
| JsonScriptAsset
|
|
111
|
+
| ContentStylesheetAsset
|
|
112
|
+
| FileStylesheetAsset;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IHmrManager } from '../../internal-types';
|
|
2
|
+
import type { AssetDefinition, ProcessedAsset } from './assets.types';
|
|
3
|
+
/**
|
|
4
|
+
* Base interface for asset processors.
|
|
5
|
+
* Processors transform asset definitions into processed assets.
|
|
6
|
+
*/
|
|
7
|
+
export interface AssetProcessor<T extends AssetDefinition = AssetDefinition> {
|
|
8
|
+
process(asset: T): Promise<ProcessedAsset>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface for processors that support HMR (Hot Module Replacement).
|
|
12
|
+
* These processors can receive an HMR manager to enable hot reloading capabilities.
|
|
13
|
+
*/
|
|
14
|
+
export interface HmrAwareProcessor extends AssetProcessor {
|
|
15
|
+
setHmrManager(hmrManager: IHmrManager): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to check if a processor supports HMR.
|
|
19
|
+
* @param processor - The processor to check
|
|
20
|
+
* @returns True if the processor implements HmrAwareProcessor
|
|
21
|
+
*/
|
|
22
|
+
export declare function isHmrAware(processor: AssetProcessor): processor is HmrAwareProcessor;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssetKind, AssetSource } from './assets.types';
|
|
2
|
+
import type { BaseProcessor } from './processors/base/base-processor';
|
|
3
|
+
export declare class ProcessorRegistry {
|
|
4
|
+
private processors;
|
|
5
|
+
register(kind: AssetKind, variant: AssetSource, processor: BaseProcessor<any>): void;
|
|
6
|
+
getProcessor(kind: AssetKind, variant: AssetSource): BaseProcessor<any> | undefined;
|
|
7
|
+
getAllProcessors(): Map<`${AssetKind}-${AssetSource}`, BaseProcessor<any>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ProcessorRegistry {
|
|
2
|
+
processors = /* @__PURE__ */ new Map();
|
|
3
|
+
register(kind, variant, processor) {
|
|
4
|
+
this.processors.set(`${kind}-${variant}`, processor);
|
|
5
|
+
}
|
|
6
|
+
getProcessor(kind, variant) {
|
|
7
|
+
return this.processors.get(`${kind}-${variant}`);
|
|
8
|
+
}
|
|
9
|
+
getAllProcessors() {
|
|
10
|
+
return this.processors;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
ProcessorRegistry
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../../../internal-types.js';
|
|
2
|
+
import type { BaseAsset, ProcessedAsset } from '../../assets.types.js';
|
|
3
|
+
export declare abstract class BaseProcessor<T extends BaseAsset> {
|
|
4
|
+
protected appConfig: EcoPagesAppConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Cache for processed assets to avoid reprocessing the same asset multiple times.
|
|
7
|
+
* The cache key is a combination of the asset name and its hash.
|
|
8
|
+
* The cache value is the processed asset.
|
|
9
|
+
*/
|
|
10
|
+
protected cache: Map<string, ProcessedAsset>;
|
|
11
|
+
constructor({ appConfig }: {
|
|
12
|
+
appConfig: EcoPagesAppConfig;
|
|
13
|
+
});
|
|
14
|
+
get isDevelopment(): boolean;
|
|
15
|
+
get isProduction(): boolean;
|
|
16
|
+
abstract process(dep: T): Promise<ProcessedAsset>;
|
|
17
|
+
protected getAssetsDir(): string;
|
|
18
|
+
protected writeCacheFile(key: string, path: ProcessedAsset): void;
|
|
19
|
+
protected getCacheFile(key: string): ProcessedAsset | undefined;
|
|
20
|
+
protected hasCacheFile(key: string): boolean;
|
|
21
|
+
protected generateHash(content: string): string;
|
|
22
|
+
protected buildCacheKey(identifier: string, contentHash: string, dep: T): string;
|
|
23
|
+
protected getOrProcess(cacheKey: string, processFn: () => ProcessedAsset | Promise<ProcessedAsset>): Promise<ProcessedAsset>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { RESOLVED_ASSETS_DIR } from "../../../../constants.js";
|
|
3
|
+
import { rapidhash } from "../../../../utils/hash.js";
|
|
4
|
+
import { isDevelopmentRuntime, isProductionRuntime } from "../../../../utils/runtime.js";
|
|
5
|
+
class BaseProcessor {
|
|
6
|
+
appConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Cache for processed assets to avoid reprocessing the same asset multiple times.
|
|
9
|
+
* The cache key is a combination of the asset name and its hash.
|
|
10
|
+
* The cache value is the processed asset.
|
|
11
|
+
*/
|
|
12
|
+
cache = /* @__PURE__ */ new Map();
|
|
13
|
+
constructor({ appConfig }) {
|
|
14
|
+
this.appConfig = appConfig;
|
|
15
|
+
}
|
|
16
|
+
get isDevelopment() {
|
|
17
|
+
return isDevelopmentRuntime();
|
|
18
|
+
}
|
|
19
|
+
get isProduction() {
|
|
20
|
+
return isProductionRuntime();
|
|
21
|
+
}
|
|
22
|
+
getAssetsDir() {
|
|
23
|
+
return path.join(this.appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR);
|
|
24
|
+
}
|
|
25
|
+
writeCacheFile(key, path2) {
|
|
26
|
+
this.cache.set(key, path2);
|
|
27
|
+
}
|
|
28
|
+
getCacheFile(key) {
|
|
29
|
+
return this.cache.get(key);
|
|
30
|
+
}
|
|
31
|
+
hasCacheFile(key) {
|
|
32
|
+
return this.cache.has(key);
|
|
33
|
+
}
|
|
34
|
+
generateHash(content) {
|
|
35
|
+
return rapidhash(content).toString();
|
|
36
|
+
}
|
|
37
|
+
buildCacheKey(identifier, contentHash, dep) {
|
|
38
|
+
const attrsHash = dep.attributes ? this.generateHash(JSON.stringify(dep.attributes)) : "";
|
|
39
|
+
const position = dep.position ?? "";
|
|
40
|
+
return `${identifier}:${contentHash}:${position}:${attrsHash}`;
|
|
41
|
+
}
|
|
42
|
+
getOrProcess(cacheKey, processFn) {
|
|
43
|
+
if (this.hasCacheFile(cacheKey)) {
|
|
44
|
+
return Promise.resolve(this.getCacheFile(cacheKey));
|
|
45
|
+
}
|
|
46
|
+
const result = processFn();
|
|
47
|
+
if (result instanceof Promise) {
|
|
48
|
+
return result.then((asset) => {
|
|
49
|
+
this.writeCacheFile(cacheKey, asset);
|
|
50
|
+
return asset;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.writeCacheFile(cacheKey, result);
|
|
54
|
+
return Promise.resolve(result);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
BaseProcessor
|
|
59
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../../../internal-types';
|
|
2
|
+
import type { EcoBuildPlugin } from '../../../../build/build-types.js';
|
|
3
|
+
import type { ScriptAsset } from '../../assets.types';
|
|
4
|
+
import { BaseProcessor } from './base-processor';
|
|
5
|
+
export declare abstract class BaseScriptProcessor<T extends ScriptAsset> extends BaseProcessor<T> {
|
|
6
|
+
constructor({ appConfig }: {
|
|
7
|
+
appConfig: EcoPagesAppConfig;
|
|
8
|
+
});
|
|
9
|
+
protected shouldBundle(dep: T): boolean;
|
|
10
|
+
protected getBundlerOptions(dep: T): Record<string, any>;
|
|
11
|
+
protected collectBuildPlugins(): EcoBuildPlugin[];
|
|
12
|
+
protected bundleScript({ entrypoint, outdir, plugins: additionalPlugins, ...rest }: {
|
|
13
|
+
entrypoint: string;
|
|
14
|
+
outdir: string;
|
|
15
|
+
} & ScriptAsset['bundleOptions']): Promise<string>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { appLogger } from "../../../../global/app-logger";
|
|
2
|
+
import { defaultBuildAdapter } from "../../../../build/build-adapter.js";
|
|
3
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { BaseProcessor } from "./base-processor";
|
|
6
|
+
class BaseScriptProcessor extends BaseProcessor {
|
|
7
|
+
constructor({ appConfig }) {
|
|
8
|
+
super({ appConfig });
|
|
9
|
+
}
|
|
10
|
+
shouldBundle(dep) {
|
|
11
|
+
return dep.bundle !== false;
|
|
12
|
+
}
|
|
13
|
+
getBundlerOptions(dep) {
|
|
14
|
+
return dep.bundleOptions || {};
|
|
15
|
+
}
|
|
16
|
+
collectBuildPlugins() {
|
|
17
|
+
const plugins = [];
|
|
18
|
+
if (this.appConfig.processors?.size) {
|
|
19
|
+
for (const processor of this.appConfig.processors.values()) {
|
|
20
|
+
if (processor.buildPlugins) {
|
|
21
|
+
plugins.push(...processor.buildPlugins);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (this.appConfig.loaders?.size) {
|
|
26
|
+
plugins.push(...this.appConfig.loaders.values());
|
|
27
|
+
}
|
|
28
|
+
return plugins;
|
|
29
|
+
}
|
|
30
|
+
async bundleScript({
|
|
31
|
+
entrypoint,
|
|
32
|
+
outdir,
|
|
33
|
+
plugins: additionalPlugins,
|
|
34
|
+
...rest
|
|
35
|
+
}) {
|
|
36
|
+
const buildPlugins = this.collectBuildPlugins();
|
|
37
|
+
const allPlugins = additionalPlugins ? [...additionalPlugins, ...buildPlugins] : buildPlugins;
|
|
38
|
+
const build = await defaultBuildAdapter.build({
|
|
39
|
+
entrypoints: [entrypoint],
|
|
40
|
+
outdir,
|
|
41
|
+
root: this.appConfig.rootDir,
|
|
42
|
+
...defaultBuildAdapter.getTranspileOptions("browser-script"),
|
|
43
|
+
splitting: true,
|
|
44
|
+
naming: "[name]-[hash].[ext]",
|
|
45
|
+
plugins: allPlugins,
|
|
46
|
+
...rest
|
|
47
|
+
});
|
|
48
|
+
if (!build.success) {
|
|
49
|
+
for (const log of build.logs) {
|
|
50
|
+
appLogger.debug(log.message, log);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const entryBaseName = path.parse(entrypoint).name;
|
|
54
|
+
const entryOutput = build.outputs.map((output) => output.path).find((outputPath) => path.basename(outputPath) === `${entryBaseName}.js`);
|
|
55
|
+
if (entryOutput) {
|
|
56
|
+
return entryOutput;
|
|
57
|
+
}
|
|
58
|
+
const nonVendorOutput = build.outputs.map((output) => output.path).find((outputPath) => !path.basename(outputPath).startsWith("vendors"));
|
|
59
|
+
if (nonVendorOutput) {
|
|
60
|
+
return nonVendorOutput;
|
|
61
|
+
}
|
|
62
|
+
const primaryOutput = build.outputs[0]?.path;
|
|
63
|
+
if (primaryOutput) {
|
|
64
|
+
return primaryOutput;
|
|
65
|
+
}
|
|
66
|
+
const namedFallbackOutput = path.join(outdir, `${entryBaseName}.js`);
|
|
67
|
+
if (fileSystem.exists(namedFallbackOutput)) {
|
|
68
|
+
return namedFallbackOutput;
|
|
69
|
+
}
|
|
70
|
+
const fallbackOutput = path.join(outdir, "entry_0.js");
|
|
71
|
+
if (fileSystem.exists(fallbackOutput)) {
|
|
72
|
+
return fallbackOutput;
|
|
73
|
+
}
|
|
74
|
+
const logMessage = build.logs.map((log) => log.message).join(" | ");
|
|
75
|
+
throw new Error(`No build output generated for ${entrypoint}${logMessage ? `: ${logMessage}` : ""}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
BaseScriptProcessor
|
|
80
|
+
};
|