@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
@@ -1,27 +1,91 @@
1
1
  import "node:module";
2
+ import { ModuleFederation } from "@module-federation/runtime";
2
3
  import { loadBackendFederationExpose } from "./entry.mjs";
4
+ import { createBackendFederationLoadEntryPlugin } from "./plugin.mjs";
3
5
  import { collectRemotes } from "./remotes.mjs";
4
- import { normalizeExpose } from "./utils.mjs";
5
- function exposeForRemoteRequest(expose) {
6
- return `./${normalizeExpose(expose)}`;
6
+ function _check_private_redeclaration(obj, privateCollection) {
7
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
7
8
  }
9
+ function _class_apply_descriptor_get(receiver, descriptor) {
10
+ if (descriptor.get) return descriptor.get.call(receiver);
11
+ return descriptor.value;
12
+ }
13
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
14
+ if (descriptor.set) descriptor.set.call(receiver, value);
15
+ else {
16
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
17
+ descriptor.value = value;
18
+ }
19
+ }
20
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
21
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
22
+ return privateMap.get(receiver);
23
+ }
24
+ function _class_private_field_get(receiver, privateMap) {
25
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
26
+ return _class_apply_descriptor_get(receiver, descriptor);
27
+ }
28
+ function _class_private_field_init(obj, privateMap, value) {
29
+ _check_private_redeclaration(obj, privateMap);
30
+ privateMap.set(obj, value);
31
+ }
32
+ function _class_private_field_set(receiver, privateMap, value) {
33
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
34
+ _class_apply_descriptor_set(receiver, descriptor, value);
35
+ return value;
36
+ }
37
+ let nextRuntimeId = 0;
8
38
  function parseRemoteRequest(request) {
9
39
  const [remoteName, ...exposeParts] = request.split('/');
10
- if (!remoteName || 0 === exposeParts.length) throw new Error(`[BFF][Effect] Invalid backend federation request ${request}.`);
11
- return {
12
- remoteName,
13
- expose: exposeForRemoteRequest(exposeParts.join('/'))
14
- };
40
+ if (void 0 === remoteName || 0 === remoteName.length || 0 === exposeParts.length) return;
41
+ return remoteName;
42
+ }
43
+ function createLocalEntryPlugin(options, remotes) {
44
+ return createBackendFederationLoadEntryPlugin({
45
+ resolveEntry (resolvedRemote) {
46
+ const remote = remotes.find((candidate)=>candidate.name === resolvedRemote.name);
47
+ if (void 0 === remote) return;
48
+ return {
49
+ get (expose) {
50
+ return ()=>loadBackendFederationExpose(remote, expose, options);
51
+ }
52
+ };
53
+ }
54
+ });
55
+ }
56
+ function isolateRegisteredRemoteEntries(remotes) {
57
+ const runtimeId = nextRuntimeId;
58
+ nextRuntimeId += 1;
59
+ return remotes.map((remote)=>({
60
+ ...remote,
61
+ entry: `${remote.entry}#modernjs-backend-runtime-${runtimeId}`
62
+ }));
63
+ }
64
+ var _remoteNames = /*#__PURE__*/ new WeakMap();
65
+ class BackendFederationRuntime extends ModuleFederation {
66
+ loadRemote(request, loadOptions) {
67
+ const remoteName = parseRemoteRequest(request);
68
+ if (void 0 === remoteName) return Promise.reject(new Error(`[BFF][Effect] Invalid backend federation request ${request}.`));
69
+ if (!_class_private_field_get(this, _remoteNames).has(remoteName)) return Promise.reject(new Error(`[BFF][Effect] Missing backend federation remote ${remoteName}.`));
70
+ return super.loadRemote(request, loadOptions);
71
+ }
72
+ constructor(options, remotes){
73
+ super({
74
+ name: options.hostName,
75
+ remotes: isolateRegisteredRemoteEntries(remotes),
76
+ shared: {},
77
+ plugins: [
78
+ createLocalEntryPlugin(options, remotes)
79
+ ]
80
+ }), _class_private_field_init(this, _remoteNames, {
81
+ writable: true,
82
+ value: void 0
83
+ });
84
+ _class_private_field_set(this, _remoteNames, new Set(remotes.map((remote)=>remote.name)));
85
+ }
15
86
  }
16
87
  function createBackendFederationRuntime(options) {
17
88
  const remotes = collectRemotes(options);
18
- return {
19
- async loadRemote (request) {
20
- const { remoteName, expose } = parseRemoteRequest(request);
21
- const remote = remotes.find((candidate)=>candidate.name === remoteName);
22
- if (!remote) throw new Error(`[BFF][Effect] Missing backend federation remote ${remoteName}.`);
23
- return loadBackendFederationExpose(remote, expose, options);
24
- }
25
- };
89
+ return new BackendFederationRuntime(options, remotes);
26
90
  }
27
91
  export { createBackendFederationRuntime };
@@ -0,0 +1,39 @@
1
+ import "node:module";
2
+ import { dispatchEffectBffRequestWithContext } from "./dispatch.mjs";
3
+ import { runWithEffectContext, useEffectContext, useOperationContext } from "./edge-context.mjs";
4
+ import { resolveEffectBffModuleHandler } from "./module.mjs";
5
+ export * from "./handler.mjs";
6
+ async function dispatchEffectBffRequest(handler, request, options = {}) {
7
+ return dispatchEffectBffRequestWithContext(handler, request, {
8
+ ...options,
9
+ runWithEffectContext: runWithEffectContext
10
+ });
11
+ }
12
+ async function createEffectBffEdgeDispatcher(options) {
13
+ const loaded = await resolveEffectBffModuleHandler(options.module, {
14
+ openapi: options.openapi,
15
+ dataPlatform: options.dataPlatform,
16
+ onWarning: options.onWarning
17
+ });
18
+ if (!loaded) throw new Error('[BFF][Effect] Invalid Effect edge module. Export defineEffectBff(...) or a { api, layer } HttpApi module.');
19
+ return {
20
+ dispatch: (request, dispatchOptions = {})=>dispatchEffectBffRequest(loaded.handler, request, {
21
+ ...dispatchOptions,
22
+ prefix: options.prefix,
23
+ onError: options.onError
24
+ }),
25
+ dispose: async ()=>{
26
+ await loaded.dispose?.();
27
+ }
28
+ };
29
+ }
30
+ const createEffectBffTestHandler = createEffectBffEdgeHandler;
31
+ async function createEffectBffEdgeHandler(options) {
32
+ const dispatcher = await createEffectBffEdgeDispatcher(options);
33
+ return {
34
+ handler: dispatcher.dispatch,
35
+ dispose: dispatcher.dispose
36
+ };
37
+ }
38
+ export { createEffectOperationContext } from "./operation-context.mjs";
39
+ export { createEffectBffEdgeDispatcher, createEffectBffEdgeHandler, createEffectBffTestHandler, dispatchEffectBffRequest, runWithEffectContext, useEffectContext, useOperationContext };
@@ -1,40 +1,3 @@
1
1
  import "node:module";
2
- import { dispatchEffectBffRequestWithContext } from "./dispatch.mjs";
3
- import { runWithEffectContext, useEffectContext, useOperationContext } from "./edge-context.mjs";
4
- import { resolveEffectBffModuleHandler } from "./module.mjs";
5
- export * from "./handler.mjs";
6
- async function dispatchEffectBffRequest(handler, request, options = {}) {
7
- return dispatchEffectBffRequestWithContext(handler, request, {
8
- ...options,
9
- runWithEffectContext: runWithEffectContext
10
- });
11
- }
12
- async function createEffectBffEdgeDispatcher(options) {
13
- const loaded = await resolveEffectBffModuleHandler(options.module, {
14
- openapi: options.openapi,
15
- dataPlatform: options.dataPlatform,
16
- onWarning: options.onWarning
17
- });
18
- if (!loaded) throw new Error('[BFF][Effect] Invalid Effect edge module. Export defineEffectBff(...) or a { api, layer } HttpApi module.');
19
- return {
20
- dispatch: (request, dispatchOptions = {})=>dispatchEffectBffRequest(loaded.handler, request, {
21
- ...dispatchOptions,
22
- prefix: options.prefix,
23
- onError: options.onError
24
- }),
25
- dispose: async ()=>{
26
- await loaded.dispose?.();
27
- }
28
- };
29
- }
30
- const createEffectBffTestHandler = createEffectBffEdgeHandler;
31
- async function createEffectBffEdgeHandler(options) {
32
- const dispatcher = await createEffectBffEdgeDispatcher(options);
33
- return {
34
- handler: dispatcher.dispatch,
35
- dispose: dispatcher.dispose
36
- };
37
- }
2
+ export * from "./edge-dispatcher.mjs";
38
3
  export { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, createBackendFederationLoadEntryPlugin, createBackendFederationRuntime, loadBackendFederatedEffectApi, validateExpectedBackendFederationIdentity } from "./backend-federation.mjs";
39
- export { createEffectOperationContext } from "./operation-context.mjs";
40
- export { createEffectBffEdgeDispatcher, createEffectBffEdgeHandler, createEffectBffTestHandler, dispatchEffectBffRequest, runWithEffectContext, useEffectContext, useOperationContext };
@@ -3,26 +3,27 @@ import { logger } from "@modern-js/utils";
3
3
  import { collectEffectEndpoints } from "../../runtime/effect/endpoint-contracts.mjs";
4
4
  import { renderEffectClientCode, renderEffectClientDeclaration } from "./rendering.mjs";
5
5
  import { getHttpApiRuntime, loadEffectApi } from "./runtime.mjs";
6
- async function generateEffectClient(options) {
7
- const api = await loadEffectApi({
6
+ function generateEffectClient(options) {
7
+ return loadEffectApi({
8
8
  appDir: options.appDir,
9
9
  resourcePath: options.resourcePath,
10
10
  onDependency: options.onDependency
11
+ }).then((api)=>{
12
+ if (null === api) {
13
+ logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
14
+ return null;
15
+ }
16
+ return getHttpApiRuntime().then((httpApiRuntime)=>{
17
+ const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
18
+ return {
19
+ code: renderEffectClientCode(endpoints, options),
20
+ declaration: renderEffectClientDeclaration(endpoints),
21
+ endpoints
22
+ };
23
+ });
11
24
  });
12
- if (!api) {
13
- logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
14
- return null;
15
- }
16
- const httpApiRuntime = await getHttpApiRuntime();
17
- const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
18
- return {
19
- code: renderEffectClientCode(endpoints, options),
20
- declaration: renderEffectClientDeclaration(endpoints),
21
- endpoints
22
- };
23
25
  }
24
- async function generateEffectClientCode(options) {
25
- const artifacts = await generateEffectClient(options);
26
- return artifacts ? artifacts.code : null;
26
+ function generateEffectClientCode(options) {
27
+ return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
27
28
  }
28
29
  export { generateEffectClient, generateEffectClientCode };
@@ -1,6 +1,5 @@
1
1
  import "node:module";
2
- import { findExists, fs } from "@modern-js/utils";
3
- import path from "path";
2
+ import { findExists, fs, upath } from "@modern-js/utils";
4
3
  const JS_OR_TS_EXTS = [
5
4
  '.js',
6
5
  '.jsx',
@@ -14,13 +13,13 @@ const JS_OR_TS_EXTS = [
14
13
  function resolveEffectEntryFile(options) {
15
14
  const { appDir, apiDir, effectEntry } = options;
16
15
  const resolveEntry = (entryWithoutExt)=>{
17
- if (path.extname(entryWithoutExt)) return fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
16
+ if ('' !== upath.extname(entryWithoutExt)) return fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
18
17
  return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`));
19
18
  };
20
- if (effectEntry) {
21
- const entryWithoutExt = path.isAbsolute(effectEntry) ? effectEntry : path.resolve(appDir, effectEntry);
19
+ if (void 0 !== effectEntry && '' !== effectEntry) {
20
+ const entryWithoutExt = upath.isAbsolute(effectEntry) ? effectEntry : upath.resolve(appDir, effectEntry);
22
21
  return resolveEntry(entryWithoutExt);
23
22
  }
24
- return resolveEntry(path.resolve(apiDir, 'index'));
23
+ return resolveEntry(upath.resolve(apiDir, 'index'));
25
24
  }
26
25
  export { resolveEffectEntryFile };
@@ -1,7 +1,6 @@
1
1
  import "node:module";
2
2
  import { deriveOperationVersion } from "@modern-js/bff-core";
3
- import { fs } from "@modern-js/utils";
4
- import path from "path";
3
+ import { fs, upath } from "@modern-js/utils";
5
4
  import { createEffectEndpointContractHash, ensureLeadingSlash, normalizeEffectPrefix } from "../../runtime/effect/endpoint-contracts.mjs";
6
5
  const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
7
6
  const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/plugin-bff/effect-client-runtime';
@@ -14,17 +13,17 @@ function isAbsoluteUrl(value) {
14
13
  }
15
14
  }
16
15
  function resolveBatchEndpoint(prefix, endpoint) {
17
- const value = endpoint || '/_data/batch';
16
+ const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
18
17
  if (isAbsoluteUrl(value)) return value;
19
18
  const normalizedPrefix = normalizeEffectPrefix(prefix);
20
19
  const normalizedEndpoint = ensureLeadingSlash(value);
21
- if (!normalizedPrefix) return normalizedEndpoint;
20
+ if ('' === normalizedPrefix) return normalizedEndpoint;
22
21
  if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
23
22
  return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
24
23
  }
25
24
  function getPackageInfo(appDir) {
26
25
  try {
27
- const packageJsonPath = path.resolve(appDir, './package.json');
26
+ const packageJsonPath = upath.resolve(appDir, './package.json');
28
27
  const packageJson = fs.readJSONSync(packageJsonPath);
29
28
  return {
30
29
  name: packageJson.name,
@@ -39,9 +38,9 @@ function renderEffectClientCode(endpoints, options) {
39
38
  const httpMethodDecider = options.httpMethodDecider || 'functionName';
40
39
  const packageInfo = getPackageInfo(options.appDir);
41
40
  const packageName = packageInfo.name;
42
- const dataPlatformAppNamespace = packageName || 'unknown-app';
43
- const requestId = 'bundle' === options.target ? packageName || process.env.npm_package_name : void 0;
44
- const normalizedRequestId = requestId || 'default';
41
+ const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
42
+ const requestId = 'bundle' === options.target ? void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
43
+ const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
45
44
  const operationVersion = deriveOperationVersion(packageInfo.version);
46
45
  const batchConfig = options.dataPlatformBatch;
47
46
  const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
@@ -58,7 +57,7 @@ function renderEffectClientCode(endpoints, options) {
58
57
  };
59
58
  const config = {
60
59
  appNamespace: dataPlatformAppNamespace,
61
- ...requestId ? {
60
+ ...void 0 !== requestId && '' !== requestId ? {
62
61
  requestId
63
62
  } : {},
64
63
  port: options.port,
@@ -72,7 +71,7 @@ function renderEffectClientCode(endpoints, options) {
72
71
  maxBatchSize: batchConfig?.maxBatchSize ?? 16,
73
72
  maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
74
73
  requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
75
- allowedMethods: batchConfig?.allowedMethods && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
74
+ allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
76
75
  'GET'
77
76
  ]
78
77
  }
@@ -1,36 +1,29 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
- import { compatibleRequire } from "@modern-js/utils";
4
- import path from "path";
3
+ import { compatibleRequire, upath } from "@modern-js/utils";
5
4
  import { extractHttpApiFromModule } from "../../runtime/effect/endpoint-contracts.mjs";
6
5
  import { loadEffectSourceModule } from "../effectSourceLoader.mjs";
7
6
  let httpApiRuntimePromise;
8
7
  function isRecord(value) {
9
8
  return 'object' == typeof value && null !== value;
10
9
  }
11
- async function getHttpApiRuntime() {
12
- if (!httpApiRuntimePromise) httpApiRuntimePromise = (async ()=>{
13
- let mod;
14
- try {
15
- mod = await compatibleRequire('effect/unstable/httpapi', false);
16
- } catch (error) {
17
- const message = error instanceof Error ? error.message : String(error);
18
- if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
19
- const effectPackageJson = require.resolve('effect/package.json');
20
- const effectHttpApiRuntimePath = path.join(path.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
21
- mod = await compatibleRequire(effectHttpApiRuntimePath, false);
22
- }
23
- if (isRecord(mod) && isRecord(mod.HttpApi)) {
24
- const maybeHttpApi = mod.HttpApi;
25
- if ('function' == typeof maybeHttpApi.isHttpApi && 'function' == typeof maybeHttpApi.reflect) return maybeHttpApi;
26
- }
10
+ function isHttpApiRuntime(value) {
11
+ return isRecord(value) && 'function' == typeof value.isHttpApi && 'function' == typeof value.reflect;
12
+ }
13
+ function getHttpApiRuntime() {
14
+ if (void 0 === httpApiRuntimePromise) httpApiRuntimePromise = compatibleRequire('effect/unstable/httpapi', false).catch((error)=>{
15
+ const message = error instanceof Error ? error.message : String(error);
16
+ if (!message.includes("Cannot find module 'effect/unstable/httpapi'")) throw error;
17
+ const effectPackageJson = require.resolve('effect/package.json');
18
+ const effectHttpApiRuntimePath = upath.join(upath.dirname(effectPackageJson), 'dist', 'unstable', 'httpapi', 'index.js');
19
+ return compatibleRequire(effectHttpApiRuntimePath, false);
20
+ }).then((mod)=>{
21
+ if (isRecord(mod) && isHttpApiRuntime(mod.HttpApi)) return mod.HttpApi;
27
22
  throw new Error('[BFF][Effect] Unable to resolve HttpApi runtime from effect/unstable/httpapi.');
28
- })();
23
+ });
29
24
  return httpApiRuntimePromise;
30
25
  }
31
- async function loadEffectApi(options) {
32
- const httpApiRuntime = await getHttpApiRuntime();
33
- const mod = await loadEffectSourceModule(options);
34
- return extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi);
26
+ function loadEffectApi(options) {
27
+ return getHttpApiRuntime().then((httpApiRuntime)=>loadEffectSourceModule(options).then((mod)=>extractHttpApiFromModule(mod, httpApiRuntime.isHttpApi)));
35
28
  }
36
29
  export { getHttpApiRuntime, loadEffectApi };
@@ -152,9 +152,7 @@ function externalizeInstalledDependencies(options) {
152
152
  pluginData: resolution.pluginData,
153
153
  sideEffects: resolution.sideEffects,
154
154
  suffix: resolution.suffix,
155
- warnings: resolution.warnings,
156
- watchDirs: resolution.watchDirs,
157
- watchFiles: resolution.watchFiles
155
+ warnings: resolution.warnings
158
156
  };
159
157
  }
160
158
  return {
@@ -169,9 +167,7 @@ function externalizeInstalledDependencies(options) {
169
167
  pluginData: resolution.pluginData,
170
168
  sideEffects: resolution.sideEffects,
171
169
  suffix: resolution.suffix,
172
- warnings: resolution.warnings,
173
- watchDirs: resolution.watchDirs,
174
- watchFiles: resolution.watchFiles
170
+ warnings: resolution.warnings
175
171
  };
176
172
  });
177
173
  }
@@ -209,6 +205,11 @@ function normalizeImportedModule(module) {
209
205
  if (1 === Object.keys(namespace).length && null !== commonJsModule && 'object' == typeof commonJsModule && true === commonJsModule.__esModule) return commonJsModule;
210
206
  return module;
211
207
  }
208
+ async function loadEffectBuiltModule(resourcePath) {
209
+ const canonicalPath = await node_fs.promises.realpath(node_path.resolve(resourcePath));
210
+ if (!await isEsmOnlyFile(canonicalPath)) return createRequire(canonicalPath)(canonicalPath);
211
+ return normalizeImportedModule(await dynamicImport(pathToFileURL(canonicalPath).href));
212
+ }
212
213
  async function loadEffectSourceModule(options) {
213
214
  const resourcePath = node_path.resolve(options.resourcePath);
214
215
  const appDir = node_path.resolve(options.appDir ?? node_path.dirname(resourcePath));
@@ -253,4 +254,4 @@ async function loadEffectSourceModule(options) {
253
254
  const revision = node_crypto.createHash('sha256').update(output).digest('hex');
254
255
  return normalizeImportedModule(await dynamicImport(`${pathToFileURL(outputPath).href}?v=${revision}`));
255
256
  }
256
- export { bundleEffectEntryForNode, loadEffectSourceModule };
257
+ export { bundleEffectEntryForNode, loadEffectBuiltModule, loadEffectSourceModule };
@@ -1,7 +1,7 @@
1
1
  import type { AppTools } from '@modern-js/app-tools';
2
2
  import type { CLIPluginAPI } from '@modern-js/plugin';
3
3
  export declare const createBffGenerator: (api: CLIPluginAPI<AppTools>) => {
4
- compileApi: () => Promise<void>;
4
+ compileApi: () => Promise<void | undefined>;
5
5
  generate: () => Promise<void>;
6
- handleCrossProjectInvocation: (isBuild?: boolean) => Promise<void>;
6
+ handleCrossProjectInvocation: (isBuild?: boolean) => Promise<void | undefined>;
7
7
  };
@@ -1,4 +1,6 @@
1
+ import type { AppTools } from '@modern-js/app-tools';
1
2
  type SerializedGlobalVars = Record<string, string>;
2
- export declare const serializeServerGlobalVars: (options: unknown) => SerializedGlobalVars;
3
- export declare const transformServerGlobalVars: (outputDirectories: string[], globalVars: SerializedGlobalVars) => Promise<void>;
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>;
4
6
  export {};
@@ -1,4 +1,4 @@
1
1
  import type { ServerPluginAPI } from '@modern-js/server-core';
2
2
  import { type ResolvedCrossProjectPolicy } from '../../../utils/crossProjectServerPolicy';
3
3
  import type { EffectApiModule } from '../module';
4
- export declare function resolveEffectAdapterCrossProjectPolicy(api: ServerPluginAPI, prefix: string, mod: EffectApiModule | null): Promise<ResolvedCrossProjectPolicy>;
4
+ export declare function resolveEffectAdapterCrossProjectPolicy(api: ServerPluginAPI, prefix: string, mod: EffectApiModule | null): Promise<ResolvedCrossProjectPolicy | undefined>;
@@ -1,3 +1,3 @@
1
- import type { ModuleFederation } from '@module-federation/runtime';
1
+ import { ModuleFederation } from '@module-federation/runtime';
2
2
  import type { BackendFederationRuntimeOptions } from './types';
3
3
  export declare function createBackendFederationRuntime(options: BackendFederationRuntimeOptions): ModuleFederation;
@@ -0,0 +1,26 @@
1
+ import { type DispatchEffectBffRequestOptions } from './dispatch';
2
+ import type { EffectBffOpenApiConfig, EffectDataPlatformValidationOptions } from './handler';
3
+ import { type EffectApiModule, type EffectBffRequestHandler } from './module';
4
+ import type { EffectContext } from './operation-context';
5
+ export { runWithEffectContext, useEffectContext, useOperationContext, } from './edge-context';
6
+ export * from './handler';
7
+ export { type CreateEffectOperationContextOptions, createEffectOperationContext, type EffectContext, } from './operation-context';
8
+ export type EffectBffEdgeDispatchOptions = Omit<DispatchEffectBffRequestOptions, 'runWithEffectContext'>;
9
+ export type EffectBffEdgeHandlerOptions = {
10
+ module: EffectApiModule;
11
+ prefix?: string;
12
+ openapi?: EffectBffOpenApiConfig;
13
+ dataPlatform?: EffectDataPlatformValidationOptions;
14
+ onError?: (error: unknown, context: EffectContext) => Promise<Response> | Response;
15
+ onWarning?: (message: string) => void;
16
+ };
17
+ export declare function dispatchEffectBffRequest(handler: EffectBffRequestHandler, request: Request, options?: EffectBffEdgeDispatchOptions): Promise<Response>;
18
+ export declare function createEffectBffEdgeDispatcher(options: EffectBffEdgeHandlerOptions): Promise<{
19
+ dispatch: (request: Request, dispatchOptions?: Omit<EffectBffEdgeDispatchOptions, 'prefix' | 'onError'>) => Promise<Response>;
20
+ dispose: () => Promise<void>;
21
+ }>;
22
+ export declare const createEffectBffTestHandler: typeof createEffectBffEdgeHandler;
23
+ export declare function createEffectBffEdgeHandler(options: EffectBffEdgeHandlerOptions): Promise<{
24
+ handler: (request: Request, dispatchOptions?: Omit<EffectBffEdgeDispatchOptions, 'prefix' | 'onError'>) => Promise<Response>;
25
+ dispose: () => Promise<void>;
26
+ }>;
@@ -1,27 +1,2 @@
1
- import { type DispatchEffectBffRequestOptions } from './dispatch';
2
- import type { EffectBffOpenApiConfig, EffectDataPlatformValidationOptions } from './handler';
3
- import { type EffectApiModule, type EffectBffRequestHandler } from './module';
4
- import type { EffectContext } from './operation-context';
5
1
  export { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, type BackendFederatedEffectApiModule, type BackendFederationEntryExports, type BackendFederationExpectedIdentity, type BackendFederationIdentityIssue, type BackendFederationIdentityLoadOptions, type BackendFederationLoadEntryPluginOptions, type BackendFederationRemote, type BackendFederationRuntimeOptions, createBackendFederationLoadEntryPlugin, createBackendFederationRuntime, loadBackendFederatedEffectApi, validateExpectedBackendFederationIdentity, } from './backend-federation';
6
- export { runWithEffectContext, useEffectContext, useOperationContext, } from './edge-context';
7
- export * from './handler';
8
- export { type CreateEffectOperationContextOptions, createEffectOperationContext, type EffectContext, } from './operation-context';
9
- export type EffectBffEdgeDispatchOptions = Omit<DispatchEffectBffRequestOptions, 'runWithEffectContext'>;
10
- export type EffectBffEdgeHandlerOptions = {
11
- module: EffectApiModule;
12
- prefix?: string;
13
- openapi?: EffectBffOpenApiConfig;
14
- dataPlatform?: EffectDataPlatformValidationOptions;
15
- onError?: (error: unknown, context: EffectContext) => Promise<Response> | Response;
16
- onWarning?: (message: string) => void;
17
- };
18
- export declare function dispatchEffectBffRequest(handler: EffectBffRequestHandler, request: Request, options?: EffectBffEdgeDispatchOptions): Promise<Response>;
19
- export declare function createEffectBffEdgeDispatcher(options: EffectBffEdgeHandlerOptions): Promise<{
20
- dispatch: (request: Request, dispatchOptions?: Omit<EffectBffEdgeDispatchOptions, 'prefix' | 'onError'>) => Promise<Response>;
21
- dispose: () => Promise<void>;
22
- }>;
23
- export declare const createEffectBffTestHandler: typeof createEffectBffEdgeHandler;
24
- export declare function createEffectBffEdgeHandler(options: EffectBffEdgeHandlerOptions): Promise<{
25
- handler: (request: Request, dispatchOptions?: Omit<EffectBffEdgeDispatchOptions, 'prefix' | 'onError'>) => Promise<Response>;
26
- dispose: () => Promise<void>;
27
- }>;
2
+ export * from './edge-dispatcher';
@@ -8,6 +8,16 @@ export declare function bundleEffectEntryForNode(options: {
8
8
  entryPath: string;
9
9
  format: 'cjs' | 'esm';
10
10
  }): Promise<void>;
11
+ /**
12
+ * Loads the relocatable artifact emitted by the production BFF build.
13
+ *
14
+ * Production entries have already been compiled and bundled by
15
+ * `bundleEffectEntryForNode`. Loading that artifact through the development
16
+ * source-graph bundler a second time changes its module format and can strip
17
+ * CommonJS runtime globals from bundled dependencies. Keep the built module's
18
+ * native Node boundary intact instead.
19
+ */
20
+ export declare function loadEffectBuiltModule(resourcePath: string): Promise<unknown>;
11
21
  /**
12
22
  * Loads an Effect source entry as native ESM while keeping its complete local
13
23
  * source graph observable by the framework watcher.
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.102",
20
+ "version": "3.5.0-ultramodern.103",
21
21
  "types": "./dist/types/cli.d.ts",
22
22
  "main": "./dist/cjs/cli.js",
23
23
  "exports": {
@@ -80,9 +80,22 @@
80
80
  },
81
81
  "./effect-edge": {
82
82
  "types": "./dist/types/runtime/effect/edge.d.ts",
83
+ "node": {
84
+ "import": "./dist/esm-node/runtime/effect/edge.mjs",
85
+ "require": "./dist/cjs/runtime/effect/edge.js"
86
+ },
83
87
  "import": "./dist/esm/runtime/effect/edge.mjs",
84
88
  "default": "./dist/esm/runtime/effect/edge.mjs"
85
89
  },
90
+ "./effect-edge/dispatcher": {
91
+ "types": "./dist/types/runtime/effect/edge-dispatcher.d.ts",
92
+ "node": {
93
+ "import": "./dist/esm-node/runtime/effect/edge-dispatcher.mjs",
94
+ "require": "./dist/cjs/runtime/effect/edge-dispatcher.js"
95
+ },
96
+ "import": "./dist/esm/runtime/effect/edge-dispatcher.mjs",
97
+ "default": "./dist/esm/runtime/effect/edge-dispatcher.mjs"
98
+ },
86
99
  "./effect-client": {
87
100
  "types": "./dist/types/runtime/effect-client/index.d.ts",
88
101
  "node": {
@@ -138,6 +151,9 @@
138
151
  "effect-edge": [
139
152
  "./dist/types/runtime/effect/edge.d.ts"
140
153
  ],
154
+ "effect-edge/dispatcher": [
155
+ "./dist/types/runtime/effect/edge-dispatcher.d.ts"
156
+ ],
141
157
  "effect-client": [
142
158
  "./dist/types/runtime/effect-client/index.d.ts"
143
159
  ],
@@ -153,13 +169,13 @@
153
169
  }
154
170
  },
155
171
  "dependencies": {
156
- "@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.5.0-ultramodern.102",
157
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.102",
158
- "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.102",
159
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.102",
160
- "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.5.0-ultramodern.102",
161
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.102",
162
- "@module-federation/runtime": "2.8.0",
172
+ "@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.5.0-ultramodern.103",
173
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.103",
174
+ "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.103",
175
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.103",
176
+ "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.5.0-ultramodern.103",
177
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.103",
178
+ "@module-federation/runtime": "2.8.2",
163
179
  "@opentelemetry/api": "1.9.1",
164
180
  "@opentelemetry/api-logs": "0.220.0",
165
181
  "@opentelemetry/resources": "2.9.0",
@@ -176,8 +192,8 @@
176
192
  "type-is": "^2.1.0"
177
193
  },
178
194
  "peerDependencies": {
179
- "@effect/opentelemetry": "4.0.0-beta.102",
180
- "effect": "4.0.0-beta.102"
195
+ "@effect/opentelemetry": "4.0.0-beta.107",
196
+ "effect": "4.0.0-beta.107"
181
197
  },
182
198
  "peerDependenciesMeta": {
183
199
  "@effect/opentelemetry": {
@@ -188,20 +204,20 @@
188
204
  }
189
205
  },
190
206
  "devDependencies": {
191
- "@effect/opentelemetry": "4.0.0-beta.102",
192
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.102",
193
- "@modern-js/bff-runtime": "npm:@bleedingdev/modern-js-bff-runtime@3.5.0-ultramodern.102",
194
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.102",
195
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.102",
196
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.102",
207
+ "@effect/opentelemetry": "4.0.0-beta.107",
208
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.103",
209
+ "@modern-js/bff-runtime": "npm:@bleedingdev/modern-js-bff-runtime@3.5.0-ultramodern.103",
210
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.103",
211
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.103",
212
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.103",
197
213
  "@rsbuild/core": "2.1.5",
198
214
  "@rslib/core": "0.23.2",
199
215
  "@scripts/rstest-config": "2.66.0",
200
- "@types/node": "^26.1.1",
216
+ "@types/node": "^26.2.0",
201
217
  "@types/qs": "^6.15.1",
202
218
  "@types/type-is": "^1.6.7",
203
219
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
204
- "effect": "4.0.0-beta.102",
220
+ "effect": "4.0.0-beta.107",
205
221
  "memfs": "^4.64.0",
206
222
  "typescript": "^7.0.2",
207
223
  "zod": "^4.4.3"