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