@bleedingdev/modern-js-plugin-bff-build-extensions 3.9.3-ultramodern.1 → 3.9.3-ultramodern.11
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/client-artifacts.js +2 -1
- package/dist/cjs/compile.js +2 -1
- package/dist/cjs/server-global-vars.js +1 -25
- package/dist/esm/client-artifacts.mjs +2 -1
- package/dist/esm/compile.mjs +2 -1
- package/dist/esm/server-global-vars.mjs +3 -24
- package/dist/esm-node/client-artifacts.mjs +2 -1
- package/dist/esm-node/compile.mjs +2 -1
- package/dist/esm-node/server-global-vars.mjs +3 -24
- package/dist/types/server-global-vars.d.ts +2 -6
- package/package.json +24 -24
- package/src/client-artifacts.ts +1 -0
- package/src/compile.ts +5 -7
- package/src/server-global-vars.ts +5 -42
|
@@ -50,7 +50,8 @@ function registerBffClientArtifacts(api, metadata) {
|
|
|
50
50
|
appDir: generation.appDirectory,
|
|
51
51
|
resourcePath: sourceEffectEntry,
|
|
52
52
|
prefix: generation.prefix,
|
|
53
|
-
requestId: generation.requestId
|
|
53
|
+
requestId: generation.requestId,
|
|
54
|
+
globalVars: config.source.globalVars
|
|
54
55
|
});
|
|
55
56
|
if (null === operationContracts) throw new Error(`Cannot resolve exported Effect HttpApi in ${sourceEffectEntry}.`);
|
|
56
57
|
metadata.set(generation, {
|
package/dist/cjs/compile.js
CHANGED
|
@@ -30,11 +30,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
registerBffCompilation: ()=>registerBffCompilation
|
|
32
32
|
});
|
|
33
|
+
const server_global_vars_namespaceObject = require("@modern-js/plugin-bff-extensions/server-global-vars");
|
|
33
34
|
const external_server_global_vars_js_namespaceObject = require("./server-global-vars.js");
|
|
34
35
|
function registerBffCompilation(api) {
|
|
35
36
|
const serialized = new WeakMap();
|
|
36
37
|
api.onBeforeBffCompile((context)=>{
|
|
37
|
-
serialized.set(context, (0,
|
|
38
|
+
serialized.set(context, (0, server_global_vars_namespaceObject.serializeServerGlobalVars)(api.getNormalizedConfig().source.globalVars));
|
|
38
39
|
});
|
|
39
40
|
api.onAfterBffCompile(async (context)=>{
|
|
40
41
|
const globals = serialized.get(context);
|
|
@@ -28,7 +28,6 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
serializeServerGlobalVars: ()=>serializeServerGlobalVars,
|
|
32
31
|
transformServerGlobalVars: ()=>transformServerGlobalVars
|
|
33
32
|
});
|
|
34
33
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
@@ -46,32 +45,11 @@ const collectJavaScriptFiles = (directory)=>Promise.resolve().then(()=>utils_nam
|
|
|
46
45
|
absolutePath
|
|
47
46
|
] : [];
|
|
48
47
|
})).then((nested)=>nested.flat()));
|
|
49
|
-
const serializeServerGlobalVars = (options)=>{
|
|
50
|
-
const globalVars = (0, utils_namespaceObject.applyOptionsChain)({}, options, {
|
|
51
|
-
env: 'server',
|
|
52
|
-
target: 'node'
|
|
53
|
-
});
|
|
54
|
-
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
55
|
-
let serialized;
|
|
56
|
-
try {
|
|
57
|
-
serialized = JSON.stringify(value);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`, {
|
|
60
|
-
cause: error
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`);
|
|
64
|
-
return [
|
|
65
|
-
key,
|
|
66
|
-
serialized
|
|
67
|
-
];
|
|
68
|
-
}));
|
|
69
|
-
};
|
|
70
48
|
const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resolve().then(()=>{
|
|
71
49
|
if (0 === Object.keys(globalVars).length) return;
|
|
72
50
|
return Promise.all(outputDirectories.map((directory)=>utils_namespaceObject.fs.pathExists(directory).then((directoryExists)=>directoryExists ? directory : void 0))).then((existingDirectories)=>{
|
|
73
51
|
const filesPromise = Promise.all(existingDirectories.filter((directory)=>void 0 !== directory).map(collectJavaScriptFiles)).then((files)=>files.flat());
|
|
74
|
-
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)
|
|
52
|
+
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`${globalVars[name]};`).join('')}\n` : '';
|
|
75
53
|
return filesPromise.then((files)=>Promise.all(files.map((filename)=>utils_namespaceObject.fs.readFile(filename, 'utf8').then((source)=>{
|
|
76
54
|
const sourceMapFilename = `${filename}.map`;
|
|
77
55
|
return utils_namespaceObject.fs.pathExists(sourceMapFilename).then((sourceMapExists)=>{
|
|
@@ -104,10 +82,8 @@ const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resol
|
|
|
104
82
|
}))));
|
|
105
83
|
}).then(()=>void 0);
|
|
106
84
|
});
|
|
107
|
-
exports.serializeServerGlobalVars = __webpack_exports__.serializeServerGlobalVars;
|
|
108
85
|
exports.transformServerGlobalVars = __webpack_exports__.transformServerGlobalVars;
|
|
109
86
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
110
|
-
"serializeServerGlobalVars",
|
|
111
87
|
"transformServerGlobalVars"
|
|
112
88
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
113
89
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -17,7 +17,8 @@ function registerBffClientArtifacts(api, metadata) {
|
|
|
17
17
|
appDir: generation.appDirectory,
|
|
18
18
|
resourcePath: sourceEffectEntry,
|
|
19
19
|
prefix: generation.prefix,
|
|
20
|
-
requestId: generation.requestId
|
|
20
|
+
requestId: generation.requestId,
|
|
21
|
+
globalVars: config.source.globalVars
|
|
21
22
|
});
|
|
22
23
|
if (null === operationContracts) throw new Error(`Cannot resolve exported Effect HttpApi in ${sourceEffectEntry}.`);
|
|
23
24
|
metadata.set(generation, {
|
package/dist/esm/compile.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { serializeServerGlobalVars
|
|
1
|
+
import { serializeServerGlobalVars } from "@modern-js/plugin-bff-extensions/server-global-vars";
|
|
2
|
+
import { transformServerGlobalVars } from "./server-global-vars.mjs";
|
|
2
3
|
function registerBffCompilation(api) {
|
|
3
4
|
const serialized = new WeakMap();
|
|
4
5
|
api.onBeforeBffCompile((context)=>{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fs, upath } from "@modern-js/utils";
|
|
2
2
|
const RELEASE_IDENTITY_GLOBAL_NAMES = [
|
|
3
3
|
'ULTRAMODERN_BUILD_MARKER',
|
|
4
4
|
'ULTRAMODERN_SOURCE_REVISION',
|
|
@@ -13,32 +13,11 @@ const collectJavaScriptFiles = (directory)=>Promise.resolve().then(()=>fs.readdi
|
|
|
13
13
|
absolutePath
|
|
14
14
|
] : [];
|
|
15
15
|
})).then((nested)=>nested.flat()));
|
|
16
|
-
const serializeServerGlobalVars = (options)=>{
|
|
17
|
-
const globalVars = applyOptionsChain({}, options, {
|
|
18
|
-
env: 'server',
|
|
19
|
-
target: 'node'
|
|
20
|
-
});
|
|
21
|
-
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
22
|
-
let serialized;
|
|
23
|
-
try {
|
|
24
|
-
serialized = JSON.stringify(value);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`, {
|
|
27
|
-
cause: error
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`);
|
|
31
|
-
return [
|
|
32
|
-
key,
|
|
33
|
-
serialized
|
|
34
|
-
];
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
37
16
|
const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resolve().then(()=>{
|
|
38
17
|
if (0 === Object.keys(globalVars).length) return;
|
|
39
18
|
return Promise.all(outputDirectories.map((directory)=>fs.pathExists(directory).then((directoryExists)=>directoryExists ? directory : void 0))).then((existingDirectories)=>{
|
|
40
19
|
const filesPromise = Promise.all(existingDirectories.filter((directory)=>void 0 !== directory).map(collectJavaScriptFiles)).then((files)=>files.flat());
|
|
41
|
-
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)
|
|
20
|
+
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`${globalVars[name]};`).join('')}\n` : '';
|
|
42
21
|
return filesPromise.then((files)=>Promise.all(files.map((filename)=>fs.readFile(filename, 'utf8').then((source)=>{
|
|
43
22
|
const sourceMapFilename = `${filename}.map`;
|
|
44
23
|
return fs.pathExists(sourceMapFilename).then((sourceMapExists)=>{
|
|
@@ -71,4 +50,4 @@ const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resol
|
|
|
71
50
|
}))));
|
|
72
51
|
}).then(()=>void 0);
|
|
73
52
|
});
|
|
74
|
-
export {
|
|
53
|
+
export { transformServerGlobalVars };
|
|
@@ -18,7 +18,8 @@ function registerBffClientArtifacts(api, metadata) {
|
|
|
18
18
|
appDir: generation.appDirectory,
|
|
19
19
|
resourcePath: sourceEffectEntry,
|
|
20
20
|
prefix: generation.prefix,
|
|
21
|
-
requestId: generation.requestId
|
|
21
|
+
requestId: generation.requestId,
|
|
22
|
+
globalVars: config.source.globalVars
|
|
22
23
|
});
|
|
23
24
|
if (null === operationContracts) throw new Error(`Cannot resolve exported Effect HttpApi in ${sourceEffectEntry}.`);
|
|
24
25
|
metadata.set(generation, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { serializeServerGlobalVars
|
|
2
|
+
import { serializeServerGlobalVars } from "@modern-js/plugin-bff-extensions/server-global-vars";
|
|
3
|
+
import { transformServerGlobalVars } from "./server-global-vars.mjs";
|
|
3
4
|
function registerBffCompilation(api) {
|
|
4
5
|
const serialized = new WeakMap();
|
|
5
6
|
api.onBeforeBffCompile((context)=>{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { fs, upath } from "@modern-js/utils";
|
|
3
3
|
const RELEASE_IDENTITY_GLOBAL_NAMES = [
|
|
4
4
|
'ULTRAMODERN_BUILD_MARKER',
|
|
5
5
|
'ULTRAMODERN_SOURCE_REVISION',
|
|
@@ -14,32 +14,11 @@ const collectJavaScriptFiles = (directory)=>Promise.resolve().then(()=>fs.readdi
|
|
|
14
14
|
absolutePath
|
|
15
15
|
] : [];
|
|
16
16
|
})).then((nested)=>nested.flat()));
|
|
17
|
-
const serializeServerGlobalVars = (options)=>{
|
|
18
|
-
const globalVars = applyOptionsChain({}, options, {
|
|
19
|
-
env: 'server',
|
|
20
|
-
target: 'node'
|
|
21
|
-
});
|
|
22
|
-
return Object.fromEntries(Object.entries(globalVars).map(([key, value])=>{
|
|
23
|
-
let serialized;
|
|
24
|
-
try {
|
|
25
|
-
serialized = JSON.stringify(value);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`, {
|
|
28
|
-
cause: error
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (void 0 === serialized) throw new Error(`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`);
|
|
32
|
-
return [
|
|
33
|
-
key,
|
|
34
|
-
serialized
|
|
35
|
-
];
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
17
|
const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resolve().then(()=>{
|
|
39
18
|
if (0 === Object.keys(globalVars).length) return;
|
|
40
19
|
return Promise.all(outputDirectories.map((directory)=>fs.pathExists(directory).then((directoryExists)=>directoryExists ? directory : void 0))).then((existingDirectories)=>{
|
|
41
20
|
const filesPromise = Promise.all(existingDirectories.filter((directory)=>void 0 !== directory).map(collectJavaScriptFiles)).then((files)=>files.flat());
|
|
42
|
-
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)
|
|
21
|
+
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`${globalVars[name]};`).join('')}\n` : '';
|
|
43
22
|
return filesPromise.then((files)=>Promise.all(files.map((filename)=>fs.readFile(filename, 'utf8').then((source)=>{
|
|
44
23
|
const sourceMapFilename = `${filename}.map`;
|
|
45
24
|
return fs.pathExists(sourceMapFilename).then((sourceMapExists)=>{
|
|
@@ -72,4 +51,4 @@ const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resol
|
|
|
72
51
|
}))));
|
|
73
52
|
}).then(()=>void 0);
|
|
74
53
|
});
|
|
75
|
-
export {
|
|
54
|
+
export { transformServerGlobalVars };
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
type ServerGlobalVarsOptions = NonNullable<NonNullable<AppTools['config']>['source']>['globalVars'];
|
|
4
|
-
export declare const serializeServerGlobalVars: (options: ServerGlobalVarsOptions) => SerializedGlobalVars;
|
|
5
|
-
export declare const transformServerGlobalVars: (outputDirectories: string[], globalVars: SerializedGlobalVars) => Promise<undefined>;
|
|
6
|
-
export {};
|
|
1
|
+
import type { SerializedServerGlobalVars } from '@modern-js/plugin-bff-extensions/server-global-vars';
|
|
2
|
+
export declare const transformServerGlobalVars: (outputDirectories: string[], globalVars: SerializedServerGlobalVars) => Promise<undefined>;
|
package/package.json
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
"url": "https://github.com/ultramodernjs/ultramodern.js/issues"
|
|
5
5
|
},
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"version": "3.9.3-ultramodern.
|
|
7
|
+
"version": "3.9.3-ultramodern.11",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"src"
|
|
11
11
|
],
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=26.
|
|
13
|
+
"node": ">=26.12.0"
|
|
14
14
|
},
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"publishConfig": {
|
|
@@ -65,19 +65,19 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.
|
|
69
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.
|
|
70
|
-
"@modern-js/plugin-bff": "npm:@bleedingdev/modern-js-plugin-bff@3.9.3-ultramodern.
|
|
71
|
-
"@modern-js/plugin-bff-extensions": "npm:@bleedingdev/modern-js-plugin-bff-extensions@3.9.3-ultramodern.
|
|
72
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.
|
|
73
|
-
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.
|
|
74
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.
|
|
75
|
-
"@swc/core": "1.16.
|
|
68
|
+
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.11",
|
|
69
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.11",
|
|
70
|
+
"@modern-js/plugin-bff": "npm:@bleedingdev/modern-js-plugin-bff@3.9.3-ultramodern.11",
|
|
71
|
+
"@modern-js/plugin-bff-extensions": "npm:@bleedingdev/modern-js-plugin-bff-extensions@3.9.3-ultramodern.11",
|
|
72
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.11",
|
|
73
|
+
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.11",
|
|
74
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.11",
|
|
75
|
+
"@swc/core": "1.16.18"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@effect/opentelemetry": "4.0.
|
|
79
|
-
"@modern-js/app-tools": "3.9.3-ultramodern.
|
|
80
|
-
"effect": "4.0.
|
|
78
|
+
"@effect/opentelemetry": "4.0.5",
|
|
79
|
+
"@modern-js/app-tools": "3.9.3-ultramodern.11",
|
|
80
|
+
"effect": "4.0.5"
|
|
81
81
|
},
|
|
82
82
|
"peerDependenciesMeta": {
|
|
83
83
|
"@effect/opentelemetry": {
|
|
@@ -88,21 +88,21 @@
|
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@effect/opentelemetry": "4.0.
|
|
92
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.3-ultramodern.
|
|
93
|
-
"@modern-js/bff-effect": "npm:@bleedingdev/modern-js-bff-effect@3.9.3-ultramodern.
|
|
94
|
-
"@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.9.3-ultramodern.
|
|
95
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.3-ultramodern.
|
|
96
|
-
"@modern-js/tsconfig": "npm:@bleedingdev/modern-js-tsconfig@3.9.3-ultramodern.
|
|
97
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.
|
|
98
|
-
"@rsbuild/core": "2.2.
|
|
91
|
+
"@effect/opentelemetry": "4.0.5",
|
|
92
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.3-ultramodern.11",
|
|
93
|
+
"@modern-js/bff-effect": "npm:@bleedingdev/modern-js-bff-effect@3.9.3-ultramodern.11",
|
|
94
|
+
"@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.9.3-ultramodern.11",
|
|
95
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.3-ultramodern.11",
|
|
96
|
+
"@modern-js/tsconfig": "npm:@bleedingdev/modern-js-tsconfig@3.9.3-ultramodern.11",
|
|
97
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.11",
|
|
98
|
+
"@rsbuild/core": "2.2.13",
|
|
99
99
|
"@rslib/core": "1.0.3",
|
|
100
100
|
"@scripts/rstest-config": "2.66.0",
|
|
101
|
-
"@types/node": "^26.6.
|
|
102
|
-
"effect": "4.0.
|
|
101
|
+
"@types/node": "^26.6.5",
|
|
102
|
+
"effect": "4.0.5",
|
|
103
103
|
"esbuild": "^0.28.2",
|
|
104
104
|
"typescript": "7.0.2",
|
|
105
|
-
"zod": "^4.6.
|
|
105
|
+
"zod": "^4.6.7"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"dev": "rslib build --watch",
|
package/src/client-artifacts.ts
CHANGED
package/src/compile.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { AppTools, BffCompilation } from '@modern-js/app-tools';
|
|
2
2
|
import type { CLIPluginAPI } from '@modern-js/plugin';
|
|
3
|
-
import type { BffRuntimeBuildIdentity } from './runtime-build-identity';
|
|
4
3
|
import {
|
|
4
|
+
type SerializedServerGlobalVars,
|
|
5
5
|
serializeServerGlobalVars,
|
|
6
|
-
|
|
7
|
-
} from './
|
|
6
|
+
} from '@modern-js/plugin-bff-extensions/server-global-vars';
|
|
7
|
+
import type { BffRuntimeBuildIdentity } from './runtime-build-identity';
|
|
8
|
+
import { transformServerGlobalVars } from './server-global-vars';
|
|
8
9
|
|
|
9
10
|
export function registerBffCompilation(api: CLIPluginAPI<AppTools>) {
|
|
10
|
-
const serialized = new WeakMap<
|
|
11
|
-
BffCompilation,
|
|
12
|
-
ReturnType<typeof serializeServerGlobalVars>
|
|
13
|
-
>();
|
|
11
|
+
const serialized = new WeakMap<BffCompilation, SerializedServerGlobalVars>();
|
|
14
12
|
api.onBeforeBffCompile(context => {
|
|
15
13
|
serialized.set(
|
|
16
14
|
context,
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import { applyOptionsChain, fs, upath as path } from '@modern-js/utils';
|
|
4
|
-
|
|
5
|
-
type SerializedGlobalVars = Record<string, string>;
|
|
6
|
-
type ServerGlobalVarsOptions = NonNullable<
|
|
7
|
-
NonNullable<AppTools['config']>['source']
|
|
8
|
-
>['globalVars'];
|
|
1
|
+
import type { SerializedServerGlobalVars } from '@modern-js/plugin-bff-extensions/server-global-vars';
|
|
2
|
+
import { fs, upath as path } from '@modern-js/utils';
|
|
9
3
|
|
|
10
4
|
const RELEASE_IDENTITY_GLOBAL_NAMES = [
|
|
11
5
|
'ULTRAMODERN_BUILD_MARKER',
|
|
@@ -28,41 +22,9 @@ const collectJavaScriptFiles = (directory: string): Promise<string[]> =>
|
|
|
28
22
|
).then(nested => nested.flat()),
|
|
29
23
|
);
|
|
30
24
|
|
|
31
|
-
export const serializeServerGlobalVars = (
|
|
32
|
-
options: ServerGlobalVarsOptions,
|
|
33
|
-
): SerializedGlobalVars => {
|
|
34
|
-
const globalVars = applyOptionsChain<
|
|
35
|
-
Record<string, unknown>,
|
|
36
|
-
{ env: string; target: RsbuildTarget }
|
|
37
|
-
>({}, options, {
|
|
38
|
-
env: 'server',
|
|
39
|
-
target: 'node',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return Object.fromEntries(
|
|
43
|
-
Object.entries(globalVars).map(([key, value]) => {
|
|
44
|
-
let serialized: string | undefined;
|
|
45
|
-
try {
|
|
46
|
-
serialized = JSON.stringify(value);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`,
|
|
50
|
-
{ cause: error },
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (serialized === undefined) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`source.globalVars["${key}"] cannot be serialized exactly for BFF compilation.`,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return [key, serialized];
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
25
|
export const transformServerGlobalVars = (
|
|
64
26
|
outputDirectories: string[],
|
|
65
|
-
globalVars:
|
|
27
|
+
globalVars: SerializedServerGlobalVars,
|
|
66
28
|
) =>
|
|
67
29
|
Promise.resolve().then(() => {
|
|
68
30
|
if (Object.keys(globalVars).length === 0) {
|
|
@@ -86,7 +48,8 @@ export const transformServerGlobalVars = (
|
|
|
86
48
|
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every(
|
|
87
49
|
name => Object.hasOwn(globalVars, name),
|
|
88
50
|
)
|
|
89
|
-
?
|
|
51
|
+
? // String statements, so a following "use strict" stays in the prologue.
|
|
52
|
+
`${RELEASE_IDENTITY_GLOBAL_NAMES.map(name => `${globalVars[name]};`).join('')}\n`
|
|
90
53
|
: '';
|
|
91
54
|
|
|
92
55
|
return filesPromise.then(files =>
|