@vercel/microfrontends 1.0.1-canary.1 → 1.0.1-canary.3
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 +43 -33
- package/dist/config.cjs +41 -32
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +41 -32
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +41 -32
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +41 -32
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +88 -46
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.d.ts +1 -1
- package/dist/experimental/vite.js +88 -48
- package/dist/experimental/vite.js.map +1 -1
- package/dist/{index-d5994ac5.d.ts → index-2b59c627.d.ts} +1 -1
- package/dist/microfrontends/server.cjs +41 -32
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +1 -1
- package/dist/microfrontends/server.js +41 -32
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +41 -32
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +1 -1
- package/dist/microfrontends.js +41 -32
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/config.cjs +205 -131
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +7 -1
- package/dist/next/config.js +205 -131
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +41 -32
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +41 -32
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +41 -32
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +2 -2
- package/dist/next/testing.js +42 -33
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +41 -32
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +41 -32
- package/dist/utils/mfe-port.js.map +1 -1
- package/package.json +2 -1
|
@@ -33,9 +33,6 @@ __export(vite_exports, {
|
|
|
33
33
|
microfrontends: () => microfrontends
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(vite_exports);
|
|
36
|
-
var import_node_fs9 = require("fs");
|
|
37
|
-
var import_node_path9 = require("path");
|
|
38
|
-
var import_node_process = require("process");
|
|
39
36
|
|
|
40
37
|
// src/config/microfrontends/server/index.ts
|
|
41
38
|
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
@@ -275,16 +272,17 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
275
272
|
const maybeError = validatePathExpression(path5);
|
|
276
273
|
if (maybeError) {
|
|
277
274
|
errors.push(maybeError);
|
|
278
|
-
}
|
|
279
|
-
const existing = pathsByApplicationId.get(path5);
|
|
280
|
-
if (existing) {
|
|
281
|
-
existing.applications.push(id);
|
|
282
275
|
} else {
|
|
283
|
-
pathsByApplicationId.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
276
|
+
const existing = pathsByApplicationId.get(path5);
|
|
277
|
+
if (existing) {
|
|
278
|
+
existing.applications.push(id);
|
|
279
|
+
} else {
|
|
280
|
+
pathsByApplicationId.set(path5, {
|
|
281
|
+
applications: [id],
|
|
282
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
|
|
283
|
+
applicationId: id
|
|
284
|
+
});
|
|
285
|
+
}
|
|
288
286
|
}
|
|
289
287
|
}
|
|
290
288
|
}
|
|
@@ -324,26 +322,38 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
324
322
|
};
|
|
325
323
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
326
324
|
function validatePathExpression(path5) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (token
|
|
341
|
-
return `
|
|
325
|
+
try {
|
|
326
|
+
const tokens = (0, import_path_to_regexp2.parse)(path5);
|
|
327
|
+
if (/(?<!\\)\{/.test(path5)) {
|
|
328
|
+
return `Optional paths are not supported: ${path5}`;
|
|
329
|
+
}
|
|
330
|
+
if (/(?<!\\|\()\?/.test(path5)) {
|
|
331
|
+
return `Optional paths are not supported: ${path5}`;
|
|
332
|
+
}
|
|
333
|
+
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path5)) {
|
|
334
|
+
return `Only one wildcard is allowed per path segment: ${path5}`;
|
|
335
|
+
}
|
|
336
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
337
|
+
const token = tokens[i];
|
|
338
|
+
if (token === void 0) {
|
|
339
|
+
return `token ${i} in ${path5} is undefined, this shouldn't happen`;
|
|
342
340
|
}
|
|
343
|
-
if (token
|
|
344
|
-
|
|
341
|
+
if (typeof token !== "string") {
|
|
342
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
343
|
+
// Only limited regex is supported for now, due to performance considerations
|
|
344
|
+
!/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
|
|
345
|
+
token.pattern
|
|
346
|
+
)) {
|
|
347
|
+
return `Path ${path5} cannot use unsupported regular expression wildcard`;
|
|
348
|
+
}
|
|
349
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
350
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
|
|
351
|
+
}
|
|
345
352
|
}
|
|
346
353
|
}
|
|
354
|
+
} catch (e) {
|
|
355
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
356
|
+
return `Path ${path5} could not be parsed into regexp: ${message}`;
|
|
347
357
|
}
|
|
348
358
|
return void 0;
|
|
349
359
|
}
|
|
@@ -697,12 +707,8 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
697
707
|
const skipValidation = opts?.skipValidation ?? [];
|
|
698
708
|
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
699
709
|
if (isMainConfig(c)) {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
if (!skipValidation.includes("defaultApplication")) {
|
|
704
|
-
validateConfigDefaultApplication(c.applications);
|
|
705
|
-
}
|
|
710
|
+
validateConfigPaths(c.applications);
|
|
711
|
+
validateConfigDefaultApplication(c.applications);
|
|
706
712
|
if (!skipValidation.includes("deprecatedFields")) {
|
|
707
713
|
validateDeprecatedFields(c);
|
|
708
714
|
}
|
|
@@ -1697,6 +1703,20 @@ function getApplicationContext(opts) {
|
|
|
1697
1703
|
}
|
|
1698
1704
|
}
|
|
1699
1705
|
|
|
1706
|
+
// src/vite/detect-framework.ts
|
|
1707
|
+
var import_node_fs9 = require("fs");
|
|
1708
|
+
var import_node_path9 = require("path");
|
|
1709
|
+
var import_node_process = require("process");
|
|
1710
|
+
function detectFramework() {
|
|
1711
|
+
if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "svelte.config.js"))) {
|
|
1712
|
+
return "sveltekit";
|
|
1713
|
+
}
|
|
1714
|
+
if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.js")) || (0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.ts"))) {
|
|
1715
|
+
return "react-router";
|
|
1716
|
+
}
|
|
1717
|
+
return "unknown";
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1700
1720
|
// src/vite/index.ts
|
|
1701
1721
|
function microfrontends(opts) {
|
|
1702
1722
|
const { name: fromApp } = getApplicationContext();
|
|
@@ -1706,22 +1726,44 @@ function microfrontends(opts) {
|
|
|
1706
1726
|
}
|
|
1707
1727
|
});
|
|
1708
1728
|
const app = microfrontendsObj.config.getApplication(fromApp);
|
|
1729
|
+
if (app.isDefault() && opts?.basePath) {
|
|
1730
|
+
throw new Error(
|
|
1731
|
+
"`basePath` can not be set for the default microfrontends application."
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
if (opts?.basePath && !opts.basePath.startsWith("/")) {
|
|
1735
|
+
throw new Error("`basePath` must start with a `/`");
|
|
1736
|
+
}
|
|
1709
1737
|
const additionalConfigOptions = {};
|
|
1738
|
+
const framework = detectFramework();
|
|
1710
1739
|
if (!app.isDefault()) {
|
|
1711
1740
|
if (opts?.basePath) {
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
if (type === "asset") {
|
|
1719
|
-
return `/${app.getAssetPrefix()}/${filename}`;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1741
|
+
if (framework !== "react-router" || !process.env.VERCEL_ENV) {
|
|
1742
|
+
let basePath = opts.basePath;
|
|
1743
|
+
if (process.env.NODE_ENV === "production" && !basePath.endsWith("/")) {
|
|
1744
|
+
basePath = `${basePath}/`;
|
|
1745
|
+
}
|
|
1746
|
+
additionalConfigOptions.base = basePath;
|
|
1723
1747
|
}
|
|
1748
|
+
} else if (framework !== "sveltekit") {
|
|
1749
|
+
additionalConfigOptions.experimental = {
|
|
1750
|
+
renderBuiltUrl(filename, { type }) {
|
|
1751
|
+
if (type === "asset") {
|
|
1752
|
+
return `/${app.getAssetPrefix()}/${filename}`;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1724
1756
|
}
|
|
1757
|
+
if (framework === "react-router") {
|
|
1758
|
+
additionalConfigOptions.build = {
|
|
1759
|
+
assetsDir: `./${opts?.basePath ?? app.getAssetPrefix()}`
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
if (app.development.local.port) {
|
|
1764
|
+
additionalConfigOptions.server = {
|
|
1765
|
+
port: app.development.local.port
|
|
1766
|
+
};
|
|
1725
1767
|
}
|
|
1726
1768
|
return {
|
|
1727
1769
|
name: "vite-plugin-vercel-microfrontends",
|