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

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 +116 -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 +82 -72
  7. package/dist/experimental/sveltekit.cjs.map +1 -1
  8. package/dist/experimental/sveltekit.js +82 -72
  9. package/dist/experimental/sveltekit.js.map +1 -1
  10. package/dist/experimental/vite.cjs +85 -75
  11. package/dist/experimental/vite.cjs.map +1 -1
  12. package/dist/experimental/vite.js +85 -75
  13. package/dist/experimental/vite.js.map +1 -1
  14. package/dist/microfrontends/server.cjs +82 -45
  15. package/dist/microfrontends/server.cjs.map +1 -1
  16. package/dist/microfrontends/server.js +82 -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 +82 -72
  23. package/dist/next/config.cjs.map +1 -1
  24. package/dist/next/config.js +82 -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 +86 -49
  35. package/dist/utils/mfe-port.cjs.map +1 -1
  36. package/dist/utils/mfe-port.js +86 -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
  }
@@ -917,6 +920,9 @@ var import_node_fs = __toESM(require("fs"), 1);
917
920
  var import_node_path = __toESM(require("path"), 1);
918
921
  var GIT_DIRECTORY = ".git";
919
922
  function findRepositoryRoot(startDir) {
923
+ if (process.env.NX_WORKSPACE_ROOT) {
924
+ return process.env.NX_WORKSPACE_ROOT;
925
+ }
920
926
  let currentDir = startDir || process.cwd();
921
927
  while (currentDir !== import_node_path.default.parse(currentDir).root) {
922
928
  const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
@@ -1074,6 +1080,9 @@ function isMonorepo({
1074
1080
  if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1075
1081
  return true;
1076
1082
  }
1083
+ if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1084
+ return true;
1085
+ }
1077
1086
  const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1078
1087
  if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1079
1088
  return false;
@@ -1119,8 +1128,42 @@ function findConfig({ dir }) {
1119
1128
  return null;
1120
1129
  }
1121
1130
 
1122
- // src/config/microfrontends/server/utils/get-output-file-path.ts
1131
+ // src/config/microfrontends/utils/get-application-context.ts
1132
+ var import_node_fs7 = __toESM(require("fs"), 1);
1123
1133
  var import_node_path7 = __toESM(require("path"), 1);
1134
+ function getApplicationContext(opts) {
1135
+ if (opts?.appName) {
1136
+ return { name: opts.appName };
1137
+ }
1138
+ if (process.env.NX_TASK_TARGET_PROJECT) {
1139
+ return { name: process.env.NX_TASK_TARGET_PROJECT };
1140
+ }
1141
+ try {
1142
+ const packageJsonString = import_node_fs7.default.readFileSync(
1143
+ import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
1144
+ "utf-8"
1145
+ );
1146
+ const packageJson = JSON.parse(packageJsonString);
1147
+ if (!packageJson.name) {
1148
+ throw new MicrofrontendError(
1149
+ `package.json file missing required field "name"`,
1150
+ {
1151
+ type: "packageJson",
1152
+ subtype: "missing_field_name",
1153
+ source: "@vercel/microfrontends/next"
1154
+ }
1155
+ );
1156
+ }
1157
+ return { name: packageJson.name };
1158
+ } catch (err) {
1159
+ throw MicrofrontendError.handle(err, {
1160
+ fileName: "package.json"
1161
+ });
1162
+ }
1163
+ }
1164
+
1165
+ // src/config/microfrontends/server/utils/get-output-file-path.ts
1166
+ var import_node_path8 = __toESM(require("path"), 1);
1124
1167
 
1125
1168
  // src/config/microfrontends/server/constants.ts
1126
1169
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1128,7 +1171,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1128
1171
 
1129
1172
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1130
1173
  function getOutputFilePath() {
1131
- return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1174
+ return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1132
1175
  }
1133
1176
 
1134
1177
  // src/config/microfrontends/server/validation.ts
@@ -1467,8 +1510,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1467
1510
  pretty: true
1468
1511
  }) {
1469
1512
  const outputPath = getOutputFilePath();
1470
- import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
1471
- import_node_fs7.default.writeFileSync(
1513
+ import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
1514
+ import_node_fs8.default.writeFileSync(
1472
1515
  outputPath,
1473
1516
  JSON.stringify(
1474
1517
  this.config.toSchemaJson(),
@@ -1554,14 +1597,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1554
1597
  }
1555
1598
  try {
1556
1599
  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 };
1600
+ const { name: appName } = getApplicationContext({ packageRoot });
1601
+ const configMeta = meta ?? { fromApp: appName };
1565
1602
  const maybeConfig = findConfig({ dir: packageRoot });
1566
1603
  if (maybeConfig) {
1567
1604
  return MicrofrontendsServer.fromFile({
@@ -1576,7 +1613,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1576
1613
  if (isMonorepo2) {
1577
1614
  const defaultPackage = findDefaultMicrofrontendsPackage({
1578
1615
  repositoryRoot,
1579
- applicationName: packageJson.name
1616
+ applicationName: appName
1580
1617
  });
1581
1618
  const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1582
1619
  if (maybeConfigFromDefault) {
@@ -1606,7 +1643,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1606
1643
  options
1607
1644
  }) {
1608
1645
  try {
1609
- const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1646
+ const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1610
1647
  const config = MicrofrontendsServer.validate(configJson);
1611
1648
  if (!isMainConfig(config) && options?.resolveMainConfig) {
1612
1649
  const repositoryRoot = findRepositoryRoot();
@@ -1654,7 +1691,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1654
1691
  overrides
1655
1692
  }) {
1656
1693
  try {
1657
- const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1694
+ const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1658
1695
  const validatedConfig = MicrofrontendsServer.validate(config);
1659
1696
  if (!isMainConfig(validatedConfig)) {
1660
1697
  throw new MicrofrontendError(
@@ -1685,33 +1722,6 @@ var MicrofrontendsServer = class extends Microfrontends {
1685
1722
  }
1686
1723
  };
1687
1724
 
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
1725
  // src/sveltekit/config/index.ts
1716
1726
  function withMicrofrontends(config, opts) {
1717
1727
  const { name: fromApp } = getApplicationContext(opts);