@bleedingdev/modern-js-plugin-bff-extensions 3.9.3-ultramodern.1 → 3.9.3-ultramodern.2
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/effect-server/index.js +2 -1
- package/dist/cjs/effect-source-loader/loader.js +2 -0
- package/dist/cjs/server-global-vars/index.js +61 -0
- package/dist/esm/effect-server/index.mjs +2 -1
- package/dist/esm/effect-source-loader/loader.mjs +2 -0
- package/dist/esm/server-global-vars/index.mjs +23 -0
- package/dist/esm-node/effect-server/index.mjs +2 -1
- package/dist/esm-node/effect-source-loader/loader.mjs +2 -0
- package/dist/esm-node/server-global-vars/index.mjs +24 -0
- package/dist/types/effect-source-loader/http-api-runtime.d.ts +2 -0
- package/dist/types/effect-source-loader/loader.d.ts +3 -0
- package/dist/types/effect-source-loader/operation-contracts.d.ts +2 -0
- package/dist/types/server-global-vars/index.d.ts +11 -0
- package/package.json +22 -10
- package/src/effect-server/index.ts +1 -0
- package/src/effect-source-loader/http-api-runtime.ts +2 -0
- package/src/effect-source-loader/loader.ts +7 -0
- package/src/effect-source-loader/operation-contracts.ts +2 -0
- package/src/server-global-vars/index.ts +46 -0
|
@@ -90,7 +90,8 @@ const effect_server = ()=>({
|
|
|
90
90
|
try {
|
|
91
91
|
mod = await ((0, utils_namespaceObject.isProd)() ? (0, loader_js_namespaceObject.loadEffectBuiltModule)(entryFile) : (0, loader_js_namespaceObject.loadEffectSourceModule)({
|
|
92
92
|
resourcePath: entryFile,
|
|
93
|
-
appDir: appDirectory || external_node_path_default().dirname(entryFile)
|
|
93
|
+
appDir: appDirectory || external_node_path_default().dirname(entryFile),
|
|
94
|
+
globalVars: api.getServerConfig()?.source?.globalVars
|
|
94
95
|
}));
|
|
95
96
|
} catch (error) {
|
|
96
97
|
utils_namespaceObject.logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
@@ -50,6 +50,7 @@ const external_node_path_namespaceObject = require("node:path");
|
|
|
50
50
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
51
51
|
const external_node_url_namespaceObject = require("node:url");
|
|
52
52
|
const external_esbuild_namespaceObject = require("esbuild");
|
|
53
|
+
const index_js_namespaceObject = require("../server-global-vars/index.js");
|
|
53
54
|
const NODE_TARGET = 'node26.10';
|
|
54
55
|
const SOURCE_LOADERS = new Map([
|
|
55
56
|
[
|
|
@@ -285,6 +286,7 @@ async function loadEffectSourceModule(options) {
|
|
|
285
286
|
js: `import { createRequire as __modernCreateEffectRequire } from 'node:module'; const require = __modernCreateEffectRequire(${JSON.stringify((0, external_node_url_namespaceObject.pathToFileURL)(resourcePath).href)});`
|
|
286
287
|
},
|
|
287
288
|
bundle: true,
|
|
289
|
+
define: (0, index_js_namespaceObject.serializeServerGlobalVars)(options.globalVars),
|
|
288
290
|
entryPoints: [
|
|
289
291
|
resourcePath
|
|
290
292
|
],
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
serializeServerGlobalVars: ()=>serializeServerGlobalVars
|
|
32
|
+
});
|
|
33
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
34
|
+
const serializeServerGlobalVars = (options)=>{
|
|
35
|
+
const globalVars = (0, utils_namespaceObject.applyOptionsChain)({}, options, {
|
|
36
|
+
env: 'server',
|
|
37
|
+
target: 'node'
|
|
38
|
+
});
|
|
39
|
+
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
40
|
+
let serialized;
|
|
41
|
+
try {
|
|
42
|
+
serialized = JSON.stringify(value);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`, {
|
|
45
|
+
cause: error
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`);
|
|
49
|
+
return [
|
|
50
|
+
key,
|
|
51
|
+
serialized
|
|
52
|
+
];
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
exports.serializeServerGlobalVars = __webpack_exports__.serializeServerGlobalVars;
|
|
56
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
57
|
+
"serializeServerGlobalVars"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
|
@@ -48,7 +48,8 @@ const effect_server = ()=>({
|
|
|
48
48
|
try {
|
|
49
49
|
mod = await (isProd() ? loadEffectBuiltModule(entryFile) : loadEffectSourceModule({
|
|
50
50
|
resourcePath: entryFile,
|
|
51
|
-
appDir: appDirectory || node_path.dirname(entryFile)
|
|
51
|
+
appDir: appDirectory || node_path.dirname(entryFile),
|
|
52
|
+
globalVars: api.getServerConfig()?.source?.globalVars
|
|
52
53
|
}));
|
|
53
54
|
} catch (error) {
|
|
54
55
|
logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
@@ -4,6 +4,7 @@ import { builtinModules, createRequire } from "node:module";
|
|
|
4
4
|
import node_path from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { build, transform } from "esbuild";
|
|
7
|
+
import { serializeServerGlobalVars } from "../server-global-vars/index.mjs";
|
|
7
8
|
const NODE_TARGET = 'node26.10';
|
|
8
9
|
const SOURCE_LOADERS = new Map([
|
|
9
10
|
[
|
|
@@ -239,6 +240,7 @@ async function loadEffectSourceModule(options) {
|
|
|
239
240
|
js: `import { createRequire as __modernCreateEffectRequire } from 'node:module'; const require = __modernCreateEffectRequire(${JSON.stringify(pathToFileURL(resourcePath).href)});`
|
|
240
241
|
},
|
|
241
242
|
bundle: true,
|
|
243
|
+
define: serializeServerGlobalVars(options.globalVars),
|
|
242
244
|
entryPoints: [
|
|
243
245
|
resourcePath
|
|
244
246
|
],
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
2
|
+
const serializeServerGlobalVars = (options)=>{
|
|
3
|
+
const globalVars = applyOptionsChain({}, options, {
|
|
4
|
+
env: 'server',
|
|
5
|
+
target: 'node'
|
|
6
|
+
});
|
|
7
|
+
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
8
|
+
let serialized;
|
|
9
|
+
try {
|
|
10
|
+
serialized = JSON.stringify(value);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`, {
|
|
13
|
+
cause: error
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`);
|
|
17
|
+
return [
|
|
18
|
+
key,
|
|
19
|
+
serialized
|
|
20
|
+
];
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
export { serializeServerGlobalVars };
|
|
@@ -49,7 +49,8 @@ const effect_server = ()=>({
|
|
|
49
49
|
try {
|
|
50
50
|
mod = await (isProd() ? loadEffectBuiltModule(entryFile) : loadEffectSourceModule({
|
|
51
51
|
resourcePath: entryFile,
|
|
52
|
-
appDir: appDirectory || node_path.dirname(entryFile)
|
|
52
|
+
appDir: appDirectory || node_path.dirname(entryFile),
|
|
53
|
+
globalVars: api.getServerConfig()?.source?.globalVars
|
|
53
54
|
}));
|
|
54
55
|
} catch (error) {
|
|
55
56
|
logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
@@ -5,6 +5,7 @@ import { builtinModules, createRequire } from "node:module";
|
|
|
5
5
|
import node_path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import { build, transform } from "esbuild";
|
|
8
|
+
import { serializeServerGlobalVars } from "../server-global-vars/index.mjs";
|
|
8
9
|
const NODE_TARGET = 'node26.10';
|
|
9
10
|
const SOURCE_LOADERS = new Map([
|
|
10
11
|
[
|
|
@@ -240,6 +241,7 @@ async function loadEffectSourceModule(options) {
|
|
|
240
241
|
js: `import { createRequire as __modernCreateEffectRequire } from 'node:module'; const require = __modernCreateEffectRequire(${JSON.stringify(pathToFileURL(resourcePath).href)});`
|
|
241
242
|
},
|
|
242
243
|
bundle: true,
|
|
244
|
+
define: serializeServerGlobalVars(options.globalVars),
|
|
243
245
|
entryPoints: [
|
|
244
246
|
resourcePath
|
|
245
247
|
],
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
3
|
+
const serializeServerGlobalVars = (options)=>{
|
|
4
|
+
const globalVars = applyOptionsChain({}, options, {
|
|
5
|
+
env: 'server',
|
|
6
|
+
target: 'node'
|
|
7
|
+
});
|
|
8
|
+
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
9
|
+
let serialized;
|
|
10
|
+
try {
|
|
11
|
+
serialized = JSON.stringify(value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`, {
|
|
14
|
+
cause: error
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`);
|
|
18
|
+
return [
|
|
19
|
+
key,
|
|
20
|
+
serialized
|
|
21
|
+
];
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
export { serializeServerGlobalVars };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HttpApiLike, type HttpApiReflect } from '@modern-js/bff-effect/effect';
|
|
2
|
+
import type { ServerGlobalVarsOptions } from '../server-global-vars/index.js';
|
|
2
3
|
type HttpApiRuntime = {
|
|
3
4
|
isHttpApi: (value: unknown) => boolean;
|
|
4
5
|
reflect: HttpApiReflect;
|
|
@@ -7,6 +8,7 @@ export declare function getHttpApiRuntime(): Promise<HttpApiRuntime>;
|
|
|
7
8
|
export declare function loadEffectApi(options: {
|
|
8
9
|
appDir: string;
|
|
9
10
|
resourcePath: string;
|
|
11
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
10
12
|
onDependency?: (dependency: string) => void;
|
|
11
13
|
}): Promise<HttpApiLike | null>;
|
|
12
14
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { type ServerGlobalVarsOptions } from '../server-global-vars/index.js';
|
|
1
2
|
export type EffectSourceLoaderOptions = {
|
|
2
3
|
resourcePath: string;
|
|
3
4
|
appDir?: string;
|
|
5
|
+
/** `source.globalVars`, replaced in the loaded source graph. */
|
|
6
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
4
7
|
onDependency?: (dependency: string) => void;
|
|
5
8
|
};
|
|
6
9
|
export declare function bundleEffectEntryForNode(options: {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { ServerGlobalVarsOptions } from '../server-global-vars/index.js';
|
|
1
2
|
/** Derives server policy metadata without emitting or typing a client. */
|
|
2
3
|
export declare function resolveEffectOperationContracts(options: {
|
|
3
4
|
appDir: string;
|
|
4
5
|
resourcePath: string;
|
|
5
6
|
prefix: string;
|
|
6
7
|
requestId?: string;
|
|
8
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
7
9
|
onDependency?: (dependency: string) => void;
|
|
8
10
|
}): Promise<import("@modern-js/server-runtime-extensions/bff-policy/node").OperationContractMap | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ServerSourceConfigExtension } from '@modern-js/runtime-extensions/server-config';
|
|
2
|
+
export type ServerGlobalVarsOptions = ServerSourceConfigExtension['globalVars'];
|
|
3
|
+
/** Each global name mapped to the JSON source text that replaces it. */
|
|
4
|
+
export type SerializedServerGlobalVars = Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves `source.globalVars` for BFF server code and serializes every value
|
|
7
|
+
* to the JSON text that replaces it. Dev source loading and build output use
|
|
8
|
+
* this one function, so both see the same values. A value without an exact
|
|
9
|
+
* JSON form (such as `undefined`, a function or a BigInt) is rejected.
|
|
10
|
+
*/
|
|
11
|
+
export declare const serializeServerGlobalVars: (options: ServerGlobalVarsOptions) => SerializedServerGlobalVars;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"modern.js",
|
|
19
19
|
"ultramodern.js"
|
|
20
20
|
],
|
|
21
|
-
"version": "3.9.3-ultramodern.
|
|
21
|
+
"version": "3.9.3-ultramodern.2",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
24
|
"src"
|
|
@@ -66,6 +66,14 @@
|
|
|
66
66
|
},
|
|
67
67
|
"default": "./dist/cjs/effect-source-loader/index.js"
|
|
68
68
|
},
|
|
69
|
+
"./server-global-vars": {
|
|
70
|
+
"types": "./dist/types/server-global-vars/index.d.ts",
|
|
71
|
+
"node": {
|
|
72
|
+
"import": "./dist/esm-node/server-global-vars/index.mjs",
|
|
73
|
+
"require": "./dist/cjs/server-global-vars/index.js"
|
|
74
|
+
},
|
|
75
|
+
"default": "./dist/cjs/server-global-vars/index.js"
|
|
76
|
+
},
|
|
69
77
|
"./backend-federation": {
|
|
70
78
|
"types": "./dist/types/backend-federation/index.d.ts",
|
|
71
79
|
"node": {
|
|
@@ -155,6 +163,10 @@
|
|
|
155
163
|
"./dist/types/effect-source-loader/index.d.ts",
|
|
156
164
|
"./src/effect-source-loader/index.ts"
|
|
157
165
|
],
|
|
166
|
+
"server-global-vars": [
|
|
167
|
+
"./dist/types/server-global-vars/index.d.ts",
|
|
168
|
+
"./src/server-global-vars/index.ts"
|
|
169
|
+
],
|
|
158
170
|
"backend-federation": [
|
|
159
171
|
"./dist/types/backend-federation/index.d.ts",
|
|
160
172
|
"./src/backend-federation/index.ts"
|
|
@@ -193,14 +205,14 @@
|
|
|
193
205
|
"node": ">=26.10.0"
|
|
194
206
|
},
|
|
195
207
|
"dependencies": {
|
|
196
|
-
"@modern-js/backend-federation-contracts": "npm:@bleedingdev/modern-js-backend-federation-contracts@3.9.3-ultramodern.
|
|
197
|
-
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.
|
|
198
|
-
"@modern-js/bff-effect": "npm:@bleedingdev/modern-js-bff-effect@3.9.3-ultramodern.
|
|
199
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.
|
|
200
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.3-ultramodern.
|
|
201
|
-
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.
|
|
202
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.
|
|
203
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.
|
|
208
|
+
"@modern-js/backend-federation-contracts": "npm:@bleedingdev/modern-js-backend-federation-contracts@3.9.3-ultramodern.2",
|
|
209
|
+
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.2",
|
|
210
|
+
"@modern-js/bff-effect": "npm:@bleedingdev/modern-js-bff-effect@3.9.3-ultramodern.2",
|
|
211
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.2",
|
|
212
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.3-ultramodern.2",
|
|
213
|
+
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.2",
|
|
214
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.2",
|
|
215
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.2",
|
|
204
216
|
"@module-federation/runtime": "2.9.2",
|
|
205
217
|
"@swc/core": "1.16.13",
|
|
206
218
|
"esbuild": "^0.28.2"
|
|
@@ -219,7 +231,7 @@
|
|
|
219
231
|
},
|
|
220
232
|
"devDependencies": {
|
|
221
233
|
"@effect/opentelemetry": "4.0.0",
|
|
222
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.
|
|
234
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.2",
|
|
223
235
|
"@rsbuild/core": "2.2.11",
|
|
224
236
|
"@rslib/core": "1.0.3",
|
|
225
237
|
"@scripts/rstest-config": "2.66.0",
|
|
@@ -78,6 +78,7 @@ export default (): ServerPlugin => ({
|
|
|
78
78
|
: loadEffectSourceModule({
|
|
79
79
|
resourcePath: entryFile,
|
|
80
80
|
appDir: appDirectory || path.dirname(entryFile),
|
|
81
|
+
globalVars: api.getServerConfig()?.source?.globalVars,
|
|
81
82
|
}))) as EffectApiModule;
|
|
82
83
|
} catch (error) {
|
|
83
84
|
logger.error(
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type HttpApiReflect,
|
|
5
5
|
} from '@modern-js/bff-effect/effect';
|
|
6
6
|
import { HttpApi } from 'effect/http-api';
|
|
7
|
+
import type { ServerGlobalVarsOptions } from '../server-global-vars';
|
|
7
8
|
import { loadEffectSourceModule } from './loader';
|
|
8
9
|
|
|
9
10
|
type HttpApiRuntime = {
|
|
@@ -29,6 +30,7 @@ export function getHttpApiRuntime(): Promise<HttpApiRuntime> {
|
|
|
29
30
|
export function loadEffectApi(options: {
|
|
30
31
|
appDir: string;
|
|
31
32
|
resourcePath: string;
|
|
33
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
32
34
|
onDependency?: (dependency: string) => void;
|
|
33
35
|
}): Promise<HttpApiLike | null> {
|
|
34
36
|
return getHttpApiRuntime().then(httpApiRuntime =>
|
|
@@ -12,6 +12,10 @@ import {
|
|
|
12
12
|
type Plugin,
|
|
13
13
|
transform,
|
|
14
14
|
} from 'esbuild';
|
|
15
|
+
import {
|
|
16
|
+
type ServerGlobalVarsOptions,
|
|
17
|
+
serializeServerGlobalVars,
|
|
18
|
+
} from '../server-global-vars';
|
|
15
19
|
|
|
16
20
|
const NODE_TARGET = 'node26.10';
|
|
17
21
|
const SOURCE_LOADERS = new Map<string, Loader>([
|
|
@@ -28,6 +32,8 @@ const SOURCE_LOADERS = new Map<string, Loader>([
|
|
|
28
32
|
export type EffectSourceLoaderOptions = {
|
|
29
33
|
resourcePath: string;
|
|
30
34
|
appDir?: string;
|
|
35
|
+
/** `source.globalVars`, replaced in the loaded source graph. */
|
|
36
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
31
37
|
onDependency?: (dependency: string) => void;
|
|
32
38
|
};
|
|
33
39
|
|
|
@@ -352,6 +358,7 @@ export async function loadEffectSourceModule(
|
|
|
352
358
|
js: `import { createRequire as __modernCreateEffectRequire } from 'node:module'; const require = __modernCreateEffectRequire(${JSON.stringify(pathToFileURL(resourcePath).href)});`,
|
|
353
359
|
},
|
|
354
360
|
bundle: true,
|
|
361
|
+
define: serializeServerGlobalVars(options.globalVars),
|
|
355
362
|
entryPoints: [resourcePath],
|
|
356
363
|
format: 'esm',
|
|
357
364
|
jsx: 'automatic',
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
resolveOperationProducer,
|
|
8
8
|
} from '@modern-js/server-runtime-extensions/bff-policy/node';
|
|
9
9
|
import { upath as path } from '@modern-js/utils';
|
|
10
|
+
import type { ServerGlobalVarsOptions } from '../server-global-vars';
|
|
10
11
|
import { getHttpApiRuntime, loadEffectApi } from './http-api-runtime';
|
|
11
12
|
|
|
12
13
|
/** Derives server policy metadata without emitting or typing a client. */
|
|
@@ -15,6 +16,7 @@ export async function resolveEffectOperationContracts(options: {
|
|
|
15
16
|
resourcePath: string;
|
|
16
17
|
prefix: string;
|
|
17
18
|
requestId?: string;
|
|
19
|
+
globalVars?: ServerGlobalVarsOptions;
|
|
18
20
|
onDependency?: (dependency: string) => void;
|
|
19
21
|
}) {
|
|
20
22
|
const api = await loadEffectApi(options);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ServerGlobalVars,
|
|
3
|
+
ServerGlobalVarsContext,
|
|
4
|
+
ServerSourceConfigExtension,
|
|
5
|
+
} from '@modern-js/runtime-extensions/server-config';
|
|
6
|
+
import { applyOptionsChain } from '@modern-js/utils';
|
|
7
|
+
|
|
8
|
+
export type ServerGlobalVarsOptions = ServerSourceConfigExtension['globalVars'];
|
|
9
|
+
|
|
10
|
+
/** Each global name mapped to the JSON source text that replaces it. */
|
|
11
|
+
export type SerializedServerGlobalVars = Record<string, string>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolves `source.globalVars` for BFF server code and serializes every value
|
|
15
|
+
* to the JSON text that replaces it. Dev source loading and build output use
|
|
16
|
+
* this one function, so both see the same values. A value without an exact
|
|
17
|
+
* JSON form (such as `undefined`, a function or a BigInt) is rejected.
|
|
18
|
+
*/
|
|
19
|
+
export const serializeServerGlobalVars = (
|
|
20
|
+
options: ServerGlobalVarsOptions,
|
|
21
|
+
): SerializedServerGlobalVars => {
|
|
22
|
+
const globalVars = applyOptionsChain<
|
|
23
|
+
ServerGlobalVars,
|
|
24
|
+
ServerGlobalVarsContext
|
|
25
|
+
>({}, options, { env: 'server', target: 'node' });
|
|
26
|
+
|
|
27
|
+
return Object.fromEntries(
|
|
28
|
+
Object.entries(globalVars).map(([key, value]) => {
|
|
29
|
+
let serialized: string | undefined;
|
|
30
|
+
try {
|
|
31
|
+
serialized = JSON.stringify(value);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`,
|
|
35
|
+
{ cause: error },
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (serialized === undefined) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`source.globalVars["${key}"] cannot be serialized exactly for BFF server code.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return [key, serialized];
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
};
|