@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/utils/mfe-port.cjs
CHANGED
|
@@ -33,12 +33,12 @@ __export(mfe_port_exports, {
|
|
|
33
33
|
mfePort: () => mfePort
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(mfe_port_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
37
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
38
38
|
|
|
39
39
|
// src/config/microfrontends/server/index.ts
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
41
|
+
var import_node_path8 = require("path");
|
|
42
42
|
|
|
43
43
|
// src/config/overrides/constants.ts
|
|
44
44
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -177,19 +177,177 @@ function getConfigStringFromEnv() {
|
|
|
177
177
|
return config;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
// src/config/
|
|
180
|
+
// src/config/schema/utils/is-default-app.ts
|
|
181
|
+
function isDefaultApp(a) {
|
|
182
|
+
return !("routing" in a);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
186
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
187
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
188
|
+
var GIT_DIRECTORY = ".git";
|
|
189
|
+
function hasGitDirectory(dir) {
|
|
190
|
+
const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
|
|
191
|
+
return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
|
|
192
|
+
}
|
|
193
|
+
function hasPnpmWorkspaces(dir) {
|
|
194
|
+
return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
|
|
195
|
+
}
|
|
196
|
+
function findRepositoryRoot(startDir) {
|
|
197
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
198
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
199
|
+
}
|
|
200
|
+
let currentDir = startDir || process.cwd();
|
|
201
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
202
|
+
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
203
|
+
return currentDir;
|
|
204
|
+
}
|
|
205
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
206
|
+
}
|
|
207
|
+
throw new Error(
|
|
208
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
213
|
+
var import_node_path2 = require("path");
|
|
214
|
+
var import_node_fs2 = require("fs");
|
|
181
215
|
var import_jsonc_parser = require("jsonc-parser");
|
|
216
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
182
217
|
|
|
183
|
-
// src/config/
|
|
184
|
-
|
|
185
|
-
|
|
218
|
+
// src/config/constants.ts
|
|
219
|
+
var CONFIGURATION_FILENAMES = [
|
|
220
|
+
"microfrontends.jsonc",
|
|
221
|
+
"microfrontends.json"
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
225
|
+
var configCache = {};
|
|
226
|
+
function findDefaultMicrofrontendsPackages({
|
|
227
|
+
repositoryRoot,
|
|
228
|
+
applicationName
|
|
229
|
+
}) {
|
|
230
|
+
try {
|
|
231
|
+
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
232
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
233
|
+
{
|
|
234
|
+
cwd: repositoryRoot,
|
|
235
|
+
absolute: true,
|
|
236
|
+
onlyFiles: true,
|
|
237
|
+
followSymbolicLinks: false,
|
|
238
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
const matchingPaths = [];
|
|
242
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
243
|
+
try {
|
|
244
|
+
const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
|
|
245
|
+
microfrontendsJsonPath,
|
|
246
|
+
"utf-8"
|
|
247
|
+
);
|
|
248
|
+
const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
|
|
249
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
250
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
251
|
+
}
|
|
252
|
+
} catch (error) {
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (matchingPaths.length > 1) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
258
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (matchingPaths.length === 0) {
|
|
262
|
+
throw new Error(
|
|
263
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
const [packageJsonPath] = matchingPaths;
|
|
267
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
273
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
274
|
+
if (configCache[cacheKey]) {
|
|
275
|
+
return configCache[cacheKey];
|
|
276
|
+
}
|
|
277
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
278
|
+
if (!result) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
"Error trying to resolve the main microfrontends configuration"
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
configCache[cacheKey] = result;
|
|
284
|
+
return result;
|
|
186
285
|
}
|
|
187
286
|
|
|
188
|
-
// src/config/
|
|
189
|
-
|
|
190
|
-
|
|
287
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
288
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
289
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
290
|
+
function isMonorepo({
|
|
291
|
+
repositoryRoot
|
|
292
|
+
}) {
|
|
293
|
+
try {
|
|
294
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path3.default.resolve(repositoryRoot)) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
const packageJsonPath = import_node_path3.default.join(repositoryRoot, "package.json");
|
|
304
|
+
if (!import_node_fs3.default.existsSync(packageJsonPath)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
const packageJson = JSON.parse(
|
|
308
|
+
import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
|
|
309
|
+
);
|
|
310
|
+
return packageJson.workspaces !== void 0;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
318
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
319
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
320
|
+
var PACKAGE_JSON = "package.json";
|
|
321
|
+
function findPackageRoot(startDir) {
|
|
322
|
+
let currentDir = startDir || process.cwd();
|
|
323
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
324
|
+
const pkgJsonPath = import_node_path4.default.join(currentDir, PACKAGE_JSON);
|
|
325
|
+
if (import_node_fs4.default.existsSync(pkgJsonPath)) {
|
|
326
|
+
return currentDir;
|
|
327
|
+
}
|
|
328
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
329
|
+
}
|
|
330
|
+
throw new Error(
|
|
331
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
332
|
+
);
|
|
191
333
|
}
|
|
192
334
|
|
|
335
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
336
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
337
|
+
var import_node_path5 = require("path");
|
|
338
|
+
function findConfig({ dir }) {
|
|
339
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
340
|
+
const maybeConfig = (0, import_node_path5.join)(dir, filename);
|
|
341
|
+
if (import_node_fs5.default.existsSync(maybeConfig)) {
|
|
342
|
+
return maybeConfig;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
349
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
350
|
+
|
|
193
351
|
// src/config/microfrontends-config/client/index.ts
|
|
194
352
|
var import_path_to_regexp = require("path-to-regexp");
|
|
195
353
|
var MicrofrontendConfigClient = class {
|
|
@@ -258,6 +416,10 @@ var MicrofrontendConfigClient = class {
|
|
|
258
416
|
|
|
259
417
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
260
418
|
var import_path_to_regexp2 = require("path-to-regexp");
|
|
419
|
+
var LIST_FORMATTER = new Intl.ListFormat("en", {
|
|
420
|
+
style: "long",
|
|
421
|
+
type: "conjunction"
|
|
422
|
+
});
|
|
261
423
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
262
424
|
if (!applicationConfigsById) {
|
|
263
425
|
return;
|
|
@@ -390,15 +552,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
390
552
|
if (!applicationConfigsById) {
|
|
391
553
|
return;
|
|
392
554
|
}
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
);
|
|
396
|
-
const
|
|
397
|
-
(
|
|
555
|
+
const applicationsWithoutRouting = Object.entries(
|
|
556
|
+
applicationConfigsById
|
|
557
|
+
).filter(([, app]) => isDefaultApp(app));
|
|
558
|
+
const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
|
|
559
|
+
(acc) => {
|
|
560
|
+
return acc + 1;
|
|
561
|
+
},
|
|
562
|
+
0
|
|
398
563
|
);
|
|
399
|
-
const numApplications = Object.keys(applicationConfigsById).length;
|
|
400
|
-
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
401
|
-
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
402
564
|
if (numApplicationsWithoutRouting === 0) {
|
|
403
565
|
throw new MicrofrontendError(
|
|
404
566
|
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
@@ -406,8 +568,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
406
568
|
);
|
|
407
569
|
}
|
|
408
570
|
if (numApplicationsWithoutRouting > 1) {
|
|
571
|
+
const applicationNamesMissingRouting = applicationsWithoutRouting.map(
|
|
572
|
+
([name]) => name
|
|
573
|
+
);
|
|
409
574
|
throw new MicrofrontendError(
|
|
410
|
-
`
|
|
575
|
+
`All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
|
|
411
576
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
412
577
|
);
|
|
413
578
|
}
|
|
@@ -718,42 +883,28 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
718
883
|
constructor({
|
|
719
884
|
config,
|
|
720
885
|
overrides,
|
|
721
|
-
meta,
|
|
722
886
|
opts
|
|
723
887
|
}) {
|
|
724
888
|
this.childApplications = {};
|
|
725
889
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
726
890
|
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
727
891
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
app: appConfig,
|
|
735
|
-
overrides: appOverrides
|
|
736
|
-
});
|
|
737
|
-
} else {
|
|
738
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
739
|
-
app: appConfig,
|
|
740
|
-
overrides: appOverrides
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
} else {
|
|
745
|
-
this.partOf = config.partOf;
|
|
746
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
747
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
748
|
-
meta.fromApp,
|
|
749
|
-
{
|
|
750
|
-
// we don't know routing because we're not in the main config
|
|
751
|
-
app: { routing: [] },
|
|
892
|
+
let defaultApplication;
|
|
893
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
894
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
895
|
+
if (isDefaultApp(appConfig)) {
|
|
896
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
897
|
+
app: appConfig,
|
|
752
898
|
overrides: appOverrides
|
|
753
|
-
}
|
|
754
|
-
|
|
899
|
+
});
|
|
900
|
+
} else {
|
|
901
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
902
|
+
app: appConfig,
|
|
903
|
+
overrides: appOverrides
|
|
904
|
+
});
|
|
905
|
+
}
|
|
755
906
|
}
|
|
756
|
-
if (
|
|
907
|
+
if (!defaultApplication) {
|
|
757
908
|
throw new MicrofrontendError(
|
|
758
909
|
"Could not find default application in microfrontends configuration",
|
|
759
910
|
{
|
|
@@ -762,34 +913,30 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
762
913
|
}
|
|
763
914
|
);
|
|
764
915
|
}
|
|
916
|
+
this.defaultApplication = defaultApplication;
|
|
765
917
|
this.config = config;
|
|
766
918
|
this.options = config.options;
|
|
767
919
|
this.serialized = {
|
|
768
920
|
config,
|
|
769
|
-
overrides
|
|
770
|
-
meta
|
|
921
|
+
overrides
|
|
771
922
|
};
|
|
772
923
|
}
|
|
773
924
|
static validate(config, opts) {
|
|
774
925
|
const skipValidation = opts?.skipValidation ?? [];
|
|
775
|
-
const c = typeof config === "string" ? (0,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
validateDeprecatedFields(c);
|
|
781
|
-
}
|
|
926
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
927
|
+
validateConfigPaths(c.applications);
|
|
928
|
+
validateConfigDefaultApplication(c.applications);
|
|
929
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
930
|
+
validateDeprecatedFields(c);
|
|
782
931
|
}
|
|
783
932
|
return c;
|
|
784
933
|
}
|
|
785
934
|
static fromEnv({
|
|
786
|
-
meta,
|
|
787
935
|
cookies
|
|
788
936
|
}) {
|
|
789
937
|
return new MicrofrontendConfigIsomorphic({
|
|
790
|
-
config: (0,
|
|
791
|
-
overrides: parseOverrides(cookies ?? [])
|
|
792
|
-
meta
|
|
938
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
939
|
+
overrides: parseOverrides(cookies ?? [])
|
|
793
940
|
});
|
|
794
941
|
}
|
|
795
942
|
isOverridesDisabled() {
|
|
@@ -814,7 +961,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
814
961
|
].filter(Boolean);
|
|
815
962
|
}
|
|
816
963
|
getApplication(name) {
|
|
817
|
-
if (this.defaultApplication
|
|
964
|
+
if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
|
|
818
965
|
return this.defaultApplication;
|
|
819
966
|
}
|
|
820
967
|
const app = this.childApplications[name] || Object.values(this.childApplications).find(
|
|
@@ -832,7 +979,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
832
979
|
return app;
|
|
833
980
|
}
|
|
834
981
|
getApplicationByProjectId(projectId) {
|
|
835
|
-
if (this.defaultApplication
|
|
982
|
+
if (this.defaultApplication.projectId === projectId) {
|
|
836
983
|
return this.defaultApplication;
|
|
837
984
|
}
|
|
838
985
|
return Object.values(this.childApplications).find(
|
|
@@ -840,19 +987,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
840
987
|
);
|
|
841
988
|
}
|
|
842
989
|
/**
|
|
843
|
-
* Returns the default application.
|
|
844
|
-
* is undefined ( )
|
|
990
|
+
* Returns the default application.
|
|
845
991
|
*/
|
|
846
992
|
getDefaultApplication() {
|
|
847
|
-
if (!this.defaultApplication) {
|
|
848
|
-
throw new MicrofrontendError(
|
|
849
|
-
"Could not find default application in microfrontends configuration",
|
|
850
|
-
{
|
|
851
|
-
type: "application",
|
|
852
|
-
subtype: "not_found"
|
|
853
|
-
}
|
|
854
|
-
);
|
|
855
|
-
}
|
|
856
993
|
return this.defaultApplication;
|
|
857
994
|
}
|
|
858
995
|
/**
|
|
@@ -879,11 +1016,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
879
1016
|
}
|
|
880
1017
|
])
|
|
881
1018
|
);
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
};
|
|
886
|
-
}
|
|
1019
|
+
applications[this.defaultApplication.name] = {
|
|
1020
|
+
default: true
|
|
1021
|
+
};
|
|
887
1022
|
return new MicrofrontendConfigClient({
|
|
888
1023
|
applications
|
|
889
1024
|
});
|
|
@@ -893,301 +1028,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
893
1028
|
}
|
|
894
1029
|
};
|
|
895
1030
|
|
|
896
|
-
// src/config/microfrontends-config/isomorphic/child.ts
|
|
897
|
-
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
898
|
-
constructor({
|
|
899
|
-
config,
|
|
900
|
-
overrides,
|
|
901
|
-
meta
|
|
902
|
-
}) {
|
|
903
|
-
super({ config, overrides, meta });
|
|
904
|
-
this.isMainConfig = false;
|
|
905
|
-
this.partOf = config.partOf;
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
|
|
909
|
-
// src/config/microfrontends-config/isomorphic/main.ts
|
|
910
|
-
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
911
|
-
constructor({
|
|
912
|
-
config,
|
|
913
|
-
overrides,
|
|
914
|
-
meta
|
|
915
|
-
}) {
|
|
916
|
-
super({ config, overrides, meta });
|
|
917
|
-
this.isMainConfig = true;
|
|
918
|
-
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
919
|
-
let defaultApplication;
|
|
920
|
-
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
921
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
922
|
-
if (isDefaultApp(appConfig)) {
|
|
923
|
-
defaultApplication = new DefaultApplication(appId, {
|
|
924
|
-
app: appConfig,
|
|
925
|
-
overrides: appOverrides
|
|
926
|
-
});
|
|
927
|
-
} else {
|
|
928
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
929
|
-
app: appConfig,
|
|
930
|
-
overrides: appOverrides
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
if (!defaultApplication) {
|
|
935
|
-
throw new MicrofrontendError(
|
|
936
|
-
"Could not find default application in microfrontends configuration",
|
|
937
|
-
{
|
|
938
|
-
type: "application",
|
|
939
|
-
subtype: "not_found"
|
|
940
|
-
}
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
this.defaultApplication = defaultApplication;
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
|
|
947
|
-
// src/config/microfrontends/isomorphic/index.ts
|
|
948
|
-
var Microfrontends = class {
|
|
949
|
-
constructor({
|
|
950
|
-
config,
|
|
951
|
-
overrides,
|
|
952
|
-
meta
|
|
953
|
-
}) {
|
|
954
|
-
if (isMainConfig(config)) {
|
|
955
|
-
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
956
|
-
} else {
|
|
957
|
-
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
isChildConfig() {
|
|
961
|
-
return this.config instanceof MicrofrontendChildConfig;
|
|
962
|
-
}
|
|
963
|
-
static fromEnv({
|
|
964
|
-
cookies,
|
|
965
|
-
meta
|
|
966
|
-
}) {
|
|
967
|
-
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
968
|
-
cookies,
|
|
969
|
-
meta
|
|
970
|
-
});
|
|
971
|
-
return new Microfrontends(config.serialize());
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
|
|
975
|
-
// src/config/microfrontends/utils/find-repository-root.ts
|
|
976
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
977
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
978
|
-
var GIT_DIRECTORY = ".git";
|
|
979
|
-
function findRepositoryRoot(startDir) {
|
|
980
|
-
if (process.env.NX_WORKSPACE_ROOT) {
|
|
981
|
-
return process.env.NX_WORKSPACE_ROOT;
|
|
982
|
-
}
|
|
983
|
-
let currentDir = startDir || process.cwd();
|
|
984
|
-
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
985
|
-
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
986
|
-
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
987
|
-
return currentDir;
|
|
988
|
-
}
|
|
989
|
-
currentDir = import_node_path.default.dirname(currentDir);
|
|
990
|
-
}
|
|
991
|
-
throw new Error(
|
|
992
|
-
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
993
|
-
);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// src/config/microfrontends/utils/find-package-path.ts
|
|
997
|
-
var import_node_path2 = require("path");
|
|
998
|
-
var import_node_fs2 = require("fs");
|
|
999
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1000
|
-
var configCache = {};
|
|
1001
|
-
function findPackagePathWithGlob({
|
|
1002
|
-
repositoryRoot,
|
|
1003
|
-
name
|
|
1004
|
-
}) {
|
|
1005
|
-
try {
|
|
1006
|
-
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
1007
|
-
cwd: repositoryRoot,
|
|
1008
|
-
absolute: true,
|
|
1009
|
-
onlyFiles: true,
|
|
1010
|
-
followSymbolicLinks: false,
|
|
1011
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1012
|
-
});
|
|
1013
|
-
const matchingPaths = [];
|
|
1014
|
-
for (const packageJsonPath2 of packageJsonPaths) {
|
|
1015
|
-
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
1016
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1017
|
-
if (packageJson.name === name) {
|
|
1018
|
-
matchingPaths.push(packageJsonPath2);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
if (matchingPaths.length > 1) {
|
|
1022
|
-
throw new Error(
|
|
1023
|
-
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
1024
|
-
);
|
|
1025
|
-
}
|
|
1026
|
-
if (matchingPaths.length === 0) {
|
|
1027
|
-
throw new Error(
|
|
1028
|
-
`Could not find package with the name "${name}" in the repository`
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
const [packageJsonPath] = matchingPaths;
|
|
1032
|
-
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
1033
|
-
} catch (error) {
|
|
1034
|
-
return null;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
function findPackagePath(opts) {
|
|
1038
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
1039
|
-
if (configCache[cacheKey]) {
|
|
1040
|
-
return configCache[cacheKey];
|
|
1041
|
-
}
|
|
1042
|
-
const result = findPackagePathWithGlob(opts);
|
|
1043
|
-
if (!result) {
|
|
1044
|
-
throw new Error(
|
|
1045
|
-
`Could not find package with the name "${opts.name}" in the repository`
|
|
1046
|
-
);
|
|
1047
|
-
}
|
|
1048
|
-
configCache[cacheKey] = result;
|
|
1049
|
-
return result;
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1053
|
-
var import_node_path3 = require("path");
|
|
1054
|
-
var import_node_fs3 = require("fs");
|
|
1055
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
1056
|
-
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1057
|
-
|
|
1058
|
-
// src/config/constants.ts
|
|
1059
|
-
var CONFIGURATION_FILENAMES = [
|
|
1060
|
-
"microfrontends.jsonc",
|
|
1061
|
-
"microfrontends.json"
|
|
1062
|
-
];
|
|
1063
|
-
|
|
1064
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1065
|
-
var configCache2 = {};
|
|
1066
|
-
function findDefaultMicrofrontendsPackages({
|
|
1067
|
-
repositoryRoot,
|
|
1068
|
-
applicationName
|
|
1069
|
-
}) {
|
|
1070
|
-
try {
|
|
1071
|
-
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
1072
|
-
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
1073
|
-
{
|
|
1074
|
-
cwd: repositoryRoot,
|
|
1075
|
-
absolute: true,
|
|
1076
|
-
onlyFiles: true,
|
|
1077
|
-
followSymbolicLinks: false,
|
|
1078
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1079
|
-
}
|
|
1080
|
-
);
|
|
1081
|
-
const matchingPaths = [];
|
|
1082
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1083
|
-
try {
|
|
1084
|
-
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
1085
|
-
microfrontendsJsonPath,
|
|
1086
|
-
"utf-8"
|
|
1087
|
-
);
|
|
1088
|
-
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1089
|
-
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
1090
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1091
|
-
}
|
|
1092
|
-
} catch (error) {
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
if (matchingPaths.length > 1) {
|
|
1096
|
-
throw new Error(
|
|
1097
|
-
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
1098
|
-
${matchingPaths.join("\n \u2022 ")}`
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
|
-
if (matchingPaths.length === 0) {
|
|
1102
|
-
throw new Error(
|
|
1103
|
-
`Could not find default application with "applications.${applicationName}"`
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
const [packageJsonPath] = matchingPaths;
|
|
1107
|
-
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
1108
|
-
} catch (error) {
|
|
1109
|
-
return null;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
function findDefaultMicrofrontendsPackage(opts) {
|
|
1113
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
1114
|
-
if (configCache2[cacheKey]) {
|
|
1115
|
-
return configCache2[cacheKey];
|
|
1116
|
-
}
|
|
1117
|
-
const result = findDefaultMicrofrontendsPackages(opts);
|
|
1118
|
-
if (!result) {
|
|
1119
|
-
throw new Error(
|
|
1120
|
-
"Error trying to resolve the main microfrontends configuration"
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
configCache2[cacheKey] = result;
|
|
1124
|
-
return result;
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1128
|
-
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1129
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
1130
|
-
function isMonorepo({
|
|
1131
|
-
repositoryRoot
|
|
1132
|
-
}) {
|
|
1133
|
-
try {
|
|
1134
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
1135
|
-
return true;
|
|
1136
|
-
}
|
|
1137
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1138
|
-
return true;
|
|
1139
|
-
}
|
|
1140
|
-
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1141
|
-
return true;
|
|
1142
|
-
}
|
|
1143
|
-
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1144
|
-
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1145
|
-
return false;
|
|
1146
|
-
}
|
|
1147
|
-
const packageJson = JSON.parse(
|
|
1148
|
-
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
1149
|
-
);
|
|
1150
|
-
return packageJson.workspaces !== void 0;
|
|
1151
|
-
} catch (error) {
|
|
1152
|
-
console.error("Error determining if repository is a monorepo", error);
|
|
1153
|
-
return false;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
// src/config/microfrontends/utils/find-package-root.ts
|
|
1158
|
-
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1159
|
-
var import_node_path5 = __toESM(require("path"), 1);
|
|
1160
|
-
var PACKAGE_JSON = "package.json";
|
|
1161
|
-
function findPackageRoot(startDir) {
|
|
1162
|
-
let currentDir = startDir || process.cwd();
|
|
1163
|
-
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1164
|
-
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1165
|
-
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
1166
|
-
return currentDir;
|
|
1167
|
-
}
|
|
1168
|
-
currentDir = import_node_path5.default.dirname(currentDir);
|
|
1169
|
-
}
|
|
1170
|
-
throw new Error(
|
|
1171
|
-
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
1176
|
-
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1177
|
-
var import_node_path6 = require("path");
|
|
1178
|
-
function findConfig({ dir }) {
|
|
1179
|
-
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1180
|
-
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1181
|
-
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1182
|
-
return maybeConfig;
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
return null;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1031
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1189
|
-
var
|
|
1190
|
-
var
|
|
1032
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1033
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
1191
1034
|
function getApplicationContext(opts) {
|
|
1192
1035
|
if (opts?.appName) {
|
|
1193
1036
|
return { name: opts.appName };
|
|
@@ -1196,8 +1039,8 @@ function getApplicationContext(opts) {
|
|
|
1196
1039
|
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1197
1040
|
}
|
|
1198
1041
|
try {
|
|
1199
|
-
const packageJsonString =
|
|
1200
|
-
|
|
1042
|
+
const packageJsonString = import_node_fs6.default.readFileSync(
|
|
1043
|
+
import_node_path6.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1201
1044
|
"utf-8"
|
|
1202
1045
|
);
|
|
1203
1046
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1220,7 +1063,7 @@ function getApplicationContext(opts) {
|
|
|
1220
1063
|
}
|
|
1221
1064
|
|
|
1222
1065
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1223
|
-
var
|
|
1066
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1224
1067
|
|
|
1225
1068
|
// src/config/microfrontends/server/constants.ts
|
|
1226
1069
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1228,7 +1071,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1228
1071
|
|
|
1229
1072
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1230
1073
|
function getOutputFilePath() {
|
|
1231
|
-
return
|
|
1074
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1232
1075
|
}
|
|
1233
1076
|
|
|
1234
1077
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1241,16 +1084,6 @@ var schema_default = {
|
|
|
1241
1084
|
$ref: "#/definitions/Config",
|
|
1242
1085
|
definitions: {
|
|
1243
1086
|
Config: {
|
|
1244
|
-
anyOf: [
|
|
1245
|
-
{
|
|
1246
|
-
$ref: "#/definitions/MainConfig"
|
|
1247
|
-
},
|
|
1248
|
-
{
|
|
1249
|
-
$ref: "#/definitions/ChildConfig"
|
|
1250
|
-
}
|
|
1251
|
-
]
|
|
1252
|
-
},
|
|
1253
|
-
MainConfig: {
|
|
1254
1087
|
type: "object",
|
|
1255
1088
|
properties: {
|
|
1256
1089
|
$schema: {
|
|
@@ -1507,27 +1340,6 @@ var schema_default = {
|
|
|
1507
1340
|
},
|
|
1508
1341
|
required: ["paths"],
|
|
1509
1342
|
additionalProperties: false
|
|
1510
|
-
},
|
|
1511
|
-
ChildConfig: {
|
|
1512
|
-
type: "object",
|
|
1513
|
-
properties: {
|
|
1514
|
-
$schema: {
|
|
1515
|
-
type: "string"
|
|
1516
|
-
},
|
|
1517
|
-
version: {
|
|
1518
|
-
type: "string",
|
|
1519
|
-
const: "1"
|
|
1520
|
-
},
|
|
1521
|
-
options: {
|
|
1522
|
-
$ref: "#/definitions/Options"
|
|
1523
|
-
},
|
|
1524
|
-
partOf: {
|
|
1525
|
-
type: "string",
|
|
1526
|
-
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."
|
|
1527
|
-
}
|
|
1528
|
-
},
|
|
1529
|
-
required: ["partOf"],
|
|
1530
|
-
additionalProperties: false
|
|
1531
1343
|
}
|
|
1532
1344
|
}
|
|
1533
1345
|
};
|
|
@@ -1536,13 +1348,54 @@ var schema_default = {
|
|
|
1536
1348
|
var SCHEMA = schema_default;
|
|
1537
1349
|
|
|
1538
1350
|
// src/config/microfrontends/server/validation.ts
|
|
1539
|
-
|
|
1351
|
+
var LIST_FORMATTER2 = new Intl.ListFormat("en", {
|
|
1352
|
+
style: "long",
|
|
1353
|
+
type: "disjunction"
|
|
1354
|
+
});
|
|
1355
|
+
function formatAjvErrors(errors) {
|
|
1540
1356
|
if (!errors) {
|
|
1541
1357
|
return [];
|
|
1542
1358
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1359
|
+
const errorMessages = [];
|
|
1360
|
+
for (const error of errors) {
|
|
1361
|
+
if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
const instancePath = error.instancePath.slice(1);
|
|
1365
|
+
const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
|
|
1366
|
+
if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
|
|
1367
|
+
errorMessages.push(
|
|
1368
|
+
`Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
|
|
1369
|
+
);
|
|
1370
|
+
} else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
|
|
1371
|
+
const anyOfErrors = errors.filter(
|
|
1372
|
+
(e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
|
|
1373
|
+
);
|
|
1374
|
+
if (anyOfErrors.every((e) => e.keyword === "type")) {
|
|
1375
|
+
const allowedTypes = LIST_FORMATTER2.format(
|
|
1376
|
+
anyOfErrors.map((e) => {
|
|
1377
|
+
return e.keyword === "type" ? String(e.params.type) : "unknown";
|
|
1378
|
+
})
|
|
1379
|
+
);
|
|
1380
|
+
errorMessages.push(
|
|
1381
|
+
`Incorrect type for ${instancePath}. Must be one of ${allowedTypes}`
|
|
1382
|
+
);
|
|
1383
|
+
} else {
|
|
1384
|
+
errorMessages.push(
|
|
1385
|
+
`Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
} else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
|
|
1389
|
+
errorMessages.push(
|
|
1390
|
+
`Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
|
|
1391
|
+
);
|
|
1392
|
+
} else if (error.keyword === "required") {
|
|
1393
|
+
errorMessages.push(
|
|
1394
|
+
`Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return errorMessages;
|
|
1546
1399
|
}
|
|
1547
1400
|
function validateSchema(configString) {
|
|
1548
1401
|
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
@@ -1551,8 +1404,10 @@ function validateSchema(configString) {
|
|
|
1551
1404
|
const isValid = validate(parsedConfig);
|
|
1552
1405
|
if (!isValid) {
|
|
1553
1406
|
throw new MicrofrontendError(
|
|
1554
|
-
`Invalid microfrontends config
|
|
1555
|
-
- ${
|
|
1407
|
+
`Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
|
|
1408
|
+
- ${error}`).join(
|
|
1409
|
+
""
|
|
1410
|
+
)}
|
|
1556
1411
|
|
|
1557
1412
|
See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
1558
1413
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
@@ -1562,7 +1417,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
|
1562
1417
|
}
|
|
1563
1418
|
|
|
1564
1419
|
// src/config/microfrontends/server/index.ts
|
|
1565
|
-
var MicrofrontendsServer = class
|
|
1420
|
+
var MicrofrontendsServer = class {
|
|
1421
|
+
constructor({
|
|
1422
|
+
config,
|
|
1423
|
+
overrides
|
|
1424
|
+
}) {
|
|
1425
|
+
this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
|
|
1426
|
+
}
|
|
1566
1427
|
/**
|
|
1567
1428
|
* Writes the configuration to a file.
|
|
1568
1429
|
*/
|
|
@@ -1570,8 +1431,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1570
1431
|
pretty: true
|
|
1571
1432
|
}) {
|
|
1572
1433
|
const outputPath = getOutputFilePath();
|
|
1573
|
-
|
|
1574
|
-
|
|
1434
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1435
|
+
import_node_fs7.default.writeFileSync(
|
|
1575
1436
|
outputPath,
|
|
1576
1437
|
JSON.stringify(
|
|
1577
1438
|
this.config.toSchemaJson(),
|
|
@@ -1586,22 +1447,19 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1586
1447
|
*/
|
|
1587
1448
|
static fromUnknown({
|
|
1588
1449
|
config,
|
|
1589
|
-
cookies
|
|
1590
|
-
meta
|
|
1450
|
+
cookies
|
|
1591
1451
|
}) {
|
|
1592
1452
|
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1593
1453
|
if (typeof config === "string") {
|
|
1594
1454
|
return new MicrofrontendsServer({
|
|
1595
1455
|
config: MicrofrontendsServer.validate(config),
|
|
1596
|
-
overrides
|
|
1597
|
-
meta
|
|
1456
|
+
overrides
|
|
1598
1457
|
});
|
|
1599
1458
|
}
|
|
1600
1459
|
if (typeof config === "object") {
|
|
1601
1460
|
return new MicrofrontendsServer({
|
|
1602
1461
|
config,
|
|
1603
|
-
overrides
|
|
1604
|
-
meta
|
|
1462
|
+
overrides
|
|
1605
1463
|
});
|
|
1606
1464
|
}
|
|
1607
1465
|
throw new MicrofrontendError(
|
|
@@ -1614,13 +1472,11 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1614
1472
|
* Uses additional validation that is only available when in a node runtime
|
|
1615
1473
|
*/
|
|
1616
1474
|
static fromEnv({
|
|
1617
|
-
cookies
|
|
1618
|
-
meta
|
|
1475
|
+
cookies
|
|
1619
1476
|
}) {
|
|
1620
1477
|
return new MicrofrontendsServer({
|
|
1621
1478
|
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1622
|
-
overrides: parseOverrides(cookies)
|
|
1623
|
-
meta
|
|
1479
|
+
overrides: parseOverrides(cookies)
|
|
1624
1480
|
});
|
|
1625
1481
|
}
|
|
1626
1482
|
/**
|
|
@@ -1643,29 +1499,22 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1643
1499
|
static infer({
|
|
1644
1500
|
directory,
|
|
1645
1501
|
filePath,
|
|
1646
|
-
|
|
1647
|
-
cookies,
|
|
1648
|
-
options
|
|
1502
|
+
cookies
|
|
1649
1503
|
} = {}) {
|
|
1650
|
-
if (filePath
|
|
1504
|
+
if (filePath) {
|
|
1651
1505
|
return MicrofrontendsServer.fromFile({
|
|
1652
1506
|
filePath,
|
|
1653
|
-
cookies
|
|
1654
|
-
meta,
|
|
1655
|
-
options
|
|
1507
|
+
cookies
|
|
1656
1508
|
});
|
|
1657
1509
|
}
|
|
1658
1510
|
try {
|
|
1659
1511
|
const packageRoot = findPackageRoot(directory);
|
|
1660
1512
|
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1661
|
-
const configMeta = meta ?? { fromApp: appName };
|
|
1662
1513
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1663
1514
|
if (maybeConfig) {
|
|
1664
1515
|
return MicrofrontendsServer.fromFile({
|
|
1665
1516
|
filePath: maybeConfig,
|
|
1666
|
-
cookies
|
|
1667
|
-
meta: configMeta,
|
|
1668
|
-
options
|
|
1517
|
+
cookies
|
|
1669
1518
|
});
|
|
1670
1519
|
}
|
|
1671
1520
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1679,14 +1528,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1679
1528
|
if (maybeConfigFromDefault) {
|
|
1680
1529
|
return MicrofrontendsServer.fromFile({
|
|
1681
1530
|
filePath: maybeConfigFromDefault,
|
|
1682
|
-
cookies
|
|
1683
|
-
meta: configMeta,
|
|
1684
|
-
options
|
|
1531
|
+
cookies
|
|
1685
1532
|
});
|
|
1686
1533
|
}
|
|
1687
1534
|
}
|
|
1688
1535
|
throw new Error("Unable to infer");
|
|
1689
1536
|
} catch (e) {
|
|
1537
|
+
if (e instanceof MicrofrontendError) {
|
|
1538
|
+
throw e;
|
|
1539
|
+
}
|
|
1690
1540
|
throw new MicrofrontendError(
|
|
1691
1541
|
"Unable to locate and parse microfrontends configuration",
|
|
1692
1542
|
{ cause: e, type: "config", subtype: "inference_failed" }
|
|
@@ -1698,44 +1548,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1698
1548
|
*/
|
|
1699
1549
|
static fromFile({
|
|
1700
1550
|
filePath,
|
|
1701
|
-
cookies
|
|
1702
|
-
meta,
|
|
1703
|
-
options
|
|
1551
|
+
cookies
|
|
1704
1552
|
}) {
|
|
1705
1553
|
try {
|
|
1706
|
-
const configJson =
|
|
1554
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1707
1555
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1708
|
-
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1709
|
-
const repositoryRoot = findRepositoryRoot();
|
|
1710
|
-
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1711
|
-
if (isMonorepo2) {
|
|
1712
|
-
const packagePath = findPackagePath({
|
|
1713
|
-
repositoryRoot,
|
|
1714
|
-
name: config.partOf
|
|
1715
|
-
});
|
|
1716
|
-
if (!packagePath) {
|
|
1717
|
-
throw new MicrofrontendError(
|
|
1718
|
-
`Could not find default application "${config.partOf}" in the repository`,
|
|
1719
|
-
{ type: "config", subtype: "not_found" }
|
|
1720
|
-
);
|
|
1721
|
-
}
|
|
1722
|
-
const maybeConfig = findConfig({ dir: packagePath });
|
|
1723
|
-
if (!maybeConfig) {
|
|
1724
|
-
throw new MicrofrontendError(
|
|
1725
|
-
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1726
|
-
{ type: "config", subtype: "not_found" }
|
|
1727
|
-
);
|
|
1728
|
-
}
|
|
1729
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1730
|
-
filePath: maybeConfig,
|
|
1731
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
1556
|
return new MicrofrontendsServer({
|
|
1736
1557
|
config,
|
|
1737
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1738
|
-
meta
|
|
1558
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1739
1559
|
});
|
|
1740
1560
|
} catch (e) {
|
|
1741
1561
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1744,24 +1564,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1744
1564
|
}
|
|
1745
1565
|
}
|
|
1746
1566
|
/*
|
|
1747
|
-
* Generates a
|
|
1567
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1748
1568
|
*/
|
|
1749
1569
|
static fromMainConfigFile({
|
|
1750
1570
|
filePath,
|
|
1751
1571
|
overrides
|
|
1752
1572
|
}) {
|
|
1753
1573
|
try {
|
|
1754
|
-
const config =
|
|
1574
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1755
1575
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1756
|
-
if (!isMainConfig(validatedConfig)) {
|
|
1757
|
-
throw new MicrofrontendError(
|
|
1758
|
-
`${filePath} is not a main microfrontend config`,
|
|
1759
|
-
{
|
|
1760
|
-
type: "config",
|
|
1761
|
-
subtype: "invalid_main_path"
|
|
1762
|
-
}
|
|
1763
|
-
);
|
|
1764
|
-
}
|
|
1765
1576
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1766
1577
|
if (!defaultApplication) {
|
|
1767
1578
|
throw new MicrofrontendError(
|
|
@@ -1771,8 +1582,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1771
1582
|
}
|
|
1772
1583
|
return new MicrofrontendsServer({
|
|
1773
1584
|
config: validatedConfig,
|
|
1774
|
-
overrides
|
|
1775
|
-
meta: { fromApp: defaultApplication }
|
|
1585
|
+
overrides
|
|
1776
1586
|
});
|
|
1777
1587
|
} catch (e) {
|
|
1778
1588
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1800,8 +1610,8 @@ function mfePort(packageDir) {
|
|
|
1800
1610
|
};
|
|
1801
1611
|
}
|
|
1802
1612
|
function getPackageJson(packageDir) {
|
|
1803
|
-
const filePath =
|
|
1804
|
-
return JSON.parse(
|
|
1613
|
+
const filePath = import_node_path9.default.join(packageDir, "package.json");
|
|
1614
|
+
return JSON.parse(import_node_fs8.default.readFileSync(filePath, "utf-8"));
|
|
1805
1615
|
}
|
|
1806
1616
|
function loadConfig({
|
|
1807
1617
|
packageDir,
|
|
@@ -1810,9 +1620,7 @@ function loadConfig({
|
|
|
1810
1620
|
let config;
|
|
1811
1621
|
try {
|
|
1812
1622
|
config = MicrofrontendsServer.infer({
|
|
1813
|
-
directory: packageDir
|
|
1814
|
-
meta: { fromApp: appName },
|
|
1815
|
-
options: { resolveMainConfig: true }
|
|
1623
|
+
directory: packageDir
|
|
1816
1624
|
});
|
|
1817
1625
|
} catch (e) {
|
|
1818
1626
|
return void 0;
|