@bleedingdev/modern-js-app-tools-extensions 3.9.0-ultramodern.3 → 3.9.0-ultramodern.5
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/backend-federation-build/codegen.js +256 -0
- package/dist/cjs/backend-federation-build/config.js +204 -0
- package/dist/cjs/backend-federation-build/emit.js +150 -0
- package/dist/cjs/backend-federation-build/index.js +53 -0
- package/dist/cjs/build-config/build-environment.js +268 -0
- package/dist/cjs/build-config/precompress/plugin.js +124 -0
- package/dist/cjs/build-config/precompress/types.js +18 -0
- package/dist/cjs/build-config/public.js +46 -0
- package/dist/cjs/cloudflare/constants.js +1 -1
- package/dist/cjs/cloudflare/delivery-unit.js +9 -9
- package/dist/cjs/cloudflare-output-contract.js +37 -1
- package/dist/cjs/cloudflare-output-verifier/identity.js +6 -6
- package/dist/cjs/cloudflare-output-verifier/worker-bundles.js +4 -1
- package/dist/cjs/config.js +29 -1
- package/dist/cjs/deploy-output/npmAliases.js +226 -0
- package/dist/cjs/deploy-output/plugin.js +76 -0
- package/dist/cjs/deploy-output/target.js +48 -0
- package/dist/cjs/native-type-checker.js +150 -0
- package/dist/cjs/release-envelope/framework-output.js +27 -27
- package/dist/cjs/release-envelope/plugin.js +2 -1
- package/dist/cjs/release-identity.js +3 -6
- package/dist/esm/backend-federation-build/codegen.mjs +205 -0
- package/dist/esm/backend-federation-build/config.mjs +128 -0
- package/dist/esm/backend-federation-build/emit.mjs +99 -0
- package/dist/esm/backend-federation-build/index.mjs +1 -0
- package/dist/esm/build-config/build-environment.mjs +224 -0
- package/dist/esm/build-config/precompress/plugin.mjs +76 -0
- package/dist/esm/build-config/precompress/types.mjs +0 -0
- package/dist/esm/build-config/public.mjs +1 -0
- package/dist/esm/cloudflare/constants.mjs +1 -1
- package/dist/esm/cloudflare/delivery-unit.mjs +1 -1
- package/dist/esm/cloudflare-output-contract.mjs +35 -2
- package/dist/esm/cloudflare-output-verifier/identity.mjs +1 -1
- package/dist/esm/cloudflare-output-verifier/worker-bundles.mjs +5 -2
- package/dist/esm/config.mjs +1 -0
- package/dist/esm/deploy-output/npmAliases.mjs +174 -0
- package/dist/esm/deploy-output/plugin.mjs +28 -0
- package/dist/esm/deploy-output/target.mjs +10 -0
- package/dist/esm/native-type-checker.mjs +99 -0
- package/dist/esm/release-envelope/framework-output.mjs +1 -1
- package/dist/esm/release-envelope/plugin.mjs +2 -1
- package/dist/esm/release-identity.mjs +3 -6
- package/dist/esm-node/backend-federation-build/codegen.mjs +206 -0
- package/dist/esm-node/backend-federation-build/config.mjs +129 -0
- package/dist/esm-node/backend-federation-build/emit.mjs +100 -0
- package/dist/esm-node/backend-federation-build/index.mjs +2 -0
- package/dist/esm-node/build-config/build-environment.mjs +225 -0
- package/dist/esm-node/build-config/precompress/plugin.mjs +77 -0
- package/dist/esm-node/build-config/precompress/types.mjs +1 -0
- package/dist/esm-node/build-config/public.mjs +2 -0
- package/dist/esm-node/cloudflare/constants.mjs +1 -1
- package/dist/esm-node/cloudflare/delivery-unit.mjs +1 -1
- package/dist/esm-node/cloudflare-output-contract.mjs +35 -2
- package/dist/esm-node/cloudflare-output-verifier/identity.mjs +1 -1
- package/dist/esm-node/cloudflare-output-verifier/worker-bundles.mjs +5 -2
- package/dist/esm-node/config.mjs +1 -0
- package/dist/esm-node/deploy-output/npmAliases.mjs +175 -0
- package/dist/esm-node/deploy-output/plugin.mjs +31 -0
- package/dist/esm-node/deploy-output/target.mjs +11 -0
- package/dist/esm-node/native-type-checker.mjs +100 -0
- package/dist/esm-node/release-envelope/framework-output.mjs +1 -1
- package/dist/esm-node/release-envelope/plugin.mjs +2 -1
- package/dist/esm-node/release-identity.mjs +3 -6
- package/dist/types/backend-federation-build/codegen.d.ts +86 -0
- package/dist/types/backend-federation-build/config.d.ts +103 -0
- package/dist/types/backend-federation-build/emit.d.ts +21 -0
- package/dist/types/backend-federation-build/index.d.ts +2 -0
- package/dist/types/build-config/build-environment.d.ts +22 -0
- package/dist/types/build-config/precompress/plugin.d.ts +4 -0
- package/dist/types/build-config/precompress/types.d.ts +19 -0
- package/dist/types/build-config/public.d.ts +2 -0
- package/dist/types/cloudflare/constants.d.ts +1 -1
- package/dist/types/cloudflare/delivery-unit.d.ts +1 -1
- package/dist/types/cloudflare/worker-manifest.d.ts +2 -2
- package/dist/types/cloudflare-output-contract.d.ts +2 -1
- package/dist/types/cloudflare-output-verifier/identity.d.ts +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/deploy-output/npmAliases.d.ts +14 -0
- package/dist/types/deploy-output/plugin.d.ts +15 -0
- package/dist/types/deploy-output/target.d.ts +6 -0
- package/dist/types/native-type-checker.d.ts +15 -0
- package/dist/types/precompress/LICENSE +20 -0
- package/dist/types/precompress/index.d.ts +76 -0
- package/package.json +55 -8
- package/src/backend-federation-build/codegen.ts +245 -0
- package/src/backend-federation-build/config.ts +376 -0
- package/src/backend-federation-build/emit.ts +205 -0
- package/src/backend-federation-build/index.ts +2 -0
- package/src/build-config/build-environment.ts +404 -0
- package/src/build-config/precompress/plugin.ts +140 -0
- package/src/build-config/precompress/types.ts +26 -0
- package/src/build-config/public.ts +6 -0
- package/src/cloudflare/constants.ts +1 -1
- package/src/cloudflare/delivery-unit.ts +2 -2
- package/src/cloudflare/worker-manifest.ts +1 -0
- package/src/cloudflare-builder.ts +1 -0
- package/src/cloudflare-output-contract.ts +37 -0
- package/src/cloudflare-output-verifier/identity.ts +1 -1
- package/src/cloudflare-output-verifier/worker-bundles.ts +5 -3
- package/src/config.ts +7 -0
- package/src/deploy-output/npmAliases.ts +333 -0
- package/src/deploy-output/plugin.ts +49 -0
- package/src/deploy-output/target.ts +23 -0
- package/src/native-type-checker.ts +122 -0
- package/src/release-envelope/framework-output.ts +1 -1
- package/src/release-envelope/plugin.ts +5 -1
- package/src/release-identity.ts +3 -2
|
@@ -53,7 +53,7 @@ const promises_namespaceObject = require("node:fs/promises");
|
|
|
53
53
|
var promises_default = /*#__PURE__*/ __webpack_require__.n(promises_namespaceObject);
|
|
54
54
|
const external_node_path_namespaceObject = require("node:path");
|
|
55
55
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
56
|
-
const
|
|
56
|
+
const backend_federation_contracts_namespaceObject = require("@modern-js/backend-federation-contracts");
|
|
57
57
|
const external_index_js_namespaceObject = require("./index.js");
|
|
58
58
|
const MICROVERTICAL_RELEASE_ENVELOPE_PATH = 'release/microvertical-release-envelope.json';
|
|
59
59
|
const MICROVERTICAL_RELEASE_IDENTITY_CARRIERS_PATH = 'release/microvertical-release-identity-carriers.json';
|
|
@@ -176,9 +176,9 @@ const writeReleaseEnvelope = async (artifactRoot, envelope)=>{
|
|
|
176
176
|
await promises_default().writeFile(envelopePath, `${(0, external_index_js_namespaceObject.canonicalSerializeMicroVerticalReleaseEnvelope)(envelope)}\n`);
|
|
177
177
|
};
|
|
178
178
|
const readBuildArtifact = async (distDirectory)=>{
|
|
179
|
-
const artifactPath = external_node_path_default().join(distDirectory,
|
|
179
|
+
const artifactPath = external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_FILE);
|
|
180
180
|
const artifact = await readJson(artifactPath);
|
|
181
|
-
if (!(0,
|
|
181
|
+
if (!(0, backend_federation_contracts_namespaceObject.isUltramodernBuildArtifact)(artifact)) throw new Error(`[ultramodern-release-envelope] ${backend_federation_contracts_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_FILE} is missing or invalid.`);
|
|
182
182
|
if ('workspace' === artifact.deliveryUnit.sourceRevision) throw new Error('[ultramodern-release-envelope] sourceRevision "workspace" cannot produce a promotable full-stack envelope.');
|
|
183
183
|
return artifact;
|
|
184
184
|
};
|
|
@@ -195,7 +195,7 @@ const assertIdentityBlock = (value, identity, location, includeReleaseVersion)=>
|
|
|
195
195
|
for (const [field, expectedValue] of Object.entries(expected))if (value[field] !== expectedValue) throw new Error(`[ultramodern-release-envelope] ${location}.${field} must match ${expectedValue}; received ${String(value[field])}.`);
|
|
196
196
|
};
|
|
197
197
|
const readBackendManifest = async (distDirectory, identity)=>{
|
|
198
|
-
const manifest = await readJson(external_node_path_default().join(distDirectory,
|
|
198
|
+
const manifest = await readJson(external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE));
|
|
199
199
|
if (!isRecord(manifest) || !isRecord(manifest.backendFederation)) throw new Error('[ultramodern-release-envelope] backend federation manifest is missing backendFederation metadata.');
|
|
200
200
|
assertIdentityBlock(manifest.backendFederation.deliveryUnit, identity, 'backendFederation.deliveryUnit', true);
|
|
201
201
|
const versionBoundary = manifest.backendFederation.versionBoundary;
|
|
@@ -324,10 +324,10 @@ const createReleaseArtifactInputs = async (distDirectory, identity, target)=>{
|
|
|
324
324
|
add(ssrPaths, 'node' === target ? 'nodejs' : 'workerd');
|
|
325
325
|
add(apiBackendPaths, 'node' === target ? 'nodejs' : 'workerd-effect');
|
|
326
326
|
add([
|
|
327
|
-
|
|
327
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE
|
|
328
328
|
], 'module-federation-manifest');
|
|
329
329
|
add([
|
|
330
|
-
|
|
330
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
331
331
|
], 'node' === target ? 'nodejs' : 'commonjs-module');
|
|
332
332
|
const surfaces = {
|
|
333
333
|
uiClient: [
|
|
@@ -340,8 +340,8 @@ const createReleaseArtifactInputs = async (distDirectory, identity, target)=>{
|
|
|
340
340
|
...apiBackendPaths
|
|
341
341
|
].sort((left, right)=>left.localeCompare(right)),
|
|
342
342
|
backendFederation: {
|
|
343
|
-
manifest:
|
|
344
|
-
container:
|
|
343
|
+
manifest: backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
344
|
+
container: backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
const artifacts = [
|
|
@@ -350,8 +350,8 @@ const createReleaseArtifactInputs = async (distDirectory, identity, target)=>{
|
|
|
350
350
|
const identityCarrierMetadata = await writeReleaseIdentityCarrierMetadata(distDirectory, identity, {
|
|
351
351
|
apiBackend: apiBackendPaths,
|
|
352
352
|
backendFederation: [
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
354
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
355
355
|
],
|
|
356
356
|
ssr: [
|
|
357
357
|
...new Set([
|
|
@@ -379,8 +379,8 @@ const pathExists = async (filePath)=>{
|
|
|
379
379
|
};
|
|
380
380
|
const emitFrameworkMicroVerticalReleaseEnvelope = async ({ apiOnly, distDirectory, target })=>{
|
|
381
381
|
if (apiOnly) return;
|
|
382
|
-
const backendManifestPath = external_node_path_default().join(distDirectory,
|
|
383
|
-
const backendContainerPath = external_node_path_default().join(distDirectory,
|
|
382
|
+
const backendManifestPath = external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE);
|
|
383
|
+
const backendContainerPath = external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE);
|
|
384
384
|
const [hasBackendManifest, hasBackendContainer] = await Promise.all([
|
|
385
385
|
pathExists(backendManifestPath),
|
|
386
386
|
pathExists(backendContainerPath)
|
|
@@ -428,9 +428,9 @@ const readFrameworkMicroVerticalReleaseEnvelope = async ({ artifactRoot, expecte
|
|
|
428
428
|
const verifyBuildOutputReleaseEnvelope = async (distDirectory, expectedTarget)=>{
|
|
429
429
|
const [hasEnvelope, hasBuildArtifact, hasBackendManifest, hasBackendEntry] = await Promise.all([
|
|
430
430
|
pathExists(external_node_path_default().join(distDirectory, MICROVERTICAL_RELEASE_ENVELOPE_PATH)),
|
|
431
|
-
pathExists(external_node_path_default().join(distDirectory,
|
|
432
|
-
pathExists(external_node_path_default().join(distDirectory,
|
|
433
|
-
pathExists(external_node_path_default().join(distDirectory,
|
|
431
|
+
pathExists(external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_FILE)),
|
|
432
|
+
pathExists(external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE)),
|
|
433
|
+
pathExists(external_node_path_default().join(distDirectory, backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE))
|
|
434
434
|
]);
|
|
435
435
|
const isFullStackMicroVertical = hasBuildArtifact && (hasBackendManifest || hasBackendEntry);
|
|
436
436
|
return readFrameworkMicroVerticalReleaseEnvelope({
|
|
@@ -451,12 +451,12 @@ const createNodeStagedReleaseArtifactInputs = async (outputDirectory, identity)=
|
|
|
451
451
|
for (const requiredPath of [
|
|
452
452
|
'index.js',
|
|
453
453
|
'package.json',
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
455
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
456
456
|
])if (!files.includes(requiredPath)) throw new Error(`[ultramodern-release-envelope] final Node staging is missing ${requiredPath}.`);
|
|
457
457
|
const backendFederationPaths = new Set([
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
459
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
460
460
|
]);
|
|
461
461
|
const uiClientPaths = files.filter((logicalPath)=>{
|
|
462
462
|
const topLevel = logicalPath.split('/')[0];
|
|
@@ -495,13 +495,13 @@ const createNodeStagedReleaseArtifactInputs = async (outputDirectory, identity)=
|
|
|
495
495
|
for (const logicalPath of uiClientPaths)runtimeByPath.set(logicalPath, 'browser');
|
|
496
496
|
for (const logicalPath of ssrPaths)runtimeByPath.set(logicalPath, 'nodejs');
|
|
497
497
|
for (const logicalPath of apiBackendPaths)runtimeByPath.set(logicalPath, 'nodejs');
|
|
498
|
-
runtimeByPath.set(
|
|
499
|
-
runtimeByPath.set(
|
|
498
|
+
runtimeByPath.set(backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE, 'module-federation-manifest');
|
|
499
|
+
runtimeByPath.set(backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE, 'nodejs');
|
|
500
500
|
const identityCarrierMetadata = await writeReleaseIdentityCarrierMetadata(outputDirectory, identity, {
|
|
501
501
|
apiBackend: apiBackendPaths,
|
|
502
502
|
backendFederation: [
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
504
|
+
backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
505
505
|
],
|
|
506
506
|
ssr: [
|
|
507
507
|
...new Set([
|
|
@@ -529,8 +529,8 @@ const createNodeStagedReleaseArtifactInputs = async (outputDirectory, identity)=
|
|
|
529
529
|
...apiBackendPaths
|
|
530
530
|
].sort((left, right)=>left.localeCompare(right)),
|
|
531
531
|
backendFederation: {
|
|
532
|
-
manifest:
|
|
533
|
-
container:
|
|
532
|
+
manifest: backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE,
|
|
533
|
+
container: backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
};
|
|
@@ -566,8 +566,8 @@ const createCloudflareStagedReleaseArtifactInputs = async (outputDirectory, iden
|
|
|
566
566
|
'worker/package.json'
|
|
567
567
|
])if (!files.includes(requiredPath)) throw new Error(`[ultramodern-release-envelope] final Cloudflare staging is missing ${requiredPath}.`);
|
|
568
568
|
if (files.some((logicalPath)=>'public/release' === logicalPath || logicalPath.startsWith('public/release/'))) throw new Error('[ultramodern-release-envelope] final Cloudflare envelope must remain private and cannot be staged under public/release.');
|
|
569
|
-
const backendManifestPath = `public/${
|
|
570
|
-
const backendContainerPath = `public/${
|
|
569
|
+
const backendManifestPath = `public/${backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE}`;
|
|
570
|
+
const backendContainerPath = `public/${backend_federation_contracts_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`;
|
|
571
571
|
const apiBackendPaths = files.filter((logicalPath)=>EFFECT_BFF_WORKER_PATTERN.test(logicalPath));
|
|
572
572
|
const ssrPaths = files.filter((logicalPath)=>(logicalPath.startsWith('server/') || logicalPath.startsWith('worker/')) && COMPILED_MODULE_PATTERN.test(logicalPath) && !EFFECT_BFF_WORKER_PATTERN.test(logicalPath));
|
|
573
573
|
const uiClientPaths = files.filter((logicalPath)=>logicalPath.startsWith('public/') && logicalPath !== backendManifestPath && logicalPath !== backendContainerPath);
|
|
@@ -52,7 +52,8 @@ const createUltramodernReleaseEnvelopePlugin = ({ resolveDeployTarget })=>({
|
|
|
52
52
|
name: '@modern-js/ultramodern-release-envelope',
|
|
53
53
|
pre: [
|
|
54
54
|
'@modern-js/backend-federation-build',
|
|
55
|
-
'@modern-js/plugin-bff'
|
|
55
|
+
'@modern-js/plugin-bff',
|
|
56
|
+
'@modern-js/deploy-output-aliases'
|
|
56
57
|
],
|
|
57
58
|
post: [
|
|
58
59
|
'@modern-js/plugin-deploy'
|
|
@@ -38,11 +38,8 @@ const BUILD_MARKER_NAMESPACE = 'ultramodern-delivery-unit-release-build-marker:v
|
|
|
38
38
|
const PROMOTABLE_SOURCE_REVISION_PATTERN = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u;
|
|
39
39
|
const gitOutput = (workspaceRoot, args)=>{
|
|
40
40
|
try {
|
|
41
|
-
return (0, external_node_child_process_namespaceObject.execFileSync)('git',
|
|
42
|
-
|
|
43
|
-
workspaceRoot,
|
|
44
|
-
...args
|
|
45
|
-
], {
|
|
41
|
+
return (0, external_node_child_process_namespaceObject.execFileSync)('git', args, {
|
|
42
|
+
cwd: workspaceRoot,
|
|
46
43
|
encoding: 'utf8',
|
|
47
44
|
stdio: [
|
|
48
45
|
'ignore',
|
|
@@ -77,7 +74,7 @@ const resolveUltramodernSourceRevision = (workspaceRoot = process.cwd(), configu
|
|
|
77
74
|
]);
|
|
78
75
|
const status = gitOutput(gitRoot, [
|
|
79
76
|
'status',
|
|
80
|
-
'--porcelain
|
|
77
|
+
'--porcelain',
|
|
81
78
|
'--untracked-files=all'
|
|
82
79
|
]);
|
|
83
80
|
if (!revision || void 0 === status || status.length > 0) return 'workspace';
|
|
@@ -0,0 +1,205 @@
|
|
|
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/backend-federation-contracts";
|
|
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 };
|
|
@@ -0,0 +1,128 @@
|
|
|
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/backend-federation-contracts";
|
|
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 };
|
|
@@ -0,0 +1,99 @@
|
|
|
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 { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, stampUltramodernBuildArtifactIdentity } from "@modern-js/backend-federation-contracts";
|
|
6
|
+
import { createBackendFederationEntryIntegrity } from "@modern-js/server-runtime-extensions/backend-federation-security/node";
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, emitBackendFederationArtifacts } from "./emit.mjs";
|