@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
@@ -35,8 +35,8 @@ __export(vite_exports, {
35
35
  module.exports = __toCommonJS(vite_exports);
36
36
 
37
37
  // src/config/microfrontends/server/index.ts
38
- var import_node_fs7 = __toESM(require("fs"), 1);
39
- var import_node_path8 = require("path");
38
+ var import_node_fs8 = __toESM(require("fs"), 1);
39
+ var import_node_path9 = require("path");
40
40
 
41
41
  // src/config/overrides/constants.ts
42
42
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -219,21 +219,21 @@ var MicrofrontendConfigClient = class {
219
219
  isEqual(other) {
220
220
  return JSON.stringify(this.applications) === JSON.stringify(other.applications);
221
221
  }
222
- getApplicationNameForPath(path5) {
223
- if (!path5.startsWith("/")) {
222
+ getApplicationNameForPath(path6) {
223
+ if (!path6.startsWith("/")) {
224
224
  throw new Error(`Path must start with a /`);
225
225
  }
226
- if (this.pathCache[path5]) {
227
- return this.pathCache[path5];
226
+ if (this.pathCache[path6]) {
227
+ return this.pathCache[path6];
228
228
  }
229
- const pathname = new URL(path5, "https://example.com").pathname;
229
+ const pathname = new URL(path6, "https://example.com").pathname;
230
230
  for (const [name, application] of Object.entries(this.applications)) {
231
231
  if (application.routing) {
232
232
  for (const group of application.routing) {
233
233
  for (const childPath of group.paths) {
234
234
  const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
235
235
  if (regexp.test(pathname)) {
236
- this.pathCache[path5] = name;
236
+ this.pathCache[path6] = name;
237
237
  return name;
238
238
  }
239
239
  }
@@ -246,7 +246,7 @@ var MicrofrontendConfigClient = class {
246
246
  if (!defaultApplication) {
247
247
  return null;
248
248
  }
249
- this.pathCache[path5] = defaultApplication[0];
249
+ this.pathCache[path6] = defaultApplication[0];
250
250
  return defaultApplication[0];
251
251
  }
252
252
  serialize() {
@@ -268,18 +268,18 @@ var validateConfigPaths = (applicationConfigsById) => {
268
268
  }
269
269
  const childApp = app;
270
270
  for (const pathMatch of childApp.routing) {
271
- for (const path5 of pathMatch.paths) {
272
- const maybeError = validatePathExpression(path5);
271
+ for (const path6 of pathMatch.paths) {
272
+ const maybeError = validatePathExpression(path6);
273
273
  if (maybeError) {
274
274
  errors.push(maybeError);
275
275
  } else {
276
- const existing = pathsByApplicationId.get(path5);
276
+ const existing = pathsByApplicationId.get(path6);
277
277
  if (existing) {
278
278
  existing.applications.push(id);
279
279
  } else {
280
- pathsByApplicationId.set(path5, {
280
+ pathsByApplicationId.set(path6, {
281
281
  applications: [id],
282
- matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
282
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
283
283
  applicationId: id
284
284
  });
285
285
  }
@@ -288,24 +288,24 @@ var validateConfigPaths = (applicationConfigsById) => {
288
288
  }
289
289
  }
290
290
  const entries = Array.from(pathsByApplicationId.entries());
291
- for (const [path5, { applications: ids, matcher, applicationId }] of entries) {
291
+ for (const [path6, { applications: ids, matcher, applicationId }] of entries) {
292
292
  if (ids.length > 1) {
293
293
  errors.push(
294
- `Duplicate path "${path5}" for applications "${ids.join(", ")}"`
294
+ `Duplicate path "${path6}" for applications "${ids.join(", ")}"`
295
295
  );
296
296
  }
297
297
  for (const [
298
298
  matchPath,
299
299
  { applications: matchIds, applicationId: matchApplicationId }
300
300
  ] of entries) {
301
- if (path5 === matchPath) {
301
+ if (path6 === matchPath) {
302
302
  continue;
303
303
  }
304
304
  if (applicationId === matchApplicationId) {
305
305
  continue;
306
306
  }
307
307
  if (matcher.test(matchPath)) {
308
- const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
308
+ const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
309
309
  const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
310
310
  errors.push(
311
311
  `Overlapping path detected between ${source} and ${destination}`
@@ -321,39 +321,42 @@ var validateConfigPaths = (applicationConfigsById) => {
321
321
  }
322
322
  };
323
323
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
324
- function validatePathExpression(path5) {
324
+ function validatePathExpression(path6) {
325
325
  try {
326
- const tokens = (0, import_path_to_regexp2.parse)(path5);
327
- if (/(?<!\\)\{/.test(path5)) {
328
- return `Optional paths are not supported: ${path5}`;
326
+ const tokens = (0, import_path_to_regexp2.parse)(path6);
327
+ if (/(?<!\\)\{/.test(path6)) {
328
+ return `Optional paths are not supported: ${path6}`;
329
329
  }
330
- if (/(?<!\\|\()\?/.test(path5)) {
331
- return `Optional paths are not supported: ${path5}`;
330
+ if (/(?<!\\|\()\?/.test(path6)) {
331
+ return `Optional paths are not supported: ${path6}`;
332
332
  }
333
- if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path5)) {
334
- return `Only one wildcard is allowed per path segment: ${path5}`;
333
+ if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path6)) {
334
+ return `Only one wildcard is allowed per path segment: ${path6}`;
335
335
  }
336
336
  for (let i = 0; i < tokens.length; i++) {
337
337
  const token = tokens[i];
338
338
  if (token === void 0) {
339
- return `token ${i} in ${path5} is undefined, this shouldn't happen`;
339
+ return `token ${i} in ${path6} is undefined, this shouldn't happen`;
340
340
  }
341
341
  if (typeof token !== "string") {
342
+ if (!token.name) {
343
+ return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
344
+ }
342
345
  if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
343
346
  // Only limited regex is supported for now, due to performance considerations
344
347
  !/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
345
348
  token.pattern
346
349
  )) {
347
- return `Path ${path5} cannot use unsupported regular expression wildcard`;
350
+ return `Path ${path6} cannot use unsupported regular expression wildcard`;
348
351
  }
349
352
  if (token.modifier && i !== tokens.length - 1) {
350
- return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
353
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
351
354
  }
352
355
  }
353
356
  }
354
357
  } catch (e) {
355
358
  const message = e instanceof Error ? e.message : String(e);
356
- return `Path ${path5} could not be parsed into regexp: ${message}`;
359
+ return `Path ${path6} could not be parsed into regexp: ${message}`;
357
360
  }
358
361
  return void 0;
359
362
  }
@@ -1065,6 +1068,9 @@ function isMonorepo({
1065
1068
  if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1066
1069
  return true;
1067
1070
  }
1071
+ if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1072
+ return true;
1073
+ }
1068
1074
  const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1069
1075
  if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1070
1076
  return false;
@@ -1110,8 +1116,42 @@ function findConfig({ dir }) {
1110
1116
  return null;
1111
1117
  }
1112
1118
 
1113
- // src/config/microfrontends/server/utils/get-output-file-path.ts
1119
+ // src/config/microfrontends/utils/get-application-context.ts
1120
+ var import_node_fs7 = __toESM(require("fs"), 1);
1114
1121
  var import_node_path7 = __toESM(require("path"), 1);
1122
+ function getApplicationContext(opts) {
1123
+ if (opts?.appName) {
1124
+ return { name: opts.appName };
1125
+ }
1126
+ if (process.env.NX_TASK_TARGET_PROJECT) {
1127
+ return { name: process.env.NX_TASK_TARGET_PROJECT };
1128
+ }
1129
+ try {
1130
+ const packageJsonString = import_node_fs7.default.readFileSync(
1131
+ import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
1132
+ "utf-8"
1133
+ );
1134
+ const packageJson = JSON.parse(packageJsonString);
1135
+ if (!packageJson.name) {
1136
+ throw new MicrofrontendError(
1137
+ `package.json file missing required field "name"`,
1138
+ {
1139
+ type: "packageJson",
1140
+ subtype: "missing_field_name",
1141
+ source: "@vercel/microfrontends/next"
1142
+ }
1143
+ );
1144
+ }
1145
+ return { name: packageJson.name };
1146
+ } catch (err) {
1147
+ throw MicrofrontendError.handle(err, {
1148
+ fileName: "package.json"
1149
+ });
1150
+ }
1151
+ }
1152
+
1153
+ // src/config/microfrontends/server/utils/get-output-file-path.ts
1154
+ var import_node_path8 = __toESM(require("path"), 1);
1115
1155
 
1116
1156
  // src/config/microfrontends/server/constants.ts
1117
1157
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1119,7 +1159,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1119
1159
 
1120
1160
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1121
1161
  function getOutputFilePath() {
1122
- return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1162
+ return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1123
1163
  }
1124
1164
 
1125
1165
  // src/config/microfrontends/server/validation.ts
@@ -1458,8 +1498,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1458
1498
  pretty: true
1459
1499
  }) {
1460
1500
  const outputPath = getOutputFilePath();
1461
- import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
1462
- import_node_fs7.default.writeFileSync(
1501
+ import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
1502
+ import_node_fs8.default.writeFileSync(
1463
1503
  outputPath,
1464
1504
  JSON.stringify(
1465
1505
  this.config.toSchemaJson(),
@@ -1545,14 +1585,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1545
1585
  }
1546
1586
  try {
1547
1587
  const packageRoot = findPackageRoot(directory);
1548
- const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
1549
- const packageJson = JSON.parse(
1550
- import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
1551
- );
1552
- if (!packageJson.name) {
1553
- throw new Error(`No name found in package.json at ${packageJsonPath}`);
1554
- }
1555
- const configMeta = meta ?? { fromApp: packageJson.name };
1588
+ const { name: appName } = getApplicationContext({ packageRoot });
1589
+ const configMeta = meta ?? { fromApp: appName };
1556
1590
  const maybeConfig = findConfig({ dir: packageRoot });
1557
1591
  if (maybeConfig) {
1558
1592
  return MicrofrontendsServer.fromFile({
@@ -1567,7 +1601,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1567
1601
  if (isMonorepo2) {
1568
1602
  const defaultPackage = findDefaultMicrofrontendsPackage({
1569
1603
  repositoryRoot,
1570
- applicationName: packageJson.name
1604
+ applicationName: appName
1571
1605
  });
1572
1606
  const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1573
1607
  if (maybeConfigFromDefault) {
@@ -1597,7 +1631,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1597
1631
  options
1598
1632
  }) {
1599
1633
  try {
1600
- const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1634
+ const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1601
1635
  const config = MicrofrontendsServer.validate(configJson);
1602
1636
  if (!isMainConfig(config) && options?.resolveMainConfig) {
1603
1637
  const repositoryRoot = findRepositoryRoot();
@@ -1645,7 +1679,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1645
1679
  overrides
1646
1680
  }) {
1647
1681
  try {
1648
- const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1682
+ const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1649
1683
  const validatedConfig = MicrofrontendsServer.validate(config);
1650
1684
  if (!isMainConfig(validatedConfig)) {
1651
1685
  throw new MicrofrontendError(
@@ -1676,42 +1710,15 @@ var MicrofrontendsServer = class extends Microfrontends {
1676
1710
  }
1677
1711
  };
1678
1712
 
1679
- // src/config/microfrontends/utils/get-application-context.ts
1680
- var import_node_fs8 = __toESM(require("fs"), 1);
1681
- function getApplicationContext(opts) {
1682
- if (opts?.appName) {
1683
- return { name: opts.appName };
1684
- }
1685
- try {
1686
- const packageJsonString = import_node_fs8.default.readFileSync("./package.json", "utf-8");
1687
- const packageJson = JSON.parse(packageJsonString);
1688
- if (!packageJson.name) {
1689
- throw new MicrofrontendError(
1690
- `package.json file missing required field "name"`,
1691
- {
1692
- type: "packageJson",
1693
- subtype: "missing_field_name",
1694
- source: "@vercel/microfrontends/next"
1695
- }
1696
- );
1697
- }
1698
- return { name: packageJson.name };
1699
- } catch (err) {
1700
- throw MicrofrontendError.handle(err, {
1701
- fileName: "package.json"
1702
- });
1703
- }
1704
- }
1705
-
1706
1713
  // src/vite/detect-framework.ts
1707
1714
  var import_node_fs9 = require("fs");
1708
- var import_node_path9 = require("path");
1715
+ var import_node_path10 = require("path");
1709
1716
  var import_node_process = require("process");
1710
1717
  function detectFramework() {
1711
- if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "svelte.config.js"))) {
1718
+ if ((0, import_node_fs9.existsSync)((0, import_node_path10.join)((0, import_node_process.cwd)(), "svelte.config.js"))) {
1712
1719
  return "sveltekit";
1713
1720
  }
1714
- if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.js")) || (0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.ts"))) {
1721
+ if ((0, import_node_fs9.existsSync)((0, import_node_path10.join)((0, import_node_process.cwd)(), "react-router.config.js")) || (0, import_node_fs9.existsSync)((0, import_node_path10.join)((0, import_node_process.cwd)(), "react-router.config.ts"))) {
1715
1722
  return "react-router";
1716
1723
  }
1717
1724
  return "unknown";