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