@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 { 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
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
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';
|
|
@@ -0,0 +1,5 @@
|
|
|
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";
|
|
@@ -0,0 +1,5 @@
|
|
|
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';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentScriptAsset, ProcessedAsset } from '../../assets.types';
|
|
2
|
+
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
3
|
+
export declare class ContentScriptProcessor extends BaseScriptProcessor<ContentScriptAsset> {
|
|
4
|
+
process(dep: ContentScriptAsset): Promise<ProcessedAsset>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
+
import { BaseScriptProcessor } from "../base/base-script-processor";
|
|
4
|
+
class ContentScriptProcessor extends BaseScriptProcessor {
|
|
5
|
+
async process(dep) {
|
|
6
|
+
const hash = this.generateHash(dep.content);
|
|
7
|
+
const filename = dep.name ? `${dep.name}.js` : `script-${hash}.js`;
|
|
8
|
+
const shouldBundle = this.shouldBundle(dep);
|
|
9
|
+
const filepath = path.join(this.getAssetsDir(), "scripts", filename);
|
|
10
|
+
if (!shouldBundle) {
|
|
11
|
+
if (!dep.inline) fileSystem.write(filepath, dep.content);
|
|
12
|
+
const unbundledProcessedAsset = {
|
|
13
|
+
filepath,
|
|
14
|
+
content: dep.inline ? dep.content : void 0,
|
|
15
|
+
kind: "script",
|
|
16
|
+
position: dep.position,
|
|
17
|
+
attributes: dep.attributes,
|
|
18
|
+
inline: dep.inline,
|
|
19
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
20
|
+
};
|
|
21
|
+
this.writeCacheFile(filename, unbundledProcessedAsset);
|
|
22
|
+
return unbundledProcessedAsset;
|
|
23
|
+
}
|
|
24
|
+
if (dep.content) {
|
|
25
|
+
const tempDir = this.appConfig.absolutePaths.distDir;
|
|
26
|
+
fileSystem.ensureDir(tempDir);
|
|
27
|
+
const tempFileName = path.join(
|
|
28
|
+
tempDir,
|
|
29
|
+
`${path.parse(filename).name}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp.js`
|
|
30
|
+
);
|
|
31
|
+
fileSystem.write(tempFileName, dep.content);
|
|
32
|
+
const bundledFilePath = await this.bundleScript({
|
|
33
|
+
entrypoint: tempFileName,
|
|
34
|
+
outdir: this.getAssetsDir(),
|
|
35
|
+
minify: this.isProduction,
|
|
36
|
+
naming: `${path.parse(filename).name}-[hash].[ext]`,
|
|
37
|
+
...this.getBundlerOptions(dep)
|
|
38
|
+
});
|
|
39
|
+
const processedAsset = {
|
|
40
|
+
filepath: bundledFilePath,
|
|
41
|
+
content: dep.inline ? fileSystem.readFileSync(bundledFilePath).toString() : void 0,
|
|
42
|
+
kind: "script",
|
|
43
|
+
position: dep.position,
|
|
44
|
+
attributes: dep.attributes,
|
|
45
|
+
inline: dep.inline,
|
|
46
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
47
|
+
};
|
|
48
|
+
fileSystem.remove(tempFileName);
|
|
49
|
+
this.writeCacheFile(filename, processedAsset);
|
|
50
|
+
return processedAsset;
|
|
51
|
+
}
|
|
52
|
+
throw new Error("No content found for script asset");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
ContentScriptProcessor
|
|
57
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IHmrManager } from '../../../../internal-types';
|
|
2
|
+
import type { FileScriptAsset, ProcessedAsset } from '../../assets.types';
|
|
3
|
+
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
4
|
+
export declare class FileScriptProcessor extends BaseScriptProcessor<FileScriptAsset> {
|
|
5
|
+
private hmrManager?;
|
|
6
|
+
setHmrManager(hmrManager: IHmrManager): void;
|
|
7
|
+
process(dep: FileScriptAsset): Promise<ProcessedAsset>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { RESOLVED_ASSETS_DIR } from "../../../../constants";
|
|
3
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
+
import { BaseScriptProcessor } from "../base/base-script-processor";
|
|
5
|
+
class FileScriptProcessor extends BaseScriptProcessor {
|
|
6
|
+
hmrManager;
|
|
7
|
+
setHmrManager(hmrManager) {
|
|
8
|
+
this.hmrManager = hmrManager;
|
|
9
|
+
}
|
|
10
|
+
async process(dep) {
|
|
11
|
+
if (this.hmrManager?.isEnabled() && !dep.inline) {
|
|
12
|
+
const outputUrl = await this.hmrManager.registerEntrypoint(dep.filepath);
|
|
13
|
+
return {
|
|
14
|
+
filepath: dep.filepath,
|
|
15
|
+
srcUrl: outputUrl,
|
|
16
|
+
kind: "script",
|
|
17
|
+
position: dep.position,
|
|
18
|
+
attributes: dep.attributes,
|
|
19
|
+
inline: false,
|
|
20
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const content = fileSystem.readFileSync(dep.filepath);
|
|
24
|
+
const shouldBundle = this.shouldBundle(dep);
|
|
25
|
+
const configHash = this.generateHash(
|
|
26
|
+
JSON.stringify({
|
|
27
|
+
bundle: shouldBundle,
|
|
28
|
+
minify: shouldBundle && this.isProduction,
|
|
29
|
+
opts: dep.bundleOptions
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
const cachekey = `${this.buildCacheKey(dep.filepath, this.generateHash(content), dep)}:${configHash}`;
|
|
33
|
+
return this.getOrProcess(cachekey, async () => {
|
|
34
|
+
if (!shouldBundle) {
|
|
35
|
+
const outFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
|
|
36
|
+
let filepath;
|
|
37
|
+
if (!dep.inline) {
|
|
38
|
+
filepath = path.join(this.getAssetsDir(), outFilepath);
|
|
39
|
+
fileSystem.copyFile(dep.filepath, filepath);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
filepath,
|
|
43
|
+
content,
|
|
44
|
+
kind: "script",
|
|
45
|
+
position: dep.position,
|
|
46
|
+
attributes: dep.attributes,
|
|
47
|
+
inline: dep.inline,
|
|
48
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const relativeFilepath = path.relative(this.appConfig.absolutePaths.srcDir, dep.filepath);
|
|
52
|
+
const outdirPath = path.join(this.appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR, relativeFilepath);
|
|
53
|
+
const outdirDirname = path.dirname(outdirPath);
|
|
54
|
+
const bundlerOptions = this.getBundlerOptions(dep);
|
|
55
|
+
const bundledFilePath = await this.bundleScript({
|
|
56
|
+
entrypoint: dep.filepath,
|
|
57
|
+
outdir: outdirDirname,
|
|
58
|
+
minify: this.isProduction,
|
|
59
|
+
...bundlerOptions,
|
|
60
|
+
plugins: bundlerOptions.plugins
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
filepath: bundledFilePath,
|
|
64
|
+
content: dep.inline ? fileSystem.readFileSync(bundledFilePath).toString() : void 0,
|
|
65
|
+
kind: "script",
|
|
66
|
+
position: dep.position,
|
|
67
|
+
attributes: dep.attributes,
|
|
68
|
+
inline: dep.inline,
|
|
69
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
FileScriptProcessor
|
|
76
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
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.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NodeModuleScriptAsset } from '../../assets.types';
|
|
2
|
+
import { BaseScriptProcessor } from '../base/base-script-processor';
|
|
3
|
+
export declare class NodeModuleScriptProcessor extends BaseScriptProcessor<NodeModuleScriptAsset> {
|
|
4
|
+
process(dep: NodeModuleScriptAsset): Promise<import("../../assets.types").ProcessedAsset>;
|
|
5
|
+
private resolveModulePath;
|
|
6
|
+
private resolveModulePathFallback;
|
|
7
|
+
}
|
package/src/services/asset-processing-service/processors/script/node-module-script.processor.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
+
import { defaultBuildAdapter } from "../../../../build/build-adapter.js";
|
|
4
|
+
import { BaseScriptProcessor } from "../base/base-script-processor";
|
|
5
|
+
class NodeModuleScriptProcessor extends BaseScriptProcessor {
|
|
6
|
+
async process(dep) {
|
|
7
|
+
const modulePath = this.resolveModulePath(dep.importPath, this.appConfig.rootDir);
|
|
8
|
+
const moduleName = path.basename(modulePath);
|
|
9
|
+
const filename = dep.name ?? `nm-${moduleName}`;
|
|
10
|
+
const configHash = this.generateHash(
|
|
11
|
+
JSON.stringify({ inline: dep.inline, minify: !dep.inline && this.isProduction, opts: dep.bundleOptions })
|
|
12
|
+
);
|
|
13
|
+
const cachekey = `${this.buildCacheKey(filename, this.generateHash(modulePath), dep)}:${configHash}`;
|
|
14
|
+
return this.getOrProcess(cachekey, async () => {
|
|
15
|
+
if (dep.inline) {
|
|
16
|
+
const content = fileSystem.readFileAsBuffer(modulePath).toString();
|
|
17
|
+
return {
|
|
18
|
+
content,
|
|
19
|
+
kind: dep.kind,
|
|
20
|
+
position: dep.position,
|
|
21
|
+
attributes: dep.attributes,
|
|
22
|
+
inline: true,
|
|
23
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const outdir = path.join(this.getAssetsDir(), "vendors");
|
|
27
|
+
const filePath = await this.bundleScript({
|
|
28
|
+
entrypoint: modulePath,
|
|
29
|
+
outdir,
|
|
30
|
+
minify: this.isProduction,
|
|
31
|
+
naming: dep.name ? `${dep.name}-[hash].[ext]` : "[name]-[hash].[ext]",
|
|
32
|
+
...this.getBundlerOptions(dep)
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
filepath: filePath,
|
|
36
|
+
kind: dep.kind,
|
|
37
|
+
position: dep.position,
|
|
38
|
+
attributes: dep.attributes,
|
|
39
|
+
inline: dep.inline,
|
|
40
|
+
excludeFromHtml: dep.excludeFromHtml
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
resolveModulePath(importPath, rootDir) {
|
|
45
|
+
if (path.isAbsolute(importPath) && fileSystem.exists(importPath)) {
|
|
46
|
+
return importPath;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return defaultBuildAdapter.resolve(importPath, rootDir);
|
|
50
|
+
} catch {
|
|
51
|
+
return this.resolveModulePathFallback(importPath, rootDir);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
resolveModulePathFallback(importPath, rootDir, maxDepth = 5) {
|
|
55
|
+
let currentDir = rootDir;
|
|
56
|
+
let remainingDepth = maxDepth;
|
|
57
|
+
while (remainingDepth >= 0) {
|
|
58
|
+
const modulePath = path.join(currentDir, "node_modules", importPath);
|
|
59
|
+
if (fileSystem.exists(modulePath)) {
|
|
60
|
+
return modulePath;
|
|
61
|
+
}
|
|
62
|
+
const parentDir = path.dirname(currentDir);
|
|
63
|
+
if (parentDir === currentDir) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
currentDir = parentDir;
|
|
67
|
+
remainingDepth -= 1;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`Could not resolve module '${importPath}' from '${rootDir}'`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
NodeModuleScriptProcessor
|
|
74
|
+
};
|
package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentStylesheetAsset, ProcessedAsset } from '../../assets.types';
|
|
2
|
+
import { BaseProcessor } from '../base/base-processor';
|
|
3
|
+
export declare class ContentStylesheetProcessor extends BaseProcessor<ContentStylesheetAsset> {
|
|
4
|
+
process(dep: ContentStylesheetAsset): Promise<ProcessedAsset>;
|
|
5
|
+
}
|
package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
+
import { BaseProcessor } from "../base/base-processor";
|
|
4
|
+
class ContentStylesheetProcessor extends BaseProcessor {
|
|
5
|
+
async process(dep) {
|
|
6
|
+
const hash = this.generateHash(dep.content);
|
|
7
|
+
const filename = `style-${hash}.css`;
|
|
8
|
+
const cachekey = this.buildCacheKey(filename, hash, dep);
|
|
9
|
+
return this.getOrProcess(cachekey, () => {
|
|
10
|
+
const filepath = path.join(this.getAssetsDir(), "styles", filename);
|
|
11
|
+
if (!dep.inline) fileSystem.write(filepath, dep.content);
|
|
12
|
+
return {
|
|
13
|
+
filepath: dep.inline ? void 0 : filepath,
|
|
14
|
+
content: dep.inline ? dep.content : void 0,
|
|
15
|
+
kind: "stylesheet",
|
|
16
|
+
position: dep.position,
|
|
17
|
+
attributes: dep.attributes,
|
|
18
|
+
inline: dep.inline
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
ContentStylesheetProcessor
|
|
25
|
+
};
|
package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FileStylesheetAsset, ProcessedAsset } from '../../assets.types';
|
|
2
|
+
import { BaseProcessor } from '../base/base-processor';
|
|
3
|
+
export declare class FileStylesheetProcessor extends BaseProcessor<FileStylesheetAsset> {
|
|
4
|
+
private static readonly PROCESSABLE_STYLESHEET_EXTENSIONS;
|
|
5
|
+
getStyleContent: (srcUrl: string) => Buffer;
|
|
6
|
+
private isProcessableStylesheet;
|
|
7
|
+
private applyStylesheetProcessors;
|
|
8
|
+
process(dep: FileStylesheetAsset): Promise<ProcessedAsset>;
|
|
9
|
+
}
|