@vercel/microfrontends 2.2.2 → 2.3.1
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/CHANGELOG.md +12 -0
- package/dist/bin/cli.cjs +263 -263
- package/dist/config.cjs +23 -23
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +23 -23
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +260 -260
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +240 -240
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +260 -260
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +240 -240
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +260 -260
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +240 -240
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends/utils.cjs +22 -0
- package/dist/microfrontends/utils.cjs.map +1 -1
- package/dist/microfrontends/utils.d.ts +5 -1
- package/dist/microfrontends/utils.js +21 -0
- package/dist/microfrontends/utils.js.map +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +260 -260
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +240 -240
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +23 -23
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +23 -23
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +23 -23
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.js +23 -23
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +260 -260
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +240 -240
- package/dist/utils/mfe-port.js.map +1 -1
- package/package.json +2 -2
|
@@ -130,7 +130,16 @@ var MicrofrontendError = class extends Error {
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
// src/config/microfrontends-config/isomorphic/index.ts
|
|
133
|
-
import { parse } from "jsonc-parser";
|
|
133
|
+
import { parse as parse2 } from "jsonc-parser";
|
|
134
|
+
|
|
135
|
+
// src/config/microfrontends/utils/hash-application-name.ts
|
|
136
|
+
import md5 from "md5";
|
|
137
|
+
function hashApplicationName(name) {
|
|
138
|
+
if (!name) {
|
|
139
|
+
throw new Error("Application name is required to generate hash");
|
|
140
|
+
}
|
|
141
|
+
return md5(name).substring(0, 6).padStart(6, "0");
|
|
142
|
+
}
|
|
134
143
|
|
|
135
144
|
// src/config/overrides/constants.ts
|
|
136
145
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -280,6 +289,231 @@ function getConfigStringFromEnv() {
|
|
|
280
289
|
return config;
|
|
281
290
|
}
|
|
282
291
|
|
|
292
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
293
|
+
import fs from "node:fs";
|
|
294
|
+
import { join } from "node:path";
|
|
295
|
+
|
|
296
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
297
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
298
|
+
"microfrontends.json",
|
|
299
|
+
"microfrontends.jsonc"
|
|
300
|
+
];
|
|
301
|
+
function getPossibleConfigurationFilenames({
|
|
302
|
+
customConfigFilename
|
|
303
|
+
}) {
|
|
304
|
+
if (customConfigFilename) {
|
|
305
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`Found VC_MICROFRONTENDS_CONFIG_FILE_NAME but the name is invalid. Received: ${customConfigFilename}. The file name must end with '.json' or '.jsonc'. It's also possible for the env var to include the path, eg microfrontends-dev.json or /path/to/microfrontends-dev.json.`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
return Array.from(
|
|
311
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
318
|
+
function findConfig({
|
|
319
|
+
dir,
|
|
320
|
+
customConfigFilename
|
|
321
|
+
}) {
|
|
322
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
323
|
+
customConfigFilename
|
|
324
|
+
})) {
|
|
325
|
+
const maybeConfig = join(dir, filename);
|
|
326
|
+
if (fs.existsSync(maybeConfig)) {
|
|
327
|
+
return maybeConfig;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/config/microfrontends/utils/generate-default-asset-prefix.ts
|
|
334
|
+
var PREFIX = "vc-ap";
|
|
335
|
+
function generateDefaultAssetPrefixFromName({
|
|
336
|
+
name
|
|
337
|
+
}) {
|
|
338
|
+
if (!name) {
|
|
339
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
340
|
+
}
|
|
341
|
+
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
345
|
+
import { readFileSync, statSync } from "node:fs";
|
|
346
|
+
import { dirname, join as join2 } from "node:path";
|
|
347
|
+
import fg from "fast-glob";
|
|
348
|
+
import { parse } from "jsonc-parser";
|
|
349
|
+
var configCache = {};
|
|
350
|
+
function findPackageWithMicrofrontendsConfig({
|
|
351
|
+
repositoryRoot,
|
|
352
|
+
applicationContext,
|
|
353
|
+
customConfigFilename
|
|
354
|
+
}) {
|
|
355
|
+
const applicationName = applicationContext.name;
|
|
356
|
+
logger.debug(
|
|
357
|
+
"[MFE Config] Searching repository for configs containing application:",
|
|
358
|
+
applicationName
|
|
359
|
+
);
|
|
360
|
+
try {
|
|
361
|
+
const microfrontendsJsonPaths = fg.globSync(
|
|
362
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
363
|
+
{
|
|
364
|
+
cwd: repositoryRoot,
|
|
365
|
+
absolute: true,
|
|
366
|
+
onlyFiles: true,
|
|
367
|
+
followSymbolicLinks: false,
|
|
368
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
logger.debug(
|
|
372
|
+
"[MFE Config] Found",
|
|
373
|
+
microfrontendsJsonPaths.length,
|
|
374
|
+
"config file(s) in repository"
|
|
375
|
+
);
|
|
376
|
+
const matchingPaths = [];
|
|
377
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
378
|
+
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
379
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
logger.debug(
|
|
383
|
+
"[MFE Config] Total matching config files:",
|
|
384
|
+
matchingPaths.length
|
|
385
|
+
);
|
|
386
|
+
if (matchingPaths.length > 1) {
|
|
387
|
+
throw new MicrofrontendError(
|
|
388
|
+
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
389
|
+
${matchingPaths.join("\n \u2022 ")}`,
|
|
390
|
+
{ type: "config", subtype: "inference_failed" }
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
if (matchingPaths.length === 0) {
|
|
394
|
+
if (repositoryRoot && doesMisplacedConfigExist(
|
|
395
|
+
repositoryRoot,
|
|
396
|
+
applicationName,
|
|
397
|
+
customConfigFilename
|
|
398
|
+
)) {
|
|
399
|
+
logger.debug(
|
|
400
|
+
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
401
|
+
);
|
|
402
|
+
const misplacedConfigPath = join2(
|
|
403
|
+
repositoryRoot,
|
|
404
|
+
".vercel",
|
|
405
|
+
customConfigFilename || "microfrontends.json"
|
|
406
|
+
);
|
|
407
|
+
throw new MicrofrontendError(
|
|
408
|
+
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
409
|
+
|
|
410
|
+
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
411
|
+
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
412
|
+
|
|
413
|
+
To fix this:
|
|
414
|
+
1. If using \`vercel link\`, run it with \`vercel link --repo\` to handle monorepos, or run \`vercel microfrontends pull --cwd=<application-directory>\` to make sure it pulls the \`microfrontends.json\` file to the correct location
|
|
415
|
+
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
416
|
+
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
417
|
+
|
|
418
|
+
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
419
|
+
{ type: "config", subtype: "inference_failed" }
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
let additionalErrorMessage = "";
|
|
423
|
+
if (microfrontendsJsonPaths.length > 0) {
|
|
424
|
+
if (!applicationContext.projectName) {
|
|
425
|
+
additionalErrorMessage = `
|
|
426
|
+
|
|
427
|
+
If the name in package.json (${applicationContext.packageJsonName}) differs from your Vercel Project name, set the \`packageName\` field for the application in \`microfrontends.json\` to ensure that the configuration can be found locally.`;
|
|
428
|
+
} else {
|
|
429
|
+
additionalErrorMessage = `
|
|
430
|
+
|
|
431
|
+
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
throw new MicrofrontendError(
|
|
435
|
+
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
436
|
+
|
|
437
|
+
If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
|
|
438
|
+
|
|
439
|
+
If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
|
|
440
|
+
|
|
441
|
+
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
442
|
+
{ type: "config", subtype: "inference_failed" }
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
const [packageJsonPath] = matchingPaths;
|
|
446
|
+
return dirname(packageJsonPath);
|
|
447
|
+
} catch (error2) {
|
|
448
|
+
if (error2 instanceof MicrofrontendError) {
|
|
449
|
+
throw error2;
|
|
450
|
+
}
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function inferMicrofrontendsLocation(opts) {
|
|
455
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
456
|
+
if (configCache[cacheKey]) {
|
|
457
|
+
return configCache[cacheKey];
|
|
458
|
+
}
|
|
459
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
460
|
+
if (!result) {
|
|
461
|
+
throw new MicrofrontendError(
|
|
462
|
+
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
463
|
+
{ type: "config", subtype: "inference_failed" }
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
configCache[cacheKey] = result;
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
function existsSync(path6) {
|
|
470
|
+
try {
|
|
471
|
+
statSync(path6);
|
|
472
|
+
return true;
|
|
473
|
+
} catch (_) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
478
|
+
logger.debug(
|
|
479
|
+
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
480
|
+
);
|
|
481
|
+
const misplacedConfigPath = join2(
|
|
482
|
+
repositoryRoot,
|
|
483
|
+
".vercel",
|
|
484
|
+
customConfigFilename || "microfrontends.json"
|
|
485
|
+
);
|
|
486
|
+
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
487
|
+
}
|
|
488
|
+
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
489
|
+
try {
|
|
490
|
+
const microfrontendsJsonContent = readFileSync(
|
|
491
|
+
microfrontendsJsonPath,
|
|
492
|
+
"utf-8"
|
|
493
|
+
);
|
|
494
|
+
const microfrontendsJson = parse(microfrontendsJsonContent);
|
|
495
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
496
|
+
logger.debug(
|
|
497
|
+
"[MFE Config] Found application in config:",
|
|
498
|
+
microfrontendsJsonPath
|
|
499
|
+
);
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
503
|
+
if (app.packageName === applicationName) {
|
|
504
|
+
logger.debug(
|
|
505
|
+
"[MFE Config] Found application via packageName in config:",
|
|
506
|
+
microfrontendsJsonPath
|
|
507
|
+
);
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
} catch (error2) {
|
|
512
|
+
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
513
|
+
}
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
|
|
283
517
|
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
284
518
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
285
519
|
var MFE_APP_PORT_ENV = "MFE_APP_PORT";
|
|
@@ -418,26 +652,6 @@ var LocalHost = class extends Host {
|
|
|
418
652
|
}
|
|
419
653
|
};
|
|
420
654
|
|
|
421
|
-
// src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
|
|
422
|
-
import md5 from "md5";
|
|
423
|
-
function hashApplicationName(name) {
|
|
424
|
-
if (!name) {
|
|
425
|
-
throw new Error("Application name is required to generate hash");
|
|
426
|
-
}
|
|
427
|
-
return md5(name).substring(0, 6).padStart(6, "0");
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
431
|
-
var PREFIX = "vc-ap";
|
|
432
|
-
function generateAssetPrefixFromName({
|
|
433
|
-
name
|
|
434
|
-
}) {
|
|
435
|
-
if (!name) {
|
|
436
|
-
throw new Error("Name is required to generate an asset prefix");
|
|
437
|
-
}
|
|
438
|
-
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
655
|
// src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
|
|
442
656
|
function generateAutomationBypassEnvVarName({
|
|
443
657
|
name
|
|
@@ -518,7 +732,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
518
732
|
);
|
|
519
733
|
}
|
|
520
734
|
};
|
|
521
|
-
var
|
|
735
|
+
var PATH_DEFAULT_PATTERNS = ["[^\\/#\\?]+?", "(?:(?!\\.)[^\\/#\\?])+?"];
|
|
522
736
|
function validatePathExpression(path6) {
|
|
523
737
|
try {
|
|
524
738
|
const tokens = parsePathRegexp(path6);
|
|
@@ -540,7 +754,7 @@ function validatePathExpression(path6) {
|
|
|
540
754
|
if (!token.name) {
|
|
541
755
|
return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
|
|
542
756
|
}
|
|
543
|
-
if (token.pattern
|
|
757
|
+
if (!PATH_DEFAULT_PATTERNS.includes(token.pattern) && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
544
758
|
// Only limited regex is supported for now, due to performance considerations
|
|
545
759
|
// Allows all letters, numbers, and hyphens. Other characters must be escaped.
|
|
546
760
|
!/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
|
|
@@ -655,7 +869,7 @@ var Application = class {
|
|
|
655
869
|
return this.default;
|
|
656
870
|
}
|
|
657
871
|
getAssetPrefix() {
|
|
658
|
-
const generatedAssetPrefix =
|
|
872
|
+
const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
|
|
659
873
|
name: this.name
|
|
660
874
|
});
|
|
661
875
|
if ("assetPrefix" in this.serialized) {
|
|
@@ -749,7 +963,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
749
963
|
};
|
|
750
964
|
}
|
|
751
965
|
static validate(config) {
|
|
752
|
-
const c = typeof config === "string" ?
|
|
966
|
+
const c = typeof config === "string" ? parse2(config) : config;
|
|
753
967
|
validateConfigPaths(c.applications);
|
|
754
968
|
validateConfigDefaultApplication(c.applications);
|
|
755
969
|
return c;
|
|
@@ -758,7 +972,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
758
972
|
cookies
|
|
759
973
|
}) {
|
|
760
974
|
return new MicrofrontendConfigIsomorphic({
|
|
761
|
-
config:
|
|
975
|
+
config: parse2(getConfigStringFromEnv()),
|
|
762
976
|
overrides: parseOverrides(cookies ?? [])
|
|
763
977
|
});
|
|
764
978
|
}
|
|
@@ -872,47 +1086,6 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
872
1086
|
}
|
|
873
1087
|
};
|
|
874
1088
|
|
|
875
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
876
|
-
import fs from "node:fs";
|
|
877
|
-
import { join } from "node:path";
|
|
878
|
-
|
|
879
|
-
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
880
|
-
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
881
|
-
"microfrontends.json",
|
|
882
|
-
"microfrontends.jsonc"
|
|
883
|
-
];
|
|
884
|
-
function getPossibleConfigurationFilenames({
|
|
885
|
-
customConfigFilename
|
|
886
|
-
}) {
|
|
887
|
-
if (customConfigFilename) {
|
|
888
|
-
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
889
|
-
throw new Error(
|
|
890
|
-
`Found VC_MICROFRONTENDS_CONFIG_FILE_NAME but the name is invalid. Received: ${customConfigFilename}. The file name must end with '.json' or '.jsonc'. It's also possible for the env var to include the path, eg microfrontends-dev.json or /path/to/microfrontends-dev.json.`
|
|
891
|
-
);
|
|
892
|
-
}
|
|
893
|
-
return Array.from(
|
|
894
|
-
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
901
|
-
function findConfig({
|
|
902
|
-
dir,
|
|
903
|
-
customConfigFilename
|
|
904
|
-
}) {
|
|
905
|
-
for (const filename of getPossibleConfigurationFilenames({
|
|
906
|
-
customConfigFilename
|
|
907
|
-
})) {
|
|
908
|
-
const maybeConfig = join(dir, filename);
|
|
909
|
-
if (fs.existsSync(maybeConfig)) {
|
|
910
|
-
return maybeConfig;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
return null;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
1089
|
// src/config/microfrontends/utils/find-package-root.ts
|
|
917
1090
|
import fs2 from "node:fs";
|
|
918
1091
|
import path from "node:path";
|
|
@@ -1045,179 +1218,6 @@ function getApplicationContext(opts) {
|
|
|
1045
1218
|
}
|
|
1046
1219
|
}
|
|
1047
1220
|
|
|
1048
|
-
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
1049
|
-
import { readFileSync, statSync } from "node:fs";
|
|
1050
|
-
import { dirname, join as join2 } from "node:path";
|
|
1051
|
-
import fg from "fast-glob";
|
|
1052
|
-
import { parse as parse2 } from "jsonc-parser";
|
|
1053
|
-
var configCache = {};
|
|
1054
|
-
function findPackageWithMicrofrontendsConfig({
|
|
1055
|
-
repositoryRoot,
|
|
1056
|
-
applicationContext,
|
|
1057
|
-
customConfigFilename
|
|
1058
|
-
}) {
|
|
1059
|
-
const applicationName = applicationContext.name;
|
|
1060
|
-
logger.debug(
|
|
1061
|
-
"[MFE Config] Searching repository for configs containing application:",
|
|
1062
|
-
applicationName
|
|
1063
|
-
);
|
|
1064
|
-
try {
|
|
1065
|
-
const microfrontendsJsonPaths = fg.globSync(
|
|
1066
|
-
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
1067
|
-
{
|
|
1068
|
-
cwd: repositoryRoot,
|
|
1069
|
-
absolute: true,
|
|
1070
|
-
onlyFiles: true,
|
|
1071
|
-
followSymbolicLinks: false,
|
|
1072
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1073
|
-
}
|
|
1074
|
-
);
|
|
1075
|
-
logger.debug(
|
|
1076
|
-
"[MFE Config] Found",
|
|
1077
|
-
microfrontendsJsonPaths.length,
|
|
1078
|
-
"config file(s) in repository"
|
|
1079
|
-
);
|
|
1080
|
-
const matchingPaths = [];
|
|
1081
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1082
|
-
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
1083
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
logger.debug(
|
|
1087
|
-
"[MFE Config] Total matching config files:",
|
|
1088
|
-
matchingPaths.length
|
|
1089
|
-
);
|
|
1090
|
-
if (matchingPaths.length > 1) {
|
|
1091
|
-
throw new MicrofrontendError(
|
|
1092
|
-
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
1093
|
-
${matchingPaths.join("\n \u2022 ")}`,
|
|
1094
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
if (matchingPaths.length === 0) {
|
|
1098
|
-
if (repositoryRoot && doesMisplacedConfigExist(
|
|
1099
|
-
repositoryRoot,
|
|
1100
|
-
applicationName,
|
|
1101
|
-
customConfigFilename
|
|
1102
|
-
)) {
|
|
1103
|
-
logger.debug(
|
|
1104
|
-
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
1105
|
-
);
|
|
1106
|
-
const misplacedConfigPath = join2(
|
|
1107
|
-
repositoryRoot,
|
|
1108
|
-
".vercel",
|
|
1109
|
-
customConfigFilename || "microfrontends.json"
|
|
1110
|
-
);
|
|
1111
|
-
throw new MicrofrontendError(
|
|
1112
|
-
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
1113
|
-
|
|
1114
|
-
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
1115
|
-
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
1116
|
-
|
|
1117
|
-
To fix this:
|
|
1118
|
-
1. If using \`vercel link\`, run it with \`vercel link --repo\` to handle monorepos, or run \`vercel microfrontends pull --cwd=<application-directory>\` to make sure it pulls the \`microfrontends.json\` file to the correct location
|
|
1119
|
-
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
1120
|
-
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
1121
|
-
|
|
1122
|
-
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
1123
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1126
|
-
let additionalErrorMessage = "";
|
|
1127
|
-
if (microfrontendsJsonPaths.length > 0) {
|
|
1128
|
-
if (!applicationContext.projectName) {
|
|
1129
|
-
additionalErrorMessage = `
|
|
1130
|
-
|
|
1131
|
-
If the name in package.json (${applicationContext.packageJsonName}) differs from your Vercel Project name, set the \`packageName\` field for the application in \`microfrontends.json\` to ensure that the configuration can be found locally.`;
|
|
1132
|
-
} else {
|
|
1133
|
-
additionalErrorMessage = `
|
|
1134
|
-
|
|
1135
|
-
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
throw new MicrofrontendError(
|
|
1139
|
-
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
1140
|
-
|
|
1141
|
-
If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
|
|
1142
|
-
|
|
1143
|
-
If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
|
|
1144
|
-
|
|
1145
|
-
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
1146
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1149
|
-
const [packageJsonPath] = matchingPaths;
|
|
1150
|
-
return dirname(packageJsonPath);
|
|
1151
|
-
} catch (error2) {
|
|
1152
|
-
if (error2 instanceof MicrofrontendError) {
|
|
1153
|
-
throw error2;
|
|
1154
|
-
}
|
|
1155
|
-
return null;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
function inferMicrofrontendsLocation(opts) {
|
|
1159
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
1160
|
-
if (configCache[cacheKey]) {
|
|
1161
|
-
return configCache[cacheKey];
|
|
1162
|
-
}
|
|
1163
|
-
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
1164
|
-
if (!result) {
|
|
1165
|
-
throw new MicrofrontendError(
|
|
1166
|
-
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
1167
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1168
|
-
);
|
|
1169
|
-
}
|
|
1170
|
-
configCache[cacheKey] = result;
|
|
1171
|
-
return result;
|
|
1172
|
-
}
|
|
1173
|
-
function existsSync(path6) {
|
|
1174
|
-
try {
|
|
1175
|
-
statSync(path6);
|
|
1176
|
-
return true;
|
|
1177
|
-
} catch (_) {
|
|
1178
|
-
return false;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
1182
|
-
logger.debug(
|
|
1183
|
-
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
1184
|
-
);
|
|
1185
|
-
const misplacedConfigPath = join2(
|
|
1186
|
-
repositoryRoot,
|
|
1187
|
-
".vercel",
|
|
1188
|
-
customConfigFilename || "microfrontends.json"
|
|
1189
|
-
);
|
|
1190
|
-
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
1191
|
-
}
|
|
1192
|
-
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
1193
|
-
try {
|
|
1194
|
-
const microfrontendsJsonContent = readFileSync(
|
|
1195
|
-
microfrontendsJsonPath,
|
|
1196
|
-
"utf-8"
|
|
1197
|
-
);
|
|
1198
|
-
const microfrontendsJson = parse2(microfrontendsJsonContent);
|
|
1199
|
-
if (microfrontendsJson.applications[applicationName]) {
|
|
1200
|
-
logger.debug(
|
|
1201
|
-
"[MFE Config] Found application in config:",
|
|
1202
|
-
microfrontendsJsonPath
|
|
1203
|
-
);
|
|
1204
|
-
return true;
|
|
1205
|
-
}
|
|
1206
|
-
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
1207
|
-
if (app.packageName === applicationName) {
|
|
1208
|
-
logger.debug(
|
|
1209
|
-
"[MFE Config] Found application via packageName in config:",
|
|
1210
|
-
microfrontendsJsonPath
|
|
1211
|
-
);
|
|
1212
|
-
return true;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
} catch (error2) {
|
|
1216
|
-
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
1217
|
-
}
|
|
1218
|
-
return false;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1221
|
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1222
1222
|
import fs5 from "node:fs";
|
|
1223
1223
|
import path4 from "node:path";
|