@vercel/microfrontends 0.14.0 → 0.16.0
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 +392 -1620
- package/dist/config.cjs +478 -1001
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -25
- package/dist/config.js +474 -980
- package/dist/config.js.map +1 -1
- package/dist/{v2/microfrontends → microfrontends}/server.cjs +91 -150
- package/dist/microfrontends/server.cjs.map +1 -0
- package/dist/{v2/microfrontends → microfrontends}/server.d.ts +4 -4
- package/dist/{v2/microfrontends → microfrontends}/server.js +91 -150
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +49 -28
- package/dist/microfrontends.cjs.map +1 -0
- package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -4
- package/dist/{v2/microfrontends.js → microfrontends.js} +48 -27
- package/dist/microfrontends.js.map +1 -0
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +1344 -1024
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +1343 -1023
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +77 -18
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +13 -2
- package/dist/next/endpoints.js +77 -18
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +765 -395
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +765 -395
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +615 -1031
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +14 -12
- package/dist/next/testing.js +609 -1015
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +40 -108
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +24 -2
- package/dist/overrides.js +36 -106
- package/dist/overrides.js.map +1 -1
- package/dist/{v2/routing.cjs → routing.cjs} +3 -3
- package/dist/routing.cjs.map +1 -0
- package/dist/{v2/schema.cjs → schema.cjs} +1 -1
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/utils/mfe-port.cjs +237 -1338
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +230 -1331
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +31 -361
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +3 -146
- package/dist/validation.js +30 -359
- package/dist/validation.js.map +1 -1
- package/package.json +29 -92
- package/schema/schema.json +174 -244
- package/dist/config/client.cjs +0 -54
- package/dist/config/client.cjs.map +0 -1
- package/dist/config/client.d.ts +0 -23
- package/dist/config/client.js +0 -28
- package/dist/config/client.js.map +0 -1
- package/dist/config/edge.cjs +0 -508
- package/dist/config/edge.cjs.map +0 -1
- package/dist/config/edge.d.ts +0 -20
- package/dist/config/edge.js +0 -481
- package/dist/config/edge.js.map +0 -1
- package/dist/microfrontend-config-983a5139.d.ts +0 -154
- package/dist/schema-2922d49e.d.ts +0 -182
- package/dist/v2/config.cjs +0 -709
- package/dist/v2/config.cjs.map +0 -1
- package/dist/v2/config.d.ts +0 -4
- package/dist/v2/config.js +0 -684
- package/dist/v2/config.js.map +0 -1
- package/dist/v2/microfrontends/server.cjs.map +0 -1
- package/dist/v2/microfrontends/server.js.map +0 -1
- package/dist/v2/microfrontends.cjs.map +0 -1
- package/dist/v2/microfrontends.js.map +0 -1
- package/dist/v2/next/client.cjs +0 -3
- package/dist/v2/next/client.cjs.map +0 -1
- package/dist/v2/next/client.d.ts +0 -45
- package/dist/v2/next/client.js +0 -3
- package/dist/v2/next/client.js.map +0 -1
- package/dist/v2/next/config.cjs +0 -2178
- package/dist/v2/next/config.cjs.map +0 -1
- package/dist/v2/next/config.d.ts +0 -22
- package/dist/v2/next/config.js +0 -2143
- package/dist/v2/next/config.js.map +0 -1
- package/dist/v2/next/endpoints.cjs +0 -141
- package/dist/v2/next/endpoints.cjs.map +0 -1
- package/dist/v2/next/endpoints.d.ts +0 -26
- package/dist/v2/next/endpoints.js +0 -116
- package/dist/v2/next/endpoints.js.map +0 -1
- package/dist/v2/next/middleware.cjs +0 -1099
- package/dist/v2/next/middleware.cjs.map +0 -1
- package/dist/v2/next/middleware.d.ts +0 -34
- package/dist/v2/next/middleware.js +0 -1071
- package/dist/v2/next/middleware.js.map +0 -1
- package/dist/v2/next/testing.cjs +0 -992
- package/dist/v2/next/testing.cjs.map +0 -1
- package/dist/v2/next/testing.d.ts +0 -55
- package/dist/v2/next/testing.js +0 -961
- package/dist/v2/next/testing.js.map +0 -1
- package/dist/v2/overrides.cjs +0 -75
- package/dist/v2/overrides.cjs.map +0 -1
- package/dist/v2/overrides.d.ts +0 -24
- package/dist/v2/overrides.js +0 -45
- package/dist/v2/overrides.js.map +0 -1
- package/dist/v2/routing.cjs.map +0 -1
- package/dist/v2/schema.cjs.map +0 -1
- package/dist/v2/schema.d.ts +0 -1
- package/schema/schema-v2.json +0 -266
- /package/dist/{v2/routing.d.ts → routing.d.ts} +0 -0
- /package/dist/{v2/routing.js → routing.js} +0 -0
- /package/dist/{v2/routing.js.map → routing.js.map} +0 -0
- /package/dist/{v2/schema.js → schema.js} +0 -0
- /package/dist/{v2/schema.js.map → schema.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// src/config
|
|
1
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
2
2
|
import { parse } from "jsonc-parser";
|
|
3
3
|
|
|
4
|
-
// src/config
|
|
4
|
+
// src/config/errors.ts
|
|
5
5
|
var MicrofrontendError = class extends Error {
|
|
6
6
|
constructor(message, opts) {
|
|
7
7
|
super(message);
|
|
@@ -93,7 +93,7 @@ var MicrofrontendError = class extends Error {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
// src/config
|
|
96
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
97
97
|
function getConfigStringFromEnv() {
|
|
98
98
|
const config = process.env.MFE_CONFIG;
|
|
99
99
|
if (!config) {
|
|
@@ -105,17 +105,17 @@ function getConfigStringFromEnv() {
|
|
|
105
105
|
return config;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// src/config
|
|
108
|
+
// src/config/schema/utils/is-main-config.ts
|
|
109
109
|
function isMainConfig(c) {
|
|
110
110
|
return !("partOf" in c);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
// src/config
|
|
113
|
+
// src/config/schema/utils/is-default-app.ts
|
|
114
114
|
function isDefaultApp(a) {
|
|
115
115
|
return !("routing" in a);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
// src/config
|
|
118
|
+
// src/config/microfrontends-config/client/index.ts
|
|
119
119
|
import { pathToRegexp } from "path-to-regexp";
|
|
120
120
|
var MicrofrontendConfigClient = class {
|
|
121
121
|
constructor(config, opts) {
|
|
@@ -181,17 +181,17 @@ var MicrofrontendConfigClient = class {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
-
// src/config
|
|
184
|
+
// src/config/overrides/constants.ts
|
|
185
185
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
186
186
|
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
187
187
|
|
|
188
|
-
// src/config
|
|
188
|
+
// src/config/overrides/is-override-cookie.ts
|
|
189
189
|
function isOverrideCookie(cookie) {
|
|
190
190
|
var _a;
|
|
191
191
|
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
// src/config
|
|
194
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
195
195
|
function getOverrideFromCookie(cookie) {
|
|
196
196
|
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
197
197
|
return;
|
|
@@ -201,7 +201,7 @@ function getOverrideFromCookie(cookie) {
|
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
// src/config
|
|
204
|
+
// src/config/overrides/parse-overrides.ts
|
|
205
205
|
function parseOverrides(cookies) {
|
|
206
206
|
const overridesConfig = { applications: {} };
|
|
207
207
|
cookies.forEach((cookie) => {
|
|
@@ -215,7 +215,7 @@ function parseOverrides(cookies) {
|
|
|
215
215
|
return overridesConfig;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
// src/config
|
|
218
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
219
219
|
import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
|
|
220
220
|
var SUPPORTED_VERSIONS = ["2"];
|
|
221
221
|
var validateConfigVersion = (version) => {
|
|
@@ -240,13 +240,9 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
240
240
|
}
|
|
241
241
|
for (const pathMatch of app.routing) {
|
|
242
242
|
for (const path of pathMatch.paths) {
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
errors.push(
|
|
247
|
-
`Path ${path} may only have a :wildcard in the last path component`
|
|
248
|
-
);
|
|
249
|
-
}
|
|
243
|
+
const maybeError = validatePathExpression(path);
|
|
244
|
+
if (maybeError) {
|
|
245
|
+
errors.push(maybeError);
|
|
250
246
|
}
|
|
251
247
|
const existing = pathsByApplicationId.get(path);
|
|
252
248
|
if (existing) {
|
|
@@ -296,6 +292,31 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
296
292
|
});
|
|
297
293
|
}
|
|
298
294
|
};
|
|
295
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
296
|
+
function validatePathExpression(path) {
|
|
297
|
+
const tokens = parsePathRegexp(path);
|
|
298
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
299
|
+
const token = tokens[i];
|
|
300
|
+
if (token === void 0) {
|
|
301
|
+
return `token ${i} in ${path} is undefined, this shouldn't happen`;
|
|
302
|
+
}
|
|
303
|
+
if (typeof token !== "string") {
|
|
304
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
305
|
+
return `Path ${path} cannot use a regular expression wildcard`;
|
|
306
|
+
}
|
|
307
|
+
if (token.prefix !== "/") {
|
|
308
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path}`;
|
|
309
|
+
}
|
|
310
|
+
if (token.suffix) {
|
|
311
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
312
|
+
}
|
|
313
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
314
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path}. Modifiers are only allowed in the last path component`;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
299
320
|
var validateAppPaths = (name, app) => {
|
|
300
321
|
for (const group of app.routing) {
|
|
301
322
|
for (const p of group.paths) {
|
|
@@ -344,7 +365,7 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
344
365
|
}
|
|
345
366
|
};
|
|
346
367
|
|
|
347
|
-
// src/config
|
|
368
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
348
369
|
var PREFIX = "vc-ap";
|
|
349
370
|
function generateAssetPrefixFromName({
|
|
350
371
|
name
|
|
@@ -355,7 +376,7 @@ function generateAssetPrefixFromName({
|
|
|
355
376
|
return `${PREFIX}-${name}`;
|
|
356
377
|
}
|
|
357
378
|
|
|
358
|
-
// src/config
|
|
379
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
359
380
|
function generatePortFromName({
|
|
360
381
|
name,
|
|
361
382
|
minPort = 3e3,
|
|
@@ -375,7 +396,7 @@ function generatePortFromName({
|
|
|
375
396
|
return port;
|
|
376
397
|
}
|
|
377
398
|
|
|
378
|
-
// src/config
|
|
399
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
379
400
|
var Host = class {
|
|
380
401
|
constructor(hostConfig, options) {
|
|
381
402
|
const { protocol = "https", host, port } = hostConfig;
|
|
@@ -424,7 +445,7 @@ var LocalHost = class extends Host {
|
|
|
424
445
|
}
|
|
425
446
|
};
|
|
426
447
|
|
|
427
|
-
// src/config
|
|
448
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
428
449
|
var Application = class {
|
|
429
450
|
constructor(name, {
|
|
430
451
|
app,
|
|
@@ -494,10 +515,10 @@ var ChildApplication = class extends Application {
|
|
|
494
515
|
}
|
|
495
516
|
};
|
|
496
517
|
|
|
497
|
-
// src/config
|
|
518
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
498
519
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
499
520
|
|
|
500
|
-
// src/config
|
|
521
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
501
522
|
var MicrofrontendConfigIsomorphic = class {
|
|
502
523
|
constructor({
|
|
503
524
|
config,
|
|
@@ -679,7 +700,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
679
700
|
}
|
|
680
701
|
};
|
|
681
702
|
|
|
682
|
-
// src/config
|
|
703
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
683
704
|
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
684
705
|
constructor({
|
|
685
706
|
config,
|
|
@@ -692,7 +713,7 @@ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
692
713
|
}
|
|
693
714
|
};
|
|
694
715
|
|
|
695
|
-
// src/config
|
|
716
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
696
717
|
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
697
718
|
constructor({
|
|
698
719
|
config,
|
|
@@ -731,7 +752,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
731
752
|
}
|
|
732
753
|
};
|
|
733
754
|
|
|
734
|
-
// src/config
|
|
755
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
735
756
|
var Microfrontends = class {
|
|
736
757
|
constructor({
|
|
737
758
|
config,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config/microfrontends-config/isomorphic/index.ts","../src/config/errors.ts","../src/config/microfrontends-config/utils/get-config-from-env.ts","../src/config/schema/utils/is-main-config.ts","../src/config/schema/utils/is-default-app.ts","../src/config/microfrontends-config/client/index.ts","../src/config/overrides/constants.ts","../src/config/overrides/is-override-cookie.ts","../src/config/overrides/get-override-from-cookie.ts","../src/config/overrides/parse-overrides.ts","../src/config/microfrontends-config/isomorphic/validation.ts","../src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts","../src/config/microfrontends-config/isomorphic/utils/generate-port.ts","../src/config/microfrontends-config/isomorphic/host.ts","../src/config/microfrontends-config/isomorphic/application.ts","../src/config/microfrontends-config/isomorphic/constants.ts","../src/config/microfrontends-config/isomorphic/child.ts","../src/config/microfrontends-config/isomorphic/main.ts","../src/config/microfrontends/isomorphic/index.ts"],"sourcesContent":["import { parse } from 'jsonc-parser';\nimport { getConfigStringFromEnv } from '../utils/get-config-from-env';\nimport { isMainConfig } from '../../schema/utils/is-main-config';\nimport { isDefaultApp } from '../../schema/utils/is-default-app';\nimport type { Config } from '../../schema/types';\nimport type { ClientConfig } from '../client/types';\nimport { MicrofrontendError } from '../../errors';\nimport { MicrofrontendConfigClient } from '../client';\nimport { type OverridesConfig, parseOverrides } from '../../overrides';\nimport { DefaultApplication, ChildApplication } from './application';\nimport { DEFAULT_LOCAL_PROXY_PORT } from './constants';\nimport {\n validateConfigDefaultApplication,\n validateConfigPaths,\n validateConfigVersion,\n} from './validation';\n\nexport interface ConfigMeta {\n /**\n * The application name that the configuration is being loaded from.\n */\n fromApp: string;\n}\n\n/**\n * A class to manage the microfrontends configuration.\n */\nexport class MicrofrontendConfigIsomorphic {\n config: Config;\n isMainConfig: boolean;\n partOf?: string;\n defaultApplication?: DefaultApplication;\n childApplications: Record<string, ChildApplication> = {};\n overrides?: OverridesConfig;\n options?: Config['options'];\n\n private readonly serialized: {\n config: Config;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n };\n\n constructor({\n config,\n overrides,\n meta,\n }: { config: Config; overrides?: OverridesConfig; meta: ConfigMeta }) {\n // run validation on init\n MicrofrontendConfigIsomorphic.validate(config);\n\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n this.overrides = overrides && !disableOverrides ? overrides : undefined;\n this.isMainConfig = isMainConfig(config);\n\n if (isMainConfig(config)) {\n // create applications\n for (const [appId, appConfig] of Object.entries(config.applications)) {\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[appId]\n : undefined;\n\n if (isDefaultApp(appConfig)) {\n this.defaultApplication = new DefaultApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n } else {\n this.childApplications[appId] = new ChildApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n }\n }\n } else {\n this.partOf = config.partOf;\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[meta.fromApp]\n : undefined;\n this.childApplications[meta.fromApp] = new ChildApplication(\n meta.fromApp,\n {\n // we don't know routing because we're not in the main config\n app: { routing: [] },\n overrides: appOverrides,\n },\n );\n }\n\n // the main configuration file should ALWAYS have the default\n if (isMainConfig(config) && !this.defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n this.config = config;\n this.options = config.options;\n this.serialized = {\n config,\n overrides,\n meta,\n };\n }\n\n static validate(config: string | Config): Config {\n // let this throw if it's not valid JSON\n const c = typeof config === 'string' ? (parse(config) as Config) : config;\n\n if (isMainConfig(c)) {\n // run validation\n validateConfigVersion(c.version);\n validateConfigPaths(c.applications);\n validateConfigDefaultApplication(c.applications);\n }\n\n return c;\n }\n\n static fromEnv({\n meta,\n cookies,\n }: {\n meta: ConfigMeta;\n cookies?: { name: string; value: string }[];\n }): MicrofrontendConfigIsomorphic {\n return new MicrofrontendConfigIsomorphic({\n config: parse(getConfigStringFromEnv()) as Config,\n overrides: parseOverrides(cookies ?? []),\n meta,\n });\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getApplicationsByType(): {\n defaultApplication?: DefaultApplication;\n applications: ChildApplication[];\n } {\n return {\n defaultApplication: this.defaultApplication,\n applications: Object.values(this.childApplications),\n };\n }\n\n getChildApplications(): ChildApplication[] {\n return Object.values(this.childApplications);\n }\n\n getAllApplications(): (DefaultApplication | ChildApplication)[] {\n return [\n this.defaultApplication,\n ...Object.values(this.childApplications),\n ].filter(Boolean) as (DefaultApplication | ChildApplication)[];\n }\n\n getApplication(name: string): DefaultApplication | ChildApplication {\n // check the default\n if (this.defaultApplication?.name === name) {\n return this.defaultApplication;\n }\n const app = this.childApplications[name];\n if (!app) {\n throw new MicrofrontendError(\n `Could not find microfrontends configuration for application \"${name}\"`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n return app;\n }\n\n getApplicationByProjectId(\n projectId: string,\n ): DefaultApplication | ChildApplication | undefined {\n // check the default\n if (this.defaultApplication?.vercel?.projectId === projectId) {\n return this.defaultApplication;\n }\n\n return Object.values(this.childApplications).find(\n (app) => app.vercel?.projectId === projectId,\n );\n }\n\n /**\n * Returns the default application. This can throw if the default application\n * is undefined ( )\n */\n getDefaultApplication(): DefaultApplication {\n if (!this.defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n return this.defaultApplication;\n }\n\n /**\n * Returns the configured port for the local proxy\n */\n getLocalProxyPort(): number {\n return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;\n }\n\n /**\n * Serializes the class back to the Schema type.\n *\n * NOTE: This is used when writing the config to disk and must always match the input Schema\n */\n toSchemaJson(): Config {\n return this.serialized.config;\n }\n\n toClientConfig(): MicrofrontendConfigClient {\n const applications: ClientConfig['applications'] = Object.fromEntries(\n Object.entries(this.childApplications).map(([name, application]) => [\n name,\n {\n default: false,\n routing: application.routing,\n },\n ]),\n );\n\n // add the default application\n if (this.defaultApplication) {\n applications[this.defaultApplication.name] = {\n default: true,\n };\n }\n\n return new MicrofrontendConfigClient({\n applications,\n });\n }\n\n serialize(): {\n config: Config;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n } {\n return this.serialized;\n }\n}\n","export type MicrofrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'application'\n | 'unknown';\n\nexport type MicrofrontendErrorSubtype =\n | 'not_found'\n | 'inference_failed'\n | 'not_found_in_env'\n | 'invalid_asset_prefix'\n | 'invalid_main_path'\n | 'does_not_match_schema'\n | 'unable_to_read_file'\n | 'unsupported_validation_env'\n | 'unsupported_version'\n | 'invalid_path'\n | 'invalid_permissions'\n | 'invalid_syntax'\n | 'missing_microfrontend_config_path'\n | 'unsupported_operation';\n\n// A mapping of error types to their subtypes.\ninterface TypeToSubtype {\n application:\n | 'invalid_asset_prefix'\n | 'invalid_path'\n | 'multiple_package_managers'\n | 'not_found';\n config:\n | 'conflicting_paths'\n | 'does_not_match_schema'\n | 'invalid_main_path'\n | 'invalid_preview_deployment_suffix'\n | 'multiple_default_applications'\n | 'no_default_application'\n | 'not_found_in_env'\n | 'not_found'\n | 'inference_failed'\n | 'unable_to_read_file'\n | 'invalid_syntax'\n | 'invalid_permissions'\n | 'unsupported_operation'\n | 'unsupported_validation_env'\n | 'unsupported_version';\n packageJson:\n | 'missing_field_name'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n vercelJson:\n | 'missing_field_microfrontend_config_path'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n unknown: never;\n}\n\nexport type MicrofrontendErrorSource =\n | '@vercel/microfrontends'\n | '@vercel/microfrontends/next'\n | 'fs'\n | 'ajv';\n\nexport interface MicrofrontendErrorOptions<T extends MicrofrontendErrorType> {\n source?: MicrofrontendErrorSource;\n type?: T;\n subtype?: TypeToSubtype[T];\n}\n\ninterface HandleOptions {\n fileName?: string;\n}\n\nexport class MicrofrontendError<\n T extends MicrofrontendErrorType = 'unknown',\n> extends Error {\n public source: MicrofrontendErrorSource;\n public type: T;\n public subtype?: TypeToSubtype[T];\n\n constructor(message: string, opts?: MicrofrontendErrorOptions<T>) {\n super(message);\n this.name = 'MicrofrontendsError';\n this.source = opts?.source ?? '@vercel/microfrontends';\n this.type = opts?.type ?? ('unknown' as T);\n this.subtype = opts?.subtype;\n Error.captureStackTrace(this, MicrofrontendError);\n }\n\n isKnown(): boolean {\n return this.type !== 'unknown';\n }\n\n isUnknown(): boolean {\n return !this.isKnown();\n }\n\n /**\n * Converts an error to a MicrofrontendsError.\n * @param original - The original error to convert.\n * @returns The converted MicrofrontendsError.\n */\n static convert(\n original: Error,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (opts?.fileName) {\n const err = MicrofrontendError.convertFSError(original, opts.fileName);\n if (err) {\n return err;\n }\n }\n\n if (\n original.message.includes(\n 'Code generation from strings disallowed for this context',\n )\n ) {\n return new MicrofrontendError(original.message, {\n type: 'config',\n subtype: 'unsupported_validation_env',\n source: 'ajv',\n });\n }\n\n // unknown catch-all\n return new MicrofrontendError(original.message);\n }\n\n static convertFSError(\n original: Error,\n fileName: string,\n ): MicrofrontendError<MicrofrontendErrorType> | null {\n if (original instanceof Error && 'code' in original) {\n if (original.code === 'ENOENT') {\n return new MicrofrontendError(`Could not find \"${fileName}\"`, {\n type: 'config',\n subtype: 'unable_to_read_file',\n source: 'fs',\n });\n }\n if (original.code === 'EACCES') {\n return new MicrofrontendError(\n `Permission denied while accessing \"${fileName}\"`,\n {\n type: 'config',\n subtype: 'invalid_permissions',\n source: 'fs',\n },\n );\n }\n }\n\n if (original instanceof SyntaxError) {\n return new MicrofrontendError(\n `Failed to parse \"${fileName}\": Invalid JSON format.`,\n {\n type: 'config',\n subtype: 'invalid_syntax',\n source: 'fs',\n },\n );\n }\n\n return null;\n }\n\n /**\n * Handles an unknown error and returns a MicrofrontendsError instance.\n * @param err - The error to handle.\n * @returns A MicrofrontendsError instance.\n */\n static handle(\n err: unknown,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (err instanceof MicrofrontendError) {\n return err as MicrofrontendError<MicrofrontendErrorType>;\n }\n\n // handle Error instances\n if (err instanceof Error) {\n return MicrofrontendError.convert(err, opts);\n }\n\n // handle object errors\n if (typeof err === 'object' && err !== null) {\n if ('message' in err && typeof err.message === 'string') {\n return MicrofrontendError.convert(new Error(err.message), opts);\n }\n }\n\n return new MicrofrontendError('An unknown error occurred');\n }\n}\n","import { MicrofrontendError } from '../../errors';\n\n/**\n * Utility to fetch the microfrontend configuration string from the environment.\n */\nexport function getConfigStringFromEnv(): string {\n const config = process.env.MFE_CONFIG;\n if (!config) {\n throw new MicrofrontendError(`Missing \"MFE_CONFIG\" in environment.`, {\n type: 'config',\n subtype: 'not_found_in_env',\n });\n }\n return config;\n}\n","import type { Config, MainConfig } from '../types';\n\nexport function isMainConfig(c: Config): c is MainConfig {\n return !('partOf' in c);\n}\n","import type { Application, DefaultApplication } from '../types';\n\nexport function isDefaultApp(a: Application): a is DefaultApplication {\n return !('routing' in a);\n}\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","// cookie name needs to match proxy\n// https://github.com/vercel/proxy/blob/fb00d723136ad539a194e4a851dd272010527c35/lib/routing/micro_frontends_overrides.lua#L7\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\nexport const OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n","import { OVERRIDES_COOKIE_PREFIX } from './constants';\n\nexport function isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n}\n","import { isOverrideCookie } from './is-override-cookie';\nimport { OVERRIDES_ENV_COOKIE_PREFIX } from './constants';\n\nexport function getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n}): { application: string; host: string } | undefined {\n if (!isOverrideCookie(cookie) || !cookie.value) return;\n return {\n application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ''),\n host: cookie.value,\n };\n}\n","import type { OverridesConfig } from './types';\nimport { getOverrideFromCookie } from './get-override-from-cookie';\n\nexport function parseOverrides(\n cookies: { name: string; value?: string | null }[],\n): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.application] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n}\n","import { pathToRegexp, parse as parsePathRegexp } from 'path-to-regexp';\nimport type {\n ApplicationId,\n PathGroup,\n ApplicationRouting,\n ChildApplication as ChildApplicationConfig,\n} from '../../schema/types';\nimport { MicrofrontendError } from '../../errors';\nimport { isDefaultApp } from '../../schema/utils/is-default-app';\n\nconst SUPPORTED_VERSIONS = ['2'];\n\nexport const validateConfigVersion = (version: string): void => {\n if (!SUPPORTED_VERSIONS.includes(version)) {\n throw new MicrofrontendError(\n `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n};\n\n/**\n * Validate all paths in a configuration - ensures paths do not overlap\n */\nexport const validateConfigPaths = (\n applicationConfigsById?: ApplicationRouting,\n): void => {\n if (!applicationConfigsById) {\n return;\n }\n\n const pathsByApplicationId = new Map<\n PathGroup['paths'][number],\n {\n applications: ApplicationId[];\n matcher: RegExp;\n applicationId?: ApplicationId;\n }\n >();\n const errors: string[] = [];\n\n for (const [id, app] of Object.entries(applicationConfigsById)) {\n if (isDefaultApp(app)) {\n // default applications do not have routing\n continue;\n }\n\n for (const pathMatch of app.routing) {\n for (const path of pathMatch.paths) {\n const maybeError = validatePathExpression(path);\n if (maybeError) {\n errors.push(maybeError);\n }\n\n const existing = pathsByApplicationId.get(path);\n if (existing) {\n existing.applications.push(id);\n } else {\n pathsByApplicationId.set(path, {\n applications: [id],\n matcher: pathToRegexp(path),\n applicationId: id,\n });\n }\n }\n }\n }\n const entries = Array.from(pathsByApplicationId.entries());\n\n entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {\n if (ids.length > 1) {\n errors.push(\n `Duplicate path \"${path}\" for applications \"${ids.join(', ')}\"`,\n );\n }\n\n entries.forEach(\n ([\n matchPath,\n { applications: matchIds, applicationId: matchApplicationId },\n ]) => {\n if (path === matchPath) {\n // we're comparing to ourselves, so skip\n return;\n }\n\n if (applicationId === matchApplicationId) {\n // we're comparing to paths within our own application, which are allowed to overlap, so skip\n return;\n }\n\n if (matcher.test(matchPath)) {\n const source = `\"${path}\" of application${ids.length > 0 ? 's' : ''} ${ids.join(', ')}`;\n const destination = `\"${matchPath}\" of application${matchIds.length > 0 ? 's' : ''} ${matchIds.join(', ')}`;\n\n errors.push(\n `Overlapping path detected between ${source} and ${destination}`,\n );\n }\n },\n );\n });\n\n if (errors.length) {\n throw new MicrofrontendError(`Invalid paths: ${errors.join(', ')}`, {\n type: 'config',\n subtype: 'conflicting_paths',\n });\n }\n};\n\n// From https://github.com/pillarjs/path-to-regexp/blob/b0778f5e8e6c6e9ee4e2f5b34e877cc5229f8036/src/index.ts#L143\nconst PATH_DEFAULT_PATTERN = '[^\\\\/#\\\\?]+?';\n\nfunction validatePathExpression(path: string): string | undefined {\n const tokens = parsePathRegexp(path);\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n if (token === undefined) {\n return `token ${i} in ${path} is undefined, this shouldn't happen`;\n }\n if (typeof token !== 'string') {\n if (token.pattern !== PATH_DEFAULT_PATTERN) {\n return `Path ${path} cannot use a regular expression wildcard`;\n }\n if (token.prefix !== '/') {\n return `Wildcard :${token.name} must be immediately after a / in ${path}`;\n }\n if (token.suffix) {\n return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;\n }\n if (token.modifier && i !== tokens.length - 1) {\n return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path}. Modifiers are only allowed in the last path component`;\n }\n }\n }\n return undefined;\n}\n\n/**\n * Validate all paths in an application - ensures paths are the correct format\n */\nexport const validateAppPaths = (\n name: string,\n app: ChildApplicationConfig,\n): void => {\n // validate routes\n for (const group of app.routing) {\n for (const p of group.paths) {\n if (p === '/') {\n continue;\n }\n if (p.endsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must not end with a slash.`,\n { type: 'application', subtype: 'invalid_path' },\n );\n }\n\n if (!p.startsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must start with a slash.`,\n { type: 'application', subtype: 'invalid_path' },\n );\n }\n }\n }\n};\n\n/**\n * Make sure only one `Application` defines routing\n * */\nexport const validateConfigDefaultApplication = (\n applicationConfigsById?: ApplicationRouting,\n): void => {\n if (!applicationConfigsById) {\n return;\n }\n\n // find all applications that have routing\n const applicationsWithRouting = Object.entries(applicationConfigsById).filter(\n ([, app]) => !isDefaultApp(app),\n );\n // get all the application names\n const applicationsWithRoutingNames = applicationsWithRouting.map(\n ([key]) => key,\n );\n const numApplications = Object.keys(applicationConfigsById).length;\n const numApplicationsWithRouting = applicationsWithRoutingNames.length;\n const numApplicationsWithoutRouting =\n numApplications - numApplicationsWithRouting;\n\n if (numApplicationsWithoutRouting === 0) {\n throw new MicrofrontendError(\n `No default application found. At least one application needs to be the default by omitting routing.`,\n { type: 'config', subtype: 'no_default_application' },\n );\n }\n\n if (numApplicationsWithoutRouting > 1) {\n throw new MicrofrontendError(\n `Only one application can omit \"routing\". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,\n { type: 'config', subtype: 'multiple_default_applications' },\n );\n }\n};\n","const PREFIX = 'vc-ap';\n\nexport function generateAssetPrefixFromName({\n name,\n}: {\n name: string;\n}): string {\n if (!name) {\n throw new Error('Name is required to generate an asset prefix');\n }\n\n return `${PREFIX}-${name}`;\n}\n","export function generatePortFromName({\n name,\n minPort = 3000,\n maxPort = 8000,\n}: {\n name: string;\n minPort?: number;\n maxPort?: number;\n}): number {\n if (!name) {\n throw new Error('Name is required to generate a port');\n }\n\n // hash the name\n let hash = 0;\n for (let i = 0; i < name.length; i++) {\n // eslint-disable-next-line no-bitwise\n hash = (hash << 5) - hash + name.charCodeAt(i);\n // Convert to 32-bit\n // eslint-disable-next-line no-bitwise\n hash |= 0;\n }\n hash = Math.abs(hash);\n\n // Map the hash to the port range\n const range = maxPort - minPort;\n const port = minPort + (hash % range);\n\n return port;\n}\n","import type {\n HostConfig as RemoteHostConfigSchema,\n LocalHostConfig as LocalHostConfigSchema,\n} from '../../schema/types';\nimport { generatePortFromName } from './utils/generate-port';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\ninterface HostOptions {\n isLocal?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: string;\n port: number;\n local: boolean | undefined;\n\n constructor(hostConfig: RemoteHostConfigSchema, options?: HostOptions) {\n const { protocol = 'https', host, port } = hostConfig;\n this.protocol = protocol;\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.local = options?.isLocal;\n }\n\n isLocal(): boolean {\n return this.local || this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: {\n protocol: RemoteHostConfigSchema['protocol'];\n port?: RemoteHostConfigSchema['port'];\n }): number {\n if (!port) {\n if (protocol === 'http') {\n return 80;\n }\n return 443;\n }\n\n return port;\n }\n\n isDefaultPort(): boolean {\n return this.port === Host.getPort({ protocol: this.protocol });\n }\n\n toString(opts: HostDisplayOptions = {}): string {\n const url = this.toUrl(opts);\n // strip the trailing slash\n return url.toString().replace(/\\/$/, '');\n }\n\n toUrl(opts: HostDisplayOptions = {}): URL {\n const { includeDefaultPort } = opts;\n const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? '' : `:${this.port}`}`;\n\n return new URL(url);\n }\n}\n\n/**\n * A Host subclass with defaults for locally running applications\n */\nexport class LocalHost extends Host {\n constructor({\n appName,\n ...hostConfig\n }: LocalHostConfigSchema & { appName: string }) {\n // set defaults for local\n const host = hostConfig.host ?? 'localhost';\n const port = hostConfig.port ?? generatePortFromName({ name: appName });\n const protocol = hostConfig.protocol ?? 'http';\n\n super({ protocol, host, port });\n }\n}\n","import type {\n Application as ApplicationConfig,\n DefaultApplication as DefaultApplicationConfig,\n ChildApplication as ChildApplicationConfig,\n PathGroup,\n Vercel,\n} from '../../schema/types';\nimport type { ApplicationOverrideConfig } from '../../overrides';\nimport { validateAppPaths } from './validation';\nimport { generateAssetPrefixFromName } from './utils/generate-asset-prefix';\nimport { Host, LocalHost } from './host';\n\nexport class Application {\n readonly default: boolean;\n name: string;\n development: {\n local: LocalHost;\n fallback?: Host;\n };\n production?: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n readonly serialized: ApplicationConfig;\n\n constructor(\n name: string,\n {\n app,\n overrides,\n isDefault,\n }: {\n app: ApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n isDefault?: boolean;\n },\n ) {\n this.name = name;\n this.development = {\n local: new LocalHost({\n appName: name,\n ...app.development?.local,\n }),\n fallback: app.development?.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = app.production ? new Host(app.production) : undefined;\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n this.default = isDefault ?? false;\n this.serialized = app;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n getAssetPrefix(): string {\n return generateAssetPrefixFromName({ name: this.name });\n }\n\n serialize(): ApplicationConfig {\n return this.serialized;\n }\n}\n\nexport class DefaultApplication extends Application {\n readonly default = true;\n production: Host;\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: {\n app: DefaultApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n },\n ) {\n super(name, {\n app,\n overrides,\n isDefault: true,\n });\n\n this.production = new Host(app.production);\n }\n\n getAssetPrefix(): string {\n return '';\n }\n}\n\nexport class ChildApplication extends Application {\n readonly default = false;\n routing: PathGroup[];\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: {\n app: ChildApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n },\n ) {\n // validate\n ChildApplication.validate(name, app);\n\n super(name, {\n app,\n overrides,\n isDefault: false,\n });\n\n this.routing = app.routing;\n }\n\n static validate(name: string, app: ChildApplicationConfig): void {\n // validate routes\n validateAppPaths(name, app);\n }\n}\n","export const DEFAULT_LOCAL_PROXY_PORT = 3024;\n","import type { ChildConfig } from '../../schema/types';\nimport type { OverridesConfig } from '../../overrides';\nimport { type ConfigMeta, MicrofrontendConfigIsomorphic } from '.';\n\nexport class MicrofrontendChildConfig extends MicrofrontendConfigIsomorphic {\n isMainConfig = false;\n partOf?: string;\n\n constructor({\n config,\n overrides,\n meta,\n }: {\n config: ChildConfig;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n }) {\n super({ config, overrides, meta });\n this.partOf = config.partOf;\n }\n}\n","import { isDefaultApp } from '../../schema/utils/is-default-app';\nimport type { MainConfig } from '../../schema/types';\nimport { MicrofrontendError } from '../../errors';\nimport type { OverridesConfig } from '../../overrides';\nimport { DefaultApplication, ChildApplication } from './application';\nimport { type ConfigMeta, MicrofrontendConfigIsomorphic } from '.';\n\nexport class MicrofrontendMainConfig extends MicrofrontendConfigIsomorphic {\n isMainConfig = true;\n defaultApplication: DefaultApplication;\n\n constructor({\n config,\n overrides,\n meta,\n }: {\n config: MainConfig;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n }) {\n super({ config, overrides, meta });\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n let defaultApplication: DefaultApplication | undefined;\n for (const [appId, appConfig] of Object.entries(config.applications)) {\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[appId]\n : undefined;\n\n if (isDefaultApp(appConfig)) {\n defaultApplication = new DefaultApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n } else {\n this.childApplications[appId] = new ChildApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n }\n }\n\n // validate that this.defaultApplication is defined\n if (!defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n this.defaultApplication = defaultApplication;\n }\n}\n","import {\n type ConfigMeta,\n MicrofrontendConfigIsomorphic,\n} from '../../microfrontends-config/isomorphic';\nimport { MicrofrontendChildConfig } from '../../microfrontends-config/isomorphic/child';\nimport { MicrofrontendMainConfig } from '../../microfrontends-config/isomorphic/main';\nimport type { MicrofrontendsConfig } from '../types';\nimport type { Config } from '../../schema/types';\nimport type { OverridesConfig } from '../../overrides';\nimport { isMainConfig } from '../../schema/utils/is-main-config';\n\nexport class Microfrontends {\n config: MicrofrontendsConfig;\n\n constructor({\n config,\n overrides,\n meta,\n }: { config: Config; overrides?: OverridesConfig; meta: ConfigMeta }) {\n if (isMainConfig(config)) {\n this.config = new MicrofrontendMainConfig({ config, overrides, meta });\n } else {\n this.config = new MicrofrontendChildConfig({ config, overrides, meta });\n }\n }\n\n isChildConfig(): boolean {\n return this.config instanceof MicrofrontendChildConfig;\n }\n\n static fromEnv({\n cookies,\n meta,\n }: {\n cookies?: { name: string; value: string }[];\n meta: ConfigMeta;\n }): Microfrontends {\n const config = MicrofrontendConfigIsomorphic.fromEnv({\n cookies,\n meta,\n });\n return new Microfrontends(config.serialize());\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa;;;AC2Ef,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAAM,SAAS;AAC3B,SAAK,UAAU,6B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AAA,EACF,GAGmB;AACjB,UAAM,SAAS,8BAA8B,QAAQ;AAAA,MACnD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO,IAAI,eAAe,OAAO,UAAU,CAAC;AAAA,EAC9C;AACF;","names":["pathToRegexp","pathToRegexp","_a"]}
|
package/dist/next/client.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var M=Object.create;var C=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},_=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of H(e))!I.call(t,r)&&r!==n&&C(t,r,{get:()=>e[r],enumerable:!(o=w(e,r))||o.enumerable});return t};var N=(t,e,n)=>(n=t!=null?M(Z(t)):{},_(e||!t||!t.__esModule?C(n,"default",{value:t,enumerable:!0}):n,t)),z=t=>_(C({},"__esModule",{value:!0}),t);var $={};D($,{Link:()=>F,PrefetchCrossZoneLinks:()=>U,PrefetchCrossZoneLinksContext:()=>E,PrefetchCrossZoneLinksProvider:()=>J,useZoneForHref:()=>T});module.exports=z($);var P=require("react"),S=N(require("next/link"),1);var d=require("react");var b=require("path-to-regexp"),l=class{constructor(e,n){this.pathCache={};if(this.serialized=e,n!=null&&n.removeFlaggedPaths)for(let o of Object.values(e.applications))o.routing&&(o.routing=o.routing.filter(r=>!r.flag));this.applications=e.applications}static fromEnv(e,n){if(!e)throw new Error("No microfrontends configuration found");return new l(JSON.parse(e),n)}isEqual(e){return JSON.stringify(this.applications)===JSON.stringify(e.applications)}getApplicationNameForPath(e){if(!e.startsWith("/"))throw new Error("Path must start with a /");if(this.pathCache[e])return this.pathCache[e];let n=new URL(e,"https://example.com").pathname;for(let[r,i]of Object.entries(this.applications))if(i.routing){for(let a of i.routing)for(let s of a.paths)if((0,b.pathToRegexp)(s).test(n))return this.pathCache[e]=r,r}let o=Object.entries(this.applications).find(([,r])=>r.default);return o?(this.pathCache[e]=o[0],o[0]):null}serialize(){return this.serialized}};var v=null;async function B(){try{let t=await fetch("/.well-known/vercel/microfrontends/client-config");if(t.status!==200)return null;let e=await t.json();return new l(e.config)}catch{return null}}function g(t,{removeFlaggedPathsFromDefault:e}={}){let[n,o]=(0,d.useState)(l.fromEnv(t,{removeFlaggedPaths:e})),[r,i]=(0,d.useState)(!0);return(0,d.useEffect)(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){i(!1);return}let a=l.fromEnv(t);if(!Object.values(a.applications).some(u=>{var p;return(p=u.routing)==null?void 0:p.some(A=>A.flag)})){i(!1);return}v||(v=B()),v.then(u=>{u&&o(p=>p.isEqual(u)?p:u)}).finally(()=>{i(!1)})},[t,n.applications]),{clientConfig:n,isLoading:r}}var f=require("react"),h=require("react/jsx-runtime"),E=(0,f.createContext)({prefetchHref:()=>{}});function J({children:t}){let[e,n]=(0,f.useState)(new Set),[o,r]=(0,f.useState)(!1);(0,f.useEffect)(()=>{r(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let i=(0,f.useCallback)(s=>{e.has(s)||n(new Set(e).add(s))},[e]),a=(0,f.useMemo)(()=>({prefetchHref:i}),[i]);return o?(0,h.jsxs)(E.Provider,{value:a,children:[t,[...e].map(s=>(0,h.jsx)("link",{as:"fetch",href:s,rel:"preload"},s))]}):(0,h.jsx)(h.Fragment,{children:t})}var m=require("react"),O=N(require("next/script"),1);var R=require("react/jsx-runtime"),L="data-prefetch",c={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${L}]`},x={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}}]},V={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}},{selector_matches:c.prefetch}]};function k(t){if(!t)return!0;if("checkVisibility"in t)return t.checkVisibility({opacityProperty:!0});let e=t,n=window.getComputedStyle(e);return n.display==="none"||n.visibility==="hidden"||n.opacity==="0"?!1:k(e.parentElement)}function U(){let{isLoading:t}=g(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG),[e,n]=(0,m.useState)([]);return(0,m.useEffect)(()=>{if(t)return;let r=new IntersectionObserver(i=>{i.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(L)&&k(a.target)&&a.target.setAttribute(L,"true")})},{root:null,rootMargin:"0px",threshold:.1});return e.forEach(i=>r.observe(i)),()=>{r.disconnect()}},[t,e]),(0,m.useEffect)(()=>{if(t)return;let r=new MutationObserver(i=>{i.some(s=>s.type==="childList"&&s.addedNodes.length>0||s.type==="attributes"&&s.attributeName==="href")&&n(Array.from(document.querySelectorAll(`a${c.anyZone}:not(${c.prefetch}):not(${c.sameZone}):not(${c.external})`)))});return r.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{r.disconnect()}},[t]),t?null:(0,R.jsx)(O.default,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:x},{eagerness:"immediate",where:V}],prerender:[{eagerness:"conservative",where:x}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}var y=require("react/jsx-runtime"),X=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function T(t){let{clientConfig:e,isLoading:n}=g(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,{removeFlaggedPathsFromDefault:!0}),o=typeof t=="string"&&t.startsWith("/"),r=o?e.getApplicationNameForPath(t):null;return{zoneOfHref:r,isDifferentZone:!o||(r?X!==r:!1),isLoading:n}}var F=(0,P.forwardRef)(({children:t,...e},n)=>{let{prefetchHref:o}=(0,P.useContext)(E),{zoneOfHref:r,isDifferentZone:i,isLoading:a}=T(e.href);function s(){e.href&&o(e.href)}if(i&&r!==null){let{prefetch:u,...p}=e;return(0,y.jsx)("a",{...p,"data-zone":r,onMouseOver:e.prefetch!==!1?s:void 0,children:t})}return(0,y.jsx)(S.default,{...e,"data-zone":r?"same":"null",prefetch:e.prefetch??(a?!1:void 0),ref:n,children:t})});F.displayName="MultiZonesLink";0&&(module.exports={Link,PrefetchCrossZoneLinks,PrefetchCrossZoneLinksContext,PrefetchCrossZoneLinksProvider,useZoneForHref});
|
|
3
3
|
//# sourceMappingURL=client.cjs.map
|
package/dist/next/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/client/index.ts","../../src/next/client/link/multi-zones-link.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links-context.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links.tsx","../../src/config/client/use-client-config.ts","../../src/config/client/client-config.ts","../../src/config/client/paths.ts"],"sourcesContent":["export * from './link';\nexport * from './prefetch';\n","import type { AnchorHTMLAttributes } from 'react';\nimport { forwardRef, useContext } from 'react';\nimport NextLink, { type LinkProps as NextLinkProps } from 'next/link';\nimport { PrefetchCrossZoneLinksContext } from '../prefetch';\nimport { getApplicationNameForPath } from '../../../config/client/paths';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\ninterface BaseProps {\n children: React.ReactNode;\n href: string;\n}\nexport type LinkProps = BaseProps &\n Omit<NextLinkProps, keyof BaseProps> &\n Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseProps>;\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport function useZoneForHref(href: LinkProps['href'] | undefined): {\n zoneOfHref: string | null;\n isDifferentZone: boolean;\n isLoading: boolean;\n} {\n const { clientConfig, isLoading } = useClientConfig({\n removeFlaggedPathsFromDefault: true,\n });\n const isRelativePath =\n typeof href === 'string' && (href as string).startsWith('/');\n const zoneOfHref = isRelativePath\n ? getApplicationNameForPath(clientConfig, href as string)\n : null;\n const isDifferentZone =\n !isRelativePath || (zoneOfHref ? CURRENT_ZONE !== zoneOfHref : false);\n return { zoneOfHref, isDifferentZone, isLoading };\n}\n\n/**\n * A Link component that works with Multi-Zones set-ups and will prefetch the\n * cross zone links automatically.\n */\nexport const Link = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ children, ...props }, ref): JSX.Element => {\n const { prefetchHref } = useContext(PrefetchCrossZoneLinksContext);\n const { zoneOfHref, isDifferentZone, isLoading } = useZoneForHref(\n props.href,\n );\n\n function onHoverPrefetch(): void {\n if (!props.href) {\n return;\n }\n prefetchHref(props.href);\n }\n\n if (isDifferentZone && zoneOfHref !== null) {\n const { prefetch: _, ...rest } = props;\n return (\n // biome-ignore lint/a11y/useKeyWithMouseEvents: Only used for prefetching.\n // biome-ignore lint/nursery/noStaticElementInteractions: Ignored using `--suppress`\n <a\n {...rest}\n data-zone={zoneOfHref}\n onMouseOver={props.prefetch !== false ? onHoverPrefetch : undefined}\n >\n {children}\n </a>\n );\n }\n\n return (\n <NextLink\n {...props}\n data-zone={!zoneOfHref ? 'null' : 'same'}\n prefetch={props.prefetch ?? (isLoading ? false : undefined)}\n ref={ref}\n >\n {children}\n </NextLink>\n );\n },\n);\nLink.displayName = 'MultiZonesLink';\n","import React, {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nexport interface PrefetchCrossZoneLinksContext {\n prefetchHref: (href: string) => void;\n}\n\nexport const PrefetchCrossZoneLinksContext =\n createContext<PrefetchCrossZoneLinksContext>({\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n prefetchHref: () => {},\n });\n\nexport function PrefetchCrossZoneLinksProvider({\n children,\n}: { children: React.ReactNode }): JSX.Element | null {\n const [seenHrefs, setSeenHrefs] = useState(new Set<string>());\n const [isSafariOrFirefox, setIsSafariOrFirefox] = useState(false);\n\n useEffect(() => {\n setIsSafariOrFirefox(\n typeof navigator !== 'undefined' &&\n (navigator.userAgent.includes('Firefox') ||\n (navigator.userAgent.includes('Safari') &&\n !navigator.userAgent.includes('Chrome'))),\n );\n }, []);\n\n const prefetchHref = useCallback(\n (href: string): void => {\n if (!seenHrefs.has(href)) {\n setSeenHrefs(new Set(seenHrefs).add(href));\n }\n },\n [seenHrefs],\n );\n\n const value = useMemo(() => ({ prefetchHref }), [prefetchHref]);\n\n if (!isSafariOrFirefox) {\n return <>{children}</>;\n }\n\n return (\n <PrefetchCrossZoneLinksContext.Provider value={value}>\n {children}\n {[...seenHrefs].map((href) => (\n <link as=\"fetch\" href={href} key={href} rel=\"preload\" />\n ))}\n </PrefetchCrossZoneLinksContext.Provider>\n );\n}\n","import { useEffect, useState } from 'react';\nimport Script from 'next/script';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\nconst PREFETCH_ATTR = 'data-prefetch';\nconst DATA_ATTR_SELECTORS = {\n anyZone: '[data-zone]',\n external: '[data-zone=\"null\"]',\n sameZone: '[data-zone=\"same\"]',\n prefetch: `[${PREFETCH_ATTR}]`,\n} as const;\n\nconst PREFETCH_ON_HOVER_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n ],\n};\n\nconst PREFETCH_WHEN_VISIBLE_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n { selector_matches: DATA_ATTR_SELECTORS.prefetch },\n ],\n};\n\nfunction checkVisibility(element: Element | null): boolean {\n if (!element) return true;\n\n if ('checkVisibility' in element) {\n return element.checkVisibility({ opacityProperty: true });\n }\n\n // hack to get around TS thinking element is never;\n const el = element as Element;\n const style = window.getComputedStyle(el);\n\n if (\n style.display === 'none' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false;\n }\n\n return checkVisibility(el.parentElement);\n}\n\nexport function PrefetchCrossZoneLinks(): JSX.Element | null {\n const { isLoading } = useClientConfig();\n const [links, setLinks] = useState<HTMLAnchorElement[]>([]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Intersection observer to add the data-prefetch attribute to cross-zone\n * links that have yet to be prefetched and are visible.\n */\n const observer = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (\n entry.isIntersecting &&\n !entry.target.hasAttribute(PREFETCH_ATTR) &&\n // lazy perform the visibility check for nodes that are intersecting the viewport\n // and have not been prefetched.\n checkVisibility(entry.target)\n ) {\n entry.target.setAttribute(PREFETCH_ATTR, 'true');\n }\n });\n },\n {\n root: null,\n rootMargin: '0px',\n threshold: 0.1,\n },\n );\n\n links.forEach((link) => observer.observe(link));\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading, links]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Mutation observer to notify when new nodes have entered/exited the document\n * or an href has changed.\n */\n const observer = new MutationObserver((mutations) => {\n const hasChanged = mutations.some((mutation) => {\n return (\n (mutation.type === 'childList' && mutation.addedNodes.length > 0) ||\n (mutation.type === 'attributes' && mutation.attributeName === 'href')\n );\n });\n\n if (hasChanged) {\n // Whenever there's a change, add all cross-zone links that haven't been\n // prefetched.\n setLinks(\n Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n `a${DATA_ATTR_SELECTORS.anyZone}:not(${DATA_ATTR_SELECTORS.prefetch}):not(${DATA_ATTR_SELECTORS.sameZone}):not(${DATA_ATTR_SELECTORS.external})`,\n ),\n ),\n );\n }\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['href'],\n });\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading]);\n\n // Wait till the zone-config loads to take into consideration any\n // flagged routes.\n if (isLoading) {\n return null;\n }\n\n // Prefetch links with moderate eagerness by default, immediately when marked \"data-prefetch\".\n // Prerender links with conservative eagerness by default, immediately when marked \"data-prefetch\".\n const speculationRules = {\n prefetch: [\n {\n eagerness: 'moderate',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n {\n eagerness: 'immediate',\n where: PREFETCH_WHEN_VISIBLE_PREDICATES,\n },\n ],\n prerender: [\n {\n eagerness: 'conservative',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n ],\n };\n\n return (\n <Script\n dangerouslySetInnerHTML={{\n __html: `${JSON.stringify(speculationRules)}`,\n }}\n id=\"prefetch-zones-links\"\n type=\"speculationrules\"\n />\n );\n}\n","'use client';\n\nimport { useState, useEffect } from 'react';\nimport type { ClientConfig, WellKnownClientData } from './types';\nimport { getClientConfigFromEnv } from './client-config';\n\nlet cachedServerClientConfigPromise: Promise<ClientConfig | null> | null = null;\n\nasync function fetchClientConfigFromServer(): Promise<ClientConfig | null> {\n try {\n const response = await fetch(\n '/.well-known/vercel/microfrontends/client-config',\n );\n if (response.status !== 200) {\n return null;\n }\n const responseJson = (await response.json()) as WellKnownClientData;\n return responseJson.config;\n } catch (err) {\n return null;\n }\n}\n\nfunction isEqual(config1: ClientConfig, config2: ClientConfig): boolean {\n return JSON.stringify(config1) === JSON.stringify(config2);\n}\n\nfunction removeFlaggedPaths(config: ClientConfig): ClientConfig {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing.matches = app.routing.matches.filter(\n (match) => !match.options?.flag,\n );\n }\n }\n return config;\n}\n\n/**\n * Hook to use the client micro-frontends configuration. This hook will resolve\n * dynamic paths by fetching the configuration from the server if necessary,\n * allowing the server to specify the values for dynamic paths.\n */\nexport function useClientConfig({\n removeFlaggedPathsFromDefault,\n}: {\n removeFlaggedPathsFromDefault?: boolean;\n} = {}): {\n clientConfig: ClientConfig;\n isLoading: boolean;\n} {\n const [clientConfig, setClientConfig] = useState<ClientConfig>(\n removeFlaggedPathsFromDefault\n ? removeFlaggedPaths(getClientConfigFromEnv())\n : getClientConfigFromEnv(),\n );\n const [isLoading, setIsLoading] = useState(true);\n useEffect(() => {\n if (\n process.env.NODE_ENV === 'test' &&\n process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER !== '1'\n ) {\n setIsLoading(false);\n return;\n }\n // Since we may remove flagged paths from the client config above, we need\n // to use the original client config to determine if the config has any\n // dynamic paths.\n const originalClientConfig = getClientConfigFromEnv();\n // As an optimization, only fetch the config from the server if the\n // micro-frontends configuration has any dynamic paths. If it doesn't,\n // then the server won't return any different values.\n const hasDynamicPaths = Object.values(\n originalClientConfig.applications,\n ).some((app) => app.routing?.matches.some((group) => group.options?.flag));\n if (!hasDynamicPaths) {\n setIsLoading(false);\n return;\n }\n if (!cachedServerClientConfigPromise) {\n cachedServerClientConfigPromise = fetchClientConfigFromServer();\n }\n void cachedServerClientConfigPromise\n .then((newConfig) => {\n if (newConfig) {\n setClientConfig((prevConfig) => {\n return isEqual(prevConfig, newConfig) ? prevConfig : newConfig;\n });\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, [clientConfig.applications]);\n\n return { clientConfig, isLoading };\n}\n\nexport function resetCachedServerClientConfigPromise(): void {\n cachedServerClientConfigPromise = null;\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\nconst weakCache = new WeakMap<ClientConfig, Record<string, string>>();\n/**\n * Given a relative path, this function returns the name of the micro-frontend\n * that serves the path.\n */\nexport function getApplicationNameForPath(\n config: ClientConfig,\n path: string,\n): string {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n const cache = weakCache.get(config) ?? {};\n if (cache[path]) {\n return cache[path];\n }\n if (!weakCache.has(config)) {\n weakCache.set(config, cache);\n }\n const pathname = new URL(path, 'https://example.com').pathname;\n\n for (const [name, application] of Object.entries(config.applications)) {\n if (application.routing) {\n for (const group of application.routing.matches) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n cache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(config.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n throw new Error(\n 'No default application found. A default application must be configured in the micro-frontends configuration.',\n );\n }\n cache[path] = defaultApplication[0];\n return defaultApplication[0];\n}\n"],"mappings":";0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,2BAAAC,EAAA,kCAAAC,EAAA,mCAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GCCA,IAAAQ,EAAuC,iBACvCC,EAA0D,0BCF1D,IAAAC,EAMO,iBAuCIC,EAAA,6BAjCEC,KACX,iBAA6C,CAE3C,aAAc,IAAM,CAAC,CACvB,CAAC,EAEI,SAASC,EAA+B,CAC7C,SAAAC,CACF,EAAsD,CACpD,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,IAAI,GAAa,EACtD,CAACC,EAAmBC,CAAoB,KAAI,YAAS,EAAK,KAEhE,aAAU,IAAM,CACdA,EACE,OAAO,UAAc,MAClB,UAAU,UAAU,SAAS,SAAS,GACpC,UAAU,UAAU,SAAS,QAAQ,GACpC,CAAC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,EACA,GAAI,CAACG,EACH,MAAM,IAAI,MACR,8GACF,EAEF,OAAAN,EAAMD,CAAI,EAAIO,EAAmB,CAAC,EAC3BA,EAAmB,CAAC,CAC7B,CLWQ,IAAAC,EAAA,6BA3CFC,EAAe,QAAQ,IAAI,oCAE1B,SAASC,EAAeC,EAI7B,CACA,GAAM,CAAE,aAAAC,EAAc,UAAAC,CAAU,EAAIC,EAAgB,CAClD,8BAA+B,EACjC,CAAC,EACKC,EACJ,OAAOJ,GAAS,UAAaA,EAAgB,WAAW,GAAG,EACvDK,EAAaD,EACfE,EAA0BL,EAAcD,CAAc,EACtD,KAGJ,MAAO,CAAE,WAAAK,EAAY,gBADnB,CAACD,IAAmBC,EAAaP,IAAiBO,EAAa,IAC3B,UAAAH,CAAU,CAClD,CAMO,IAAMK,KAAO,cAClB,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAM,EAAGC,IAAqB,CAC5C,GAAM,CAAE,aAAAC,CAAa,KAAI,cAAWC,CAA6B,EAC3D,CAAE,WAAAP,EAAY,gBAAAQ,EAAiB,UAAAX,CAAU,EAAIH,EACjDU,EAAM,IACR,EAEA,SAASK,GAAwB,CAC1BL,EAAM,MAGXE,EAAaF,EAAM,IAAI,CACzB,CAEA,GAAII,GAAmBR,IAAe,KAAM,CAC1C,GAAM,CAAE,SAAUU,EAAG,GAAGC,CAAK,EAAIP,EACjC,SAGE,OAAC,KACE,GAAGO,EACJ,YAAWX,EACX,YAAaI,EAAM,WAAa,GAAQK,EAAkB,OAEzD,SAAAN,EACH,EAIJ,SACE,OAAC,EAAAS,QAAA,CACE,GAAGR,EACJ,YAAYJ,EAAsB,OAAT,OACzB,SAAUI,EAAM,WAAaP,EAAY,GAAQ,QACjD,IAAKQ,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAD,EAAK,YAAc","names":["client_exports","__export","Link","PrefetchCrossZoneLinks","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","useZoneForHref","__toCommonJS","import_react","import_link","import_react","import_jsx_runtime","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","import_react","import_script","import_react","getClientConfigFromEnv","clientConfigJson","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","isEqual","config1","config2","removeFlaggedPaths","config","app","match","_a","useClientConfig","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","getClientConfigFromEnv","isLoading","setIsLoading","originalClientConfig","group","newConfig","prevConfig","import_jsx_runtime","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","observer","entries","entry","link","mutations","mutation","Script","import_path_to_regexp","weakCache","getApplicationNameForPath","config","path","cache","pathname","name","application","group","childPath","defaultApplication","import_jsx_runtime","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","getApplicationNameForPath","Link","children","props","ref","prefetchHref","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/client/index.ts","../../src/next/client/link/multi-zones-link.tsx","../../src/config/react/use-client-config.ts","../../src/config/microfrontends-config/client/index.ts","../../src/next/client/prefetch/prefetch-cross-zone-links-context.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links.tsx"],"sourcesContent":["export * from './link';\nexport * from './prefetch';\n","import type { AnchorHTMLAttributes } from 'react';\nimport { forwardRef, useContext } from 'react';\nimport NextLink, { type LinkProps as NextLinkProps } from 'next/link';\nimport { useClientConfig } from '../../../config/react/use-client-config';\nimport { PrefetchCrossZoneLinksContext } from '../prefetch';\n\ninterface BaseProps {\n children: React.ReactNode;\n href: string;\n}\nexport type LinkProps = BaseProps &\n Omit<NextLinkProps, keyof BaseProps> &\n Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseProps>;\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport function useZoneForHref(href: LinkProps['href'] | undefined): {\n zoneOfHref: string | null;\n isDifferentZone: boolean;\n isLoading: boolean;\n} {\n const { clientConfig, isLoading } = useClientConfig(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n {\n removeFlaggedPathsFromDefault: true,\n },\n );\n const isRelativePath =\n typeof href === 'string' && (href as string).startsWith('/');\n const zoneOfHref = isRelativePath\n ? clientConfig.getApplicationNameForPath(href as string)\n : null;\n const isDifferentZone =\n !isRelativePath || (zoneOfHref ? CURRENT_ZONE !== zoneOfHref : false);\n return { zoneOfHref, isDifferentZone, isLoading };\n}\n\n/**\n * A Link component that works with Multi-Zones set-ups and will prefetch the\n * cross zone links automatically.\n */\nexport const Link = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ children, ...props }, ref): JSX.Element => {\n const { prefetchHref } = useContext(PrefetchCrossZoneLinksContext);\n const { zoneOfHref, isDifferentZone, isLoading } = useZoneForHref(\n props.href,\n );\n\n function onHoverPrefetch(): void {\n if (!props.href) {\n return;\n }\n prefetchHref(props.href);\n }\n\n if (isDifferentZone && zoneOfHref !== null) {\n const { prefetch: _, ...rest } = props;\n return (\n // biome-ignore lint/a11y/useKeyWithMouseEvents: Only used for prefetching.\n // biome-ignore lint/nursery/noStaticElementInteractions: Ignored using `--suppress`\n <a\n {...rest}\n data-zone={zoneOfHref}\n onMouseOver={props.prefetch !== false ? onHoverPrefetch : undefined}\n >\n {children}\n </a>\n );\n }\n\n return (\n <NextLink\n {...props}\n data-zone={!zoneOfHref ? 'null' : 'same'}\n prefetch={props.prefetch ?? (isLoading ? false : undefined)}\n ref={ref}\n >\n {children}\n </NextLink>\n );\n },\n);\nLink.displayName = 'MultiZonesLink';\n","'use client';\n\nimport { useState, useEffect } from 'react';\nimport type { WellKnownClientData } from '../well-known/types';\nimport { MicrofrontendConfigClient } from '../microfrontends-config/client';\n\nlet cachedServerClientConfigPromise: Promise<MicrofrontendConfigClient | null> | null =\n null;\n\nasync function fetchClientConfigFromServer(): Promise<MicrofrontendConfigClient | null> {\n try {\n const response = await fetch(\n '/.well-known/vercel/microfrontends/client-config',\n );\n if (response.status !== 200) {\n return null;\n }\n const responseJson = (await response.json()) as WellKnownClientData;\n return new MicrofrontendConfigClient(responseJson.config);\n } catch (err) {\n return null;\n }\n}\n\n/**\n * Hook to use the client microfrontends configuration. This hook will resolve\n * dynamic paths by fetching the configuration from the server if necessary,\n * allowing the server to specify the values for dynamic paths.\n */\nexport function useClientConfig(\n config: string | undefined,\n {\n removeFlaggedPathsFromDefault,\n }: {\n removeFlaggedPathsFromDefault?: boolean;\n } = {},\n): {\n clientConfig: MicrofrontendConfigClient;\n isLoading: boolean;\n} {\n const [clientConfig, setClientConfig] = useState<MicrofrontendConfigClient>(\n MicrofrontendConfigClient.fromEnv(config, {\n removeFlaggedPaths: removeFlaggedPathsFromDefault,\n }),\n );\n const [isLoading, setIsLoading] = useState(true);\n useEffect(() => {\n if (\n process.env.NODE_ENV === 'test' &&\n process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER !== '1'\n ) {\n setIsLoading(false);\n return;\n }\n // Since we may remove flagged paths from the client config above, we need\n // to use the original client config to determine if the config has any\n // dynamic paths.\n const originalClientConfig = MicrofrontendConfigClient.fromEnv(config);\n // As an optimization, only fetch the config from the server if the\n // microfrontends configuration has any dynamic paths. If it doesn't,\n // then the server won't return any different values.\n const hasDynamicPaths = Object.values(\n originalClientConfig.applications,\n ).some((app) => app.routing?.some((group) => group.flag));\n if (!hasDynamicPaths) {\n setIsLoading(false);\n return;\n }\n if (!cachedServerClientConfigPromise) {\n cachedServerClientConfigPromise = fetchClientConfigFromServer();\n }\n void cachedServerClientConfigPromise\n .then((newConfig) => {\n if (newConfig) {\n setClientConfig((prevConfig) => {\n return prevConfig.isEqual(newConfig) ? prevConfig : newConfig;\n });\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, [config, clientConfig.applications]);\n\n return { clientConfig, isLoading };\n}\n\nexport function resetCachedServerClientConfigPromise(): void {\n cachedServerClientConfigPromise = null;\n}\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 React, {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nexport interface PrefetchCrossZoneLinksContext {\n prefetchHref: (href: string) => void;\n}\n\nexport const PrefetchCrossZoneLinksContext =\n createContext<PrefetchCrossZoneLinksContext>({\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n prefetchHref: () => {},\n });\n\nexport function PrefetchCrossZoneLinksProvider({\n children,\n}: { children: React.ReactNode }): JSX.Element | null {\n const [seenHrefs, setSeenHrefs] = useState(new Set<string>());\n const [isSafariOrFirefox, setIsSafariOrFirefox] = useState(false);\n\n useEffect(() => {\n setIsSafariOrFirefox(\n typeof navigator !== 'undefined' &&\n (navigator.userAgent.includes('Firefox') ||\n (navigator.userAgent.includes('Safari') &&\n !navigator.userAgent.includes('Chrome'))),\n );\n }, []);\n\n const prefetchHref = useCallback(\n (href: string): void => {\n if (!seenHrefs.has(href)) {\n setSeenHrefs(new Set(seenHrefs).add(href));\n }\n },\n [seenHrefs],\n );\n\n const value = useMemo(() => ({ prefetchHref }), [prefetchHref]);\n\n if (!isSafariOrFirefox) {\n return <>{children}</>;\n }\n\n return (\n <PrefetchCrossZoneLinksContext.Provider value={value}>\n {children}\n {[...seenHrefs].map((href) => (\n <link as=\"fetch\" href={href} key={href} rel=\"preload\" />\n ))}\n </PrefetchCrossZoneLinksContext.Provider>\n );\n}\n","import { useEffect, useState } from 'react';\nimport Script from 'next/script';\nimport { useClientConfig } from '../../../config/react/use-client-config';\n\nconst PREFETCH_ATTR = 'data-prefetch';\nconst DATA_ATTR_SELECTORS = {\n anyZone: '[data-zone]',\n external: '[data-zone=\"null\"]',\n sameZone: '[data-zone=\"same\"]',\n prefetch: `[${PREFETCH_ATTR}]`,\n} as const;\n\nconst PREFETCH_ON_HOVER_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n ],\n};\n\nconst PREFETCH_WHEN_VISIBLE_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n { selector_matches: DATA_ATTR_SELECTORS.prefetch },\n ],\n};\n\nfunction checkVisibility(element: Element | null): boolean {\n if (!element) return true;\n\n if ('checkVisibility' in element) {\n return element.checkVisibility({ opacityProperty: true });\n }\n\n // hack to get around TS thinking element is never;\n const el = element as Element;\n const style = window.getComputedStyle(el);\n\n if (\n style.display === 'none' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false;\n }\n\n return checkVisibility(el.parentElement);\n}\n\nexport function PrefetchCrossZoneLinks(): JSX.Element | null {\n const { isLoading } = useClientConfig(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n );\n const [links, setLinks] = useState<HTMLAnchorElement[]>([]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Intersection observer to add the data-prefetch attribute to cross-zone\n * links that have yet to be prefetched and are visible.\n */\n const observer = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (\n entry.isIntersecting &&\n !entry.target.hasAttribute(PREFETCH_ATTR) &&\n // lazy perform the visibility check for nodes that are intersecting the viewport\n // and have not been prefetched.\n checkVisibility(entry.target)\n ) {\n entry.target.setAttribute(PREFETCH_ATTR, 'true');\n }\n });\n },\n {\n root: null,\n rootMargin: '0px',\n threshold: 0.1,\n },\n );\n\n links.forEach((link) => observer.observe(link));\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading, links]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Mutation observer to notify when new nodes have entered/exited the document\n * or an href has changed.\n */\n const observer = new MutationObserver((mutations) => {\n const hasChanged = mutations.some((mutation) => {\n return (\n (mutation.type === 'childList' && mutation.addedNodes.length > 0) ||\n (mutation.type === 'attributes' && mutation.attributeName === 'href')\n );\n });\n\n if (hasChanged) {\n // Whenever there's a change, add all cross-zone links that haven't been\n // prefetched.\n setLinks(\n Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n `a${DATA_ATTR_SELECTORS.anyZone}:not(${DATA_ATTR_SELECTORS.prefetch}):not(${DATA_ATTR_SELECTORS.sameZone}):not(${DATA_ATTR_SELECTORS.external})`,\n ),\n ),\n );\n }\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['href'],\n });\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading]);\n\n // Wait till the zone-config loads to take into consideration any\n // flagged routes.\n if (isLoading) {\n return null;\n }\n\n // Prefetch links with moderate eagerness by default, immediately when marked \"data-prefetch\".\n // Prerender links with conservative eagerness by default, immediately when marked \"data-prefetch\".\n const speculationRules = {\n prefetch: [\n {\n eagerness: 'moderate',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n {\n eagerness: 'immediate',\n where: PREFETCH_WHEN_VISIBLE_PREDICATES,\n },\n ],\n prerender: [\n {\n eagerness: 'conservative',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n ],\n };\n\n return (\n <Script\n dangerouslySetInnerHTML={{\n __html: `${JSON.stringify(speculationRules)}`,\n }}\n id=\"prefetch-zones-links\"\n type=\"speculationrules\"\n />\n );\n}\n"],"mappings":";0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,2BAAAC,EAAA,kCAAAC,EAAA,mCAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GCCA,IAAAQ,EAAuC,iBACvCC,EAA0D,0BCA1D,IAAAC,EAAoC,iBCFpC,IAAAC,EAA6B,0BAOhBC,EAAN,KAAgC,CAKrC,YAAYC,EAAsBC,EAAyC,CAH3E,eAAoC,CAAC,EAKnC,GADA,KAAK,WAAaD,EACd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D,IAAKO,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAD,EAAK,YAAc","names":["client_exports","__export","Link","PrefetchCrossZoneLinks","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","useZoneForHref","__toCommonJS","import_react","import_link","import_react","import_path_to_regexp","MicrofrontendConfigClient","config","opts","app","match","other","path","pathname","name","application","group","childPath","defaultApplication","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","responseJson","MicrofrontendConfigClient","useClientConfig","config","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","isLoading","setIsLoading","originalClientConfig","app","_a","group","newConfig","prevConfig","import_react","import_jsx_runtime","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","import_react","import_script","import_jsx_runtime","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","observer","entries","entry","link","mutations","mutation","Script","import_jsx_runtime","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","Link","children","props","ref","prefetchHref","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
|
package/dist/next/client.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{forwardRef as
|
|
2
|
+
import{forwardRef as Z,useContext as I}from"react";import D from"next/link";import{useState as C,useEffect as b}from"react";import{pathToRegexp as N}from"path-to-regexp";var c=class{constructor(e,r){this.pathCache={};if(this.serialized=e,r!=null&&r.removeFlaggedPaths)for(let i of Object.values(e.applications))i.routing&&(i.routing=i.routing.filter(n=>!n.flag));this.applications=e.applications}static fromEnv(e,r){if(!e)throw new Error("No microfrontends configuration found");return new c(JSON.parse(e),r)}isEqual(e){return JSON.stringify(this.applications)===JSON.stringify(e.applications)}getApplicationNameForPath(e){if(!e.startsWith("/"))throw new Error("Path must start with a /");if(this.pathCache[e])return this.pathCache[e];let r=new URL(e,"https://example.com").pathname;for(let[n,o]of Object.entries(this.applications))if(o.routing){for(let a of o.routing)for(let s of a.paths)if(N(s).test(r))return this.pathCache[e]=n,n}let i=Object.entries(this.applications).find(([,n])=>n.default);return i?(this.pathCache[e]=i[0],i[0]):null}serialize(){return this.serialized}};var h=null;async function x(){try{let t=await fetch("/.well-known/vercel/microfrontends/client-config");if(t.status!==200)return null;let e=await t.json();return new c(e.config)}catch{return null}}function p(t,{removeFlaggedPathsFromDefault:e}={}){let[r,i]=C(c.fromEnv(t,{removeFlaggedPaths:e})),[n,o]=C(!0);return b(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){o(!1);return}let a=c.fromEnv(t);if(!Object.values(a.applications).some(l=>{var u;return(u=l.routing)==null?void 0:u.some(_=>_.flag)})){o(!1);return}h||(h=x()),h.then(l=>{l&&i(u=>u.isEqual(l)?u:l)}).finally(()=>{o(!1)})},[t,r.applications]),{clientConfig:r,isLoading:n}}import{createContext as O,useCallback as k,useEffect as R,useMemo as S,useState as g}from"react";import{Fragment as T,jsx as E,jsxs as F}from"react/jsx-runtime";var d=O({prefetchHref:()=>{}});function j({children:t}){let[e,r]=g(new Set),[i,n]=g(!1);R(()=>{n(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let o=k(s=>{e.has(s)||r(new Set(e).add(s))},[e]),a=S(()=>({prefetchHref:o}),[o]);return i?F(d.Provider,{value:a,children:[t,[...e].map(s=>E("link",{as:"fetch",href:s,rel:"preload"},s))]}):E(T,{children:t})}import{useEffect as P,useState as A}from"react";import M from"next/script";import{jsx as H}from"react/jsx-runtime";var m="data-prefetch",f={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${m}]`},v={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}}]},w={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}},{selector_matches:f.prefetch}]};function L(t){if(!t)return!0;if("checkVisibility"in t)return t.checkVisibility({opacityProperty:!0});let e=t,r=window.getComputedStyle(e);return r.display==="none"||r.visibility==="hidden"||r.opacity==="0"?!1:L(e.parentElement)}function ne(){let{isLoading:t}=p(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG),[e,r]=A([]);return P(()=>{if(t)return;let n=new IntersectionObserver(o=>{o.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(m)&&L(a.target)&&a.target.setAttribute(m,"true")})},{root:null,rootMargin:"0px",threshold:.1});return e.forEach(o=>n.observe(o)),()=>{n.disconnect()}},[t,e]),P(()=>{if(t)return;let n=new MutationObserver(o=>{o.some(s=>s.type==="childList"&&s.addedNodes.length>0||s.type==="attributes"&&s.attributeName==="href")&&r(Array.from(document.querySelectorAll(`a${f.anyZone}:not(${f.prefetch}):not(${f.sameZone}):not(${f.external})`)))});return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{n.disconnect()}},[t]),t?null:H(M,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:v},{eagerness:"immediate",where:w}],prerender:[{eagerness:"conservative",where:v}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}import{jsx as y}from"react/jsx-runtime";var z=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function B(t){let{clientConfig:e,isLoading:r}=p(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,{removeFlaggedPathsFromDefault:!0}),i=typeof t=="string"&&t.startsWith("/"),n=i?e.getApplicationNameForPath(t):null;return{zoneOfHref:n,isDifferentZone:!i||(n?z!==n:!1),isLoading:r}}var J=Z(({children:t,...e},r)=>{let{prefetchHref:i}=I(d),{zoneOfHref:n,isDifferentZone:o,isLoading:a}=B(e.href);function s(){e.href&&i(e.href)}if(o&&n!==null){let{prefetch:l,...u}=e;return y("a",{...u,"data-zone":n,onMouseOver:e.prefetch!==!1?s:void 0,children:t})}return y(D,{...e,"data-zone":n?"same":"null",prefetch:e.prefetch??(a?!1:void 0),ref:r,children:t})});J.displayName="MultiZonesLink";export{J as Link,ne as PrefetchCrossZoneLinks,d as PrefetchCrossZoneLinksContext,j as PrefetchCrossZoneLinksProvider,B as useZoneForHref};
|
|
3
3
|
//# sourceMappingURL=client.js.map
|