@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.1 → 3.9.0-ultramodern.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/generator/index.js +0 -1
- package/dist/cjs/builder/shared/builderPlugins/index.js +4 -11
- package/dist/cjs/config/index.js +4 -11
- package/dist/cjs/index.js +46 -72
- package/dist/cjs/plugins/deploy/platforms/node.js +0 -13
- package/dist/cjs/plugins/deploy/utils/generator.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +2 -1
- package/dist/cjs/{plugins/backendFederationBuild.js → server-plugin.js} +4 -7
- package/dist/esm/builder/generator/index.mjs +1 -2
- package/dist/esm/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm/config/index.mjs +0 -1
- package/dist/esm/index.mjs +3 -6
- package/dist/esm/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm/plugins/deploy/utils/generator.mjs +1 -1
- package/dist/esm/plugins/serverBuild.mjs +2 -1
- package/dist/esm/server-plugin.mjs +1 -0
- package/dist/esm-node/builder/generator/index.mjs +1 -2
- package/dist/esm-node/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm-node/config/index.mjs +0 -1
- package/dist/esm-node/index.mjs +3 -6
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm-node/plugins/deploy/utils/generator.mjs +1 -1
- package/dist/esm-node/plugins/serverBuild.mjs +2 -1
- package/dist/esm-node/server-plugin.mjs +2 -0
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/config/index.d.ts +0 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
- package/dist/types/server-plugin.d.ts +10 -0
- package/dist/types/types/config/output.d.ts +0 -9
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/plugin.d.ts +56 -2
- package/dist/types/utils/initAppContext.d.ts +3 -2
- package/docs/apis/app/commands.md +2 -0
- package/docs/apis/app/hooks/api/lambda.md +2 -0
- package/docs/apis/app/hooks/config/favicon.md +2 -0
- package/docs/apis/app/hooks/config/html.md +2 -0
- package/docs/apis/app/hooks/config/icon.md +2 -0
- package/docs/apis/app/hooks/config/mock.md +2 -0
- package/docs/apis/app/hooks/config/public.md +2 -0
- package/docs/apis/app/hooks/config/upload.md +2 -0
- package/docs/apis/app/hooks/modern-config.md +2 -0
- package/docs/apis/app/hooks/server/server.md +2 -0
- package/docs/apis/app/hooks/shared.md +2 -0
- package/docs/apis/app/hooks/src/app.md +2 -0
- package/docs/apis/app/hooks/src/entry.md +2 -0
- package/docs/apis/app/hooks/src/entry.server.md +2 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +2 -0
- package/docs/apis/app/hooks/src/routes.md +2 -0
- package/docs/apis/app/hooks/src/server.md +2 -0
- package/docs/apis/app/runtime/bff/use-backend-context.md +2 -0
- package/docs/apis/app/runtime/core/create-root.md +2 -0
- package/docs/apis/app/runtime/core/render.md +2 -0
- package/docs/apis/app/runtime/core/runtime-context.md +2 -0
- package/docs/apis/app/runtime/router/router.md +2 -0
- package/docs/apis/app/runtime/ssr/no-ssr.md +2 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +2 -0
- package/docs/apis/app/runtime/ssr/renderString.md +2 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +2 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +2 -0
- package/docs/apis/app/runtime/utility/head.md +2 -0
- package/docs/apis/app/runtime/utility/loadable.md +2 -0
- package/docs/community/blog/2022-0708-updates.md +2 -0
- package/docs/community/blog/2022-0910-updates.md +2 -0
- package/docs/community/blog/overview.md +2 -0
- package/docs/community/blog/v2-release-note.md +2 -0
- package/docs/community/blog/v3-release-note.md +2 -0
- package/docs/community/contributing-guide.md +2 -0
- package/docs/community/releases.md +2 -0
- package/docs/community/showcase.md +2 -0
- package/docs/community/team.md +2 -0
- package/docs/configure/app/bff/cross-project.md +2 -0
- package/docs/configure/app/bff/effect.md +31 -24
- package/docs/configure/app/bff/prefix.md +2 -0
- package/docs/configure/app/bff/runtime-framework.md +2 -0
- package/docs/configure/app/builder-plugins.md +2 -0
- package/docs/configure/app/dev/asset-prefix.md +2 -0
- package/docs/configure/app/dev/before-start-url.md +2 -0
- package/docs/configure/app/dev/client.md +2 -0
- package/docs/configure/app/dev/hmr.md +2 -0
- package/docs/configure/app/dev/host.md +2 -0
- package/docs/configure/app/dev/https.md +2 -0
- package/docs/configure/app/dev/lazy-compilation.md +2 -0
- package/docs/configure/app/dev/live-reload.md +2 -0
- package/docs/configure/app/dev/mock-dir.md +2 -0
- package/docs/configure/app/dev/progress-bar.md +2 -0
- package/docs/configure/app/dev/server.md +2 -0
- package/docs/configure/app/dev/setup-middlewares.md +2 -0
- package/docs/configure/app/dev/start-url.md +2 -0
- package/docs/configure/app/dev/watch-files.md +2 -0
- package/docs/configure/app/dev/write-to-disk.md +2 -0
- package/docs/configure/app/experiments/source-build.md +2 -0
- package/docs/configure/app/html/app-icon.md +2 -0
- package/docs/configure/app/html/crossorigin.md +2 -0
- package/docs/configure/app/html/favicon.md +2 -0
- package/docs/configure/app/html/inject.md +2 -0
- package/docs/configure/app/html/meta.md +2 -0
- package/docs/configure/app/html/mount-id.md +2 -0
- package/docs/configure/app/html/output-structure.md +2 -0
- package/docs/configure/app/html/script-loading.md +2 -0
- package/docs/configure/app/html/tags.md +2 -0
- package/docs/configure/app/html/template-parameters.md +2 -0
- package/docs/configure/app/html/template.md +2 -0
- package/docs/configure/app/html/title.md +2 -0
- package/docs/configure/app/output/asset-prefix.md +2 -0
- package/docs/configure/app/output/assets-retry.md +2 -0
- package/docs/configure/app/output/charset.md +2 -0
- package/docs/configure/app/output/clean-dist-path.md +2 -0
- package/docs/configure/app/output/convert-to-rem.md +2 -0
- package/docs/configure/app/output/copy.md +2 -0
- package/docs/configure/app/output/css-modules.md +2 -0
- package/docs/configure/app/output/data-uri-limit.md +2 -0
- package/docs/configure/app/output/disable-css-module-extension.md +2 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +2 -0
- package/docs/configure/app/output/disable-svgr.md +2 -0
- package/docs/configure/app/output/disable-ts-checker.md +2 -0
- package/docs/configure/app/output/dist-path.md +2 -0
- package/docs/configure/app/output/enable-asset-manifest.md +2 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +2 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +2 -0
- package/docs/configure/app/output/externals.md +2 -0
- package/docs/configure/app/output/filename-hash.md +2 -0
- package/docs/configure/app/output/filename.md +2 -0
- package/docs/configure/app/output/inject-styles.md +2 -0
- package/docs/configure/app/output/inline-scripts.md +2 -0
- package/docs/configure/app/output/inline-styles.md +2 -0
- package/docs/configure/app/output/legal-comments.md +2 -0
- package/docs/configure/app/output/minify.md +2 -0
- package/docs/configure/app/output/override-browserslist.md +2 -0
- package/docs/configure/app/output/polyfill.md +2 -0
- package/docs/configure/app/output/source-map.md +2 -0
- package/docs/configure/app/output/split-route-chunks.md +2 -0
- package/docs/configure/app/output/ssg.md +2 -0
- package/docs/configure/app/output/ssgByEntries.md +2 -0
- package/docs/configure/app/output/svg-default-export.md +2 -0
- package/docs/configure/app/output/temp-dir.md +2 -0
- package/docs/configure/app/performance/build-cache.md +2 -0
- package/docs/configure/app/performance/chunk-split.md +2 -0
- package/docs/configure/app/performance/dns-prefetch.md +2 -0
- package/docs/configure/app/performance/preconnect.md +2 -0
- package/docs/configure/app/performance/prefetch.md +2 -0
- package/docs/configure/app/performance/preload.md +2 -0
- package/docs/configure/app/performance/print-file-size.md +2 -0
- package/docs/configure/app/performance/profile.md +2 -0
- package/docs/configure/app/performance/remove-console.md +2 -0
- package/docs/configure/app/performance/remove-moment-locale.md +2 -0
- package/docs/configure/app/performance/rsdoctor.md +2 -0
- package/docs/configure/app/plugins.md +2 -0
- package/docs/configure/app/resolve/alias-strategy.md +2 -0
- package/docs/configure/app/resolve/alias.md +2 -0
- package/docs/configure/app/resolve/condition-names.md +2 -0
- package/docs/configure/app/resolve/dedupe.md +2 -0
- package/docs/configure/app/resolve/extensions.md +2 -0
- package/docs/configure/app/runtime/0-intro.md +2 -0
- package/docs/configure/app/runtime/plugins.md +2 -0
- package/docs/configure/app/runtime/router.md +2 -0
- package/docs/configure/app/security/check-syntax.md +2 -0
- package/docs/configure/app/security/nonce.md +2 -0
- package/docs/configure/app/security/sri.md +2 -0
- package/docs/configure/app/server/base-url.md +2 -0
- package/docs/configure/app/server/port.md +2 -0
- package/docs/configure/app/server/public-routes.md +2 -0
- package/docs/configure/app/server/routes.md +2 -0
- package/docs/configure/app/server/rsc.md +2 -0
- package/docs/configure/app/server/ssr-by-entries.md +2 -0
- package/docs/configure/app/server/ssr.md +2 -0
- package/docs/configure/app/server/tsconfig-path.md +2 -0
- package/docs/configure/app/source/alias-strategy.md +2 -0
- package/docs/configure/app/source/alias.md +2 -0
- package/docs/configure/app/source/config-dir.md +2 -0
- package/docs/configure/app/source/decorators.md +2 -0
- package/docs/configure/app/source/define.md +2 -0
- package/docs/configure/app/source/disable-default-entries.md +2 -0
- package/docs/configure/app/source/enable-async-entry.md +2 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +2 -0
- package/docs/configure/app/source/entries-dir.md +2 -0
- package/docs/configure/app/source/entries.md +2 -0
- package/docs/configure/app/source/exclude.md +2 -0
- package/docs/configure/app/source/global-vars.md +2 -0
- package/docs/configure/app/source/include.md +2 -0
- package/docs/configure/app/source/main-entry-name.md +2 -0
- package/docs/configure/app/source/pre-entry.md +2 -0
- package/docs/configure/app/source/react-compiler.md +2 -0
- package/docs/configure/app/source/transform-import.md +2 -0
- package/docs/configure/app/split-chunks.md +2 -0
- package/docs/configure/app/tools/autoprefixer.md +2 -0
- package/docs/configure/app/tools/bundler-chain.md +2 -0
- package/docs/configure/app/tools/css-extract.md +2 -0
- package/docs/configure/app/tools/css-loader.md +2 -0
- package/docs/configure/app/tools/dev-server.md +2 -0
- package/docs/configure/app/tools/html-plugin.md +2 -0
- package/docs/configure/app/tools/less.md +2 -0
- package/docs/configure/app/tools/lightningcss-loader.md +2 -0
- package/docs/configure/app/tools/minify-css.md +2 -0
- package/docs/configure/app/tools/postcss.md +2 -0
- package/docs/configure/app/tools/rspack.md +2 -0
- package/docs/configure/app/tools/sass.md +2 -0
- package/docs/configure/app/tools/style-loader.md +2 -0
- package/docs/configure/app/tools/swc.md +2 -0
- package/docs/configure/app/tools/ts-checker.md +2 -0
- package/docs/configure/app/usage.md +2 -0
- package/docs/guides/advanced-features/bff/cross-project.md +2 -0
- package/docs/guides/advanced-features/bff/data-platform.md +4 -2
- package/docs/guides/advanced-features/bff/extend-server.md +2 -0
- package/docs/guides/advanced-features/bff/frameworks.md +38 -24
- package/docs/guides/advanced-features/bff/function.md +4 -2
- package/docs/guides/advanced-features/bff/operators.md +19 -17
- package/docs/guides/advanced-features/bff/sdk.md +2 -0
- package/docs/guides/advanced-features/bff/upload.md +2 -0
- package/docs/guides/advanced-features/bff.md +2 -0
- package/docs/guides/advanced-features/build-performance.md +2 -0
- package/docs/guides/advanced-features/compatibility.md +2 -0
- package/docs/guides/advanced-features/international/advanced.md +2 -0
- package/docs/guides/advanced-features/international/api.md +2 -0
- package/docs/guides/advanced-features/international/best-practices.md +2 -0
- package/docs/guides/advanced-features/international/configuration.md +2 -0
- package/docs/guides/advanced-features/international/locale-detection.md +2 -0
- package/docs/guides/advanced-features/international/quick-start.md +2 -0
- package/docs/guides/advanced-features/international/resource-loading.md +2 -0
- package/docs/guides/advanced-features/international/routing.md +2 -0
- package/docs/guides/advanced-features/international.md +2 -0
- package/docs/guides/advanced-features/low-level.md +2 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +2 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +2 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +2 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +2 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +2 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +2 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +2 -0
- package/docs/guides/advanced-features/source-build.md +2 -0
- package/docs/guides/advanced-features/web-server.md +2 -0
- package/docs/guides/basic-features/alias.md +2 -0
- package/docs/guides/basic-features/css/css-in-js.md +2 -0
- package/docs/guides/basic-features/css/css-modules.md +2 -0
- package/docs/guides/basic-features/css/css.md +2 -0
- package/docs/guides/basic-features/css/tailwindcss.md +2 -0
- package/docs/guides/basic-features/data/data-cache.md +2 -0
- package/docs/guides/basic-features/data/data-fetch.md +2 -0
- package/docs/guides/basic-features/data/data-write.md +2 -0
- package/docs/guides/basic-features/debug/mock.md +2 -0
- package/docs/guides/basic-features/debug/proxy.md +2 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +2 -0
- package/docs/guides/basic-features/debug/using-storybook.md +2 -0
- package/docs/guides/basic-features/deploy.md +2 -0
- package/docs/guides/basic-features/env-vars.md +2 -0
- package/docs/guides/basic-features/html.md +2 -0
- package/docs/guides/basic-features/output-files.md +2 -0
- package/docs/guides/basic-features/render/before-render.md +2 -0
- package/docs/guides/basic-features/render/overview.md +2 -0
- package/docs/guides/basic-features/render/rsc.md +2 -0
- package/docs/guides/basic-features/render/ssg.md +2 -0
- package/docs/guides/basic-features/render/ssr-cache.md +2 -0
- package/docs/guides/basic-features/render/ssr.md +2 -0
- package/docs/guides/basic-features/render/streaming-ssr.md +2 -0
- package/docs/guides/basic-features/routes/config-routes.md +2 -0
- package/docs/guides/basic-features/routes/routes.md +2 -0
- package/docs/guides/basic-features/static-assets/json-files.md +2 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +2 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.md +2 -0
- package/docs/guides/basic-features/static-assets.md +2 -0
- package/docs/guides/basic-features/testing/playwright.md +2 -0
- package/docs/guides/basic-features/testing/rstest.md +2 -0
- package/docs/guides/concept/builder.md +2 -0
- package/docs/guides/concept/entries.md +2 -0
- package/docs/guides/concept/server.md +2 -0
- package/docs/guides/get-started/ai-coding-agents.md +2 -0
- package/docs/guides/get-started/glossary.md +2 -0
- package/docs/guides/get-started/introduction.md +2 -0
- package/docs/guides/get-started/quick-start.md +3 -5
- package/docs/guides/get-started/tech-stack.md +2 -0
- package/docs/guides/get-started/ultramodern.md +11 -90
- package/docs/guides/get-started/upgrade.md +2 -0
- package/docs/guides/topic-detail/module-federation/application.md +2 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +2 -0
- package/docs/guides/topic-detail/module-federation/i18n.md +2 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +2 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +2 -0
- package/docs/guides/topic-detail/module-federation/usage.md +2 -0
- package/docs/guides/troubleshooting/builder.md +2 -0
- package/docs/guides/troubleshooting/cli.md +2 -0
- package/docs/guides/troubleshooting/dependencies.md +2 -0
- package/docs/guides/troubleshooting/hmr.md +2 -0
- package/docs/guides/upgrade/config.md +2 -0
- package/docs/guides/upgrade/entry.md +2 -0
- package/docs/guides/upgrade/other.md +2 -0
- package/docs/guides/upgrade/overview.md +2 -0
- package/docs/guides/upgrade/tailwindcss.md +2 -0
- package/docs/guides/upgrade/web-server.md +2 -0
- package/docs/index.md +2 -0
- package/docs/llms.txt +2 -2
- package/docs/plugin/cli-plugins/api.md +2 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +2 -0
- package/docs/plugin/official/cli-plugins.md +2 -0
- package/docs/plugin/plugin-system.md +2 -0
- package/docs/plugin/runtime-plugins/api.md +2 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +2 -0
- package/docs/plugin/server-plugins/life-cycle.md +2 -0
- package/docs/tutorials/examples/csr-auth.md +2 -0
- package/docs/tutorials/foundations/introduction.md +2 -0
- package/package.json +30 -38
- package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +0 -125
- package/dist/cjs/config/build-environment.js +0 -268
- package/dist/cjs/config/public.js +0 -46
- package/dist/cjs/plugins/backend-federation/codegen.js +0 -256
- package/dist/cjs/plugins/backend-federation/config.js +0 -204
- package/dist/cjs/plugins/backend-federation/emit.js +0 -150
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +0 -62
- package/dist/cjs/plugins/deploy/utils/npmAliases.js +0 -226
- package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +0 -44
- package/dist/cjs/presetUltramodern.js +0 -168
- package/dist/cjs/types/config/precompress.js +0 -18
- package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -77
- package/dist/esm/config/build-environment.mjs +0 -224
- package/dist/esm/config/public.mjs +0 -1
- package/dist/esm/plugins/backend-federation/codegen.mjs +0 -205
- package/dist/esm/plugins/backend-federation/config.mjs +0 -128
- package/dist/esm/plugins/backend-federation/emit.mjs +0 -99
- package/dist/esm/plugins/backendFederationBuild.mjs +0 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -1
- package/dist/esm/plugins/deploy/utils/npmAliases.mjs +0 -174
- package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +0 -6
- package/dist/esm/presetUltramodern.mjs +0 -112
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -78
- package/dist/esm-node/config/build-environment.mjs +0 -225
- package/dist/esm-node/config/public.mjs +0 -2
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +0 -206
- package/dist/esm-node/plugins/backend-federation/config.mjs +0 -129
- package/dist/esm-node/plugins/backend-federation/emit.mjs +0 -100
- package/dist/esm-node/plugins/backendFederationBuild.mjs +0 -2
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -2
- package/dist/esm-node/plugins/deploy/utils/npmAliases.mjs +0 -175
- package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +0 -7
- package/dist/esm-node/presetUltramodern.mjs +0 -113
- package/dist/esm-node/types/config/precompress.mjs +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterPrecompress.d.ts +0 -3
- package/dist/types/config/build-environment.d.ts +0 -22
- package/dist/types/config/public.d.ts +0 -2
- package/dist/types/plugins/backend-federation/codegen.d.ts +0 -86
- package/dist/types/plugins/backend-federation/config.d.ts +0 -103
- package/dist/types/plugins/backend-federation/emit.d.ts +0 -13
- package/dist/types/plugins/backendFederationBuild.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +0 -1
- package/dist/types/plugins/deploy/utils/npmAliases.d.ts +0 -14
- package/dist/types/plugins/ultramodernReleaseEnvelope.d.ts +0 -3
- package/dist/types/presetUltramodern.d.ts +0 -87
- package/dist/types/types/config/precompress.d.ts +0 -20
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import node_path from "node:path";
|
|
2
|
-
import { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, formatBackendFederationValidationErrors, validateBackendFederationManifest } from "@modern-js/utils/universal";
|
|
3
|
-
import { build } from "esbuild";
|
|
4
|
-
import { normalizeRelativePath } from "./config.mjs";
|
|
5
|
-
const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
|
|
6
|
-
const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
|
|
7
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
8
|
-
};
|
|
9
|
-
const createPublicPath = (containerEntry, fallbackPort)=>{
|
|
10
|
-
try {
|
|
11
|
-
return new URL('.', containerEntry).href;
|
|
12
|
-
} catch {
|
|
13
|
-
const slashIndex = containerEntry.lastIndexOf('/');
|
|
14
|
-
if (slashIndex >= 0) return containerEntry.slice(0, slashIndex + 1);
|
|
15
|
-
return `http://localhost:${fallbackPort}/`;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const createBackendRemoteEntrySource = async (workspaceRoot, app, effectApiPath, entryPath)=>{
|
|
19
|
-
const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(effectApiPath), effectApiPath);
|
|
20
|
-
const containerMetadata = {
|
|
21
|
-
buildVersion: app.buildVersion,
|
|
22
|
-
expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
|
|
23
|
-
name: app.backendName,
|
|
24
|
-
packageName: app.packageName,
|
|
25
|
-
remoteType: app.remoteType,
|
|
26
|
-
source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
|
|
27
|
-
version: app.version,
|
|
28
|
-
...app.unitId ? {
|
|
29
|
-
unitId: app.unitId
|
|
30
|
-
} : {},
|
|
31
|
-
...app.sourceRevision ? {
|
|
32
|
-
sourceRevision: app.sourceRevision
|
|
33
|
-
} : {}
|
|
34
|
-
};
|
|
35
|
-
const compatibility = {
|
|
36
|
-
build: app.buildVersion,
|
|
37
|
-
contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
|
|
38
|
-
nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
|
|
39
|
-
packageName: app.packageName,
|
|
40
|
-
...app.unitId ? {
|
|
41
|
-
unitId: app.unitId
|
|
42
|
-
} : {},
|
|
43
|
-
...app.sourceRevision ? {
|
|
44
|
-
sourceRevision: app.sourceRevision
|
|
45
|
-
} : {}
|
|
46
|
-
};
|
|
47
|
-
const source = `// Generated by Modern.js backend federation build.
|
|
48
|
-
import * as exposedNamespace from ${JSON.stringify(effectApiSpecifier)};
|
|
49
|
-
|
|
50
|
-
const exposedModule = {
|
|
51
|
-
...exposedNamespace,
|
|
52
|
-
backendFederationContract: {
|
|
53
|
-
...(exposedNamespace.backendFederationContract ?? {}),
|
|
54
|
-
compatibility: {
|
|
55
|
-
...(exposedNamespace.backendFederationContract?.compatibility ?? {}),
|
|
56
|
-
...${JSON.stringify(compatibility)},
|
|
57
|
-
},
|
|
58
|
-
name: ${JSON.stringify(app.backendName)},
|
|
59
|
-
role: 'microvertical-server',
|
|
60
|
-
runtimeFramework: 'effect',
|
|
61
|
-
strictEffectApproach: true,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
const exposedModules = {
|
|
65
|
-
${JSON.stringify(BACKEND_FEDERATION_EFFECT_EXPOSE)}: () => Promise.resolve(exposedModule),
|
|
66
|
-
};
|
|
67
|
-
const __modernjsBackendFederation = ${JSON.stringify(containerMetadata)};
|
|
68
|
-
|
|
69
|
-
function init() {}
|
|
70
|
-
|
|
71
|
-
function get(id) {
|
|
72
|
-
const load = exposedModules[id];
|
|
73
|
-
if (!load) {
|
|
74
|
-
throw new Error(\`Unexpected backend federation expose: \${id}\`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return async () => load();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = { __modernjsBackendFederation, get, init };
|
|
81
|
-
`;
|
|
82
|
-
const result = await build({
|
|
83
|
-
absWorkingDir: node_path.dirname(effectApiPath),
|
|
84
|
-
bundle: true,
|
|
85
|
-
format: 'cjs',
|
|
86
|
-
logLevel: 'silent',
|
|
87
|
-
platform: 'node',
|
|
88
|
-
stdin: {
|
|
89
|
-
contents: source,
|
|
90
|
-
loader: 'ts',
|
|
91
|
-
resolveDir: node_path.dirname(effectApiPath),
|
|
92
|
-
sourcefile: node_path.basename(entryPath)
|
|
93
|
-
},
|
|
94
|
-
target: 'node20',
|
|
95
|
-
write: false
|
|
96
|
-
});
|
|
97
|
-
const output = result.outputFiles[0];
|
|
98
|
-
if (!output) throw new Error('[backend-federation-build] CommonJS backend federation container emitted no output.');
|
|
99
|
-
return output.text;
|
|
100
|
-
};
|
|
101
|
-
const createBackendManifest = (workspaceRoot, distDirectory, app, entryIntegrity)=>{
|
|
102
|
-
const sourceModule = `${app.directory}/api/effect-api.ts`;
|
|
103
|
-
const publicPath = createPublicPath(app.containerEntry, app.port);
|
|
104
|
-
const manifest = {
|
|
105
|
-
schemaVersion: 1,
|
|
106
|
-
id: app.backendName,
|
|
107
|
-
name: app.backendName,
|
|
108
|
-
version: app.version,
|
|
109
|
-
buildVersion: app.buildVersion,
|
|
110
|
-
metaData: {
|
|
111
|
-
name: app.backendName,
|
|
112
|
-
type: 'backend',
|
|
113
|
-
buildInfo: {
|
|
114
|
-
buildVersion: app.buildVersion,
|
|
115
|
-
buildName: app.packageName
|
|
116
|
-
},
|
|
117
|
-
remoteEntry: {
|
|
118
|
-
name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
|
|
119
|
-
path: '',
|
|
120
|
-
type: app.remoteType
|
|
121
|
-
},
|
|
122
|
-
globalName: app.backendName,
|
|
123
|
-
publicPath,
|
|
124
|
-
ssrRemoteEntry: {
|
|
125
|
-
name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
|
|
126
|
-
path: '',
|
|
127
|
-
type: app.remoteType
|
|
128
|
-
},
|
|
129
|
-
ssrPublicPath: publicPath
|
|
130
|
-
},
|
|
131
|
-
entry: {
|
|
132
|
-
...entryIntegrity,
|
|
133
|
-
file: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
|
|
134
|
-
path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE))),
|
|
135
|
-
type: app.remoteType,
|
|
136
|
-
url: app.containerEntry
|
|
137
|
-
},
|
|
138
|
-
exposes: [
|
|
139
|
-
{
|
|
140
|
-
id: `${app.backendName}:${BACKEND_FEDERATION_EFFECT_EXPOSE}`,
|
|
141
|
-
name: BACKEND_FEDERATION_EFFECT_EXPOSE,
|
|
142
|
-
path: '',
|
|
143
|
-
assets: {
|
|
144
|
-
js: {
|
|
145
|
-
async: [],
|
|
146
|
-
sync: [
|
|
147
|
-
BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
css: {
|
|
151
|
-
async: [],
|
|
152
|
-
sync: []
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
shared: [],
|
|
158
|
-
backendFederation: {
|
|
159
|
-
role: 'microvertical-server',
|
|
160
|
-
appId: app.id,
|
|
161
|
-
name: app.backendName,
|
|
162
|
-
runtimeFramework: 'effect',
|
|
163
|
-
strictEffectApproach: true,
|
|
164
|
-
contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
|
|
165
|
-
nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
|
|
166
|
-
remoteType: app.remoteType,
|
|
167
|
-
expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
|
|
168
|
-
manifestUrl: app.manifestUrl,
|
|
169
|
-
containerEntry: app.containerEntry,
|
|
170
|
-
source: {
|
|
171
|
-
module: sourceModule
|
|
172
|
-
},
|
|
173
|
-
readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
|
|
174
|
-
openapiPath: `${app.apiPrefix}/openapi.json`,
|
|
175
|
-
...app.deliveryUnit ? {
|
|
176
|
-
deliveryUnit: app.deliveryUnit
|
|
177
|
-
} : {},
|
|
178
|
-
versionBoundary: {
|
|
179
|
-
invariant: 'web-and-api-same-build',
|
|
180
|
-
packageName: app.packageName,
|
|
181
|
-
version: app.version,
|
|
182
|
-
buildVersion: app.buildVersion,
|
|
183
|
-
...app.uiManifestUrl ? {
|
|
184
|
-
uiManifestUrl: app.uiManifestUrl
|
|
185
|
-
} : {},
|
|
186
|
-
...app.deliveryUnit ? {
|
|
187
|
-
deliveryUnit: {
|
|
188
|
-
unitId: app.deliveryUnit.unitId,
|
|
189
|
-
buildMarker: app.deliveryUnit.buildMarker,
|
|
190
|
-
sourceRevision: app.deliveryUnit.sourceRevision
|
|
191
|
-
}
|
|
192
|
-
} : {}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const validation = validateBackendFederationManifest(manifest, {
|
|
197
|
-
path: 'backendFederationManifest',
|
|
198
|
-
requireEffectExpose: true,
|
|
199
|
-
requireEffectRuntime: true,
|
|
200
|
-
requireVersionFields: true
|
|
201
|
-
});
|
|
202
|
-
if (!validation.ok) throw new Error(`[backend-federation-build] Invalid backend federation manifest: ${formatBackendFederationValidationErrors(validation.errors)}.`);
|
|
203
|
-
return manifest;
|
|
204
|
-
};
|
|
205
|
-
export { createBackendManifest, createBackendRemoteEntrySource };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import promises from "node:fs/promises";
|
|
3
|
-
import node_path from "node:path";
|
|
4
|
-
import { resolveUltramodernSourceRevision } from "@modern-js/app-tools-extensions/release-identity";
|
|
5
|
-
import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, DELIVERY_UNIT_DEPLOY_PROFILE, DELIVERY_UNIT_KIND, DELIVERY_UNIT_SCHEMA_VERSION, ULTRAMODERN_BUILD_ARTIFACT_FILE, ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, deliveryUnitContractBlock, isUltramodernBuildArtifact, validateDeliveryUnitRecord, validateUltramodernBuildArtifact } from "@modern-js/utils/universal";
|
|
6
|
-
const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
|
|
7
|
-
const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
|
|
8
|
-
const isRecord = (value)=>'object' == typeof value && null !== value;
|
|
9
|
-
const readJsonFile = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf8'));
|
|
10
|
-
const buildArtifactPathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_ARTIFACT_PATH);
|
|
11
|
-
const buildModulePathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_MODULE_PATH);
|
|
12
|
-
const readBuildIdentity = async (appDirectory)=>{
|
|
13
|
-
const buildArtifactPath = buildArtifactPathFor(appDirectory);
|
|
14
|
-
if (existsSync(buildArtifactPath)) {
|
|
15
|
-
const artifact = await readJsonFile(buildArtifactPath);
|
|
16
|
-
const artifactValidation = validateUltramodernBuildArtifact(artifact, buildArtifactPath);
|
|
17
|
-
if (!artifactValidation.ok) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
|
|
18
|
-
if (!isUltramodernBuildArtifact(artifact)) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
|
|
19
|
-
const deliveryUnit = artifact.deliveryUnit;
|
|
20
|
-
return {
|
|
21
|
-
artifact,
|
|
22
|
-
appId: deliveryUnit.appId,
|
|
23
|
-
buildVersion: deliveryUnit.buildMarker,
|
|
24
|
-
packageName: deliveryUnit.packageName,
|
|
25
|
-
version: deliveryUnit.version,
|
|
26
|
-
unitId: deliveryUnit.unitId,
|
|
27
|
-
sourceRevision: deliveryUnit.sourceRevision
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const buildModulePath = buildModulePathFor(appDirectory);
|
|
31
|
-
if (!existsSync(buildModulePath)) return {};
|
|
32
|
-
console.warn(`[backend-federation-build] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ${ULTRAMODERN_BUILD_ARTIFACT_FILE}.`);
|
|
33
|
-
const source = await promises.readFile(buildModulePath, 'utf8');
|
|
34
|
-
return {
|
|
35
|
-
appId: source.match(/\bappId:\s*['"]([^'"]+)['"]/u)?.[1],
|
|
36
|
-
buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
|
|
37
|
-
packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
|
|
38
|
-
version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
|
|
39
|
-
unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
|
|
40
|
-
sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
|
|
44
|
-
const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
45
|
-
const createBackendName = (app, id)=>{
|
|
46
|
-
const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
|
|
47
|
-
if (configuredName) return configuredName;
|
|
48
|
-
const mfName = stringValue(app.moduleFederation?.name);
|
|
49
|
-
return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
|
|
50
|
-
};
|
|
51
|
-
const findWorkspaceRoot = (appDirectory)=>{
|
|
52
|
-
let current = appDirectory;
|
|
53
|
-
while(true){
|
|
54
|
-
if (existsSync(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
|
|
55
|
-
const parent = node_path.dirname(current);
|
|
56
|
-
if (parent === current) return;
|
|
57
|
-
current = parent;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const resolveWorkspaceSourceRevision = async (workspaceRoot)=>resolveUltramodernSourceRevision(workspaceRoot);
|
|
61
|
-
const createStampedDeliveryUnit = (input)=>{
|
|
62
|
-
if (!input.unitId || !input.buildMarker || !input.packageName || !input.version) return;
|
|
63
|
-
const record = {
|
|
64
|
-
schemaVersion: DELIVERY_UNIT_SCHEMA_VERSION,
|
|
65
|
-
kind: DELIVERY_UNIT_KIND,
|
|
66
|
-
appId: input.appId,
|
|
67
|
-
unitId: input.unitId,
|
|
68
|
-
packageName: input.packageName,
|
|
69
|
-
version: input.version,
|
|
70
|
-
buildMarker: input.buildMarker,
|
|
71
|
-
sourceRevision: input.sourceRevision,
|
|
72
|
-
deployProfile: DELIVERY_UNIT_DEPLOY_PROFILE
|
|
73
|
-
};
|
|
74
|
-
const validation = validateDeliveryUnitRecord(record);
|
|
75
|
-
if (!validation.ok) return;
|
|
76
|
-
return deliveryUnitContractBlock(record);
|
|
77
|
-
};
|
|
78
|
-
const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
|
|
79
|
-
const id = stringValue(compactApp.id);
|
|
80
|
-
const appPath = stringValue(compactApp.path);
|
|
81
|
-
if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
|
|
82
|
-
const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
|
|
83
|
-
if (node_path.resolve(workspaceRoot, directory) !== node_path.resolve(appDirectory)) return;
|
|
84
|
-
const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
|
|
85
|
-
if (void 0 === port) return;
|
|
86
|
-
const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
|
|
87
|
-
const apiStem = stringValue(compactApp.api.stem) ?? id;
|
|
88
|
-
const backendName = createBackendName(compactApp, id);
|
|
89
|
-
const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_FEDERATION_MANIFEST_FILE}`;
|
|
90
|
-
const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`;
|
|
91
|
-
const configuredRemoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType);
|
|
92
|
-
if (void 0 !== configuredRemoteType && 'commonjs-module' !== configuredRemoteType) throw new Error(`[backend-federation-build] Node backend federation remoteType must be "commonjs-module"; received "${configuredRemoteType}" for ${id}.`);
|
|
93
|
-
if (!new URL(containerEntry).pathname.endsWith(`/${BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`)) throw new Error(`[backend-federation-build] Node backend federation containerEntry must end with "/${BACKEND_FEDERATION_REMOTE_ENTRY_FILE}"; received "${containerEntry}" for ${id}.`);
|
|
94
|
-
const remoteType = 'commonjs-module';
|
|
95
|
-
const packageName = stringValue(compactApp.package);
|
|
96
|
-
const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
|
|
97
|
-
const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
|
|
98
|
-
unitId: stringValue(compactApp.deliveryUnit.unitId),
|
|
99
|
-
buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
|
|
100
|
-
sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
|
|
101
|
-
packageName: stringValue(compactApp.deliveryUnit.packageName),
|
|
102
|
-
version: stringValue(compactApp.deliveryUnit.version)
|
|
103
|
-
} : void 0;
|
|
104
|
-
return {
|
|
105
|
-
id,
|
|
106
|
-
directory,
|
|
107
|
-
packageName,
|
|
108
|
-
port,
|
|
109
|
-
apiPrefix,
|
|
110
|
-
apiStem,
|
|
111
|
-
backendName,
|
|
112
|
-
manifestUrl,
|
|
113
|
-
containerEntry,
|
|
114
|
-
remoteType,
|
|
115
|
-
uiManifestUrl,
|
|
116
|
-
compactDeliveryUnit
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
|
|
120
|
-
const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
|
|
121
|
-
const compactConfig = await readJsonFile(compactConfigPath);
|
|
122
|
-
const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
|
|
123
|
-
for (const app of apps){
|
|
124
|
-
const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
|
|
125
|
-
if (resolved) return resolved;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
export { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createAppFromCompactMetadata, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, normalizeRelativePath, readBuildIdentity, resolveWorkspaceSourceRevision };
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import promises from "node:fs/promises";
|
|
3
|
-
import node_path from "node:path";
|
|
4
|
-
import { resolveUltramodernReleaseIdentity } from "@modern-js/app-tools-extensions/release-identity";
|
|
5
|
-
import { createBackendFederationEntryIntegrity } from "@modern-js/server-runtime-extensions/backend-federation-security/node";
|
|
6
|
-
import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, stampUltramodernBuildArtifactIdentity } from "@modern-js/utils/universal";
|
|
7
|
-
import { createBackendManifest, createBackendRemoteEntrySource } from "./codegen.mjs";
|
|
8
|
-
import { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, readBuildIdentity, resolveWorkspaceSourceRevision } from "./config.mjs";
|
|
9
|
-
const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
|
|
10
|
-
const workspaceRoot = findWorkspaceRoot(appDirectory);
|
|
11
|
-
if (!workspaceRoot) return;
|
|
12
|
-
const effectApiPath = node_path.join(appDirectory, 'api/effect-api.ts');
|
|
13
|
-
const backendFederationConfigPath = node_path.join(appDirectory, 'backend-federation.config.ts');
|
|
14
|
-
if (!existsSync(effectApiPath) || !existsSync(backendFederationConfigPath)) return;
|
|
15
|
-
const app = await findBackendFederationApp(workspaceRoot, appDirectory);
|
|
16
|
-
if (!app) return;
|
|
17
|
-
const buildIdentity = await readBuildIdentity(appDirectory);
|
|
18
|
-
const compactDeliveryUnit = app.compactDeliveryUnit;
|
|
19
|
-
const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
|
|
20
|
-
const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
|
|
21
|
-
if (hasBuildIdentity) {
|
|
22
|
-
const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
|
|
23
|
-
const buildIdentityPath = existsSync(buildArtifactPathFor(appDirectory)) ? buildArtifactPathFor(appDirectory) : buildModulePathFor(appDirectory);
|
|
24
|
-
const mismatches = [];
|
|
25
|
-
const compare = (label, a, b, leftLabel = 'deliveryUnit')=>{
|
|
26
|
-
if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: ${leftLabel}=${a} vs ultramodern-build=${b}`);
|
|
27
|
-
};
|
|
28
|
-
compare('appId', app.id, buildIdentity.appId, 'topology');
|
|
29
|
-
if (hasCompactDeliveryUnit) {
|
|
30
|
-
compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
|
|
31
|
-
compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
|
|
32
|
-
compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
|
|
33
|
-
compare('version', compactDeliveryUnit?.version, buildIdentity.version);
|
|
34
|
-
}
|
|
35
|
-
if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (topology) and ${buildIdentityPath}: ${mismatches.join('; ')}`);
|
|
36
|
-
}
|
|
37
|
-
const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
|
|
38
|
-
const generationBuildMarker = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
|
|
39
|
-
const sourceRevision = await resolveWorkspaceSourceRevision(workspaceRoot);
|
|
40
|
-
const buildVersion = generationBuildMarker && unitId ? resolveUltramodernReleaseIdentity({
|
|
41
|
-
generationBuildMarker,
|
|
42
|
-
unitId,
|
|
43
|
-
workspaceRoot
|
|
44
|
-
}).buildMarker : void 0;
|
|
45
|
-
const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
|
|
46
|
-
const version = compactDeliveryUnit?.version ?? buildIdentity.version;
|
|
47
|
-
const deliveryUnit = createStampedDeliveryUnit({
|
|
48
|
-
appId: app.id,
|
|
49
|
-
unitId,
|
|
50
|
-
buildMarker: buildVersion,
|
|
51
|
-
packageName,
|
|
52
|
-
version,
|
|
53
|
-
sourceRevision
|
|
54
|
-
});
|
|
55
|
-
const stampedBuildArtifact = buildIdentity.artifact ? stampUltramodernBuildArtifactIdentity(buildIdentity.artifact, {
|
|
56
|
-
buildMarker: buildVersion ?? buildIdentity.artifact.deliveryUnit.buildMarker,
|
|
57
|
-
sourceRevision
|
|
58
|
-
}) : void 0;
|
|
59
|
-
const resolvedApp = {
|
|
60
|
-
...app,
|
|
61
|
-
packageName,
|
|
62
|
-
version,
|
|
63
|
-
buildVersion,
|
|
64
|
-
unitId,
|
|
65
|
-
sourceRevision,
|
|
66
|
-
deliveryUnit
|
|
67
|
-
};
|
|
68
|
-
const manifestPath = node_path.join(distDirectory, BACKEND_FEDERATION_MANIFEST_FILE);
|
|
69
|
-
const entryPath = node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE);
|
|
70
|
-
const deliveryUnitArtifactPath = stampedBuildArtifact ? node_path.join(distDirectory, ULTRAMODERN_BUILD_ARTIFACT_FILE) : void 0;
|
|
71
|
-
const entrySource = await createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath);
|
|
72
|
-
await promises.mkdir(distDirectory, {
|
|
73
|
-
recursive: true
|
|
74
|
-
});
|
|
75
|
-
await promises.writeFile(entryPath, entrySource);
|
|
76
|
-
await promises.writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp, createBackendFederationEntryIntegrity(entrySource)), null, 2)}\n`);
|
|
77
|
-
if (stampedBuildArtifact && deliveryUnitArtifactPath) await promises.writeFile(deliveryUnitArtifactPath, `${JSON.stringify(stampedBuildArtifact, null, 2)}\n`);
|
|
78
|
-
return {
|
|
79
|
-
appId: resolvedApp.id,
|
|
80
|
-
manifestPath,
|
|
81
|
-
containerPath: entryPath,
|
|
82
|
-
...deliveryUnitArtifactPath ? {
|
|
83
|
-
deliveryUnitArtifactPath
|
|
84
|
-
} : {},
|
|
85
|
-
remoteName: resolvedApp.backendName,
|
|
86
|
-
remoteType: resolvedApp.remoteType
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
const emit = ()=>({
|
|
90
|
-
name: '@modern-js/backend-federation-build',
|
|
91
|
-
setup (api) {
|
|
92
|
-
api.onAfterBuild(async ()=>{
|
|
93
|
-
const { appDirectory, distDirectory } = api.getAppContext();
|
|
94
|
-
await emitBackendFederationArtifacts(appDirectory, distDirectory);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
export default emit;
|
|
99
|
-
export { emitBackendFederationArtifacts };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default, emitBackendFederationArtifacts } from "./backend-federation/emit.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@modern-js/app-tools-extensions/cloudflare-output-verifier";
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import promises from "node:fs/promises";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
const dependencyKeys = [
|
|
4
|
-
'dependencies',
|
|
5
|
-
'optionalDependencies'
|
|
6
|
-
];
|
|
7
|
-
const exactVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;
|
|
8
|
-
async function readPackageJson(filePath) {
|
|
9
|
-
return JSON.parse(await promises.readFile(filePath, 'utf8'));
|
|
10
|
-
}
|
|
11
|
-
function parseNpmAlias(aliasName, specifier) {
|
|
12
|
-
if (!specifier.startsWith('npm:')) return;
|
|
13
|
-
const target = specifier.slice(4);
|
|
14
|
-
const versionSeparator = target.lastIndexOf('@');
|
|
15
|
-
if (versionSeparator <= 0 || versionSeparator === target.length - 1) throw new Error(`Invalid npm alias specifier for ${aliasName}: ${specifier}`);
|
|
16
|
-
return {
|
|
17
|
-
aliasName,
|
|
18
|
-
targetName: target.slice(0, versionSeparator),
|
|
19
|
-
targetVersion: target.slice(versionSeparator + 1)
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function aliasesFromPackageJson(packageJson) {
|
|
23
|
-
const aliases = [];
|
|
24
|
-
for (const dependencyKey of dependencyKeys)for (const [aliasName, specifier] of Object.entries(packageJson[dependencyKey] ?? {})){
|
|
25
|
-
const alias = parseNpmAlias(aliasName, specifier);
|
|
26
|
-
if (alias) aliases.push(alias);
|
|
27
|
-
}
|
|
28
|
-
return aliases;
|
|
29
|
-
}
|
|
30
|
-
async function collectPackageRecords(nodeModulesDirectory) {
|
|
31
|
-
const records = [];
|
|
32
|
-
const visitedNodeModules = new Set();
|
|
33
|
-
const visitPackage = async (directory)=>{
|
|
34
|
-
const packageJsonPath = node_path.join(directory, 'package.json');
|
|
35
|
-
try {
|
|
36
|
-
const packageJson = await readPackageJson(packageJsonPath);
|
|
37
|
-
if (packageJson.name && packageJson.version) records.push({
|
|
38
|
-
directory,
|
|
39
|
-
packageJson
|
|
40
|
-
});
|
|
41
|
-
} catch (error) {
|
|
42
|
-
if ('ENOENT' !== error.code) throw error;
|
|
43
|
-
}
|
|
44
|
-
await visitNodeModules(node_path.join(directory, 'node_modules'));
|
|
45
|
-
};
|
|
46
|
-
const visitScope = async (scopeDirectory)=>{
|
|
47
|
-
const entries = await promises.readdir(scopeDirectory, {
|
|
48
|
-
withFileTypes: true
|
|
49
|
-
});
|
|
50
|
-
for (const entry of entries)if (entry.isDirectory()) await visitPackage(node_path.join(scopeDirectory, entry.name));
|
|
51
|
-
};
|
|
52
|
-
const visitNdepeStore = async (storeDirectory)=>{
|
|
53
|
-
const entries = await promises.readdir(storeDirectory, {
|
|
54
|
-
withFileTypes: true
|
|
55
|
-
});
|
|
56
|
-
for (const entry of entries)if (entry.isDirectory()) {
|
|
57
|
-
const entryPath = node_path.join(storeDirectory, entry.name);
|
|
58
|
-
if (entry.name.startsWith('@')) await visitScope(entryPath);
|
|
59
|
-
else await visitNodeModules(node_path.join(entryPath, 'node_modules'));
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const visitNodeModules = async (directory)=>{
|
|
63
|
-
const resolvedDirectory = node_path.resolve(directory);
|
|
64
|
-
if (visitedNodeModules.has(resolvedDirectory)) return;
|
|
65
|
-
visitedNodeModules.add(resolvedDirectory);
|
|
66
|
-
let entries;
|
|
67
|
-
try {
|
|
68
|
-
entries = await promises.readdir(directory, {
|
|
69
|
-
withFileTypes: true
|
|
70
|
-
});
|
|
71
|
-
} catch (error) {
|
|
72
|
-
if ('ENOENT' === error.code) return;
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
for (const entry of entries){
|
|
76
|
-
if (!entry.isDirectory()) continue;
|
|
77
|
-
const entryPath = node_path.join(directory, entry.name);
|
|
78
|
-
if ('.ndepe' === entry.name) await visitNdepeStore(entryPath);
|
|
79
|
-
else if (entry.name.startsWith('@')) await visitScope(entryPath);
|
|
80
|
-
else await visitPackage(entryPath);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
await visitNodeModules(nodeModulesDirectory);
|
|
84
|
-
return records;
|
|
85
|
-
}
|
|
86
|
-
async function resolveAliasTarget(ownerDirectory, alias, outputDirectory) {
|
|
87
|
-
let directory = ownerDirectory;
|
|
88
|
-
const outputRoot = node_path.resolve(outputDirectory);
|
|
89
|
-
const resolvedOutputRoot = await promises.realpath(outputRoot);
|
|
90
|
-
while(directory === outputRoot || directory.startsWith(`${outputRoot}${node_path.sep}`)){
|
|
91
|
-
const candidate = node_path.join(directory, 'node_modules', alias.targetName);
|
|
92
|
-
try {
|
|
93
|
-
const resolvedCandidate = await promises.realpath(candidate);
|
|
94
|
-
if (resolvedCandidate !== resolvedOutputRoot && !resolvedCandidate.startsWith(`${resolvedOutputRoot}${node_path.sep}`)) throw new Error(`Cannot preserve npm alias ${alias.aliasName}: emitted target ${candidate} resolves outside deployment output to ${resolvedCandidate}`);
|
|
95
|
-
const packageJson = await readPackageJson(node_path.join(candidate, 'package.json'));
|
|
96
|
-
if (packageJson.name !== alias.targetName || !packageJson.version) throw new Error(`npm alias ${alias.aliasName} resolved ${candidate} to unexpected package ${String(packageJson.name)}`);
|
|
97
|
-
if (exactVersionPattern.test(alias.targetVersion) && packageJson.version !== alias.targetVersion) return;
|
|
98
|
-
return {
|
|
99
|
-
directory: candidate,
|
|
100
|
-
packageJson
|
|
101
|
-
};
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if ('ENOENT' !== error.code) throw error;
|
|
104
|
-
}
|
|
105
|
-
if (directory === outputRoot) break;
|
|
106
|
-
directory = node_path.dirname(directory);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async function ensureAliasLink(ownerDirectory, alias, target) {
|
|
110
|
-
const aliasPath = node_path.join(ownerDirectory, 'node_modules', alias.aliasName);
|
|
111
|
-
await promises.mkdir(node_path.dirname(aliasPath), {
|
|
112
|
-
recursive: true
|
|
113
|
-
});
|
|
114
|
-
try {
|
|
115
|
-
const [existing, expected] = await Promise.all([
|
|
116
|
-
promises.realpath(aliasPath),
|
|
117
|
-
promises.realpath(target.directory)
|
|
118
|
-
]);
|
|
119
|
-
if (existing === expected) return;
|
|
120
|
-
throw new Error(`Cannot preserve npm alias ${alias.aliasName}: ${aliasPath} already resolves to ${existing}, expected ${expected}`);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if ('ENOENT' !== error.code) throw error;
|
|
123
|
-
}
|
|
124
|
-
const linkTarget = node_path.relative(node_path.dirname(aliasPath), target.directory);
|
|
125
|
-
await promises.symlink(linkTarget, aliasPath, 'dir');
|
|
126
|
-
}
|
|
127
|
-
function aliasSpecifier(alias) {
|
|
128
|
-
return `npm:${alias.targetName}@${alias.targetVersion}`;
|
|
129
|
-
}
|
|
130
|
-
async function readPackageIdentity(entryPath) {
|
|
131
|
-
let directory = node_path.dirname(entryPath);
|
|
132
|
-
const root = node_path.parse(directory).root;
|
|
133
|
-
while(directory !== root){
|
|
134
|
-
try {
|
|
135
|
-
const packageJson = await readPackageJson(node_path.join(directory, 'package.json'));
|
|
136
|
-
if (packageJson.name && packageJson.version) return {
|
|
137
|
-
name: packageJson.name,
|
|
138
|
-
version: packageJson.version
|
|
139
|
-
};
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if ('ENOENT' !== error.code) throw error;
|
|
142
|
-
}
|
|
143
|
-
directory = node_path.dirname(directory);
|
|
144
|
-
}
|
|
145
|
-
throw new Error(`Cannot find owning package for deployment entry ${entryPath}`);
|
|
146
|
-
}
|
|
147
|
-
async function preserveNpmAliases({ appDirectory, outputDirectory, implicitAliases = [] }) {
|
|
148
|
-
const records = await collectPackageRecords(node_path.join(outputDirectory, 'node_modules'));
|
|
149
|
-
const appPackageJson = await readPackageJson(node_path.join(appDirectory, 'package.json'));
|
|
150
|
-
const rootAliases = [
|
|
151
|
-
...aliasesFromPackageJson(appPackageJson),
|
|
152
|
-
...implicitAliases
|
|
153
|
-
].filter((alias)=>alias.aliasName !== alias.targetName);
|
|
154
|
-
const emittedRootAliases = [];
|
|
155
|
-
for (const alias of rootAliases){
|
|
156
|
-
const target = await resolveAliasTarget(outputDirectory, alias, outputDirectory);
|
|
157
|
-
if (!target) {
|
|
158
|
-
if (implicitAliases.includes(alias)) throw new Error(`Cannot preserve implicit npm alias ${alias.aliasName}: emitted target ${alias.targetName}@${alias.targetVersion} is missing`);
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
await ensureAliasLink(outputDirectory, alias, target);
|
|
162
|
-
emittedRootAliases.push(alias);
|
|
163
|
-
}
|
|
164
|
-
for (const record of records)for (const alias of aliasesFromPackageJson(record.packageJson).filter((candidate)=>candidate.aliasName !== candidate.targetName)){
|
|
165
|
-
const target = await resolveAliasTarget(record.directory, alias, outputDirectory);
|
|
166
|
-
if (target) await ensureAliasLink(record.directory, alias, target);
|
|
167
|
-
}
|
|
168
|
-
const outputPackageJsonPath = node_path.join(outputDirectory, 'package.json');
|
|
169
|
-
const outputPackageJson = await readPackageJson(outputPackageJsonPath);
|
|
170
|
-
outputPackageJson.dependencies ??= {};
|
|
171
|
-
for (const alias of emittedRootAliases)outputPackageJson.dependencies[alias.aliasName] = aliasSpecifier(alias);
|
|
172
|
-
await promises.writeFile(outputPackageJsonPath, `${JSON.stringify(outputPackageJson, null, 2)}\n`);
|
|
173
|
-
}
|
|
174
|
-
export { preserveNpmAliases, readPackageIdentity };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
|
|
2
|
-
import { resolveDeployTarget } from "./deploy/index.mjs";
|
|
3
|
-
const ultramodernReleaseEnvelope = ()=>createUltramodernReleaseEnvelopePlugin({
|
|
4
|
-
resolveDeployTarget: resolveDeployTarget
|
|
5
|
-
});
|
|
6
|
-
export default ultramodernReleaseEnvelope;
|