@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.
Files changed (86) hide show
  1. package/dist/cjs/builder/generator/index.js +0 -1
  2. package/dist/cjs/builder/shared/builderPlugins/index.js +4 -11
  3. package/dist/cjs/config/index.js +4 -11
  4. package/dist/cjs/index.js +80 -111
  5. package/dist/cjs/plugins/deploy/platforms/node.js +0 -13
  6. package/dist/cjs/plugins/serverBuild.js +2 -1
  7. package/dist/esm/builder/generator/index.mjs +1 -2
  8. package/dist/esm/builder/shared/builderPlugins/index.mjs +0 -1
  9. package/dist/esm/config/index.mjs +0 -1
  10. package/dist/esm/index.mjs +1 -6
  11. package/dist/esm/plugins/deploy/platforms/node.mjs +0 -13
  12. package/dist/esm/plugins/serverBuild.mjs +2 -1
  13. package/dist/esm-node/builder/generator/index.mjs +1 -2
  14. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +0 -1
  15. package/dist/esm-node/config/index.mjs +0 -1
  16. package/dist/esm-node/index.mjs +1 -6
  17. package/dist/esm-node/plugins/deploy/platforms/node.mjs +0 -13
  18. package/dist/esm-node/plugins/serverBuild.mjs +2 -1
  19. package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
  20. package/dist/types/config/index.d.ts +0 -1
  21. package/dist/types/index.d.ts +0 -1
  22. package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
  23. package/dist/types/types/config/output.d.ts +0 -9
  24. package/dist/types/types/index.d.ts +1 -1
  25. package/dist/types/types/plugin.d.ts +56 -2
  26. package/dist/types/utils/initAppContext.d.ts +3 -2
  27. package/docs/configure/app/bff/effect.md +27 -21
  28. package/docs/guides/advanced-features/bff/data-platform.md +2 -2
  29. package/docs/guides/advanced-features/bff/frameworks.md +27 -20
  30. package/docs/guides/advanced-features/bff/function.md +2 -2
  31. package/docs/guides/advanced-features/bff/operators.md +17 -17
  32. package/docs/guides/get-started/quick-start.md +1 -5
  33. package/docs/guides/get-started/ultramodern.md +1 -1
  34. package/docs/llms.txt +2 -2
  35. package/package.json +14 -30
  36. package/rslib.config.mts +0 -5
  37. package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +0 -125
  38. package/dist/cjs/config/build-environment.js +0 -268
  39. package/dist/cjs/config/public.js +0 -46
  40. package/dist/cjs/plugins/backend-federation/codegen.js +0 -256
  41. package/dist/cjs/plugins/backend-federation/config.js +0 -204
  42. package/dist/cjs/plugins/backend-federation/emit.js +0 -150
  43. package/dist/cjs/plugins/backendFederationBuild.js +0 -53
  44. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +0 -62
  45. package/dist/cjs/plugins/deploy/utils/npmAliases.js +0 -226
  46. package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +0 -44
  47. package/dist/cjs/presetUltramodern.js +0 -175
  48. package/dist/cjs/types/config/precompress.js +0 -18
  49. package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -77
  50. package/dist/esm/config/build-environment.mjs +0 -224
  51. package/dist/esm/config/public.mjs +0 -1
  52. package/dist/esm/plugins/backend-federation/codegen.mjs +0 -205
  53. package/dist/esm/plugins/backend-federation/config.mjs +0 -128
  54. package/dist/esm/plugins/backend-federation/emit.mjs +0 -99
  55. package/dist/esm/plugins/backendFederationBuild.mjs +0 -1
  56. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -1
  57. package/dist/esm/plugins/deploy/utils/npmAliases.mjs +0 -174
  58. package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +0 -6
  59. package/dist/esm/presetUltramodern.mjs +0 -119
  60. package/dist/esm/types/config/precompress.mjs +0 -0
  61. package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -78
  62. package/dist/esm-node/config/build-environment.mjs +0 -225
  63. package/dist/esm-node/config/public.mjs +0 -2
  64. package/dist/esm-node/plugins/backend-federation/codegen.mjs +0 -206
  65. package/dist/esm-node/plugins/backend-federation/config.mjs +0 -129
  66. package/dist/esm-node/plugins/backend-federation/emit.mjs +0 -100
  67. package/dist/esm-node/plugins/backendFederationBuild.mjs +0 -2
  68. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -2
  69. package/dist/esm-node/plugins/deploy/utils/npmAliases.mjs +0 -175
  70. package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +0 -7
  71. package/dist/esm-node/presetUltramodern.mjs +0 -120
  72. package/dist/esm-node/types/config/precompress.mjs +0 -1
  73. package/dist/types/builder/shared/builderPlugins/adapterPrecompress.d.ts +0 -3
  74. package/dist/types/config/build-environment.d.ts +0 -22
  75. package/dist/types/config/public.d.ts +0 -2
  76. package/dist/types/plugins/backend-federation/codegen.d.ts +0 -86
  77. package/dist/types/plugins/backend-federation/config.d.ts +0 -103
  78. package/dist/types/plugins/backend-federation/emit.d.ts +0 -13
  79. package/dist/types/plugins/backendFederationBuild.d.ts +0 -2
  80. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +0 -1
  81. package/dist/types/plugins/deploy/utils/npmAliases.d.ts +0 -14
  82. package/dist/types/plugins/ultramodernReleaseEnvelope.d.ts +0 -3
  83. package/dist/types/precompress/LICENSE +0 -20
  84. package/dist/types/precompress/index.d.ts +0 -76
  85. package/dist/types/presetUltramodern.d.ts +0 -87
  86. package/dist/types/types/config/precompress.d.ts +0 -19
@@ -1,206 +0,0 @@
1
- import "node:module";
2
- import node_path from "node:path";
3
- 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";
4
- import { build } from "esbuild";
5
- import { normalizeRelativePath } from "./config.mjs";
6
- const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
7
- const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
8
- return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
9
- };
10
- const createPublicPath = (containerEntry, fallbackPort)=>{
11
- try {
12
- return new URL('.', containerEntry).href;
13
- } catch {
14
- const slashIndex = containerEntry.lastIndexOf('/');
15
- if (slashIndex >= 0) return containerEntry.slice(0, slashIndex + 1);
16
- return `http://localhost:${fallbackPort}/`;
17
- }
18
- };
19
- const createBackendRemoteEntrySource = async (workspaceRoot, app, effectApiPath, entryPath)=>{
20
- const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(effectApiPath), effectApiPath);
21
- const containerMetadata = {
22
- buildVersion: app.buildVersion,
23
- expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
24
- name: app.backendName,
25
- packageName: app.packageName,
26
- remoteType: app.remoteType,
27
- source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
28
- version: app.version,
29
- ...app.unitId ? {
30
- unitId: app.unitId
31
- } : {},
32
- ...app.sourceRevision ? {
33
- sourceRevision: app.sourceRevision
34
- } : {}
35
- };
36
- const compatibility = {
37
- build: app.buildVersion,
38
- contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
39
- nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
40
- packageName: app.packageName,
41
- ...app.unitId ? {
42
- unitId: app.unitId
43
- } : {},
44
- ...app.sourceRevision ? {
45
- sourceRevision: app.sourceRevision
46
- } : {}
47
- };
48
- const source = `// Generated by Modern.js backend federation build.
49
- import * as exposedNamespace from ${JSON.stringify(effectApiSpecifier)};
50
-
51
- const exposedModule = {
52
- ...exposedNamespace,
53
- backendFederationContract: {
54
- ...(exposedNamespace.backendFederationContract ?? {}),
55
- compatibility: {
56
- ...(exposedNamespace.backendFederationContract?.compatibility ?? {}),
57
- ...${JSON.stringify(compatibility)},
58
- },
59
- name: ${JSON.stringify(app.backendName)},
60
- role: 'microvertical-server',
61
- runtimeFramework: 'effect',
62
- strictEffectApproach: true,
63
- },
64
- };
65
- const exposedModules = {
66
- ${JSON.stringify(BACKEND_FEDERATION_EFFECT_EXPOSE)}: () => Promise.resolve(exposedModule),
67
- };
68
- const __modernjsBackendFederation = ${JSON.stringify(containerMetadata)};
69
-
70
- function init() {}
71
-
72
- function get(id) {
73
- const load = exposedModules[id];
74
- if (!load) {
75
- throw new Error(\`Unexpected backend federation expose: \${id}\`);
76
- }
77
-
78
- return async () => load();
79
- }
80
-
81
- module.exports = { __modernjsBackendFederation, get, init };
82
- `;
83
- const result = await build({
84
- absWorkingDir: node_path.dirname(effectApiPath),
85
- bundle: true,
86
- format: 'cjs',
87
- logLevel: 'silent',
88
- platform: 'node',
89
- stdin: {
90
- contents: source,
91
- loader: 'ts',
92
- resolveDir: node_path.dirname(effectApiPath),
93
- sourcefile: node_path.basename(entryPath)
94
- },
95
- target: 'node20',
96
- write: false
97
- });
98
- const output = result.outputFiles[0];
99
- if (!output) throw new Error('[backend-federation-build] CommonJS backend federation container emitted no output.');
100
- return output.text;
101
- };
102
- const createBackendManifest = (workspaceRoot, distDirectory, app, entryIntegrity)=>{
103
- const sourceModule = `${app.directory}/api/effect-api.ts`;
104
- const publicPath = createPublicPath(app.containerEntry, app.port);
105
- const manifest = {
106
- schemaVersion: 1,
107
- id: app.backendName,
108
- name: app.backendName,
109
- version: app.version,
110
- buildVersion: app.buildVersion,
111
- metaData: {
112
- name: app.backendName,
113
- type: 'backend',
114
- buildInfo: {
115
- buildVersion: app.buildVersion,
116
- buildName: app.packageName
117
- },
118
- remoteEntry: {
119
- name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
120
- path: '',
121
- type: app.remoteType
122
- },
123
- globalName: app.backendName,
124
- publicPath,
125
- ssrRemoteEntry: {
126
- name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
127
- path: '',
128
- type: app.remoteType
129
- },
130
- ssrPublicPath: publicPath
131
- },
132
- entry: {
133
- ...entryIntegrity,
134
- file: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
135
- path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE))),
136
- type: app.remoteType,
137
- url: app.containerEntry
138
- },
139
- exposes: [
140
- {
141
- id: `${app.backendName}:${BACKEND_FEDERATION_EFFECT_EXPOSE}`,
142
- name: BACKEND_FEDERATION_EFFECT_EXPOSE,
143
- path: '',
144
- assets: {
145
- js: {
146
- async: [],
147
- sync: [
148
- BACKEND_FEDERATION_REMOTE_ENTRY_FILE
149
- ]
150
- },
151
- css: {
152
- async: [],
153
- sync: []
154
- }
155
- }
156
- }
157
- ],
158
- shared: [],
159
- backendFederation: {
160
- role: 'microvertical-server',
161
- appId: app.id,
162
- name: app.backendName,
163
- runtimeFramework: 'effect',
164
- strictEffectApproach: true,
165
- contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
166
- nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
167
- remoteType: app.remoteType,
168
- expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
169
- manifestUrl: app.manifestUrl,
170
- containerEntry: app.containerEntry,
171
- source: {
172
- module: sourceModule
173
- },
174
- readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
175
- openapiPath: `${app.apiPrefix}/openapi.json`,
176
- ...app.deliveryUnit ? {
177
- deliveryUnit: app.deliveryUnit
178
- } : {},
179
- versionBoundary: {
180
- invariant: 'web-and-api-same-build',
181
- packageName: app.packageName,
182
- version: app.version,
183
- buildVersion: app.buildVersion,
184
- ...app.uiManifestUrl ? {
185
- uiManifestUrl: app.uiManifestUrl
186
- } : {},
187
- ...app.deliveryUnit ? {
188
- deliveryUnit: {
189
- unitId: app.deliveryUnit.unitId,
190
- buildMarker: app.deliveryUnit.buildMarker,
191
- sourceRevision: app.deliveryUnit.sourceRevision
192
- }
193
- } : {}
194
- }
195
- }
196
- };
197
- const validation = validateBackendFederationManifest(manifest, {
198
- path: 'backendFederationManifest',
199
- requireEffectExpose: true,
200
- requireEffectRuntime: true,
201
- requireVersionFields: true
202
- });
203
- if (!validation.ok) throw new Error(`[backend-federation-build] Invalid backend federation manifest: ${formatBackendFederationValidationErrors(validation.errors)}.`);
204
- return manifest;
205
- };
206
- export { createBackendManifest, createBackendRemoteEntrySource };
@@ -1,129 +0,0 @@
1
- import "node:module";
2
- import { existsSync } from "node:fs";
3
- import promises from "node:fs/promises";
4
- import node_path from "node:path";
5
- import { resolveUltramodernSourceRevision } from "@modern-js/app-tools-extensions/release-identity";
6
- 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";
7
- const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
8
- const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
9
- const isRecord = (value)=>'object' == typeof value && null !== value;
10
- const readJsonFile = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf8'));
11
- const buildArtifactPathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_ARTIFACT_PATH);
12
- const buildModulePathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_MODULE_PATH);
13
- const readBuildIdentity = async (appDirectory)=>{
14
- const buildArtifactPath = buildArtifactPathFor(appDirectory);
15
- if (existsSync(buildArtifactPath)) {
16
- const artifact = await readJsonFile(buildArtifactPath);
17
- const artifactValidation = validateUltramodernBuildArtifact(artifact, buildArtifactPath);
18
- if (!artifactValidation.ok) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
19
- if (!isUltramodernBuildArtifact(artifact)) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
20
- const deliveryUnit = artifact.deliveryUnit;
21
- return {
22
- artifact,
23
- appId: deliveryUnit.appId,
24
- buildVersion: deliveryUnit.buildMarker,
25
- packageName: deliveryUnit.packageName,
26
- version: deliveryUnit.version,
27
- unitId: deliveryUnit.unitId,
28
- sourceRevision: deliveryUnit.sourceRevision
29
- };
30
- }
31
- const buildModulePath = buildModulePathFor(appDirectory);
32
- if (!existsSync(buildModulePath)) return {};
33
- console.warn(`[backend-federation-build] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ${ULTRAMODERN_BUILD_ARTIFACT_FILE}.`);
34
- const source = await promises.readFile(buildModulePath, 'utf8');
35
- return {
36
- appId: source.match(/\bappId:\s*['"]([^'"]+)['"]/u)?.[1],
37
- buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
38
- packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
39
- version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
40
- unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
41
- sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
42
- };
43
- };
44
- const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
45
- const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
46
- const createBackendName = (app, id)=>{
47
- const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
48
- if (configuredName) return configuredName;
49
- const mfName = stringValue(app.moduleFederation?.name);
50
- return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
51
- };
52
- const findWorkspaceRoot = (appDirectory)=>{
53
- let current = appDirectory;
54
- while(true){
55
- if (existsSync(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
56
- const parent = node_path.dirname(current);
57
- if (parent === current) return;
58
- current = parent;
59
- }
60
- };
61
- const resolveWorkspaceSourceRevision = async (workspaceRoot)=>resolveUltramodernSourceRevision(workspaceRoot);
62
- const createStampedDeliveryUnit = (input)=>{
63
- if (!input.unitId || !input.buildMarker || !input.packageName || !input.version) return;
64
- const record = {
65
- schemaVersion: DELIVERY_UNIT_SCHEMA_VERSION,
66
- kind: DELIVERY_UNIT_KIND,
67
- appId: input.appId,
68
- unitId: input.unitId,
69
- packageName: input.packageName,
70
- version: input.version,
71
- buildMarker: input.buildMarker,
72
- sourceRevision: input.sourceRevision,
73
- deployProfile: DELIVERY_UNIT_DEPLOY_PROFILE
74
- };
75
- const validation = validateDeliveryUnitRecord(record);
76
- if (!validation.ok) return;
77
- return deliveryUnitContractBlock(record);
78
- };
79
- const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
80
- const id = stringValue(compactApp.id);
81
- const appPath = stringValue(compactApp.path);
82
- if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
83
- const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
84
- if (node_path.resolve(workspaceRoot, directory) !== node_path.resolve(appDirectory)) return;
85
- const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
86
- if (void 0 === port) return;
87
- const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
88
- const apiStem = stringValue(compactApp.api.stem) ?? id;
89
- const backendName = createBackendName(compactApp, id);
90
- const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_FEDERATION_MANIFEST_FILE}`;
91
- const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`;
92
- const configuredRemoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType);
93
- 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}.`);
94
- 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}.`);
95
- const remoteType = 'commonjs-module';
96
- const packageName = stringValue(compactApp.package);
97
- const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
98
- const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
99
- unitId: stringValue(compactApp.deliveryUnit.unitId),
100
- buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
101
- sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
102
- packageName: stringValue(compactApp.deliveryUnit.packageName),
103
- version: stringValue(compactApp.deliveryUnit.version)
104
- } : void 0;
105
- return {
106
- id,
107
- directory,
108
- packageName,
109
- port,
110
- apiPrefix,
111
- apiStem,
112
- backendName,
113
- manifestUrl,
114
- containerEntry,
115
- remoteType,
116
- uiManifestUrl,
117
- compactDeliveryUnit
118
- };
119
- };
120
- const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
121
- const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
122
- const compactConfig = await readJsonFile(compactConfigPath);
123
- const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
124
- for (const app of apps){
125
- const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
126
- if (resolved) return resolved;
127
- }
128
- };
129
- export { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createAppFromCompactMetadata, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, normalizeRelativePath, readBuildIdentity, resolveWorkspaceSourceRevision };
@@ -1,100 +0,0 @@
1
- import "node:module";
2
- import { existsSync } from "node:fs";
3
- import promises from "node:fs/promises";
4
- import node_path from "node:path";
5
- import { resolveUltramodernReleaseIdentity } from "@modern-js/app-tools-extensions/release-identity";
6
- import { createBackendFederationEntryIntegrity } from "@modern-js/server-runtime-extensions/backend-federation-security/node";
7
- import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, stampUltramodernBuildArtifactIdentity } from "@modern-js/utils/universal";
8
- import { createBackendManifest, createBackendRemoteEntrySource } from "./codegen.mjs";
9
- import { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, readBuildIdentity, resolveWorkspaceSourceRevision } from "./config.mjs";
10
- const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
11
- const workspaceRoot = findWorkspaceRoot(appDirectory);
12
- if (!workspaceRoot) return;
13
- const effectApiPath = node_path.join(appDirectory, 'api/effect-api.ts');
14
- const backendFederationConfigPath = node_path.join(appDirectory, 'backend-federation.config.ts');
15
- if (!existsSync(effectApiPath) || !existsSync(backendFederationConfigPath)) return;
16
- const app = await findBackendFederationApp(workspaceRoot, appDirectory);
17
- if (!app) return;
18
- const buildIdentity = await readBuildIdentity(appDirectory);
19
- const compactDeliveryUnit = app.compactDeliveryUnit;
20
- const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
21
- const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
22
- if (hasBuildIdentity) {
23
- const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
24
- const buildIdentityPath = existsSync(buildArtifactPathFor(appDirectory)) ? buildArtifactPathFor(appDirectory) : buildModulePathFor(appDirectory);
25
- const mismatches = [];
26
- const compare = (label, a, b, leftLabel = 'deliveryUnit')=>{
27
- if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: ${leftLabel}=${a} vs ultramodern-build=${b}`);
28
- };
29
- compare('appId', app.id, buildIdentity.appId, 'topology');
30
- if (hasCompactDeliveryUnit) {
31
- compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
32
- compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
33
- compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
34
- compare('version', compactDeliveryUnit?.version, buildIdentity.version);
35
- }
36
- if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (topology) and ${buildIdentityPath}: ${mismatches.join('; ')}`);
37
- }
38
- const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
39
- const generationBuildMarker = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
40
- const sourceRevision = await resolveWorkspaceSourceRevision(workspaceRoot);
41
- const buildVersion = generationBuildMarker && unitId ? resolveUltramodernReleaseIdentity({
42
- generationBuildMarker,
43
- unitId,
44
- workspaceRoot
45
- }).buildMarker : void 0;
46
- const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
47
- const version = compactDeliveryUnit?.version ?? buildIdentity.version;
48
- const deliveryUnit = createStampedDeliveryUnit({
49
- appId: app.id,
50
- unitId,
51
- buildMarker: buildVersion,
52
- packageName,
53
- version,
54
- sourceRevision
55
- });
56
- const stampedBuildArtifact = buildIdentity.artifact ? stampUltramodernBuildArtifactIdentity(buildIdentity.artifact, {
57
- buildMarker: buildVersion ?? buildIdentity.artifact.deliveryUnit.buildMarker,
58
- sourceRevision
59
- }) : void 0;
60
- const resolvedApp = {
61
- ...app,
62
- packageName,
63
- version,
64
- buildVersion,
65
- unitId,
66
- sourceRevision,
67
- deliveryUnit
68
- };
69
- const manifestPath = node_path.join(distDirectory, BACKEND_FEDERATION_MANIFEST_FILE);
70
- const entryPath = node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE);
71
- const deliveryUnitArtifactPath = stampedBuildArtifact ? node_path.join(distDirectory, ULTRAMODERN_BUILD_ARTIFACT_FILE) : void 0;
72
- const entrySource = await createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath);
73
- await promises.mkdir(distDirectory, {
74
- recursive: true
75
- });
76
- await promises.writeFile(entryPath, entrySource);
77
- await promises.writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp, createBackendFederationEntryIntegrity(entrySource)), null, 2)}\n`);
78
- if (stampedBuildArtifact && deliveryUnitArtifactPath) await promises.writeFile(deliveryUnitArtifactPath, `${JSON.stringify(stampedBuildArtifact, null, 2)}\n`);
79
- return {
80
- appId: resolvedApp.id,
81
- manifestPath,
82
- containerPath: entryPath,
83
- ...deliveryUnitArtifactPath ? {
84
- deliveryUnitArtifactPath
85
- } : {},
86
- remoteName: resolvedApp.backendName,
87
- remoteType: resolvedApp.remoteType
88
- };
89
- };
90
- const emit = ()=>({
91
- name: '@modern-js/backend-federation-build',
92
- setup (api) {
93
- api.onAfterBuild(async ()=>{
94
- const { appDirectory, distDirectory } = api.getAppContext();
95
- await emitBackendFederationArtifacts(appDirectory, distDirectory);
96
- });
97
- }
98
- });
99
- export default emit;
100
- export { emitBackendFederationArtifacts };
@@ -1,2 +0,0 @@
1
- import "node:module";
2
- export { default, emitBackendFederationArtifacts } from "./backend-federation/emit.mjs";
@@ -1,2 +0,0 @@
1
- import "node:module";
2
- export * from "@modern-js/app-tools-extensions/cloudflare-output-verifier";
@@ -1,175 +0,0 @@
1
- import "node:module";
2
- import promises from "node:fs/promises";
3
- import node_path from "node:path";
4
- const dependencyKeys = [
5
- 'dependencies',
6
- 'optionalDependencies'
7
- ];
8
- const exactVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;
9
- async function readPackageJson(filePath) {
10
- return JSON.parse(await promises.readFile(filePath, 'utf8'));
11
- }
12
- function parseNpmAlias(aliasName, specifier) {
13
- if (!specifier.startsWith('npm:')) return;
14
- const target = specifier.slice(4);
15
- const versionSeparator = target.lastIndexOf('@');
16
- if (versionSeparator <= 0 || versionSeparator === target.length - 1) throw new Error(`Invalid npm alias specifier for ${aliasName}: ${specifier}`);
17
- return {
18
- aliasName,
19
- targetName: target.slice(0, versionSeparator),
20
- targetVersion: target.slice(versionSeparator + 1)
21
- };
22
- }
23
- function aliasesFromPackageJson(packageJson) {
24
- const aliases = [];
25
- for (const dependencyKey of dependencyKeys)for (const [aliasName, specifier] of Object.entries(packageJson[dependencyKey] ?? {})){
26
- const alias = parseNpmAlias(aliasName, specifier);
27
- if (alias) aliases.push(alias);
28
- }
29
- return aliases;
30
- }
31
- async function collectPackageRecords(nodeModulesDirectory) {
32
- const records = [];
33
- const visitedNodeModules = new Set();
34
- const visitPackage = async (directory)=>{
35
- const packageJsonPath = node_path.join(directory, 'package.json');
36
- try {
37
- const packageJson = await readPackageJson(packageJsonPath);
38
- if (packageJson.name && packageJson.version) records.push({
39
- directory,
40
- packageJson
41
- });
42
- } catch (error) {
43
- if ('ENOENT' !== error.code) throw error;
44
- }
45
- await visitNodeModules(node_path.join(directory, 'node_modules'));
46
- };
47
- const visitScope = async (scopeDirectory)=>{
48
- const entries = await promises.readdir(scopeDirectory, {
49
- withFileTypes: true
50
- });
51
- for (const entry of entries)if (entry.isDirectory()) await visitPackage(node_path.join(scopeDirectory, entry.name));
52
- };
53
- const visitNdepeStore = async (storeDirectory)=>{
54
- const entries = await promises.readdir(storeDirectory, {
55
- withFileTypes: true
56
- });
57
- for (const entry of entries)if (entry.isDirectory()) {
58
- const entryPath = node_path.join(storeDirectory, entry.name);
59
- if (entry.name.startsWith('@')) await visitScope(entryPath);
60
- else await visitNodeModules(node_path.join(entryPath, 'node_modules'));
61
- }
62
- };
63
- const visitNodeModules = async (directory)=>{
64
- const resolvedDirectory = node_path.resolve(directory);
65
- if (visitedNodeModules.has(resolvedDirectory)) return;
66
- visitedNodeModules.add(resolvedDirectory);
67
- let entries;
68
- try {
69
- entries = await promises.readdir(directory, {
70
- withFileTypes: true
71
- });
72
- } catch (error) {
73
- if ('ENOENT' === error.code) return;
74
- throw error;
75
- }
76
- for (const entry of entries){
77
- if (!entry.isDirectory()) continue;
78
- const entryPath = node_path.join(directory, entry.name);
79
- if ('.ndepe' === entry.name) await visitNdepeStore(entryPath);
80
- else if (entry.name.startsWith('@')) await visitScope(entryPath);
81
- else await visitPackage(entryPath);
82
- }
83
- };
84
- await visitNodeModules(nodeModulesDirectory);
85
- return records;
86
- }
87
- async function resolveAliasTarget(ownerDirectory, alias, outputDirectory) {
88
- let directory = ownerDirectory;
89
- const outputRoot = node_path.resolve(outputDirectory);
90
- const resolvedOutputRoot = await promises.realpath(outputRoot);
91
- while(directory === outputRoot || directory.startsWith(`${outputRoot}${node_path.sep}`)){
92
- const candidate = node_path.join(directory, 'node_modules', alias.targetName);
93
- try {
94
- const resolvedCandidate = await promises.realpath(candidate);
95
- 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}`);
96
- const packageJson = await readPackageJson(node_path.join(candidate, 'package.json'));
97
- if (packageJson.name !== alias.targetName || !packageJson.version) throw new Error(`npm alias ${alias.aliasName} resolved ${candidate} to unexpected package ${String(packageJson.name)}`);
98
- if (exactVersionPattern.test(alias.targetVersion) && packageJson.version !== alias.targetVersion) return;
99
- return {
100
- directory: candidate,
101
- packageJson
102
- };
103
- } catch (error) {
104
- if ('ENOENT' !== error.code) throw error;
105
- }
106
- if (directory === outputRoot) break;
107
- directory = node_path.dirname(directory);
108
- }
109
- }
110
- async function ensureAliasLink(ownerDirectory, alias, target) {
111
- const aliasPath = node_path.join(ownerDirectory, 'node_modules', alias.aliasName);
112
- await promises.mkdir(node_path.dirname(aliasPath), {
113
- recursive: true
114
- });
115
- try {
116
- const [existing, expected] = await Promise.all([
117
- promises.realpath(aliasPath),
118
- promises.realpath(target.directory)
119
- ]);
120
- if (existing === expected) return;
121
- throw new Error(`Cannot preserve npm alias ${alias.aliasName}: ${aliasPath} already resolves to ${existing}, expected ${expected}`);
122
- } catch (error) {
123
- if ('ENOENT' !== error.code) throw error;
124
- }
125
- const linkTarget = node_path.relative(node_path.dirname(aliasPath), target.directory);
126
- await promises.symlink(linkTarget, aliasPath, 'dir');
127
- }
128
- function aliasSpecifier(alias) {
129
- return `npm:${alias.targetName}@${alias.targetVersion}`;
130
- }
131
- async function readPackageIdentity(entryPath) {
132
- let directory = node_path.dirname(entryPath);
133
- const root = node_path.parse(directory).root;
134
- while(directory !== root){
135
- try {
136
- const packageJson = await readPackageJson(node_path.join(directory, 'package.json'));
137
- if (packageJson.name && packageJson.version) return {
138
- name: packageJson.name,
139
- version: packageJson.version
140
- };
141
- } catch (error) {
142
- if ('ENOENT' !== error.code) throw error;
143
- }
144
- directory = node_path.dirname(directory);
145
- }
146
- throw new Error(`Cannot find owning package for deployment entry ${entryPath}`);
147
- }
148
- async function preserveNpmAliases({ appDirectory, outputDirectory, implicitAliases = [] }) {
149
- const records = await collectPackageRecords(node_path.join(outputDirectory, 'node_modules'));
150
- const appPackageJson = await readPackageJson(node_path.join(appDirectory, 'package.json'));
151
- const rootAliases = [
152
- ...aliasesFromPackageJson(appPackageJson),
153
- ...implicitAliases
154
- ].filter((alias)=>alias.aliasName !== alias.targetName);
155
- const emittedRootAliases = [];
156
- for (const alias of rootAliases){
157
- const target = await resolveAliasTarget(outputDirectory, alias, outputDirectory);
158
- if (!target) {
159
- if (implicitAliases.includes(alias)) throw new Error(`Cannot preserve implicit npm alias ${alias.aliasName}: emitted target ${alias.targetName}@${alias.targetVersion} is missing`);
160
- continue;
161
- }
162
- await ensureAliasLink(outputDirectory, alias, target);
163
- emittedRootAliases.push(alias);
164
- }
165
- for (const record of records)for (const alias of aliasesFromPackageJson(record.packageJson).filter((candidate)=>candidate.aliasName !== candidate.targetName)){
166
- const target = await resolveAliasTarget(record.directory, alias, outputDirectory);
167
- if (target) await ensureAliasLink(record.directory, alias, target);
168
- }
169
- const outputPackageJsonPath = node_path.join(outputDirectory, 'package.json');
170
- const outputPackageJson = await readPackageJson(outputPackageJsonPath);
171
- outputPackageJson.dependencies ??= {};
172
- for (const alias of emittedRootAliases)outputPackageJson.dependencies[alias.aliasName] = aliasSpecifier(alias);
173
- await promises.writeFile(outputPackageJsonPath, `${JSON.stringify(outputPackageJson, null, 2)}\n`);
174
- }
175
- export { preserveNpmAliases, readPackageIdentity };
@@ -1,7 +0,0 @@
1
- import "node:module";
2
- import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
3
- import { resolveDeployTarget } from "./deploy/index.mjs";
4
- const ultramodernReleaseEnvelope = ()=>createUltramodernReleaseEnvelopePlugin({
5
- resolveDeployTarget: resolveDeployTarget
6
- });
7
- export default ultramodernReleaseEnvelope;