@vercel/microfrontends 2.0.0 → 2.1.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/CHANGELOG.md +17 -0
- package/README.md +1 -5
- package/dist/bin/cli.cjs +226 -79
- package/dist/config.cjs +5 -4
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +5 -4
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +51 -20
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +51 -20
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +51 -20
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +51 -20
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +51 -20
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +51 -20
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends/utils.cjs +32 -7
- package/dist/microfrontends/utils.cjs.map +1 -1
- package/dist/microfrontends/utils.d.ts +8 -2
- package/dist/microfrontends/utils.js +31 -7
- package/dist/microfrontends/utils.js.map +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.ts +15 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +62 -20
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +62 -20
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +5 -4
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +5 -4
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +5 -4
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.js +5 -4
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +66 -40
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +66 -40
- package/dist/utils/mfe-port.js.map +1 -1
- package/package.json +4 -4
|
@@ -222,22 +222,38 @@ var import_node_fs2 = require("fs");
|
|
|
222
222
|
var import_jsonc_parser = require("jsonc-parser");
|
|
223
223
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
224
224
|
|
|
225
|
-
// src/config/
|
|
226
|
-
var
|
|
225
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
226
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
227
227
|
"microfrontends.jsonc",
|
|
228
228
|
"microfrontends.json"
|
|
229
229
|
];
|
|
230
|
+
function getPossibleConfigurationFilenames({
|
|
231
|
+
customConfigFilename
|
|
232
|
+
}) {
|
|
233
|
+
if (customConfigFilename) {
|
|
234
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return Array.from(
|
|
240
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
244
|
+
}
|
|
230
245
|
|
|
231
246
|
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
232
247
|
var configCache = {};
|
|
233
248
|
function findPackageWithMicrofrontendsConfig({
|
|
234
249
|
repositoryRoot,
|
|
235
|
-
applicationContext
|
|
250
|
+
applicationContext,
|
|
251
|
+
customConfigFilename
|
|
236
252
|
}) {
|
|
237
253
|
const applicationName = applicationContext.name;
|
|
238
254
|
try {
|
|
239
255
|
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
240
|
-
`**/{${
|
|
256
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
241
257
|
{
|
|
242
258
|
cwd: repositoryRoot,
|
|
243
259
|
absolute: true,
|
|
@@ -293,6 +309,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
|
|
|
293
309
|
|
|
294
310
|
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.
|
|
295
311
|
|
|
312
|
+
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.
|
|
313
|
+
|
|
296
314
|
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
297
315
|
{ type: "config", subtype: "inference_failed" }
|
|
298
316
|
);
|
|
@@ -307,7 +325,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
|
307
325
|
}
|
|
308
326
|
}
|
|
309
327
|
function inferMicrofrontendsLocation(opts) {
|
|
310
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
|
|
328
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
311
329
|
if (configCache[cacheKey]) {
|
|
312
330
|
return configCache[cacheKey];
|
|
313
331
|
}
|
|
@@ -373,8 +391,13 @@ function findPackageRoot(startDir) {
|
|
|
373
391
|
// src/config/microfrontends/utils/find-config.ts
|
|
374
392
|
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
375
393
|
var import_node_path5 = require("path");
|
|
376
|
-
function findConfig({
|
|
377
|
-
|
|
394
|
+
function findConfig({
|
|
395
|
+
dir,
|
|
396
|
+
customConfigFilename
|
|
397
|
+
}) {
|
|
398
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
399
|
+
customConfigFilename
|
|
400
|
+
})) {
|
|
378
401
|
const maybeConfig = (0, import_node_path5.join)(dir, filename);
|
|
379
402
|
if (import_node_fs5.default.existsSync(maybeConfig)) {
|
|
380
403
|
return maybeConfig;
|
|
@@ -441,7 +464,7 @@ var MicrofrontendConfigClient = class {
|
|
|
441
464
|
static fromEnv(config) {
|
|
442
465
|
if (!config) {
|
|
443
466
|
throw new Error(
|
|
444
|
-
"Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
|
|
467
|
+
"Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`? Is the local proxy running and this application is being accessed via the proxy port? See https://vercel.com/docs/microfrontends/local-development#setting-up-microfrontends-proxy"
|
|
445
468
|
);
|
|
446
469
|
}
|
|
447
470
|
return new MicrofrontendConfigClient(JSON.parse(config));
|
|
@@ -581,10 +604,11 @@ function validatePathExpression(path6) {
|
|
|
581
604
|
}
|
|
582
605
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
583
606
|
// Only limited regex is supported for now, due to performance considerations
|
|
584
|
-
|
|
585
|
-
|
|
607
|
+
// Allows all letters, numbers, and hyphens. Other characters must be escaped.
|
|
608
|
+
!/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
|
|
609
|
+
token.pattern.replace(/\\./g, "")
|
|
586
610
|
)) {
|
|
587
|
-
return `Path ${path6} cannot use unsupported regular expression wildcard`;
|
|
611
|
+
return `Path ${path6} cannot use unsupported regular expression wildcard. If the path includes special characters, they must be escaped with backslash (e.g. '\\(')`;
|
|
588
612
|
}
|
|
589
613
|
if (token.modifier && i !== tokens.length - 1) {
|
|
590
614
|
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
@@ -1476,7 +1500,11 @@ var MicrofrontendsServer = class {
|
|
|
1476
1500
|
appName,
|
|
1477
1501
|
packageRoot
|
|
1478
1502
|
});
|
|
1479
|
-
const
|
|
1503
|
+
const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
|
|
1504
|
+
const maybeConfig = findConfig({
|
|
1505
|
+
dir: packageRoot,
|
|
1506
|
+
customConfigFilename
|
|
1507
|
+
});
|
|
1480
1508
|
if (maybeConfig) {
|
|
1481
1509
|
return MicrofrontendsServer.fromFile({
|
|
1482
1510
|
filePath: maybeConfig,
|
|
@@ -1485,11 +1513,9 @@ var MicrofrontendsServer = class {
|
|
|
1485
1513
|
}
|
|
1486
1514
|
const repositoryRoot = findRepositoryRoot();
|
|
1487
1515
|
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
process.env.VC_MICROFRONTENDS_CONFIG
|
|
1492
|
-
);
|
|
1516
|
+
const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
|
|
1517
|
+
if (typeof configFromEnv === "string") {
|
|
1518
|
+
const maybeConfigFromEnv = (0, import_node_path8.resolve)(packageRoot, configFromEnv);
|
|
1493
1519
|
if (maybeConfigFromEnv) {
|
|
1494
1520
|
return MicrofrontendsServer.fromFile({
|
|
1495
1521
|
filePath: maybeConfigFromEnv,
|
|
@@ -1498,7 +1524,8 @@ var MicrofrontendsServer = class {
|
|
|
1498
1524
|
}
|
|
1499
1525
|
} else {
|
|
1500
1526
|
const maybeConfigFromVercel = findConfig({
|
|
1501
|
-
dir: (0, import_node_path8.join)(packageRoot, ".vercel")
|
|
1527
|
+
dir: (0, import_node_path8.join)(packageRoot, ".vercel"),
|
|
1528
|
+
customConfigFilename
|
|
1502
1529
|
});
|
|
1503
1530
|
if (maybeConfigFromVercel) {
|
|
1504
1531
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1509,9 +1536,13 @@ var MicrofrontendsServer = class {
|
|
|
1509
1536
|
if (isMonorepo2) {
|
|
1510
1537
|
const defaultPackage = inferMicrofrontendsLocation({
|
|
1511
1538
|
repositoryRoot,
|
|
1512
|
-
applicationContext
|
|
1539
|
+
applicationContext,
|
|
1540
|
+
customConfigFilename
|
|
1541
|
+
});
|
|
1542
|
+
const maybeConfigFromDefault = findConfig({
|
|
1543
|
+
dir: defaultPackage,
|
|
1544
|
+
customConfigFilename
|
|
1513
1545
|
});
|
|
1514
|
-
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1515
1546
|
if (maybeConfigFromDefault) {
|
|
1516
1547
|
return MicrofrontendsServer.fromFile({
|
|
1517
1548
|
filePath: maybeConfigFromDefault,
|