@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.12 → 3.9.0-ultramodern.14
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/cjs/backend-federation-security/node.js +3 -3
- package/dist/cjs/localisedLoader.js +65 -0
- package/dist/cjs/localisedLoaderPlugin.js +2 -23
- package/dist/esm/backend-federation-security/node.mjs +3 -3
- package/dist/esm/localisedLoader.mjs +24 -0
- package/dist/esm/localisedLoaderPlugin.mjs +2 -23
- package/dist/esm-node/backend-federation-security/node.mjs +3 -3
- package/dist/esm-node/localisedLoader.mjs +25 -0
- package/dist/esm-node/localisedLoaderPlugin.mjs +2 -23
- package/dist/types/backend-federation-security/node.d.ts +1 -1
- package/dist/types/localisedLoader.d.ts +15 -0
- package/dist/types-esm/backend-federation-security/node.d.mts +1 -1
- package/dist/types-esm/localisedLoader.d.mts +15 -0
- package/package.json +35 -13
- package/src/backend-federation-security/node.ts +32 -22
- package/src/localisedLoader.ts +50 -0
- package/src/localisedLoaderPlugin.ts +6 -38
- package/tests/backendFederationSecurity.test.ts +8 -0
- package/tests/bff-policy/zodEvaluatorProbe.test.ts +49 -0
|
@@ -50,7 +50,7 @@ function createBackendFederationEntryIntegrity(value) {
|
|
|
50
50
|
sha256: (0, external_node_crypto_namespaceObject.createHash)('sha256').update(bytes).digest('hex')
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
53
|
+
const evaluateNodeBackendFederationCommonJs = (source, { remote }, privateRuntimeCapability)=>{
|
|
54
54
|
const module = {
|
|
55
55
|
exports: {}
|
|
56
56
|
};
|
|
@@ -59,8 +59,8 @@ const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
|
59
59
|
if (!nodeBuiltins.has(specifier)) throw new external_index_js_namespaceObject.BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`);
|
|
60
60
|
return nodeRequire(specifier);
|
|
61
61
|
};
|
|
62
|
-
const evaluate = new Function('module', 'exports', 'globalThis', 'require', source);
|
|
63
|
-
evaluate(module, exports1, globalThis, requireBuiltin);
|
|
62
|
+
const evaluate = new Function('module', 'exports', 'globalThis', 'require', '__modernjs_backend_private_capability__', source);
|
|
63
|
+
evaluate(module, exports1, globalThis, requireBuiltin, privateRuntimeCapability);
|
|
64
64
|
return module.exports;
|
|
65
65
|
};
|
|
66
66
|
exports.createBackendFederationEntryIntegrity = __webpack_exports__.createBackendFederationEntryIntegrity;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
expandLocalisedLoaderRoutes: ()=>expandLocalisedLoaderRoutes,
|
|
32
|
+
resolveLocalisedLoaderRoute: ()=>resolveLocalisedLoaderRoute
|
|
33
|
+
});
|
|
34
|
+
const localised_loader_identity_namespaceObject = require("@modern-js/runtime-extensions/localised-loader-identity");
|
|
35
|
+
const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
|
|
36
|
+
function expandLocalisedLoaderRoutes(routes) {
|
|
37
|
+
const languages = new Set();
|
|
38
|
+
const localisedUrls = {};
|
|
39
|
+
let physical = false;
|
|
40
|
+
const visit = (nodes)=>{
|
|
41
|
+
for (const route of nodes){
|
|
42
|
+
physical ||= 'modernCanonicalPath' in route;
|
|
43
|
+
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
44
|
+
if (identity?.paths) {
|
|
45
|
+
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
46
|
+
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
47
|
+
}
|
|
48
|
+
if ('children' in route && route.children) visit(route.children);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
visit(routes);
|
|
52
|
+
return physical || 0 === languages.size ? routes : (0, localised_urls_namespaceObject.applyLocalisedUrlsToRoutes)(routes, [
|
|
53
|
+
...languages
|
|
54
|
+
], localisedUrls);
|
|
55
|
+
}
|
|
56
|
+
const resolveLocalisedLoaderRoute = (requestedRouteId, { routes, matchedRouteIds })=>(0, localised_loader_identity_namespaceObject.resolveLocalisedLoaderRouteId)(routes, requestedRouteId, matchedRouteIds);
|
|
57
|
+
exports.expandLocalisedLoaderRoutes = __webpack_exports__.expandLocalisedLoaderRoutes;
|
|
58
|
+
exports.resolveLocalisedLoaderRoute = __webpack_exports__.resolveLocalisedLoaderRoute;
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
60
|
+
"expandLocalisedLoaderRoutes",
|
|
61
|
+
"resolveLocalisedLoaderRoute"
|
|
62
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
63
|
+
Object.defineProperty(exports, '__esModule', {
|
|
64
|
+
value: true
|
|
65
|
+
});
|
|
@@ -31,35 +31,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
injectLocalisedLoaderPlugin: ()=>injectLocalisedLoaderPlugin
|
|
32
32
|
});
|
|
33
33
|
const runtime_namespaceObject = require("@modern-js/plugin-data-loader/runtime");
|
|
34
|
-
const localised_loader_identity_namespaceObject = require("@modern-js/runtime-extensions/localised-loader-identity");
|
|
35
|
-
const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
|
|
36
34
|
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
37
|
-
|
|
38
|
-
const languages = new Set();
|
|
39
|
-
const localisedUrls = {};
|
|
40
|
-
let physical = false;
|
|
41
|
-
const visit = (nodes)=>{
|
|
42
|
-
for (const route of nodes){
|
|
43
|
-
physical ||= 'modernCanonicalPath' in route;
|
|
44
|
-
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
45
|
-
if (identity?.paths) {
|
|
46
|
-
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
47
|
-
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
48
|
-
}
|
|
49
|
-
if ('children' in route && route.children) visit(route.children);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
visit(routes);
|
|
53
|
-
return physical || 0 === languages.size ? routes : (0, localised_urls_namespaceObject.applyLocalisedUrlsToRoutes)(routes, [
|
|
54
|
-
...languages
|
|
55
|
-
], localisedUrls);
|
|
56
|
-
}
|
|
35
|
+
const external_localisedLoader_js_namespaceObject = require("./localisedLoader.js");
|
|
57
36
|
function injectLocalisedLoaderPlugin() {
|
|
58
37
|
return {
|
|
59
38
|
name: '@modern-js/localised-loader',
|
|
60
39
|
setup (api) {
|
|
61
40
|
const handler = async (context, next)=>{
|
|
62
|
-
(0, runtime_namespaceObject.setLoaderRouteIdResolver)((0, server_core_namespaceObject.getLoaderCtx)(context),
|
|
41
|
+
(0, runtime_namespaceObject.setLoaderRouteIdResolver)((0, server_core_namespaceObject.getLoaderCtx)(context), external_localisedLoader_js_namespaceObject.resolveLocalisedLoaderRoute, external_localisedLoader_js_namespaceObject.expandLocalisedLoaderRoutes);
|
|
63
42
|
await next();
|
|
64
43
|
};
|
|
65
44
|
api.onPrepare(()=>{
|
|
@@ -14,7 +14,7 @@ function createBackendFederationEntryIntegrity(value) {
|
|
|
14
14
|
sha256: createHash('sha256').update(bytes).digest('hex')
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
17
|
+
const evaluateNodeBackendFederationCommonJs = (source, { remote }, privateRuntimeCapability)=>{
|
|
18
18
|
const module = {
|
|
19
19
|
exports: {}
|
|
20
20
|
};
|
|
@@ -23,8 +23,8 @@ const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
|
23
23
|
if (!nodeBuiltins.has(specifier)) throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`);
|
|
24
24
|
return nodeRequire(specifier);
|
|
25
25
|
};
|
|
26
|
-
const evaluate = new Function('module', 'exports', 'globalThis', 'require', source);
|
|
27
|
-
evaluate(module, exports, globalThis, requireBuiltin);
|
|
26
|
+
const evaluate = new Function('module', 'exports', 'globalThis', 'require', '__modernjs_backend_private_capability__', source);
|
|
27
|
+
evaluate(module, exports, globalThis, requireBuiltin, privateRuntimeCapability);
|
|
28
28
|
return module.exports;
|
|
29
29
|
};
|
|
30
30
|
export { createBackendFederationEntryIntegrity, evaluateNodeBackendFederationCommonJs };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
|
|
2
|
+
import { applyLocalisedUrlsToRoutes } from "@modern-js/runtime-extensions/localised-urls";
|
|
3
|
+
function expandLocalisedLoaderRoutes(routes) {
|
|
4
|
+
const languages = new Set();
|
|
5
|
+
const localisedUrls = {};
|
|
6
|
+
let physical = false;
|
|
7
|
+
const visit = (nodes)=>{
|
|
8
|
+
for (const route of nodes){
|
|
9
|
+
physical ||= 'modernCanonicalPath' in route;
|
|
10
|
+
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
11
|
+
if (identity?.paths) {
|
|
12
|
+
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
13
|
+
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
14
|
+
}
|
|
15
|
+
if ('children' in route && route.children) visit(route.children);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
visit(routes);
|
|
19
|
+
return physical || 0 === languages.size ? routes : applyLocalisedUrlsToRoutes(routes, [
|
|
20
|
+
...languages
|
|
21
|
+
], localisedUrls);
|
|
22
|
+
}
|
|
23
|
+
const resolveLocalisedLoaderRoute = (requestedRouteId, { routes, matchedRouteIds })=>resolveLocalisedLoaderRouteId(routes, requestedRouteId, matchedRouteIds);
|
|
24
|
+
export { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute };
|
|
@@ -1,33 +1,12 @@
|
|
|
1
1
|
import { setLoaderRouteIdResolver } from "@modern-js/plugin-data-loader/runtime";
|
|
2
|
-
import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
|
|
3
|
-
import { applyLocalisedUrlsToRoutes } from "@modern-js/runtime-extensions/localised-urls";
|
|
4
2
|
import { getLoaderCtx } from "@modern-js/server-core";
|
|
5
|
-
|
|
6
|
-
const languages = new Set();
|
|
7
|
-
const localisedUrls = {};
|
|
8
|
-
let physical = false;
|
|
9
|
-
const visit = (nodes)=>{
|
|
10
|
-
for (const route of nodes){
|
|
11
|
-
physical ||= 'modernCanonicalPath' in route;
|
|
12
|
-
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
13
|
-
if (identity?.paths) {
|
|
14
|
-
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
15
|
-
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
16
|
-
}
|
|
17
|
-
if ('children' in route && route.children) visit(route.children);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
visit(routes);
|
|
21
|
-
return physical || 0 === languages.size ? routes : applyLocalisedUrlsToRoutes(routes, [
|
|
22
|
-
...languages
|
|
23
|
-
], localisedUrls);
|
|
24
|
-
}
|
|
3
|
+
import { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute } from "./localisedLoader.mjs";
|
|
25
4
|
function injectLocalisedLoaderPlugin() {
|
|
26
5
|
return {
|
|
27
6
|
name: '@modern-js/localised-loader',
|
|
28
7
|
setup (api) {
|
|
29
8
|
const handler = async (context, next)=>{
|
|
30
|
-
setLoaderRouteIdResolver(getLoaderCtx(context),
|
|
9
|
+
setLoaderRouteIdResolver(getLoaderCtx(context), resolveLocalisedLoaderRoute, expandLocalisedLoaderRoutes);
|
|
31
10
|
await next();
|
|
32
11
|
};
|
|
33
12
|
api.onPrepare(()=>{
|
|
@@ -15,7 +15,7 @@ function createBackendFederationEntryIntegrity(value) {
|
|
|
15
15
|
sha256: createHash('sha256').update(bytes).digest('hex')
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
18
|
+
const evaluateNodeBackendFederationCommonJs = (source, { remote }, privateRuntimeCapability)=>{
|
|
19
19
|
const module = {
|
|
20
20
|
exports: {}
|
|
21
21
|
};
|
|
@@ -24,8 +24,8 @@ const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
|
24
24
|
if (!nodeBuiltins.has(specifier)) throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`);
|
|
25
25
|
return nodeRequire(specifier);
|
|
26
26
|
};
|
|
27
|
-
const evaluate = new Function('module', 'exports', 'globalThis', 'require', source);
|
|
28
|
-
evaluate(module, exports, globalThis, requireBuiltin);
|
|
27
|
+
const evaluate = new Function('module', 'exports', 'globalThis', 'require', '__modernjs_backend_private_capability__', source);
|
|
28
|
+
evaluate(module, exports, globalThis, requireBuiltin, privateRuntimeCapability);
|
|
29
29
|
return module.exports;
|
|
30
30
|
};
|
|
31
31
|
export { createBackendFederationEntryIntegrity, evaluateNodeBackendFederationCommonJs };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
|
|
3
|
+
import { applyLocalisedUrlsToRoutes } from "@modern-js/runtime-extensions/localised-urls";
|
|
4
|
+
function expandLocalisedLoaderRoutes(routes) {
|
|
5
|
+
const languages = new Set();
|
|
6
|
+
const localisedUrls = {};
|
|
7
|
+
let physical = false;
|
|
8
|
+
const visit = (nodes)=>{
|
|
9
|
+
for (const route of nodes){
|
|
10
|
+
physical ||= 'modernCanonicalPath' in route;
|
|
11
|
+
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
12
|
+
if (identity?.paths) {
|
|
13
|
+
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
14
|
+
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
15
|
+
}
|
|
16
|
+
if ('children' in route && route.children) visit(route.children);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
visit(routes);
|
|
20
|
+
return physical || 0 === languages.size ? routes : applyLocalisedUrlsToRoutes(routes, [
|
|
21
|
+
...languages
|
|
22
|
+
], localisedUrls);
|
|
23
|
+
}
|
|
24
|
+
const resolveLocalisedLoaderRoute = (requestedRouteId, { routes, matchedRouteIds })=>resolveLocalisedLoaderRouteId(routes, requestedRouteId, matchedRouteIds);
|
|
25
|
+
export { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute };
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { setLoaderRouteIdResolver } from "@modern-js/plugin-data-loader/runtime";
|
|
3
|
-
import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
|
|
4
|
-
import { applyLocalisedUrlsToRoutes } from "@modern-js/runtime-extensions/localised-urls";
|
|
5
3
|
import { getLoaderCtx } from "@modern-js/server-core";
|
|
6
|
-
|
|
7
|
-
const languages = new Set();
|
|
8
|
-
const localisedUrls = {};
|
|
9
|
-
let physical = false;
|
|
10
|
-
const visit = (nodes)=>{
|
|
11
|
-
for (const route of nodes){
|
|
12
|
-
physical ||= 'modernCanonicalPath' in route;
|
|
13
|
-
const identity = Reflect.get(route, 'modernLocalisedRoute');
|
|
14
|
-
if (identity?.paths) {
|
|
15
|
-
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
16
|
-
for (const language of Object.keys(identity.paths))languages.add(language);
|
|
17
|
-
}
|
|
18
|
-
if ('children' in route && route.children) visit(route.children);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
visit(routes);
|
|
22
|
-
return physical || 0 === languages.size ? routes : applyLocalisedUrlsToRoutes(routes, [
|
|
23
|
-
...languages
|
|
24
|
-
], localisedUrls);
|
|
25
|
-
}
|
|
4
|
+
import { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute } from "./localisedLoader.mjs";
|
|
26
5
|
function injectLocalisedLoaderPlugin() {
|
|
27
6
|
return {
|
|
28
7
|
name: '@modern-js/localised-loader',
|
|
29
8
|
setup (api) {
|
|
30
9
|
const handler = async (context, next)=>{
|
|
31
|
-
setLoaderRouteIdResolver(getLoaderCtx(context),
|
|
10
|
+
setLoaderRouteIdResolver(getLoaderCtx(context), resolveLocalisedLoaderRoute, expandLocalisedLoaderRoutes);
|
|
32
11
|
await next();
|
|
33
12
|
};
|
|
34
13
|
api.onPrepare(()=>{
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type BackendFederationCommonJsEvaluator, type BackendFederationEntryIntegrity } from './index.js';
|
|
2
2
|
export declare function createBackendFederationEntryIntegrity(value: string | Uint8Array): BackendFederationEntryIntegrity;
|
|
3
|
-
export declare const evaluateNodeBackendFederationCommonJs: BackendFederationCommonJsEvaluator
|
|
3
|
+
export declare const evaluateNodeBackendFederationCommonJs: (source: Parameters<BackendFederationCommonJsEvaluator>[0], { remote }: Parameters<BackendFederationCommonJsEvaluator>[1], privateRuntimeCapability?: unknown) => Record<string, unknown>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoaderRouteIdResolver } from '@modern-js/plugin-data-loader/runtime';
|
|
2
|
+
import type { ServerLoaderBundle } from '@modern-js/server-core';
|
|
3
|
+
type LoaderRoutes = ServerLoaderBundle['routes'];
|
|
4
|
+
/**
|
|
5
|
+
* Project canonical-only localized routes so loader matching sees every
|
|
6
|
+
* localized URL. Routes already emitted as physical localized aliases are
|
|
7
|
+
* returned unchanged.
|
|
8
|
+
*
|
|
9
|
+
* Runtime-neutral: shared by the Node server plugin and the Cloudflare worker
|
|
10
|
+
* route data handler.
|
|
11
|
+
*/
|
|
12
|
+
export declare function expandLocalisedLoaderRoutes(routes: LoaderRoutes): LoaderRoutes;
|
|
13
|
+
/** Resolve a canonical loader route ID to the localized alias matched by the URL. */
|
|
14
|
+
export declare const resolveLocalisedLoaderRoute: LoaderRouteIdResolver;
|
|
15
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type BackendFederationCommonJsEvaluator, type BackendFederationEntryIntegrity } from './index.mjs';
|
|
2
2
|
export declare function createBackendFederationEntryIntegrity(value: string | Uint8Array): BackendFederationEntryIntegrity;
|
|
3
|
-
export declare const evaluateNodeBackendFederationCommonJs: BackendFederationCommonJsEvaluator
|
|
3
|
+
export declare const evaluateNodeBackendFederationCommonJs: (source: Parameters<BackendFederationCommonJsEvaluator>[0], { remote }: Parameters<BackendFederationCommonJsEvaluator>[1], privateRuntimeCapability?: unknown) => Record<string, unknown>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoaderRouteIdResolver } from '@modern-js/plugin-data-loader/runtime';
|
|
2
|
+
import type { ServerLoaderBundle } from '@modern-js/server-core';
|
|
3
|
+
type LoaderRoutes = ServerLoaderBundle['routes'];
|
|
4
|
+
/**
|
|
5
|
+
* Project canonical-only localized routes so loader matching sees every
|
|
6
|
+
* localized URL. Routes already emitted as physical localized aliases are
|
|
7
|
+
* returned unchanged.
|
|
8
|
+
*
|
|
9
|
+
* Runtime-neutral: shared by the Node server plugin and the Cloudflare worker
|
|
10
|
+
* route data handler.
|
|
11
|
+
*/
|
|
12
|
+
export declare function expandLocalisedLoaderRoutes(routes: LoaderRoutes): LoaderRoutes;
|
|
13
|
+
/** Resolve a canonical loader route ID to the localized alias matched by the URL. */
|
|
14
|
+
export declare const resolveLocalisedLoaderRoute: LoaderRouteIdResolver;
|
|
15
|
+
export {};
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.9.0-ultramodern.
|
|
20
|
+
"version": "3.9.0-ultramodern.14",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -85,6 +85,24 @@
|
|
|
85
85
|
"default": "./dist/esm/runtimeLifecycle.mjs",
|
|
86
86
|
"types": "./dist/types-esm/runtimeLifecycle.d.mts"
|
|
87
87
|
},
|
|
88
|
+
"./localised-loader": {
|
|
89
|
+
"node": {
|
|
90
|
+
"import": {
|
|
91
|
+
"types": "./dist/types-esm/localisedLoader.d.mts",
|
|
92
|
+
"default": "./dist/esm-node/localisedLoader.mjs"
|
|
93
|
+
},
|
|
94
|
+
"require": {
|
|
95
|
+
"types": "./dist/types/localisedLoader.d.ts",
|
|
96
|
+
"default": "./dist/cjs/localisedLoader.js"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"import": {
|
|
100
|
+
"types": "./dist/types-esm/localisedLoader.d.mts",
|
|
101
|
+
"default": "./dist/esm/localisedLoader.mjs"
|
|
102
|
+
},
|
|
103
|
+
"default": "./dist/esm/localisedLoader.mjs",
|
|
104
|
+
"types": "./dist/types-esm/localisedLoader.d.mts"
|
|
105
|
+
},
|
|
88
106
|
"./static-serving/node": {
|
|
89
107
|
"node": {
|
|
90
108
|
"import": {
|
|
@@ -171,6 +189,10 @@
|
|
|
171
189
|
"./dist/types/runtimeLifecycle.d.ts",
|
|
172
190
|
"./src/runtimeLifecycle.ts"
|
|
173
191
|
],
|
|
192
|
+
"localised-loader": [
|
|
193
|
+
"./dist/types/localisedLoader.d.ts",
|
|
194
|
+
"./src/localisedLoader.ts"
|
|
195
|
+
],
|
|
174
196
|
"static-serving/node": [
|
|
175
197
|
"./dist/types/static-serving/plugin.d.ts",
|
|
176
198
|
"./src/static-serving/plugin.ts"
|
|
@@ -197,25 +219,25 @@
|
|
|
197
219
|
"node": ">=26.7.0"
|
|
198
220
|
},
|
|
199
221
|
"dependencies": {
|
|
200
|
-
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.9.0-ultramodern.
|
|
201
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.
|
|
202
|
-
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.9.0-ultramodern.
|
|
203
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.
|
|
204
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.0-ultramodern.
|
|
205
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.0-ultramodern.
|
|
206
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.
|
|
222
|
+
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.9.0-ultramodern.14",
|
|
223
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.14",
|
|
224
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.9.0-ultramodern.14",
|
|
225
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.14",
|
|
226
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.0-ultramodern.14",
|
|
227
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.0-ultramodern.14",
|
|
228
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.14",
|
|
207
229
|
"@swc/helpers": "^0.5.23",
|
|
208
230
|
"reflect-metadata": "^0.2.2"
|
|
209
231
|
},
|
|
210
232
|
"devDependencies": {
|
|
211
|
-
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.9.0-ultramodern.
|
|
212
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.
|
|
213
|
-
"@rslib/core": "1.0.
|
|
233
|
+
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.9.0-ultramodern.14",
|
|
234
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.14",
|
|
235
|
+
"@rslib/core": "1.0.2",
|
|
214
236
|
"@scripts/rstest-config": "2.66.0",
|
|
215
|
-
"@types/node": "^26.
|
|
237
|
+
"@types/node": "^26.6.2",
|
|
216
238
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
217
239
|
"esbuild": "^0.28.2",
|
|
218
|
-
"zod": "^4.5
|
|
240
|
+
"zod": "^4.6.5"
|
|
219
241
|
},
|
|
220
242
|
"sideEffects": false,
|
|
221
243
|
"publishConfig": {
|
|
@@ -26,26 +26,36 @@ export function createBackendFederationEntryIntegrity(
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export const evaluateNodeBackendFederationCommonJs
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'exports',
|
|
45
|
-
'globalThis',
|
|
46
|
-
'require',
|
|
47
|
-
source,
|
|
48
|
-
);
|
|
49
|
-
evaluate(module, exports, globalThis, requireBuiltin);
|
|
50
|
-
return module.exports;
|
|
29
|
+
export const evaluateNodeBackendFederationCommonJs = (
|
|
30
|
+
source: Parameters<BackendFederationCommonJsEvaluator>[0],
|
|
31
|
+
{ remote }: Parameters<BackendFederationCommonJsEvaluator>[1],
|
|
32
|
+
privateRuntimeCapability?: unknown,
|
|
33
|
+
) => {
|
|
34
|
+
const module = { exports: {} as Record<string, unknown> };
|
|
35
|
+
const exports = module.exports;
|
|
36
|
+
const requireBuiltin = (specifier: string) => {
|
|
37
|
+
if (!nodeBuiltins.has(specifier)) {
|
|
38
|
+
throw new BackendFederationRemoteEntryError(
|
|
39
|
+
'unsupported_entry',
|
|
40
|
+
`[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return nodeRequire(specifier);
|
|
51
44
|
};
|
|
45
|
+
const evaluate = new Function(
|
|
46
|
+
'module',
|
|
47
|
+
'exports',
|
|
48
|
+
'globalThis',
|
|
49
|
+
'require',
|
|
50
|
+
'__modernjs_backend_private_capability__',
|
|
51
|
+
source,
|
|
52
|
+
);
|
|
53
|
+
evaluate(
|
|
54
|
+
module,
|
|
55
|
+
exports,
|
|
56
|
+
globalThis,
|
|
57
|
+
requireBuiltin,
|
|
58
|
+
privateRuntimeCapability,
|
|
59
|
+
);
|
|
60
|
+
return module.exports;
|
|
61
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { LoaderRouteIdResolver } from '@modern-js/plugin-data-loader/runtime';
|
|
2
|
+
import { resolveLocalisedLoaderRouteId } from '@modern-js/runtime-extensions/localised-loader-identity';
|
|
3
|
+
import { applyLocalisedUrlsToRoutes } from '@modern-js/runtime-extensions/localised-urls';
|
|
4
|
+
import type { ServerLoaderBundle } from '@modern-js/server-core';
|
|
5
|
+
|
|
6
|
+
type LoaderRoutes = ServerLoaderBundle['routes'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Project canonical-only localized routes so loader matching sees every
|
|
10
|
+
* localized URL. Routes already emitted as physical localized aliases are
|
|
11
|
+
* returned unchanged.
|
|
12
|
+
*
|
|
13
|
+
* Runtime-neutral: shared by the Node server plugin and the Cloudflare worker
|
|
14
|
+
* route data handler.
|
|
15
|
+
*/
|
|
16
|
+
export function expandLocalisedLoaderRoutes(
|
|
17
|
+
routes: LoaderRoutes,
|
|
18
|
+
): LoaderRoutes {
|
|
19
|
+
const languages = new Set<string>();
|
|
20
|
+
const localisedUrls: Record<string, Record<string, string>> = {};
|
|
21
|
+
let physical = false;
|
|
22
|
+
const visit = (nodes: LoaderRoutes) => {
|
|
23
|
+
for (const route of nodes) {
|
|
24
|
+
physical ||= 'modernCanonicalPath' in route;
|
|
25
|
+
const identity = Reflect.get(route, 'modernLocalisedRoute') as
|
|
26
|
+
| { canonicalPath: string; paths?: Record<string, string> }
|
|
27
|
+
| undefined;
|
|
28
|
+
if (identity?.paths) {
|
|
29
|
+
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
30
|
+
for (const language of Object.keys(identity.paths))
|
|
31
|
+
languages.add(language);
|
|
32
|
+
}
|
|
33
|
+
if ('children' in route && route.children) visit(route.children);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
visit(routes);
|
|
37
|
+
return physical || languages.size === 0
|
|
38
|
+
? routes
|
|
39
|
+
: (applyLocalisedUrlsToRoutes(
|
|
40
|
+
routes,
|
|
41
|
+
[...languages],
|
|
42
|
+
localisedUrls,
|
|
43
|
+
) as LoaderRoutes);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Resolve a canonical loader route ID to the localized alias matched by the URL. */
|
|
47
|
+
export const resolveLocalisedLoaderRoute: LoaderRouteIdResolver = (
|
|
48
|
+
requestedRouteId,
|
|
49
|
+
{ routes, matchedRouteIds },
|
|
50
|
+
) => resolveLocalisedLoaderRouteId(routes, requestedRouteId, matchedRouteIds);
|
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
import { setLoaderRouteIdResolver } from '@modern-js/plugin-data-loader/runtime';
|
|
2
|
-
import { resolveLocalisedLoaderRouteId } from '@modern-js/runtime-extensions/localised-loader-identity';
|
|
3
|
-
import { applyLocalisedUrlsToRoutes } from '@modern-js/runtime-extensions/localised-urls';
|
|
4
2
|
import {
|
|
5
3
|
getLoaderCtx,
|
|
6
4
|
type MiddlewareHandler,
|
|
7
|
-
type ServerLoaderBundle,
|
|
8
5
|
type ServerPlugin,
|
|
9
6
|
} from '@modern-js/server-core';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let physical = false;
|
|
15
|
-
const visit = (nodes: ServerLoaderBundle['routes']) => {
|
|
16
|
-
for (const route of nodes) {
|
|
17
|
-
physical ||= 'modernCanonicalPath' in route;
|
|
18
|
-
const identity = Reflect.get(route, 'modernLocalisedRoute') as
|
|
19
|
-
| { canonicalPath: string; paths?: Record<string, string> }
|
|
20
|
-
| undefined;
|
|
21
|
-
if (identity?.paths) {
|
|
22
|
-
localisedUrls[identity.canonicalPath] = identity.paths;
|
|
23
|
-
for (const language of Object.keys(identity.paths))
|
|
24
|
-
languages.add(language);
|
|
25
|
-
}
|
|
26
|
-
if ('children' in route && route.children) visit(route.children);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
visit(routes);
|
|
30
|
-
return physical || languages.size === 0
|
|
31
|
-
? routes
|
|
32
|
-
: (applyLocalisedUrlsToRoutes(
|
|
33
|
-
routes,
|
|
34
|
-
[...languages],
|
|
35
|
-
localisedUrls,
|
|
36
|
-
) as typeof routes);
|
|
37
|
-
}
|
|
7
|
+
import {
|
|
8
|
+
expandLocalisedLoaderRoutes,
|
|
9
|
+
resolveLocalisedLoaderRoute,
|
|
10
|
+
} from './localisedLoader';
|
|
38
11
|
|
|
39
12
|
export function injectLocalisedLoaderPlugin(): ServerPlugin {
|
|
40
13
|
return {
|
|
@@ -43,13 +16,8 @@ export function injectLocalisedLoaderPlugin(): ServerPlugin {
|
|
|
43
16
|
const handler: MiddlewareHandler = async (context, next) => {
|
|
44
17
|
setLoaderRouteIdResolver(
|
|
45
18
|
getLoaderCtx(context),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
routes,
|
|
49
|
-
requestedRouteId,
|
|
50
|
-
matchedRouteIds,
|
|
51
|
-
),
|
|
52
|
-
expandCanonicalRoutes,
|
|
19
|
+
resolveLocalisedLoaderRoute,
|
|
20
|
+
expandLocalisedLoaderRoutes,
|
|
53
21
|
);
|
|
54
22
|
await next();
|
|
55
23
|
};
|
|
@@ -402,10 +402,18 @@ describe('verified backend federation entry loading', () => {
|
|
|
402
402
|
) as { get(id: string): () => string };
|
|
403
403
|
|
|
404
404
|
expect(builtinEntry.get('./effect-api')()).toBe('value');
|
|
405
|
+
const privateCapability = { register: () => undefined };
|
|
406
|
+
const capabilityEntry = evaluateNodeBackendFederationCommonJs(
|
|
407
|
+
'module.exports = { get: () => () => __modernjs_backend_private_capability__ };',
|
|
408
|
+
{ remote: { entry: entryUrl, name: remoteName } },
|
|
409
|
+
privateCapability,
|
|
410
|
+
) as { get(id: string): () => unknown };
|
|
411
|
+
expect(capabilityEntry.get('./effect-api')()).toBe(privateCapability);
|
|
405
412
|
expect(() =>
|
|
406
413
|
evaluateNodeBackendFederationCommonJs(
|
|
407
414
|
"require('@attacker/package'); module.exports = { get() {} };",
|
|
408
415
|
{ remote: { entry: entryUrl, name: remoteName } },
|
|
416
|
+
privateCapability,
|
|
409
417
|
),
|
|
410
418
|
).toThrow(
|
|
411
419
|
expect.objectContaining<Partial<BackendFederationRemoteEntryError>>({
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Operation contracts load the optional zod peer at runtime. Upstream zod
|
|
5
|
+
// decides lazily whether to probe `new Function("")` for its object JIT and
|
|
6
|
+
// skips the probe under `z.config({ jitless: true })` and on Cloudflare
|
|
7
|
+
// Workers, so CSP/Worker bundles need no evaluator patch.
|
|
8
|
+
const countFunctionConstructions = (setup: string) =>
|
|
9
|
+
Number(
|
|
10
|
+
execFileSync(
|
|
11
|
+
process.execPath,
|
|
12
|
+
[
|
|
13
|
+
'--input-type=module',
|
|
14
|
+
'-e',
|
|
15
|
+
`
|
|
16
|
+
let constructions = 0;
|
|
17
|
+
globalThis.Function = new Proxy(Function, {
|
|
18
|
+
construct(target, args, newTarget) {
|
|
19
|
+
constructions += 1;
|
|
20
|
+
return Reflect.construct(target, args, newTarget);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const { z } = await import('zod');
|
|
24
|
+
${setup}
|
|
25
|
+
z.object({ id: z.string(), count: z.number() }).parse({ id: 'a', count: 1 });
|
|
26
|
+
process.stdout.write(String(constructions));
|
|
27
|
+
`,
|
|
28
|
+
],
|
|
29
|
+
{ cwd: path.resolve(__dirname, '../..'), encoding: 'utf8' },
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
describe('upstream zod evaluator probe', () => {
|
|
34
|
+
test('constructs Function by default, proving the probe is observable', () => {
|
|
35
|
+
expect(countFunctionConstructions('')).toBeGreaterThan(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('never constructs Function on Cloudflare Workers', () => {
|
|
39
|
+
expect(
|
|
40
|
+
countFunctionConstructions(
|
|
41
|
+
`Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { userAgent: 'Cloudflare-Workers' } });`,
|
|
42
|
+
),
|
|
43
|
+
).toBe(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('never constructs Function under jitless configuration', () => {
|
|
47
|
+
expect(countFunctionConstructions('z.config({ jitless: true });')).toBe(0);
|
|
48
|
+
});
|
|
49
|
+
});
|