@vercel/microfrontends 1.2.0 → 1.2.2

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 (50) hide show
  1. package/dist/bin/cli.cjs +67 -21
  2. package/dist/config.cjs +3 -1
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.js +3 -1
  5. package/dist/config.js.map +1 -1
  6. package/dist/experimental/sveltekit.cjs +35 -18
  7. package/dist/experimental/sveltekit.cjs.map +1 -1
  8. package/dist/experimental/sveltekit.js +35 -18
  9. package/dist/experimental/sveltekit.js.map +1 -1
  10. package/dist/experimental/vite.cjs +35 -18
  11. package/dist/experimental/vite.cjs.map +1 -1
  12. package/dist/experimental/vite.d.ts +3 -2
  13. package/dist/experimental/vite.js +35 -18
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +35 -18
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.js +35 -18
  18. package/dist/microfrontends/server.js.map +1 -1
  19. package/dist/microfrontends/utils.cjs +176 -2
  20. package/dist/microfrontends/utils.cjs.map +1 -1
  21. package/dist/microfrontends/utils.d.ts +11 -1
  22. package/dist/microfrontends/utils.js +174 -1
  23. package/dist/microfrontends/utils.js.map +1 -1
  24. package/dist/next/client.cjs +1 -1
  25. package/dist/next/client.cjs.map +1 -1
  26. package/dist/next/client.js +1 -1
  27. package/dist/next/client.js.map +1 -1
  28. package/dist/next/config.cjs +35 -18
  29. package/dist/next/config.cjs.map +1 -1
  30. package/dist/next/config.d.ts +16 -2
  31. package/dist/next/config.js +35 -18
  32. package/dist/next/config.js.map +1 -1
  33. package/dist/next/endpoints.cjs +3 -1
  34. package/dist/next/endpoints.cjs.map +1 -1
  35. package/dist/next/endpoints.js +3 -1
  36. package/dist/next/endpoints.js.map +1 -1
  37. package/dist/next/middleware.cjs +7 -3
  38. package/dist/next/middleware.cjs.map +1 -1
  39. package/dist/next/middleware.js +7 -3
  40. package/dist/next/middleware.js.map +1 -1
  41. package/dist/next/testing.cjs +3 -1
  42. package/dist/next/testing.cjs.map +1 -1
  43. package/dist/next/testing.d.ts +28 -0
  44. package/dist/next/testing.js +3 -1
  45. package/dist/next/testing.js.map +1 -1
  46. package/dist/utils/mfe-port.cjs +35 -18
  47. package/dist/utils/mfe-port.cjs.map +1 -1
  48. package/dist/utils/mfe-port.js +35 -18
  49. package/dist/utils/mfe-port.js.map +1 -1
  50. package/package.json +1 -1
@@ -167,11 +167,11 @@ function findRepositoryRoot(startDir) {
167
167
  currentDir = path.dirname(currentDir);
168
168
  }
169
169
  throw new Error(
170
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
170
+ `Could not find the root of the repository for ${startDir}. Please ensure that the directory is part of a Git repository. If you suspect that this should work, please file an issue to the Vercel team.`
171
171
  );
172
172
  }
173
173
 
174
- // src/config/microfrontends/utils/find-default-package.ts
174
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
175
175
  import { dirname } from "node:path";
176
176
  import { readFileSync } from "node:fs";
177
177
  import { parse } from "jsonc-parser";
@@ -183,9 +183,9 @@ var CONFIGURATION_FILENAMES = [
183
183
  "microfrontends.json"
184
184
  ];
185
185
 
186
- // src/config/microfrontends/utils/find-default-package.ts
186
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
187
187
  var configCache = {};
188
- function findDefaultMicrofrontendsPackages({
188
+ function findPackageWithMicrofrontendsConfig({
189
189
  repositoryRoot,
190
190
  applicationName
191
191
  }) {
@@ -210,19 +210,29 @@ function findDefaultMicrofrontendsPackages({
210
210
  const microfrontendsJson = parse(microfrontendsJsonContent);
211
211
  if (microfrontendsJson.applications[applicationName]) {
212
212
  matchingPaths.push(microfrontendsJsonPath);
213
+ } else {
214
+ for (const [_, app] of Object.entries(
215
+ microfrontendsJson.applications
216
+ )) {
217
+ if (app.packageName === applicationName) {
218
+ matchingPaths.push(microfrontendsJsonPath);
219
+ }
220
+ }
213
221
  }
214
222
  } catch (error) {
215
223
  }
216
224
  }
217
225
  if (matchingPaths.length > 1) {
218
- throw new Error(
219
- `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
220
- ${matchingPaths.join("\n \u2022 ")}`
226
+ throw new MicrofrontendError(
227
+ `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
228
+ ${matchingPaths.join("\n \u2022 ")}`,
229
+ { type: "config", subtype: "inference_failed" }
221
230
  );
222
231
  }
223
232
  if (matchingPaths.length === 0) {
224
- throw new Error(
225
- `Could not find default application with "applications.${applicationName}"`
233
+ throw new MicrofrontendError(
234
+ `Could not find a \`microfrontends.json\` file in the repository that contains "applications.${applicationName}". Microfrontends defined in separate repositories are not supported yet.`,
235
+ { type: "config", subtype: "inference_failed" }
226
236
  );
227
237
  }
228
238
  const [packageJsonPath] = matchingPaths;
@@ -231,15 +241,16 @@ ${matchingPaths.join("\n \u2022 ")}`
231
241
  return null;
232
242
  }
233
243
  }
234
- function findDefaultMicrofrontendsPackage(opts) {
244
+ function inferMicrofrontendsLocation(opts) {
235
245
  const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
236
246
  if (configCache[cacheKey]) {
237
247
  return configCache[cacheKey];
238
248
  }
239
- const result = findDefaultMicrofrontendsPackages(opts);
249
+ const result = findPackageWithMicrofrontendsConfig(opts);
240
250
  if (!result) {
241
- throw new Error(
242
- "Error trying to resolve the main microfrontends configuration"
251
+ throw new MicrofrontendError(
252
+ `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationName}" starting in directory "${opts.repositoryRoot}".`,
253
+ { type: "config", subtype: "inference_failed" }
243
254
  );
244
255
  }
245
256
  configCache[cacheKey] = result;
@@ -290,7 +301,7 @@ function findPackageRoot(startDir) {
290
301
  currentDir = path3.dirname(currentDir);
291
302
  }
292
303
  throw new Error(
293
- "Package root not found. Specify the root of the package with the `package.root` option."
304
+ `The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
294
305
  );
295
306
  }
296
307
 
@@ -331,7 +342,9 @@ var MicrofrontendConfigClient = class {
331
342
  */
332
343
  static fromEnv(config, opts) {
333
344
  if (!config) {
334
- throw new Error("No microfrontends configuration found");
345
+ throw new Error(
346
+ "Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
347
+ );
335
348
  }
336
349
  return new MicrofrontendConfigClient(
337
350
  JSON.parse(config),
@@ -1353,7 +1366,7 @@ var MicrofrontendsServer = class {
1353
1366
  const repositoryRoot = findRepositoryRoot();
1354
1367
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1355
1368
  if (isMonorepo2) {
1356
- const defaultPackage = findDefaultMicrofrontendsPackage({
1369
+ const defaultPackage = inferMicrofrontendsLocation({
1357
1370
  repositoryRoot,
1358
1371
  applicationName: appName
1359
1372
  });
@@ -1365,13 +1378,17 @@ var MicrofrontendsServer = class {
1365
1378
  });
1366
1379
  }
1367
1380
  }
1368
- throw new Error("Unable to infer");
1381
+ throw new MicrofrontendError(
1382
+ "Unable to automatically infer the location of the `microfrontends.json` file. Microfrontends defined in separate repositories are not supported yet. If you suspect this is thrown in error, please reach out to the Vercel team.",
1383
+ { type: "config", subtype: "inference_failed" }
1384
+ );
1369
1385
  } catch (e) {
1370
1386
  if (e instanceof MicrofrontendError) {
1371
1387
  throw e;
1372
1388
  }
1389
+ const errorMessage = e instanceof Error ? e.message : String(e);
1373
1390
  throw new MicrofrontendError(
1374
- "Unable to locate and parse microfrontends configuration",
1391
+ `Unable to locate and parse the \`microfrontends.json\` configuration file. Original error message: ${errorMessage}`,
1375
1392
  { cause: e, type: "config", subtype: "inference_failed" }
1376
1393
  );
1377
1394
  }