@vercel/microfrontends 1.0.1-canary.3 → 1.0.1-canary.4

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.
Files changed (38) hide show
  1. package/dist/bin/cli.cjs +113 -79
  2. package/dist/config.cjs +3 -0
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.js +3 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/experimental/sveltekit.cjs +79 -72
  7. package/dist/experimental/sveltekit.cjs.map +1 -1
  8. package/dist/experimental/sveltekit.js +79 -72
  9. package/dist/experimental/sveltekit.js.map +1 -1
  10. package/dist/experimental/vite.cjs +82 -75
  11. package/dist/experimental/vite.cjs.map +1 -1
  12. package/dist/experimental/vite.js +82 -75
  13. package/dist/experimental/vite.js.map +1 -1
  14. package/dist/microfrontends/server.cjs +79 -45
  15. package/dist/microfrontends/server.cjs.map +1 -1
  16. package/dist/microfrontends/server.js +79 -45
  17. package/dist/microfrontends/server.js.map +1 -1
  18. package/dist/microfrontends.cjs +3 -0
  19. package/dist/microfrontends.cjs.map +1 -1
  20. package/dist/microfrontends.js +3 -0
  21. package/dist/microfrontends.js.map +1 -1
  22. package/dist/next/config.cjs +79 -72
  23. package/dist/next/config.cjs.map +1 -1
  24. package/dist/next/config.js +79 -72
  25. package/dist/next/config.js.map +1 -1
  26. package/dist/next/middleware.cjs +3 -0
  27. package/dist/next/middleware.cjs.map +1 -1
  28. package/dist/next/middleware.js +3 -0
  29. package/dist/next/middleware.js.map +1 -1
  30. package/dist/next/testing.cjs +3 -0
  31. package/dist/next/testing.cjs.map +1 -1
  32. package/dist/next/testing.js +3 -0
  33. package/dist/next/testing.js.map +1 -1
  34. package/dist/utils/mfe-port.cjs +83 -49
  35. package/dist/utils/mfe-port.cjs.map +1 -1
  36. package/dist/utils/mfe-port.js +83 -49
  37. package/dist/utils/mfe-port.js.map +1 -1
  38. package/package.json +2 -2
@@ -44,8 +44,8 @@ function displayLocalProxyInfo(port) {
44
44
  }
45
45
 
46
46
  // src/config/microfrontends/server/index.ts
47
- var import_node_fs7 = __toESM(require("fs"), 1);
48
- var import_node_path8 = require("path");
47
+ var import_node_fs8 = __toESM(require("fs"), 1);
48
+ var import_node_path9 = require("path");
49
49
 
50
50
  // src/config/overrides/constants.ts
51
51
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -228,21 +228,21 @@ var MicrofrontendConfigClient = class {
228
228
  isEqual(other) {
229
229
  return JSON.stringify(this.applications) === JSON.stringify(other.applications);
230
230
  }
231
- getApplicationNameForPath(path5) {
232
- if (!path5.startsWith("/")) {
231
+ getApplicationNameForPath(path6) {
232
+ if (!path6.startsWith("/")) {
233
233
  throw new Error(`Path must start with a /`);
234
234
  }
235
- if (this.pathCache[path5]) {
236
- return this.pathCache[path5];
235
+ if (this.pathCache[path6]) {
236
+ return this.pathCache[path6];
237
237
  }
238
- const pathname = new URL(path5, "https://example.com").pathname;
238
+ const pathname = new URL(path6, "https://example.com").pathname;
239
239
  for (const [name, application] of Object.entries(this.applications)) {
240
240
  if (application.routing) {
241
241
  for (const group of application.routing) {
242
242
  for (const childPath of group.paths) {
243
243
  const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
244
244
  if (regexp.test(pathname)) {
245
- this.pathCache[path5] = name;
245
+ this.pathCache[path6] = name;
246
246
  return name;
247
247
  }
248
248
  }
@@ -255,7 +255,7 @@ var MicrofrontendConfigClient = class {
255
255
  if (!defaultApplication) {
256
256
  return null;
257
257
  }
258
- this.pathCache[path5] = defaultApplication[0];
258
+ this.pathCache[path6] = defaultApplication[0];
259
259
  return defaultApplication[0];
260
260
  }
261
261
  serialize() {
@@ -277,18 +277,18 @@ var validateConfigPaths = (applicationConfigsById) => {
277
277
  }
278
278
  const childApp = app;
279
279
  for (const pathMatch of childApp.routing) {
280
- for (const path5 of pathMatch.paths) {
281
- const maybeError = validatePathExpression(path5);
280
+ for (const path6 of pathMatch.paths) {
281
+ const maybeError = validatePathExpression(path6);
282
282
  if (maybeError) {
283
283
  errors.push(maybeError);
284
284
  } else {
285
- const existing = pathsByApplicationId.get(path5);
285
+ const existing = pathsByApplicationId.get(path6);
286
286
  if (existing) {
287
287
  existing.applications.push(id);
288
288
  } else {
289
- pathsByApplicationId.set(path5, {
289
+ pathsByApplicationId.set(path6, {
290
290
  applications: [id],
291
- matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
291
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
292
292
  applicationId: id
293
293
  });
294
294
  }
@@ -297,24 +297,24 @@ var validateConfigPaths = (applicationConfigsById) => {
297
297
  }
298
298
  }
299
299
  const entries = Array.from(pathsByApplicationId.entries());
300
- for (const [path5, { applications: ids, matcher, applicationId }] of entries) {
300
+ for (const [path6, { applications: ids, matcher, applicationId }] of entries) {
301
301
  if (ids.length > 1) {
302
302
  errors.push(
303
- `Duplicate path "${path5}" for applications "${ids.join(", ")}"`
303
+ `Duplicate path "${path6}" for applications "${ids.join(", ")}"`
304
304
  );
305
305
  }
306
306
  for (const [
307
307
  matchPath,
308
308
  { applications: matchIds, applicationId: matchApplicationId }
309
309
  ] of entries) {
310
- if (path5 === matchPath) {
310
+ if (path6 === matchPath) {
311
311
  continue;
312
312
  }
313
313
  if (applicationId === matchApplicationId) {
314
314
  continue;
315
315
  }
316
316
  if (matcher.test(matchPath)) {
317
- const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
317
+ const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
318
318
  const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
319
319
  errors.push(
320
320
  `Overlapping path detected between ${source} and ${destination}`
@@ -330,39 +330,42 @@ var validateConfigPaths = (applicationConfigsById) => {
330
330
  }
331
331
  };
332
332
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
333
- function validatePathExpression(path5) {
333
+ function validatePathExpression(path6) {
334
334
  try {
335
- const tokens = (0, import_path_to_regexp2.parse)(path5);
336
- if (/(?<!\\)\{/.test(path5)) {
337
- return `Optional paths are not supported: ${path5}`;
335
+ const tokens = (0, import_path_to_regexp2.parse)(path6);
336
+ if (/(?<!\\)\{/.test(path6)) {
337
+ return `Optional paths are not supported: ${path6}`;
338
338
  }
339
- if (/(?<!\\|\()\?/.test(path5)) {
340
- return `Optional paths are not supported: ${path5}`;
339
+ if (/(?<!\\|\()\?/.test(path6)) {
340
+ return `Optional paths are not supported: ${path6}`;
341
341
  }
342
- if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path5)) {
343
- return `Only one wildcard is allowed per path segment: ${path5}`;
342
+ if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path6)) {
343
+ return `Only one wildcard is allowed per path segment: ${path6}`;
344
344
  }
345
345
  for (let i = 0; i < tokens.length; i++) {
346
346
  const token = tokens[i];
347
347
  if (token === void 0) {
348
- return `token ${i} in ${path5} is undefined, this shouldn't happen`;
348
+ return `token ${i} in ${path6} is undefined, this shouldn't happen`;
349
349
  }
350
350
  if (typeof token !== "string") {
351
+ if (!token.name) {
352
+ return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
353
+ }
351
354
  if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
352
355
  // Only limited regex is supported for now, due to performance considerations
353
356
  !/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
354
357
  token.pattern
355
358
  )) {
356
- return `Path ${path5} cannot use unsupported regular expression wildcard`;
359
+ return `Path ${path6} cannot use unsupported regular expression wildcard`;
357
360
  }
358
361
  if (token.modifier && i !== tokens.length - 1) {
359
- return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
362
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
360
363
  }
361
364
  }
362
365
  }
363
366
  } catch (e) {
364
367
  const message = e instanceof Error ? e.message : String(e);
365
- return `Path ${path5} could not be parsed into regexp: ${message}`;
368
+ return `Path ${path6} could not be parsed into regexp: ${message}`;
366
369
  }
367
370
  return void 0;
368
371
  }
@@ -1074,6 +1077,9 @@ function isMonorepo({
1074
1077
  if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1075
1078
  return true;
1076
1079
  }
1080
+ if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1081
+ return true;
1082
+ }
1077
1083
  const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1078
1084
  if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1079
1085
  return false;
@@ -1119,8 +1125,42 @@ function findConfig({ dir }) {
1119
1125
  return null;
1120
1126
  }
1121
1127
 
1122
- // src/config/microfrontends/server/utils/get-output-file-path.ts
1128
+ // src/config/microfrontends/utils/get-application-context.ts
1129
+ var import_node_fs7 = __toESM(require("fs"), 1);
1123
1130
  var import_node_path7 = __toESM(require("path"), 1);
1131
+ function getApplicationContext(opts) {
1132
+ if (opts?.appName) {
1133
+ return { name: opts.appName };
1134
+ }
1135
+ if (process.env.NX_TASK_TARGET_PROJECT) {
1136
+ return { name: process.env.NX_TASK_TARGET_PROJECT };
1137
+ }
1138
+ try {
1139
+ const packageJsonString = import_node_fs7.default.readFileSync(
1140
+ import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
1141
+ "utf-8"
1142
+ );
1143
+ const packageJson = JSON.parse(packageJsonString);
1144
+ if (!packageJson.name) {
1145
+ throw new MicrofrontendError(
1146
+ `package.json file missing required field "name"`,
1147
+ {
1148
+ type: "packageJson",
1149
+ subtype: "missing_field_name",
1150
+ source: "@vercel/microfrontends/next"
1151
+ }
1152
+ );
1153
+ }
1154
+ return { name: packageJson.name };
1155
+ } catch (err) {
1156
+ throw MicrofrontendError.handle(err, {
1157
+ fileName: "package.json"
1158
+ });
1159
+ }
1160
+ }
1161
+
1162
+ // src/config/microfrontends/server/utils/get-output-file-path.ts
1163
+ var import_node_path8 = __toESM(require("path"), 1);
1124
1164
 
1125
1165
  // src/config/microfrontends/server/constants.ts
1126
1166
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1128,7 +1168,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1128
1168
 
1129
1169
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1130
1170
  function getOutputFilePath() {
1131
- return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1171
+ return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1132
1172
  }
1133
1173
 
1134
1174
  // src/config/microfrontends/server/validation.ts
@@ -1467,8 +1507,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1467
1507
  pretty: true
1468
1508
  }) {
1469
1509
  const outputPath = getOutputFilePath();
1470
- import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
1471
- import_node_fs7.default.writeFileSync(
1510
+ import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
1511
+ import_node_fs8.default.writeFileSync(
1472
1512
  outputPath,
1473
1513
  JSON.stringify(
1474
1514
  this.config.toSchemaJson(),
@@ -1554,14 +1594,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1554
1594
  }
1555
1595
  try {
1556
1596
  const packageRoot = findPackageRoot(directory);
1557
- const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
1558
- const packageJson = JSON.parse(
1559
- import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
1560
- );
1561
- if (!packageJson.name) {
1562
- throw new Error(`No name found in package.json at ${packageJsonPath}`);
1563
- }
1564
- const configMeta = meta ?? { fromApp: packageJson.name };
1597
+ const { name: appName } = getApplicationContext({ packageRoot });
1598
+ const configMeta = meta ?? { fromApp: appName };
1565
1599
  const maybeConfig = findConfig({ dir: packageRoot });
1566
1600
  if (maybeConfig) {
1567
1601
  return MicrofrontendsServer.fromFile({
@@ -1576,7 +1610,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1576
1610
  if (isMonorepo2) {
1577
1611
  const defaultPackage = findDefaultMicrofrontendsPackage({
1578
1612
  repositoryRoot,
1579
- applicationName: packageJson.name
1613
+ applicationName: appName
1580
1614
  });
1581
1615
  const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1582
1616
  if (maybeConfigFromDefault) {
@@ -1606,7 +1640,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1606
1640
  options
1607
1641
  }) {
1608
1642
  try {
1609
- const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1643
+ const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1610
1644
  const config = MicrofrontendsServer.validate(configJson);
1611
1645
  if (!isMainConfig(config) && options?.resolveMainConfig) {
1612
1646
  const repositoryRoot = findRepositoryRoot();
@@ -1654,7 +1688,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1654
1688
  overrides
1655
1689
  }) {
1656
1690
  try {
1657
- const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1691
+ const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1658
1692
  const validatedConfig = MicrofrontendsServer.validate(config);
1659
1693
  if (!isMainConfig(validatedConfig)) {
1660
1694
  throw new MicrofrontendError(
@@ -1685,33 +1719,6 @@ var MicrofrontendsServer = class extends Microfrontends {
1685
1719
  }
1686
1720
  };
1687
1721
 
1688
- // src/config/microfrontends/utils/get-application-context.ts
1689
- var import_node_fs8 = __toESM(require("fs"), 1);
1690
- function getApplicationContext(opts) {
1691
- if (opts?.appName) {
1692
- return { name: opts.appName };
1693
- }
1694
- try {
1695
- const packageJsonString = import_node_fs8.default.readFileSync("./package.json", "utf-8");
1696
- const packageJson = JSON.parse(packageJsonString);
1697
- if (!packageJson.name) {
1698
- throw new MicrofrontendError(
1699
- `package.json file missing required field "name"`,
1700
- {
1701
- type: "packageJson",
1702
- subtype: "missing_field_name",
1703
- source: "@vercel/microfrontends/next"
1704
- }
1705
- );
1706
- }
1707
- return { name: packageJson.name };
1708
- } catch (err) {
1709
- throw MicrofrontendError.handle(err, {
1710
- fileName: "package.json"
1711
- });
1712
- }
1713
- }
1714
-
1715
1722
  // src/sveltekit/config/index.ts
1716
1723
  function withMicrofrontends(config, opts) {
1717
1724
  const { name: fromApp } = getApplicationContext(opts);