@vercel/microfrontends 1.0.1-canary.2 → 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 (44) hide show
  1. package/dist/bin/cli.cjs +115 -85
  2. package/dist/config.cjs +5 -6
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +1 -1
  5. package/dist/config.js +5 -6
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +81 -78
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +81 -78
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +124 -88
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.d.ts +1 -1
  14. package/dist/experimental/vite.js +124 -90
  15. package/dist/experimental/vite.js.map +1 -1
  16. package/dist/{index-d5994ac5.d.ts → index-2b59c627.d.ts} +1 -1
  17. package/dist/microfrontends/server.cjs +81 -51
  18. package/dist/microfrontends/server.cjs.map +1 -1
  19. package/dist/microfrontends/server.d.ts +1 -1
  20. package/dist/microfrontends/server.js +81 -51
  21. package/dist/microfrontends/server.js.map +1 -1
  22. package/dist/microfrontends.cjs +5 -6
  23. package/dist/microfrontends.cjs.map +1 -1
  24. package/dist/microfrontends.d.ts +1 -1
  25. package/dist/microfrontends.js +5 -6
  26. package/dist/microfrontends.js.map +1 -1
  27. package/dist/next/config.cjs +81 -78
  28. package/dist/next/config.cjs.map +1 -1
  29. package/dist/next/config.js +81 -78
  30. package/dist/next/config.js.map +1 -1
  31. package/dist/next/middleware.cjs +5 -6
  32. package/dist/next/middleware.cjs.map +1 -1
  33. package/dist/next/middleware.js +5 -6
  34. package/dist/next/middleware.js.map +1 -1
  35. package/dist/next/testing.cjs +5 -6
  36. package/dist/next/testing.cjs.map +1 -1
  37. package/dist/next/testing.d.ts +1 -1
  38. package/dist/next/testing.js +5 -6
  39. package/dist/next/testing.js.map +1 -1
  40. package/dist/utils/mfe-port.cjs +85 -55
  41. package/dist/utils/mfe-port.cjs.map +1 -1
  42. package/dist/utils/mfe-port.js +85 -55
  43. package/dist/utils/mfe-port.js.map +1 -1
  44. 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
  }
@@ -716,12 +719,8 @@ var MicrofrontendConfigIsomorphic = class {
716
719
  const skipValidation = opts?.skipValidation ?? [];
717
720
  const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
718
721
  if (isMainConfig(c)) {
719
- if (!skipValidation.includes("paths")) {
720
- validateConfigPaths(c.applications);
721
- }
722
- if (!skipValidation.includes("defaultApplication")) {
723
- validateConfigDefaultApplication(c.applications);
724
- }
722
+ validateConfigPaths(c.applications);
723
+ validateConfigDefaultApplication(c.applications);
725
724
  if (!skipValidation.includes("deprecatedFields")) {
726
725
  validateDeprecatedFields(c);
727
726
  }
@@ -1078,6 +1077,9 @@ function isMonorepo({
1078
1077
  if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1079
1078
  return true;
1080
1079
  }
1080
+ if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1081
+ return true;
1082
+ }
1081
1083
  const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1082
1084
  if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1083
1085
  return false;
@@ -1123,8 +1125,42 @@ function findConfig({ dir }) {
1123
1125
  return null;
1124
1126
  }
1125
1127
 
1126
- // 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);
1127
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);
1128
1164
 
1129
1165
  // src/config/microfrontends/server/constants.ts
1130
1166
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1132,7 +1168,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1132
1168
 
1133
1169
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1134
1170
  function getOutputFilePath() {
1135
- 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);
1136
1172
  }
1137
1173
 
1138
1174
  // src/config/microfrontends/server/validation.ts
@@ -1471,8 +1507,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1471
1507
  pretty: true
1472
1508
  }) {
1473
1509
  const outputPath = getOutputFilePath();
1474
- import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
1475
- 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(
1476
1512
  outputPath,
1477
1513
  JSON.stringify(
1478
1514
  this.config.toSchemaJson(),
@@ -1558,14 +1594,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1558
1594
  }
1559
1595
  try {
1560
1596
  const packageRoot = findPackageRoot(directory);
1561
- const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
1562
- const packageJson = JSON.parse(
1563
- import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
1564
- );
1565
- if (!packageJson.name) {
1566
- throw new Error(`No name found in package.json at ${packageJsonPath}`);
1567
- }
1568
- const configMeta = meta ?? { fromApp: packageJson.name };
1597
+ const { name: appName } = getApplicationContext({ packageRoot });
1598
+ const configMeta = meta ?? { fromApp: appName };
1569
1599
  const maybeConfig = findConfig({ dir: packageRoot });
1570
1600
  if (maybeConfig) {
1571
1601
  return MicrofrontendsServer.fromFile({
@@ -1580,7 +1610,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1580
1610
  if (isMonorepo2) {
1581
1611
  const defaultPackage = findDefaultMicrofrontendsPackage({
1582
1612
  repositoryRoot,
1583
- applicationName: packageJson.name
1613
+ applicationName: appName
1584
1614
  });
1585
1615
  const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1586
1616
  if (maybeConfigFromDefault) {
@@ -1610,7 +1640,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1610
1640
  options
1611
1641
  }) {
1612
1642
  try {
1613
- const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1643
+ const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1614
1644
  const config = MicrofrontendsServer.validate(configJson);
1615
1645
  if (!isMainConfig(config) && options?.resolveMainConfig) {
1616
1646
  const repositoryRoot = findRepositoryRoot();
@@ -1658,7 +1688,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1658
1688
  overrides
1659
1689
  }) {
1660
1690
  try {
1661
- const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1691
+ const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1662
1692
  const validatedConfig = MicrofrontendsServer.validate(config);
1663
1693
  if (!isMainConfig(validatedConfig)) {
1664
1694
  throw new MicrofrontendError(
@@ -1689,33 +1719,6 @@ var MicrofrontendsServer = class extends Microfrontends {
1689
1719
  }
1690
1720
  };
1691
1721
 
1692
- // src/config/microfrontends/utils/get-application-context.ts
1693
- var import_node_fs8 = __toESM(require("fs"), 1);
1694
- function getApplicationContext(opts) {
1695
- if (opts?.appName) {
1696
- return { name: opts.appName };
1697
- }
1698
- try {
1699
- const packageJsonString = import_node_fs8.default.readFileSync("./package.json", "utf-8");
1700
- const packageJson = JSON.parse(packageJsonString);
1701
- if (!packageJson.name) {
1702
- throw new MicrofrontendError(
1703
- `package.json file missing required field "name"`,
1704
- {
1705
- type: "packageJson",
1706
- subtype: "missing_field_name",
1707
- source: "@vercel/microfrontends/next"
1708
- }
1709
- );
1710
- }
1711
- return { name: packageJson.name };
1712
- } catch (err) {
1713
- throw MicrofrontendError.handle(err, {
1714
- fileName: "package.json"
1715
- });
1716
- }
1717
- }
1718
-
1719
1722
  // src/next/config/transforms/asset-prefix.ts
1720
1723
  function transform(args) {
1721
1724
  const { next, app } = args;