@vercel/microfrontends 1.1.1-canary.3 → 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 +225 -493
- package/dist/config.cjs +27 -62
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +153 -4
- package/dist/config.js +27 -62
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +228 -480
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +218 -470
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +258 -502
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +244 -488
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +227 -476
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +14 -20
- package/dist/microfrontends/server.js +217 -466
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/next/config.cjs +229 -489
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +219 -479
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.d.ts +2 -2
- package/dist/next/middleware.cjs +42 -162
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +2 -4
- package/dist/next/middleware.js +42 -162
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +28 -64
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +28 -64
- 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 +232 -483
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +218 -469
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +0 -31
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +0 -31
- package/dist/validation.js.map +1 -1
- package/package.json +1 -8
- package/schema/schema.json +0 -33
- package/dist/index-7e69650e.d.ts +0 -165
- package/dist/microfrontends.cjs +0 -969
- package/dist/microfrontends.cjs.map +0 -1
- package/dist/microfrontends.d.ts +0 -45
- package/dist/microfrontends.js +0 -942
- package/dist/microfrontends.js.map +0 -1
|
@@ -44,8 +44,8 @@ function displayLocalProxyInfo(port) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// src/config/microfrontends/server/index.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
48
|
+
var import_node_path8 = require("path");
|
|
49
49
|
|
|
50
50
|
// src/config/overrides/constants.ts
|
|
51
51
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -184,19 +184,177 @@ function getConfigStringFromEnv() {
|
|
|
184
184
|
return config;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
// src/config/
|
|
187
|
+
// src/config/schema/utils/is-default-app.ts
|
|
188
|
+
function isDefaultApp(a) {
|
|
189
|
+
return !("routing" in a);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
193
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
194
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
195
|
+
var GIT_DIRECTORY = ".git";
|
|
196
|
+
function hasGitDirectory(dir) {
|
|
197
|
+
const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
|
|
198
|
+
return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
|
|
199
|
+
}
|
|
200
|
+
function hasPnpmWorkspaces(dir) {
|
|
201
|
+
return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
|
|
202
|
+
}
|
|
203
|
+
function findRepositoryRoot(startDir) {
|
|
204
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
205
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
206
|
+
}
|
|
207
|
+
let currentDir = startDir || process.cwd();
|
|
208
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
209
|
+
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
210
|
+
return currentDir;
|
|
211
|
+
}
|
|
212
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(
|
|
215
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
220
|
+
var import_node_path2 = require("path");
|
|
221
|
+
var import_node_fs2 = require("fs");
|
|
188
222
|
var import_jsonc_parser = require("jsonc-parser");
|
|
223
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
189
224
|
|
|
190
|
-
// src/config/
|
|
191
|
-
|
|
192
|
-
|
|
225
|
+
// src/config/constants.ts
|
|
226
|
+
var CONFIGURATION_FILENAMES = [
|
|
227
|
+
"microfrontends.jsonc",
|
|
228
|
+
"microfrontends.json"
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
232
|
+
var configCache = {};
|
|
233
|
+
function findDefaultMicrofrontendsPackages({
|
|
234
|
+
repositoryRoot,
|
|
235
|
+
applicationName
|
|
236
|
+
}) {
|
|
237
|
+
try {
|
|
238
|
+
const microfrontendsJsonPaths = import_fast_glob.default.globSync(
|
|
239
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
240
|
+
{
|
|
241
|
+
cwd: repositoryRoot,
|
|
242
|
+
absolute: true,
|
|
243
|
+
onlyFiles: true,
|
|
244
|
+
followSymbolicLinks: false,
|
|
245
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
const matchingPaths = [];
|
|
249
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
250
|
+
try {
|
|
251
|
+
const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
|
|
252
|
+
microfrontendsJsonPath,
|
|
253
|
+
"utf-8"
|
|
254
|
+
);
|
|
255
|
+
const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
|
|
256
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
257
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
258
|
+
}
|
|
259
|
+
} catch (error) {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (matchingPaths.length > 1) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
265
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (matchingPaths.length === 0) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const [packageJsonPath] = matchingPaths;
|
|
274
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
280
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
281
|
+
if (configCache[cacheKey]) {
|
|
282
|
+
return configCache[cacheKey];
|
|
283
|
+
}
|
|
284
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
285
|
+
if (!result) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
"Error trying to resolve the main microfrontends configuration"
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
configCache[cacheKey] = result;
|
|
291
|
+
return result;
|
|
193
292
|
}
|
|
194
293
|
|
|
195
|
-
// src/config/
|
|
196
|
-
|
|
197
|
-
|
|
294
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
295
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
296
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
297
|
+
function isMonorepo({
|
|
298
|
+
repositoryRoot
|
|
299
|
+
}) {
|
|
300
|
+
try {
|
|
301
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path3.default.resolve(repositoryRoot)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
const packageJsonPath = import_node_path3.default.join(repositoryRoot, "package.json");
|
|
311
|
+
if (!import_node_fs3.default.existsSync(packageJsonPath)) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
const packageJson = JSON.parse(
|
|
315
|
+
import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
|
|
316
|
+
);
|
|
317
|
+
return packageJson.workspaces !== void 0;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
325
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
326
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
327
|
+
var PACKAGE_JSON = "package.json";
|
|
328
|
+
function findPackageRoot(startDir) {
|
|
329
|
+
let currentDir = startDir || process.cwd();
|
|
330
|
+
while (currentDir !== import_node_path4.default.parse(currentDir).root) {
|
|
331
|
+
const pkgJsonPath = import_node_path4.default.join(currentDir, PACKAGE_JSON);
|
|
332
|
+
if (import_node_fs4.default.existsSync(pkgJsonPath)) {
|
|
333
|
+
return currentDir;
|
|
334
|
+
}
|
|
335
|
+
currentDir = import_node_path4.default.dirname(currentDir);
|
|
336
|
+
}
|
|
337
|
+
throw new Error(
|
|
338
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
343
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
344
|
+
var import_node_path5 = require("path");
|
|
345
|
+
function findConfig({ dir }) {
|
|
346
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
347
|
+
const maybeConfig = (0, import_node_path5.join)(dir, filename);
|
|
348
|
+
if (import_node_fs5.default.existsSync(maybeConfig)) {
|
|
349
|
+
return maybeConfig;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
198
353
|
}
|
|
199
354
|
|
|
355
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
356
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
357
|
+
|
|
200
358
|
// src/config/microfrontends-config/client/index.ts
|
|
201
359
|
var import_path_to_regexp = require("path-to-regexp");
|
|
202
360
|
var MicrofrontendConfigClient = class {
|
|
@@ -732,42 +890,28 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
732
890
|
constructor({
|
|
733
891
|
config,
|
|
734
892
|
overrides,
|
|
735
|
-
meta,
|
|
736
893
|
opts
|
|
737
894
|
}) {
|
|
738
895
|
this.childApplications = {};
|
|
739
896
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
740
897
|
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
741
898
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
app: appConfig,
|
|
749
|
-
overrides: appOverrides
|
|
750
|
-
});
|
|
751
|
-
} else {
|
|
752
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
753
|
-
app: appConfig,
|
|
754
|
-
overrides: appOverrides
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
} else {
|
|
759
|
-
this.partOf = config.partOf;
|
|
760
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
761
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
762
|
-
meta.fromApp,
|
|
763
|
-
{
|
|
764
|
-
// we don't know routing because we're not in the main config
|
|
765
|
-
app: { routing: [] },
|
|
899
|
+
let defaultApplication;
|
|
900
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
901
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
902
|
+
if (isDefaultApp(appConfig)) {
|
|
903
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
904
|
+
app: appConfig,
|
|
766
905
|
overrides: appOverrides
|
|
767
|
-
}
|
|
768
|
-
|
|
906
|
+
});
|
|
907
|
+
} else {
|
|
908
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
909
|
+
app: appConfig,
|
|
910
|
+
overrides: appOverrides
|
|
911
|
+
});
|
|
912
|
+
}
|
|
769
913
|
}
|
|
770
|
-
if (
|
|
914
|
+
if (!defaultApplication) {
|
|
771
915
|
throw new MicrofrontendError(
|
|
772
916
|
"Could not find default application in microfrontends configuration",
|
|
773
917
|
{
|
|
@@ -776,34 +920,30 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
776
920
|
}
|
|
777
921
|
);
|
|
778
922
|
}
|
|
923
|
+
this.defaultApplication = defaultApplication;
|
|
779
924
|
this.config = config;
|
|
780
925
|
this.options = config.options;
|
|
781
926
|
this.serialized = {
|
|
782
927
|
config,
|
|
783
|
-
overrides
|
|
784
|
-
meta
|
|
928
|
+
overrides
|
|
785
929
|
};
|
|
786
930
|
}
|
|
787
931
|
static validate(config, opts) {
|
|
788
932
|
const skipValidation = opts?.skipValidation ?? [];
|
|
789
|
-
const c = typeof config === "string" ? (0,
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
validateDeprecatedFields(c);
|
|
795
|
-
}
|
|
933
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
|
|
934
|
+
validateConfigPaths(c.applications);
|
|
935
|
+
validateConfigDefaultApplication(c.applications);
|
|
936
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
937
|
+
validateDeprecatedFields(c);
|
|
796
938
|
}
|
|
797
939
|
return c;
|
|
798
940
|
}
|
|
799
941
|
static fromEnv({
|
|
800
|
-
meta,
|
|
801
942
|
cookies
|
|
802
943
|
}) {
|
|
803
944
|
return new MicrofrontendConfigIsomorphic({
|
|
804
|
-
config: (0,
|
|
805
|
-
overrides: parseOverrides(cookies ?? [])
|
|
806
|
-
meta
|
|
945
|
+
config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
|
|
946
|
+
overrides: parseOverrides(cookies ?? [])
|
|
807
947
|
});
|
|
808
948
|
}
|
|
809
949
|
isOverridesDisabled() {
|
|
@@ -828,7 +968,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
828
968
|
].filter(Boolean);
|
|
829
969
|
}
|
|
830
970
|
getApplication(name) {
|
|
831
|
-
if (this.defaultApplication
|
|
971
|
+
if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
|
|
832
972
|
return this.defaultApplication;
|
|
833
973
|
}
|
|
834
974
|
const app = this.childApplications[name] || Object.values(this.childApplications).find(
|
|
@@ -846,7 +986,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
846
986
|
return app;
|
|
847
987
|
}
|
|
848
988
|
getApplicationByProjectId(projectId) {
|
|
849
|
-
if (this.defaultApplication
|
|
989
|
+
if (this.defaultApplication.projectId === projectId) {
|
|
850
990
|
return this.defaultApplication;
|
|
851
991
|
}
|
|
852
992
|
return Object.values(this.childApplications).find(
|
|
@@ -854,19 +994,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
854
994
|
);
|
|
855
995
|
}
|
|
856
996
|
/**
|
|
857
|
-
* Returns the default application.
|
|
858
|
-
* is undefined ( )
|
|
997
|
+
* Returns the default application.
|
|
859
998
|
*/
|
|
860
999
|
getDefaultApplication() {
|
|
861
|
-
if (!this.defaultApplication) {
|
|
862
|
-
throw new MicrofrontendError(
|
|
863
|
-
"Could not find default application in microfrontends configuration",
|
|
864
|
-
{
|
|
865
|
-
type: "application",
|
|
866
|
-
subtype: "not_found"
|
|
867
|
-
}
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
1000
|
return this.defaultApplication;
|
|
871
1001
|
}
|
|
872
1002
|
/**
|
|
@@ -893,11 +1023,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
893
1023
|
}
|
|
894
1024
|
])
|
|
895
1025
|
);
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
};
|
|
900
|
-
}
|
|
1026
|
+
applications[this.defaultApplication.name] = {
|
|
1027
|
+
default: true
|
|
1028
|
+
};
|
|
901
1029
|
return new MicrofrontendConfigClient({
|
|
902
1030
|
applications
|
|
903
1031
|
});
|
|
@@ -907,307 +1035,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
907
1035
|
}
|
|
908
1036
|
};
|
|
909
1037
|
|
|
910
|
-
// src/config/microfrontends-config/isomorphic/child.ts
|
|
911
|
-
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
912
|
-
constructor({
|
|
913
|
-
config,
|
|
914
|
-
overrides,
|
|
915
|
-
meta
|
|
916
|
-
}) {
|
|
917
|
-
super({ config, overrides, meta });
|
|
918
|
-
this.isMainConfig = false;
|
|
919
|
-
this.partOf = config.partOf;
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
|
|
923
|
-
// src/config/microfrontends-config/isomorphic/main.ts
|
|
924
|
-
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
925
|
-
constructor({
|
|
926
|
-
config,
|
|
927
|
-
overrides,
|
|
928
|
-
meta
|
|
929
|
-
}) {
|
|
930
|
-
super({ config, overrides, meta });
|
|
931
|
-
this.isMainConfig = true;
|
|
932
|
-
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
933
|
-
let defaultApplication;
|
|
934
|
-
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
935
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
936
|
-
if (isDefaultApp(appConfig)) {
|
|
937
|
-
defaultApplication = new DefaultApplication(appId, {
|
|
938
|
-
app: appConfig,
|
|
939
|
-
overrides: appOverrides
|
|
940
|
-
});
|
|
941
|
-
} else {
|
|
942
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
943
|
-
app: appConfig,
|
|
944
|
-
overrides: appOverrides
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
if (!defaultApplication) {
|
|
949
|
-
throw new MicrofrontendError(
|
|
950
|
-
"Could not find default application in microfrontends configuration",
|
|
951
|
-
{
|
|
952
|
-
type: "application",
|
|
953
|
-
subtype: "not_found"
|
|
954
|
-
}
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
this.defaultApplication = defaultApplication;
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
// src/config/microfrontends/isomorphic/index.ts
|
|
962
|
-
var Microfrontends = class {
|
|
963
|
-
constructor({
|
|
964
|
-
config,
|
|
965
|
-
overrides,
|
|
966
|
-
meta
|
|
967
|
-
}) {
|
|
968
|
-
if (isMainConfig(config)) {
|
|
969
|
-
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
970
|
-
} else {
|
|
971
|
-
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
isChildConfig() {
|
|
975
|
-
return this.config instanceof MicrofrontendChildConfig;
|
|
976
|
-
}
|
|
977
|
-
static fromEnv({
|
|
978
|
-
cookies,
|
|
979
|
-
meta
|
|
980
|
-
}) {
|
|
981
|
-
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
982
|
-
cookies,
|
|
983
|
-
meta
|
|
984
|
-
});
|
|
985
|
-
return new Microfrontends(config.serialize());
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
|
|
989
|
-
// src/config/microfrontends/utils/find-repository-root.ts
|
|
990
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
991
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
992
|
-
var GIT_DIRECTORY = ".git";
|
|
993
|
-
function hasGitDirectory(dir) {
|
|
994
|
-
const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
|
|
995
|
-
return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
|
|
996
|
-
}
|
|
997
|
-
function hasPnpmWorkspaces(dir) {
|
|
998
|
-
return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
|
|
999
|
-
}
|
|
1000
|
-
function findRepositoryRoot(startDir) {
|
|
1001
|
-
if (process.env.NX_WORKSPACE_ROOT) {
|
|
1002
|
-
return process.env.NX_WORKSPACE_ROOT;
|
|
1003
|
-
}
|
|
1004
|
-
let currentDir = startDir || process.cwd();
|
|
1005
|
-
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
1006
|
-
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
1007
|
-
return currentDir;
|
|
1008
|
-
}
|
|
1009
|
-
currentDir = import_node_path.default.dirname(currentDir);
|
|
1010
|
-
}
|
|
1011
|
-
throw new Error(
|
|
1012
|
-
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
1013
|
-
);
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// src/config/microfrontends/utils/find-package-path.ts
|
|
1017
|
-
var import_node_path2 = require("path");
|
|
1018
|
-
var import_node_fs2 = require("fs");
|
|
1019
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1020
|
-
var configCache = {};
|
|
1021
|
-
function findPackagePathWithGlob({
|
|
1022
|
-
repositoryRoot,
|
|
1023
|
-
name
|
|
1024
|
-
}) {
|
|
1025
|
-
try {
|
|
1026
|
-
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
1027
|
-
cwd: repositoryRoot,
|
|
1028
|
-
absolute: true,
|
|
1029
|
-
onlyFiles: true,
|
|
1030
|
-
followSymbolicLinks: false,
|
|
1031
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1032
|
-
});
|
|
1033
|
-
const matchingPaths = [];
|
|
1034
|
-
for (const packageJsonPath2 of packageJsonPaths) {
|
|
1035
|
-
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
1036
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1037
|
-
if (packageJson.name === name) {
|
|
1038
|
-
matchingPaths.push(packageJsonPath2);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
if (matchingPaths.length > 1) {
|
|
1042
|
-
throw new Error(
|
|
1043
|
-
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
if (matchingPaths.length === 0) {
|
|
1047
|
-
throw new Error(
|
|
1048
|
-
`Could not find package with the name "${name}" in the repository`
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
const [packageJsonPath] = matchingPaths;
|
|
1052
|
-
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
1053
|
-
} catch (error) {
|
|
1054
|
-
return null;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
function findPackagePath(opts) {
|
|
1058
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
1059
|
-
if (configCache[cacheKey]) {
|
|
1060
|
-
return configCache[cacheKey];
|
|
1061
|
-
}
|
|
1062
|
-
const result = findPackagePathWithGlob(opts);
|
|
1063
|
-
if (!result) {
|
|
1064
|
-
throw new Error(
|
|
1065
|
-
`Could not find package with the name "${opts.name}" in the repository`
|
|
1066
|
-
);
|
|
1067
|
-
}
|
|
1068
|
-
configCache[cacheKey] = result;
|
|
1069
|
-
return result;
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1073
|
-
var import_node_path3 = require("path");
|
|
1074
|
-
var import_node_fs3 = require("fs");
|
|
1075
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
1076
|
-
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1077
|
-
|
|
1078
|
-
// src/config/constants.ts
|
|
1079
|
-
var CONFIGURATION_FILENAMES = [
|
|
1080
|
-
"microfrontends.jsonc",
|
|
1081
|
-
"microfrontends.json"
|
|
1082
|
-
];
|
|
1083
|
-
|
|
1084
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1085
|
-
var configCache2 = {};
|
|
1086
|
-
function findDefaultMicrofrontendsPackages({
|
|
1087
|
-
repositoryRoot,
|
|
1088
|
-
applicationName
|
|
1089
|
-
}) {
|
|
1090
|
-
try {
|
|
1091
|
-
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
1092
|
-
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
1093
|
-
{
|
|
1094
|
-
cwd: repositoryRoot,
|
|
1095
|
-
absolute: true,
|
|
1096
|
-
onlyFiles: true,
|
|
1097
|
-
followSymbolicLinks: false,
|
|
1098
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1099
|
-
}
|
|
1100
|
-
);
|
|
1101
|
-
const matchingPaths = [];
|
|
1102
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1103
|
-
try {
|
|
1104
|
-
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
1105
|
-
microfrontendsJsonPath,
|
|
1106
|
-
"utf-8"
|
|
1107
|
-
);
|
|
1108
|
-
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1109
|
-
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
1110
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1111
|
-
}
|
|
1112
|
-
} catch (error) {
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
if (matchingPaths.length > 1) {
|
|
1116
|
-
throw new Error(
|
|
1117
|
-
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
1118
|
-
${matchingPaths.join("\n \u2022 ")}`
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
if (matchingPaths.length === 0) {
|
|
1122
|
-
throw new Error(
|
|
1123
|
-
`Could not find default application with "applications.${applicationName}"`
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1126
|
-
const [packageJsonPath] = matchingPaths;
|
|
1127
|
-
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
1128
|
-
} catch (error) {
|
|
1129
|
-
return null;
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
function findDefaultMicrofrontendsPackage(opts) {
|
|
1133
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
1134
|
-
if (configCache2[cacheKey]) {
|
|
1135
|
-
return configCache2[cacheKey];
|
|
1136
|
-
}
|
|
1137
|
-
const result = findDefaultMicrofrontendsPackages(opts);
|
|
1138
|
-
if (!result) {
|
|
1139
|
-
throw new Error(
|
|
1140
|
-
"Error trying to resolve the main microfrontends configuration"
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1143
|
-
configCache2[cacheKey] = result;
|
|
1144
|
-
return result;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1148
|
-
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1149
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
1150
|
-
function isMonorepo({
|
|
1151
|
-
repositoryRoot
|
|
1152
|
-
}) {
|
|
1153
|
-
try {
|
|
1154
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
1155
|
-
return true;
|
|
1156
|
-
}
|
|
1157
|
-
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1158
|
-
return true;
|
|
1159
|
-
}
|
|
1160
|
-
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1161
|
-
return true;
|
|
1162
|
-
}
|
|
1163
|
-
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1164
|
-
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1165
|
-
return false;
|
|
1166
|
-
}
|
|
1167
|
-
const packageJson = JSON.parse(
|
|
1168
|
-
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
1169
|
-
);
|
|
1170
|
-
return packageJson.workspaces !== void 0;
|
|
1171
|
-
} catch (error) {
|
|
1172
|
-
console.error("Error determining if repository is a monorepo", error);
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
// src/config/microfrontends/utils/find-package-root.ts
|
|
1178
|
-
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1179
|
-
var import_node_path5 = __toESM(require("path"), 1);
|
|
1180
|
-
var PACKAGE_JSON = "package.json";
|
|
1181
|
-
function findPackageRoot(startDir) {
|
|
1182
|
-
let currentDir = startDir || process.cwd();
|
|
1183
|
-
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1184
|
-
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1185
|
-
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
1186
|
-
return currentDir;
|
|
1187
|
-
}
|
|
1188
|
-
currentDir = import_node_path5.default.dirname(currentDir);
|
|
1189
|
-
}
|
|
1190
|
-
throw new Error(
|
|
1191
|
-
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
1196
|
-
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1197
|
-
var import_node_path6 = require("path");
|
|
1198
|
-
function findConfig({ dir }) {
|
|
1199
|
-
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1200
|
-
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1201
|
-
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1202
|
-
return maybeConfig;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
return null;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
1038
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1209
|
-
var
|
|
1210
|
-
var
|
|
1039
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1040
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
1211
1041
|
function getApplicationContext(opts) {
|
|
1212
1042
|
if (opts?.appName) {
|
|
1213
1043
|
return { name: opts.appName };
|
|
@@ -1216,8 +1046,8 @@ function getApplicationContext(opts) {
|
|
|
1216
1046
|
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1217
1047
|
}
|
|
1218
1048
|
try {
|
|
1219
|
-
const packageJsonString =
|
|
1220
|
-
|
|
1049
|
+
const packageJsonString = import_node_fs6.default.readFileSync(
|
|
1050
|
+
import_node_path6.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1221
1051
|
"utf-8"
|
|
1222
1052
|
);
|
|
1223
1053
|
const packageJson = JSON.parse(packageJsonString);
|
|
@@ -1240,7 +1070,7 @@ function getApplicationContext(opts) {
|
|
|
1240
1070
|
}
|
|
1241
1071
|
|
|
1242
1072
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1243
|
-
var
|
|
1073
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1244
1074
|
|
|
1245
1075
|
// src/config/microfrontends/server/constants.ts
|
|
1246
1076
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1248,7 +1078,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1248
1078
|
|
|
1249
1079
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1250
1080
|
function getOutputFilePath() {
|
|
1251
|
-
return
|
|
1081
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1252
1082
|
}
|
|
1253
1083
|
|
|
1254
1084
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1261,16 +1091,6 @@ var schema_default = {
|
|
|
1261
1091
|
$ref: "#/definitions/Config",
|
|
1262
1092
|
definitions: {
|
|
1263
1093
|
Config: {
|
|
1264
|
-
anyOf: [
|
|
1265
|
-
{
|
|
1266
|
-
$ref: "#/definitions/MainConfig"
|
|
1267
|
-
},
|
|
1268
|
-
{
|
|
1269
|
-
$ref: "#/definitions/ChildConfig"
|
|
1270
|
-
}
|
|
1271
|
-
]
|
|
1272
|
-
},
|
|
1273
|
-
MainConfig: {
|
|
1274
1094
|
type: "object",
|
|
1275
1095
|
properties: {
|
|
1276
1096
|
$schema: {
|
|
@@ -1527,27 +1347,6 @@ var schema_default = {
|
|
|
1527
1347
|
},
|
|
1528
1348
|
required: ["paths"],
|
|
1529
1349
|
additionalProperties: false
|
|
1530
|
-
},
|
|
1531
|
-
ChildConfig: {
|
|
1532
|
-
type: "object",
|
|
1533
|
-
properties: {
|
|
1534
|
-
$schema: {
|
|
1535
|
-
type: "string"
|
|
1536
|
-
},
|
|
1537
|
-
version: {
|
|
1538
|
-
type: "string",
|
|
1539
|
-
const: "1"
|
|
1540
|
-
},
|
|
1541
|
-
options: {
|
|
1542
|
-
$ref: "#/definitions/Options"
|
|
1543
|
-
},
|
|
1544
|
-
partOf: {
|
|
1545
|
-
type: "string",
|
|
1546
|
-
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."
|
|
1547
|
-
}
|
|
1548
|
-
},
|
|
1549
|
-
required: ["partOf"],
|
|
1550
|
-
additionalProperties: false
|
|
1551
1350
|
}
|
|
1552
1351
|
}
|
|
1553
1352
|
};
|
|
@@ -1625,7 +1424,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
|
1625
1424
|
}
|
|
1626
1425
|
|
|
1627
1426
|
// src/config/microfrontends/server/index.ts
|
|
1628
|
-
var MicrofrontendsServer = class
|
|
1427
|
+
var MicrofrontendsServer = class {
|
|
1428
|
+
constructor({
|
|
1429
|
+
config,
|
|
1430
|
+
overrides
|
|
1431
|
+
}) {
|
|
1432
|
+
this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
|
|
1433
|
+
}
|
|
1629
1434
|
/**
|
|
1630
1435
|
* Writes the configuration to a file.
|
|
1631
1436
|
*/
|
|
@@ -1633,8 +1438,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1633
1438
|
pretty: true
|
|
1634
1439
|
}) {
|
|
1635
1440
|
const outputPath = getOutputFilePath();
|
|
1636
|
-
|
|
1637
|
-
|
|
1441
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1442
|
+
import_node_fs7.default.writeFileSync(
|
|
1638
1443
|
outputPath,
|
|
1639
1444
|
JSON.stringify(
|
|
1640
1445
|
this.config.toSchemaJson(),
|
|
@@ -1649,22 +1454,19 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1649
1454
|
*/
|
|
1650
1455
|
static fromUnknown({
|
|
1651
1456
|
config,
|
|
1652
|
-
cookies
|
|
1653
|
-
meta
|
|
1457
|
+
cookies
|
|
1654
1458
|
}) {
|
|
1655
1459
|
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1656
1460
|
if (typeof config === "string") {
|
|
1657
1461
|
return new MicrofrontendsServer({
|
|
1658
1462
|
config: MicrofrontendsServer.validate(config),
|
|
1659
|
-
overrides
|
|
1660
|
-
meta
|
|
1463
|
+
overrides
|
|
1661
1464
|
});
|
|
1662
1465
|
}
|
|
1663
1466
|
if (typeof config === "object") {
|
|
1664
1467
|
return new MicrofrontendsServer({
|
|
1665
1468
|
config,
|
|
1666
|
-
overrides
|
|
1667
|
-
meta
|
|
1469
|
+
overrides
|
|
1668
1470
|
});
|
|
1669
1471
|
}
|
|
1670
1472
|
throw new MicrofrontendError(
|
|
@@ -1677,13 +1479,11 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1677
1479
|
* Uses additional validation that is only available when in a node runtime
|
|
1678
1480
|
*/
|
|
1679
1481
|
static fromEnv({
|
|
1680
|
-
cookies
|
|
1681
|
-
meta
|
|
1482
|
+
cookies
|
|
1682
1483
|
}) {
|
|
1683
1484
|
return new MicrofrontendsServer({
|
|
1684
1485
|
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1685
|
-
overrides: parseOverrides(cookies)
|
|
1686
|
-
meta
|
|
1486
|
+
overrides: parseOverrides(cookies)
|
|
1687
1487
|
});
|
|
1688
1488
|
}
|
|
1689
1489
|
/**
|
|
@@ -1706,29 +1506,22 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1706
1506
|
static infer({
|
|
1707
1507
|
directory,
|
|
1708
1508
|
filePath,
|
|
1709
|
-
|
|
1710
|
-
cookies,
|
|
1711
|
-
options
|
|
1509
|
+
cookies
|
|
1712
1510
|
} = {}) {
|
|
1713
|
-
if (filePath
|
|
1511
|
+
if (filePath) {
|
|
1714
1512
|
return MicrofrontendsServer.fromFile({
|
|
1715
1513
|
filePath,
|
|
1716
|
-
cookies
|
|
1717
|
-
meta,
|
|
1718
|
-
options
|
|
1514
|
+
cookies
|
|
1719
1515
|
});
|
|
1720
1516
|
}
|
|
1721
1517
|
try {
|
|
1722
1518
|
const packageRoot = findPackageRoot(directory);
|
|
1723
1519
|
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1724
|
-
const configMeta = meta ?? { fromApp: appName };
|
|
1725
1520
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1726
1521
|
if (maybeConfig) {
|
|
1727
1522
|
return MicrofrontendsServer.fromFile({
|
|
1728
1523
|
filePath: maybeConfig,
|
|
1729
|
-
cookies
|
|
1730
|
-
meta: configMeta,
|
|
1731
|
-
options
|
|
1524
|
+
cookies
|
|
1732
1525
|
});
|
|
1733
1526
|
}
|
|
1734
1527
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1742,9 +1535,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1742
1535
|
if (maybeConfigFromDefault) {
|
|
1743
1536
|
return MicrofrontendsServer.fromFile({
|
|
1744
1537
|
filePath: maybeConfigFromDefault,
|
|
1745
|
-
cookies
|
|
1746
|
-
meta: configMeta,
|
|
1747
|
-
options
|
|
1538
|
+
cookies
|
|
1748
1539
|
});
|
|
1749
1540
|
}
|
|
1750
1541
|
}
|
|
@@ -1764,44 +1555,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1764
1555
|
*/
|
|
1765
1556
|
static fromFile({
|
|
1766
1557
|
filePath,
|
|
1767
|
-
cookies
|
|
1768
|
-
meta,
|
|
1769
|
-
options
|
|
1558
|
+
cookies
|
|
1770
1559
|
}) {
|
|
1771
1560
|
try {
|
|
1772
|
-
const configJson =
|
|
1561
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1773
1562
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1774
|
-
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1775
|
-
const repositoryRoot = findRepositoryRoot();
|
|
1776
|
-
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1777
|
-
if (isMonorepo2) {
|
|
1778
|
-
const packagePath = findPackagePath({
|
|
1779
|
-
repositoryRoot,
|
|
1780
|
-
name: config.partOf
|
|
1781
|
-
});
|
|
1782
|
-
if (!packagePath) {
|
|
1783
|
-
throw new MicrofrontendError(
|
|
1784
|
-
`Could not find default application "${config.partOf}" in the repository`,
|
|
1785
|
-
{ type: "config", subtype: "not_found" }
|
|
1786
|
-
);
|
|
1787
|
-
}
|
|
1788
|
-
const maybeConfig = findConfig({ dir: packagePath });
|
|
1789
|
-
if (!maybeConfig) {
|
|
1790
|
-
throw new MicrofrontendError(
|
|
1791
|
-
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1792
|
-
{ type: "config", subtype: "not_found" }
|
|
1793
|
-
);
|
|
1794
|
-
}
|
|
1795
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1796
|
-
filePath: maybeConfig,
|
|
1797
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
1563
|
return new MicrofrontendsServer({
|
|
1802
1564
|
config,
|
|
1803
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1804
|
-
meta
|
|
1565
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1805
1566
|
});
|
|
1806
1567
|
} catch (e) {
|
|
1807
1568
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1810,24 +1571,15 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1810
1571
|
}
|
|
1811
1572
|
}
|
|
1812
1573
|
/*
|
|
1813
|
-
* Generates a
|
|
1574
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1814
1575
|
*/
|
|
1815
1576
|
static fromMainConfigFile({
|
|
1816
1577
|
filePath,
|
|
1817
1578
|
overrides
|
|
1818
1579
|
}) {
|
|
1819
1580
|
try {
|
|
1820
|
-
const config =
|
|
1581
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1821
1582
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1822
|
-
if (!isMainConfig(validatedConfig)) {
|
|
1823
|
-
throw new MicrofrontendError(
|
|
1824
|
-
`${filePath} is not a main microfrontend config`,
|
|
1825
|
-
{
|
|
1826
|
-
type: "config",
|
|
1827
|
-
subtype: "invalid_main_path"
|
|
1828
|
-
}
|
|
1829
|
-
);
|
|
1830
|
-
}
|
|
1831
1583
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1832
1584
|
if (!defaultApplication) {
|
|
1833
1585
|
throw new MicrofrontendError(
|
|
@@ -1837,8 +1589,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1837
1589
|
}
|
|
1838
1590
|
return new MicrofrontendsServer({
|
|
1839
1591
|
config: validatedConfig,
|
|
1840
|
-
overrides
|
|
1841
|
-
meta: { fromApp: defaultApplication }
|
|
1592
|
+
overrides
|
|
1842
1593
|
});
|
|
1843
1594
|
} catch (e) {
|
|
1844
1595
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1852,10 +1603,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1852
1603
|
function withMicrofrontends(config, opts) {
|
|
1853
1604
|
const { name: fromApp } = getApplicationContext(opts);
|
|
1854
1605
|
const microfrontends = MicrofrontendsServer.infer({
|
|
1855
|
-
filePath: opts?.configPath
|
|
1856
|
-
meta: {
|
|
1857
|
-
fromApp
|
|
1858
|
-
}
|
|
1606
|
+
filePath: opts?.configPath
|
|
1859
1607
|
});
|
|
1860
1608
|
const app = microfrontends.config.getApplication(fromApp);
|
|
1861
1609
|
if (!app.isDefault()) {
|