@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
|
@@ -167,11 +167,11 @@ function findRepositoryRoot(startDir) {
|
|
|
167
167
|
currentDir = path.dirname(currentDir);
|
|
168
168
|
}
|
|
169
169
|
throw new Error(
|
|
170
|
-
|
|
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/
|
|
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/
|
|
186
|
+
// src/config/microfrontends/utils/infer-microfrontends-location.ts
|
|
187
187
|
var configCache = {};
|
|
188
|
-
function
|
|
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
|
|
219
|
-
`Found multiple
|
|
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
|
|
225
|
-
`Could not find
|
|
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
|
|
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 =
|
|
249
|
+
const result = findPackageWithMicrofrontendsConfig(opts);
|
|
240
250
|
if (!result) {
|
|
241
|
-
throw new
|
|
242
|
-
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
}
|