@vercel/microfrontends 1.1.1-canary.2 → 1.1.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.
- package/dist/bin/cli.cjs +303 -512
- package/dist/config.cjs +43 -71
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +153 -4
- package/dist/config.js +43 -71
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +296 -489
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +286 -479
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +326 -511
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +312 -497
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +295 -485
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +14 -20
- package/dist/microfrontends/server.js +285 -475
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/next/config.cjs +297 -498
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +287 -488
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +2 -0
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +13 -3
- package/dist/next/endpoints.js +1 -0
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +58 -171
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +2 -4
- package/dist/next/middleware.js +58 -171
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +44 -73
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +44 -73
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/schema.cjs +2 -9
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +3 -4
- package/dist/schema.js +1 -7
- package/dist/schema.js.map +1 -1
- package/dist/{types-6ee19ccc.d.ts → types-54064641.d.ts} +2 -13
- package/dist/{types-73527280.d.ts → types-a4add5ab.d.ts} +1 -1
- package/dist/{types-74e3336c.d.ts → types-f1260e44.d.ts} +1 -1
- package/dist/utils/mfe-port.cjs +300 -492
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +286 -478
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +49 -37
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +49 -37
- package/dist/validation.js.map +1 -1
- package/package.json +2 -9
- package/schema/schema.json +0 -33
- package/dist/index-7e69650e.d.ts +0 -165
- package/dist/microfrontends.cjs +0 -962
- package/dist/microfrontends.cjs.map +0 -1
- package/dist/microfrontends.d.ts +0 -45
- package/dist/microfrontends.js +0 -935
- package/dist/microfrontends.js.map +0 -1
package/dist/next/config.cjs
CHANGED
|
@@ -44,8 +44,8 @@ function displayLocalProxyInfo(port) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// src/config/microfrontends/server/index.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
48
|
+
var import_node_path8 = require("path");
|
|
49
49
|
|
|
50
50
|
// src/config/overrides/constants.ts
|
|
51
51
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -184,19 +184,177 @@ function getConfigStringFromEnv() {
|
|
|
184
184
|
return config;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
// src/config/
|
|
187
|
+
// src/config/schema/utils/is-default-app.ts
|
|
188
|
+
function isDefaultApp(a) {
|
|
189
|
+
return !("routing" in a);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
193
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
194
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
195
|
+
var GIT_DIRECTORY = ".git";
|
|
196
|
+
function hasGitDirectory(dir) {
|
|
197
|
+
const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
|
|
198
|
+
return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
|
|
199
|
+
}
|
|
200
|
+
function hasPnpmWorkspaces(dir) {
|
|
201
|
+
return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
|
|
202
|
+
}
|
|
203
|
+
function findRepositoryRoot(startDir) {
|
|
204
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
205
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
206
|
+
}
|
|
207
|
+
let currentDir = startDir || process.cwd();
|
|
208
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
209
|
+
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
210
|
+
return currentDir;
|
|
211
|
+
}
|
|
212
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(
|
|
215
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
220
|
+
var import_node_path2 = require("path");
|
|
221
|
+
var import_node_fs2 = require("fs");
|
|
188
222
|
var import_jsonc_parser = require("jsonc-parser");
|
|
223
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
224
|
+
|
|
225
|
+
// src/config/constants.ts
|
|
226
|
+
var CONFIGURATION_FILENAMES = [
|
|
227
|
+
"microfrontends.jsonc",
|
|
228
|
+
"microfrontends.json"
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
232
|
+
var configCache = {};
|
|
233
|
+
function findDefaultMicrofrontendsPackages({
|
|
234
|
+
repositoryRoot,
|
|
235
|
+
applicationName
|
|
236
|
+
}) {
|
|
237
|
+
try {
|
|
238
|
+
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
239
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
240
|
+
{
|
|
241
|
+
cwd: repositoryRoot,
|
|
242
|
+
absolute: true,
|
|
243
|
+
onlyFiles: true,
|
|
244
|
+
followSymbolicLinks: false,
|
|
245
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
const matchingPaths = [];
|
|
249
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
250
|
+
try {
|
|
251
|
+
const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
|
|
252
|
+
microfrontendsJsonPath,
|
|
253
|
+
"utf-8"
|
|
254
|
+
);
|
|
255
|
+
const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
|
|
256
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
257
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
258
|
+
}
|
|
259
|
+
} catch (error) {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (matchingPaths.length > 1) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
265
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (matchingPaths.length === 0) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const [packageJsonPath] = matchingPaths;
|
|
274
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
280
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
281
|
+
if (configCache[cacheKey]) {
|
|
282
|
+
return configCache[cacheKey];
|
|
283
|
+
}
|
|
284
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
285
|
+
if (!result) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
"Error trying to resolve the main microfrontends configuration"
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
configCache[cacheKey] = result;
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
189
293
|
|
|
190
|
-
// src/config/
|
|
191
|
-
|
|
192
|
-
|
|
294
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
295
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
296
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
297
|
+
function isMonorepo({
|
|
298
|
+
repositoryRoot
|
|
299
|
+
}) {
|
|
300
|
+
try {
|
|
301
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path3.default.resolve(repositoryRoot)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
const packageJsonPath = import_node_path3.default.join(repositoryRoot, "package.json");
|
|
311
|
+
if (!import_node_fs3.default.existsSync(packageJsonPath)) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
const packageJson = JSON.parse(
|
|
315
|
+
import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
|
|
316
|
+
);
|
|
317
|
+
return packageJson.workspaces !== void 0;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
193
322
|
}
|
|
194
323
|
|
|
195
|
-
// src/config/
|
|
196
|
-
|
|
197
|
-
|
|
324
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
325
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
326
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
327
|
+
var PACKAGE_JSON = "package.json";
|
|
328
|
+
function findPackageRoot(startDir) {
|
|
329
|
+
let currentDir = startDir || process.cwd();
|
|
330
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
331
|
+
const pkgJsonPath = import_node_path4.default.join(currentDir, PACKAGE_JSON);
|
|
332
|
+
if (import_node_fs4.default.existsSync(pkgJsonPath)) {
|
|
333
|
+
return currentDir;
|
|
334
|
+
}
|
|
335
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
336
|
+
}
|
|
337
|
+
throw new Error(
|
|
338
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
343
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
344
|
+
var import_node_path5 = require("path");
|
|
345
|
+
function findConfig({ dir }) {
|
|
346
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
347
|
+
const maybeConfig = (0, import_node_path5.join)(dir, filename);
|
|
348
|
+
if (import_node_fs5.default.existsSync(maybeConfig)) {
|
|
349
|
+
return maybeConfig;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
198
353
|
}
|
|
199
354
|
|
|
355
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
356
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
357
|
+
|
|
200
358
|
// src/config/microfrontends-config/client/index.ts
|
|
201
359
|
var import_path_to_regexp = require("path-to-regexp");
|
|
202
360
|
var MicrofrontendConfigClient = class {
|
|
@@ -265,6 +423,10 @@ var MicrofrontendConfigClient = class {
|
|
|
265
423
|
|
|
266
424
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
267
425
|
var import_path_to_regexp2 = require("path-to-regexp");
|
|
426
|
+
var LIST_FORMATTER = new Intl.ListFormat("en", {
|
|
427
|
+
style: "long",
|
|
428
|
+
type: "conjunction"
|
|
429
|
+
});
|
|
268
430
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
269
431
|
if (!applicationConfigsById) {
|
|
270
432
|
return;
|
|
@@ -397,15 +559,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
397
559
|
if (!applicationConfigsById) {
|
|
398
560
|
return;
|
|
399
561
|
}
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
);
|
|
403
|
-
const
|
|
404
|
-
(
|
|
562
|
+
const applicationsWithoutRouting = Object.entries(
|
|
563
|
+
applicationConfigsById
|
|
564
|
+
).filter(([, app]) => isDefaultApp(app));
|
|
565
|
+
const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
|
|
566
|
+
(acc) => {
|
|
567
|
+
return acc + 1;
|
|
568
|
+
},
|
|
569
|
+
0
|
|
405
570
|
);
|
|
406
|
-
const numApplications = Object.keys(applicationConfigsById).length;
|
|
407
|
-
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
408
|
-
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
409
571
|
if (numApplicationsWithoutRouting === 0) {
|
|
410
572
|
throw new MicrofrontendError(
|
|
411
573
|
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
@@ -413,8 +575,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
413
575
|
);
|
|
414
576
|
}
|
|
415
577
|
if (numApplicationsWithoutRouting > 1) {
|
|
578
|
+
const applicationNamesMissingRouting = applicationsWithoutRouting.map(
|
|
579
|
+
([name]) => name
|
|
580
|
+
);
|
|
416
581
|
throw new MicrofrontendError(
|
|
417
|
-
`
|
|
582
|
+
`All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
|
|
418
583
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
419
584
|
);
|
|
420
585
|
}
|
|
@@ -725,42 +890,28 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
725
890
|
constructor({
|
|
726
891
|
config,
|
|
727
892
|
overrides,
|
|
728
|
-
meta,
|
|
729
893
|
opts
|
|
730
894
|
}) {
|
|
731
895
|
this.childApplications = {};
|
|
732
896
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
733
897
|
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
734
898
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
app: appConfig,
|
|
742
|
-
overrides: appOverrides
|
|
743
|
-
});
|
|
744
|
-
} else {
|
|
745
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
746
|
-
app: appConfig,
|
|
747
|
-
overrides: appOverrides
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
} else {
|
|
752
|
-
this.partOf = config.partOf;
|
|
753
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
754
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
755
|
-
meta.fromApp,
|
|
756
|
-
{
|
|
757
|
-
// we don't know routing because we're not in the main config
|
|
758
|
-
app: { routing: [] },
|
|
899
|
+
let defaultApplication;
|
|
900
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
901
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
902
|
+
if (isDefaultApp(appConfig)) {
|
|
903
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
904
|
+
app: appConfig,
|
|
759
905
|
overrides: appOverrides
|
|
760
|
-
}
|
|
761
|
-
|
|
906
|
+
});
|
|
907
|
+
} else {
|
|
908
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
909
|
+
app: appConfig,
|
|
910
|
+
overrides: appOverrides
|
|
911
|
+
});
|
|
912
|
+
}
|
|
762
913
|
}
|
|
763
|
-
if (
|
|
914
|
+
if (!defaultApplication) {
|
|
764
915
|
throw new MicrofrontendError(
|
|
765
916
|
"Could not find default application in microfrontends configuration",
|
|
766
917
|
{
|
|
@@ -769,34 +920,30 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
769
920
|
}
|
|
770
921
|
);
|
|
771
922
|
}
|
|
923
|
+
this.defaultApplication = defaultApplication;
|
|
772
924
|
this.config = config;
|
|
773
925
|
this.options = config.options;
|
|
774
926
|
this.serialized = {
|
|
775
927
|
config,
|
|
776
|
-
overrides
|
|
777
|
-
meta
|
|
928
|
+
overrides
|
|
778
929
|
};
|
|
779
930
|
}
|
|
780
931
|
static validate(config, opts) {
|
|
781
932
|
const skipValidation = opts?.skipValidation ?? [];
|
|
782
|
-
const c = typeof config === "string" ? (0,
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
validateDeprecatedFields(c);
|
|
788
|
-
}
|
|
933
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
934
|
+
validateConfigPaths(c.applications);
|
|
935
|
+
validateConfigDefaultApplication(c.applications);
|
|
936
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
937
|
+
validateDeprecatedFields(c);
|
|
789
938
|
}
|
|
790
939
|
return c;
|
|
791
940
|
}
|
|
792
941
|
static fromEnv({
|
|
793
|
-
meta,
|
|
794
942
|
cookies
|
|
795
943
|
}) {
|
|
796
944
|
return new MicrofrontendConfigIsomorphic({
|
|
797
|
-
config: (0,
|
|
798
|
-
overrides: parseOverrides(cookies ?? [])
|
|
799
|
-
meta
|
|
945
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
946
|
+
overrides: parseOverrides(cookies ?? [])
|
|
800
947
|
});
|
|
801
948
|
}
|
|
802
949
|
isOverridesDisabled() {
|
|
@@ -821,7 +968,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
821
968
|
].filter(Boolean);
|
|
822
969
|
}
|
|
823
970
|
getApplication(name) {
|
|
824
|
-
if (this.defaultApplication
|
|
971
|
+
if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
|
|
825
972
|
return this.defaultApplication;
|
|
826
973
|
}
|
|
827
974
|
const app = this.childApplications[name] || Object.values(this.childApplications).find(
|
|
@@ -839,7 +986,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
839
986
|
return app;
|
|
840
987
|
}
|
|
841
988
|
getApplicationByProjectId(projectId) {
|
|
842
|
-
if (this.defaultApplication
|
|
989
|
+
if (this.defaultApplication.projectId === projectId) {
|
|
843
990
|
return this.defaultApplication;
|
|
844
991
|
}
|
|
845
992
|
return Object.values(this.childApplications).find(
|
|
@@ -847,19 +994,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
847
994
|
);
|
|
848
995
|
}
|
|
849
996
|
/**
|
|
850
|
-
* Returns the default application.
|
|
851
|
-
* is undefined ( )
|
|
997
|
+
* Returns the default application.
|
|
852
998
|
*/
|
|
853
999
|
getDefaultApplication() {
|
|
854
|
-
if (!this.defaultApplication) {
|
|
855
|
-
throw new MicrofrontendError(
|
|
856
|
-
"Could not find default application in microfrontends configuration",
|
|
857
|
-
{
|
|
858
|
-
type: "application",
|
|
859
|
-
subtype: "not_found"
|
|
860
|
-
}
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
1000
|
return this.defaultApplication;
|
|
864
1001
|
}
|
|
865
1002
|
/**
|
|
@@ -886,11 +1023,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
886
1023
|
}
|
|
887
1024
|
])
|
|
888
1025
|
);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
};
|
|
893
|
-
}
|
|
1026
|
+
applications[this.defaultApplication.name] = {
|
|
1027
|
+
default: true
|
|
1028
|
+
};
|
|
894
1029
|
return new MicrofrontendConfigClient({
|
|
895
1030
|
applications
|
|
896
1031
|
});
|
|
@@ -900,301 +1035,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
900
1035
|
}
|
|
901
1036
|
};
|
|
902
1037
|
|
|
903
|
-
// src/config/microfrontends-config/isomorphic/child.ts
|
|
904
|
-
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
905
|
-
constructor({
|
|
906
|
-
config,
|
|
907
|
-
overrides,
|
|
908
|
-
meta
|
|
909
|
-
}) {
|
|
910
|
-
super({ config, overrides, meta });
|
|
911
|
-
this.isMainConfig = false;
|
|
912
|
-
this.partOf = config.partOf;
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
// src/config/microfrontends-config/isomorphic/main.ts
|
|
917
|
-
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
918
|
-
constructor({
|
|
919
|
-
config,
|
|
920
|
-
overrides,
|
|
921
|
-
meta
|
|
922
|
-
}) {
|
|
923
|
-
super({ config, overrides, meta });
|
|
924
|
-
this.isMainConfig = true;
|
|
925
|
-
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
926
|
-
let defaultApplication;
|
|
927
|
-
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
928
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
929
|
-
if (isDefaultApp(appConfig)) {
|
|
930
|
-
defaultApplication = new DefaultApplication(appId, {
|
|
931
|
-
app: appConfig,
|
|
932
|
-
overrides: appOverrides
|
|
933
|
-
});
|
|
934
|
-
} else {
|
|
935
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
936
|
-
app: appConfig,
|
|
937
|
-
overrides: appOverrides
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
if (!defaultApplication) {
|
|
942
|
-
throw new MicrofrontendError(
|
|
943
|
-
"Could not find default application in microfrontends configuration",
|
|
944
|
-
{
|
|
945
|
-
type: "application",
|
|
946
|
-
subtype: "not_found"
|
|
947
|
-
}
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
this.defaultApplication = defaultApplication;
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
// src/config/microfrontends/isomorphic/index.ts
|
|
955
|
-
var Microfrontends = class {
|
|
956
|
-
constructor({
|
|
957
|
-
config,
|
|
958
|
-
overrides,
|
|
959
|
-
meta
|
|
960
|
-
}) {
|
|
961
|
-
if (isMainConfig(config)) {
|
|
962
|
-
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
963
|
-
} else {
|
|
964
|
-
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
isChildConfig() {
|
|
968
|
-
return this.config instanceof MicrofrontendChildConfig;
|
|
969
|
-
}
|
|
970
|
-
static fromEnv({
|
|
971
|
-
cookies,
|
|
972
|
-
meta
|
|
973
|
-
}) {
|
|
974
|
-
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
975
|
-
cookies,
|
|
976
|
-
meta
|
|
977
|
-
});
|
|
978
|
-
return new Microfrontends(config.serialize());
|
|
979
|
-
}
|
|
980
|
-
};
|
|
981
|
-
|
|
982
|
-
// src/config/microfrontends/utils/find-repository-root.ts
|
|
983
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
984
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
985
|
-
var GIT_DIRECTORY = ".git";
|
|
986
|
-
function findRepositoryRoot(startDir) {
|
|
987
|
-
if (process.env.NX_WORKSPACE_ROOT) {
|
|
988
|
-
return process.env.NX_WORKSPACE_ROOT;
|
|
989
|
-
}
|
|
990
|
-
let currentDir = startDir || process.cwd();
|
|
991
|
-
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
992
|
-
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
993
|
-
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
994
|
-
return currentDir;
|
|
995
|
-
}
|
|
996
|
-
currentDir = import_node_path.default.dirname(currentDir);
|
|
997
|
-
}
|
|
998
|
-
throw new Error(
|
|
999
|
-
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
// src/config/microfrontends/utils/find-package-path.ts
|
|
1004
|
-
var import_node_path2 = require("path");
|
|
1005
|
-
var import_node_fs2 = require("fs");
|
|
1006
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1007
|
-
var configCache = {};
|
|
1008
|
-
function findPackagePathWithGlob({
|
|
1009
|
-
repositoryRoot,
|
|
1010
|
-
name
|
|
1011
|
-
}) {
|
|
1012
|
-
try {
|
|
1013
|
-
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
1014
|
-
cwd: repositoryRoot,
|
|
1015
|
-
absolute: true,
|
|
1016
|
-
onlyFiles: true,
|
|
1017
|
-
followSymbolicLinks: false,
|
|
1018
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1019
|
-
});
|
|
1020
|
-
const matchingPaths = [];
|
|
1021
|
-
for (const packageJsonPath2 of packageJsonPaths) {
|
|
1022
|
-
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
1023
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1024
|
-
if (packageJson.name === name) {
|
|
1025
|
-
matchingPaths.push(packageJsonPath2);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
if (matchingPaths.length > 1) {
|
|
1029
|
-
throw new Error(
|
|
1030
|
-
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
1031
|
-
);
|
|
1032
|
-
}
|
|
1033
|
-
if (matchingPaths.length === 0) {
|
|
1034
|
-
throw new Error(
|
|
1035
|
-
`Could not find package with the name "${name}" in the repository`
|
|
1036
|
-
);
|
|
1037
|
-
}
|
|
1038
|
-
const [packageJsonPath] = matchingPaths;
|
|
1039
|
-
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
1040
|
-
} catch (error) {
|
|
1041
|
-
return null;
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
function findPackagePath(opts) {
|
|
1045
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
1046
|
-
if (configCache[cacheKey]) {
|
|
1047
|
-
return configCache[cacheKey];
|
|
1048
|
-
}
|
|
1049
|
-
const result = findPackagePathWithGlob(opts);
|
|
1050
|
-
if (!result) {
|
|
1051
|
-
throw new Error(
|
|
1052
|
-
`Could not find package with the name "${opts.name}" in the repository`
|
|
1053
|
-
);
|
|
1054
|
-
}
|
|
1055
|
-
configCache[cacheKey] = result;
|
|
1056
|
-
return result;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1060
|
-
var import_node_path3 = require("path");
|
|
1061
|
-
var import_node_fs3 = require("fs");
|
|
1062
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
1063
|
-
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1064
|
-
|
|
1065
|
-
// src/config/constants.ts
|
|
1066
|
-
var CONFIGURATION_FILENAMES = [
|
|
1067
|
-
"microfrontends.jsonc",
|
|
1068
|
-
"microfrontends.json"
|
|
1069
|
-
];
|
|
1070
|
-
|
|
1071
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1072
|
-
var configCache2 = {};
|
|
1073
|
-
function findDefaultMicrofrontendsPackages({
|
|
1074
|
-
repositoryRoot,
|
|
1075
|
-
applicationName
|
|
1076
|
-
}) {
|
|
1077
|
-
try {
|
|
1078
|
-
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
1079
|
-
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
1080
|
-
{
|
|
1081
|
-
cwd: repositoryRoot,
|
|
1082
|
-
absolute: true,
|
|
1083
|
-
onlyFiles: true,
|
|
1084
|
-
followSymbolicLinks: false,
|
|
1085
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1086
|
-
}
|
|
1087
|
-
);
|
|
1088
|
-
const matchingPaths = [];
|
|
1089
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1090
|
-
try {
|
|
1091
|
-
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
1092
|
-
microfrontendsJsonPath,
|
|
1093
|
-
"utf-8"
|
|
1094
|
-
);
|
|
1095
|
-
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1096
|
-
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
1097
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1098
|
-
}
|
|
1099
|
-
} catch (error) {
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
if (matchingPaths.length > 1) {
|
|
1103
|
-
throw new Error(
|
|
1104
|
-
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
1105
|
-
${matchingPaths.join("\n \u2022 ")}`
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
if (matchingPaths.length === 0) {
|
|
1109
|
-
throw new Error(
|
|
1110
|
-
`Could not find default application with "applications.${applicationName}"`
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
const [packageJsonPath] = matchingPaths;
|
|
1114
|
-
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
1115
|
-
} catch (error) {
|
|
1116
|
-
return null;
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
function findDefaultMicrofrontendsPackage(opts) {
|
|
1120
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
1121
|
-
if (configCache2[cacheKey]) {
|
|
1122
|
-
return configCache2[cacheKey];
|
|
1123
|
-
}
|
|
1124
|
-
const result = findDefaultMicrofrontendsPackages(opts);
|
|
1125
|
-
if (!result) {
|
|
1126
|
-
throw new Error(
|
|
1127
|
-
"Error trying to resolve the main microfrontends configuration"
|
|
1128
|
-
);
|
|
1129
|
-
}
|
|
1130
|
-
configCache2[cacheKey] = result;
|
|
1131
|
-
return result;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1135
|
-
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1136
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
1137
|
-
function isMonorepo({
|
|
1138
|
-
repositoryRoot
|
|
1139
|
-
}) {
|
|
1140
|
-
try {
|
|
1141
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
1142
|
-
return true;
|
|
1143
|
-
}
|
|
1144
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1145
|
-
return true;
|
|
1146
|
-
}
|
|
1147
|
-
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1148
|
-
return true;
|
|
1149
|
-
}
|
|
1150
|
-
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1151
|
-
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1152
|
-
return false;
|
|
1153
|
-
}
|
|
1154
|
-
const packageJson = JSON.parse(
|
|
1155
|
-
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
1156
|
-
);
|
|
1157
|
-
return packageJson.workspaces !== void 0;
|
|
1158
|
-
} catch (error) {
|
|
1159
|
-
console.error("Error determining if repository is a monorepo", error);
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
// src/config/microfrontends/utils/find-package-root.ts
|
|
1165
|
-
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1166
|
-
var import_node_path5 = __toESM(require("path"), 1);
|
|
1167
|
-
var PACKAGE_JSON = "package.json";
|
|
1168
|
-
function findPackageRoot(startDir) {
|
|
1169
|
-
let currentDir = startDir || process.cwd();
|
|
1170
|
-
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1171
|
-
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1172
|
-
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
1173
|
-
return currentDir;
|
|
1174
|
-
}
|
|
1175
|
-
currentDir = import_node_path5.default.dirname(currentDir);
|
|
1176
|
-
}
|
|
1177
|
-
throw new Error(
|
|
1178
|
-
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
1179
|
-
);
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
1183
|
-
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1184
|
-
var import_node_path6 = require("path");
|
|
1185
|
-
function findConfig({ dir }) {
|
|
1186
|
-
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1187
|
-
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1188
|
-
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1189
|
-
return maybeConfig;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
return null;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
1038
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1196
|
-
var
|
|
1197
|
-
var
|
|
1039
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1040
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
1198
1041
|
function getApplicationContext(opts) {
|
|
1199
1042
|
if (opts?.appName) {
|
|
1200
1043
|
return { name: opts.appName };
|
|
@@ -1203,8 +1046,8 @@ function getApplicationContext(opts) {
|
|
|
1203
1046
|
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1204
1047
|
}
|
|
1205
1048
|
try {
|
|
1206
|
-
const packageJsonString =
|
|
1207
|
-
|
|
1049
|
+
const packageJsonString = import_node_fs6.default.readFileSync(
|
|
1050
|
+
import_node_path6.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1208
1051
|
"utf-8"
|
|
1209
1052
|
);
|
|
1210
1053
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1227,7 +1070,7 @@ function getApplicationContext(opts) {
|
|
|
1227
1070
|
}
|
|
1228
1071
|
|
|
1229
1072
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1230
|
-
var
|
|
1073
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1231
1074
|
|
|
1232
1075
|
// src/config/microfrontends/server/constants.ts
|
|
1233
1076
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1235,7 +1078,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1235
1078
|
|
|
1236
1079
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1237
1080
|
function getOutputFilePath() {
|
|
1238
|
-
return
|
|
1081
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1239
1082
|
}
|
|
1240
1083
|
|
|
1241
1084
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1248,16 +1091,6 @@ var schema_default = {
|
|
|
1248
1091
|
$ref: "#/definitions/Config",
|
|
1249
1092
|
definitions: {
|
|
1250
1093
|
Config: {
|
|
1251
|
-
anyOf: [
|
|
1252
|
-
{
|
|
1253
|
-
$ref: "#/definitions/MainConfig"
|
|
1254
|
-
},
|
|
1255
|
-
{
|
|
1256
|
-
$ref: "#/definitions/ChildConfig"
|
|
1257
|
-
}
|
|
1258
|
-
]
|
|
1259
|
-
},
|
|
1260
|
-
MainConfig: {
|
|
1261
1094
|
type: "object",
|
|
1262
1095
|
properties: {
|
|
1263
1096
|
$schema: {
|
|
@@ -1514,27 +1347,6 @@ var schema_default = {
|
|
|
1514
1347
|
},
|
|
1515
1348
|
required: ["paths"],
|
|
1516
1349
|
additionalProperties: false
|
|
1517
|
-
},
|
|
1518
|
-
ChildConfig: {
|
|
1519
|
-
type: "object",
|
|
1520
|
-
properties: {
|
|
1521
|
-
$schema: {
|
|
1522
|
-
type: "string"
|
|
1523
|
-
},
|
|
1524
|
-
version: {
|
|
1525
|
-
type: "string",
|
|
1526
|
-
const: "1"
|
|
1527
|
-
},
|
|
1528
|
-
options: {
|
|
1529
|
-
$ref: "#/definitions/Options"
|
|
1530
|
-
},
|
|
1531
|
-
partOf: {
|
|
1532
|
-
type: "string",
|
|
1533
|
-
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1534
|
-
}
|
|
1535
|
-
},
|
|
1536
|
-
required: ["partOf"],
|
|
1537
|
-
additionalProperties: false
|
|
1538
1350
|
}
|
|
1539
1351
|
}
|
|
1540
1352
|
};
|
|
@@ -1543,13 +1355,54 @@ var schema_default = {
|
|
|
1543
1355
|
var SCHEMA = schema_default;
|
|
1544
1356
|
|
|
1545
1357
|
// src/config/microfrontends/server/validation.ts
|
|
1546
|
-
|
|
1358
|
+
var LIST_FORMATTER2 = new Intl.ListFormat("en", {
|
|
1359
|
+
style: "long",
|
|
1360
|
+
type: "disjunction"
|
|
1361
|
+
});
|
|
1362
|
+
function formatAjvErrors(errors) {
|
|
1547
1363
|
if (!errors) {
|
|
1548
1364
|
return [];
|
|
1549
1365
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1366
|
+
const errorMessages = [];
|
|
1367
|
+
for (const error of errors) {
|
|
1368
|
+
if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
const instancePath = error.instancePath.slice(1);
|
|
1372
|
+
const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
|
|
1373
|
+
if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
|
|
1374
|
+
errorMessages.push(
|
|
1375
|
+
`Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
|
|
1376
|
+
);
|
|
1377
|
+
} else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
|
|
1378
|
+
const anyOfErrors = errors.filter(
|
|
1379
|
+
(e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
|
|
1380
|
+
);
|
|
1381
|
+
if (anyOfErrors.every((e) => e.keyword === "type")) {
|
|
1382
|
+
const allowedTypes = LIST_FORMATTER2.format(
|
|
1383
|
+
anyOfErrors.map((e) => {
|
|
1384
|
+
return e.keyword === "type" ? String(e.params.type) : "unknown";
|
|
1385
|
+
})
|
|
1386
|
+
);
|
|
1387
|
+
errorMessages.push(
|
|
1388
|
+
`Incorrect type for ${instancePath}. Must be one of ${allowedTypes}`
|
|
1389
|
+
);
|
|
1390
|
+
} else {
|
|
1391
|
+
errorMessages.push(
|
|
1392
|
+
`Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
} else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
|
|
1396
|
+
errorMessages.push(
|
|
1397
|
+
`Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
|
|
1398
|
+
);
|
|
1399
|
+
} else if (error.keyword === "required") {
|
|
1400
|
+
errorMessages.push(
|
|
1401
|
+
`Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
return errorMessages;
|
|
1553
1406
|
}
|
|
1554
1407
|
function validateSchema(configString) {
|
|
1555
1408
|
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
@@ -1558,8 +1411,10 @@ function validateSchema(configString) {
|
|
|
1558
1411
|
const isValid = validate(parsedConfig);
|
|
1559
1412
|
if (!isValid) {
|
|
1560
1413
|
throw new MicrofrontendError(
|
|
1561
|
-
`Invalid microfrontends config
|
|
1562
|
-
- ${
|
|
1414
|
+
`Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
|
|
1415
|
+
- ${error}`).join(
|
|
1416
|
+
""
|
|
1417
|
+
)}
|
|
1563
1418
|
|
|
1564
1419
|
See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
1565
1420
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
@@ -1569,7 +1424,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
|
1569
1424
|
}
|
|
1570
1425
|
|
|
1571
1426
|
// src/config/microfrontends/server/index.ts
|
|
1572
|
-
var MicrofrontendsServer = class
|
|
1427
|
+
var MicrofrontendsServer = class {
|
|
1428
|
+
constructor({
|
|
1429
|
+
config,
|
|
1430
|
+
overrides
|
|
1431
|
+
}) {
|
|
1432
|
+
this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
|
|
1433
|
+
}
|
|
1573
1434
|
/**
|
|
1574
1435
|
* Writes the configuration to a file.
|
|
1575
1436
|
*/
|
|
@@ -1577,8 +1438,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1577
1438
|
pretty: true
|
|
1578
1439
|
}) {
|
|
1579
1440
|
const outputPath = getOutputFilePath();
|
|
1580
|
-
|
|
1581
|
-
|
|
1441
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1442
|
+
import_node_fs7.default.writeFileSync(
|
|
1582
1443
|
outputPath,
|
|
1583
1444
|
JSON.stringify(
|
|
1584
1445
|
this.config.toSchemaJson(),
|
|
@@ -1593,22 +1454,19 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1593
1454
|
*/
|
|
1594
1455
|
static fromUnknown({
|
|
1595
1456
|
config,
|
|
1596
|
-
cookies
|
|
1597
|
-
meta
|
|
1457
|
+
cookies
|
|
1598
1458
|
}) {
|
|
1599
1459
|
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1600
1460
|
if (typeof config === "string") {
|
|
1601
1461
|
return new MicrofrontendsServer({
|
|
1602
1462
|
config: MicrofrontendsServer.validate(config),
|
|
1603
|
-
overrides
|
|
1604
|
-
meta
|
|
1463
|
+
overrides
|
|
1605
1464
|
});
|
|
1606
1465
|
}
|
|
1607
1466
|
if (typeof config === "object") {
|
|
1608
1467
|
return new MicrofrontendsServer({
|
|
1609
1468
|
config,
|
|
1610
|
-
overrides
|
|
1611
|
-
meta
|
|
1469
|
+
overrides
|
|
1612
1470
|
});
|
|
1613
1471
|
}
|
|
1614
1472
|
throw new MicrofrontendError(
|
|
@@ -1621,13 +1479,11 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1621
1479
|
* Uses additional validation that is only available when in a node runtime
|
|
1622
1480
|
*/
|
|
1623
1481
|
static fromEnv({
|
|
1624
|
-
cookies
|
|
1625
|
-
meta
|
|
1482
|
+
cookies
|
|
1626
1483
|
}) {
|
|
1627
1484
|
return new MicrofrontendsServer({
|
|
1628
1485
|
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1629
|
-
overrides: parseOverrides(cookies)
|
|
1630
|
-
meta
|
|
1486
|
+
overrides: parseOverrides(cookies)
|
|
1631
1487
|
});
|
|
1632
1488
|
}
|
|
1633
1489
|
/**
|
|
@@ -1650,29 +1506,22 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1650
1506
|
static infer({
|
|
1651
1507
|
directory,
|
|
1652
1508
|
filePath,
|
|
1653
|
-
|
|
1654
|
-
cookies,
|
|
1655
|
-
options
|
|
1509
|
+
cookies
|
|
1656
1510
|
} = {}) {
|
|
1657
|
-
if (filePath
|
|
1511
|
+
if (filePath) {
|
|
1658
1512
|
return MicrofrontendsServer.fromFile({
|
|
1659
1513
|
filePath,
|
|
1660
|
-
cookies
|
|
1661
|
-
meta,
|
|
1662
|
-
options
|
|
1514
|
+
cookies
|
|
1663
1515
|
});
|
|
1664
1516
|
}
|
|
1665
1517
|
try {
|
|
1666
1518
|
const packageRoot = findPackageRoot(directory);
|
|
1667
1519
|
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1668
|
-
const configMeta = meta ?? { fromApp: appName };
|
|
1669
1520
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1670
1521
|
if (maybeConfig) {
|
|
1671
1522
|
return MicrofrontendsServer.fromFile({
|
|
1672
1523
|
filePath: maybeConfig,
|
|
1673
|
-
cookies
|
|
1674
|
-
meta: configMeta,
|
|
1675
|
-
options
|
|
1524
|
+
cookies
|
|
1676
1525
|
});
|
|
1677
1526
|
}
|
|
1678
1527
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1686,14 +1535,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1686
1535
|
if (maybeConfigFromDefault) {
|
|
1687
1536
|
return MicrofrontendsServer.fromFile({
|
|
1688
1537
|
filePath: maybeConfigFromDefault,
|
|
1689
|
-
cookies
|
|
1690
|
-
meta: configMeta,
|
|
1691
|
-
options
|
|
1538
|
+
cookies
|
|
1692
1539
|
});
|
|
1693
1540
|
}
|
|
1694
1541
|
}
|
|
1695
1542
|
throw new Error("Unable to infer");
|
|
1696
1543
|
} catch (e) {
|
|
1544
|
+
if (e instanceof MicrofrontendError) {
|
|
1545
|
+
throw e;
|
|
1546
|
+
}
|
|
1697
1547
|
throw new MicrofrontendError(
|
|
1698
1548
|
"Unable to locate and parse microfrontends configuration",
|
|
1699
1549
|
{ cause: e, type: "config", subtype: "inference_failed" }
|
|
@@ -1705,44 +1555,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1705
1555
|
*/
|
|
1706
1556
|
static fromFile({
|
|
1707
1557
|
filePath,
|
|
1708
|
-
cookies
|
|
1709
|
-
meta,
|
|
1710
|
-
options
|
|
1558
|
+
cookies
|
|
1711
1559
|
}) {
|
|
1712
1560
|
try {
|
|
1713
|
-
const configJson =
|
|
1561
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1714
1562
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1715
|
-
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1716
|
-
const repositoryRoot = findRepositoryRoot();
|
|
1717
|
-
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1718
|
-
if (isMonorepo2) {
|
|
1719
|
-
const packagePath = findPackagePath({
|
|
1720
|
-
repositoryRoot,
|
|
1721
|
-
name: config.partOf
|
|
1722
|
-
});
|
|
1723
|
-
if (!packagePath) {
|
|
1724
|
-
throw new MicrofrontendError(
|
|
1725
|
-
`Could not find default application "${config.partOf}" in the repository`,
|
|
1726
|
-
{ type: "config", subtype: "not_found" }
|
|
1727
|
-
);
|
|
1728
|
-
}
|
|
1729
|
-
const maybeConfig = findConfig({ dir: packagePath });
|
|
1730
|
-
if (!maybeConfig) {
|
|
1731
|
-
throw new MicrofrontendError(
|
|
1732
|
-
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1733
|
-
{ type: "config", subtype: "not_found" }
|
|
1734
|
-
);
|
|
1735
|
-
}
|
|
1736
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1737
|
-
filePath: maybeConfig,
|
|
1738
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1739
|
-
});
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
1563
|
return new MicrofrontendsServer({
|
|
1743
1564
|
config,
|
|
1744
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1745
|
-
meta
|
|
1565
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1746
1566
|
});
|
|
1747
1567
|
} catch (e) {
|
|
1748
1568
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1751,24 +1571,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1751
1571
|
}
|
|
1752
1572
|
}
|
|
1753
1573
|
/*
|
|
1754
|
-
* Generates a
|
|
1574
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1755
1575
|
*/
|
|
1756
1576
|
static fromMainConfigFile({
|
|
1757
1577
|
filePath,
|
|
1758
1578
|
overrides
|
|
1759
1579
|
}) {
|
|
1760
1580
|
try {
|
|
1761
|
-
const config =
|
|
1581
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1762
1582
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1763
|
-
if (!isMainConfig(validatedConfig)) {
|
|
1764
|
-
throw new MicrofrontendError(
|
|
1765
|
-
`${filePath} is not a main microfrontend config`,
|
|
1766
|
-
{
|
|
1767
|
-
type: "config",
|
|
1768
|
-
subtype: "invalid_main_path"
|
|
1769
|
-
}
|
|
1770
|
-
);
|
|
1771
|
-
}
|
|
1772
1583
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1773
1584
|
if (!defaultApplication) {
|
|
1774
1585
|
throw new MicrofrontendError(
|
|
@@ -1778,8 +1589,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1778
1589
|
}
|
|
1779
1590
|
return new MicrofrontendsServer({
|
|
1780
1591
|
config: validatedConfig,
|
|
1781
|
-
overrides
|
|
1782
|
-
meta: { fromApp: defaultApplication }
|
|
1592
|
+
overrides
|
|
1783
1593
|
});
|
|
1784
1594
|
} catch (e) {
|
|
1785
1595
|
throw MicrofrontendError.handle(e, {
|
|
@@ -2024,7 +1834,7 @@ function transform5(args) {
|
|
|
2024
1834
|
pathname: "/_vercel/:path*"
|
|
2025
1835
|
}
|
|
2026
1836
|
});
|
|
2027
|
-
} else if (opts?.supportPagesRouter
|
|
1837
|
+
} else if (opts?.supportPagesRouter) {
|
|
2028
1838
|
for (const child of microfrontend.getChildApplications()) {
|
|
2029
1839
|
rewrites.set(`/_next/data/${child.getAssetPrefix()}-:buildId/:path*`, {
|
|
2030
1840
|
destination: {
|
|
@@ -2090,14 +1900,6 @@ ${table}
|
|
|
2090
1900
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
2091
1901
|
function transform6(args) {
|
|
2092
1902
|
const { next, app, microfrontend } = args;
|
|
2093
|
-
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
2094
|
-
console.warn(
|
|
2095
|
-
"server actions transform requires the full config - skipping"
|
|
2096
|
-
);
|
|
2097
|
-
return {
|
|
2098
|
-
next
|
|
2099
|
-
};
|
|
2100
|
-
}
|
|
2101
1903
|
const defaultApplication = microfrontend.getDefaultApplication();
|
|
2102
1904
|
const appsToAllow = [
|
|
2103
1905
|
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
@@ -2285,10 +2087,7 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
2285
2087
|
}
|
|
2286
2088
|
const { name: fromApp } = getApplicationContext(opts);
|
|
2287
2089
|
const microfrontends = MicrofrontendsServer.infer({
|
|
2288
|
-
filePath: opts?.configPath
|
|
2289
|
-
meta: {
|
|
2290
|
-
fromApp
|
|
2291
|
-
}
|
|
2090
|
+
filePath: opts?.configPath
|
|
2292
2091
|
});
|
|
2293
2092
|
const app = microfrontends.config.getApplication(fromApp);
|
|
2294
2093
|
setEnvironment({ app, microfrontends });
|