@vercel/microfrontends 0.10.0 → 0.11.0
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/README.md +5 -5
- package/dist/bin/cli.cjs +346 -90
- package/dist/config/client.d.ts +1 -1
- package/dist/config/edge.d.ts +2 -2
- package/dist/config.cjs +1 -6
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +1 -6
- package/dist/config.js.map +1 -1
- package/dist/{index-05742bef.d.ts → index-a99d5459.d.ts} +2 -2
- package/dist/{microfrontend-config-2425db74.d.ts → microfrontend-config-983a5139.d.ts} +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +13 -11
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +13 -11
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +22 -8
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +22 -8
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +1 -6
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +2 -2
- package/dist/next/testing.js +1 -6
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.d.ts +2 -2
- package/dist/{schema-83a75e61.d.ts → schema-2922d49e.d.ts} +1 -7
- package/dist/{types-4fd1c7c6.d.ts → types-0030abae.d.ts} +1 -8
- package/dist/{types-13f3e535.d.ts → types-c777c2f5.d.ts} +1 -1
- package/dist/v2/config.cjs +1 -1
- package/dist/v2/config.cjs.map +1 -1
- package/dist/v2/config.d.ts +3 -3
- package/dist/v2/config.js +1 -1
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +296 -36
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +26 -4
- package/dist/v2/microfrontends/server.js +296 -36
- package/dist/v2/microfrontends/server.js.map +1 -1
- package/dist/v2/microfrontends.cjs +1 -1
- package/dist/v2/microfrontends.cjs.map +1 -1
- package/dist/v2/microfrontends.d.ts +3 -3
- package/dist/v2/microfrontends.js +1 -1
- package/dist/v2/microfrontends.js.map +1 -1
- package/dist/v2/next/client.cjs +1 -1
- package/dist/v2/next/client.cjs.map +1 -1
- package/dist/v2/next/client.js +1 -1
- package/dist/v2/next/client.js.map +1 -1
- package/dist/v2/next/config.cjs +331 -68
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.js +331 -68
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/endpoints.cjs +5 -2
- package/dist/v2/next/endpoints.cjs.map +1 -1
- package/dist/v2/next/endpoints.d.ts +1 -1
- package/dist/v2/next/endpoints.js +5 -2
- package/dist/v2/next/endpoints.js.map +1 -1
- package/dist/v2/next/middleware.cjs +108 -88
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.js +108 -88
- package/dist/v2/next/middleware.js.map +1 -1
- package/dist/v2/overrides.cjs +1 -1
- package/dist/v2/overrides.cjs.map +1 -1
- package/dist/v2/overrides.d.ts +3 -3
- package/dist/v2/overrides.js +1 -1
- package/dist/v2/overrides.js.map +1 -1
- package/dist/v2/schema.cjs.map +1 -1
- package/dist/v2/schema.d.ts +1 -1
- package/dist/validation.cjs +0 -11
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +2 -9
- package/dist/validation.js +0 -11
- package/dist/validation.js.map +1 -1
- package/package.json +8 -7
- package/schema/schema-v2.json +0 -7
- package/schema/schema.json +0 -4
|
@@ -33,11 +33,11 @@ __export(server_exports, {
|
|
|
33
33
|
MicrofrontendsServer: () => MicrofrontendsServer
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(server_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
37
|
+
var import_node_path7 = require("path");
|
|
38
38
|
|
|
39
39
|
// src/config-v2/overrides/constants.ts
|
|
40
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-
|
|
40
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
41
41
|
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
42
42
|
|
|
43
43
|
// src/config-v2/overrides/is-override-cookie.ts
|
|
@@ -218,21 +218,21 @@ var MicrofrontendConfigClient = class {
|
|
|
218
218
|
isEqual(other) {
|
|
219
219
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
220
220
|
}
|
|
221
|
-
getApplicationNameForPath(
|
|
222
|
-
if (!
|
|
221
|
+
getApplicationNameForPath(path5) {
|
|
222
|
+
if (!path5.startsWith("/")) {
|
|
223
223
|
throw new Error(`Path must start with a /`);
|
|
224
224
|
}
|
|
225
|
-
if (this.pathCache[
|
|
226
|
-
return this.pathCache[
|
|
225
|
+
if (this.pathCache[path5]) {
|
|
226
|
+
return this.pathCache[path5];
|
|
227
227
|
}
|
|
228
|
-
const pathname = new URL(
|
|
228
|
+
const pathname = new URL(path5, "https://example.com").pathname;
|
|
229
229
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
230
230
|
if (application.routing) {
|
|
231
231
|
for (const group of application.routing) {
|
|
232
232
|
for (const childPath of group.paths) {
|
|
233
233
|
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
234
234
|
if (regexp.test(pathname)) {
|
|
235
|
-
this.pathCache[
|
|
235
|
+
this.pathCache[path5] = name;
|
|
236
236
|
return name;
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -245,7 +245,7 @@ var MicrofrontendConfigClient = class {
|
|
|
245
245
|
if (!defaultApplication) {
|
|
246
246
|
return null;
|
|
247
247
|
}
|
|
248
|
-
this.pathCache[
|
|
248
|
+
this.pathCache[path5] = defaultApplication[0];
|
|
249
249
|
return defaultApplication[0];
|
|
250
250
|
}
|
|
251
251
|
serialize() {
|
|
@@ -277,22 +277,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
277
277
|
continue;
|
|
278
278
|
}
|
|
279
279
|
for (const pathMatch of app.routing) {
|
|
280
|
-
for (const
|
|
281
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
280
|
+
for (const path5 of pathMatch.paths) {
|
|
281
|
+
const tokens = (0, import_path_to_regexp2.parse)(path5);
|
|
282
282
|
for (const token of tokens.slice(0, -1)) {
|
|
283
283
|
if (typeof token !== "string") {
|
|
284
284
|
errors.push(
|
|
285
|
-
`Path ${
|
|
285
|
+
`Path ${path5} may only have a :wildcard in the last path component`
|
|
286
286
|
);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
const existing = pathsByApplicationId.get(
|
|
289
|
+
const existing = pathsByApplicationId.get(path5);
|
|
290
290
|
if (existing) {
|
|
291
291
|
existing.applications.push(id);
|
|
292
292
|
} else {
|
|
293
|
-
pathsByApplicationId.set(
|
|
293
|
+
pathsByApplicationId.set(path5, {
|
|
294
294
|
applications: [id],
|
|
295
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
295
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
|
|
296
296
|
applicationId: id
|
|
297
297
|
});
|
|
298
298
|
}
|
|
@@ -300,10 +300,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
303
|
-
entries.forEach(([
|
|
303
|
+
entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
|
|
304
304
|
if (ids.length > 1) {
|
|
305
305
|
errors.push(
|
|
306
|
-
`Duplicate path "${
|
|
306
|
+
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
307
307
|
);
|
|
308
308
|
}
|
|
309
309
|
entries.forEach(
|
|
@@ -311,14 +311,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
311
311
|
matchPath,
|
|
312
312
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
313
313
|
]) => {
|
|
314
|
-
if (
|
|
314
|
+
if (path5 === matchPath) {
|
|
315
315
|
return;
|
|
316
316
|
}
|
|
317
317
|
if (applicationId === matchApplicationId) {
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
if (matcher.test(matchPath)) {
|
|
321
|
-
const source = `"${
|
|
321
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
322
322
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
323
323
|
errors.push(
|
|
324
324
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -809,8 +809,189 @@ var Microfrontends = class {
|
|
|
809
809
|
}
|
|
810
810
|
};
|
|
811
811
|
|
|
812
|
-
// src/config-v2/microfrontends/
|
|
812
|
+
// src/config-v2/microfrontends/utils/find-repository-root.ts
|
|
813
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
813
814
|
var import_node_path = __toESM(require("path"), 1);
|
|
815
|
+
var GIT_DIRECTORY = ".git";
|
|
816
|
+
function findRepositoryRoot(startDir) {
|
|
817
|
+
let currentDir = startDir || process.cwd();
|
|
818
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
819
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
820
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
821
|
+
return currentDir;
|
|
822
|
+
}
|
|
823
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
824
|
+
}
|
|
825
|
+
throw new Error(
|
|
826
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// src/config-v2/microfrontends/utils/find-package-path.ts
|
|
831
|
+
var import_node_path2 = require("path");
|
|
832
|
+
var import_node_fs2 = require("fs");
|
|
833
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
834
|
+
var configCache = {};
|
|
835
|
+
function findPackagePathWithGlob({
|
|
836
|
+
repositoryRoot,
|
|
837
|
+
name
|
|
838
|
+
}) {
|
|
839
|
+
try {
|
|
840
|
+
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
841
|
+
cwd: repositoryRoot,
|
|
842
|
+
absolute: true,
|
|
843
|
+
onlyFiles: true,
|
|
844
|
+
followSymbolicLinks: false,
|
|
845
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
846
|
+
});
|
|
847
|
+
const matchingPaths = [];
|
|
848
|
+
for (const packageJsonPath2 of packageJsonPaths) {
|
|
849
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
850
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
851
|
+
if (packageJson.name === name) {
|
|
852
|
+
matchingPaths.push(packageJsonPath2);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (matchingPaths.length > 1) {
|
|
856
|
+
throw new Error(
|
|
857
|
+
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
if (matchingPaths.length === 0) {
|
|
861
|
+
throw new Error(
|
|
862
|
+
`Could not find package with the name "${name}" in the repository`
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
const [packageJsonPath] = matchingPaths;
|
|
866
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
867
|
+
} catch (error) {
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
function findPackagePath(opts) {
|
|
872
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
873
|
+
if (configCache[cacheKey]) {
|
|
874
|
+
return configCache[cacheKey];
|
|
875
|
+
}
|
|
876
|
+
const result = findPackagePathWithGlob(opts);
|
|
877
|
+
if (!result) {
|
|
878
|
+
throw new Error(
|
|
879
|
+
`Could not find package with the name "${opts.name}" in the repository`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
configCache[cacheKey] = result;
|
|
883
|
+
return result;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
887
|
+
var import_node_path3 = require("path");
|
|
888
|
+
var import_node_fs3 = require("fs");
|
|
889
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
890
|
+
var configCache2 = {};
|
|
891
|
+
function findDefaultMicrofrontendsPackages({
|
|
892
|
+
repositoryRoot,
|
|
893
|
+
applicationName
|
|
894
|
+
}) {
|
|
895
|
+
try {
|
|
896
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync("**/microfrontends.json", {
|
|
897
|
+
cwd: repositoryRoot,
|
|
898
|
+
absolute: true,
|
|
899
|
+
onlyFiles: true,
|
|
900
|
+
followSymbolicLinks: false,
|
|
901
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
902
|
+
});
|
|
903
|
+
const matchingPaths = [];
|
|
904
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
905
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
906
|
+
microfrontendsJsonPath,
|
|
907
|
+
"utf-8"
|
|
908
|
+
);
|
|
909
|
+
const microfrontendsJson = JSON.parse(
|
|
910
|
+
microfrontendsJsonContent
|
|
911
|
+
);
|
|
912
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
913
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (matchingPaths.length > 1) {
|
|
917
|
+
throw new Error(
|
|
918
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
919
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
if (matchingPaths.length === 0) {
|
|
923
|
+
throw new Error(
|
|
924
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
const [packageJsonPath] = matchingPaths;
|
|
928
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
929
|
+
} catch (error) {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
934
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
935
|
+
if (configCache2[cacheKey]) {
|
|
936
|
+
return configCache2[cacheKey];
|
|
937
|
+
}
|
|
938
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
939
|
+
if (!result) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
`Error trying to resolve the main microfrontends.json configuration`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
configCache2[cacheKey] = result;
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/config-v2/microfrontends/utils/is-monorepo.ts
|
|
949
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
950
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
951
|
+
function isMonorepo({
|
|
952
|
+
repositoryRoot
|
|
953
|
+
}) {
|
|
954
|
+
try {
|
|
955
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
962
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
const packageJson = JSON.parse(
|
|
966
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
967
|
+
);
|
|
968
|
+
return packageJson.workspaces !== void 0;
|
|
969
|
+
} catch (error) {
|
|
970
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/config-v2/microfrontends/utils/find-package-root.ts
|
|
976
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
977
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
978
|
+
var PACKAGE_JSON = "package.json";
|
|
979
|
+
function findPackageRoot(startDir) {
|
|
980
|
+
let currentDir = startDir || process.cwd();
|
|
981
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
982
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
983
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
984
|
+
return currentDir;
|
|
985
|
+
}
|
|
986
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
987
|
+
}
|
|
988
|
+
throw new Error(
|
|
989
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
994
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
814
995
|
|
|
815
996
|
// src/config-v2/microfrontends/server/constants.ts
|
|
816
997
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -824,13 +1005,13 @@ function isVercel() {
|
|
|
824
1005
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
825
1006
|
function getOutputFilePath() {
|
|
826
1007
|
if (isVercel()) {
|
|
827
|
-
return
|
|
1008
|
+
return import_node_path6.default.join(
|
|
828
1009
|
".vercel",
|
|
829
1010
|
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
830
1011
|
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
831
1012
|
);
|
|
832
1013
|
}
|
|
833
|
-
return
|
|
1014
|
+
return import_node_path6.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
834
1015
|
}
|
|
835
1016
|
|
|
836
1017
|
// src/config-v2/microfrontends/server/validation.ts
|
|
@@ -1044,9 +1225,6 @@ var schema_v2_default = {
|
|
|
1044
1225
|
projectId: {
|
|
1045
1226
|
type: "string",
|
|
1046
1227
|
description: "Vercel project ID"
|
|
1047
|
-
},
|
|
1048
|
-
routeSpeedInsightsToDefaultZone: {
|
|
1049
|
-
type: "boolean"
|
|
1050
1228
|
}
|
|
1051
1229
|
},
|
|
1052
1230
|
required: ["projectId"]
|
|
@@ -1140,10 +1318,6 @@ var schema_v2_default = {
|
|
|
1140
1318
|
type: "string",
|
|
1141
1319
|
description: "flag name that can be used to enable/disable all paths in the group"
|
|
1142
1320
|
},
|
|
1143
|
-
routeToDefaultApplication: {
|
|
1144
|
-
type: "boolean",
|
|
1145
|
-
description: "True to route the request to the default application for this micro-frontends set-up. This must be `true` when using `flag` or when you want to use custom logic to make the routing decision for this group of paths."
|
|
1146
|
-
},
|
|
1147
1321
|
paths: {
|
|
1148
1322
|
type: "array",
|
|
1149
1323
|
items: {
|
|
@@ -1220,8 +1394,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1220
1394
|
pretty: true
|
|
1221
1395
|
}) {
|
|
1222
1396
|
const outputPath = getOutputFilePath();
|
|
1223
|
-
|
|
1224
|
-
|
|
1397
|
+
import_node_fs6.default.mkdirSync((0, import_node_path7.dirname)(outputPath), { recursive: true });
|
|
1398
|
+
import_node_fs6.default.writeFileSync(
|
|
1225
1399
|
outputPath,
|
|
1226
1400
|
JSON.stringify(
|
|
1227
1401
|
this.config.toSchemaJson(),
|
|
@@ -1283,18 +1457,104 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1283
1457
|
}
|
|
1284
1458
|
return config;
|
|
1285
1459
|
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
|
|
1462
|
+
* it will look for a package in the repository with a microfrontends.json file that contains the current application
|
|
1463
|
+
* and use that configuration.
|
|
1464
|
+
*
|
|
1465
|
+
* This can return either a Child or Main configuration.
|
|
1466
|
+
*/
|
|
1467
|
+
static infer({
|
|
1468
|
+
directory,
|
|
1469
|
+
filePath,
|
|
1470
|
+
meta,
|
|
1471
|
+
cookies,
|
|
1472
|
+
options
|
|
1473
|
+
} = {}) {
|
|
1474
|
+
if (filePath && meta) {
|
|
1475
|
+
return MicrofrontendsServer.fromFile({
|
|
1476
|
+
filePath,
|
|
1477
|
+
cookies,
|
|
1478
|
+
meta,
|
|
1479
|
+
options
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
try {
|
|
1483
|
+
const packageRoot = findPackageRoot(directory);
|
|
1484
|
+
const packageJsonPath = (0, import_node_path7.join)(packageRoot, "package.json");
|
|
1485
|
+
const packageJson = JSON.parse(
|
|
1486
|
+
import_node_fs6.default.readFileSync(packageJsonPath, "utf-8")
|
|
1487
|
+
);
|
|
1488
|
+
if (!packageJson.name) {
|
|
1489
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1490
|
+
}
|
|
1491
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1492
|
+
const maybeConfig = (0, import_node_path7.join)(packageRoot, "microfrontends.json");
|
|
1493
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1494
|
+
return MicrofrontendsServer.fromFile({
|
|
1495
|
+
filePath: maybeConfig,
|
|
1496
|
+
cookies,
|
|
1497
|
+
meta: configMeta,
|
|
1498
|
+
options
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1502
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1503
|
+
if (isMonorepo2) {
|
|
1504
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1505
|
+
repositoryRoot,
|
|
1506
|
+
applicationName: packageJson.name
|
|
1507
|
+
});
|
|
1508
|
+
return MicrofrontendsServer.fromFile({
|
|
1509
|
+
filePath: (0, import_node_path7.join)(defaultPackage, "microfrontends.json"),
|
|
1510
|
+
cookies,
|
|
1511
|
+
meta: configMeta,
|
|
1512
|
+
options
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
throw new Error("Unable to infer");
|
|
1516
|
+
} catch (e) {
|
|
1517
|
+
throw new MicrofrontendError(
|
|
1518
|
+
"Unable to infer microfrontends configuration",
|
|
1519
|
+
{ type: "config", subtype: "inference_failed" }
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1286
1523
|
/*
|
|
1287
1524
|
* Generates a MicrofrontendsServer instance from a file.
|
|
1288
1525
|
*/
|
|
1289
1526
|
static fromFile({
|
|
1290
1527
|
filePath,
|
|
1291
1528
|
cookies,
|
|
1292
|
-
meta
|
|
1529
|
+
meta,
|
|
1530
|
+
options
|
|
1293
1531
|
}) {
|
|
1294
1532
|
try {
|
|
1295
|
-
const
|
|
1533
|
+
const configJson = import_node_fs6.default.readFileSync(filePath, "utf-8");
|
|
1534
|
+
const config = MicrofrontendsServer.validate(configJson);
|
|
1535
|
+
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1536
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1537
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1538
|
+
if (isMonorepo2) {
|
|
1539
|
+
const packagePath = findPackagePath({
|
|
1540
|
+
repositoryRoot,
|
|
1541
|
+
name: config.partOf
|
|
1542
|
+
});
|
|
1543
|
+
if (!packagePath) {
|
|
1544
|
+
throw new MicrofrontendError(
|
|
1545
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1546
|
+
{ type: "config", subtype: "not_found" }
|
|
1547
|
+
);
|
|
1548
|
+
}
|
|
1549
|
+
const mainConfigPath = (0, import_node_path7.join)(packagePath, "microfrontends.json");
|
|
1550
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1551
|
+
filePath: mainConfigPath,
|
|
1552
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1296
1556
|
return new MicrofrontendsServer({
|
|
1297
|
-
config
|
|
1557
|
+
config,
|
|
1298
1558
|
overrides: cookies ? parseOverrides(cookies) : void 0,
|
|
1299
1559
|
meta
|
|
1300
1560
|
});
|
|
@@ -1312,7 +1572,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1312
1572
|
overrides
|
|
1313
1573
|
}) {
|
|
1314
1574
|
try {
|
|
1315
|
-
const config =
|
|
1575
|
+
const config = import_node_fs6.default.readFileSync(filePath, "utf-8");
|
|
1316
1576
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1317
1577
|
if (!isMainConfig(validatedConfig)) {
|
|
1318
1578
|
throw new MicrofrontendError(
|