@vercel/microfrontends 0.13.0 → 0.14.0
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/README.md +3 -3
- package/dist/bin/cli.cjs +85 -60
- package/dist/config/client.d.ts +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js.map +1 -1
- package/dist/{index-83133f2d.d.ts → index-bf67a461.d.ts} +3 -10
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +1 -1
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +0 -29
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +0 -29
- package/dist/next/middleware.js.map +1 -1
- package/dist/{types-a995174e.d.ts → types-a29d224a.d.ts} +1 -7
- package/dist/{types-15b7f215.d.ts → types-cfe3308b.d.ts} +1 -1
- package/dist/types-fc30696d.d.ts +11 -0
- package/dist/utils/mfe-port.cjs +70 -56
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +67 -53
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/v2/config.cjs +0 -14
- package/dist/v2/config.cjs.map +1 -1
- package/dist/v2/config.d.ts +4 -3
- package/dist/v2/config.js +0 -14
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +68 -54
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +6 -5
- package/dist/v2/microfrontends/server.js +65 -51
- package/dist/v2/microfrontends/server.js.map +1 -1
- package/dist/v2/microfrontends.cjs +0 -14
- package/dist/v2/microfrontends.cjs.map +1 -1
- package/dist/v2/microfrontends.d.ts +4 -3
- package/dist/v2/microfrontends.js +0 -14
- package/dist/v2/microfrontends.js.map +1 -1
- package/dist/v2/next/client.cjs +1 -1
- package/dist/v2/next/client.cjs.map +1 -1
- package/dist/v2/next/client.js +1 -1
- package/dist/v2/next/client.js.map +1 -1
- package/dist/v2/next/config.cjs +106 -60
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.js +103 -57
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/endpoints.cjs.map +1 -1
- package/dist/v2/next/endpoints.d.ts +13 -2
- package/dist/v2/next/endpoints.js.map +1 -1
- package/dist/v2/next/middleware.cjs +10 -54
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.d.ts +7 -2
- package/dist/v2/next/middleware.js +10 -54
- package/dist/v2/next/middleware.js.map +1 -1
- package/dist/v2/next/testing.cjs +992 -0
- package/dist/v2/next/testing.cjs.map +1 -0
- package/dist/v2/next/testing.d.ts +55 -0
- package/dist/v2/next/testing.js +961 -0
- package/dist/v2/next/testing.js.map +1 -0
- package/dist/v2/overrides.d.ts +3 -3
- package/dist/v2/routing.cjs +19 -0
- package/dist/v2/routing.cjs.map +1 -0
- package/dist/v2/routing.d.ts +26 -0
- package/dist/v2/routing.js +1 -0
- package/dist/v2/routing.js.map +1 -0
- package/dist/v2/schema.cjs.map +1 -1
- package/dist/v2/schema.d.ts +1 -1
- package/dist/validation.cjs +0 -4
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +0 -6
- package/dist/validation.js +0 -4
- package/dist/validation.js.map +1 -1
- package/package.json +20 -5
- package/schema/schema-v2.json +0 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/config-v2/microfrontends/server/index.ts
|
|
2
|
-
import
|
|
3
|
-
import { dirname as dirname3, join } from "node:path";
|
|
2
|
+
import fs5 from "node:fs";
|
|
3
|
+
import { dirname as dirname3, join as join2 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// src/config-v2/overrides/constants.ts
|
|
6
6
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -347,19 +347,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
349
|
};
|
|
350
|
-
var validateConfigOptions = (options) => {
|
|
351
|
-
var _a;
|
|
352
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
353
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
354
|
-
options.vercel.previewDeploymentSuffix
|
|
355
|
-
)) {
|
|
356
|
-
throw new MicrofrontendError(
|
|
357
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
358
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
350
|
|
|
364
351
|
// src/config-v2/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
365
352
|
var PREFIX = "vc-ap";
|
|
@@ -578,7 +565,6 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
578
565
|
validateConfigPaths(c.applications);
|
|
579
566
|
validateConfigDefaultApplication(c.applications);
|
|
580
567
|
}
|
|
581
|
-
validateConfigOptions(c.options);
|
|
582
568
|
return c;
|
|
583
569
|
}
|
|
584
570
|
static fromEnv({
|
|
@@ -854,29 +840,39 @@ function findPackagePath(opts) {
|
|
|
854
840
|
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
855
841
|
import { dirname as dirname2 } from "node:path";
|
|
856
842
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
843
|
+
import { parse as parse2 } from "jsonc-parser";
|
|
857
844
|
import fg2 from "fast-glob";
|
|
845
|
+
|
|
846
|
+
// src/config-v2/constants.ts
|
|
847
|
+
var CONFIGURATION_FILENAMES = [
|
|
848
|
+
"microfrontends.jsonc",
|
|
849
|
+
"microfrontends.json"
|
|
850
|
+
];
|
|
851
|
+
|
|
852
|
+
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
858
853
|
var configCache2 = {};
|
|
859
854
|
function findDefaultMicrofrontendsPackages({
|
|
860
855
|
repositoryRoot,
|
|
861
856
|
applicationName
|
|
862
857
|
}) {
|
|
863
858
|
try {
|
|
864
|
-
const microfrontendsJsonPaths = fg2.globSync(
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
859
|
+
const microfrontendsJsonPaths = fg2.globSync(
|
|
860
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
861
|
+
{
|
|
862
|
+
cwd: repositoryRoot,
|
|
863
|
+
absolute: true,
|
|
864
|
+
onlyFiles: true,
|
|
865
|
+
followSymbolicLinks: false,
|
|
866
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
867
|
+
}
|
|
868
|
+
);
|
|
871
869
|
const matchingPaths = [];
|
|
872
870
|
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
873
871
|
const microfrontendsJsonContent = readFileSync2(
|
|
874
872
|
microfrontendsJsonPath,
|
|
875
873
|
"utf-8"
|
|
876
874
|
);
|
|
877
|
-
const microfrontendsJson =
|
|
878
|
-
microfrontendsJsonContent
|
|
879
|
-
);
|
|
875
|
+
const microfrontendsJson = parse2(microfrontendsJsonContent);
|
|
880
876
|
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
881
877
|
matchingPaths.push(microfrontendsJsonPath);
|
|
882
878
|
}
|
|
@@ -906,7 +902,7 @@ function findDefaultMicrofrontendsPackage(opts) {
|
|
|
906
902
|
const result = findDefaultMicrofrontendsPackages(opts);
|
|
907
903
|
if (!result) {
|
|
908
904
|
throw new Error(
|
|
909
|
-
`Error trying to resolve the main microfrontends
|
|
905
|
+
`Error trying to resolve the main microfrontends configuration`
|
|
910
906
|
);
|
|
911
907
|
}
|
|
912
908
|
configCache2[cacheKey] = result;
|
|
@@ -958,6 +954,19 @@ function findPackageRoot(startDir) {
|
|
|
958
954
|
);
|
|
959
955
|
}
|
|
960
956
|
|
|
957
|
+
// src/config-v2/microfrontends/utils/find-config.ts
|
|
958
|
+
import fs4 from "node:fs";
|
|
959
|
+
import { join } from "node:path";
|
|
960
|
+
function findConfig({ dir }) {
|
|
961
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
962
|
+
const maybeConfig = join(dir, filename);
|
|
963
|
+
if (fs4.existsSync(maybeConfig)) {
|
|
964
|
+
return maybeConfig;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
|
|
961
970
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
962
971
|
import path4 from "node:path";
|
|
963
972
|
|
|
@@ -983,7 +992,7 @@ function getOutputFilePath() {
|
|
|
983
992
|
}
|
|
984
993
|
|
|
985
994
|
// src/config-v2/microfrontends/server/validation.ts
|
|
986
|
-
import { parse as
|
|
995
|
+
import { parse as parse3 } from "jsonc-parser";
|
|
987
996
|
import { Ajv } from "ajv";
|
|
988
997
|
|
|
989
998
|
// src/config/errors.ts
|
|
@@ -1136,10 +1145,6 @@ var schema_v2_default = {
|
|
|
1136
1145
|
VercelOptions: {
|
|
1137
1146
|
type: "object",
|
|
1138
1147
|
properties: {
|
|
1139
|
-
previewDeploymentSuffix: {
|
|
1140
|
-
type: "string",
|
|
1141
|
-
description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
|
|
1142
|
-
},
|
|
1143
1148
|
teamSlug: {
|
|
1144
1149
|
type: "string",
|
|
1145
1150
|
description: "Team slug for the Vercel team"
|
|
@@ -1333,7 +1338,7 @@ var SCHEMA = schema_v2_default;
|
|
|
1333
1338
|
|
|
1334
1339
|
// src/config-v2/microfrontends/server/validation.ts
|
|
1335
1340
|
function validateSchema(configString) {
|
|
1336
|
-
const parsedConfig =
|
|
1341
|
+
const parsedConfig = parse3(configString);
|
|
1337
1342
|
const ajv = new Ajv();
|
|
1338
1343
|
const validate = ajv.compile(SCHEMA);
|
|
1339
1344
|
const isValid = validate(parsedConfig);
|
|
@@ -1355,8 +1360,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1355
1360
|
pretty: true
|
|
1356
1361
|
}) {
|
|
1357
1362
|
const outputPath = getOutputFilePath();
|
|
1358
|
-
|
|
1359
|
-
|
|
1363
|
+
fs5.mkdirSync(dirname3(outputPath), { recursive: true });
|
|
1364
|
+
fs5.writeFileSync(
|
|
1360
1365
|
outputPath,
|
|
1361
1366
|
JSON.stringify(
|
|
1362
1367
|
this.config.toSchemaJson(),
|
|
@@ -1419,8 +1424,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1419
1424
|
return config;
|
|
1420
1425
|
}
|
|
1421
1426
|
/**
|
|
1422
|
-
* Looks up the configuration by inferring the package root and looking for a microfrontends
|
|
1423
|
-
* it will look for a package in the repository with a microfrontends
|
|
1427
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends config file. If a file is not found,
|
|
1428
|
+
* it will look for a package in the repository with a microfrontends file that contains the current application
|
|
1424
1429
|
* and use that configuration.
|
|
1425
1430
|
*
|
|
1426
1431
|
* This can return either a Child or Main configuration.
|
|
@@ -1442,16 +1447,16 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1442
1447
|
}
|
|
1443
1448
|
try {
|
|
1444
1449
|
const packageRoot = findPackageRoot(directory);
|
|
1445
|
-
const packageJsonPath =
|
|
1450
|
+
const packageJsonPath = join2(packageRoot, "package.json");
|
|
1446
1451
|
const packageJson = JSON.parse(
|
|
1447
|
-
|
|
1452
|
+
fs5.readFileSync(packageJsonPath, "utf-8")
|
|
1448
1453
|
);
|
|
1449
1454
|
if (!packageJson.name) {
|
|
1450
1455
|
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1451
1456
|
}
|
|
1452
1457
|
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1453
|
-
const maybeConfig =
|
|
1454
|
-
if (
|
|
1458
|
+
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1459
|
+
if (maybeConfig) {
|
|
1455
1460
|
return MicrofrontendsServer.fromFile({
|
|
1456
1461
|
filePath: maybeConfig,
|
|
1457
1462
|
cookies,
|
|
@@ -1466,12 +1471,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1466
1471
|
repositoryRoot,
|
|
1467
1472
|
applicationName: packageJson.name
|
|
1468
1473
|
});
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1474
|
+
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1475
|
+
if (maybeConfigFromDefault) {
|
|
1476
|
+
return MicrofrontendsServer.fromFile({
|
|
1477
|
+
filePath: maybeConfigFromDefault,
|
|
1478
|
+
cookies,
|
|
1479
|
+
meta: configMeta,
|
|
1480
|
+
options
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1475
1483
|
}
|
|
1476
1484
|
throw new Error("Unable to infer");
|
|
1477
1485
|
} catch (e) {
|
|
@@ -1491,7 +1499,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1491
1499
|
options
|
|
1492
1500
|
}) {
|
|
1493
1501
|
try {
|
|
1494
|
-
const configJson =
|
|
1502
|
+
const configJson = fs5.readFileSync(filePath, "utf-8");
|
|
1495
1503
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1496
1504
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1497
1505
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1507,9 +1515,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1507
1515
|
{ type: "config", subtype: "not_found" }
|
|
1508
1516
|
);
|
|
1509
1517
|
}
|
|
1510
|
-
const
|
|
1518
|
+
const maybeConfig = findConfig({ dir: packagePath });
|
|
1519
|
+
if (!maybeConfig) {
|
|
1520
|
+
throw new MicrofrontendError(
|
|
1521
|
+
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1522
|
+
{ type: "config", subtype: "not_found" }
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1511
1525
|
return MicrofrontendsServer.fromMainConfigFile({
|
|
1512
|
-
filePath:
|
|
1526
|
+
filePath: maybeConfig,
|
|
1513
1527
|
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1514
1528
|
});
|
|
1515
1529
|
}
|
|
@@ -1533,7 +1547,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1533
1547
|
overrides
|
|
1534
1548
|
}) {
|
|
1535
1549
|
try {
|
|
1536
|
-
const config =
|
|
1550
|
+
const config = fs5.readFileSync(filePath, "utf-8");
|
|
1537
1551
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1538
1552
|
if (!isMainConfig(validatedConfig)) {
|
|
1539
1553
|
throw new MicrofrontendError(
|