@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/config/microfrontends/server/index.ts
|
|
2
2
|
import fs6 from "node:fs";
|
|
3
|
-
import { dirname as
|
|
3
|
+
import { dirname as dirname2 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// src/config/overrides/constants.ts
|
|
6
6
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -139,19 +139,177 @@ function getConfigStringFromEnv() {
|
|
|
139
139
|
return config;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
// src/config/
|
|
142
|
+
// src/config/schema/utils/is-default-app.ts
|
|
143
|
+
function isDefaultApp(a) {
|
|
144
|
+
return !("routing" in a);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
148
|
+
import fs from "node:fs";
|
|
149
|
+
import path from "node:path";
|
|
150
|
+
var GIT_DIRECTORY = ".git";
|
|
151
|
+
function hasGitDirectory(dir) {
|
|
152
|
+
const gitPath = path.join(dir, GIT_DIRECTORY);
|
|
153
|
+
return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
|
|
154
|
+
}
|
|
155
|
+
function hasPnpmWorkspaces(dir) {
|
|
156
|
+
return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
|
|
157
|
+
}
|
|
158
|
+
function findRepositoryRoot(startDir) {
|
|
159
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
160
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
161
|
+
}
|
|
162
|
+
let currentDir = startDir || process.cwd();
|
|
163
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
164
|
+
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
165
|
+
return currentDir;
|
|
166
|
+
}
|
|
167
|
+
currentDir = path.dirname(currentDir);
|
|
168
|
+
}
|
|
169
|
+
throw new Error(
|
|
170
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
175
|
+
import { dirname } from "node:path";
|
|
176
|
+
import { readFileSync } from "node:fs";
|
|
143
177
|
import { parse } from "jsonc-parser";
|
|
178
|
+
import fg from "fast-glob";
|
|
179
|
+
|
|
180
|
+
// src/config/constants.ts
|
|
181
|
+
var CONFIGURATION_FILENAMES = [
|
|
182
|
+
"microfrontends.jsonc",
|
|
183
|
+
"microfrontends.json"
|
|
184
|
+
];
|
|
144
185
|
|
|
145
|
-
// src/config/
|
|
146
|
-
|
|
147
|
-
|
|
186
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
187
|
+
var configCache = {};
|
|
188
|
+
function findDefaultMicrofrontendsPackages({
|
|
189
|
+
repositoryRoot,
|
|
190
|
+
applicationName
|
|
191
|
+
}) {
|
|
192
|
+
try {
|
|
193
|
+
const microfrontendsJsonPaths = fg.globSync(
|
|
194
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
195
|
+
{
|
|
196
|
+
cwd: repositoryRoot,
|
|
197
|
+
absolute: true,
|
|
198
|
+
onlyFiles: true,
|
|
199
|
+
followSymbolicLinks: false,
|
|
200
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
const matchingPaths = [];
|
|
204
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
205
|
+
try {
|
|
206
|
+
const microfrontendsJsonContent = readFileSync(
|
|
207
|
+
microfrontendsJsonPath,
|
|
208
|
+
"utf-8"
|
|
209
|
+
);
|
|
210
|
+
const microfrontendsJson = parse(microfrontendsJsonContent);
|
|
211
|
+
if (microfrontendsJson.applications[applicationName]) {
|
|
212
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (matchingPaths.length > 1) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
220
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (matchingPaths.length === 0) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
const [packageJsonPath] = matchingPaths;
|
|
229
|
+
return dirname(packageJsonPath);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
235
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
236
|
+
if (configCache[cacheKey]) {
|
|
237
|
+
return configCache[cacheKey];
|
|
238
|
+
}
|
|
239
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
240
|
+
if (!result) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
"Error trying to resolve the main microfrontends configuration"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
configCache[cacheKey] = result;
|
|
246
|
+
return result;
|
|
148
247
|
}
|
|
149
248
|
|
|
150
|
-
// src/config/
|
|
151
|
-
|
|
152
|
-
|
|
249
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
250
|
+
import fs2 from "node:fs";
|
|
251
|
+
import path2 from "node:path";
|
|
252
|
+
function isMonorepo({
|
|
253
|
+
repositoryRoot
|
|
254
|
+
}) {
|
|
255
|
+
try {
|
|
256
|
+
if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
266
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const packageJson = JSON.parse(
|
|
270
|
+
fs2.readFileSync(packageJsonPath, "utf-8")
|
|
271
|
+
);
|
|
272
|
+
return packageJson.workspaces !== void 0;
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
280
|
+
import fs3 from "node:fs";
|
|
281
|
+
import path3 from "node:path";
|
|
282
|
+
var PACKAGE_JSON = "package.json";
|
|
283
|
+
function findPackageRoot(startDir) {
|
|
284
|
+
let currentDir = startDir || process.cwd();
|
|
285
|
+
while (currentDir !== path3.parse(currentDir).root) {
|
|
286
|
+
const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
|
|
287
|
+
if (fs3.existsSync(pkgJsonPath)) {
|
|
288
|
+
return currentDir;
|
|
289
|
+
}
|
|
290
|
+
currentDir = path3.dirname(currentDir);
|
|
291
|
+
}
|
|
292
|
+
throw new Error(
|
|
293
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
298
|
+
import fs4 from "node:fs";
|
|
299
|
+
import { join } from "node:path";
|
|
300
|
+
function findConfig({ dir }) {
|
|
301
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
302
|
+
const maybeConfig = join(dir, filename);
|
|
303
|
+
if (fs4.existsSync(maybeConfig)) {
|
|
304
|
+
return maybeConfig;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
153
308
|
}
|
|
154
309
|
|
|
310
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
311
|
+
import { parse as parse2 } from "jsonc-parser";
|
|
312
|
+
|
|
155
313
|
// src/config/microfrontends-config/client/index.ts
|
|
156
314
|
import { pathToRegexp } from "path-to-regexp";
|
|
157
315
|
var MicrofrontendConfigClient = class {
|
|
@@ -687,42 +845,28 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
687
845
|
constructor({
|
|
688
846
|
config,
|
|
689
847
|
overrides,
|
|
690
|
-
meta,
|
|
691
848
|
opts
|
|
692
849
|
}) {
|
|
693
850
|
this.childApplications = {};
|
|
694
851
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
695
852
|
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
696
853
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
app: appConfig,
|
|
704
|
-
overrides: appOverrides
|
|
705
|
-
});
|
|
706
|
-
} else {
|
|
707
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
708
|
-
app: appConfig,
|
|
709
|
-
overrides: appOverrides
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
} else {
|
|
714
|
-
this.partOf = config.partOf;
|
|
715
|
-
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
716
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
717
|
-
meta.fromApp,
|
|
718
|
-
{
|
|
719
|
-
// we don't know routing because we're not in the main config
|
|
720
|
-
app: { routing: [] },
|
|
854
|
+
let defaultApplication;
|
|
855
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
856
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
857
|
+
if (isDefaultApp(appConfig)) {
|
|
858
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
859
|
+
app: appConfig,
|
|
721
860
|
overrides: appOverrides
|
|
722
|
-
}
|
|
723
|
-
|
|
861
|
+
});
|
|
862
|
+
} else {
|
|
863
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
864
|
+
app: appConfig,
|
|
865
|
+
overrides: appOverrides
|
|
866
|
+
});
|
|
867
|
+
}
|
|
724
868
|
}
|
|
725
|
-
if (
|
|
869
|
+
if (!defaultApplication) {
|
|
726
870
|
throw new MicrofrontendError(
|
|
727
871
|
"Could not find default application in microfrontends configuration",
|
|
728
872
|
{
|
|
@@ -731,34 +875,30 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
731
875
|
}
|
|
732
876
|
);
|
|
733
877
|
}
|
|
878
|
+
this.defaultApplication = defaultApplication;
|
|
734
879
|
this.config = config;
|
|
735
880
|
this.options = config.options;
|
|
736
881
|
this.serialized = {
|
|
737
882
|
config,
|
|
738
|
-
overrides
|
|
739
|
-
meta
|
|
883
|
+
overrides
|
|
740
884
|
};
|
|
741
885
|
}
|
|
742
886
|
static validate(config, opts) {
|
|
743
887
|
const skipValidation = opts?.skipValidation ?? [];
|
|
744
|
-
const c = typeof config === "string" ?
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
validateDeprecatedFields(c);
|
|
750
|
-
}
|
|
888
|
+
const c = typeof config === "string" ? parse2(config) : config;
|
|
889
|
+
validateConfigPaths(c.applications);
|
|
890
|
+
validateConfigDefaultApplication(c.applications);
|
|
891
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
892
|
+
validateDeprecatedFields(c);
|
|
751
893
|
}
|
|
752
894
|
return c;
|
|
753
895
|
}
|
|
754
896
|
static fromEnv({
|
|
755
|
-
meta,
|
|
756
897
|
cookies
|
|
757
898
|
}) {
|
|
758
899
|
return new MicrofrontendConfigIsomorphic({
|
|
759
|
-
config:
|
|
760
|
-
overrides: parseOverrides(cookies ?? [])
|
|
761
|
-
meta
|
|
900
|
+
config: parse2(getConfigStringFromEnv()),
|
|
901
|
+
overrides: parseOverrides(cookies ?? [])
|
|
762
902
|
});
|
|
763
903
|
}
|
|
764
904
|
isOverridesDisabled() {
|
|
@@ -783,7 +923,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
783
923
|
].filter(Boolean);
|
|
784
924
|
}
|
|
785
925
|
getApplication(name) {
|
|
786
|
-
if (this.defaultApplication
|
|
926
|
+
if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
|
|
787
927
|
return this.defaultApplication;
|
|
788
928
|
}
|
|
789
929
|
const app = this.childApplications[name] || Object.values(this.childApplications).find(
|
|
@@ -801,7 +941,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
801
941
|
return app;
|
|
802
942
|
}
|
|
803
943
|
getApplicationByProjectId(projectId) {
|
|
804
|
-
if (this.defaultApplication
|
|
944
|
+
if (this.defaultApplication.projectId === projectId) {
|
|
805
945
|
return this.defaultApplication;
|
|
806
946
|
}
|
|
807
947
|
return Object.values(this.childApplications).find(
|
|
@@ -809,19 +949,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
809
949
|
);
|
|
810
950
|
}
|
|
811
951
|
/**
|
|
812
|
-
* Returns the default application.
|
|
813
|
-
* is undefined ( )
|
|
952
|
+
* Returns the default application.
|
|
814
953
|
*/
|
|
815
954
|
getDefaultApplication() {
|
|
816
|
-
if (!this.defaultApplication) {
|
|
817
|
-
throw new MicrofrontendError(
|
|
818
|
-
"Could not find default application in microfrontends configuration",
|
|
819
|
-
{
|
|
820
|
-
type: "application",
|
|
821
|
-
subtype: "not_found"
|
|
822
|
-
}
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
955
|
return this.defaultApplication;
|
|
826
956
|
}
|
|
827
957
|
/**
|
|
@@ -848,11 +978,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
848
978
|
}
|
|
849
979
|
])
|
|
850
980
|
);
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
};
|
|
855
|
-
}
|
|
981
|
+
applications[this.defaultApplication.name] = {
|
|
982
|
+
default: true
|
|
983
|
+
};
|
|
856
984
|
return new MicrofrontendConfigClient({
|
|
857
985
|
applications
|
|
858
986
|
});
|
|
@@ -862,304 +990,6 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
862
990
|
}
|
|
863
991
|
};
|
|
864
992
|
|
|
865
|
-
// src/config/microfrontends-config/isomorphic/child.ts
|
|
866
|
-
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
867
|
-
constructor({
|
|
868
|
-
config,
|
|
869
|
-
overrides,
|
|
870
|
-
meta
|
|
871
|
-
}) {
|
|
872
|
-
super({ config, overrides, meta });
|
|
873
|
-
this.isMainConfig = false;
|
|
874
|
-
this.partOf = config.partOf;
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
// src/config/microfrontends-config/isomorphic/main.ts
|
|
879
|
-
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
880
|
-
constructor({
|
|
881
|
-
config,
|
|
882
|
-
overrides,
|
|
883
|
-
meta
|
|
884
|
-
}) {
|
|
885
|
-
super({ config, overrides, meta });
|
|
886
|
-
this.isMainConfig = true;
|
|
887
|
-
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
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,
|
|
894
|
-
overrides: appOverrides
|
|
895
|
-
});
|
|
896
|
-
} else {
|
|
897
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
898
|
-
app: appConfig,
|
|
899
|
-
overrides: appOverrides
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (!defaultApplication) {
|
|
904
|
-
throw new MicrofrontendError(
|
|
905
|
-
"Could not find default application in microfrontends configuration",
|
|
906
|
-
{
|
|
907
|
-
type: "application",
|
|
908
|
-
subtype: "not_found"
|
|
909
|
-
}
|
|
910
|
-
);
|
|
911
|
-
}
|
|
912
|
-
this.defaultApplication = defaultApplication;
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
// src/config/microfrontends/isomorphic/index.ts
|
|
917
|
-
var Microfrontends = class {
|
|
918
|
-
constructor({
|
|
919
|
-
config,
|
|
920
|
-
overrides,
|
|
921
|
-
meta
|
|
922
|
-
}) {
|
|
923
|
-
if (isMainConfig(config)) {
|
|
924
|
-
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
925
|
-
} else {
|
|
926
|
-
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
isChildConfig() {
|
|
930
|
-
return this.config instanceof MicrofrontendChildConfig;
|
|
931
|
-
}
|
|
932
|
-
static fromEnv({
|
|
933
|
-
cookies,
|
|
934
|
-
meta
|
|
935
|
-
}) {
|
|
936
|
-
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
937
|
-
cookies,
|
|
938
|
-
meta
|
|
939
|
-
});
|
|
940
|
-
return new Microfrontends(config.serialize());
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
// src/config/microfrontends/utils/find-repository-root.ts
|
|
945
|
-
import fs from "node:fs";
|
|
946
|
-
import path from "node:path";
|
|
947
|
-
var GIT_DIRECTORY = ".git";
|
|
948
|
-
function hasGitDirectory(dir) {
|
|
949
|
-
const gitPath = path.join(dir, GIT_DIRECTORY);
|
|
950
|
-
return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
|
|
951
|
-
}
|
|
952
|
-
function hasPnpmWorkspaces(dir) {
|
|
953
|
-
return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
|
|
954
|
-
}
|
|
955
|
-
function findRepositoryRoot(startDir) {
|
|
956
|
-
if (process.env.NX_WORKSPACE_ROOT) {
|
|
957
|
-
return process.env.NX_WORKSPACE_ROOT;
|
|
958
|
-
}
|
|
959
|
-
let currentDir = startDir || process.cwd();
|
|
960
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
961
|
-
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
962
|
-
return currentDir;
|
|
963
|
-
}
|
|
964
|
-
currentDir = path.dirname(currentDir);
|
|
965
|
-
}
|
|
966
|
-
throw new Error(
|
|
967
|
-
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
// src/config/microfrontends/utils/find-package-path.ts
|
|
972
|
-
import { dirname } from "node:path";
|
|
973
|
-
import { readFileSync } from "node:fs";
|
|
974
|
-
import fg from "fast-glob";
|
|
975
|
-
var configCache = {};
|
|
976
|
-
function findPackagePathWithGlob({
|
|
977
|
-
repositoryRoot,
|
|
978
|
-
name
|
|
979
|
-
}) {
|
|
980
|
-
try {
|
|
981
|
-
const packageJsonPaths = fg.globSync("**/package.json", {
|
|
982
|
-
cwd: repositoryRoot,
|
|
983
|
-
absolute: true,
|
|
984
|
-
onlyFiles: true,
|
|
985
|
-
followSymbolicLinks: false,
|
|
986
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
987
|
-
});
|
|
988
|
-
const matchingPaths = [];
|
|
989
|
-
for (const packageJsonPath2 of packageJsonPaths) {
|
|
990
|
-
const packageJsonContent = readFileSync(packageJsonPath2, "utf-8");
|
|
991
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
992
|
-
if (packageJson.name === name) {
|
|
993
|
-
matchingPaths.push(packageJsonPath2);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
if (matchingPaths.length > 1) {
|
|
997
|
-
throw new Error(
|
|
998
|
-
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
999
|
-
);
|
|
1000
|
-
}
|
|
1001
|
-
if (matchingPaths.length === 0) {
|
|
1002
|
-
throw new Error(
|
|
1003
|
-
`Could not find package with the name "${name}" in the repository`
|
|
1004
|
-
);
|
|
1005
|
-
}
|
|
1006
|
-
const [packageJsonPath] = matchingPaths;
|
|
1007
|
-
return dirname(packageJsonPath);
|
|
1008
|
-
} catch (error) {
|
|
1009
|
-
return null;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
function findPackagePath(opts) {
|
|
1013
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
1014
|
-
if (configCache[cacheKey]) {
|
|
1015
|
-
return configCache[cacheKey];
|
|
1016
|
-
}
|
|
1017
|
-
const result = findPackagePathWithGlob(opts);
|
|
1018
|
-
if (!result) {
|
|
1019
|
-
throw new Error(
|
|
1020
|
-
`Could not find package with the name "${opts.name}" in the repository`
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
configCache[cacheKey] = result;
|
|
1024
|
-
return result;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1028
|
-
import { dirname as dirname2 } from "node:path";
|
|
1029
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
1030
|
-
import { parse as parse2 } from "jsonc-parser";
|
|
1031
|
-
import fg2 from "fast-glob";
|
|
1032
|
-
|
|
1033
|
-
// src/config/constants.ts
|
|
1034
|
-
var CONFIGURATION_FILENAMES = [
|
|
1035
|
-
"microfrontends.jsonc",
|
|
1036
|
-
"microfrontends.json"
|
|
1037
|
-
];
|
|
1038
|
-
|
|
1039
|
-
// src/config/microfrontends/utils/find-default-package.ts
|
|
1040
|
-
var configCache2 = {};
|
|
1041
|
-
function findDefaultMicrofrontendsPackages({
|
|
1042
|
-
repositoryRoot,
|
|
1043
|
-
applicationName
|
|
1044
|
-
}) {
|
|
1045
|
-
try {
|
|
1046
|
-
const microfrontendsJsonPaths = fg2.globSync(
|
|
1047
|
-
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
1048
|
-
{
|
|
1049
|
-
cwd: repositoryRoot,
|
|
1050
|
-
absolute: true,
|
|
1051
|
-
onlyFiles: true,
|
|
1052
|
-
followSymbolicLinks: false,
|
|
1053
|
-
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1054
|
-
}
|
|
1055
|
-
);
|
|
1056
|
-
const matchingPaths = [];
|
|
1057
|
-
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1058
|
-
try {
|
|
1059
|
-
const microfrontendsJsonContent = readFileSync2(
|
|
1060
|
-
microfrontendsJsonPath,
|
|
1061
|
-
"utf-8"
|
|
1062
|
-
);
|
|
1063
|
-
const microfrontendsJson = parse2(microfrontendsJsonContent);
|
|
1064
|
-
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
1065
|
-
matchingPaths.push(microfrontendsJsonPath);
|
|
1066
|
-
}
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
if (matchingPaths.length > 1) {
|
|
1071
|
-
throw new Error(
|
|
1072
|
-
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
1073
|
-
${matchingPaths.join("\n \u2022 ")}`
|
|
1074
|
-
);
|
|
1075
|
-
}
|
|
1076
|
-
if (matchingPaths.length === 0) {
|
|
1077
|
-
throw new Error(
|
|
1078
|
-
`Could not find default application with "applications.${applicationName}"`
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
const [packageJsonPath] = matchingPaths;
|
|
1082
|
-
return dirname2(packageJsonPath);
|
|
1083
|
-
} catch (error) {
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
function findDefaultMicrofrontendsPackage(opts) {
|
|
1088
|
-
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
1089
|
-
if (configCache2[cacheKey]) {
|
|
1090
|
-
return configCache2[cacheKey];
|
|
1091
|
-
}
|
|
1092
|
-
const result = findDefaultMicrofrontendsPackages(opts);
|
|
1093
|
-
if (!result) {
|
|
1094
|
-
throw new Error(
|
|
1095
|
-
"Error trying to resolve the main microfrontends configuration"
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
configCache2[cacheKey] = result;
|
|
1099
|
-
return result;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1103
|
-
import fs2 from "node:fs";
|
|
1104
|
-
import path2 from "node:path";
|
|
1105
|
-
function isMonorepo({
|
|
1106
|
-
repositoryRoot
|
|
1107
|
-
}) {
|
|
1108
|
-
try {
|
|
1109
|
-
if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
1110
|
-
return true;
|
|
1111
|
-
}
|
|
1112
|
-
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1113
|
-
return true;
|
|
1114
|
-
}
|
|
1115
|
-
if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
|
|
1116
|
-
return true;
|
|
1117
|
-
}
|
|
1118
|
-
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
1119
|
-
if (!fs2.existsSync(packageJsonPath)) {
|
|
1120
|
-
return false;
|
|
1121
|
-
}
|
|
1122
|
-
const packageJson = JSON.parse(
|
|
1123
|
-
fs2.readFileSync(packageJsonPath, "utf-8")
|
|
1124
|
-
);
|
|
1125
|
-
return packageJson.workspaces !== void 0;
|
|
1126
|
-
} catch (error) {
|
|
1127
|
-
console.error("Error determining if repository is a monorepo", error);
|
|
1128
|
-
return false;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
// src/config/microfrontends/utils/find-package-root.ts
|
|
1133
|
-
import fs3 from "node:fs";
|
|
1134
|
-
import path3 from "node:path";
|
|
1135
|
-
var PACKAGE_JSON = "package.json";
|
|
1136
|
-
function findPackageRoot(startDir) {
|
|
1137
|
-
let currentDir = startDir || process.cwd();
|
|
1138
|
-
while (currentDir !== path3.parse(currentDir).root) {
|
|
1139
|
-
const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
|
|
1140
|
-
if (fs3.existsSync(pkgJsonPath)) {
|
|
1141
|
-
return currentDir;
|
|
1142
|
-
}
|
|
1143
|
-
currentDir = path3.dirname(currentDir);
|
|
1144
|
-
}
|
|
1145
|
-
throw new Error(
|
|
1146
|
-
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
// src/config/microfrontends/utils/find-config.ts
|
|
1151
|
-
import fs4 from "node:fs";
|
|
1152
|
-
import { join } from "node:path";
|
|
1153
|
-
function findConfig({ dir }) {
|
|
1154
|
-
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1155
|
-
const maybeConfig = join(dir, filename);
|
|
1156
|
-
if (fs4.existsSync(maybeConfig)) {
|
|
1157
|
-
return maybeConfig;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
return null;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
993
|
// src/config/microfrontends/utils/get-application-context.ts
|
|
1164
994
|
import fs5 from "node:fs";
|
|
1165
995
|
import path4 from "node:path";
|
|
@@ -1216,16 +1046,6 @@ var schema_default = {
|
|
|
1216
1046
|
$ref: "#/definitions/Config",
|
|
1217
1047
|
definitions: {
|
|
1218
1048
|
Config: {
|
|
1219
|
-
anyOf: [
|
|
1220
|
-
{
|
|
1221
|
-
$ref: "#/definitions/MainConfig"
|
|
1222
|
-
},
|
|
1223
|
-
{
|
|
1224
|
-
$ref: "#/definitions/ChildConfig"
|
|
1225
|
-
}
|
|
1226
|
-
]
|
|
1227
|
-
},
|
|
1228
|
-
MainConfig: {
|
|
1229
1049
|
type: "object",
|
|
1230
1050
|
properties: {
|
|
1231
1051
|
$schema: {
|
|
@@ -1482,27 +1302,6 @@ var schema_default = {
|
|
|
1482
1302
|
},
|
|
1483
1303
|
required: ["paths"],
|
|
1484
1304
|
additionalProperties: false
|
|
1485
|
-
},
|
|
1486
|
-
ChildConfig: {
|
|
1487
|
-
type: "object",
|
|
1488
|
-
properties: {
|
|
1489
|
-
$schema: {
|
|
1490
|
-
type: "string"
|
|
1491
|
-
},
|
|
1492
|
-
version: {
|
|
1493
|
-
type: "string",
|
|
1494
|
-
const: "1"
|
|
1495
|
-
},
|
|
1496
|
-
options: {
|
|
1497
|
-
$ref: "#/definitions/Options"
|
|
1498
|
-
},
|
|
1499
|
-
partOf: {
|
|
1500
|
-
type: "string",
|
|
1501
|
-
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."
|
|
1502
|
-
}
|
|
1503
|
-
},
|
|
1504
|
-
required: ["partOf"],
|
|
1505
|
-
additionalProperties: false
|
|
1506
1305
|
}
|
|
1507
1306
|
}
|
|
1508
1307
|
};
|
|
@@ -1580,7 +1379,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
|
1580
1379
|
}
|
|
1581
1380
|
|
|
1582
1381
|
// src/config/microfrontends/server/index.ts
|
|
1583
|
-
var MicrofrontendsServer = class
|
|
1382
|
+
var MicrofrontendsServer = class {
|
|
1383
|
+
constructor({
|
|
1384
|
+
config,
|
|
1385
|
+
overrides
|
|
1386
|
+
}) {
|
|
1387
|
+
this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
|
|
1388
|
+
}
|
|
1584
1389
|
/**
|
|
1585
1390
|
* Writes the configuration to a file.
|
|
1586
1391
|
*/
|
|
@@ -1588,7 +1393,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1588
1393
|
pretty: true
|
|
1589
1394
|
}) {
|
|
1590
1395
|
const outputPath = getOutputFilePath();
|
|
1591
|
-
fs6.mkdirSync(
|
|
1396
|
+
fs6.mkdirSync(dirname2(outputPath), { recursive: true });
|
|
1592
1397
|
fs6.writeFileSync(
|
|
1593
1398
|
outputPath,
|
|
1594
1399
|
JSON.stringify(
|
|
@@ -1604,22 +1409,19 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1604
1409
|
*/
|
|
1605
1410
|
static fromUnknown({
|
|
1606
1411
|
config,
|
|
1607
|
-
cookies
|
|
1608
|
-
meta
|
|
1412
|
+
cookies
|
|
1609
1413
|
}) {
|
|
1610
1414
|
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1611
1415
|
if (typeof config === "string") {
|
|
1612
1416
|
return new MicrofrontendsServer({
|
|
1613
1417
|
config: MicrofrontendsServer.validate(config),
|
|
1614
|
-
overrides
|
|
1615
|
-
meta
|
|
1418
|
+
overrides
|
|
1616
1419
|
});
|
|
1617
1420
|
}
|
|
1618
1421
|
if (typeof config === "object") {
|
|
1619
1422
|
return new MicrofrontendsServer({
|
|
1620
1423
|
config,
|
|
1621
|
-
overrides
|
|
1622
|
-
meta
|
|
1424
|
+
overrides
|
|
1623
1425
|
});
|
|
1624
1426
|
}
|
|
1625
1427
|
throw new MicrofrontendError(
|
|
@@ -1632,13 +1434,11 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1632
1434
|
* Uses additional validation that is only available when in a node runtime
|
|
1633
1435
|
*/
|
|
1634
1436
|
static fromEnv({
|
|
1635
|
-
cookies
|
|
1636
|
-
meta
|
|
1437
|
+
cookies
|
|
1637
1438
|
}) {
|
|
1638
1439
|
return new MicrofrontendsServer({
|
|
1639
1440
|
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1640
|
-
overrides: parseOverrides(cookies)
|
|
1641
|
-
meta
|
|
1441
|
+
overrides: parseOverrides(cookies)
|
|
1642
1442
|
});
|
|
1643
1443
|
}
|
|
1644
1444
|
/**
|
|
@@ -1661,29 +1461,22 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1661
1461
|
static infer({
|
|
1662
1462
|
directory,
|
|
1663
1463
|
filePath,
|
|
1664
|
-
|
|
1665
|
-
cookies,
|
|
1666
|
-
options
|
|
1464
|
+
cookies
|
|
1667
1465
|
} = {}) {
|
|
1668
|
-
if (filePath
|
|
1466
|
+
if (filePath) {
|
|
1669
1467
|
return MicrofrontendsServer.fromFile({
|
|
1670
1468
|
filePath,
|
|
1671
|
-
cookies
|
|
1672
|
-
meta,
|
|
1673
|
-
options
|
|
1469
|
+
cookies
|
|
1674
1470
|
});
|
|
1675
1471
|
}
|
|
1676
1472
|
try {
|
|
1677
1473
|
const packageRoot = findPackageRoot(directory);
|
|
1678
1474
|
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1679
|
-
const configMeta = meta ?? { fromApp: appName };
|
|
1680
1475
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1681
1476
|
if (maybeConfig) {
|
|
1682
1477
|
return MicrofrontendsServer.fromFile({
|
|
1683
1478
|
filePath: maybeConfig,
|
|
1684
|
-
cookies
|
|
1685
|
-
meta: configMeta,
|
|
1686
|
-
options
|
|
1479
|
+
cookies
|
|
1687
1480
|
});
|
|
1688
1481
|
}
|
|
1689
1482
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1697,9 +1490,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1697
1490
|
if (maybeConfigFromDefault) {
|
|
1698
1491
|
return MicrofrontendsServer.fromFile({
|
|
1699
1492
|
filePath: maybeConfigFromDefault,
|
|
1700
|
-
cookies
|
|
1701
|
-
meta: configMeta,
|
|
1702
|
-
options
|
|
1493
|
+
cookies
|
|
1703
1494
|
});
|
|
1704
1495
|
}
|
|
1705
1496
|
}
|
|
@@ -1719,44 +1510,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1719
1510
|
*/
|
|
1720
1511
|
static fromFile({
|
|
1721
1512
|
filePath,
|
|
1722
|
-
cookies
|
|
1723
|
-
meta,
|
|
1724
|
-
options
|
|
1513
|
+
cookies
|
|
1725
1514
|
}) {
|
|
1726
1515
|
try {
|
|
1727
1516
|
const configJson = fs6.readFileSync(filePath, "utf-8");
|
|
1728
1517
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1729
|
-
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1730
|
-
const repositoryRoot = findRepositoryRoot();
|
|
1731
|
-
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1732
|
-
if (isMonorepo2) {
|
|
1733
|
-
const packagePath = findPackagePath({
|
|
1734
|
-
repositoryRoot,
|
|
1735
|
-
name: config.partOf
|
|
1736
|
-
});
|
|
1737
|
-
if (!packagePath) {
|
|
1738
|
-
throw new MicrofrontendError(
|
|
1739
|
-
`Could not find default application "${config.partOf}" in the repository`,
|
|
1740
|
-
{ type: "config", subtype: "not_found" }
|
|
1741
|
-
);
|
|
1742
|
-
}
|
|
1743
|
-
const maybeConfig = findConfig({ dir: packagePath });
|
|
1744
|
-
if (!maybeConfig) {
|
|
1745
|
-
throw new MicrofrontendError(
|
|
1746
|
-
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1747
|
-
{ type: "config", subtype: "not_found" }
|
|
1748
|
-
);
|
|
1749
|
-
}
|
|
1750
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1751
|
-
filePath: maybeConfig,
|
|
1752
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
1518
|
return new MicrofrontendsServer({
|
|
1757
1519
|
config,
|
|
1758
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1759
|
-
meta
|
|
1520
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1760
1521
|
});
|
|
1761
1522
|
} catch (e) {
|
|
1762
1523
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1765,7 +1526,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1765
1526
|
}
|
|
1766
1527
|
}
|
|
1767
1528
|
/*
|
|
1768
|
-
* Generates a
|
|
1529
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1769
1530
|
*/
|
|
1770
1531
|
static fromMainConfigFile({
|
|
1771
1532
|
filePath,
|
|
@@ -1774,15 +1535,6 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1774
1535
|
try {
|
|
1775
1536
|
const config = fs6.readFileSync(filePath, "utf-8");
|
|
1776
1537
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1777
|
-
if (!isMainConfig(validatedConfig)) {
|
|
1778
|
-
throw new MicrofrontendError(
|
|
1779
|
-
`${filePath} is not a main microfrontend config`,
|
|
1780
|
-
{
|
|
1781
|
-
type: "config",
|
|
1782
|
-
subtype: "invalid_main_path"
|
|
1783
|
-
}
|
|
1784
|
-
);
|
|
1785
|
-
}
|
|
1786
1538
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1787
1539
|
if (!defaultApplication) {
|
|
1788
1540
|
throw new MicrofrontendError(
|
|
@@ -1792,8 +1544,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1792
1544
|
}
|
|
1793
1545
|
return new MicrofrontendsServer({
|
|
1794
1546
|
config: validatedConfig,
|
|
1795
|
-
overrides
|
|
1796
|
-
meta: { fromApp: defaultApplication }
|
|
1547
|
+
overrides
|
|
1797
1548
|
});
|
|
1798
1549
|
} catch (e) {
|
|
1799
1550
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1820,43 +1571,39 @@ function detectFramework() {
|
|
|
1820
1571
|
// src/vite/index.ts
|
|
1821
1572
|
function microfrontends(opts) {
|
|
1822
1573
|
const { name: fromApp } = getApplicationContext();
|
|
1823
|
-
const microfrontendsObj = MicrofrontendsServer.infer(
|
|
1824
|
-
meta: {
|
|
1825
|
-
fromApp
|
|
1826
|
-
}
|
|
1827
|
-
});
|
|
1574
|
+
const microfrontendsObj = MicrofrontendsServer.infer();
|
|
1828
1575
|
const app = microfrontendsObj.config.getApplication(fromApp);
|
|
1829
1576
|
if (app.isDefault() && opts?.basePath) {
|
|
1830
1577
|
throw new Error(
|
|
1831
1578
|
"`basePath` can not be set for the default microfrontends application."
|
|
1832
1579
|
);
|
|
1833
1580
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1581
|
+
const framework = detectFramework();
|
|
1582
|
+
if (framework === "sveltekit" && opts?.basePath) {
|
|
1583
|
+
throw new Error("`basePath` is not supported for SvelteKit applications.");
|
|
1584
|
+
}
|
|
1585
|
+
if (opts?.basePath && (!opts.basePath.startsWith("/") || opts.basePath.endsWith("/"))) {
|
|
1586
|
+
throw new Error("`basePath` must start with a `/` and not end with a `/`");
|
|
1836
1587
|
}
|
|
1837
1588
|
const additionalConfigOptions = {};
|
|
1838
|
-
const framework = detectFramework();
|
|
1839
1589
|
if (!app.isDefault()) {
|
|
1840
1590
|
if (opts?.basePath) {
|
|
1591
|
+
const basePath = opts.basePath;
|
|
1841
1592
|
if (framework !== "react-router" || !process.env.VERCEL_ENV) {
|
|
1842
|
-
let basePath = opts.basePath;
|
|
1843
|
-
if (process.env.NODE_ENV === "production" && !basePath.endsWith("/")) {
|
|
1844
|
-
basePath = `${basePath}/`;
|
|
1845
|
-
}
|
|
1846
1593
|
additionalConfigOptions.base = basePath;
|
|
1847
1594
|
}
|
|
1595
|
+
if (framework === "react-router") {
|
|
1596
|
+
additionalConfigOptions.build = {
|
|
1597
|
+
assetsDir: `./${basePath}`
|
|
1598
|
+
};
|
|
1599
|
+
} else {
|
|
1600
|
+
additionalConfigOptions.build = {
|
|
1601
|
+
outDir: `dist${opts.basePath}`
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1848
1604
|
} else if (framework !== "sveltekit") {
|
|
1849
|
-
additionalConfigOptions.experimental = {
|
|
1850
|
-
renderBuiltUrl(filename, { type }) {
|
|
1851
|
-
if (type === "asset") {
|
|
1852
|
-
return `/${app.getAssetPrefix()}/${filename}`;
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
if (framework !== "sveltekit") {
|
|
1858
1605
|
additionalConfigOptions.build = {
|
|
1859
|
-
assetsDir: `./${
|
|
1606
|
+
assetsDir: `./${app.getAssetPrefix()}`
|
|
1860
1607
|
};
|
|
1861
1608
|
}
|
|
1862
1609
|
}
|
|
@@ -1864,6 +1611,15 @@ function microfrontends(opts) {
|
|
|
1864
1611
|
additionalConfigOptions.server = {
|
|
1865
1612
|
port: app.development.local.port
|
|
1866
1613
|
};
|
|
1614
|
+
additionalConfigOptions.preview = {
|
|
1615
|
+
port: app.development.local.port
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
if (process.env.MFE_DEBUG) {
|
|
1619
|
+
console.log(
|
|
1620
|
+
"[@vercel/microfrontends] Updating Vite configuration with the following changes:",
|
|
1621
|
+
additionalConfigOptions
|
|
1622
|
+
);
|
|
1867
1623
|
}
|
|
1868
1624
|
return {
|
|
1869
1625
|
name: "vite-plugin-vercel-microfrontends",
|