@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,155 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { appLogger } from "../global/app-logger.js";
|
|
3
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
+
import { invariant } from "../utils/invariant.js";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { PageModuleImportService } from "../services/page-module-import.service.js";
|
|
7
|
+
class FSRouterScanner {
|
|
8
|
+
dir;
|
|
9
|
+
origin = "";
|
|
10
|
+
templatesExt;
|
|
11
|
+
options;
|
|
12
|
+
appConfig;
|
|
13
|
+
routes = {};
|
|
14
|
+
pageModuleImportService = new PageModuleImportService();
|
|
15
|
+
constructor({
|
|
16
|
+
dir,
|
|
17
|
+
origin,
|
|
18
|
+
templatesExt,
|
|
19
|
+
options,
|
|
20
|
+
appConfig
|
|
21
|
+
}) {
|
|
22
|
+
this.dir = dir;
|
|
23
|
+
this.origin = origin;
|
|
24
|
+
this.templatesExt = templatesExt;
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.appConfig = appConfig;
|
|
27
|
+
}
|
|
28
|
+
getRoutePath(path2) {
|
|
29
|
+
const cleanedRoute = this.templatesExt.reduce((route, ext) => route.replace(ext, ""), path2).replace(/\/?index$/, "");
|
|
30
|
+
return `/${cleanedRoute}`;
|
|
31
|
+
}
|
|
32
|
+
getDynamicParamsNames(route) {
|
|
33
|
+
const matches = route.match(/\[.*?\]/g);
|
|
34
|
+
return matches ? matches.map((match) => match.slice(1, -1)) : [];
|
|
35
|
+
}
|
|
36
|
+
async getStaticPathsFromDynamicRoute({
|
|
37
|
+
route,
|
|
38
|
+
filePath,
|
|
39
|
+
getStaticPaths
|
|
40
|
+
}) {
|
|
41
|
+
const staticPaths = await getStaticPaths({
|
|
42
|
+
appConfig: this.appConfig,
|
|
43
|
+
runtimeOrigin: this.origin
|
|
44
|
+
});
|
|
45
|
+
return staticPaths.paths.map((path2) => {
|
|
46
|
+
const dynamicParamsNames = this.getDynamicParamsNames(filePath);
|
|
47
|
+
let routeWithParams = route;
|
|
48
|
+
for (const param of dynamicParamsNames) {
|
|
49
|
+
routeWithParams = routeWithParams.replace(`[${param}]`, path2.params[param]);
|
|
50
|
+
}
|
|
51
|
+
return routeWithParams;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async createStaticRoutes({
|
|
55
|
+
filePath,
|
|
56
|
+
route,
|
|
57
|
+
routePath,
|
|
58
|
+
getStaticPaths
|
|
59
|
+
}) {
|
|
60
|
+
try {
|
|
61
|
+
const routesWithParams = await this.getStaticPathsFromDynamicRoute({
|
|
62
|
+
route,
|
|
63
|
+
filePath,
|
|
64
|
+
getStaticPaths
|
|
65
|
+
});
|
|
66
|
+
for (const routeWithParams of routesWithParams) {
|
|
67
|
+
this.createRoute("dynamic", { filePath, route: routeWithParams, routePath });
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
appLogger.error(`[ecopages] Error creating static routes for ${filePath}: ${error}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async handleDynamicRouteCreation({ filePath, route, routePath }) {
|
|
74
|
+
const module = await this.importPageModule(filePath);
|
|
75
|
+
const Page = module.default;
|
|
76
|
+
const getStaticPaths = Page?.staticPaths ?? module.getStaticPaths;
|
|
77
|
+
const getStaticProps = Page?.staticProps ?? module.getStaticProps;
|
|
78
|
+
if (this.options.buildMode) {
|
|
79
|
+
invariant(getStaticProps !== void 0, `[ecopages] Missing getStaticProps in ${filePath}`);
|
|
80
|
+
invariant(getStaticPaths !== void 0, `[ecopages] Missing getStaticPaths in ${filePath}`);
|
|
81
|
+
}
|
|
82
|
+
if (getStaticPaths) {
|
|
83
|
+
return this.createStaticRoutes({
|
|
84
|
+
filePath,
|
|
85
|
+
route,
|
|
86
|
+
routePath,
|
|
87
|
+
getStaticPaths
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return this.createRoute("dynamic", { filePath, route, routePath });
|
|
91
|
+
}
|
|
92
|
+
async importPageModule(filePath) {
|
|
93
|
+
return this.pageModuleImportService.importModule({
|
|
94
|
+
filePath,
|
|
95
|
+
rootDir: this.appConfig.rootDir,
|
|
96
|
+
outdir: path.join(this.appConfig.absolutePaths.distDir, ".server-route-modules"),
|
|
97
|
+
externalPackages: false,
|
|
98
|
+
transpileErrorMessage: (details) => `Error transpiling route module: ${details}`,
|
|
99
|
+
noOutputMessage: (targetFilePath) => `No transpiled output generated for route module: ${targetFilePath}`
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
createRoute(kind, { filePath, route, routePath }) {
|
|
103
|
+
this.routes[route] = {
|
|
104
|
+
kind,
|
|
105
|
+
pathname: routePath,
|
|
106
|
+
filePath
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
getRouteData(file) {
|
|
110
|
+
const routePath = this.getRoutePath(file);
|
|
111
|
+
const route = `${this.origin}${routePath}`;
|
|
112
|
+
const filePath = path.join(this.dir, file);
|
|
113
|
+
const isCatchAll = filePath.includes("[...");
|
|
114
|
+
const isDynamic = !isCatchAll && filePath.includes("[") && filePath.includes("]");
|
|
115
|
+
const kind = isCatchAll ? "catch-all" : isDynamic ? "dynamic" : "exact";
|
|
116
|
+
return { route, routePath, filePath, kind };
|
|
117
|
+
}
|
|
118
|
+
async scan() {
|
|
119
|
+
this.routes = {};
|
|
120
|
+
if (!existsSync(this.dir)) {
|
|
121
|
+
return this.routes;
|
|
122
|
+
}
|
|
123
|
+
const scannedFiles = await fileSystem.glob(
|
|
124
|
+
this.templatesExt.map((ext) => `**/*${ext}`),
|
|
125
|
+
{ cwd: this.dir }
|
|
126
|
+
);
|
|
127
|
+
for await (const file of scannedFiles) {
|
|
128
|
+
if (file.includes(".ecopages-node.")) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const { kind, ...routeData } = this.getRouteData(file);
|
|
132
|
+
switch (kind) {
|
|
133
|
+
case "dynamic":
|
|
134
|
+
await this.handleDynamicRouteCreation(routeData);
|
|
135
|
+
break;
|
|
136
|
+
case "catch-all":
|
|
137
|
+
if (this.options.buildMode) {
|
|
138
|
+
appLogger.warn(
|
|
139
|
+
"Catch-all routes are not supported in static generation, they will not be included in the bundle\n",
|
|
140
|
+
`\u27A4 ${routeData.filePath}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
this.createRoute(kind, routeData);
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
this.createRoute(kind, routeData);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return this.routes;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
FSRouterScanner
|
|
155
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { appLogger } from '../global/app-logger.ts';
|
|
3
|
+
import type { EcoPagesAppConfig, RouteKind, Routes } from '../internal-types.ts';
|
|
4
|
+
import type { EcoPageFile, GetStaticPaths } from '../public-types.ts';
|
|
5
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
6
|
+
import { invariant } from '../utils/invariant.ts';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { PageModuleImportService } from '../services/page-module-import.service.ts';
|
|
9
|
+
|
|
10
|
+
type CreateRouteArgs = {
|
|
11
|
+
routePath: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
route: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type FSRouterScannerOptions = {
|
|
17
|
+
buildMode: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @class FSRouterScanner
|
|
22
|
+
* @description
|
|
23
|
+
* This class is responsible for scanning the file system for routes.
|
|
24
|
+
* It uses the glob package to scan the file system for files with the specified file extensions.
|
|
25
|
+
* It then creates a map of the routes with the pathname as the key.
|
|
26
|
+
* The pathname is the route without the file extension.
|
|
27
|
+
* For example, if the file is "index.tsx", the pathname will be "/index".
|
|
28
|
+
* If the file is "blog/[slug].tsx", the pathname will be "/blog/[slug]".
|
|
29
|
+
* If the file is "blog/[...slug].tsx", the pathname will be "/blog/[...slug]".
|
|
30
|
+
*/
|
|
31
|
+
export class FSRouterScanner {
|
|
32
|
+
private dir: string;
|
|
33
|
+
private origin = '';
|
|
34
|
+
private templatesExt: string[];
|
|
35
|
+
private options: FSRouterScannerOptions;
|
|
36
|
+
private appConfig: EcoPagesAppConfig;
|
|
37
|
+
routes: Routes = {};
|
|
38
|
+
private pageModuleImportService = new PageModuleImportService();
|
|
39
|
+
|
|
40
|
+
constructor({
|
|
41
|
+
dir,
|
|
42
|
+
origin,
|
|
43
|
+
templatesExt,
|
|
44
|
+
options,
|
|
45
|
+
appConfig,
|
|
46
|
+
}: {
|
|
47
|
+
dir: string;
|
|
48
|
+
origin: string;
|
|
49
|
+
templatesExt: string[];
|
|
50
|
+
options: FSRouterScannerOptions;
|
|
51
|
+
appConfig: EcoPagesAppConfig;
|
|
52
|
+
}) {
|
|
53
|
+
this.dir = dir;
|
|
54
|
+
this.origin = origin;
|
|
55
|
+
this.templatesExt = templatesExt;
|
|
56
|
+
this.options = options;
|
|
57
|
+
this.appConfig = appConfig;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private getRoutePath(path: string): string {
|
|
61
|
+
const cleanedRoute = this.templatesExt
|
|
62
|
+
.reduce((route, ext) => route.replace(ext, ''), path)
|
|
63
|
+
.replace(/\/?index$/, '');
|
|
64
|
+
return `/${cleanedRoute}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private getDynamicParamsNames(route: string): string[] {
|
|
68
|
+
const matches = route.match(/\[.*?\]/g);
|
|
69
|
+
return matches ? matches.map((match) => match.slice(1, -1)) : [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async getStaticPathsFromDynamicRoute({
|
|
73
|
+
route,
|
|
74
|
+
filePath,
|
|
75
|
+
getStaticPaths,
|
|
76
|
+
}: {
|
|
77
|
+
route: string;
|
|
78
|
+
filePath: string;
|
|
79
|
+
getStaticPaths: GetStaticPaths;
|
|
80
|
+
}): Promise<string[]> {
|
|
81
|
+
const staticPaths = await getStaticPaths({
|
|
82
|
+
appConfig: this.appConfig,
|
|
83
|
+
runtimeOrigin: this.origin,
|
|
84
|
+
});
|
|
85
|
+
return staticPaths.paths.map((path) => {
|
|
86
|
+
const dynamicParamsNames = this.getDynamicParamsNames(filePath);
|
|
87
|
+
let routeWithParams = route;
|
|
88
|
+
|
|
89
|
+
for (const param of dynamicParamsNames) {
|
|
90
|
+
routeWithParams = routeWithParams.replace(`[${param}]`, (path.params as Record<string, string>)[param]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return routeWithParams;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async createStaticRoutes({
|
|
98
|
+
filePath,
|
|
99
|
+
route,
|
|
100
|
+
routePath,
|
|
101
|
+
getStaticPaths,
|
|
102
|
+
}: CreateRouteArgs & { getStaticPaths: GetStaticPaths }): Promise<void> {
|
|
103
|
+
try {
|
|
104
|
+
const routesWithParams = await this.getStaticPathsFromDynamicRoute({
|
|
105
|
+
route,
|
|
106
|
+
filePath,
|
|
107
|
+
getStaticPaths,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for (const routeWithParams of routesWithParams) {
|
|
111
|
+
this.createRoute('dynamic', { filePath, route: routeWithParams, routePath });
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
appLogger.error(`[ecopages] Error creating static routes for ${filePath}: ${error}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private async handleDynamicRouteCreation({ filePath, route, routePath }: CreateRouteArgs): Promise<void> {
|
|
119
|
+
const module = (await this.importPageModule(filePath)) as EcoPageFile;
|
|
120
|
+
const Page = module.default;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Check for attached static functions (consolidated API) or named exports (legacy)
|
|
124
|
+
*/
|
|
125
|
+
const getStaticPaths = Page?.staticPaths ?? module.getStaticPaths;
|
|
126
|
+
const getStaticProps = Page?.staticProps ?? module.getStaticProps;
|
|
127
|
+
|
|
128
|
+
if (this.options.buildMode) {
|
|
129
|
+
invariant(getStaticProps !== undefined, `[ecopages] Missing getStaticProps in ${filePath}`);
|
|
130
|
+
invariant(getStaticPaths !== undefined, `[ecopages] Missing getStaticPaths in ${filePath}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (getStaticPaths) {
|
|
134
|
+
return this.createStaticRoutes({
|
|
135
|
+
filePath,
|
|
136
|
+
route,
|
|
137
|
+
routePath,
|
|
138
|
+
getStaticPaths,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return this.createRoute('dynamic', { filePath, route, routePath });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async importPageModule(filePath: string): Promise<unknown> {
|
|
146
|
+
return this.pageModuleImportService.importModule({
|
|
147
|
+
filePath,
|
|
148
|
+
rootDir: this.appConfig.rootDir,
|
|
149
|
+
outdir: path.join(this.appConfig.absolutePaths.distDir, '.server-route-modules'),
|
|
150
|
+
externalPackages: false,
|
|
151
|
+
transpileErrorMessage: (details) => `Error transpiling route module: ${details}`,
|
|
152
|
+
noOutputMessage: (targetFilePath) => `No transpiled output generated for route module: ${targetFilePath}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private createRoute(kind: RouteKind, { filePath, route, routePath }: CreateRouteArgs): void {
|
|
157
|
+
this.routes[route] = {
|
|
158
|
+
kind,
|
|
159
|
+
pathname: routePath,
|
|
160
|
+
filePath,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private getRouteData(file: string): CreateRouteArgs & {
|
|
165
|
+
kind: RouteKind;
|
|
166
|
+
} {
|
|
167
|
+
const routePath = this.getRoutePath(file);
|
|
168
|
+
const route = `${this.origin}${routePath}`;
|
|
169
|
+
const filePath = path.join(this.dir, file);
|
|
170
|
+
const isCatchAll = filePath.includes('[...');
|
|
171
|
+
const isDynamic = !isCatchAll && filePath.includes('[') && filePath.includes(']');
|
|
172
|
+
const kind: RouteKind = isCatchAll ? 'catch-all' : isDynamic ? 'dynamic' : 'exact';
|
|
173
|
+
|
|
174
|
+
return { route, routePath, filePath, kind };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async scan(): Promise<Routes> {
|
|
178
|
+
this.routes = {};
|
|
179
|
+
|
|
180
|
+
if (!existsSync(this.dir)) {
|
|
181
|
+
return this.routes;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const scannedFiles = await fileSystem.glob(
|
|
185
|
+
this.templatesExt.map((ext) => `**/*${ext}`),
|
|
186
|
+
{ cwd: this.dir },
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
for await (const file of scannedFiles) {
|
|
190
|
+
if (file.includes('.ecopages-node.')) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const { kind, ...routeData } = this.getRouteData(file);
|
|
195
|
+
|
|
196
|
+
switch (kind) {
|
|
197
|
+
case 'dynamic':
|
|
198
|
+
await this.handleDynamicRouteCreation(routeData);
|
|
199
|
+
break;
|
|
200
|
+
case 'catch-all':
|
|
201
|
+
if (this.options.buildMode) {
|
|
202
|
+
appLogger.warn(
|
|
203
|
+
'Catch-all routes are not supported in static generation, they will not be included in the bundle\n',
|
|
204
|
+
`➤ ${routeData.filePath}`,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
this.createRoute(kind, routeData);
|
|
208
|
+
break;
|
|
209
|
+
default:
|
|
210
|
+
this.createRoute(kind, routeData);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return this.routes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MatchResult, Route, Routes } from '../internal-types.js';
|
|
2
|
+
import type { FSRouterScanner } from './fs-router-scanner.js';
|
|
3
|
+
/**
|
|
4
|
+
* A class that manages the routes of the file system.
|
|
5
|
+
* It scans the file system for files with the specified extensions and creates a map of routes.
|
|
6
|
+
* It also provides a method to match a request to a route.
|
|
7
|
+
* It can be used to reload the routes when the file system changes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FSRouter {
|
|
10
|
+
origin: string;
|
|
11
|
+
assetPrefix: string;
|
|
12
|
+
routes: Routes;
|
|
13
|
+
scanner: FSRouterScanner;
|
|
14
|
+
onReload?: () => void;
|
|
15
|
+
constructor({ origin, assetPrefix, scanner }: {
|
|
16
|
+
origin: string;
|
|
17
|
+
assetPrefix: string;
|
|
18
|
+
scanner: FSRouterScanner;
|
|
19
|
+
});
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
getDynamicParams(route: Route, pathname: string): Record<string, string | string[]>;
|
|
22
|
+
getSearchParams(url: URL): Record<string, string>;
|
|
23
|
+
match(requestUrl: string): MatchResult | null;
|
|
24
|
+
setOnReload(cb: () => void): void;
|
|
25
|
+
reload(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { appLogger } from "../global/app-logger.js";
|
|
2
|
+
class FSRouter {
|
|
3
|
+
origin;
|
|
4
|
+
assetPrefix;
|
|
5
|
+
routes = {};
|
|
6
|
+
scanner;
|
|
7
|
+
onReload;
|
|
8
|
+
constructor({ origin, assetPrefix, scanner }) {
|
|
9
|
+
this.origin = origin;
|
|
10
|
+
this.assetPrefix = assetPrefix;
|
|
11
|
+
this.scanner = scanner;
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
this.routes = await this.scanner.scan();
|
|
15
|
+
appLogger.debug("FSRouter initialized", this.routes);
|
|
16
|
+
}
|
|
17
|
+
getDynamicParams(route, pathname) {
|
|
18
|
+
const params = {};
|
|
19
|
+
const routeParts = route.pathname.split("/");
|
|
20
|
+
const pathnameParts = pathname.split("/");
|
|
21
|
+
for (let i = 0; i < routeParts.length; i++) {
|
|
22
|
+
const part = routeParts[i];
|
|
23
|
+
if (part.startsWith("[") && part.endsWith("]")) {
|
|
24
|
+
if (part.startsWith("[...")) {
|
|
25
|
+
const param2 = part.slice(4, -1);
|
|
26
|
+
params[param2] = pathnameParts.slice(i);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
const param = part.slice(1, -1);
|
|
30
|
+
params[param] = pathnameParts[i];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return params;
|
|
34
|
+
}
|
|
35
|
+
getSearchParams(url) {
|
|
36
|
+
const query = {};
|
|
37
|
+
for (const [key, value] of url.searchParams) {
|
|
38
|
+
query[key] = value;
|
|
39
|
+
}
|
|
40
|
+
return query;
|
|
41
|
+
}
|
|
42
|
+
match(requestUrl) {
|
|
43
|
+
const url = new URL(requestUrl);
|
|
44
|
+
const pathname = url.pathname.replace(this.origin, "");
|
|
45
|
+
const routeValues = Object.values(this.routes);
|
|
46
|
+
for (const route of routeValues) {
|
|
47
|
+
if (route.kind === "exact" && (pathname === route.pathname || pathname === `${route.pathname}/`)) {
|
|
48
|
+
return {
|
|
49
|
+
filePath: route.filePath,
|
|
50
|
+
kind: "exact",
|
|
51
|
+
pathname: route.pathname,
|
|
52
|
+
query: this.getSearchParams(url)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const route of routeValues) {
|
|
57
|
+
const cleanPathname = route.pathname.replace(/\[.*?\]/g, "");
|
|
58
|
+
const isValidDynamicRoute = pathname.includes(cleanPathname);
|
|
59
|
+
if (route.kind === "dynamic" && isValidDynamicRoute) {
|
|
60
|
+
const routeParts = route.pathname.split("/");
|
|
61
|
+
const pathnameParts = pathname.split("/");
|
|
62
|
+
if (routeParts.length === pathnameParts.length) {
|
|
63
|
+
return {
|
|
64
|
+
filePath: route.filePath,
|
|
65
|
+
kind: "dynamic",
|
|
66
|
+
pathname,
|
|
67
|
+
query: this.getSearchParams(url),
|
|
68
|
+
params: this.getDynamicParams(route, pathname)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const route of routeValues) {
|
|
74
|
+
const cleanPathname = route.pathname.replace(/\[.*?\]/g, "");
|
|
75
|
+
const isValidCatchAllRoute = pathname.includes(cleanPathname);
|
|
76
|
+
if (route.kind === "catch-all" && isValidCatchAllRoute) {
|
|
77
|
+
return {
|
|
78
|
+
filePath: route.filePath,
|
|
79
|
+
kind: "catch-all",
|
|
80
|
+
pathname,
|
|
81
|
+
query: this.getSearchParams(url),
|
|
82
|
+
params: this.getDynamicParams(route, pathname)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
setOnReload(cb) {
|
|
89
|
+
this.onReload = cb;
|
|
90
|
+
}
|
|
91
|
+
reload() {
|
|
92
|
+
this.init();
|
|
93
|
+
if (this.onReload) {
|
|
94
|
+
this.onReload();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
FSRouter
|
|
100
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { appLogger } from '../global/app-logger.ts';
|
|
2
|
+
import type { MatchResult, Route, Routes } from '../internal-types.ts';
|
|
3
|
+
import type { FSRouterScanner } from './fs-router-scanner.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A class that manages the routes of the file system.
|
|
7
|
+
* It scans the file system for files with the specified extensions and creates a map of routes.
|
|
8
|
+
* It also provides a method to match a request to a route.
|
|
9
|
+
* It can be used to reload the routes when the file system changes.
|
|
10
|
+
*/
|
|
11
|
+
export class FSRouter {
|
|
12
|
+
origin: string;
|
|
13
|
+
assetPrefix: string;
|
|
14
|
+
routes: Routes = {};
|
|
15
|
+
scanner: FSRouterScanner;
|
|
16
|
+
onReload?: () => void;
|
|
17
|
+
|
|
18
|
+
constructor({ origin, assetPrefix, scanner }: { origin: string; assetPrefix: string; scanner: FSRouterScanner }) {
|
|
19
|
+
this.origin = origin;
|
|
20
|
+
this.assetPrefix = assetPrefix;
|
|
21
|
+
this.scanner = scanner;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async init() {
|
|
25
|
+
this.routes = await this.scanner.scan();
|
|
26
|
+
appLogger.debug('FSRouter initialized', this.routes);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getDynamicParams(route: Route, pathname: string): Record<string, string | string[]> {
|
|
30
|
+
const params: Record<string, string | string[]> = {};
|
|
31
|
+
const routeParts = route.pathname.split('/');
|
|
32
|
+
const pathnameParts = pathname.split('/');
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < routeParts.length; i++) {
|
|
35
|
+
const part = routeParts[i];
|
|
36
|
+
if (part.startsWith('[') && part.endsWith(']')) {
|
|
37
|
+
if (part.startsWith('[...')) {
|
|
38
|
+
const param = part.slice(4, -1);
|
|
39
|
+
params[param] = pathnameParts.slice(i);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
const param = part.slice(1, -1);
|
|
43
|
+
params[param] = pathnameParts[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return params;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getSearchParams(url: URL): Record<string, string> {
|
|
50
|
+
const query: Record<string, string> = {};
|
|
51
|
+
for (const [key, value] of url.searchParams) {
|
|
52
|
+
query[key] = value;
|
|
53
|
+
}
|
|
54
|
+
return query;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
match(requestUrl: string): MatchResult | null {
|
|
58
|
+
const url = new URL(requestUrl);
|
|
59
|
+
const pathname = url.pathname.replace(this.origin, '');
|
|
60
|
+
|
|
61
|
+
const routeValues = Object.values(this.routes);
|
|
62
|
+
|
|
63
|
+
for (const route of routeValues) {
|
|
64
|
+
if (route.kind === 'exact' && (pathname === route.pathname || pathname === `${route.pathname}/`)) {
|
|
65
|
+
return {
|
|
66
|
+
filePath: route.filePath,
|
|
67
|
+
kind: 'exact',
|
|
68
|
+
pathname: route.pathname,
|
|
69
|
+
query: this.getSearchParams(url),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const route of routeValues) {
|
|
75
|
+
const cleanPathname = route.pathname.replace(/\[.*?\]/g, '');
|
|
76
|
+
const isValidDynamicRoute = pathname.includes(cleanPathname);
|
|
77
|
+
|
|
78
|
+
if (route.kind === 'dynamic' && isValidDynamicRoute) {
|
|
79
|
+
const routeParts = route.pathname.split('/');
|
|
80
|
+
const pathnameParts = pathname.split('/');
|
|
81
|
+
|
|
82
|
+
if (routeParts.length === pathnameParts.length) {
|
|
83
|
+
return {
|
|
84
|
+
filePath: route.filePath,
|
|
85
|
+
kind: 'dynamic',
|
|
86
|
+
pathname: pathname,
|
|
87
|
+
query: this.getSearchParams(url),
|
|
88
|
+
params: this.getDynamicParams(route, pathname),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (const route of routeValues) {
|
|
95
|
+
const cleanPathname = route.pathname.replace(/\[.*?\]/g, '');
|
|
96
|
+
const isValidCatchAllRoute = pathname.includes(cleanPathname);
|
|
97
|
+
|
|
98
|
+
if (route.kind === 'catch-all' && isValidCatchAllRoute) {
|
|
99
|
+
return {
|
|
100
|
+
filePath: route.filePath,
|
|
101
|
+
kind: 'catch-all',
|
|
102
|
+
pathname: pathname,
|
|
103
|
+
query: this.getSearchParams(url),
|
|
104
|
+
params: this.getDynamicParams(route, pathname),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setOnReload(cb: () => void) {
|
|
113
|
+
this.onReload = cb;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
reload() {
|
|
117
|
+
this.init();
|
|
118
|
+
if (this.onReload) {
|
|
119
|
+
this.onReload();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig, IHmrManager } from '../../internal-types';
|
|
2
|
+
import type { AssetDefinition, AssetKind, AssetSource, ProcessedAsset } from './assets.types';
|
|
3
|
+
import { ProcessorRegistry } from './processor.registry';
|
|
4
|
+
export declare class AssetProcessingService {
|
|
5
|
+
private readonly config;
|
|
6
|
+
static readonly RESOLVED_ASSETS_DIR = "assets";
|
|
7
|
+
private registry;
|
|
8
|
+
private hmrManager?;
|
|
9
|
+
private cache;
|
|
10
|
+
constructor(config: EcoPagesAppConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Set the HMR manager for the asset processing service.
|
|
13
|
+
* @param hmrManager The HMR manager to set.
|
|
14
|
+
*/
|
|
15
|
+
setHmrManager(hmrManager: IHmrManager): void;
|
|
16
|
+
getHmrManager(): IHmrManager | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Register a processor for a specific asset kind and source.
|
|
19
|
+
* @param kind The asset kind.
|
|
20
|
+
* @param variant The asset source.
|
|
21
|
+
* @param processor The processor to register.
|
|
22
|
+
*/
|
|
23
|
+
registerProcessor(kind: AssetKind, variant: AssetSource, processor: any): void;
|
|
24
|
+
processDependencies(deps: AssetDefinition[], key: string): Promise<ProcessedAsset[]>;
|
|
25
|
+
private deduplicateDependencies;
|
|
26
|
+
private getScriptDependencyBuildSignature;
|
|
27
|
+
private getDependencyKey;
|
|
28
|
+
private generateHash;
|
|
29
|
+
private processDependenciesParallel;
|
|
30
|
+
private groupDependenciesByType;
|
|
31
|
+
private getSrcUrl;
|
|
32
|
+
private resolveProcessedAssetSrcUrl;
|
|
33
|
+
private isFilesystemPath;
|
|
34
|
+
private optimizeDependencies;
|
|
35
|
+
private getCachedAsset;
|
|
36
|
+
private setCachedAsset;
|
|
37
|
+
clearCache(): void;
|
|
38
|
+
invalidateCacheForFile(filepath: string): void;
|
|
39
|
+
static createWithDefaultProcessors(appConfig: EcoPagesAppConfig): AssetProcessingService;
|
|
40
|
+
getRegistry(): ProcessorRegistry;
|
|
41
|
+
}
|