@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
|
@@ -232,22 +232,38 @@ var import_node_fs2 = require("fs");
|
|
|
232
232
|
var import_jsonc_parser = require("jsonc-parser");
|
|
233
233
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
234
234
|
|
|
235
|
-
// src/config/
|
|
236
|
-
var
|
|
235
|
+
// src/config/microfrontends/utils/get-config-file-name.ts
|
|
236
|
+
var DEFAULT_CONFIGURATION_FILENAMES = [
|
|
237
237
|
"microfrontends.jsonc",
|
|
238
238
|
"microfrontends.json"
|
|
239
239
|
];
|
|
240
|
+
function getPossibleConfigurationFilenames({
|
|
241
|
+
customConfigFilename
|
|
242
|
+
}) {
|
|
243
|
+
if (customConfigFilename) {
|
|
244
|
+
if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
`The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return Array.from(
|
|
250
|
+
/* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return DEFAULT_CONFIGURATION_FILENAMES;
|
|
254
|
+
}
|
|
240
255
|
|
|
241
256
|
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
242
257
|
var configCache = {};
|
|
243
258
|
function findPackageWithMicrofrontendsConfig({
|
|
244
259
|
repositoryRoot,
|
|
245
|
-
applicationContext
|
|
260
|
+
applicationContext,
|
|
261
|
+
customConfigFilename
|
|
246
262
|
}) {
|
|
247
263
|
const applicationName = applicationContext.name;
|
|
248
264
|
try {
|
|
249
265
|
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
250
|
-
`**/{${
|
|
266
|
+
`**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
|
|
251
267
|
{
|
|
252
268
|
cwd: repositoryRoot,
|
|
253
269
|
absolute: true,
|
|
@@ -303,6 +319,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
|
|
|
303
319
|
|
|
304
320
|
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.
|
|
305
321
|
|
|
322
|
+
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.
|
|
323
|
+
|
|
306
324
|
If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
307
325
|
{ type: "config", subtype: "inference_failed" }
|
|
308
326
|
);
|
|
@@ -317,7 +335,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
|
|
|
317
335
|
}
|
|
318
336
|
}
|
|
319
337
|
function inferMicrofrontendsLocation(opts) {
|
|
320
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
|
|
338
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
|
|
321
339
|
if (configCache[cacheKey]) {
|
|
322
340
|
return configCache[cacheKey];
|
|
323
341
|
}
|
|
@@ -383,8 +401,13 @@ function findPackageRoot(startDir) {
|
|
|
383
401
|
// src/config/microfrontends/utils/find-config.ts
|
|
384
402
|
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
385
403
|
var import_node_path5 = require("path");
|
|
386
|
-
function findConfig({
|
|
387
|
-
|
|
404
|
+
function findConfig({
|
|
405
|
+
dir,
|
|
406
|
+
customConfigFilename
|
|
407
|
+
}) {
|
|
408
|
+
for (const filename of getPossibleConfigurationFilenames({
|
|
409
|
+
customConfigFilename
|
|
410
|
+
})) {
|
|
388
411
|
const maybeConfig = (0, import_node_path5.join)(dir, filename);
|
|
389
412
|
if (import_node_fs5.default.existsSync(maybeConfig)) {
|
|
390
413
|
return maybeConfig;
|
|
@@ -451,7 +474,7 @@ var MicrofrontendConfigClient = class {
|
|
|
451
474
|
static fromEnv(config) {
|
|
452
475
|
if (!config) {
|
|
453
476
|
throw new Error(
|
|
454
|
-
"Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
|
|
477
|
+
"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"
|
|
455
478
|
);
|
|
456
479
|
}
|
|
457
480
|
return new MicrofrontendConfigClient(JSON.parse(config));
|
|
@@ -591,10 +614,11 @@ function validatePathExpression(path6) {
|
|
|
591
614
|
}
|
|
592
615
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
593
616
|
// Only limited regex is supported for now, due to performance considerations
|
|
594
|
-
|
|
595
|
-
|
|
617
|
+
// Allows all letters, numbers, and hyphens. Other characters must be escaped.
|
|
618
|
+
!/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
|
|
619
|
+
token.pattern.replace(/\\./g, "")
|
|
596
620
|
)) {
|
|
597
|
-
return `Path ${path6} cannot use unsupported regular expression wildcard`;
|
|
621
|
+
return `Path ${path6} cannot use unsupported regular expression wildcard. If the path includes special characters, they must be escaped with backslash (e.g. '\\(')`;
|
|
598
622
|
}
|
|
599
623
|
if (token.modifier && i !== tokens.length - 1) {
|
|
600
624
|
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
@@ -1486,7 +1510,11 @@ var MicrofrontendsServer = class {
|
|
|
1486
1510
|
appName,
|
|
1487
1511
|
packageRoot
|
|
1488
1512
|
});
|
|
1489
|
-
const
|
|
1513
|
+
const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
|
|
1514
|
+
const maybeConfig = findConfig({
|
|
1515
|
+
dir: packageRoot,
|
|
1516
|
+
customConfigFilename
|
|
1517
|
+
});
|
|
1490
1518
|
if (maybeConfig) {
|
|
1491
1519
|
return MicrofrontendsServer.fromFile({
|
|
1492
1520
|
filePath: maybeConfig,
|
|
@@ -1495,11 +1523,9 @@ var MicrofrontendsServer = class {
|
|
|
1495
1523
|
}
|
|
1496
1524
|
const repositoryRoot = findRepositoryRoot();
|
|
1497
1525
|
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
process.env.VC_MICROFRONTENDS_CONFIG
|
|
1502
|
-
);
|
|
1526
|
+
const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
|
|
1527
|
+
if (typeof configFromEnv === "string") {
|
|
1528
|
+
const maybeConfigFromEnv = (0, import_node_path8.resolve)(packageRoot, configFromEnv);
|
|
1503
1529
|
if (maybeConfigFromEnv) {
|
|
1504
1530
|
return MicrofrontendsServer.fromFile({
|
|
1505
1531
|
filePath: maybeConfigFromEnv,
|
|
@@ -1508,7 +1534,8 @@ var MicrofrontendsServer = class {
|
|
|
1508
1534
|
}
|
|
1509
1535
|
} else {
|
|
1510
1536
|
const maybeConfigFromVercel = findConfig({
|
|
1511
|
-
dir: (0, import_node_path8.join)(packageRoot, ".vercel")
|
|
1537
|
+
dir: (0, import_node_path8.join)(packageRoot, ".vercel"),
|
|
1538
|
+
customConfigFilename
|
|
1512
1539
|
});
|
|
1513
1540
|
if (maybeConfigFromVercel) {
|
|
1514
1541
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1519,9 +1546,13 @@ var MicrofrontendsServer = class {
|
|
|
1519
1546
|
if (isMonorepo2) {
|
|
1520
1547
|
const defaultPackage = inferMicrofrontendsLocation({
|
|
1521
1548
|
repositoryRoot,
|
|
1522
|
-
applicationContext
|
|
1549
|
+
applicationContext,
|
|
1550
|
+
customConfigFilename
|
|
1551
|
+
});
|
|
1552
|
+
const maybeConfigFromDefault = findConfig({
|
|
1553
|
+
dir: defaultPackage,
|
|
1554
|
+
customConfigFilename
|
|
1523
1555
|
});
|
|
1524
|
-
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1525
1556
|
if (maybeConfigFromDefault) {
|
|
1526
1557
|
return MicrofrontendsServer.fromFile({
|
|
1527
1558
|
filePath: maybeConfigFromDefault,
|