@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
@@ -1,10 +1,10 @@
1
1
  // src/utils/mfe-port.ts
2
- import path5 from "node:path";
3
- import fs6 from "node:fs";
2
+ import path6 from "node:path";
3
+ import fs7 from "node:fs";
4
4
 
5
5
  // src/config/microfrontends/server/index.ts
6
- import fs5 from "node:fs";
7
- import { dirname as dirname3, join as join2 } from "node:path";
6
+ import fs6 from "node:fs";
7
+ import { dirname as dirname3 } from "node:path";
8
8
 
9
9
  // src/config/overrides/constants.ts
10
10
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -187,21 +187,21 @@ var MicrofrontendConfigClient = class {
187
187
  isEqual(other) {
188
188
  return JSON.stringify(this.applications) === JSON.stringify(other.applications);
189
189
  }
190
- getApplicationNameForPath(path6) {
191
- if (!path6.startsWith("/")) {
190
+ getApplicationNameForPath(path7) {
191
+ if (!path7.startsWith("/")) {
192
192
  throw new Error(`Path must start with a /`);
193
193
  }
194
- if (this.pathCache[path6]) {
195
- return this.pathCache[path6];
194
+ if (this.pathCache[path7]) {
195
+ return this.pathCache[path7];
196
196
  }
197
- const pathname = new URL(path6, "https://example.com").pathname;
197
+ const pathname = new URL(path7, "https://example.com").pathname;
198
198
  for (const [name, application] of Object.entries(this.applications)) {
199
199
  if (application.routing) {
200
200
  for (const group of application.routing) {
201
201
  for (const childPath of group.paths) {
202
202
  const regexp = pathToRegexp(childPath);
203
203
  if (regexp.test(pathname)) {
204
- this.pathCache[path6] = name;
204
+ this.pathCache[path7] = name;
205
205
  return name;
206
206
  }
207
207
  }
@@ -214,7 +214,7 @@ var MicrofrontendConfigClient = class {
214
214
  if (!defaultApplication) {
215
215
  return null;
216
216
  }
217
- this.pathCache[path6] = defaultApplication[0];
217
+ this.pathCache[path7] = defaultApplication[0];
218
218
  return defaultApplication[0];
219
219
  }
220
220
  serialize() {
@@ -236,18 +236,18 @@ var validateConfigPaths = (applicationConfigsById) => {
236
236
  }
237
237
  const childApp = app;
238
238
  for (const pathMatch of childApp.routing) {
239
- for (const path6 of pathMatch.paths) {
240
- const maybeError = validatePathExpression(path6);
239
+ for (const path7 of pathMatch.paths) {
240
+ const maybeError = validatePathExpression(path7);
241
241
  if (maybeError) {
242
242
  errors.push(maybeError);
243
243
  } else {
244
- const existing = pathsByApplicationId.get(path6);
244
+ const existing = pathsByApplicationId.get(path7);
245
245
  if (existing) {
246
246
  existing.applications.push(id);
247
247
  } else {
248
- pathsByApplicationId.set(path6, {
248
+ pathsByApplicationId.set(path7, {
249
249
  applications: [id],
250
- matcher: pathToRegexp2(path6),
250
+ matcher: pathToRegexp2(path7),
251
251
  applicationId: id
252
252
  });
253
253
  }
@@ -256,24 +256,24 @@ var validateConfigPaths = (applicationConfigsById) => {
256
256
  }
257
257
  }
258
258
  const entries = Array.from(pathsByApplicationId.entries());
259
- for (const [path6, { applications: ids, matcher, applicationId }] of entries) {
259
+ for (const [path7, { applications: ids, matcher, applicationId }] of entries) {
260
260
  if (ids.length > 1) {
261
261
  errors.push(
262
- `Duplicate path "${path6}" for applications "${ids.join(", ")}"`
262
+ `Duplicate path "${path7}" for applications "${ids.join(", ")}"`
263
263
  );
264
264
  }
265
265
  for (const [
266
266
  matchPath,
267
267
  { applications: matchIds, applicationId: matchApplicationId }
268
268
  ] of entries) {
269
- if (path6 === matchPath) {
269
+ if (path7 === matchPath) {
270
270
  continue;
271
271
  }
272
272
  if (applicationId === matchApplicationId) {
273
273
  continue;
274
274
  }
275
275
  if (matcher.test(matchPath)) {
276
- const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
276
+ const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
277
277
  const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
278
278
  errors.push(
279
279
  `Overlapping path detected between ${source} and ${destination}`
@@ -289,39 +289,42 @@ var validateConfigPaths = (applicationConfigsById) => {
289
289
  }
290
290
  };
291
291
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
292
- function validatePathExpression(path6) {
292
+ function validatePathExpression(path7) {
293
293
  try {
294
- const tokens = parsePathRegexp(path6);
295
- if (/(?<!\\)\{/.test(path6)) {
296
- return `Optional paths are not supported: ${path6}`;
294
+ const tokens = parsePathRegexp(path7);
295
+ if (/(?<!\\)\{/.test(path7)) {
296
+ return `Optional paths are not supported: ${path7}`;
297
297
  }
298
- if (/(?<!\\|\()\?/.test(path6)) {
299
- return `Optional paths are not supported: ${path6}`;
298
+ if (/(?<!\\|\()\?/.test(path7)) {
299
+ return `Optional paths are not supported: ${path7}`;
300
300
  }
301
- if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path6)) {
302
- return `Only one wildcard is allowed per path segment: ${path6}`;
301
+ if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path7)) {
302
+ return `Only one wildcard is allowed per path segment: ${path7}`;
303
303
  }
304
304
  for (let i = 0; i < tokens.length; i++) {
305
305
  const token = tokens[i];
306
306
  if (token === void 0) {
307
- return `token ${i} in ${path6} is undefined, this shouldn't happen`;
307
+ return `token ${i} in ${path7} is undefined, this shouldn't happen`;
308
308
  }
309
309
  if (typeof token !== "string") {
310
+ if (!token.name) {
311
+ return `Only named wildcards are allowed: ${path7} (hint: add ":path" to the wildcard)`;
312
+ }
310
313
  if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
311
314
  // Only limited regex is supported for now, due to performance considerations
312
315
  !/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
313
316
  token.pattern
314
317
  )) {
315
- return `Path ${path6} cannot use unsupported regular expression wildcard`;
318
+ return `Path ${path7} cannot use unsupported regular expression wildcard`;
316
319
  }
317
320
  if (token.modifier && i !== tokens.length - 1) {
318
- return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
321
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
319
322
  }
320
323
  }
321
324
  }
322
325
  } catch (e) {
323
326
  const message = e instanceof Error ? e.message : String(e);
324
- return `Path ${path6} could not be parsed into regexp: ${message}`;
327
+ return `Path ${path7} could not be parsed into regexp: ${message}`;
325
328
  }
326
329
  return void 0;
327
330
  }
@@ -675,12 +678,8 @@ var MicrofrontendConfigIsomorphic = class {
675
678
  const skipValidation = opts?.skipValidation ?? [];
676
679
  const c = typeof config === "string" ? parse(config) : config;
677
680
  if (isMainConfig(c)) {
678
- if (!skipValidation.includes("paths")) {
679
- validateConfigPaths(c.applications);
680
- }
681
- if (!skipValidation.includes("defaultApplication")) {
682
- validateConfigDefaultApplication(c.applications);
683
- }
681
+ validateConfigPaths(c.applications);
682
+ validateConfigDefaultApplication(c.applications);
684
683
  if (!skipValidation.includes("deprecatedFields")) {
685
684
  validateDeprecatedFields(c);
686
685
  }
@@ -1037,6 +1036,9 @@ function isMonorepo({
1037
1036
  if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
1038
1037
  return true;
1039
1038
  }
1039
+ if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
1040
+ return true;
1041
+ }
1040
1042
  const packageJsonPath = path2.join(repositoryRoot, "package.json");
1041
1043
  if (!fs2.existsSync(packageJsonPath)) {
1042
1044
  return false;
@@ -1082,8 +1084,42 @@ function findConfig({ dir }) {
1082
1084
  return null;
1083
1085
  }
1084
1086
 
1085
- // src/config/microfrontends/server/utils/get-output-file-path.ts
1087
+ // src/config/microfrontends/utils/get-application-context.ts
1088
+ import fs5 from "node:fs";
1086
1089
  import path4 from "node:path";
1090
+ function getApplicationContext(opts) {
1091
+ if (opts?.appName) {
1092
+ return { name: opts.appName };
1093
+ }
1094
+ if (process.env.NX_TASK_TARGET_PROJECT) {
1095
+ return { name: process.env.NX_TASK_TARGET_PROJECT };
1096
+ }
1097
+ try {
1098
+ const packageJsonString = fs5.readFileSync(
1099
+ path4.join(opts?.packageRoot || ".", "package.json"),
1100
+ "utf-8"
1101
+ );
1102
+ const packageJson = JSON.parse(packageJsonString);
1103
+ if (!packageJson.name) {
1104
+ throw new MicrofrontendError(
1105
+ `package.json file missing required field "name"`,
1106
+ {
1107
+ type: "packageJson",
1108
+ subtype: "missing_field_name",
1109
+ source: "@vercel/microfrontends/next"
1110
+ }
1111
+ );
1112
+ }
1113
+ return { name: packageJson.name };
1114
+ } catch (err) {
1115
+ throw MicrofrontendError.handle(err, {
1116
+ fileName: "package.json"
1117
+ });
1118
+ }
1119
+ }
1120
+
1121
+ // src/config/microfrontends/server/utils/get-output-file-path.ts
1122
+ import path5 from "node:path";
1087
1123
 
1088
1124
  // src/config/microfrontends/server/constants.ts
1089
1125
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1091,7 +1127,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1091
1127
 
1092
1128
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1093
1129
  function getOutputFilePath() {
1094
- return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1130
+ return path5.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1095
1131
  }
1096
1132
 
1097
1133
  // src/config/microfrontends/server/validation.ts
@@ -1430,8 +1466,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1430
1466
  pretty: true
1431
1467
  }) {
1432
1468
  const outputPath = getOutputFilePath();
1433
- fs5.mkdirSync(dirname3(outputPath), { recursive: true });
1434
- fs5.writeFileSync(
1469
+ fs6.mkdirSync(dirname3(outputPath), { recursive: true });
1470
+ fs6.writeFileSync(
1435
1471
  outputPath,
1436
1472
  JSON.stringify(
1437
1473
  this.config.toSchemaJson(),
@@ -1517,14 +1553,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1517
1553
  }
1518
1554
  try {
1519
1555
  const packageRoot = findPackageRoot(directory);
1520
- const packageJsonPath = join2(packageRoot, "package.json");
1521
- const packageJson = JSON.parse(
1522
- fs5.readFileSync(packageJsonPath, "utf-8")
1523
- );
1524
- if (!packageJson.name) {
1525
- throw new Error(`No name found in package.json at ${packageJsonPath}`);
1526
- }
1527
- const configMeta = meta ?? { fromApp: packageJson.name };
1556
+ const { name: appName } = getApplicationContext({ packageRoot });
1557
+ const configMeta = meta ?? { fromApp: appName };
1528
1558
  const maybeConfig = findConfig({ dir: packageRoot });
1529
1559
  if (maybeConfig) {
1530
1560
  return MicrofrontendsServer.fromFile({
@@ -1539,7 +1569,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1539
1569
  if (isMonorepo2) {
1540
1570
  const defaultPackage = findDefaultMicrofrontendsPackage({
1541
1571
  repositoryRoot,
1542
- applicationName: packageJson.name
1572
+ applicationName: appName
1543
1573
  });
1544
1574
  const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1545
1575
  if (maybeConfigFromDefault) {
@@ -1569,7 +1599,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1569
1599
  options
1570
1600
  }) {
1571
1601
  try {
1572
- const configJson = fs5.readFileSync(filePath, "utf-8");
1602
+ const configJson = fs6.readFileSync(filePath, "utf-8");
1573
1603
  const config = MicrofrontendsServer.validate(configJson);
1574
1604
  if (!isMainConfig(config) && options?.resolveMainConfig) {
1575
1605
  const repositoryRoot = findRepositoryRoot();
@@ -1617,7 +1647,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1617
1647
  overrides
1618
1648
  }) {
1619
1649
  try {
1620
- const config = fs5.readFileSync(filePath, "utf-8");
1650
+ const config = fs6.readFileSync(filePath, "utf-8");
1621
1651
  const validatedConfig = MicrofrontendsServer.validate(config);
1622
1652
  if (!isMainConfig(validatedConfig)) {
1623
1653
  throw new MicrofrontendError(
@@ -1666,8 +1696,8 @@ function mfePort(packageDir) {
1666
1696
  };
1667
1697
  }
1668
1698
  function getPackageJson(packageDir) {
1669
- const filePath = path5.join(packageDir, "package.json");
1670
- return JSON.parse(fs6.readFileSync(filePath, "utf-8"));
1699
+ const filePath = path6.join(packageDir, "package.json");
1700
+ return JSON.parse(fs7.readFileSync(filePath, "utf-8"));
1671
1701
  }
1672
1702
  function loadConfig({
1673
1703
  packageDir,