@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.
- package/dist/bin/cli.cjs +67 -21
- package/dist/config.cjs +3 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +35 -18
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +35 -18
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +35 -18
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.d.ts +3 -2
- package/dist/experimental/vite.js +35 -18
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +35 -18
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +35 -18
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends/utils.cjs +176 -2
- package/dist/microfrontends/utils.cjs.map +1 -1
- package/dist/microfrontends/utils.d.ts +11 -1
- package/dist/microfrontends/utils.js +174 -1
- package/dist/microfrontends/utils.js.map +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +35 -18
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +16 -2
- package/dist/next/config.js +35 -18
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +3 -1
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.js +3 -1
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +7 -3
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +7 -3
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +3 -1
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +28 -0
- package/dist/next/testing.js +3 -1
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +35 -18
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +35 -18
- package/dist/utils/mfe-port.js.map +1 -1
- package/package.json +1 -1
package/dist/next/config.d.ts
CHANGED
|
@@ -20,8 +20,22 @@ interface WithMicrofrontendsOptions {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
|
package/dist/next/config.js
CHANGED
|
@@ -176,11 +176,11 @@ function findRepositoryRoot(startDir) {
|
|
|
176
176
|
currentDir = path.dirname(currentDir);
|
|
177
177
|
}
|
|
178
178
|
throw new Error(
|
|
179
|
-
|
|
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/
|
|
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/
|
|
195
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
196
196
|
var configCache = {};
|
|
197
|
-
function
|
|
197
|
+
function findPackageWithMicrofrontendsConfig({
|
|
198
198
|
repositoryRoot,
|
|
199
199
|
applicationName
|
|
200
200
|
}) {
|
|
@@ -219,19 +219,29 @@ function findDefaultMicrofrontendsPackages({
|
|
|
219
219
|
const microfrontendsJson = parse(microfrontendsJsonContent);
|
|
220
220
|
if (microfrontendsJson.applications[applicationName]) {
|
|
221
221
|
matchingPaths.push(microfrontendsJsonPath);
|
|
222
|
+
} else {
|
|
223
|
+
for (const [_, app] of Object.entries(
|
|
224
|
+
microfrontendsJson.applications
|
|
225
|
+
)) {
|
|
226
|
+
if (app.packageName === applicationName) {
|
|
227
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
222
230
|
}
|
|
223
231
|
} catch (error) {
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
234
|
if (matchingPaths.length > 1) {
|
|
227
|
-
throw new
|
|
228
|
-
`Found multiple
|
|
229
|
-
${matchingPaths.join("\n \u2022 ")}
|
|
235
|
+
throw new MicrofrontendError(
|
|
236
|
+
`Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
|
|
237
|
+
${matchingPaths.join("\n \u2022 ")}`,
|
|
238
|
+
{ type: "config", subtype: "inference_failed" }
|
|
230
239
|
);
|
|
231
240
|
}
|
|
232
241
|
if (matchingPaths.length === 0) {
|
|
233
|
-
throw new
|
|
234
|
-
`Could not find
|
|
242
|
+
throw new MicrofrontendError(
|
|
243
|
+
`Could not find a \`microfrontends.json\` file in the repository that contains "applications.${applicationName}". Microfrontends defined in separate repositories are not supported yet.`,
|
|
244
|
+
{ type: "config", subtype: "inference_failed" }
|
|
235
245
|
);
|
|
236
246
|
}
|
|
237
247
|
const [packageJsonPath] = matchingPaths;
|
|
@@ -240,15 +250,16 @@ ${matchingPaths.join("\n \u2022 ")}`
|
|
|
240
250
|
return null;
|
|
241
251
|
}
|
|
242
252
|
}
|
|
243
|
-
function
|
|
253
|
+
function inferMicrofrontendsLocation(opts) {
|
|
244
254
|
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
245
255
|
if (configCache[cacheKey]) {
|
|
246
256
|
return configCache[cacheKey];
|
|
247
257
|
}
|
|
248
|
-
const result =
|
|
258
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
249
259
|
if (!result) {
|
|
250
|
-
throw new
|
|
251
|
-
|
|
260
|
+
throw new MicrofrontendError(
|
|
261
|
+
`Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationName}" starting in directory "${opts.repositoryRoot}".`,
|
|
262
|
+
{ type: "config", subtype: "inference_failed" }
|
|
252
263
|
);
|
|
253
264
|
}
|
|
254
265
|
configCache[cacheKey] = result;
|
|
@@ -299,7 +310,7 @@ function findPackageRoot(startDir) {
|
|
|
299
310
|
currentDir = path3.dirname(currentDir);
|
|
300
311
|
}
|
|
301
312
|
throw new Error(
|
|
302
|
-
|
|
313
|
+
`The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
|
|
303
314
|
);
|
|
304
315
|
}
|
|
305
316
|
|
|
@@ -340,7 +351,9 @@ var MicrofrontendConfigClient = class {
|
|
|
340
351
|
*/
|
|
341
352
|
static fromEnv(config, opts) {
|
|
342
353
|
if (!config) {
|
|
343
|
-
throw new Error(
|
|
354
|
+
throw new Error(
|
|
355
|
+
"Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
|
|
356
|
+
);
|
|
344
357
|
}
|
|
345
358
|
return new MicrofrontendConfigClient(
|
|
346
359
|
JSON.parse(config),
|
|
@@ -1362,7 +1375,7 @@ var MicrofrontendsServer = class {
|
|
|
1362
1375
|
const repositoryRoot = findRepositoryRoot();
|
|
1363
1376
|
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1364
1377
|
if (isMonorepo2) {
|
|
1365
|
-
const defaultPackage =
|
|
1378
|
+
const defaultPackage = inferMicrofrontendsLocation({
|
|
1366
1379
|
repositoryRoot,
|
|
1367
1380
|
applicationName: appName
|
|
1368
1381
|
});
|
|
@@ -1374,13 +1387,17 @@ var MicrofrontendsServer = class {
|
|
|
1374
1387
|
});
|
|
1375
1388
|
}
|
|
1376
1389
|
}
|
|
1377
|
-
throw new
|
|
1390
|
+
throw new MicrofrontendError(
|
|
1391
|
+
"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.",
|
|
1392
|
+
{ type: "config", subtype: "inference_failed" }
|
|
1393
|
+
);
|
|
1378
1394
|
} catch (e) {
|
|
1379
1395
|
if (e instanceof MicrofrontendError) {
|
|
1380
1396
|
throw e;
|
|
1381
1397
|
}
|
|
1398
|
+
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
1382
1399
|
throw new MicrofrontendError(
|
|
1383
|
-
|
|
1400
|
+
`Unable to locate and parse the \`microfrontends.json\` configuration file. Original error message: ${errorMessage}`,
|
|
1384
1401
|
{ cause: e, type: "config", subtype: "inference_failed" }
|
|
1385
1402
|
);
|
|
1386
1403
|
}
|