@vercel/microfrontends 2.3.0 → 2.3.2
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 +13 -0
- package/dist/bin/cli.cjs +275 -268
- package/dist/config.cjs +22 -21
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +3 -2
- package/dist/config.js +22 -21
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +259 -258
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +239 -238
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +259 -258
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +239 -238
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +259 -258
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +2 -2
- package/dist/microfrontends/server.js +239 -238
- 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 +259 -258
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +239 -238
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +22 -21
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +22 -21
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +22 -21
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +2 -2
- package/dist/next/testing.js +22 -21
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/schema.d.ts +2 -2
- package/dist/{types-b9ea41b2.d.ts → types-279c294f.d.ts} +1 -1
- package/dist/{types-dcd8b17a.d.ts → types-f331c2a8.d.ts} +0 -4
- package/dist/utils/mfe-port.cjs +259 -258
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +239 -238
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
@@ -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) {
|
|
@@ -699,6 +913,7 @@ var Application = class {
|
|
|
699
913
|
}
|
|
700
914
|
return generatedAssetPrefix;
|
|
701
915
|
}
|
|
916
|
+
/** @deprecated Prefer `VERCEL_AUTOMATION_BYPASS_SECRET`. Use this only if each project needs its own distinct bypass secret. */
|
|
702
917
|
getAutomationBypassEnvVarName() {
|
|
703
918
|
return generateAutomationBypassEnvVarName({ name: this.name });
|
|
704
919
|
}
|
|
@@ -785,7 +1000,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
785
1000
|
};
|
|
786
1001
|
}
|
|
787
1002
|
static validate(config) {
|
|
788
|
-
const c = typeof config === "string" ? (0,
|
|
1003
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
789
1004
|
validateConfigPaths(c.applications);
|
|
790
1005
|
validateConfigDefaultApplication(c.applications);
|
|
791
1006
|
return c;
|
|
@@ -794,7 +1009,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
794
1009
|
cookies
|
|
795
1010
|
}) {
|
|
796
1011
|
return new MicrofrontendConfigIsomorphic({
|
|
797
|
-
config: (0,
|
|
1012
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
798
1013
|
overrides: parseOverrides(cookies ?? [])
|
|
799
1014
|
});
|
|
800
1015
|
}
|
|
@@ -908,59 +1123,18 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
908
1123
|
}
|
|
909
1124
|
};
|
|
910
1125
|
|
|
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
1126
|
// src/config/microfrontends/utils/find-package-root.ts
|
|
953
|
-
var
|
|
954
|
-
var
|
|
1127
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
1128
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
955
1129
|
var PACKAGE_JSON = "package.json";
|
|
956
1130
|
function findPackageRoot(startDir) {
|
|
957
1131
|
let currentDir = startDir || process.cwd();
|
|
958
|
-
while (currentDir !==
|
|
959
|
-
const pkgJsonPath =
|
|
960
|
-
if (
|
|
1132
|
+
while (currentDir !== import_node_path3.default.parse(currentDir).root) {
|
|
1133
|
+
const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
|
|
1134
|
+
if (import_node_fs3.default.existsSync(pkgJsonPath)) {
|
|
961
1135
|
return currentDir;
|
|
962
1136
|
}
|
|
963
|
-
currentDir =
|
|
1137
|
+
currentDir = import_node_path3.default.dirname(currentDir);
|
|
964
1138
|
}
|
|
965
1139
|
throw new Error(
|
|
966
1140
|
`The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
|
|
@@ -968,18 +1142,18 @@ function findPackageRoot(startDir) {
|
|
|
968
1142
|
}
|
|
969
1143
|
|
|
970
1144
|
// src/config/microfrontends/utils/find-repository-root.ts
|
|
971
|
-
var
|
|
972
|
-
var
|
|
1145
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1146
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
973
1147
|
var GIT_DIRECTORY = ".git";
|
|
974
1148
|
function hasGitDirectory(dir) {
|
|
975
|
-
const gitPath =
|
|
976
|
-
return
|
|
1149
|
+
const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
|
|
1150
|
+
return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
|
|
977
1151
|
}
|
|
978
1152
|
function hasPnpmWorkspaces(dir) {
|
|
979
|
-
return
|
|
1153
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
|
|
980
1154
|
}
|
|
981
1155
|
function hasPackageJson(dir) {
|
|
982
|
-
return
|
|
1156
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
|
|
983
1157
|
}
|
|
984
1158
|
function findRepositoryRoot(startDir) {
|
|
985
1159
|
if (process.env.NX_WORKSPACE_ROOT) {
|
|
@@ -987,14 +1161,14 @@ function findRepositoryRoot(startDir) {
|
|
|
987
1161
|
}
|
|
988
1162
|
let currentDir = startDir || process.cwd();
|
|
989
1163
|
let lastPackageJsonDir = null;
|
|
990
|
-
while (currentDir !==
|
|
1164
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
991
1165
|
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
992
1166
|
return currentDir;
|
|
993
1167
|
}
|
|
994
1168
|
if (hasPackageJson(currentDir)) {
|
|
995
1169
|
lastPackageJsonDir = currentDir;
|
|
996
1170
|
}
|
|
997
|
-
currentDir =
|
|
1171
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
998
1172
|
}
|
|
999
1173
|
if (lastPackageJsonDir) {
|
|
1000
1174
|
return lastPackageJsonDir;
|
|
@@ -1005,8 +1179,8 @@ function findRepositoryRoot(startDir) {
|
|
|
1005
1179
|
}
|
|
1006
1180
|
|
|
1007
1181
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1008
|
-
var
|
|
1009
|
-
var
|
|
1182
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1183
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
1010
1184
|
function getApplicationContext(opts) {
|
|
1011
1185
|
if (opts?.appName) {
|
|
1012
1186
|
logger.debug(
|
|
@@ -1036,8 +1210,8 @@ function getApplicationContext(opts) {
|
|
|
1036
1210
|
};
|
|
1037
1211
|
}
|
|
1038
1212
|
try {
|
|
1039
|
-
const vercelProjectJsonPath =
|
|
1040
|
-
|
|
1213
|
+
const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
|
|
1214
|
+
import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
|
|
1041
1215
|
"utf-8"
|
|
1042
1216
|
);
|
|
1043
1217
|
const projectJson = JSON.parse(vercelProjectJsonPath);
|
|
@@ -1054,8 +1228,8 @@ function getApplicationContext(opts) {
|
|
|
1054
1228
|
} catch (_) {
|
|
1055
1229
|
}
|
|
1056
1230
|
try {
|
|
1057
|
-
const packageJsonString =
|
|
1058
|
-
|
|
1231
|
+
const packageJsonString = import_node_fs5.default.readFileSync(
|
|
1232
|
+
import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1059
1233
|
"utf-8"
|
|
1060
1234
|
);
|
|
1061
1235
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1081,179 +1255,6 @@ function getApplicationContext(opts) {
|
|
|
1081
1255
|
}
|
|
1082
1256
|
}
|
|
1083
1257
|
|
|
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
1258
|
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1258
1259
|
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1259
1260
|
var import_node_path6 = __toESM(require("path"), 1);
|