@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.101 → 3.5.0-ultramodern.103
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/cli/compress.js +1 -1
- package/dist/cjs/cli/generator.js +106 -97
- package/dist/cjs/cli/serverGlobalVars.js +43 -57
- package/dist/cjs/cli.js +6 -2
- package/dist/cjs/loader.js +6 -5
- package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +17 -12
- package/dist/cjs/runtime/effect/adapter/entry.js +13 -5
- package/dist/cjs/runtime/effect/adapter/error-response.js +11 -9
- package/dist/cjs/runtime/effect/adapter.js +2 -2
- package/dist/cjs/runtime/effect/backend-federation/load.js +26 -17
- package/dist/cjs/runtime/effect/backend-federation/plugin.js +12 -2
- package/dist/cjs/runtime/effect/backend-federation/remotes.js +5 -4
- package/dist/cjs/runtime/effect/backend-federation/runtime.js +80 -16
- package/dist/cjs/runtime/effect/edge-dispatcher.js +148 -0
- package/dist/cjs/runtime/effect/edge.js +19 -100
- package/dist/cjs/runtime/effect/handler/definition.js +1 -0
- package/dist/cjs/runtime/effect/handler/http.js +17 -6
- package/dist/cjs/utils/crossProjectApiPlugin.js +21 -2
- package/dist/cjs/utils/effect-client-generator/generator.js +17 -16
- package/dist/cjs/utils/effect-client-generator/paths.js +4 -15
- package/dist/cjs/utils/effect-client-generator/rendering.js +8 -19
- package/dist/cjs/utils/effect-client-generator/runtime.js +15 -32
- package/dist/cjs/utils/effectSourceLoader.js +70 -10
- package/dist/cjs/utils/pluginGenerator.js +4 -4
- package/dist/esm/cli/compress.mjs +1 -1
- package/dist/esm/cli/generator.mjs +108 -98
- package/dist/esm/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/loader.mjs +6 -5
- package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm/runtime/effect/adapter/entry.mjs +13 -5
- package/dist/esm/runtime/effect/adapter/error-response.mjs +11 -9
- package/dist/esm/runtime/effect/adapter.mjs +3 -3
- package/dist/esm/runtime/effect/backend-federation/load.mjs +26 -17
- package/dist/esm/runtime/effect/backend-federation/plugin.mjs +12 -2
- package/dist/esm/runtime/effect/backend-federation/remotes.mjs +5 -4
- package/dist/esm/runtime/effect/backend-federation/runtime.mjs +80 -16
- package/dist/esm/runtime/effect/edge-dispatcher.mjs +38 -0
- package/dist/esm/runtime/effect/edge.mjs +1 -38
- package/dist/esm/runtime/effect/handler/definition.mjs +1 -0
- package/dist/esm/runtime/effect/handler/http.mjs +17 -6
- package/dist/esm/utils/crossProjectApiPlugin.mjs +16 -3
- package/dist/esm/utils/effect-client-generator/generator.mjs +17 -16
- package/dist/esm/utils/effect-client-generator/paths.mjs +5 -6
- package/dist/esm/utils/effect-client-generator/rendering.mjs +9 -10
- package/dist/esm/utils/effect-client-generator/runtime.mjs +16 -23
- package/dist/esm/utils/effectSourceLoader.mjs +69 -12
- package/dist/esm/utils/pluginGenerator.mjs +5 -5
- package/dist/esm-node/cli/compress.mjs +1 -1
- package/dist/esm-node/cli/generator.mjs +108 -98
- package/dist/esm-node/cli/serverGlobalVars.mjs +44 -48
- package/dist/esm-node/cli.mjs +2 -0
- package/dist/esm-node/loader.mjs +6 -5
- package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +17 -12
- package/dist/esm-node/runtime/effect/adapter/entry.mjs +13 -5
- package/dist/esm-node/runtime/effect/adapter/error-response.mjs +11 -9
- package/dist/esm-node/runtime/effect/adapter.mjs +3 -3
- package/dist/esm-node/runtime/effect/backend-federation/load.mjs +26 -17
- package/dist/esm-node/runtime/effect/backend-federation/plugin.mjs +12 -2
- package/dist/esm-node/runtime/effect/backend-federation/remotes.mjs +5 -4
- package/dist/esm-node/runtime/effect/backend-federation/runtime.mjs +80 -16
- package/dist/esm-node/runtime/effect/edge-dispatcher.mjs +39 -0
- package/dist/esm-node/runtime/effect/edge.mjs +1 -38
- package/dist/esm-node/runtime/effect/handler/definition.mjs +1 -0
- package/dist/esm-node/runtime/effect/handler/http.mjs +17 -6
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +16 -3
- package/dist/esm-node/utils/effect-client-generator/generator.mjs +17 -16
- package/dist/esm-node/utils/effect-client-generator/paths.mjs +5 -6
- package/dist/esm-node/utils/effect-client-generator/rendering.mjs +9 -10
- package/dist/esm-node/utils/effect-client-generator/runtime.mjs +16 -23
- package/dist/esm-node/utils/effectSourceLoader.mjs +69 -12
- package/dist/esm-node/utils/pluginGenerator.mjs +5 -5
- package/dist/types/cli/generator.d.ts +2 -2
- package/dist/types/cli/serverGlobalVars.d.ts +4 -2
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/runtime/effect/adapter/cross-project-policy.d.ts +1 -1
- package/dist/types/runtime/effect/backend-federation/runtime.d.ts +1 -1
- package/dist/types/runtime/effect/edge-dispatcher.d.ts +26 -0
- package/dist/types/runtime/effect/edge.d.ts +1 -26
- package/dist/types/runtime/effect/handler/definition.d.ts +2 -12
- package/dist/types/runtime/effect/handler/http.d.ts +2 -1
- package/dist/types/runtime/effect/handler/types.d.ts +5 -0
- package/dist/types/utils/crossProjectApiPlugin.d.ts +2 -0
- package/dist/types/utils/effectSourceLoader.d.ts +10 -0
- package/dist/types/utils/pluginGenerator.d.ts +3 -1
- package/package.json +34 -18
package/dist/cjs/cli/compress.js
CHANGED
|
@@ -32,7 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
});
|
|
33
33
|
const external_prefix_js_namespaceObject = require("./prefix.js");
|
|
34
34
|
const createCompressConfig = (devServer, prefix)=>{
|
|
35
|
-
if (
|
|
35
|
+
if (void 0 === devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
|
|
36
36
|
const { compress } = devServer;
|
|
37
37
|
if (void 0 === compress || true === compress) {
|
|
38
38
|
const prefixes = (0, external_prefix_js_namespaceObject.normalizePrefixList)(prefix);
|
|
@@ -42,8 +42,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
42
42
|
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
43
43
|
const server_utils_namespaceObject = require("@modern-js/server-utils");
|
|
44
44
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
|
-
const external_path_namespaceObject = require("path");
|
|
46
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
45
|
const clientGenerator_js_namespaceObject = require("../utils/clientGenerator.js");
|
|
48
46
|
var clientGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(clientGenerator_js_namespaceObject);
|
|
49
47
|
const effectSourceLoader_js_namespaceObject = require("../utils/effectSourceLoader.js");
|
|
@@ -65,110 +63,121 @@ const effectEntryExtensions = [
|
|
|
65
63
|
'.cts'
|
|
66
64
|
];
|
|
67
65
|
function resolveEffectSourceEntry(appDirectory, apiDirectory, configuredEntry) {
|
|
68
|
-
const entry = configuredEntry ?
|
|
69
|
-
return
|
|
66
|
+
const entry = void 0 !== configuredEntry && configuredEntry.length > 0 ? utils_namespaceObject.upath.isAbsolute(configuredEntry) ? configuredEntry : utils_namespaceObject.upath.resolve(appDirectory, configuredEntry) : utils_namespaceObject.upath.resolve(apiDirectory, 'index');
|
|
67
|
+
return utils_namespaceObject.upath.extname(entry).length > 0 ? entry : effectEntryExtensions.map((extension)=>`${entry}${extension}`).find((candidate)=>utils_namespaceObject.fs.existsSync(candidate));
|
|
70
68
|
}
|
|
71
69
|
function resolveBuiltEffectEntry(appDirectory, distDirectory, sourceEntry) {
|
|
72
|
-
if (
|
|
73
|
-
const relativeEntry =
|
|
74
|
-
if ('..' === relativeEntry || relativeEntry.startsWith(`..${
|
|
75
|
-
const builtEntry =
|
|
70
|
+
if (void 0 === sourceEntry || 0 === sourceEntry.length) return;
|
|
71
|
+
const relativeEntry = utils_namespaceObject.upath.relative(appDirectory, sourceEntry);
|
|
72
|
+
if ('..' === relativeEntry || relativeEntry.startsWith(`..${utils_namespaceObject.upath.sep}`)) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
|
|
73
|
+
const builtEntry = utils_namespaceObject.upath.resolve(distDirectory, relativeEntry).replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
76
74
|
return utils_namespaceObject.fs.existsSync(builtEntry) ? builtEntry : void 0;
|
|
77
75
|
}
|
|
78
76
|
const createBffGenerator = (api)=>{
|
|
79
|
-
const compileApi =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
alias
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
77
|
+
const compileApi = ()=>Promise.resolve().then(()=>{
|
|
78
|
+
const { appDirectory, distDirectory, apiDirectory, bffRuntimeFramework, sharedDirectory, moduleType } = api.getAppContext();
|
|
79
|
+
const modernConfig = api.getNormalizedConfig();
|
|
80
|
+
const distDir = utils_namespaceObject.upath.resolve(distDirectory);
|
|
81
|
+
const apiDir = apiDirectory || utils_namespaceObject.upath.resolve(appDirectory, utils_namespaceObject.API_DIR);
|
|
82
|
+
const sharedDir = sharedDirectory || utils_namespaceObject.upath.resolve(appDirectory, utils_namespaceObject.SHARED_DIR);
|
|
83
|
+
const tsconfigPath = (0, utils_namespaceObject.resolveServerTsconfig)(appDirectory, modernConfig?.server?.tsconfigPath);
|
|
84
|
+
const sourceDirs = [];
|
|
85
|
+
return utils_namespaceObject.fs.pathExists(apiDir).then((apiDirectoryExists)=>{
|
|
86
|
+
if (apiDirectoryExists) sourceDirs.push(apiDir);
|
|
87
|
+
return utils_namespaceObject.fs.pathExists(sharedDir);
|
|
88
|
+
}).then((sharedDirectoryExists)=>{
|
|
89
|
+
if (sharedDirectoryExists) sourceDirs.push(sharedDir);
|
|
90
|
+
if (0 === sourceDirs.length) return;
|
|
91
|
+
const { alias, globalVars } = modernConfig.source;
|
|
92
|
+
const { alias: resolveAlias } = modernConfig.resolve;
|
|
93
|
+
const combinedAlias = [].concat(alias ?? []).concat(resolveAlias ?? []);
|
|
94
|
+
const serializedGlobalVars = (0, external_serverGlobalVars_js_namespaceObject.serializeServerGlobalVars)(globalVars);
|
|
95
|
+
return (0, server_utils_namespaceObject.compile)(appDirectory, {
|
|
96
|
+
alias: combinedAlias
|
|
97
|
+
}, {
|
|
98
|
+
sourceDirs,
|
|
99
|
+
distDir,
|
|
100
|
+
tsconfigPath,
|
|
101
|
+
moduleType,
|
|
102
|
+
throwErrorInsteadOfExit: true
|
|
103
|
+
}).then(()=>(0, external_serverGlobalVars_js_namespaceObject.transformServerGlobalVars)(sourceDirs.map((sourceDir)=>utils_namespaceObject.upath.resolve(distDir, utils_namespaceObject.upath.relative(appDirectory, sourceDir))), serializedGlobalVars)).then(()=>{
|
|
104
|
+
if ('effect' !== bffRuntimeFramework) return;
|
|
105
|
+
const sourceEntry = resolveEffectSourceEntry(appDirectory, apiDir, modernConfig.bff?.effect?.entry);
|
|
106
|
+
const builtEntry = resolveBuiltEffectEntry(appDirectory, distDir, sourceEntry);
|
|
107
|
+
if (void 0 === builtEntry || 0 === builtEntry.length) throw new Error(`Effect BFF entry was not emitted into ${distDir}: ${sourceEntry ?? utils_namespaceObject.upath.resolve(apiDir, 'index')}`);
|
|
108
|
+
return (0, effectSourceLoader_js_namespaceObject.bundleEffectEntryForNode)({
|
|
109
|
+
appDir: appDirectory,
|
|
110
|
+
entryPath: builtEntry,
|
|
111
|
+
format: 'module' === moduleType ? 'esm' : 'cjs'
|
|
112
|
+
});
|
|
112
113
|
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const generate = async ()=>{
|
|
117
|
-
const { appDirectory, apiDirectory, lambdaDirectory, port, bffRuntimeFramework } = api.getAppContext();
|
|
118
|
-
const modernConfig = api.getNormalizedConfig();
|
|
119
|
-
const relativeDistPath = modernConfig?.output?.distPath?.root || 'dist';
|
|
120
|
-
const { bff } = modernConfig || {};
|
|
121
|
-
const prefix = (0, external_prefix_js_namespaceObject.getPrimaryPrefix)(bff?.prefix);
|
|
122
|
-
const httpMethodDecider = bff?.httpMethodDecider;
|
|
123
|
-
const apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
124
|
-
apiDir: apiDirectory,
|
|
125
|
-
appDir: appDirectory,
|
|
126
|
-
lambdaDir: lambdaDirectory,
|
|
127
|
-
prefix,
|
|
128
|
-
httpMethodDecider,
|
|
129
|
-
isBuild: true
|
|
130
|
-
});
|
|
131
|
-
const lambdaDir = apiRouter.getLambdaDir();
|
|
132
|
-
const existLambda = apiRouter.isExistLambda();
|
|
133
|
-
const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
|
|
134
|
-
const relativeApiPath = external_path_default().relative(appDirectory, apiDirectory);
|
|
135
|
-
const relativeLambdaPath = external_path_default().relative(appDirectory, lambdaDir);
|
|
136
|
-
await pluginGenerator_js_default()({
|
|
137
|
-
prefix,
|
|
138
|
-
appDirectory,
|
|
139
|
-
relativeDistPath,
|
|
140
|
-
relativeApiPath,
|
|
141
|
-
relativeLambdaPath,
|
|
142
|
-
runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect'
|
|
114
|
+
});
|
|
143
115
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
116
|
+
const generate = ()=>Promise.resolve().then(()=>{
|
|
117
|
+
const { appDirectory, apiDirectory, lambdaDirectory, port, bffRuntimeFramework, packageName } = api.getAppContext();
|
|
118
|
+
const modernConfig = api.getNormalizedConfig();
|
|
119
|
+
const relativeDistPath = modernConfig?.output?.distPath?.root || 'dist';
|
|
120
|
+
const { bff } = modernConfig || {};
|
|
121
|
+
const prefix = (0, external_prefix_js_namespaceObject.getPrimaryPrefix)(bff?.prefix);
|
|
122
|
+
const httpMethodDecider = bff?.httpMethodDecider;
|
|
123
|
+
const apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
124
|
+
apiDir: apiDirectory,
|
|
125
|
+
appDir: appDirectory,
|
|
126
|
+
lambdaDir: lambdaDirectory,
|
|
127
|
+
prefix,
|
|
128
|
+
httpMethodDecider,
|
|
129
|
+
isBuild: true
|
|
130
|
+
});
|
|
131
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
132
|
+
const existLambda = apiRouter.isExistLambda();
|
|
133
|
+
const packageJson = utils_namespaceObject.fs.readJSONSync(utils_namespaceObject.upath.resolve(appDirectory, 'package.json'));
|
|
134
|
+
const requestId = packageJson.name || packageName;
|
|
135
|
+
const operationContractsPromise = existLambda ? apiRouter.getApiHandlers().then((handlers)=>(0, bff_core_namespaceObject.buildOperationContractMap)({
|
|
136
|
+
handlers,
|
|
137
|
+
requestId,
|
|
138
|
+
operationVersion: (0, bff_core_namespaceObject.deriveOperationVersion)(packageJson.version)
|
|
139
|
+
})) : Promise.resolve({});
|
|
140
|
+
return operationContractsPromise.then((operationContracts)=>{
|
|
141
|
+
const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
|
|
142
|
+
const relativeApiPath = utils_namespaceObject.upath.relative(appDirectory, apiDirectory);
|
|
143
|
+
const relativeLambdaPath = utils_namespaceObject.upath.relative(appDirectory, lambdaDir);
|
|
144
|
+
const sourceEffectEntry = 'effect' === bffRuntimeFramework ? resolveEffectSourceEntry(appDirectory, apiDirectory, bff?.effect?.entry) : void 0;
|
|
145
|
+
const relativeEffectEntry = void 0 !== sourceEffectEntry && sourceEffectEntry.length > 0 ? utils_namespaceObject.upath.relative(appDirectory, sourceEffectEntry).replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js') : '';
|
|
146
|
+
return pluginGenerator_js_default()({
|
|
147
|
+
prefix,
|
|
148
|
+
appDirectory,
|
|
149
|
+
relativeDistPath,
|
|
150
|
+
relativeApiPath,
|
|
151
|
+
relativeLambdaPath,
|
|
152
|
+
runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect',
|
|
153
|
+
relativeEffectEntry,
|
|
154
|
+
operationContracts
|
|
155
|
+
}).then(()=>clientGenerator_js_default()({
|
|
156
|
+
prefix,
|
|
157
|
+
appDir: appDirectory,
|
|
158
|
+
apiDir: apiDirectory,
|
|
159
|
+
lambdaDir,
|
|
160
|
+
existLambda,
|
|
161
|
+
port,
|
|
162
|
+
requestCreator: bff?.requestCreator,
|
|
163
|
+
httpMethodDecider,
|
|
164
|
+
relativeDistPath,
|
|
165
|
+
relativeApiPath,
|
|
166
|
+
bffRuntimeFramework,
|
|
167
|
+
effectEntry: bff?.effect?.entry,
|
|
168
|
+
effectDataPlatformBatch: bff?.effect?.dataPlatform?.batch
|
|
169
|
+
})).then(()=>runtimeGenerator_js_default()({
|
|
170
|
+
runtime,
|
|
171
|
+
appDirectory,
|
|
172
|
+
relativeDistPath
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
158
175
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
const handleCrossProjectInvocation = (isBuild = false)=>Promise.resolve().then(()=>{
|
|
177
|
+
const { bff } = api.getNormalizedConfig();
|
|
178
|
+
if (bff?.crossProject !== true) return;
|
|
179
|
+
return isBuild ? generate() : compileApi().then(()=>generate());
|
|
163
180
|
});
|
|
164
|
-
};
|
|
165
|
-
const handleCrossProjectInvocation = async (isBuild = false)=>{
|
|
166
|
-
const { bff } = api.getNormalizedConfig();
|
|
167
|
-
if (bff?.crossProject) {
|
|
168
|
-
if (!isBuild) await compileApi();
|
|
169
|
-
await generate();
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
181
|
return {
|
|
173
182
|
compileApi,
|
|
174
183
|
generate,
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
5
|
var define = (defs, kind)=>{
|
|
@@ -42,26 +33,20 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
42
33
|
});
|
|
43
34
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
35
|
const core_namespaceObject = require("@swc/core");
|
|
45
|
-
const external_path_namespaceObject = require("path");
|
|
46
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
36
|
const RELEASE_IDENTITY_GLOBAL_NAMES = [
|
|
48
37
|
'ULTRAMODERN_BUILD_MARKER',
|
|
49
38
|
'ULTRAMODERN_SOURCE_REVISION',
|
|
50
39
|
'ULTRAMODERN_RELEASE_VERSION'
|
|
51
40
|
];
|
|
52
|
-
const collectJavaScriptFiles =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
] : [];
|
|
62
|
-
}));
|
|
63
|
-
return nested.flat();
|
|
64
|
-
};
|
|
41
|
+
const collectJavaScriptFiles = (directory)=>Promise.resolve().then(()=>utils_namespaceObject.fs.readdir(directory, {
|
|
42
|
+
withFileTypes: true
|
|
43
|
+
})).then((entries)=>Promise.all(entries.map((entry)=>{
|
|
44
|
+
const absolutePath = utils_namespaceObject.upath.join(directory, entry.name);
|
|
45
|
+
if (entry.isDirectory()) return collectJavaScriptFiles(absolutePath);
|
|
46
|
+
return /\.(?:c|m)?js$/u.test(entry.name) ? [
|
|
47
|
+
absolutePath
|
|
48
|
+
] : [];
|
|
49
|
+
})).then((nested)=>nested.flat()));
|
|
65
50
|
const serializeServerGlobalVars = (options)=>{
|
|
66
51
|
const globalVars = (0, utils_namespaceObject.applyOptionsChain)({}, options, {
|
|
67
52
|
env: 'server',
|
|
@@ -83,39 +68,40 @@ const serializeServerGlobalVars = (options)=>{
|
|
|
83
68
|
];
|
|
84
69
|
}));
|
|
85
70
|
};
|
|
86
|
-
const transformServerGlobalVars =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
71
|
+
const transformServerGlobalVars = (outputDirectories, globalVars)=>Promise.resolve().then(()=>{
|
|
72
|
+
if (0 === Object.keys(globalVars).length) return;
|
|
73
|
+
return Promise.all(outputDirectories.map((directory)=>utils_namespaceObject.fs.pathExists(directory).then((directoryExists)=>directoryExists ? directory : void 0))).then((existingDirectories)=>{
|
|
74
|
+
const filesPromise = Promise.all(existingDirectories.filter((directory)=>void 0 !== directory).map(collectJavaScriptFiles)).then((files)=>files.flat());
|
|
75
|
+
const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`void ${globalVars[name]};`).join('')}\n` : '';
|
|
76
|
+
return filesPromise.then((files)=>Promise.all(files.map((filename)=>utils_namespaceObject.fs.readFile(filename, 'utf8').then((source)=>{
|
|
77
|
+
const sourceMapFilename = `${filename}.map`;
|
|
78
|
+
return utils_namespaceObject.fs.pathExists(sourceMapFilename).then((sourceMapExists)=>{
|
|
79
|
+
const inputSourceMapPromise = sourceMapExists ? utils_namespaceObject.fs.readFile(sourceMapFilename, 'utf8') : Promise.resolve(void 0);
|
|
80
|
+
return inputSourceMapPromise.then((inputSourceMap)=>(0, core_namespaceObject.transform)(`${releaseIdentityBanner}${source}`, {
|
|
81
|
+
filename,
|
|
82
|
+
inputSourceMap,
|
|
83
|
+
sourceMaps: sourceMapExists,
|
|
84
|
+
jsc: {
|
|
85
|
+
parser: {
|
|
86
|
+
syntax: "ecmascript"
|
|
87
|
+
},
|
|
88
|
+
preserveAllComments: true,
|
|
89
|
+
target: 'es2022',
|
|
90
|
+
transform: {
|
|
91
|
+
optimizer: {
|
|
92
|
+
globals: {
|
|
93
|
+
vars: globalVars
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}).then((result)=>utils_namespaceObject.fs.writeFile(filename, result.code).then(()=>{
|
|
99
|
+
if (sourceMapExists && void 0 !== result.map && result.map.length > 0) return utils_namespaceObject.fs.writeFile(sourceMapFilename, result.map);
|
|
100
|
+
})));
|
|
101
|
+
});
|
|
102
|
+
}))));
|
|
103
|
+
}).then(()=>void 0);
|
|
104
|
+
});
|
|
119
105
|
exports.serializeServerGlobalVars = __webpack_exports__.serializeServerGlobalVars;
|
|
120
106
|
exports.transformServerGlobalVars = __webpack_exports__.transformServerGlobalVars;
|
|
121
107
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
package/dist/cjs/cli.js
CHANGED
|
@@ -37,7 +37,8 @@ var __webpack_require__ = {};
|
|
|
37
37
|
var __webpack_exports__ = {};
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
bffPlugin: ()=>bffPlugin
|
|
40
|
+
bffPlugin: ()=>bffPlugin,
|
|
41
|
+
default: ()=>cli
|
|
41
42
|
});
|
|
42
43
|
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
43
44
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
@@ -170,9 +171,12 @@ const bffPlugin = ()=>({
|
|
|
170
171
|
});
|
|
171
172
|
}
|
|
172
173
|
});
|
|
174
|
+
const cli = bffPlugin;
|
|
173
175
|
exports.bffPlugin = __webpack_exports__.bffPlugin;
|
|
176
|
+
exports["default"] = __webpack_exports__["default"];
|
|
174
177
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
175
|
-
"bffPlugin"
|
|
178
|
+
"bffPlugin",
|
|
179
|
+
"default"
|
|
176
180
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
177
181
|
Object.defineProperty(exports, '__esModule', {
|
|
178
182
|
value: true
|
package/dist/cjs/loader.js
CHANGED
|
@@ -46,6 +46,7 @@ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_na
|
|
|
46
46
|
const effectClientGenerator_js_namespaceObject = require("./utils/effectClientGenerator.js");
|
|
47
47
|
const EFFECT_BFF_WORKER_RUNTIME_QUERY = 'modern-bff-runtime';
|
|
48
48
|
const EFFECT_BFF_WORKER_RUNTIME_SOURCE_QUERY = 'modern-bff-runtime-source';
|
|
49
|
+
const createErrorModule = (message)=>`throw new Error(${JSON.stringify(message)});`;
|
|
49
50
|
async function transformEffectRuntimeSource(source, filename) {
|
|
50
51
|
const swc = await import("@swc/core");
|
|
51
52
|
const result = await swc.transform(source, {
|
|
@@ -67,7 +68,7 @@ async function transformEffectRuntimeSource(source, filename) {
|
|
|
67
68
|
function createEffectWorkerRuntimeWrapper(resourcePath) {
|
|
68
69
|
const sourceRequest = `${resourcePath}?${EFFECT_BFF_WORKER_RUNTIME_SOURCE_QUERY}`;
|
|
69
70
|
return `import * as effectBffModule from ${JSON.stringify(sourceRequest)};
|
|
70
|
-
import { createEffectBffEdgeDispatcher } from '@modern-js/plugin-bff/effect-edge';
|
|
71
|
+
import { createEffectBffEdgeDispatcher } from '@modern-js/plugin-bff/effect-edge/dispatcher';
|
|
71
72
|
|
|
72
73
|
export const __modern_create_effect_bff_dispatcher = options =>
|
|
73
74
|
createEffectBffEdgeDispatcher({
|
|
@@ -108,13 +109,13 @@ async function loader(source) {
|
|
|
108
109
|
onDependency: (dependency)=>this.addDependency(dependency)
|
|
109
110
|
});
|
|
110
111
|
if (code) return void callback(void 0, code);
|
|
111
|
-
callback(void 0, `
|
|
112
|
+
callback(void 0, createErrorModule(`Failed to generate Effect client for ${resourcePath}`));
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
115
|
const warning = `The file ${resourcePath} is not allowed to be imported in src directory, only API definition files are allowed.`;
|
|
115
116
|
if (!draftOptions.existLambda) {
|
|
116
117
|
utils_namespaceObject.logger.warn(warning);
|
|
117
|
-
callback(null,
|
|
118
|
+
callback(null, createErrorModule(warning));
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
const options = {
|
|
@@ -131,14 +132,14 @@ async function loader(source) {
|
|
|
131
132
|
const { lambdaDir } = draftOptions;
|
|
132
133
|
if (!resourcePath.startsWith(lambdaDir)) {
|
|
133
134
|
utils_namespaceObject.logger.warn(warning);
|
|
134
|
-
callback(null,
|
|
135
|
+
callback(null, createErrorModule(warning));
|
|
135
136
|
return;
|
|
136
137
|
}
|
|
137
138
|
if (draftOptions.fetcher) options.fetcher = draftOptions.fetcher;
|
|
138
139
|
if (draftOptions.requestCreator) options.requestCreator = draftOptions.requestCreator;
|
|
139
140
|
options.requireResolve = require.resolve;
|
|
140
141
|
const result = await (0, bff_core_namespaceObject.generateClient)(options);
|
|
141
|
-
callback(void 0, result.isOk ? result.value :
|
|
142
|
+
callback(void 0, result.isOk ? result.value : createErrorModule(result.value));
|
|
142
143
|
}
|
|
143
144
|
const src_loader = loader;
|
|
144
145
|
exports["default"] = __webpack_exports__["default"];
|
|
@@ -34,23 +34,28 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
34
34
|
const httpapi_namespaceObject = require("effect/unstable/httpapi");
|
|
35
35
|
const crossProjectServerPolicy_js_namespaceObject = require("../../../utils/crossProjectServerPolicy.js");
|
|
36
36
|
const external_endpoint_contracts_js_namespaceObject = require("../endpoint-contracts.js");
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
|
|
38
|
+
const contractSourcesPromise = null === mod ? Promise.resolve([]) : Promise.resolve().then(()=>(0, external_endpoint_contracts_js_namespaceObject.extractHttpApiFromModule)(mod, httpapi_namespaceObject.HttpApi.isHttpApi)).then((effectApi)=>{
|
|
39
|
+
if (null !== effectApi) {
|
|
40
|
+
const reflect = (apiValue, handlers)=>{
|
|
41
|
+
if (!httpapi_namespaceObject.HttpApi.isHttpApi(apiValue)) throw new Error('[BFF][Effect] Endpoint reflection received a non-HttpApi value.');
|
|
42
|
+
httpapi_namespaceObject.HttpApi.reflect(apiValue, {
|
|
43
43
|
onGroup: handlers.onGroup ?? (()=>{}),
|
|
44
44
|
onEndpoint: handlers.onEndpoint
|
|
45
45
|
});
|
|
46
|
-
|
|
46
|
+
};
|
|
47
|
+
return (0, external_endpoint_contracts_js_namespaceObject.toOperationContractSources)((0, external_endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(reflect, effectApi, prefix));
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
return [];
|
|
50
|
+
}).catch((error)=>{
|
|
49
51
|
utils_namespaceObject.logger.warn(`[BFF][Effect] Failed reflect HttpApi endpoints cross-project policy: ${String(error)}`);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
return [];
|
|
53
|
+
});
|
|
54
|
+
return contractSourcesPromise.then((contractSources)=>{
|
|
55
|
+
const policy = (0, crossProjectServerPolicy_js_namespaceObject.resolveAdapterCrossProjectPolicy)(api, contractSources);
|
|
56
|
+
if (policy?.enabled === true && 0 === contractSources.length) utils_namespaceObject.logger.warn('[BFF][Effect] Cross-project policy enabled but no HttpApi endpoints could be reflected; requests fail operation-contract matching unless allowUnknownOperations is enabled.');
|
|
57
|
+
return policy;
|
|
58
|
+
});
|
|
54
59
|
}
|
|
55
60
|
exports.resolveEffectAdapterCrossProjectPolicy = __webpack_exports__.resolveEffectAdapterCrossProjectPolicy;
|
|
56
61
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -64,24 +64,32 @@ function relativeAppPath(appDirectory, entryPath) {
|
|
|
64
64
|
const relativePath = external_path_default().relative(appDirectory, entryPath);
|
|
65
65
|
return '..' === relativePath || relativePath.startsWith(`..${external_path_default().sep}`) ? void 0 : relativePath;
|
|
66
66
|
}
|
|
67
|
+
function isDependencyPath(relativePath) {
|
|
68
|
+
return relativePath?.split(/[\\/]/u).includes('node_modules') ?? false;
|
|
69
|
+
}
|
|
67
70
|
function resolveEffectAdapterEntryFile(api) {
|
|
68
71
|
const { appDirectory, apiDirectory, distDirectory } = api.getServerContext();
|
|
69
72
|
const appRoot = external_path_default().resolve(appDirectory || process.cwd());
|
|
70
|
-
const productionRoot = (0, utils_namespaceObject.isProd)() && distDirectory ? distDirectory : void 0;
|
|
73
|
+
const productionRoot = (0, utils_namespaceObject.isProd)() && distDirectory ? external_path_default().resolve(distDirectory) : void 0;
|
|
71
74
|
const bffConfig = api.getServerConfig()?.bff;
|
|
72
75
|
const configuredEntry = bffConfig?.effect?.entry;
|
|
73
76
|
if (configuredEntry) {
|
|
74
77
|
const sourceEntry = external_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_path_default().resolve(appRoot, configuredEntry);
|
|
75
78
|
if (productionRoot) {
|
|
76
79
|
const relativeEntry = relativeAppPath(appRoot, sourceEntry);
|
|
80
|
+
if (void 0 === relativeEntry || isDependencyPath(relativeEntry)) return resolveJsOrTsEntry(sourceEntry);
|
|
77
81
|
return relativeEntry ? resolveJsOrTsEntry(builtEntryPath(external_path_default().resolve(productionRoot, relativeEntry))) : void 0;
|
|
78
82
|
}
|
|
79
83
|
return resolveJsOrTsEntry(sourceEntry);
|
|
80
84
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const resolvedApiDirectory = external_path_default().resolve(appRoot, apiDirectory || utils_namespaceObject.API_DIR);
|
|
86
|
+
const productionApiDirectory = productionRoot ? void 0 !== relativeAppPath(productionRoot, resolvedApiDirectory) ? resolvedApiDirectory : (()=>{
|
|
87
|
+
const relativeApiDirectory = relativeAppPath(appRoot, resolvedApiDirectory);
|
|
88
|
+
if (isDependencyPath(relativeApiDirectory)) return resolvedApiDirectory;
|
|
89
|
+
return relativeApiDirectory ? external_path_default().resolve(productionRoot, relativeApiDirectory) : void 0;
|
|
90
|
+
})() : resolvedApiDirectory;
|
|
91
|
+
if (!productionApiDirectory) return;
|
|
92
|
+
return resolveJsOrTsEntry(external_path_default().resolve(productionApiDirectory, 'index'));
|
|
85
93
|
}
|
|
86
94
|
exports.resolveEffectAdapterEntryFile = __webpack_exports__.resolveEffectAdapterEntryFile;
|
|
87
95
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -32,23 +32,25 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
});
|
|
33
33
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
34
34
|
const external_safe_failure_js_namespaceObject = require("../../safe-failure.js");
|
|
35
|
-
|
|
35
|
+
function createEffectAdapterRuntimeErrorResponse(api, error, c) {
|
|
36
36
|
try {
|
|
37
37
|
const serverConfig = api.getServerConfig();
|
|
38
38
|
const onErrorHandler = serverConfig?.onError;
|
|
39
|
-
if (onErrorHandler) {
|
|
39
|
+
if (void 0 !== onErrorHandler) {
|
|
40
40
|
const onErrorContext = ensureJsonContext(c);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
return Promise.resolve(onErrorHandler(error instanceof Error ? error : new Error(String(error)), onErrorContext)).then((result)=>result instanceof Response ? result : (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error)).catch((configError)=>{
|
|
42
|
+
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${String(configError)}`);
|
|
43
|
+
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
utils_namespaceObject.logger.error(error instanceof Error ? error : new Error(String(error)));
|
|
44
47
|
} catch (configError) {
|
|
45
48
|
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
46
49
|
}
|
|
47
|
-
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error);
|
|
50
|
+
return Promise.resolve((0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error));
|
|
48
51
|
}
|
|
49
52
|
function ensureJsonContext(c) {
|
|
50
|
-
|
|
51
|
-
if ('function' == typeof maybeJsonContext.json) return c;
|
|
53
|
+
if ('json' in c && 'function' == typeof c.json) return c;
|
|
52
54
|
const headers = {
|
|
53
55
|
'content-type': 'application/json; charset=utf-8'
|
|
54
56
|
};
|
|
@@ -59,7 +61,7 @@ function ensureJsonContext(c) {
|
|
|
59
61
|
headers: extraHeaders
|
|
60
62
|
} : statusOrInit;
|
|
61
63
|
const responseHeaders = new Headers(headers);
|
|
62
|
-
if (responseInit.headers) new Headers(responseInit.headers).forEach((value, key)=>{
|
|
64
|
+
if (void 0 !== responseInit.headers) new Headers(responseInit.headers).forEach((value, key)=>{
|
|
63
65
|
responseHeaders.set(key, value);
|
|
64
66
|
});
|
|
65
67
|
return new Response(JSON.stringify(data), {
|
|
@@ -71,10 +71,10 @@ class EffectAdapter {
|
|
|
71
71
|
let mod;
|
|
72
72
|
try {
|
|
73
73
|
const { appDirectory } = this.api.getServerContext();
|
|
74
|
-
mod = await (0, effectSourceLoader_js_namespaceObject.loadEffectSourceModule)({
|
|
74
|
+
mod = await ((0, utils_namespaceObject.isProd)() ? (0, effectSourceLoader_js_namespaceObject.loadEffectBuiltModule)(entryFile) : (0, effectSourceLoader_js_namespaceObject.loadEffectSourceModule)({
|
|
75
75
|
resourcePath: entryFile,
|
|
76
76
|
appDir: appDirectory || external_path_default().dirname(entryFile)
|
|
77
|
-
});
|
|
77
|
+
}));
|
|
78
78
|
} catch (error) {
|
|
79
79
|
utils_namespaceObject.logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
80
80
|
this.handler = null;
|