@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
|
@@ -166,7 +166,16 @@ var MicrofrontendError = class extends Error {
|
|
|
166
166
|
};
|
|
167
167
|
|
|
168
168
|
// src/config/microfrontends-config/isomorphic/index.ts
|
|
169
|
-
var
|
|
169
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
170
|
+
|
|
171
|
+
// src/config/microfrontends/utils/hash-application-name.ts
|
|
172
|
+
var import_md5 = __toESM(require("md5"), 1);
|
|
173
|
+
function hashApplicationName(name) {
|
|
174
|
+
if (!name) {
|
|
175
|
+
throw new Error("Application name is required to generate hash");
|
|
176
|
+
}
|
|
177
|
+
return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
|
|
178
|
+
}
|
|
170
179
|
|
|
171
180
|
// src/config/overrides/constants.ts
|
|
172
181
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -316,6 +325,231 @@ function getConfigStringFromEnv() {
|
|
|
316
325
|
return config;
|
|
317
326
|
}
|
|
318
327
|
|
|
328
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
329
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
330
|
+
var import_node_path = require("path");
|
|
331
|
+
|
|
332
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
333
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
334
|
+
"microfrontends.json",
|
|
335
|
+
"microfrontends.jsonc"
|
|
336
|
+
];
|
|
337
|
+
function getPossibleConfigurationFilenames({
|
|
338
|
+
customConfigFilename
|
|
339
|
+
}) {
|
|
340
|
+
if (customConfigFilename) {
|
|
341
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
`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.`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return Array.from(
|
|
347
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
354
|
+
function findConfig({
|
|
355
|
+
dir,
|
|
356
|
+
customConfigFilename
|
|
357
|
+
}) {
|
|
358
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
359
|
+
customConfigFilename
|
|
360
|
+
})) {
|
|
361
|
+
const maybeConfig = (0, import_node_path.join)(dir, filename);
|
|
362
|
+
if (import_node_fs.default.existsSync(maybeConfig)) {
|
|
363
|
+
return maybeConfig;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/config/microfrontends/utils/generate-default-asset-prefix.ts
|
|
370
|
+
var PREFIX = "vc-ap";
|
|
371
|
+
function generateDefaultAssetPrefixFromName({
|
|
372
|
+
name
|
|
373
|
+
}) {
|
|
374
|
+
if (!name) {
|
|
375
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
376
|
+
}
|
|
377
|
+
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
381
|
+
var import_node_fs2 = require("fs");
|
|
382
|
+
var import_node_path2 = require("path");
|
|
383
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
384
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
385
|
+
var configCache = {};
|
|
386
|
+
function findPackageWithMicrofrontendsConfig({
|
|
387
|
+
repositoryRoot,
|
|
388
|
+
applicationContext,
|
|
389
|
+
customConfigFilename
|
|
390
|
+
}) {
|
|
391
|
+
const applicationName = applicationContext.name;
|
|
392
|
+
logger.debug(
|
|
393
|
+
"[MFE Config] Searching repository for configs containing application:",
|
|
394
|
+
applicationName
|
|
395
|
+
);
|
|
396
|
+
try {
|
|
397
|
+
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
398
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
399
|
+
{
|
|
400
|
+
cwd: repositoryRoot,
|
|
401
|
+
absolute: true,
|
|
402
|
+
onlyFiles: true,
|
|
403
|
+
followSymbolicLinks: false,
|
|
404
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
logger.debug(
|
|
408
|
+
"[MFE Config] Found",
|
|
409
|
+
microfrontendsJsonPaths.length,
|
|
410
|
+
"config file(s) in repository"
|
|
411
|
+
);
|
|
412
|
+
const matchingPaths = [];
|
|
413
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
414
|
+
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
415
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
logger.debug(
|
|
419
|
+
"[MFE Config] Total matching config files:",
|
|
420
|
+
matchingPaths.length
|
|
421
|
+
);
|
|
422
|
+
if (matchingPaths.length > 1) {
|
|
423
|
+
throw new MicrofrontendError(
|
|
424
|
+
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
425
|
+
${matchingPaths.join("\n \u2022 ")}`,
|
|
426
|
+
{ type: "config", subtype: "inference_failed" }
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
if (matchingPaths.length === 0) {
|
|
430
|
+
if (repositoryRoot && doesMisplacedConfigExist(
|
|
431
|
+
repositoryRoot,
|
|
432
|
+
applicationName,
|
|
433
|
+
customConfigFilename
|
|
434
|
+
)) {
|
|
435
|
+
logger.debug(
|
|
436
|
+
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
437
|
+
);
|
|
438
|
+
const misplacedConfigPath = (0, import_node_path2.join)(
|
|
439
|
+
repositoryRoot,
|
|
440
|
+
".vercel",
|
|
441
|
+
customConfigFilename || "microfrontends.json"
|
|
442
|
+
);
|
|
443
|
+
throw new MicrofrontendError(
|
|
444
|
+
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
445
|
+
|
|
446
|
+
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
447
|
+
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
448
|
+
|
|
449
|
+
To fix this:
|
|
450
|
+
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
|
|
451
|
+
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
452
|
+
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
453
|
+
|
|
454
|
+
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
455
|
+
{ type: "config", subtype: "inference_failed" }
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
let additionalErrorMessage = "";
|
|
459
|
+
if (microfrontendsJsonPaths.length > 0) {
|
|
460
|
+
if (!applicationContext.projectName) {
|
|
461
|
+
additionalErrorMessage = `
|
|
462
|
+
|
|
463
|
+
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.`;
|
|
464
|
+
} else {
|
|
465
|
+
additionalErrorMessage = `
|
|
466
|
+
|
|
467
|
+
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
throw new MicrofrontendError(
|
|
471
|
+
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
472
|
+
|
|
473
|
+
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.
|
|
474
|
+
|
|
475
|
+
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.
|
|
476
|
+
|
|
477
|
+
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
478
|
+
{ type: "config", subtype: "inference_failed" }
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
const [packageJsonPath] = matchingPaths;
|
|
482
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
483
|
+
} catch (error2) {
|
|
484
|
+
if (error2 instanceof MicrofrontendError) {
|
|
485
|
+
throw error2;
|
|
486
|
+
}
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function inferMicrofrontendsLocation(opts) {
|
|
491
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
492
|
+
if (configCache[cacheKey]) {
|
|
493
|
+
return configCache[cacheKey];
|
|
494
|
+
}
|
|
495
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
496
|
+
if (!result) {
|
|
497
|
+
throw new MicrofrontendError(
|
|
498
|
+
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
499
|
+
{ type: "config", subtype: "inference_failed" }
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
configCache[cacheKey] = result;
|
|
503
|
+
return result;
|
|
504
|
+
}
|
|
505
|
+
function existsSync(path6) {
|
|
506
|
+
try {
|
|
507
|
+
(0, import_node_fs2.statSync)(path6);
|
|
508
|
+
return true;
|
|
509
|
+
} catch (_) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
514
|
+
logger.debug(
|
|
515
|
+
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
516
|
+
);
|
|
517
|
+
const misplacedConfigPath = (0, import_node_path2.join)(
|
|
518
|
+
repositoryRoot,
|
|
519
|
+
".vercel",
|
|
520
|
+
customConfigFilename || "microfrontends.json"
|
|
521
|
+
);
|
|
522
|
+
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
523
|
+
}
|
|
524
|
+
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
525
|
+
try {
|
|
526
|
+
const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
|
|
527
|
+
microfrontendsJsonPath,
|
|
528
|
+
"utf-8"
|
|
529
|
+
);
|
|
530
|
+
const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
|
|
531
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
532
|
+
logger.debug(
|
|
533
|
+
"[MFE Config] Found application in config:",
|
|
534
|
+
microfrontendsJsonPath
|
|
535
|
+
);
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
539
|
+
if (app.packageName === applicationName) {
|
|
540
|
+
logger.debug(
|
|
541
|
+
"[MFE Config] Found application via packageName in config:",
|
|
542
|
+
microfrontendsJsonPath
|
|
543
|
+
);
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
} catch (error2) {
|
|
548
|
+
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
|
|
319
553
|
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
320
554
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
321
555
|
var MFE_APP_PORT_ENV = "MFE_APP_PORT";
|
|
@@ -454,26 +688,6 @@ var LocalHost = class extends Host {
|
|
|
454
688
|
}
|
|
455
689
|
};
|
|
456
690
|
|
|
457
|
-
// src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
|
|
458
|
-
var import_md5 = __toESM(require("md5"), 1);
|
|
459
|
-
function hashApplicationName(name) {
|
|
460
|
-
if (!name) {
|
|
461
|
-
throw new Error("Application name is required to generate hash");
|
|
462
|
-
}
|
|
463
|
-
return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
467
|
-
var PREFIX = "vc-ap";
|
|
468
|
-
function generateAssetPrefixFromName({
|
|
469
|
-
name
|
|
470
|
-
}) {
|
|
471
|
-
if (!name) {
|
|
472
|
-
throw new Error("Name is required to generate an asset prefix");
|
|
473
|
-
}
|
|
474
|
-
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
691
|
// src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
|
|
478
692
|
function generateAutomationBypassEnvVarName({
|
|
479
693
|
name
|
|
@@ -554,7 +768,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
554
768
|
);
|
|
555
769
|
}
|
|
556
770
|
};
|
|
557
|
-
var
|
|
771
|
+
var PATH_DEFAULT_PATTERNS = ["[^\\/#\\?]+?", "(?:(?!\\.)[^\\/#\\?])+?"];
|
|
558
772
|
function validatePathExpression(path6) {
|
|
559
773
|
try {
|
|
560
774
|
const tokens = (0, import_path_to_regexp2.parse)(path6);
|
|
@@ -576,7 +790,7 @@ function validatePathExpression(path6) {
|
|
|
576
790
|
if (!token.name) {
|
|
577
791
|
return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
|
|
578
792
|
}
|
|
579
|
-
if (token.pattern
|
|
793
|
+
if (!PATH_DEFAULT_PATTERNS.includes(token.pattern) && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
580
794
|
// Only limited regex is supported for now, due to performance considerations
|
|
581
795
|
// Allows all letters, numbers, and hyphens. Other characters must be escaped.
|
|
582
796
|
!/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
|
|
@@ -691,7 +905,7 @@ var Application = class {
|
|
|
691
905
|
return this.default;
|
|
692
906
|
}
|
|
693
907
|
getAssetPrefix() {
|
|
694
|
-
const generatedAssetPrefix =
|
|
908
|
+
const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
|
|
695
909
|
name: this.name
|
|
696
910
|
});
|
|
697
911
|
if ("assetPrefix" in this.serialized) {
|
|
@@ -785,7 +999,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
785
999
|
};
|
|
786
1000
|
}
|
|
787
1001
|
static validate(config) {
|
|
788
|
-
const c = typeof config === "string" ? (0,
|
|
1002
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
789
1003
|
validateConfigPaths(c.applications);
|
|
790
1004
|
validateConfigDefaultApplication(c.applications);
|
|
791
1005
|
return c;
|
|
@@ -794,7 +1008,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
794
1008
|
cookies
|
|
795
1009
|
}) {
|
|
796
1010
|
return new MicrofrontendConfigIsomorphic({
|
|
797
|
-
config: (0,
|
|
1011
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
798
1012
|
overrides: parseOverrides(cookies ?? [])
|
|
799
1013
|
});
|
|
800
1014
|
}
|
|
@@ -908,59 +1122,18 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
908
1122
|
}
|
|
909
1123
|
};
|
|
910
1124
|
|
|
911
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
912
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
913
|
-
var import_node_path = require("path");
|
|
914
|
-
|
|
915
|
-
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
916
|
-
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
917
|
-
"microfrontends.json",
|
|
918
|
-
"microfrontends.jsonc"
|
|
919
|
-
];
|
|
920
|
-
function getPossibleConfigurationFilenames({
|
|
921
|
-
customConfigFilename
|
|
922
|
-
}) {
|
|
923
|
-
if (customConfigFilename) {
|
|
924
|
-
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
925
|
-
throw new Error(
|
|
926
|
-
`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.`
|
|
927
|
-
);
|
|
928
|
-
}
|
|
929
|
-
return Array.from(
|
|
930
|
-
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
931
|
-
);
|
|
932
|
-
}
|
|
933
|
-
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
937
|
-
function findConfig({
|
|
938
|
-
dir,
|
|
939
|
-
customConfigFilename
|
|
940
|
-
}) {
|
|
941
|
-
for (const filename of getPossibleConfigurationFilenames({
|
|
942
|
-
customConfigFilename
|
|
943
|
-
})) {
|
|
944
|
-
const maybeConfig = (0, import_node_path.join)(dir, filename);
|
|
945
|
-
if (import_node_fs.default.existsSync(maybeConfig)) {
|
|
946
|
-
return maybeConfig;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return null;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
1125
|
// src/config/microfrontends/utils/find-package-root.ts
|
|
953
|
-
var
|
|
954
|
-
var
|
|
1126
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
1127
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
955
1128
|
var PACKAGE_JSON = "package.json";
|
|
956
1129
|
function findPackageRoot(startDir) {
|
|
957
1130
|
let currentDir = startDir || process.cwd();
|
|
958
|
-
while (currentDir !==
|
|
959
|
-
const pkgJsonPath =
|
|
960
|
-
if (
|
|
1131
|
+
while (currentDir !== import_node_path3.default.parse(currentDir).root) {
|
|
1132
|
+
const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
|
|
1133
|
+
if (import_node_fs3.default.existsSync(pkgJsonPath)) {
|
|
961
1134
|
return currentDir;
|
|
962
1135
|
}
|
|
963
|
-
currentDir =
|
|
1136
|
+
currentDir = import_node_path3.default.dirname(currentDir);
|
|
964
1137
|
}
|
|
965
1138
|
throw new Error(
|
|
966
1139
|
`The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
|
|
@@ -968,18 +1141,18 @@ function findPackageRoot(startDir) {
|
|
|
968
1141
|
}
|
|
969
1142
|
|
|
970
1143
|
// src/config/microfrontends/utils/find-repository-root.ts
|
|
971
|
-
var
|
|
972
|
-
var
|
|
1144
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1145
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
973
1146
|
var GIT_DIRECTORY = ".git";
|
|
974
1147
|
function hasGitDirectory(dir) {
|
|
975
|
-
const gitPath =
|
|
976
|
-
return
|
|
1148
|
+
const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
|
|
1149
|
+
return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
|
|
977
1150
|
}
|
|
978
1151
|
function hasPnpmWorkspaces(dir) {
|
|
979
|
-
return
|
|
1152
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
|
|
980
1153
|
}
|
|
981
1154
|
function hasPackageJson(dir) {
|
|
982
|
-
return
|
|
1155
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
|
|
983
1156
|
}
|
|
984
1157
|
function findRepositoryRoot(startDir) {
|
|
985
1158
|
if (process.env.NX_WORKSPACE_ROOT) {
|
|
@@ -987,14 +1160,14 @@ function findRepositoryRoot(startDir) {
|
|
|
987
1160
|
}
|
|
988
1161
|
let currentDir = startDir || process.cwd();
|
|
989
1162
|
let lastPackageJsonDir = null;
|
|
990
|
-
while (currentDir !==
|
|
1163
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
991
1164
|
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
992
1165
|
return currentDir;
|
|
993
1166
|
}
|
|
994
1167
|
if (hasPackageJson(currentDir)) {
|
|
995
1168
|
lastPackageJsonDir = currentDir;
|
|
996
1169
|
}
|
|
997
|
-
currentDir =
|
|
1170
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
998
1171
|
}
|
|
999
1172
|
if (lastPackageJsonDir) {
|
|
1000
1173
|
return lastPackageJsonDir;
|
|
@@ -1005,8 +1178,8 @@ function findRepositoryRoot(startDir) {
|
|
|
1005
1178
|
}
|
|
1006
1179
|
|
|
1007
1180
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1008
|
-
var
|
|
1009
|
-
var
|
|
1181
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1182
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
1010
1183
|
function getApplicationContext(opts) {
|
|
1011
1184
|
if (opts?.appName) {
|
|
1012
1185
|
logger.debug(
|
|
@@ -1036,8 +1209,8 @@ function getApplicationContext(opts) {
|
|
|
1036
1209
|
};
|
|
1037
1210
|
}
|
|
1038
1211
|
try {
|
|
1039
|
-
const vercelProjectJsonPath =
|
|
1040
|
-
|
|
1212
|
+
const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
|
|
1213
|
+
import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
|
|
1041
1214
|
"utf-8"
|
|
1042
1215
|
);
|
|
1043
1216
|
const projectJson = JSON.parse(vercelProjectJsonPath);
|
|
@@ -1054,8 +1227,8 @@ function getApplicationContext(opts) {
|
|
|
1054
1227
|
} catch (_) {
|
|
1055
1228
|
}
|
|
1056
1229
|
try {
|
|
1057
|
-
const packageJsonString =
|
|
1058
|
-
|
|
1230
|
+
const packageJsonString = import_node_fs5.default.readFileSync(
|
|
1231
|
+
import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1059
1232
|
"utf-8"
|
|
1060
1233
|
);
|
|
1061
1234
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1081,179 +1254,6 @@ function getApplicationContext(opts) {
|
|
|
1081
1254
|
}
|
|
1082
1255
|
}
|
|
1083
1256
|
|
|
1084
|
-
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
1085
|
-
var import_node_fs5 = require("fs");
|
|
1086
|
-
var import_node_path5 = require("path");
|
|
1087
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1088
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
1089
|
-
var configCache = {};
|
|
1090
|
-
function findPackageWithMicrofrontendsConfig({
|
|
1091
|
-
repositoryRoot,
|
|
1092
|
-
applicationContext,
|
|
1093
|
-
customConfigFilename
|
|
1094
|
-
}) {
|
|
1095
|
-
const applicationName = applicationContext.name;
|
|
1096
|
-
logger.debug(
|
|
1097
|
-
"[MFE Config] Searching repository for configs containing application:",
|
|
1098
|
-
applicationName
|
|
1099
|
-
);
|
|
1100
|
-
try {
|
|
1101
|
-
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
1102
|
-
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
1103
|
-
{
|
|
1104
|
-
cwd: repositoryRoot,
|
|
1105
|
-
absolute: true,
|
|
1106
|
-
onlyFiles: true,
|
|
1107
|
-
followSymbolicLinks: false,
|
|
1108
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1109
|
-
}
|
|
1110
|
-
);
|
|
1111
|
-
logger.debug(
|
|
1112
|
-
"[MFE Config] Found",
|
|
1113
|
-
microfrontendsJsonPaths.length,
|
|
1114
|
-
"config file(s) in repository"
|
|
1115
|
-
);
|
|
1116
|
-
const matchingPaths = [];
|
|
1117
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1118
|
-
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
1119
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
logger.debug(
|
|
1123
|
-
"[MFE Config] Total matching config files:",
|
|
1124
|
-
matchingPaths.length
|
|
1125
|
-
);
|
|
1126
|
-
if (matchingPaths.length > 1) {
|
|
1127
|
-
throw new MicrofrontendError(
|
|
1128
|
-
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
1129
|
-
${matchingPaths.join("\n \u2022 ")}`,
|
|
1130
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
if (matchingPaths.length === 0) {
|
|
1134
|
-
if (repositoryRoot && doesMisplacedConfigExist(
|
|
1135
|
-
repositoryRoot,
|
|
1136
|
-
applicationName,
|
|
1137
|
-
customConfigFilename
|
|
1138
|
-
)) {
|
|
1139
|
-
logger.debug(
|
|
1140
|
-
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
1141
|
-
);
|
|
1142
|
-
const misplacedConfigPath = (0, import_node_path5.join)(
|
|
1143
|
-
repositoryRoot,
|
|
1144
|
-
".vercel",
|
|
1145
|
-
customConfigFilename || "microfrontends.json"
|
|
1146
|
-
);
|
|
1147
|
-
throw new MicrofrontendError(
|
|
1148
|
-
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
1149
|
-
|
|
1150
|
-
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
1151
|
-
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
1152
|
-
|
|
1153
|
-
To fix this:
|
|
1154
|
-
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
|
|
1155
|
-
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
1156
|
-
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
1157
|
-
|
|
1158
|
-
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
1159
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
let additionalErrorMessage = "";
|
|
1163
|
-
if (microfrontendsJsonPaths.length > 0) {
|
|
1164
|
-
if (!applicationContext.projectName) {
|
|
1165
|
-
additionalErrorMessage = `
|
|
1166
|
-
|
|
1167
|
-
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.`;
|
|
1168
|
-
} else {
|
|
1169
|
-
additionalErrorMessage = `
|
|
1170
|
-
|
|
1171
|
-
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
throw new MicrofrontendError(
|
|
1175
|
-
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
1176
|
-
|
|
1177
|
-
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.
|
|
1178
|
-
|
|
1179
|
-
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.
|
|
1180
|
-
|
|
1181
|
-
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
1182
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
const [packageJsonPath] = matchingPaths;
|
|
1186
|
-
return (0, import_node_path5.dirname)(packageJsonPath);
|
|
1187
|
-
} catch (error2) {
|
|
1188
|
-
if (error2 instanceof MicrofrontendError) {
|
|
1189
|
-
throw error2;
|
|
1190
|
-
}
|
|
1191
|
-
return null;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
function inferMicrofrontendsLocation(opts) {
|
|
1195
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
1196
|
-
if (configCache[cacheKey]) {
|
|
1197
|
-
return configCache[cacheKey];
|
|
1198
|
-
}
|
|
1199
|
-
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
1200
|
-
if (!result) {
|
|
1201
|
-
throw new MicrofrontendError(
|
|
1202
|
-
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
1203
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1204
|
-
);
|
|
1205
|
-
}
|
|
1206
|
-
configCache[cacheKey] = result;
|
|
1207
|
-
return result;
|
|
1208
|
-
}
|
|
1209
|
-
function existsSync(path6) {
|
|
1210
|
-
try {
|
|
1211
|
-
(0, import_node_fs5.statSync)(path6);
|
|
1212
|
-
return true;
|
|
1213
|
-
} catch (_) {
|
|
1214
|
-
return false;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
1218
|
-
logger.debug(
|
|
1219
|
-
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
1220
|
-
);
|
|
1221
|
-
const misplacedConfigPath = (0, import_node_path5.join)(
|
|
1222
|
-
repositoryRoot,
|
|
1223
|
-
".vercel",
|
|
1224
|
-
customConfigFilename || "microfrontends.json"
|
|
1225
|
-
);
|
|
1226
|
-
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
1227
|
-
}
|
|
1228
|
-
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
1229
|
-
try {
|
|
1230
|
-
const microfrontendsJsonContent = (0, import_node_fs5.readFileSync)(
|
|
1231
|
-
microfrontendsJsonPath,
|
|
1232
|
-
"utf-8"
|
|
1233
|
-
);
|
|
1234
|
-
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1235
|
-
if (microfrontendsJson.applications[applicationName]) {
|
|
1236
|
-
logger.debug(
|
|
1237
|
-
"[MFE Config] Found application in config:",
|
|
1238
|
-
microfrontendsJsonPath
|
|
1239
|
-
);
|
|
1240
|
-
return true;
|
|
1241
|
-
}
|
|
1242
|
-
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
1243
|
-
if (app.packageName === applicationName) {
|
|
1244
|
-
logger.debug(
|
|
1245
|
-
"[MFE Config] Found application via packageName in config:",
|
|
1246
|
-
microfrontendsJsonPath
|
|
1247
|
-
);
|
|
1248
|
-
return true;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
} catch (error2) {
|
|
1252
|
-
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
1253
|
-
}
|
|
1254
|
-
return false;
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
1257
|
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1258
1258
|
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1259
1259
|
var import_node_path6 = __toESM(require("path"), 1);
|