@vercel/microfrontends 1.1.1-canary.2 → 1.1.1-canary.4
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/bin/cli.cjs +303 -512
- package/dist/config.cjs +43 -71
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +153 -4
- package/dist/config.js +43 -71
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +296 -489
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +286 -479
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +326 -511
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +312 -497
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +295 -485
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +14 -20
- package/dist/microfrontends/server.js +285 -475
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/next/config.cjs +297 -498
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +287 -488
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +2 -0
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +13 -3
- package/dist/next/endpoints.js +1 -0
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +58 -171
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +2 -4
- package/dist/next/middleware.js +58 -171
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +44 -73
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +44 -73
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/schema.cjs +2 -9
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +3 -4
- package/dist/schema.js +1 -7
- package/dist/schema.js.map +1 -1
- package/dist/{types-6ee19ccc.d.ts → types-54064641.d.ts} +2 -13
- package/dist/{types-73527280.d.ts → types-a4add5ab.d.ts} +1 -1
- package/dist/{types-74e3336c.d.ts → types-f1260e44.d.ts} +1 -1
- package/dist/utils/mfe-port.cjs +300 -492
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +286 -478
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +49 -37
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +49 -37
- package/dist/validation.js.map +1 -1
- package/package.json +2 -9
- package/schema/schema.json +0 -33
- package/dist/index-7e69650e.d.ts +0 -165
- package/dist/microfrontends.cjs +0 -962
- package/dist/microfrontends.cjs.map +0 -1
- package/dist/microfrontends.d.ts +0 -45
- package/dist/microfrontends.js +0 -935
- package/dist/microfrontends.js.map +0 -1
package/dist/next/endpoints.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/next/endpoints/index.ts
|
|
21
21
|
var endpoints_exports = {};
|
|
22
22
|
__export(endpoints_exports, {
|
|
23
|
+
getWellKnownClientData: () => getWellKnownClientData,
|
|
23
24
|
handleClientConfigForPagesRouter: () => handleClientConfigForPagesRouter,
|
|
24
25
|
wellKnownNextjsClientConfigAppRoute: () => wellKnownNextjsClientConfigAppRoute
|
|
25
26
|
});
|
|
@@ -144,6 +145,7 @@ async function handleClientConfigForPagesRouter(res, flagValues) {
|
|
|
144
145
|
}
|
|
145
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
147
|
0 && (module.exports = {
|
|
148
|
+
getWellKnownClientData,
|
|
147
149
|
handleClientConfigForPagesRouter,
|
|
148
150
|
wellKnownNextjsClientConfigAppRoute
|
|
149
151
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import type { NextApiResponse } from 'next';\nimport { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the microfrontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\n/**\n * A Next.js Pages Router API to export the microfrontends client config data to the client.\n *\n * @example In the `pages/api/.well-known/vercel/microfrontends/client-config/index.ts` file,\n * add this code:\n * ```\n * import { handleClientConfigForPagesRouter } from '@vercel/microfrontends/next/endpoints';\n * import type { NextApiResponse } from 'next';\n *\n * async function handler(\n * _,\n * res: NextApiResponse,\n * ): Promise<void> {\n * await handleClientConfigForPagesRouter(res, {\n * flagValue: () => Promise.resolve(true)\n * });\n * }\n * ```\n *\n * Then also make sure to add the following rewrite rule to your `next.config.js` file:\n * ```\n * rewrites: () =>\n * Promise.resolve([\n * {\n * source: '/.well-known/vercel/microfrontends/client-config',\n * destination: '/api/.well-known/vercel/microfrontends/client-config',\n * },\n * ]),\n * ```\n */\nexport async function handleClientConfigForPagesRouter(\n res: NextApiResponse,\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<void> {\n const clientData = await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n );\n res.status(200).json(clientData);\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA6B;;;ACD7B,4BAA6B;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,MAAM,oBAAoB;AAC5B,iBAAW,OAAO,OAAO,OAAO,OAAO,YAAY,GAAG;AACpD,YAAI,IAAI,SAAS;AACf,cAAI,UAAU,IAAI,QAAQ,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QACL,QACA,MAC2B;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO,IAAI;AAAA,MACT,KAAK,MAAM,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ,OA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AI,UAAU,MAAM;AAClB,cAAM,WAAW,UAAU;AAC3B,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,UAAU;AAAA,EACxB;AAEA,SAAO;AAAA,IACL,QAAQ,OAAO,UAAU;AAAA,EAC3B;AACF;;;AFhCA,eAAsB,oCACpB,YACuB;AACvB,SAAO,2BAAa;AAAA,IAClB,MAAM;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAgCA,eAAsB,iCACpB,KACA,YACe;AACf,QAAM,aAAa,MAAM;AAAA,IACvB,QAAQ,IAAI;AAAA,IACZ;AAAA,EACF;AACA,MAAI,OAAO,GAAG,EAAE,KAAK,UAAU;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import type { NextApiResponse } from 'next';\nimport { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the microfrontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\n/**\n * A Next.js Pages Router API to export the microfrontends client config data to the client.\n *\n * @example In the `pages/api/.well-known/vercel/microfrontends/client-config/index.ts` file,\n * add this code:\n * ```\n * import { handleClientConfigForPagesRouter } from '@vercel/microfrontends/next/endpoints';\n * import type { NextApiResponse } from 'next';\n *\n * async function handler(\n * _,\n * res: NextApiResponse,\n * ): Promise<void> {\n * await handleClientConfigForPagesRouter(res, {\n * flagValue: () => Promise.resolve(true)\n * });\n * }\n * ```\n *\n * Then also make sure to add the following rewrite rule to your `next.config.js` file:\n * ```\n * rewrites: () =>\n * Promise.resolve([\n * {\n * source: '/.well-known/vercel/microfrontends/client-config',\n * destination: '/api/.well-known/vercel/microfrontends/client-config',\n * },\n * ]),\n * ```\n */\nexport async function handleClientConfigForPagesRouter(\n res: NextApiResponse,\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<void> {\n const clientData = await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n );\n res.status(200).json(clientData);\n}\n\nexport { getWellKnownClientData };\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA6B;;;ACD7B,4BAA6B;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,MAAM,oBAAoB;AAC5B,iBAAW,OAAO,OAAO,OAAO,OAAO,YAAY,GAAG;AACpD,YAAI,IAAI,SAAS;AACf,cAAI,UAAU,IAAI,QAAQ,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QACL,QACA,MAC2B;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO,IAAI;AAAA,MACT,KAAK,MAAM,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ,OAA2C;AACjD,WACE,KAAK,UAAU,KAAK,YAAY,MAAM,KAAK,UAAU,MAAM,YAAY;AAAA,EAE3E;AAAA,EAEA,0BAA0B,MAA6B;AACrD,QAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AACzB,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,QAAI,KAAK,UAAU,IAAI,GAAG;AACxB,aAAO,KAAK,UAAU,IAAI;AAAA,IAC5B;AAEA,UAAM,WAAW,IAAI,IAAI,MAAM,qBAAqB,EAAE;AACtD,eAAW,CAAC,MAAM,WAAW,KAAK,OAAO,QAAQ,KAAK,YAAY,GAAG;AACnE,UAAI,YAAY,SAAS;AACvB,mBAAW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AsB,oCACpB,YACuB;AACvB,SAAO,2BAAa;AAAA,IAClB,MAAM;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAgCA,eAAsB,iCACpB,KACA,YACe;AACf,QAAM,aAAa,MAAM;AAAA,IACvB,QAAQ,IAAI;AAAA,IACZ;AAAA,EACF;AACA,MAAI,OAAO,GAAG,EAAE,KAAK,UAAU;AACjC;","names":[]}
|
package/dist/next/endpoints.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextApiResponse } from 'next';
|
|
2
2
|
import { NextResponse } from 'next/server';
|
|
3
|
-
import { C as ClientConfig } from '../types-
|
|
4
|
-
import '../types-
|
|
3
|
+
import { C as ClientConfig } from '../types-f1260e44.js';
|
|
4
|
+
import '../types-54064641.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Data that is returned from the `.well-known/vercel/microfrontends/client-config`
|
|
@@ -12,6 +12,16 @@ interface WellKnownClientData {
|
|
|
12
12
|
config: ClientConfig;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Returns data used by the client to ensure that navigations across
|
|
17
|
+
* microfrontend boundaries are routed and prefetched correctly. The client
|
|
18
|
+
* configuration is safe to expose to users.
|
|
19
|
+
*
|
|
20
|
+
* This data should be exposed in a `.well-known/vercel/microfrontends/client-config`
|
|
21
|
+
* endpoint.
|
|
22
|
+
*/
|
|
23
|
+
declare function getWellKnownClientData(clientConfig: string | undefined, flagValues?: Record<string, () => Promise<boolean>>): Promise<WellKnownClientData>;
|
|
24
|
+
|
|
15
25
|
/**
|
|
16
26
|
* A Next.js App Router API handler to export the microfrontends client config
|
|
17
27
|
* data.
|
|
@@ -55,4 +65,4 @@ declare function wellKnownNextjsClientConfigAppRoute(flagValues: Record<string,
|
|
|
55
65
|
*/
|
|
56
66
|
declare function handleClientConfigForPagesRouter(res: NextApiResponse, flagValues: Record<string, () => Promise<boolean>>): Promise<void>;
|
|
57
67
|
|
|
58
|
-
export { WellKnownClientData, handleClientConfigForPagesRouter, wellKnownNextjsClientConfigAppRoute };
|
|
68
|
+
export { WellKnownClientData, getWellKnownClientData, handleClientConfigForPagesRouter, wellKnownNextjsClientConfigAppRoute };
|
package/dist/next/endpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import type { NextApiResponse } from 'next';\nimport { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the microfrontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\n/**\n * A Next.js Pages Router API to export the microfrontends client config data to the client.\n *\n * @example In the `pages/api/.well-known/vercel/microfrontends/client-config/index.ts` file,\n * add this code:\n * ```\n * import { handleClientConfigForPagesRouter } from '@vercel/microfrontends/next/endpoints';\n * import type { NextApiResponse } from 'next';\n *\n * async function handler(\n * _,\n * res: NextApiResponse,\n * ): Promise<void> {\n * await handleClientConfigForPagesRouter(res, {\n * flagValue: () => Promise.resolve(true)\n * });\n * }\n * ```\n *\n * Then also make sure to add the following rewrite rule to your `next.config.js` file:\n * ```\n * rewrites: () =>\n * Promise.resolve([\n * {\n * source: '/.well-known/vercel/microfrontends/client-config',\n * destination: '/api/.well-known/vercel/microfrontends/client-config',\n * },\n * ]),\n * ```\n */\nexport async function handleClientConfigForPagesRouter(\n res: NextApiResponse,\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<void> {\n const clientData = await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n );\n res.status(200).json(clientData);\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";AACA,SAAS,oBAAoB;;;ACD7B,SAAS,oBAAoB;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,MAAM,oBAAoB;AAC5B,iBAAW,OAAO,OAAO,OAAO,OAAO,YAAY,GAAG;AACpD,YAAI,IAAI,SAAS;AACf,cAAI,UAAU,IAAI,QAAQ,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,OAAO;AAAA,EA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AAC9B,QAAM,SAAS,0BAA0B,QAAQ,YAAY;AAC7D,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,SAAS;AAC3C,UAAI,UAAU,MAAM;AAClB,cAAM,WAAW,UAAU;AAC3B,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,UAAU;AAAA,EACxB;AAEA,SAAO;AAAA,IACL,QAAQ,OAAO,UAAU;AAAA,EAC3B;AACF;;;AFhCA,eAAsB,oCACpB,YACuB;AACvB,SAAO,aAAa;AAAA,IAClB,MAAM;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAgCA,eAAsB,iCACpB,KACA,YACe;AACf,QAAM,aAAa,MAAM;AAAA,IACvB,QAAQ,IAAI;AAAA,IACZ;AAAA,EACF;AACA,MAAI,OAAO,GAAG,EAAE,KAAK,UAAU;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import type { NextApiResponse } from 'next';\nimport { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the microfrontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\n/**\n * A Next.js Pages Router API to export the microfrontends client config data to the client.\n *\n * @example In the `pages/api/.well-known/vercel/microfrontends/client-config/index.ts` file,\n * add this code:\n * ```\n * import { handleClientConfigForPagesRouter } from '@vercel/microfrontends/next/endpoints';\n * import type { NextApiResponse } from 'next';\n *\n * async function handler(\n * _,\n * res: NextApiResponse,\n * ): Promise<void> {\n * await handleClientConfigForPagesRouter(res, {\n * flagValue: () => Promise.resolve(true)\n * });\n * }\n * ```\n *\n * Then also make sure to add the following rewrite rule to your `next.config.js` file:\n * ```\n * rewrites: () =>\n * Promise.resolve([\n * {\n * source: '/.well-known/vercel/microfrontends/client-config',\n * destination: '/api/.well-known/vercel/microfrontends/client-config',\n * },\n * ]),\n * ```\n */\nexport async function handleClientConfigForPagesRouter(\n res: NextApiResponse,\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<void> {\n const clientData = await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n );\n res.status(200).json(clientData);\n}\n\nexport { getWellKnownClientData };\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";AACA,SAAS,oBAAoB;;;ACD7B,SAAS,oBAAoB;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,MAAM,oBAAoB;AAC5B,iBAAW,OAAO,OAAO,OAAO,OAAO,YAAY,GAAG;AACpD,YAAI,IAAI,SAAS;AACf,cAAI,UAAU,IAAI,QAAQ,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QACL,QACA,MAC2B;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO,IAAI;AAAA,MACT,KAAK,MAAM,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ,OAA2C;AACjD,WACE,KAAK,UAAU,KAAK,YAAY,MAAM,KAAK,UAAU,MAAM,YAAY;AAAA,EAE3E;AAAA,EAEA,0BAA0B,MAA6B;AACrD,QAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AACzB,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,QAAI,KAAK,UAAU,IAAI,GAAG;AACxB,aAAO,KAAK,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AAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,UAAU;AAAA,EACxB;AAEA,SAAO;AAAA,IACL,QAAQ,OAAO,UAAU;AAAA,EAC3B;AACF;;;AFhCA,eAAsB,oCACpB,YACuB;AACvB,SAAO,aAAa;AAAA,IAClB,MAAM;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAgCA,eAAsB,iCACpB,KACA,YACe;AACf,QAAM,aAAa,MAAM;AAAA,IACvB,QAAQ,IAAI;AAAA,IACZ;AAAA,EACF;AACA,MAAI,OAAO,GAAG,EAAE,KAAK,UAAU;AACjC;","names":[]}
|
package/dist/next/middleware.cjs
CHANGED
|
@@ -29,6 +29,12 @@ module.exports = __toCommonJS(middleware_exports);
|
|
|
29
29
|
var import_server = require("next/server");
|
|
30
30
|
var import_path_to_regexp3 = require("path-to-regexp");
|
|
31
31
|
|
|
32
|
+
// src/next/utils/route-to-local-proxy.ts
|
|
33
|
+
function routeToLocalProxy() {
|
|
34
|
+
const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
|
|
35
|
+
return isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY);
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
// src/config/microfrontends-config/isomorphic/index.ts
|
|
33
39
|
var import_jsonc_parser = require("jsonc-parser");
|
|
34
40
|
|
|
@@ -136,11 +142,6 @@ function getConfigStringFromEnv() {
|
|
|
136
142
|
return config;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
// src/config/schema/utils/is-main-config.ts
|
|
140
|
-
function isMainConfig(c) {
|
|
141
|
-
return !("partOf" in c);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
145
|
// src/config/schema/utils/is-default-app.ts
|
|
145
146
|
function isDefaultApp(a) {
|
|
146
147
|
return !("routing" in a);
|
|
@@ -247,6 +248,10 @@ function parseOverrides(cookies) {
|
|
|
247
248
|
|
|
248
249
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
249
250
|
var import_path_to_regexp2 = require("path-to-regexp");
|
|
251
|
+
var LIST_FORMATTER = new Intl.ListFormat("en", {
|
|
252
|
+
style: "long",
|
|
253
|
+
type: "conjunction"
|
|
254
|
+
});
|
|
250
255
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
251
256
|
if (!applicationConfigsById) {
|
|
252
257
|
return;
|
|
@@ -379,15 +384,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
379
384
|
if (!applicationConfigsById) {
|
|
380
385
|
return;
|
|
381
386
|
}
|
|
382
|
-
const
|
|
383
|
-
|
|
387
|
+
const applicationsWithoutRouting = Object.entries(
|
|
388
|
+
applicationConfigsById
|
|
389
|
+
).filter(([, app]) => isDefaultApp(app));
|
|
390
|
+
const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
|
|
391
|
+
(acc) => {
|
|
392
|
+
return acc + 1;
|
|
393
|
+
},
|
|
394
|
+
0
|
|
384
395
|
);
|
|
385
|
-
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
386
|
-
([key]) => key
|
|
387
|
-
);
|
|
388
|
-
const numApplications = Object.keys(applicationConfigsById).length;
|
|
389
|
-
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
390
|
-
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
391
396
|
if (numApplicationsWithoutRouting === 0) {
|
|
392
397
|
throw new MicrofrontendError(
|
|
393
398
|
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
@@ -395,8 +400,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
395
400
|
);
|
|
396
401
|
}
|
|
397
402
|
if (numApplicationsWithoutRouting > 1) {
|
|
403
|
+
const applicationNamesMissingRouting = applicationsWithoutRouting.map(
|
|
404
|
+
([name]) => name
|
|
405
|
+
);
|
|
398
406
|
throw new MicrofrontendError(
|
|
399
|
-
`
|
|
407
|
+
`All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
|
|
400
408
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
401
409
|
);
|
|
402
410
|
}
|
|
@@ -707,42 +715,28 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
707
715
|
constructor({
|
|
708
716
|
config,
|
|
709
717
|
overrides,
|
|
710
|
-
meta,
|
|
711
718
|
opts
|
|
712
719
|
}) {
|
|
713
720
|
this.childApplications = {};
|
|
714
721
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
715
722
|
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
716
723
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
app: appConfig,
|
|
724
|
-
overrides: appOverrides
|
|
725
|
-
});
|
|
726
|
-
} else {
|
|
727
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
728
|
-
app: appConfig,
|
|
729
|
-
overrides: appOverrides
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
} else {
|
|
734
|
-
this.partOf = config.partOf;
|
|
735
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
736
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
737
|
-
meta.fromApp,
|
|
738
|
-
{
|
|
739
|
-
// we don't know routing because we're not in the main config
|
|
740
|
-
app: { routing: [] },
|
|
724
|
+
let defaultApplication;
|
|
725
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
726
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
727
|
+
if (isDefaultApp(appConfig)) {
|
|
728
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
729
|
+
app: appConfig,
|
|
741
730
|
overrides: appOverrides
|
|
742
|
-
}
|
|
743
|
-
|
|
731
|
+
});
|
|
732
|
+
} else {
|
|
733
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
734
|
+
app: appConfig,
|
|
735
|
+
overrides: appOverrides
|
|
736
|
+
});
|
|
737
|
+
}
|
|
744
738
|
}
|
|
745
|
-
if (
|
|
739
|
+
if (!defaultApplication) {
|
|
746
740
|
throw new MicrofrontendError(
|
|
747
741
|
"Could not find default application in microfrontends configuration",
|
|
748
742
|
{
|
|
@@ -751,34 +745,30 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
751
745
|
}
|
|
752
746
|
);
|
|
753
747
|
}
|
|
748
|
+
this.defaultApplication = defaultApplication;
|
|
754
749
|
this.config = config;
|
|
755
750
|
this.options = config.options;
|
|
756
751
|
this.serialized = {
|
|
757
752
|
config,
|
|
758
|
-
overrides
|
|
759
|
-
meta
|
|
753
|
+
overrides
|
|
760
754
|
};
|
|
761
755
|
}
|
|
762
756
|
static validate(config, opts) {
|
|
763
757
|
const skipValidation = opts?.skipValidation ?? [];
|
|
764
758
|
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
validateDeprecatedFields(c);
|
|
770
|
-
}
|
|
759
|
+
validateConfigPaths(c.applications);
|
|
760
|
+
validateConfigDefaultApplication(c.applications);
|
|
761
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
762
|
+
validateDeprecatedFields(c);
|
|
771
763
|
}
|
|
772
764
|
return c;
|
|
773
765
|
}
|
|
774
766
|
static fromEnv({
|
|
775
|
-
meta,
|
|
776
767
|
cookies
|
|
777
768
|
}) {
|
|
778
769
|
return new MicrofrontendConfigIsomorphic({
|
|
779
770
|
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
780
|
-
overrides: parseOverrides(cookies ?? [])
|
|
781
|
-
meta
|
|
771
|
+
overrides: parseOverrides(cookies ?? [])
|
|
782
772
|
});
|
|
783
773
|
}
|
|
784
774
|
isOverridesDisabled() {
|
|
@@ -803,7 +793,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
803
793
|
].filter(Boolean);
|
|
804
794
|
}
|
|
805
795
|
getApplication(name) {
|
|
806
|
-
if (this.defaultApplication
|
|
796
|
+
if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
|
|
807
797
|
return this.defaultApplication;
|
|
808
798
|
}
|
|
809
799
|
const app = this.childApplications[name] || Object.values(this.childApplications).find(
|
|
@@ -821,7 +811,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
821
811
|
return app;
|
|
822
812
|
}
|
|
823
813
|
getApplicationByProjectId(projectId) {
|
|
824
|
-
if (this.defaultApplication
|
|
814
|
+
if (this.defaultApplication.projectId === projectId) {
|
|
825
815
|
return this.defaultApplication;
|
|
826
816
|
}
|
|
827
817
|
return Object.values(this.childApplications).find(
|
|
@@ -829,19 +819,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
829
819
|
);
|
|
830
820
|
}
|
|
831
821
|
/**
|
|
832
|
-
* Returns the default application.
|
|
833
|
-
* is undefined ( )
|
|
822
|
+
* Returns the default application.
|
|
834
823
|
*/
|
|
835
824
|
getDefaultApplication() {
|
|
836
|
-
if (!this.defaultApplication) {
|
|
837
|
-
throw new MicrofrontendError(
|
|
838
|
-
"Could not find default application in microfrontends configuration",
|
|
839
|
-
{
|
|
840
|
-
type: "application",
|
|
841
|
-
subtype: "not_found"
|
|
842
|
-
}
|
|
843
|
-
);
|
|
844
|
-
}
|
|
845
825
|
return this.defaultApplication;
|
|
846
826
|
}
|
|
847
827
|
/**
|
|
@@ -868,11 +848,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
868
848
|
}
|
|
869
849
|
])
|
|
870
850
|
);
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
};
|
|
875
|
-
}
|
|
851
|
+
applications[this.defaultApplication.name] = {
|
|
852
|
+
default: true
|
|
853
|
+
};
|
|
876
854
|
return new MicrofrontendConfigClient({
|
|
877
855
|
applications
|
|
878
856
|
});
|
|
@@ -882,97 +860,13 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
882
860
|
}
|
|
883
861
|
};
|
|
884
862
|
|
|
885
|
-
// src/config/microfrontends-config/isomorphic/child.ts
|
|
886
|
-
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
887
|
-
constructor({
|
|
888
|
-
config,
|
|
889
|
-
overrides,
|
|
890
|
-
meta
|
|
891
|
-
}) {
|
|
892
|
-
super({ config, overrides, meta });
|
|
893
|
-
this.isMainConfig = false;
|
|
894
|
-
this.partOf = config.partOf;
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
// src/config/microfrontends-config/isomorphic/main.ts
|
|
899
|
-
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
900
|
-
constructor({
|
|
901
|
-
config,
|
|
902
|
-
overrides,
|
|
903
|
-
meta
|
|
904
|
-
}) {
|
|
905
|
-
super({ config, overrides, meta });
|
|
906
|
-
this.isMainConfig = true;
|
|
907
|
-
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
908
|
-
let defaultApplication;
|
|
909
|
-
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
910
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
911
|
-
if (isDefaultApp(appConfig)) {
|
|
912
|
-
defaultApplication = new DefaultApplication(appId, {
|
|
913
|
-
app: appConfig,
|
|
914
|
-
overrides: appOverrides
|
|
915
|
-
});
|
|
916
|
-
} else {
|
|
917
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
918
|
-
app: appConfig,
|
|
919
|
-
overrides: appOverrides
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
if (!defaultApplication) {
|
|
924
|
-
throw new MicrofrontendError(
|
|
925
|
-
"Could not find default application in microfrontends configuration",
|
|
926
|
-
{
|
|
927
|
-
type: "application",
|
|
928
|
-
subtype: "not_found"
|
|
929
|
-
}
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
this.defaultApplication = defaultApplication;
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
|
|
936
|
-
// src/config/microfrontends/isomorphic/index.ts
|
|
937
|
-
var Microfrontends = class {
|
|
938
|
-
constructor({
|
|
939
|
-
config,
|
|
940
|
-
overrides,
|
|
941
|
-
meta
|
|
942
|
-
}) {
|
|
943
|
-
if (isMainConfig(config)) {
|
|
944
|
-
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
945
|
-
} else {
|
|
946
|
-
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
isChildConfig() {
|
|
950
|
-
return this.config instanceof MicrofrontendChildConfig;
|
|
951
|
-
}
|
|
952
|
-
static fromEnv({
|
|
953
|
-
cookies,
|
|
954
|
-
meta
|
|
955
|
-
}) {
|
|
956
|
-
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
957
|
-
cookies,
|
|
958
|
-
meta
|
|
959
|
-
});
|
|
960
|
-
return new Microfrontends(config.serialize());
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// src/next/utils/route-to-local-proxy.ts
|
|
965
|
-
function routeToLocalProxy() {
|
|
966
|
-
const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
|
|
967
|
-
return isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY);
|
|
968
|
-
}
|
|
969
|
-
|
|
970
863
|
// src/next/middleware/middleware.ts
|
|
971
864
|
function getMfeFlagHeader(req) {
|
|
972
865
|
const flagValue = req.headers.get("x-vercel-mfe-flag-value");
|
|
973
866
|
if (flagValue === "true") {
|
|
974
867
|
return true;
|
|
975
|
-
}
|
|
868
|
+
}
|
|
869
|
+
if (flagValue === "false") {
|
|
976
870
|
return false;
|
|
977
871
|
}
|
|
978
872
|
return null;
|
|
@@ -1024,28 +918,23 @@ function getFlagHandler({
|
|
|
1024
918
|
}
|
|
1025
919
|
function getMicrofrontendsMiddleware({
|
|
1026
920
|
request,
|
|
1027
|
-
flagValues
|
|
1028
|
-
fromApp
|
|
921
|
+
flagValues
|
|
1029
922
|
}) {
|
|
1030
|
-
const microfrontends =
|
|
1031
|
-
cookies: request.cookies.getAll()
|
|
1032
|
-
meta: {
|
|
1033
|
-
fromApp
|
|
1034
|
-
}
|
|
923
|
+
const microfrontends = MicrofrontendConfigIsomorphic.fromEnv({
|
|
924
|
+
cookies: request.cookies.getAll()
|
|
1035
925
|
});
|
|
1036
926
|
const middlewares = [];
|
|
1037
927
|
if (!process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
|
|
1038
928
|
throw new Error("NEXT_PUBLIC_MFE_CURRENT_APPLICATION is not set");
|
|
1039
929
|
}
|
|
1040
|
-
const currentApplication = microfrontends.
|
|
930
|
+
const currentApplication = microfrontends.getApplication(
|
|
1041
931
|
process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION
|
|
1042
932
|
);
|
|
1043
933
|
if (!currentApplication.isDefault()) {
|
|
1044
934
|
return middlewares;
|
|
1045
935
|
}
|
|
1046
|
-
const
|
|
1047
|
-
const
|
|
1048
|
-
for (const application of config.getChildApplications()) {
|
|
936
|
+
const localProxyPort = microfrontends.getLocalProxyPort();
|
|
937
|
+
for (const application of microfrontends.getChildApplications()) {
|
|
1049
938
|
for (const pathGroup of application.routing) {
|
|
1050
939
|
const flagName = pathGroup.flag;
|
|
1051
940
|
if (flagName) {
|
|
@@ -1075,14 +964,12 @@ function getMicrofrontendsMiddleware({
|
|
|
1075
964
|
}
|
|
1076
965
|
async function runMicrofrontendsMiddleware({
|
|
1077
966
|
request,
|
|
1078
|
-
fromApp,
|
|
1079
967
|
flagValues
|
|
1080
968
|
}) {
|
|
1081
969
|
const pathname = request.nextUrl.pathname;
|
|
1082
970
|
const middlewares = getMicrofrontendsMiddleware({
|
|
1083
971
|
request,
|
|
1084
|
-
flagValues
|
|
1085
|
-
fromApp
|
|
972
|
+
flagValues
|
|
1086
973
|
});
|
|
1087
974
|
for (const mware of middlewares) {
|
|
1088
975
|
if (typeof mware.src === "string" ? pathname === mware.src : mware.src.test(pathname)) {
|