@vercel/microfrontends 1.2.0 → 1.2.1

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 +50 -17
  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 +18 -14
  7. package/dist/experimental/sveltekit.cjs.map +1 -1
  8. package/dist/experimental/sveltekit.js +18 -14
  9. package/dist/experimental/sveltekit.js.map +1 -1
  10. package/dist/experimental/vite.cjs +18 -14
  11. package/dist/experimental/vite.cjs.map +1 -1
  12. package/dist/experimental/vite.d.ts +3 -2
  13. package/dist/experimental/vite.js +18 -14
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +18 -14
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.js +18 -14
  18. package/dist/microfrontends/server.js.map +1 -1
  19. package/dist/microfrontends/utils.cjs +71 -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 +69 -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 +18 -14
  29. package/dist/next/config.cjs.map +1 -1
  30. package/dist/next/config.d.ts +16 -2
  31. package/dist/next/config.js +18 -14
  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 +18 -14
  47. package/dist/utils/mfe-port.cjs.map +1 -1
  48. package/dist/utils/mfe-port.js +18 -14
  49. package/dist/utils/mfe-port.js.map +1 -1
  50. package/package.json +1 -1
@@ -20,8 +20,22 @@ interface WithMicrofrontendsOptions {
20
20
  }
21
21
 
22
22
  /**
23
- * A function that wraps the next.config.js file to automatically configure zones
24
- * based on the microfrontends configuration.
23
+ * Automatically configures your Next.js application to work with microfrontends.
24
+ *
25
+ * This function should wrap your Next.js config object before it is exported. It
26
+ * will automatically set up the necessary fields and environment variables for
27
+ * microfrontends to work.
28
+ *
29
+ * See the [Getting Started](https://vercel.com/docs/microfrontends/quickstart) guide for more information.
30
+ *
31
+ * @example Wrapping your Next.js config
32
+ * ```js
33
+ * import { withMicrofrontends } from '@vercel/microfrontends/next/config';
34
+ *
35
+ * const nextConfig = { ... };
36
+ *
37
+ * export default withMicrofrontends(nextConfig);
38
+ * ```
25
39
  */
26
40
  declare function withMicrofrontends(nextConfig: NextConfig, opts?: WithMicrofrontendsOptions): NextConfig;
27
41
 
@@ -176,11 +176,11 @@ function findRepositoryRoot(startDir) {
176
176
  currentDir = path.dirname(currentDir);
177
177
  }
178
178
  throw new Error(
179
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
179
+ `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.`
180
180
  );
181
181
  }
182
182
 
183
- // src/config/microfrontends/utils/find-default-package.ts
183
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
184
184
  import { dirname } from "node:path";
185
185
  import { readFileSync } from "node:fs";
186
186
  import { parse } from "jsonc-parser";
@@ -192,9 +192,9 @@ var CONFIGURATION_FILENAMES = [
192
192
  "microfrontends.json"
193
193
  ];
194
194
 
195
- // src/config/microfrontends/utils/find-default-package.ts
195
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
196
196
  var configCache = {};
197
- function findDefaultMicrofrontendsPackages({
197
+ function findPackageWithMicrofrontendsConfig({
198
198
  repositoryRoot,
199
199
  applicationName
200
200
  }) {
@@ -225,13 +225,13 @@ function findDefaultMicrofrontendsPackages({
225
225
  }
226
226
  if (matchingPaths.length > 1) {
227
227
  throw new Error(
228
- `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
228
+ `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
229
229
  ${matchingPaths.join("\n \u2022 ")}`
230
230
  );
231
231
  }
232
232
  if (matchingPaths.length === 0) {
233
233
  throw new Error(
234
- `Could not find default application with "applications.${applicationName}"`
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
235
  );
236
236
  }
237
237
  const [packageJsonPath] = matchingPaths;
@@ -240,15 +240,15 @@ ${matchingPaths.join("\n \u2022 ")}`
240
240
  return null;
241
241
  }
242
242
  }
243
- function findDefaultMicrofrontendsPackage(opts) {
243
+ function inferMicrofrontendsLocation(opts) {
244
244
  const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
245
245
  if (configCache[cacheKey]) {
246
246
  return configCache[cacheKey];
247
247
  }
248
- const result = findDefaultMicrofrontendsPackages(opts);
248
+ const result = findPackageWithMicrofrontendsConfig(opts);
249
249
  if (!result) {
250
250
  throw new Error(
251
- "Error trying to resolve the main microfrontends configuration"
251
+ `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationName}" starting in directory "${opts.repositoryRoot}".`
252
252
  );
253
253
  }
254
254
  configCache[cacheKey] = result;
@@ -299,7 +299,7 @@ function findPackageRoot(startDir) {
299
299
  currentDir = path3.dirname(currentDir);
300
300
  }
301
301
  throw new Error(
302
- "Package root not found. Specify the root of the package with the `package.root` option."
302
+ `The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
303
303
  );
304
304
  }
305
305
 
@@ -340,7 +340,9 @@ var MicrofrontendConfigClient = class {
340
340
  */
341
341
  static fromEnv(config, opts) {
342
342
  if (!config) {
343
- throw new Error("No microfrontends configuration found");
343
+ throw new Error(
344
+ "Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
345
+ );
344
346
  }
345
347
  return new MicrofrontendConfigClient(
346
348
  JSON.parse(config),
@@ -1362,7 +1364,7 @@ var MicrofrontendsServer = class {
1362
1364
  const repositoryRoot = findRepositoryRoot();
1363
1365
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1364
1366
  if (isMonorepo2) {
1365
- const defaultPackage = findDefaultMicrofrontendsPackage({
1367
+ const defaultPackage = inferMicrofrontendsLocation({
1366
1368
  repositoryRoot,
1367
1369
  applicationName: appName
1368
1370
  });
@@ -1374,13 +1376,15 @@ var MicrofrontendsServer = class {
1374
1376
  });
1375
1377
  }
1376
1378
  }
1377
- throw new Error("Unable to infer");
1379
+ throw new Error(
1380
+ "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."
1381
+ );
1378
1382
  } catch (e) {
1379
1383
  if (e instanceof MicrofrontendError) {
1380
1384
  throw e;
1381
1385
  }
1382
1386
  throw new MicrofrontendError(
1383
- "Unable to locate and parse microfrontends configuration",
1387
+ "Unable to locate and parse the `microfrontends.json` configuration file.",
1384
1388
  { cause: e, type: "config", subtype: "inference_failed" }
1385
1389
  );
1386
1390
  }