@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.102 → 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.
Files changed (62) hide show
  1. package/dist/cjs/cli/compress.js +1 -1
  2. package/dist/cjs/cli/generator.js +106 -108
  3. package/dist/cjs/cli/serverGlobalVars.js +43 -57
  4. package/dist/cjs/loader.js +1 -1
  5. package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +17 -12
  6. package/dist/cjs/runtime/effect/adapter/error-response.js +11 -9
  7. package/dist/cjs/runtime/effect/adapter.js +2 -2
  8. package/dist/cjs/runtime/effect/backend-federation/load.js +26 -17
  9. package/dist/cjs/runtime/effect/backend-federation/plugin.js +12 -2
  10. package/dist/cjs/runtime/effect/backend-federation/remotes.js +5 -4
  11. package/dist/cjs/runtime/effect/backend-federation/runtime.js +80 -16
  12. package/dist/cjs/runtime/effect/edge-dispatcher.js +148 -0
  13. package/dist/cjs/runtime/effect/edge.js +19 -100
  14. package/dist/cjs/utils/effect-client-generator/generator.js +17 -16
  15. package/dist/cjs/utils/effect-client-generator/paths.js +4 -15
  16. package/dist/cjs/utils/effect-client-generator/rendering.js +8 -19
  17. package/dist/cjs/utils/effect-client-generator/runtime.js +15 -32
  18. package/dist/cjs/utils/effectSourceLoader.js +10 -6
  19. package/dist/esm/cli/compress.mjs +1 -1
  20. package/dist/esm/cli/generator.mjs +107 -108
  21. package/dist/esm/cli/serverGlobalVars.mjs +44 -48
  22. package/dist/esm/loader.mjs +1 -1
  23. package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +17 -12
  24. package/dist/esm/runtime/effect/adapter/error-response.mjs +11 -9
  25. package/dist/esm/runtime/effect/adapter.mjs +3 -3
  26. package/dist/esm/runtime/effect/backend-federation/load.mjs +26 -17
  27. package/dist/esm/runtime/effect/backend-federation/plugin.mjs +12 -2
  28. package/dist/esm/runtime/effect/backend-federation/remotes.mjs +5 -4
  29. package/dist/esm/runtime/effect/backend-federation/runtime.mjs +80 -16
  30. package/dist/esm/runtime/effect/edge-dispatcher.mjs +38 -0
  31. package/dist/esm/runtime/effect/edge.mjs +1 -38
  32. package/dist/esm/utils/effect-client-generator/generator.mjs +17 -16
  33. package/dist/esm/utils/effect-client-generator/paths.mjs +5 -6
  34. package/dist/esm/utils/effect-client-generator/rendering.mjs +9 -10
  35. package/dist/esm/utils/effect-client-generator/runtime.mjs +16 -23
  36. package/dist/esm/utils/effectSourceLoader.mjs +8 -7
  37. package/dist/esm-node/cli/compress.mjs +1 -1
  38. package/dist/esm-node/cli/generator.mjs +107 -108
  39. package/dist/esm-node/cli/serverGlobalVars.mjs +44 -48
  40. package/dist/esm-node/loader.mjs +1 -1
  41. package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +17 -12
  42. package/dist/esm-node/runtime/effect/adapter/error-response.mjs +11 -9
  43. package/dist/esm-node/runtime/effect/adapter.mjs +3 -3
  44. package/dist/esm-node/runtime/effect/backend-federation/load.mjs +26 -17
  45. package/dist/esm-node/runtime/effect/backend-federation/plugin.mjs +12 -2
  46. package/dist/esm-node/runtime/effect/backend-federation/remotes.mjs +5 -4
  47. package/dist/esm-node/runtime/effect/backend-federation/runtime.mjs +80 -16
  48. package/dist/esm-node/runtime/effect/edge-dispatcher.mjs +39 -0
  49. package/dist/esm-node/runtime/effect/edge.mjs +1 -38
  50. package/dist/esm-node/utils/effect-client-generator/generator.mjs +17 -16
  51. package/dist/esm-node/utils/effect-client-generator/paths.mjs +5 -6
  52. package/dist/esm-node/utils/effect-client-generator/rendering.mjs +9 -10
  53. package/dist/esm-node/utils/effect-client-generator/runtime.mjs +16 -23
  54. package/dist/esm-node/utils/effectSourceLoader.mjs +8 -7
  55. package/dist/types/cli/generator.d.ts +2 -2
  56. package/dist/types/cli/serverGlobalVars.d.ts +4 -2
  57. package/dist/types/runtime/effect/adapter/cross-project-policy.d.ts +1 -1
  58. package/dist/types/runtime/effect/backend-federation/runtime.d.ts +1 -1
  59. package/dist/types/runtime/effect/edge-dispatcher.d.ts +26 -0
  60. package/dist/types/runtime/effect/edge.d.ts +1 -26
  61. package/dist/types/utils/effectSourceLoader.d.ts +10 -0
  62. package/package.json +34 -18
@@ -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 (!devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
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,121 +63,121 @@ const effectEntryExtensions = [
65
63
  '.cts'
66
64
  ];
67
65
  function resolveEffectSourceEntry(appDirectory, apiDirectory, configuredEntry) {
68
- const entry = configuredEntry ? external_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_path_default().resolve(appDirectory, configuredEntry) : external_path_default().resolve(apiDirectory, 'index');
69
- return external_path_default().extname(entry) ? entry : effectEntryExtensions.map((extension)=>`${entry}${extension}`).find((candidate)=>utils_namespaceObject.fs.existsSync(candidate));
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 (!sourceEntry) return;
73
- const relativeEntry = external_path_default().relative(appDirectory, sourceEntry);
74
- if ('..' === relativeEntry || relativeEntry.startsWith(`..${external_path_default().sep}`)) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
75
- const builtEntry = external_path_default().resolve(distDirectory, relativeEntry).replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
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 = async ()=>{
80
- const { appDirectory, distDirectory, apiDirectory, bffRuntimeFramework, sharedDirectory, moduleType } = api.getAppContext();
81
- const modernConfig = api.getNormalizedConfig();
82
- const distDir = external_path_default().resolve(distDirectory);
83
- const apiDir = apiDirectory || external_path_default().resolve(appDirectory, utils_namespaceObject.API_DIR);
84
- const sharedDir = sharedDirectory || external_path_default().resolve(appDirectory, utils_namespaceObject.SHARED_DIR);
85
- const tsconfigPath = (0, utils_namespaceObject.resolveServerTsconfig)(appDirectory, modernConfig?.server?.tsconfigPath);
86
- const sourceDirs = [];
87
- if (await utils_namespaceObject.fs.pathExists(apiDir)) sourceDirs.push(apiDir);
88
- if (await utils_namespaceObject.fs.pathExists(sharedDir)) sourceDirs.push(sharedDir);
89
- const { alias, globalVars } = modernConfig.source;
90
- const { alias: resolveAlias } = modernConfig.resolve;
91
- if (sourceDirs.length > 0) {
92
- const combinedAlias = [].concat(alias ?? []).concat(resolveAlias ?? []);
93
- const serializedGlobalVars = (0, external_serverGlobalVars_js_namespaceObject.serializeServerGlobalVars)(globalVars);
94
- await (0, server_utils_namespaceObject.compile)(appDirectory, {
95
- alias: combinedAlias
96
- }, {
97
- sourceDirs,
98
- distDir,
99
- tsconfigPath,
100
- moduleType,
101
- throwErrorInsteadOfExit: true
102
- });
103
- await (0, external_serverGlobalVars_js_namespaceObject.transformServerGlobalVars)(sourceDirs.map((sourceDir)=>external_path_default().resolve(distDir, external_path_default().relative(appDirectory, sourceDir))), serializedGlobalVars);
104
- if ('effect' === bffRuntimeFramework) {
105
- const sourceEntry = resolveEffectSourceEntry(appDirectory, apiDir, modernConfig.bff?.effect?.entry);
106
- const builtEntry = resolveBuiltEffectEntry(appDirectory, distDir, sourceEntry);
107
- if (!builtEntry) throw new Error(`Effect BFF entry was not emitted into ${distDir}: ${sourceEntry ?? external_path_default().resolve(apiDir, 'index')}`);
108
- await (0, effectSourceLoader_js_namespaceObject.bundleEffectEntryForNode)({
109
- appDir: appDirectory,
110
- entryPath: builtEntry,
111
- format: 'module' === moduleType ? 'esm' : 'cjs'
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 packageJson = utils_namespaceObject.fs.readJSONSync(external_path_default().resolve(appDirectory, 'package.json'));
134
- const requestId = packageJson.name || process.env.npm_package_name;
135
- const operationContracts = existLambda ? (0, bff_core_namespaceObject.buildOperationContractMap)({
136
- handlers: await apiRouter.getApiHandlers(),
137
- requestId,
138
- operationVersion: (0, bff_core_namespaceObject.deriveOperationVersion)(packageJson.version)
139
- }) : {};
140
- const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
141
- const relativeApiPath = external_path_default().relative(appDirectory, apiDirectory);
142
- const relativeLambdaPath = external_path_default().relative(appDirectory, lambdaDir);
143
- const sourceEffectEntry = 'effect' === bffRuntimeFramework ? resolveEffectSourceEntry(appDirectory, apiDirectory, bff?.effect?.entry) : void 0;
144
- const relativeEffectEntry = sourceEffectEntry ? external_path_default().relative(appDirectory, sourceEffectEntry).replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js') : '';
145
- await pluginGenerator_js_default()({
146
- prefix,
147
- appDirectory,
148
- relativeDistPath,
149
- relativeApiPath,
150
- relativeLambdaPath,
151
- runtimeFramework: 'hono' === bffRuntimeFramework ? 'hono' : 'effect',
152
- relativeEffectEntry,
153
- operationContracts
114
+ });
154
115
  });
155
- await 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
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
+ });
169
175
  });
170
- await runtimeGenerator_js_default()({
171
- runtime,
172
- appDirectory,
173
- relativeDistPath
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());
174
180
  });
175
- };
176
- const handleCrossProjectInvocation = async (isBuild = false)=>{
177
- const { bff } = api.getNormalizedConfig();
178
- if (bff?.crossProject) {
179
- if (!isBuild) await compileApi();
180
- await generate();
181
- }
182
- };
183
181
  return {
184
182
  compileApi,
185
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 = async (directory)=>{
53
- const entries = await utils_namespaceObject.fs.readdir(directory, {
54
- withFileTypes: true
55
- });
56
- const nested = await Promise.all(entries.map(async (entry)=>{
57
- const absolutePath = external_path_default().join(directory, entry.name);
58
- if (entry.isDirectory()) return collectJavaScriptFiles(absolutePath);
59
- return /\.(?:c|m)?js$/u.test(entry.name) ? [
60
- absolutePath
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 = async (outputDirectories, globalVars)=>{
87
- if (0 === Object.keys(globalVars).length) return;
88
- const existingDirectories = (await Promise.all(outputDirectories.map(async (directory)=>await utils_namespaceObject.fs.pathExists(directory) ? directory : void 0))).filter((directory)=>Boolean(directory));
89
- const files = (await Promise.all(existingDirectories.map(collectJavaScriptFiles))).flat();
90
- const releaseIdentityBanner = RELEASE_IDENTITY_GLOBAL_NAMES.every((name)=>Object.hasOwn(globalVars, name)) ? `${RELEASE_IDENTITY_GLOBAL_NAMES.map((name)=>`void ${globalVars[name]};`).join('')}\n` : '';
91
- await Promise.all(files.map(async (filename)=>{
92
- const source = await utils_namespaceObject.fs.readFile(filename, 'utf8');
93
- const sourceMapFilename = `${filename}.map`;
94
- const sourceMapExists = await utils_namespaceObject.fs.pathExists(sourceMapFilename);
95
- const inputSourceMap = sourceMapExists ? await utils_namespaceObject.fs.readFile(sourceMapFilename, 'utf8') : void 0;
96
- const result = await (0, core_namespaceObject.transform)(`${releaseIdentityBanner}${source}`, {
97
- filename,
98
- inputSourceMap,
99
- sourceMaps: sourceMapExists,
100
- jsc: {
101
- parser: {
102
- syntax: "ecmascript"
103
- },
104
- preserveAllComments: true,
105
- target: 'es2022',
106
- transform: {
107
- optimizer: {
108
- globals: {
109
- vars: globalVars
110
- }
111
- }
112
- }
113
- }
114
- });
115
- await utils_namespaceObject.fs.writeFile(filename, result.code);
116
- if (sourceMapExists && result.map) await utils_namespaceObject.fs.writeFile(sourceMapFilename, result.map);
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 === [
@@ -68,7 +68,7 @@ async function transformEffectRuntimeSource(source, filename) {
68
68
  function createEffectWorkerRuntimeWrapper(resourcePath) {
69
69
  const sourceRequest = `${resourcePath}?${EFFECT_BFF_WORKER_RUNTIME_SOURCE_QUERY}`;
70
70
  return `import * as effectBffModule from ${JSON.stringify(sourceRequest)};
71
- import { createEffectBffEdgeDispatcher } from '@modern-js/plugin-bff/effect-edge';
71
+ import { createEffectBffEdgeDispatcher } from '@modern-js/plugin-bff/effect-edge/dispatcher';
72
72
 
73
73
  export const __modern_create_effect_bff_dispatcher = options =>
74
74
  createEffectBffEdgeDispatcher({
@@ -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
- async function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
38
- let contractSources = [];
39
- if (mod) try {
40
- const effectApi = await (0, external_endpoint_contracts_js_namespaceObject.extractHttpApiFromModule)(mod, httpapi_namespaceObject.HttpApi.isHttpApi);
41
- if (effectApi) {
42
- const reflect = (apiValue, handlers)=>httpapi_namespaceObject.HttpApi.reflect(apiValue, {
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
- contractSources = (0, external_endpoint_contracts_js_namespaceObject.toOperationContractSources)((0, external_endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(reflect, effectApi, prefix));
46
+ };
47
+ return (0, external_endpoint_contracts_js_namespaceObject.toOperationContractSources)((0, external_endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(reflect, effectApi, prefix));
47
48
  }
48
- } catch (error) {
49
+ return [];
50
+ }).catch((error)=>{
49
51
  utils_namespaceObject.logger.warn(`[BFF][Effect] Failed reflect HttpApi endpoints cross-project policy: ${String(error)}`);
50
- }
51
- const policy = (0, crossProjectServerPolicy_js_namespaceObject.resolveAdapterCrossProjectPolicy)(api, contractSources);
52
- if (policy?.enabled && 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.');
53
- return policy;
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 === [
@@ -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
- async function createEffectAdapterRuntimeErrorResponse(api, error, c) {
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
- const result = await onErrorHandler(error instanceof Error ? error : new Error(String(error)), onErrorContext);
42
- if (result instanceof Response) return result;
43
- } else utils_namespaceObject.logger.error(error);
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
- const maybeJsonContext = c;
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;
@@ -31,31 +31,40 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  loadBackendFederatedEffectApi: ()=>loadBackendFederatedEffectApi
32
32
  });
33
33
  const universal_namespaceObject = require("@modern-js/utils/universal");
34
+ const Effect_namespaceObject = require("effect/Effect");
35
+ const Logger_namespaceObject = require("effect/Logger");
34
36
  const external_identity_js_namespaceObject = require("./identity.js");
35
37
  const external_runtime_js_namespaceObject = require("./runtime.js");
36
38
  const external_utils_js_namespaceObject = require("./utils.js");
37
39
  const LEGACY_LOAD_WARNING = '[BFF][Effect] loadBackendFederatedEffectApi was called without an expected delivery-unit identity (expected.unitId + expected.buildMarker). Identity-less public backend loads are deprecated (ADR-0019/MV-G23) and will be rejected in a future major.';
38
- async function loadBackendFederatedEffectApi(options) {
40
+ const legacyWarningLogger = Logger_namespaceObject.withLeveledConsole(Logger_namespaceObject.formatLogFmt);
41
+ function warnLegacyLoad() {
42
+ Effect_namespaceObject.runSync(Effect_namespaceObject.provideService(Effect_namespaceObject.logWarning(LEGACY_LOAD_WARNING), Logger_namespaceObject.CurrentLoggers, new Set([
43
+ legacyWarningLogger
44
+ ])));
45
+ }
46
+ function loadBackendFederatedEffectApi(options) {
39
47
  const remoteName = options.remote?.name ?? options.remoteName;
40
- if (!remoteName) throw new Error('[BFF][Effect] Missing backend federation remote name.');
41
- if (void 0 === options.expected) console.warn(LEGACY_LOAD_WARNING);
48
+ if (void 0 === remoteName || 0 === remoteName.length) return Promise.reject(new Error('[BFF][Effect] Missing backend federation remote name.'));
49
+ if (void 0 === options.expected) warnLegacyLoad();
42
50
  const runtime = options.runtime ?? (0, external_runtime_js_namespaceObject.createBackendFederationRuntime)(options);
43
51
  const expose = options.expose ?? options.remote?.expose ?? universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE;
44
52
  const remoteRequest = `${remoteName}/${(0, external_utils_js_namespaceObject.normalizeExpose)(expose)}`;
45
- const loaded = await runtime.loadRemote(remoteRequest);
46
- if (!(0, external_utils_js_namespaceObject.isRecord)(loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must load an object module.`);
47
- const backendContract = loaded.backendFederationContract;
48
- if (!(0, external_utils_js_namespaceObject.isRecord)(backendContract) || true !== backendContract.strictEffectApproach) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (strictEffectApproach: true).`);
49
- if ('effect' !== backendContract.runtimeFramework) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (runtimeFramework: "effect").`);
50
- if ('string' == typeof backendContract.name && backendContract.name !== remoteName) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} metadata name mismatch: expected ${remoteName}, received ${backendContract.name}.`);
51
- if (!('runtime' in loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose api and runtime.`);
52
- if (void 0 !== options.expected) {
53
- const issues = (0, external_identity_js_namespaceObject.validateExpectedBackendFederationIdentity)(loaded, options.expected, {
54
- allowMissingIdentityMetadata: true === options.allowMissingIdentityMetadata
55
- });
56
- if (issues.length > 0) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} delivery-unit identity mismatch: ${(0, external_identity_js_namespaceObject.formatBackendFederationIdentityIssues)(issues)}.`);
57
- }
58
- return loaded;
53
+ return runtime.loadRemote(remoteRequest).then((loaded)=>{
54
+ if (!(0, external_utils_js_namespaceObject.isRecord)(loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must load an object module.`);
55
+ const backendContract = loaded.backendFederationContract;
56
+ if (!(0, external_utils_js_namespaceObject.isRecord)(backendContract) || true !== backendContract.strictEffectApproach) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (strictEffectApproach: true).`);
57
+ if ('effect' !== backendContract.runtimeFramework) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose strict Effect metadata (runtimeFramework: "effect").`);
58
+ if ('string' == typeof backendContract.name && backendContract.name !== remoteName) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} metadata name mismatch: expected ${remoteName}, received ${backendContract.name}.`);
59
+ if (!('runtime' in loaded)) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} must expose api and runtime.`);
60
+ if (void 0 !== options.expected) {
61
+ const issues = (0, external_identity_js_namespaceObject.validateExpectedBackendFederationIdentity)(loaded, options.expected, {
62
+ allowMissingIdentityMetadata: true === options.allowMissingIdentityMetadata
63
+ });
64
+ if (issues.length > 0) throw new Error(`[BFF][Effect] Backend federation expose ${remoteRequest} delivery-unit identity mismatch: ${(0, external_identity_js_namespaceObject.formatBackendFederationIdentityIssues)(issues)}.`);
65
+ }
66
+ return loaded;
67
+ });
59
68
  }
60
69
  exports.loadBackendFederatedEffectApi = __webpack_exports__.loadBackendFederatedEffectApi;
61
70
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -30,13 +30,23 @@ __webpack_require__.r(__webpack_exports__);
30
30
  function createBackendFederationLoadEntryPlugin(options) {
31
31
  return {
32
32
  name: 'modernjs-backend-federation-load-entry',
33
- async loadEntry ({ remoteInfo }) {
34
- return options.resolveEntry({
33
+ loadEntry ({ remoteInfo }) {
34
+ return Promise.resolve(options.resolveEntry({
35
35
  name: remoteInfo.name,
36
36
  entry: remoteInfo.entry,
37
37
  type: remoteInfo.type,
38
38
  entryGlobalName: remoteInfo.entryGlobalName,
39
39
  shareScope: remoteInfo.shareScope
40
+ })).then((entry)=>{
41
+ if (void 0 === entry) return;
42
+ return {
43
+ get (id) {
44
+ return ()=>Promise.resolve(entry.get(id)).then((factory)=>factory());
45
+ },
46
+ init (...args) {
47
+ return entry.init?.(...args);
48
+ }
49
+ };
40
50
  });
41
51
  }
42
52
  };
@@ -31,10 +31,11 @@ function collectRemotes(options) {
31
31
  const remotes = [
32
32
  ...options.remotes ?? []
33
33
  ];
34
- if (options.remote) {
35
- const existingIndex = remotes.findIndex((remote)=>remote.name === options.remote?.name);
36
- if (existingIndex >= 0) remotes[existingIndex] = options.remote;
37
- else remotes.push(options.remote);
34
+ const configuredRemote = options.remote;
35
+ if (void 0 !== configuredRemote) {
36
+ const existingIndex = remotes.findIndex((remote)=>remote.name === configuredRemote.name);
37
+ if (existingIndex >= 0) remotes[existingIndex] = configuredRemote;
38
+ else remotes.push(configuredRemote);
38
39
  }
39
40
  return remotes;
40
41
  }