@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.4 → 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/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 +80 -111
- package/dist/cjs/plugins/deploy/platforms/node.js +0 -13
- package/dist/cjs/plugins/serverBuild.js +2 -1
- 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 +1 -6
- package/dist/esm/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm/plugins/serverBuild.mjs +2 -1
- 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 +1 -6
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm-node/plugins/serverBuild.mjs +2 -1
- 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 +0 -1
- package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
- 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/configure/app/bff/effect.md +27 -21
- package/docs/guides/advanced-features/bff/data-platform.md +2 -2
- package/docs/guides/advanced-features/bff/frameworks.md +27 -20
- package/docs/guides/advanced-features/bff/function.md +2 -2
- package/docs/guides/advanced-features/bff/operators.md +17 -17
- package/docs/guides/get-started/quick-start.md +1 -5
- package/docs/guides/get-started/ultramodern.md +1 -1
- package/docs/llms.txt +2 -2
- package/package.json +14 -30
- package/rslib.config.mts +0 -5
- 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/backendFederationBuild.js +0 -53
- 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 -175
- 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 -119
- 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 -120
- 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/precompress/LICENSE +0 -20
- package/dist/types/precompress/index.d.ts +0 -76
- package/dist/types/presetUltramodern.d.ts +0 -87
- package/dist/types/types/config/precompress.d.ts +0 -19
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { accessSync, chmodSync, constants, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
7
|
-
const EFFECT_TSGO_PACKAGE = '@effect/tsgo';
|
|
8
|
-
const EFFECT_TSGO_BIN = 'effect-tsgo';
|
|
9
|
-
const EFFECT_TSGO_RESOLUTION_ERROR = 'Unable to resolve the Effect TS-Go compiler. Install "@effect/tsgo" and a native TypeScript backend for this build config, or set EFFECT_TSGO_BIN.';
|
|
10
|
-
const executableEffectTsgoCompilers = new Map();
|
|
11
|
-
const BUILD_CONFIG_ENVIRONMENT_PLUGIN = 'ModernJsBuildConfigEnvironmentLeasePlugin';
|
|
12
|
-
const ENVIRONMENT_LEASE_REGISTRY_KEY = Symbol.for('@modern-js/app-tools/build-config-environment-lease-registry/v1');
|
|
13
|
-
const ENVIRONMENT_LEASE_REGISTRY_BRAND = Symbol.for('@modern-js/app-tools/build-config-environment-lease-registry-brand/v1');
|
|
14
|
-
const LIFECYCLE_HOOK_NAMES = [
|
|
15
|
-
'run',
|
|
16
|
-
'watchRun',
|
|
17
|
-
'afterDone',
|
|
18
|
-
'failed',
|
|
19
|
-
'shutdown',
|
|
20
|
-
'watchClose'
|
|
21
|
-
];
|
|
22
|
-
function restoreEnvironment(name, value) {
|
|
23
|
-
if (void 0 === value) delete process.env[name];
|
|
24
|
-
else process.env[name] = value;
|
|
25
|
-
}
|
|
26
|
-
function createEnvironmentLeaseRegistry() {
|
|
27
|
-
const environmentLeases = new Map();
|
|
28
|
-
return Object.freeze({
|
|
29
|
-
acquire (name, value) {
|
|
30
|
-
let lease = environmentLeases.get(name);
|
|
31
|
-
if (lease) {
|
|
32
|
-
if (lease.value !== value) throw new Error(`Build config environment "${name}" already has an active lease for a different value.`);
|
|
33
|
-
if (process.env[name] !== lease.value) throw new Error(`Build config environment lease for "${name}" lost ownership before another lease was acquired.`);
|
|
34
|
-
} else {
|
|
35
|
-
lease = {
|
|
36
|
-
originalValue: process.env[name],
|
|
37
|
-
owners: new Set(),
|
|
38
|
-
value
|
|
39
|
-
};
|
|
40
|
-
process.env[name] = value;
|
|
41
|
-
environmentLeases.set(name, lease);
|
|
42
|
-
}
|
|
43
|
-
const owner = Symbol(name);
|
|
44
|
-
lease.owners.add(owner);
|
|
45
|
-
let released = false;
|
|
46
|
-
return ()=>{
|
|
47
|
-
if (released) return;
|
|
48
|
-
if (environmentLeases.get(name) !== lease || !lease.owners.has(owner)) throw new Error(`Build config environment lease for "${name}" cannot be restored because its ownership record was lost.`);
|
|
49
|
-
released = true;
|
|
50
|
-
const lostOwnership = process.env[name] !== lease.value;
|
|
51
|
-
lease.owners.delete(owner);
|
|
52
|
-
if (0 === lease.owners.size) {
|
|
53
|
-
environmentLeases.delete(name);
|
|
54
|
-
restoreEnvironment(name, lease.originalValue);
|
|
55
|
-
} else if (lostOwnership) process.env[name] = lease.value;
|
|
56
|
-
if (lostOwnership) throw new Error(`Build config environment lease for "${name}" lost ownership before restoration.`);
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
brand: ENVIRONMENT_LEASE_REGISTRY_BRAND
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function getEnvironmentLeaseRegistry() {
|
|
63
|
-
const descriptor = Object.getOwnPropertyDescriptor(process, ENVIRONMENT_LEASE_REGISTRY_KEY);
|
|
64
|
-
if (descriptor) {
|
|
65
|
-
const registry = descriptor.value;
|
|
66
|
-
if (descriptor.configurable || descriptor.enumerable || descriptor.writable || registry?.brand !== ENVIRONMENT_LEASE_REGISTRY_BRAND || 'function' != typeof registry.acquire) throw new Error('The process-global build config environment lease registry is occupied by an incompatible value.');
|
|
67
|
-
return registry;
|
|
68
|
-
}
|
|
69
|
-
const registry = createEnvironmentLeaseRegistry();
|
|
70
|
-
Object.defineProperty(process, ENVIRONMENT_LEASE_REGISTRY_KEY, {
|
|
71
|
-
configurable: false,
|
|
72
|
-
enumerable: false,
|
|
73
|
-
value: registry,
|
|
74
|
-
writable: false
|
|
75
|
-
});
|
|
76
|
-
return registry;
|
|
77
|
-
}
|
|
78
|
-
function acquireEnvironmentLease(name, value) {
|
|
79
|
-
return getEnvironmentLeaseRegistry().acquire(name, value);
|
|
80
|
-
}
|
|
81
|
-
function releaseAfterFailure(release, originalError) {
|
|
82
|
-
try {
|
|
83
|
-
release();
|
|
84
|
-
} catch (restorationError) {
|
|
85
|
-
throw new AggregateError([
|
|
86
|
-
originalError,
|
|
87
|
-
restorationError
|
|
88
|
-
], 'Build config environment setup and restoration both failed.');
|
|
89
|
-
}
|
|
90
|
-
throw originalError;
|
|
91
|
-
}
|
|
92
|
-
class BuildConfigEnvironmentLeasePlugin {
|
|
93
|
-
apply(compiler) {
|
|
94
|
-
const hooks = compiler.hooks;
|
|
95
|
-
try {
|
|
96
|
-
const lifecycleHooks = {};
|
|
97
|
-
for (const hookName of LIFECYCLE_HOOK_NAMES){
|
|
98
|
-
const hook = hooks[hookName];
|
|
99
|
-
if (!hook || 'function' != typeof hook.tap) throw new Error(`Rspack does not expose the "${hookName}" lifecycle hook required to restore build config environment leases.`);
|
|
100
|
-
lifecycleHooks[hookName] = hook;
|
|
101
|
-
}
|
|
102
|
-
let mode = 'pending';
|
|
103
|
-
const modeTap = {
|
|
104
|
-
name: BUILD_CONFIG_ENVIRONMENT_PLUGIN,
|
|
105
|
-
stage: Number.MIN_SAFE_INTEGER
|
|
106
|
-
};
|
|
107
|
-
const releaseTap = {
|
|
108
|
-
name: BUILD_CONFIG_ENVIRONMENT_PLUGIN,
|
|
109
|
-
stage: Number.MAX_SAFE_INTEGER
|
|
110
|
-
};
|
|
111
|
-
const releaseAfterOneShot = ()=>{
|
|
112
|
-
if ('watch' !== mode && true !== compiler.watchMode) this.release();
|
|
113
|
-
};
|
|
114
|
-
lifecycleHooks.run.tap(modeTap, ()=>{
|
|
115
|
-
mode = 'run';
|
|
116
|
-
});
|
|
117
|
-
lifecycleHooks.watchRun.tap(modeTap, ()=>{
|
|
118
|
-
mode = 'watch';
|
|
119
|
-
});
|
|
120
|
-
lifecycleHooks.afterDone.tap(releaseTap, releaseAfterOneShot);
|
|
121
|
-
lifecycleHooks.failed.tap(releaseTap, releaseAfterOneShot);
|
|
122
|
-
lifecycleHooks.shutdown.tap(releaseTap, this.release);
|
|
123
|
-
lifecycleHooks.watchClose.tap(releaseTap, this.release);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
releaseAfterFailure(this.release, error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
constructor(release){
|
|
129
|
-
this.release = release;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function resolveEffectTsgoCli(from) {
|
|
133
|
-
const projectRequire = createRequire(from);
|
|
134
|
-
const packageJsonPath = projectRequire.resolve(`${EFFECT_TSGO_PACKAGE}/package.json`);
|
|
135
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
136
|
-
const bin = 'string' == typeof packageJson.bin ? packageJson.bin : packageJson.bin?.[EFFECT_TSGO_BIN];
|
|
137
|
-
if (!bin) throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
138
|
-
return resolve(dirname(packageJsonPath), bin);
|
|
139
|
-
}
|
|
140
|
-
function resolveExecutableEffectTsgoCompiler(compilerPath) {
|
|
141
|
-
if ('win32' === process.platform) return compilerPath;
|
|
142
|
-
const sourcePath = realpathSync(compilerPath);
|
|
143
|
-
const source = lstatSync(sourcePath);
|
|
144
|
-
if (!source.isFile()) throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
145
|
-
try {
|
|
146
|
-
accessSync(sourcePath, constants.X_OK);
|
|
147
|
-
return compilerPath;
|
|
148
|
-
} catch {}
|
|
149
|
-
const cachedCompiler = executableEffectTsgoCompilers.get(sourcePath);
|
|
150
|
-
if (cachedCompiler) try {
|
|
151
|
-
accessSync(cachedCompiler, constants.X_OK);
|
|
152
|
-
return cachedCompiler;
|
|
153
|
-
} catch {
|
|
154
|
-
executableEffectTsgoCompilers.delete(sourcePath);
|
|
155
|
-
}
|
|
156
|
-
const compilerBytes = readFileSync(sourcePath);
|
|
157
|
-
const compilerDigest = createHash('sha256').update(compilerBytes).digest('hex');
|
|
158
|
-
const compilerDirectory = join(tmpdir(), 'modern-js', 'effect-tsgo', compilerDigest);
|
|
159
|
-
mkdirSync(compilerDirectory, {
|
|
160
|
-
recursive: true,
|
|
161
|
-
mode: 448
|
|
162
|
-
});
|
|
163
|
-
const executableCompiler = join(compilerDirectory, basename(sourcePath));
|
|
164
|
-
try {
|
|
165
|
-
accessSync(executableCompiler, constants.X_OK);
|
|
166
|
-
} catch {
|
|
167
|
-
const temporaryCompiler = join(compilerDirectory, `.${basename(sourcePath)}.${process.pid}.tmp`);
|
|
168
|
-
rmSync(temporaryCompiler, {
|
|
169
|
-
force: true
|
|
170
|
-
});
|
|
171
|
-
try {
|
|
172
|
-
writeFileSync(temporaryCompiler, compilerBytes, {
|
|
173
|
-
flag: 'wx',
|
|
174
|
-
mode: 448
|
|
175
|
-
});
|
|
176
|
-
chmodSync(temporaryCompiler, 448);
|
|
177
|
-
renameSync(temporaryCompiler, executableCompiler);
|
|
178
|
-
} finally{
|
|
179
|
-
rmSync(temporaryCompiler, {
|
|
180
|
-
force: true
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
accessSync(executableCompiler, constants.X_OK);
|
|
185
|
-
executableEffectTsgoCompilers.set(sourcePath, executableCompiler);
|
|
186
|
-
return executableCompiler;
|
|
187
|
-
}
|
|
188
|
-
function getBuildConfigEnvironment(name) {
|
|
189
|
-
return process.env[name];
|
|
190
|
-
}
|
|
191
|
-
function withBuildConfigEnvironment(name, value, setup) {
|
|
192
|
-
return async (config, ...args)=>{
|
|
193
|
-
const release = acquireEnvironmentLease(name, value);
|
|
194
|
-
try {
|
|
195
|
-
const configured = await setup(config, ...args) ?? config;
|
|
196
|
-
configured.plugins = [
|
|
197
|
-
...configured.plugins ?? [],
|
|
198
|
-
new BuildConfigEnvironmentLeasePlugin(release)
|
|
199
|
-
];
|
|
200
|
-
return configured;
|
|
201
|
-
} catch (error) {
|
|
202
|
-
releaseAfterFailure(release, error);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function resolveEffectTsgoCompiler(options) {
|
|
207
|
-
const configuredCompiler = getBuildConfigEnvironment('EFFECT_TSGO_BIN')?.trim();
|
|
208
|
-
if (configuredCompiler) try {
|
|
209
|
-
return resolveExecutableEffectTsgoCompiler(configuredCompiler);
|
|
210
|
-
} catch {
|
|
211
|
-
throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
const compiler = execFileSync(process.execPath, [
|
|
215
|
-
resolveEffectTsgoCli(options.from),
|
|
216
|
-
'get-exe-path'
|
|
217
|
-
], {
|
|
218
|
-
encoding: 'utf-8'
|
|
219
|
-
}).trim();
|
|
220
|
-
if (compiler) return resolveExecutableEffectTsgoCompiler(compiler);
|
|
221
|
-
} catch {}
|
|
222
|
-
throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
223
|
-
}
|
|
224
|
-
export { getBuildConfigEnvironment, resolveEffectTsgoCompiler, withBuildConfigEnvironment };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getBuildConfigEnvironment, resolveEffectTsgoCompiler, withBuildConfigEnvironment } from "./build-environment.mjs";
|
|
@@ -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";
|