@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
|
@@ -153,7 +153,16 @@ var MicrofrontendError = class extends Error {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
// src/config/microfrontends-config/isomorphic/index.ts
|
|
156
|
-
var
|
|
156
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
157
|
+
|
|
158
|
+
// src/config/microfrontends/utils/hash-application-name.ts
|
|
159
|
+
var import_md5 = __toESM(require("md5"), 1);
|
|
160
|
+
function hashApplicationName(name) {
|
|
161
|
+
if (!name) {
|
|
162
|
+
throw new Error("Application name is required to generate hash");
|
|
163
|
+
}
|
|
164
|
+
return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
|
|
165
|
+
}
|
|
157
166
|
|
|
158
167
|
// src/config/overrides/constants.ts
|
|
159
168
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -303,6 +312,231 @@ function getConfigStringFromEnv() {
|
|
|
303
312
|
return config;
|
|
304
313
|
}
|
|
305
314
|
|
|
315
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
316
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
317
|
+
var import_node_path = require("path");
|
|
318
|
+
|
|
319
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
320
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
321
|
+
"microfrontends.json",
|
|
322
|
+
"microfrontends.jsonc"
|
|
323
|
+
];
|
|
324
|
+
function getPossibleConfigurationFilenames({
|
|
325
|
+
customConfigFilename
|
|
326
|
+
}) {
|
|
327
|
+
if (customConfigFilename) {
|
|
328
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
329
|
+
throw new Error(
|
|
330
|
+
`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.`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
return Array.from(
|
|
334
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
341
|
+
function findConfig({
|
|
342
|
+
dir,
|
|
343
|
+
customConfigFilename
|
|
344
|
+
}) {
|
|
345
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
346
|
+
customConfigFilename
|
|
347
|
+
})) {
|
|
348
|
+
const maybeConfig = (0, import_node_path.join)(dir, filename);
|
|
349
|
+
if (import_node_fs.default.existsSync(maybeConfig)) {
|
|
350
|
+
return maybeConfig;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/config/microfrontends/utils/generate-default-asset-prefix.ts
|
|
357
|
+
var PREFIX = "vc-ap";
|
|
358
|
+
function generateDefaultAssetPrefixFromName({
|
|
359
|
+
name
|
|
360
|
+
}) {
|
|
361
|
+
if (!name) {
|
|
362
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
363
|
+
}
|
|
364
|
+
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
368
|
+
var import_node_fs2 = require("fs");
|
|
369
|
+
var import_node_path2 = require("path");
|
|
370
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
371
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
372
|
+
var configCache = {};
|
|
373
|
+
function findPackageWithMicrofrontendsConfig({
|
|
374
|
+
repositoryRoot,
|
|
375
|
+
applicationContext,
|
|
376
|
+
customConfigFilename
|
|
377
|
+
}) {
|
|
378
|
+
const applicationName = applicationContext.name;
|
|
379
|
+
logger.debug(
|
|
380
|
+
"[MFE Config] Searching repository for configs containing application:",
|
|
381
|
+
applicationName
|
|
382
|
+
);
|
|
383
|
+
try {
|
|
384
|
+
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
385
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
386
|
+
{
|
|
387
|
+
cwd: repositoryRoot,
|
|
388
|
+
absolute: true,
|
|
389
|
+
onlyFiles: true,
|
|
390
|
+
followSymbolicLinks: false,
|
|
391
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
logger.debug(
|
|
395
|
+
"[MFE Config] Found",
|
|
396
|
+
microfrontendsJsonPaths.length,
|
|
397
|
+
"config file(s) in repository"
|
|
398
|
+
);
|
|
399
|
+
const matchingPaths = [];
|
|
400
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
401
|
+
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
402
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
logger.debug(
|
|
406
|
+
"[MFE Config] Total matching config files:",
|
|
407
|
+
matchingPaths.length
|
|
408
|
+
);
|
|
409
|
+
if (matchingPaths.length > 1) {
|
|
410
|
+
throw new MicrofrontendError(
|
|
411
|
+
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
412
|
+
${matchingPaths.join("\n \u2022 ")}`,
|
|
413
|
+
{ type: "config", subtype: "inference_failed" }
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
if (matchingPaths.length === 0) {
|
|
417
|
+
if (repositoryRoot && doesMisplacedConfigExist(
|
|
418
|
+
repositoryRoot,
|
|
419
|
+
applicationName,
|
|
420
|
+
customConfigFilename
|
|
421
|
+
)) {
|
|
422
|
+
logger.debug(
|
|
423
|
+
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
424
|
+
);
|
|
425
|
+
const misplacedConfigPath = (0, import_node_path2.join)(
|
|
426
|
+
repositoryRoot,
|
|
427
|
+
".vercel",
|
|
428
|
+
customConfigFilename || "microfrontends.json"
|
|
429
|
+
);
|
|
430
|
+
throw new MicrofrontendError(
|
|
431
|
+
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
432
|
+
|
|
433
|
+
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
434
|
+
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
435
|
+
|
|
436
|
+
To fix this:
|
|
437
|
+
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
|
|
438
|
+
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
439
|
+
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
440
|
+
|
|
441
|
+
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
442
|
+
{ type: "config", subtype: "inference_failed" }
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
let additionalErrorMessage = "";
|
|
446
|
+
if (microfrontendsJsonPaths.length > 0) {
|
|
447
|
+
if (!applicationContext.projectName) {
|
|
448
|
+
additionalErrorMessage = `
|
|
449
|
+
|
|
450
|
+
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.`;
|
|
451
|
+
} else {
|
|
452
|
+
additionalErrorMessage = `
|
|
453
|
+
|
|
454
|
+
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
throw new MicrofrontendError(
|
|
458
|
+
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
459
|
+
|
|
460
|
+
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.
|
|
461
|
+
|
|
462
|
+
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.
|
|
463
|
+
|
|
464
|
+
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
465
|
+
{ type: "config", subtype: "inference_failed" }
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
const [packageJsonPath] = matchingPaths;
|
|
469
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
470
|
+
} catch (error2) {
|
|
471
|
+
if (error2 instanceof MicrofrontendError) {
|
|
472
|
+
throw error2;
|
|
473
|
+
}
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function inferMicrofrontendsLocation(opts) {
|
|
478
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
479
|
+
if (configCache[cacheKey]) {
|
|
480
|
+
return configCache[cacheKey];
|
|
481
|
+
}
|
|
482
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
483
|
+
if (!result) {
|
|
484
|
+
throw new MicrofrontendError(
|
|
485
|
+
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
486
|
+
{ type: "config", subtype: "inference_failed" }
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
configCache[cacheKey] = result;
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
492
|
+
function existsSync(path6) {
|
|
493
|
+
try {
|
|
494
|
+
(0, import_node_fs2.statSync)(path6);
|
|
495
|
+
return true;
|
|
496
|
+
} catch (_) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
501
|
+
logger.debug(
|
|
502
|
+
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
503
|
+
);
|
|
504
|
+
const misplacedConfigPath = (0, import_node_path2.join)(
|
|
505
|
+
repositoryRoot,
|
|
506
|
+
".vercel",
|
|
507
|
+
customConfigFilename || "microfrontends.json"
|
|
508
|
+
);
|
|
509
|
+
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
510
|
+
}
|
|
511
|
+
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
512
|
+
try {
|
|
513
|
+
const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
|
|
514
|
+
microfrontendsJsonPath,
|
|
515
|
+
"utf-8"
|
|
516
|
+
);
|
|
517
|
+
const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
|
|
518
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
519
|
+
logger.debug(
|
|
520
|
+
"[MFE Config] Found application in config:",
|
|
521
|
+
microfrontendsJsonPath
|
|
522
|
+
);
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
526
|
+
if (app.packageName === applicationName) {
|
|
527
|
+
logger.debug(
|
|
528
|
+
"[MFE Config] Found application via packageName in config:",
|
|
529
|
+
microfrontendsJsonPath
|
|
530
|
+
);
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
} catch (error2) {
|
|
535
|
+
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
536
|
+
}
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
|
|
306
540
|
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
307
541
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
308
542
|
var MFE_APP_PORT_ENV = "MFE_APP_PORT";
|
|
@@ -441,26 +675,6 @@ var LocalHost = class extends Host {
|
|
|
441
675
|
}
|
|
442
676
|
};
|
|
443
677
|
|
|
444
|
-
// src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
|
|
445
|
-
var import_md5 = __toESM(require("md5"), 1);
|
|
446
|
-
function hashApplicationName(name) {
|
|
447
|
-
if (!name) {
|
|
448
|
-
throw new Error("Application name is required to generate hash");
|
|
449
|
-
}
|
|
450
|
-
return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
454
|
-
var PREFIX = "vc-ap";
|
|
455
|
-
function generateAssetPrefixFromName({
|
|
456
|
-
name
|
|
457
|
-
}) {
|
|
458
|
-
if (!name) {
|
|
459
|
-
throw new Error("Name is required to generate an asset prefix");
|
|
460
|
-
}
|
|
461
|
-
return `${PREFIX}-${hashApplicationName(name)}`;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
678
|
// src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
|
|
465
679
|
function generateAutomationBypassEnvVarName({
|
|
466
680
|
name
|
|
@@ -678,7 +892,7 @@ var Application = class {
|
|
|
678
892
|
return this.default;
|
|
679
893
|
}
|
|
680
894
|
getAssetPrefix() {
|
|
681
|
-
const generatedAssetPrefix =
|
|
895
|
+
const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
|
|
682
896
|
name: this.name
|
|
683
897
|
});
|
|
684
898
|
if ("assetPrefix" in this.serialized) {
|
|
@@ -686,6 +900,7 @@ var Application = class {
|
|
|
686
900
|
}
|
|
687
901
|
return generatedAssetPrefix;
|
|
688
902
|
}
|
|
903
|
+
/** @deprecated Prefer `VERCEL_AUTOMATION_BYPASS_SECRET`. Use this only if each project needs its own distinct bypass secret. */
|
|
689
904
|
getAutomationBypassEnvVarName() {
|
|
690
905
|
return generateAutomationBypassEnvVarName({ name: this.name });
|
|
691
906
|
}
|
|
@@ -772,7 +987,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
772
987
|
};
|
|
773
988
|
}
|
|
774
989
|
static validate(config) {
|
|
775
|
-
const c = typeof config === "string" ? (0,
|
|
990
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
776
991
|
validateConfigPaths(c.applications);
|
|
777
992
|
validateConfigDefaultApplication(c.applications);
|
|
778
993
|
return c;
|
|
@@ -781,7 +996,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
781
996
|
cookies
|
|
782
997
|
}) {
|
|
783
998
|
return new MicrofrontendConfigIsomorphic({
|
|
784
|
-
config: (0,
|
|
999
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
785
1000
|
overrides: parseOverrides(cookies ?? [])
|
|
786
1001
|
});
|
|
787
1002
|
}
|
|
@@ -895,59 +1110,18 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
895
1110
|
}
|
|
896
1111
|
};
|
|
897
1112
|
|
|
898
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
899
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
900
|
-
var import_node_path = require("path");
|
|
901
|
-
|
|
902
|
-
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
903
|
-
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
904
|
-
"microfrontends.json",
|
|
905
|
-
"microfrontends.jsonc"
|
|
906
|
-
];
|
|
907
|
-
function getPossibleConfigurationFilenames({
|
|
908
|
-
customConfigFilename
|
|
909
|
-
}) {
|
|
910
|
-
if (customConfigFilename) {
|
|
911
|
-
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
912
|
-
throw new Error(
|
|
913
|
-
`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.`
|
|
914
|
-
);
|
|
915
|
-
}
|
|
916
|
-
return Array.from(
|
|
917
|
-
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
918
|
-
);
|
|
919
|
-
}
|
|
920
|
-
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
924
|
-
function findConfig({
|
|
925
|
-
dir,
|
|
926
|
-
customConfigFilename
|
|
927
|
-
}) {
|
|
928
|
-
for (const filename of getPossibleConfigurationFilenames({
|
|
929
|
-
customConfigFilename
|
|
930
|
-
})) {
|
|
931
|
-
const maybeConfig = (0, import_node_path.join)(dir, filename);
|
|
932
|
-
if (import_node_fs.default.existsSync(maybeConfig)) {
|
|
933
|
-
return maybeConfig;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
return null;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
1113
|
// src/config/microfrontends/utils/find-package-root.ts
|
|
940
|
-
var
|
|
941
|
-
var
|
|
1114
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
1115
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
942
1116
|
var PACKAGE_JSON = "package.json";
|
|
943
1117
|
function findPackageRoot(startDir) {
|
|
944
1118
|
let currentDir = startDir || process.cwd();
|
|
945
|
-
while (currentDir !==
|
|
946
|
-
const pkgJsonPath =
|
|
947
|
-
if (
|
|
1119
|
+
while (currentDir !== import_node_path3.default.parse(currentDir).root) {
|
|
1120
|
+
const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
|
|
1121
|
+
if (import_node_fs3.default.existsSync(pkgJsonPath)) {
|
|
948
1122
|
return currentDir;
|
|
949
1123
|
}
|
|
950
|
-
currentDir =
|
|
1124
|
+
currentDir = import_node_path3.default.dirname(currentDir);
|
|
951
1125
|
}
|
|
952
1126
|
throw new Error(
|
|
953
1127
|
`The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
|
|
@@ -955,18 +1129,18 @@ function findPackageRoot(startDir) {
|
|
|
955
1129
|
}
|
|
956
1130
|
|
|
957
1131
|
// src/config/microfrontends/utils/find-repository-root.ts
|
|
958
|
-
var
|
|
959
|
-
var
|
|
1132
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1133
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
960
1134
|
var GIT_DIRECTORY = ".git";
|
|
961
1135
|
function hasGitDirectory(dir) {
|
|
962
|
-
const gitPath =
|
|
963
|
-
return
|
|
1136
|
+
const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
|
|
1137
|
+
return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
|
|
964
1138
|
}
|
|
965
1139
|
function hasPnpmWorkspaces(dir) {
|
|
966
|
-
return
|
|
1140
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
|
|
967
1141
|
}
|
|
968
1142
|
function hasPackageJson(dir) {
|
|
969
|
-
return
|
|
1143
|
+
return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
|
|
970
1144
|
}
|
|
971
1145
|
function findRepositoryRoot(startDir) {
|
|
972
1146
|
if (process.env.NX_WORKSPACE_ROOT) {
|
|
@@ -974,14 +1148,14 @@ function findRepositoryRoot(startDir) {
|
|
|
974
1148
|
}
|
|
975
1149
|
let currentDir = startDir || process.cwd();
|
|
976
1150
|
let lastPackageJsonDir = null;
|
|
977
|
-
while (currentDir !==
|
|
1151
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
978
1152
|
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
979
1153
|
return currentDir;
|
|
980
1154
|
}
|
|
981
1155
|
if (hasPackageJson(currentDir)) {
|
|
982
1156
|
lastPackageJsonDir = currentDir;
|
|
983
1157
|
}
|
|
984
|
-
currentDir =
|
|
1158
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
985
1159
|
}
|
|
986
1160
|
if (lastPackageJsonDir) {
|
|
987
1161
|
return lastPackageJsonDir;
|
|
@@ -992,8 +1166,8 @@ function findRepositoryRoot(startDir) {
|
|
|
992
1166
|
}
|
|
993
1167
|
|
|
994
1168
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
995
|
-
var
|
|
996
|
-
var
|
|
1169
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1170
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
997
1171
|
function getApplicationContext(opts) {
|
|
998
1172
|
if (opts?.appName) {
|
|
999
1173
|
logger.debug(
|
|
@@ -1023,8 +1197,8 @@ function getApplicationContext(opts) {
|
|
|
1023
1197
|
};
|
|
1024
1198
|
}
|
|
1025
1199
|
try {
|
|
1026
|
-
const vercelProjectJsonPath =
|
|
1027
|
-
|
|
1200
|
+
const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
|
|
1201
|
+
import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
|
|
1028
1202
|
"utf-8"
|
|
1029
1203
|
);
|
|
1030
1204
|
const projectJson = JSON.parse(vercelProjectJsonPath);
|
|
@@ -1041,8 +1215,8 @@ function getApplicationContext(opts) {
|
|
|
1041
1215
|
} catch (_) {
|
|
1042
1216
|
}
|
|
1043
1217
|
try {
|
|
1044
|
-
const packageJsonString =
|
|
1045
|
-
|
|
1218
|
+
const packageJsonString = import_node_fs5.default.readFileSync(
|
|
1219
|
+
import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1046
1220
|
"utf-8"
|
|
1047
1221
|
);
|
|
1048
1222
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1068,179 +1242,6 @@ function getApplicationContext(opts) {
|
|
|
1068
1242
|
}
|
|
1069
1243
|
}
|
|
1070
1244
|
|
|
1071
|
-
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
1072
|
-
var import_node_fs5 = require("fs");
|
|
1073
|
-
var import_node_path5 = require("path");
|
|
1074
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1075
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
1076
|
-
var configCache = {};
|
|
1077
|
-
function findPackageWithMicrofrontendsConfig({
|
|
1078
|
-
repositoryRoot,
|
|
1079
|
-
applicationContext,
|
|
1080
|
-
customConfigFilename
|
|
1081
|
-
}) {
|
|
1082
|
-
const applicationName = applicationContext.name;
|
|
1083
|
-
logger.debug(
|
|
1084
|
-
"[MFE Config] Searching repository for configs containing application:",
|
|
1085
|
-
applicationName
|
|
1086
|
-
);
|
|
1087
|
-
try {
|
|
1088
|
-
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
1089
|
-
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
1090
|
-
{
|
|
1091
|
-
cwd: repositoryRoot,
|
|
1092
|
-
absolute: true,
|
|
1093
|
-
onlyFiles: true,
|
|
1094
|
-
followSymbolicLinks: false,
|
|
1095
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1096
|
-
}
|
|
1097
|
-
);
|
|
1098
|
-
logger.debug(
|
|
1099
|
-
"[MFE Config] Found",
|
|
1100
|
-
microfrontendsJsonPaths.length,
|
|
1101
|
-
"config file(s) in repository"
|
|
1102
|
-
);
|
|
1103
|
-
const matchingPaths = [];
|
|
1104
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1105
|
-
if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
|
|
1106
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
logger.debug(
|
|
1110
|
-
"[MFE Config] Total matching config files:",
|
|
1111
|
-
matchingPaths.length
|
|
1112
|
-
);
|
|
1113
|
-
if (matchingPaths.length > 1) {
|
|
1114
|
-
throw new MicrofrontendError(
|
|
1115
|
-
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
1116
|
-
${matchingPaths.join("\n \u2022 ")}`,
|
|
1117
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
if (matchingPaths.length === 0) {
|
|
1121
|
-
if (repositoryRoot && doesMisplacedConfigExist(
|
|
1122
|
-
repositoryRoot,
|
|
1123
|
-
applicationName,
|
|
1124
|
-
customConfigFilename
|
|
1125
|
-
)) {
|
|
1126
|
-
logger.debug(
|
|
1127
|
-
"[MFE Config] Found misplaced config in wrong .vercel directory in repository"
|
|
1128
|
-
);
|
|
1129
|
-
const misplacedConfigPath = (0, import_node_path5.join)(
|
|
1130
|
-
repositoryRoot,
|
|
1131
|
-
".vercel",
|
|
1132
|
-
customConfigFilename || "microfrontends.json"
|
|
1133
|
-
);
|
|
1134
|
-
throw new MicrofrontendError(
|
|
1135
|
-
`Unable to automatically infer the location of the \`microfrontends.json\` file.
|
|
1136
|
-
|
|
1137
|
-
A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
|
|
1138
|
-
However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
|
|
1139
|
-
|
|
1140
|
-
To fix this:
|
|
1141
|
-
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
|
|
1142
|
-
2. If manually defined, move the config file to the \`.vercel\` directory in your application
|
|
1143
|
-
3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
|
|
1144
|
-
|
|
1145
|
-
For more information, see: https://vercel.com/docs/cli/project-linking`,
|
|
1146
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1149
|
-
let additionalErrorMessage = "";
|
|
1150
|
-
if (microfrontendsJsonPaths.length > 0) {
|
|
1151
|
-
if (!applicationContext.projectName) {
|
|
1152
|
-
additionalErrorMessage = `
|
|
1153
|
-
|
|
1154
|
-
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.`;
|
|
1155
|
-
} else {
|
|
1156
|
-
additionalErrorMessage = `
|
|
1157
|
-
|
|
1158
|
-
Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
throw new MicrofrontendError(
|
|
1162
|
-
`Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
|
|
1163
|
-
|
|
1164
|
-
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.
|
|
1165
|
-
|
|
1166
|
-
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.
|
|
1167
|
-
|
|
1168
|
-
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
1169
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
const [packageJsonPath] = matchingPaths;
|
|
1173
|
-
return (0, import_node_path5.dirname)(packageJsonPath);
|
|
1174
|
-
} catch (error2) {
|
|
1175
|
-
if (error2 instanceof MicrofrontendError) {
|
|
1176
|
-
throw error2;
|
|
1177
|
-
}
|
|
1178
|
-
return null;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
function inferMicrofrontendsLocation(opts) {
|
|
1182
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
1183
|
-
if (configCache[cacheKey]) {
|
|
1184
|
-
return configCache[cacheKey];
|
|
1185
|
-
}
|
|
1186
|
-
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
1187
|
-
if (!result) {
|
|
1188
|
-
throw new MicrofrontendError(
|
|
1189
|
-
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
|
|
1190
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
configCache[cacheKey] = result;
|
|
1194
|
-
return result;
|
|
1195
|
-
}
|
|
1196
|
-
function existsSync(path6) {
|
|
1197
|
-
try {
|
|
1198
|
-
(0, import_node_fs5.statSync)(path6);
|
|
1199
|
-
return true;
|
|
1200
|
-
} catch (_) {
|
|
1201
|
-
return false;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
|
|
1205
|
-
logger.debug(
|
|
1206
|
-
"[MFE Config] Looking for misplaced config in wrong .vercel directory"
|
|
1207
|
-
);
|
|
1208
|
-
const misplacedConfigPath = (0, import_node_path5.join)(
|
|
1209
|
-
repositoryRoot,
|
|
1210
|
-
".vercel",
|
|
1211
|
-
customConfigFilename || "microfrontends.json"
|
|
1212
|
-
);
|
|
1213
|
-
return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
|
|
1214
|
-
}
|
|
1215
|
-
function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
|
|
1216
|
-
try {
|
|
1217
|
-
const microfrontendsJsonContent = (0, import_node_fs5.readFileSync)(
|
|
1218
|
-
microfrontendsJsonPath,
|
|
1219
|
-
"utf-8"
|
|
1220
|
-
);
|
|
1221
|
-
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1222
|
-
if (microfrontendsJson.applications[applicationName]) {
|
|
1223
|
-
logger.debug(
|
|
1224
|
-
"[MFE Config] Found application in config:",
|
|
1225
|
-
microfrontendsJsonPath
|
|
1226
|
-
);
|
|
1227
|
-
return true;
|
|
1228
|
-
}
|
|
1229
|
-
for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
|
|
1230
|
-
if (app.packageName === applicationName) {
|
|
1231
|
-
logger.debug(
|
|
1232
|
-
"[MFE Config] Found application via packageName in config:",
|
|
1233
|
-
microfrontendsJsonPath
|
|
1234
|
-
);
|
|
1235
|
-
return true;
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
} catch (error2) {
|
|
1239
|
-
logger.debug("[MFE Config] Error checking application in config:", error2);
|
|
1240
|
-
}
|
|
1241
|
-
return false;
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
1245
|
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1245
1246
|
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1246
1247
|
var import_node_path6 = __toESM(require("path"), 1);
|