@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
package/dist/next/config.js
CHANGED
|
@@ -138,7 +138,16 @@ var MicrofrontendError = class extends Error {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
// src/config/microfrontends-config/isomorphic/index.ts
|
|
141
|
-
import { parse } from "jsonc-parser";
|
|
141
|
+
import { parse as parse2 } from "jsonc-parser";
|
|
142
|
+
|
|
143
|
+
// src/config/microfrontends/utils/hash-application-name.ts
|
|
144
|
+
import md5 from "md5";
|
|
145
|
+
function hashApplicationName(name) {
|
|
146
|
+
if (!name) {
|
|
147
|
+
throw new Error("Application name is required to generate hash");
|
|
148
|
+
}
|
|
149
|
+
return md5(name).substring(0, 6).padStart(6, "0");
|
|
150
|
+
}
|
|
142
151
|
|
|
143
152
|
// src/config/overrides/constants.ts
|
|
144
153
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -288,6 +297,231 @@ function getConfigStringFromEnv() {
|
|
|
288
297
|
return config;
|
|
289
298
|
}
|
|
290
299
|
|
|
300
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
301
|
+
import fs from "node:fs";
|
|
302
|
+
import { join } from "node:path";
|
|
303
|
+
|
|
304
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
305
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
306
|
+
"microfrontends.json",
|
|
307
|
+
"microfrontends.jsonc"
|
|
308
|
+
];
|
|
309
|
+
function getPossibleConfigurationFilenames({
|
|
310
|
+
customConfigFilename
|
|
311
|
+
}) {
|
|
312
|
+
if (customConfigFilename) {
|
|
313
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
314
|
+
throw new Error(
|
|
315
|
+
`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.`
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
return Array.from(
|
|
319
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
326
|
+
function findConfig({
|
|
327
|
+
dir,
|
|
328
|
+
customConfigFilename
|
|
329
|
+
}) {
|
|
330
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
331
|
+
customConfigFilename
|
|
332
|
+
})) {
|
|
333
|
+
const maybeConfig = join(dir, filename);
|
|
334
|
+
if (fs.existsSync(maybeConfig)) {
|
|
335
|
+
return maybeConfig;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/config/microfrontends/utils/generate-default-asset-prefix.ts
|
|
342
|
+
var PREFIX = "vc-ap";
|
|
343
|
+
function generateDefaultAssetPrefixFromName({
|
|
344
|
+
name
|
|
345
|
+
}) {
|
|
346
|
+
if (!name) {
|
|
347
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
348
|
+
}
|
|
349
|
+
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
353
|
+
import { readFileSync, statSync } from "node:fs";
|
|
354
|
+
import { dirname, join as join2 } from "node:path";
|
|
355
|
+
import fg from "fast-glob";
|
|
356
|
+
import { parse } from "jsonc-parser";
|
|
357
|
+
var configCache = {};
|
|
358
|
+
function findPackageWithMicrofrontendsConfig({
|
|
359
|
+
repositoryRoot,
|
|
360
|
+
applicationContext,
|
|
361
|
+
customConfigFilename
|
|
362
|
+
}) {
|
|
363
|
+
const applicationName = applicationContext.name;
|
|
364
|
+
logger.debug(
|
|
365
|
+
"[MFE Config] Searching repository for configs containing application:",
|
|
366
|
+
applicationName
|
|
367
|
+
);
|
|
368
|
+
try {
|
|
369
|
+
const microfrontendsJsonPaths = fg.globSync(
|
|
370
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
371
|
+
{
|
|
372
|
+
cwd: repositoryRoot,
|
|
373
|
+
absolute: true,
|
|
374
|
+
onlyFiles: true,
|
|
375
|
+
followSymbolicLinks: false,
|
|
376
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
logger.debug(
|
|
380
|
+
"[MFE Config] Found",
|
|
381
|
+
microfrontendsJsonPaths.length,
|
|
382
|
+
"config file(s) in repository"
|
|
383
|
+
);
|
|
384
|
+
const matchingPaths = [];
|
|
385
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
386
|
+
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
387
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
logger.debug(
|
|
391
|
+
"[MFE Config] Total matching config files:",
|
|
392
|
+
matchingPaths.length
|
|
393
|
+
);
|
|
394
|
+
if (matchingPaths.length > 1) {
|
|
395
|
+
throw new MicrofrontendError(
|
|
396
|
+
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
397
|
+
${matchingPaths.join("\n \u2022 ")}`,
|
|
398
|
+
{ type: "config", subtype: "inference_failed" }
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
if (matchingPaths.length === 0) {
|
|
402
|
+
if (repositoryRoot && doesMisplacedConfigExist(
|
|
403
|
+
repositoryRoot,
|
|
404
|
+
applicationName,
|
|
405
|
+
customConfigFilename
|
|
406
|
+
)) {
|
|
407
|
+
logger.debug(
|
|
408
|
+
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
409
|
+
);
|
|
410
|
+
const misplacedConfigPath = join2(
|
|
411
|
+
repositoryRoot,
|
|
412
|
+
".vercel",
|
|
413
|
+
customConfigFilename || "microfrontends.json"
|
|
414
|
+
);
|
|
415
|
+
throw new MicrofrontendError(
|
|
416
|
+
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
417
|
+
|
|
418
|
+
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
419
|
+
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
420
|
+
|
|
421
|
+
To fix this:
|
|
422
|
+
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
|
|
423
|
+
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
424
|
+
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
425
|
+
|
|
426
|
+
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
427
|
+
{ type: "config", subtype: "inference_failed" }
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
let additionalErrorMessage = "";
|
|
431
|
+
if (microfrontendsJsonPaths.length > 0) {
|
|
432
|
+
if (!applicationContext.projectName) {
|
|
433
|
+
additionalErrorMessage = `
|
|
434
|
+
|
|
435
|
+
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.`;
|
|
436
|
+
} else {
|
|
437
|
+
additionalErrorMessage = `
|
|
438
|
+
|
|
439
|
+
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
throw new MicrofrontendError(
|
|
443
|
+
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
444
|
+
|
|
445
|
+
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.
|
|
446
|
+
|
|
447
|
+
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.
|
|
448
|
+
|
|
449
|
+
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
450
|
+
{ type: "config", subtype: "inference_failed" }
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
const [packageJsonPath] = matchingPaths;
|
|
454
|
+
return dirname(packageJsonPath);
|
|
455
|
+
} catch (error2) {
|
|
456
|
+
if (error2 instanceof MicrofrontendError) {
|
|
457
|
+
throw error2;
|
|
458
|
+
}
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function inferMicrofrontendsLocation(opts) {
|
|
463
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
464
|
+
if (configCache[cacheKey]) {
|
|
465
|
+
return configCache[cacheKey];
|
|
466
|
+
}
|
|
467
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
468
|
+
if (!result) {
|
|
469
|
+
throw new MicrofrontendError(
|
|
470
|
+
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
471
|
+
{ type: "config", subtype: "inference_failed" }
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
configCache[cacheKey] = result;
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
function existsSync(path6) {
|
|
478
|
+
try {
|
|
479
|
+
statSync(path6);
|
|
480
|
+
return true;
|
|
481
|
+
} catch (_) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
486
|
+
logger.debug(
|
|
487
|
+
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
488
|
+
);
|
|
489
|
+
const misplacedConfigPath = join2(
|
|
490
|
+
repositoryRoot,
|
|
491
|
+
".vercel",
|
|
492
|
+
customConfigFilename || "microfrontends.json"
|
|
493
|
+
);
|
|
494
|
+
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
495
|
+
}
|
|
496
|
+
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
497
|
+
try {
|
|
498
|
+
const microfrontendsJsonContent = readFileSync(
|
|
499
|
+
microfrontendsJsonPath,
|
|
500
|
+
"utf-8"
|
|
501
|
+
);
|
|
502
|
+
const microfrontendsJson = parse(microfrontendsJsonContent);
|
|
503
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
504
|
+
logger.debug(
|
|
505
|
+
"[MFE Config] Found application in config:",
|
|
506
|
+
microfrontendsJsonPath
|
|
507
|
+
);
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
511
|
+
if (app.packageName === applicationName) {
|
|
512
|
+
logger.debug(
|
|
513
|
+
"[MFE Config] Found application via packageName in config:",
|
|
514
|
+
microfrontendsJsonPath
|
|
515
|
+
);
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
} catch (error2) {
|
|
520
|
+
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
521
|
+
}
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
|
|
291
525
|
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
292
526
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
293
527
|
var MFE_APP_PORT_ENV = "MFE_APP_PORT";
|
|
@@ -426,26 +660,6 @@ var LocalHost = class extends Host {
|
|
|
426
660
|
}
|
|
427
661
|
};
|
|
428
662
|
|
|
429
|
-
// src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
|
|
430
|
-
import md5 from "md5";
|
|
431
|
-
function hashApplicationName(name) {
|
|
432
|
-
if (!name) {
|
|
433
|
-
throw new Error("Application name is required to generate hash");
|
|
434
|
-
}
|
|
435
|
-
return md5(name).substring(0, 6).padStart(6, "0");
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
439
|
-
var PREFIX = "vc-ap";
|
|
440
|
-
function generateAssetPrefixFromName({
|
|
441
|
-
name
|
|
442
|
-
}) {
|
|
443
|
-
if (!name) {
|
|
444
|
-
throw new Error("Name is required to generate an asset prefix");
|
|
445
|
-
}
|
|
446
|
-
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
663
|
// src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
|
|
450
664
|
function generateAutomationBypassEnvVarName({
|
|
451
665
|
name
|
|
@@ -526,7 +740,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
526
740
|
);
|
|
527
741
|
}
|
|
528
742
|
};
|
|
529
|
-
var
|
|
743
|
+
var PATH_DEFAULT_PATTERNS = ["[^\\/#\\?]+?", "(?:(?!\\.)[^\\/#\\?])+?"];
|
|
530
744
|
function validatePathExpression(path6) {
|
|
531
745
|
try {
|
|
532
746
|
const tokens = parsePathRegexp(path6);
|
|
@@ -548,7 +762,7 @@ function validatePathExpression(path6) {
|
|
|
548
762
|
if (!token.name) {
|
|
549
763
|
return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
|
|
550
764
|
}
|
|
551
|
-
if (token.pattern
|
|
765
|
+
if (!PATH_DEFAULT_PATTERNS.includes(token.pattern) && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
552
766
|
// Only limited regex is supported for now, due to performance considerations
|
|
553
767
|
// Allows all letters, numbers, and hyphens. Other characters must be escaped.
|
|
554
768
|
!/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
|
|
@@ -663,7 +877,7 @@ var Application = class {
|
|
|
663
877
|
return this.default;
|
|
664
878
|
}
|
|
665
879
|
getAssetPrefix() {
|
|
666
|
-
const generatedAssetPrefix =
|
|
880
|
+
const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
|
|
667
881
|
name: this.name
|
|
668
882
|
});
|
|
669
883
|
if ("assetPrefix" in this.serialized) {
|
|
@@ -757,7 +971,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
757
971
|
};
|
|
758
972
|
}
|
|
759
973
|
static validate(config) {
|
|
760
|
-
const c = typeof config === "string" ?
|
|
974
|
+
const c = typeof config === "string" ? parse2(config) : config;
|
|
761
975
|
validateConfigPaths(c.applications);
|
|
762
976
|
validateConfigDefaultApplication(c.applications);
|
|
763
977
|
return c;
|
|
@@ -766,7 +980,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
766
980
|
cookies
|
|
767
981
|
}) {
|
|
768
982
|
return new MicrofrontendConfigIsomorphic({
|
|
769
|
-
config:
|
|
983
|
+
config: parse2(getConfigStringFromEnv()),
|
|
770
984
|
overrides: parseOverrides(cookies ?? [])
|
|
771
985
|
});
|
|
772
986
|
}
|
|
@@ -880,47 +1094,6 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
880
1094
|
}
|
|
881
1095
|
};
|
|
882
1096
|
|
|
883
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
884
|
-
import fs from "node:fs";
|
|
885
|
-
import { join } from "node:path";
|
|
886
|
-
|
|
887
|
-
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
888
|
-
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
889
|
-
"microfrontends.json",
|
|
890
|
-
"microfrontends.jsonc"
|
|
891
|
-
];
|
|
892
|
-
function getPossibleConfigurationFilenames({
|
|
893
|
-
customConfigFilename
|
|
894
|
-
}) {
|
|
895
|
-
if (customConfigFilename) {
|
|
896
|
-
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
897
|
-
throw new Error(
|
|
898
|
-
`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.`
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
return Array.from(
|
|
902
|
-
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
909
|
-
function findConfig({
|
|
910
|
-
dir,
|
|
911
|
-
customConfigFilename
|
|
912
|
-
}) {
|
|
913
|
-
for (const filename of getPossibleConfigurationFilenames({
|
|
914
|
-
customConfigFilename
|
|
915
|
-
})) {
|
|
916
|
-
const maybeConfig = join(dir, filename);
|
|
917
|
-
if (fs.existsSync(maybeConfig)) {
|
|
918
|
-
return maybeConfig;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return null;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
1097
|
// src/config/microfrontends/utils/find-package-root.ts
|
|
925
1098
|
import fs2 from "node:fs";
|
|
926
1099
|
import path from "node:path";
|
|
@@ -1053,179 +1226,6 @@ function getApplicationContext(opts) {
|
|
|
1053
1226
|
}
|
|
1054
1227
|
}
|
|
1055
1228
|
|
|
1056
|
-
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
1057
|
-
import { readFileSync, statSync } from "node:fs";
|
|
1058
|
-
import { dirname, join as join2 } from "node:path";
|
|
1059
|
-
import fg from "fast-glob";
|
|
1060
|
-
import { parse as parse2 } from "jsonc-parser";
|
|
1061
|
-
var configCache = {};
|
|
1062
|
-
function findPackageWithMicrofrontendsConfig({
|
|
1063
|
-
repositoryRoot,
|
|
1064
|
-
applicationContext,
|
|
1065
|
-
customConfigFilename
|
|
1066
|
-
}) {
|
|
1067
|
-
const applicationName = applicationContext.name;
|
|
1068
|
-
logger.debug(
|
|
1069
|
-
"[MFE Config] Searching repository for configs containing application:",
|
|
1070
|
-
applicationName
|
|
1071
|
-
);
|
|
1072
|
-
try {
|
|
1073
|
-
const microfrontendsJsonPaths = fg.globSync(
|
|
1074
|
-
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
1075
|
-
{
|
|
1076
|
-
cwd: repositoryRoot,
|
|
1077
|
-
absolute: true,
|
|
1078
|
-
onlyFiles: true,
|
|
1079
|
-
followSymbolicLinks: false,
|
|
1080
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1081
|
-
}
|
|
1082
|
-
);
|
|
1083
|
-
logger.debug(
|
|
1084
|
-
"[MFE Config] Found",
|
|
1085
|
-
microfrontendsJsonPaths.length,
|
|
1086
|
-
"config file(s) in repository"
|
|
1087
|
-
);
|
|
1088
|
-
const matchingPaths = [];
|
|
1089
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1090
|
-
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
1091
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
logger.debug(
|
|
1095
|
-
"[MFE Config] Total matching config files:",
|
|
1096
|
-
matchingPaths.length
|
|
1097
|
-
);
|
|
1098
|
-
if (matchingPaths.length > 1) {
|
|
1099
|
-
throw new MicrofrontendError(
|
|
1100
|
-
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
1101
|
-
${matchingPaths.join("\n \u2022 ")}`,
|
|
1102
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1103
|
-
);
|
|
1104
|
-
}
|
|
1105
|
-
if (matchingPaths.length === 0) {
|
|
1106
|
-
if (repositoryRoot && doesMisplacedConfigExist(
|
|
1107
|
-
repositoryRoot,
|
|
1108
|
-
applicationName,
|
|
1109
|
-
customConfigFilename
|
|
1110
|
-
)) {
|
|
1111
|
-
logger.debug(
|
|
1112
|
-
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
1113
|
-
);
|
|
1114
|
-
const misplacedConfigPath = join2(
|
|
1115
|
-
repositoryRoot,
|
|
1116
|
-
".vercel",
|
|
1117
|
-
customConfigFilename || "microfrontends.json"
|
|
1118
|
-
);
|
|
1119
|
-
throw new MicrofrontendError(
|
|
1120
|
-
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
1121
|
-
|
|
1122
|
-
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
1123
|
-
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
1124
|
-
|
|
1125
|
-
To fix this:
|
|
1126
|
-
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
|
|
1127
|
-
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
1128
|
-
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
1129
|
-
|
|
1130
|
-
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
1131
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1132
|
-
);
|
|
1133
|
-
}
|
|
1134
|
-
let additionalErrorMessage = "";
|
|
1135
|
-
if (microfrontendsJsonPaths.length > 0) {
|
|
1136
|
-
if (!applicationContext.projectName) {
|
|
1137
|
-
additionalErrorMessage = `
|
|
1138
|
-
|
|
1139
|
-
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.`;
|
|
1140
|
-
} else {
|
|
1141
|
-
additionalErrorMessage = `
|
|
1142
|
-
|
|
1143
|
-
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
throw new MicrofrontendError(
|
|
1147
|
-
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
1148
|
-
|
|
1149
|
-
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.
|
|
1150
|
-
|
|
1151
|
-
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.
|
|
1152
|
-
|
|
1153
|
-
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
1154
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1157
|
-
const [packageJsonPath] = matchingPaths;
|
|
1158
|
-
return dirname(packageJsonPath);
|
|
1159
|
-
} catch (error2) {
|
|
1160
|
-
if (error2 instanceof MicrofrontendError) {
|
|
1161
|
-
throw error2;
|
|
1162
|
-
}
|
|
1163
|
-
return null;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
function inferMicrofrontendsLocation(opts) {
|
|
1167
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
1168
|
-
if (configCache[cacheKey]) {
|
|
1169
|
-
return configCache[cacheKey];
|
|
1170
|
-
}
|
|
1171
|
-
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
1172
|
-
if (!result) {
|
|
1173
|
-
throw new MicrofrontendError(
|
|
1174
|
-
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
1175
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1176
|
-
);
|
|
1177
|
-
}
|
|
1178
|
-
configCache[cacheKey] = result;
|
|
1179
|
-
return result;
|
|
1180
|
-
}
|
|
1181
|
-
function existsSync(path6) {
|
|
1182
|
-
try {
|
|
1183
|
-
statSync(path6);
|
|
1184
|
-
return true;
|
|
1185
|
-
} catch (_) {
|
|
1186
|
-
return false;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
1190
|
-
logger.debug(
|
|
1191
|
-
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
1192
|
-
);
|
|
1193
|
-
const misplacedConfigPath = join2(
|
|
1194
|
-
repositoryRoot,
|
|
1195
|
-
".vercel",
|
|
1196
|
-
customConfigFilename || "microfrontends.json"
|
|
1197
|
-
);
|
|
1198
|
-
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
1199
|
-
}
|
|
1200
|
-
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
1201
|
-
try {
|
|
1202
|
-
const microfrontendsJsonContent = readFileSync(
|
|
1203
|
-
microfrontendsJsonPath,
|
|
1204
|
-
"utf-8"
|
|
1205
|
-
);
|
|
1206
|
-
const microfrontendsJson = parse2(microfrontendsJsonContent);
|
|
1207
|
-
if (microfrontendsJson.applications[applicationName]) {
|
|
1208
|
-
logger.debug(
|
|
1209
|
-
"[MFE Config] Found application in config:",
|
|
1210
|
-
microfrontendsJsonPath
|
|
1211
|
-
);
|
|
1212
|
-
return true;
|
|
1213
|
-
}
|
|
1214
|
-
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
1215
|
-
if (app.packageName === applicationName) {
|
|
1216
|
-
logger.debug(
|
|
1217
|
-
"[MFE Config] Found application via packageName in config:",
|
|
1218
|
-
microfrontendsJsonPath
|
|
1219
|
-
);
|
|
1220
|
-
return true;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
} catch (error2) {
|
|
1224
|
-
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
1225
|
-
}
|
|
1226
|
-
return false;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
1229
|
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1230
1230
|
import fs5 from "node:fs";
|
|
1231
1231
|
import path4 from "node:path";
|