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