@bleedingdev/modern-js-i18n-runtime-extensions 3.8.3-ultramodern.2
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/LICENSE +21 -0
- package/dist/cjs/index.js +76 -0
- package/dist/cjs/language-sync/controller.js +241 -0
- package/dist/cjs/language-sync/react.js +169 -0
- package/dist/cjs/localisedUrls/config.js +49 -0
- package/dist/cjs/localisedUrls/index.js +91 -0
- package/dist/cjs/localisedUrls/normalise.js +87 -0
- package/dist/cjs/localisedUrls/pathname.js +68 -0
- package/dist/cjs/localisedUrls/patterns.js +214 -0
- package/dist/cjs/localisedUrls/redirect.js +103 -0
- package/dist/cjs/localisedUrls/resolve.js +78 -0
- package/dist/cjs/localisedUrls/routes.js +202 -0
- package/dist/cjs/localisedUrls/types.js +18 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/language-sync/controller.mjs +203 -0
- package/dist/esm/language-sync/react.mjs +118 -0
- package/dist/esm/localisedUrls/config.mjs +11 -0
- package/dist/esm/localisedUrls/index.mjs +7 -0
- package/dist/esm/localisedUrls/normalise.mjs +37 -0
- package/dist/esm/localisedUrls/pathname.mjs +24 -0
- package/dist/esm/localisedUrls/patterns.mjs +152 -0
- package/dist/esm/localisedUrls/redirect.mjs +56 -0
- package/dist/esm/localisedUrls/resolve.mjs +37 -0
- package/dist/esm/localisedUrls/routes.mjs +161 -0
- package/dist/esm/localisedUrls/types.mjs +0 -0
- package/dist/esm-node/index.mjs +4 -0
- package/dist/esm-node/language-sync/controller.mjs +204 -0
- package/dist/esm-node/language-sync/react.mjs +119 -0
- package/dist/esm-node/localisedUrls/config.mjs +12 -0
- package/dist/esm-node/localisedUrls/index.mjs +8 -0
- package/dist/esm-node/localisedUrls/normalise.mjs +38 -0
- package/dist/esm-node/localisedUrls/pathname.mjs +25 -0
- package/dist/esm-node/localisedUrls/patterns.mjs +153 -0
- package/dist/esm-node/localisedUrls/redirect.mjs +57 -0
- package/dist/esm-node/localisedUrls/resolve.mjs +38 -0
- package/dist/esm-node/localisedUrls/routes.mjs +162 -0
- package/dist/esm-node/localisedUrls/types.mjs +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/language-sync/controller.d.ts +26 -0
- package/dist/types/language-sync/react.d.ts +38 -0
- package/dist/types/localisedUrls/config.d.ts +9 -0
- package/dist/types/localisedUrls/index.d.ts +9 -0
- package/dist/types/localisedUrls/normalise.d.ts +10 -0
- package/dist/types/localisedUrls/pathname.d.ts +4 -0
- package/dist/types/localisedUrls/patterns.d.ts +11 -0
- package/dist/types/localisedUrls/redirect.d.ts +11 -0
- package/dist/types/localisedUrls/resolve.d.ts +7 -0
- package/dist/types/localisedUrls/routes.d.ts +3 -0
- package/dist/types/localisedUrls/types.d.ts +14 -0
- package/package.json +71 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +36 -0
- package/src/index.ts +3 -0
- package/src/language-sync/controller.ts +386 -0
- package/src/language-sync/react.ts +227 -0
- package/src/localisedUrls/config.ts +18 -0
- package/src/localisedUrls/index.ts +24 -0
- package/src/localisedUrls/normalise.ts +62 -0
- package/src/localisedUrls/pathname.ts +60 -0
- package/src/localisedUrls/patterns.ts +283 -0
- package/src/localisedUrls/redirect.ts +93 -0
- package/src/localisedUrls/resolve.ts +106 -0
- package/src/localisedUrls/routes.ts +422 -0
- package/src/localisedUrls/types.ts +18 -0
- package/tests/clientRedirectIntegration.test.tsx +74 -0
- package/tests/languageSyncController.test.ts +213 -0
- package/tests/localisedUrls.test.ts +673 -0
- package/tests/reactLanguageSync.test.tsx +117 -0
- package/tests/tsconfig.json +11 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
const LOCALE_PARAM_NAMES = new Set([
|
|
31
|
+
'lang',
|
|
32
|
+
'locale',
|
|
33
|
+
'language'
|
|
34
|
+
]);
|
|
35
|
+
const normaliseSlashes = (path)=>{
|
|
36
|
+
const withoutDuplicateSlashes = path.replace(/\/+/g, '/');
|
|
37
|
+
const withLeadingSlash = withoutDuplicateSlashes.startsWith('/') ? withoutDuplicateSlashes : `/${withoutDuplicateSlashes}`;
|
|
38
|
+
return withLeadingSlash.length > 1 ? withLeadingSlash.replace(/\/+$/, '') : withLeadingSlash;
|
|
39
|
+
};
|
|
40
|
+
const normalisePathPattern = (path)=>normaliseSlashes(path).replace(/\[(.+?)\]/g, ':$1');
|
|
41
|
+
const normalisePathname = (pathname)=>normaliseSlashes(pathname);
|
|
42
|
+
const normaliseRoutePath = (path)=>{
|
|
43
|
+
const normalized = normalisePathPattern(path);
|
|
44
|
+
return '/' === normalized ? '' : normalized.slice(1);
|
|
45
|
+
};
|
|
46
|
+
const getLocaleParamSegment = (segment)=>{
|
|
47
|
+
if (!segment.startsWith(':')) return null;
|
|
48
|
+
const paramName = segment.slice(1).replace(/\?$/, '');
|
|
49
|
+
return LOCALE_PARAM_NAMES.has(paramName) ? segment : null;
|
|
50
|
+
};
|
|
51
|
+
const splitPathSegments = (path)=>{
|
|
52
|
+
if (!path) return [];
|
|
53
|
+
return normalisePathPattern(path).split('/').filter(Boolean);
|
|
54
|
+
};
|
|
55
|
+
const stripLeadingLocaleParam = (path)=>{
|
|
56
|
+
const segments = splitPathSegments(path);
|
|
57
|
+
const leadingLocaleParam = getLocaleParamSegment(segments[0] || '');
|
|
58
|
+
if (!leadingLocaleParam) return path;
|
|
59
|
+
const remainingPath = segments.slice(1).join('/');
|
|
60
|
+
return remainingPath ? `/${remainingPath}` : void 0;
|
|
61
|
+
};
|
|
62
|
+
const getLeadingLocaleParam = (path)=>{
|
|
63
|
+
const segments = splitPathSegments(path);
|
|
64
|
+
return getLocaleParamSegment(segments[0] || '');
|
|
65
|
+
};
|
|
66
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
67
|
+
getLeadingLocaleParam: getLeadingLocaleParam,
|
|
68
|
+
normalisePathPattern: normalisePathPattern,
|
|
69
|
+
normalisePathname: normalisePathname,
|
|
70
|
+
normaliseRoutePath: normaliseRoutePath,
|
|
71
|
+
stripLeadingLocaleParam: stripLeadingLocaleParam
|
|
72
|
+
});
|
|
73
|
+
exports.getLeadingLocaleParam = __webpack_exports__.getLeadingLocaleParam;
|
|
74
|
+
exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
|
|
75
|
+
exports.normalisePathname = __webpack_exports__.normalisePathname;
|
|
76
|
+
exports.normaliseRoutePath = __webpack_exports__.normaliseRoutePath;
|
|
77
|
+
exports.stripLeadingLocaleParam = __webpack_exports__.stripLeadingLocaleParam;
|
|
78
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
79
|
+
"getLeadingLocaleParam",
|
|
80
|
+
"normalisePathPattern",
|
|
81
|
+
"normalisePathname",
|
|
82
|
+
"normaliseRoutePath",
|
|
83
|
+
"stripLeadingLocaleParam"
|
|
84
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
|
+
Object.defineProperty(exports, '__esModule', {
|
|
86
|
+
value: true
|
|
87
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
canonicalTargetPathname: ()=>canonicalTargetPathname,
|
|
32
|
+
localiseTargetPathname: ()=>localiseTargetPathname,
|
|
33
|
+
stripLanguagePrefix: ()=>stripLanguagePrefix
|
|
34
|
+
});
|
|
35
|
+
const external_config_js_namespaceObject = require("./config.js");
|
|
36
|
+
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
37
|
+
const stripLanguagePrefix = (pathname, languages)=>{
|
|
38
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
39
|
+
const firstSegment = segments[0]?.toLowerCase();
|
|
40
|
+
if (firstSegment && languages.some((language)=>language.toLowerCase() === firstSegment)) return `/${segments.slice(1).join('/')}`;
|
|
41
|
+
return pathname || '/';
|
|
42
|
+
};
|
|
43
|
+
const localiseTargetPathname = (pathname, language, languages, localisedUrls)=>{
|
|
44
|
+
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
45
|
+
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
46
|
+
const resolvedPath = localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveLocalisedPath)(pathWithoutLanguage, language, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
47
|
+
const resolvedSegments = resolvedPath.split('/').filter(Boolean);
|
|
48
|
+
return `/${[
|
|
49
|
+
language,
|
|
50
|
+
...resolvedSegments
|
|
51
|
+
].join('/')}`;
|
|
52
|
+
};
|
|
53
|
+
const canonicalTargetPathname = (pathname, languages, localisedUrls)=>{
|
|
54
|
+
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
55
|
+
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
56
|
+
return localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath)(pathWithoutLanguage, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
57
|
+
};
|
|
58
|
+
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
59
|
+
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
60
|
+
exports.stripLanguagePrefix = __webpack_exports__.stripLanguagePrefix;
|
|
61
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
62
|
+
"canonicalTargetPathname",
|
|
63
|
+
"localiseTargetPathname",
|
|
64
|
+
"stripLanguagePrefix"
|
|
65
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
66
|
+
Object.defineProperty(exports, '__esModule', {
|
|
67
|
+
value: true
|
|
68
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
buildPathFromPattern: ()=>buildPathFromPattern,
|
|
32
|
+
doPathPatternsOverlap: ()=>doPathPatternsOverlap,
|
|
33
|
+
getOrderedPathParamSignature: ()=>getOrderedPathParamSignature,
|
|
34
|
+
getPathParamSignature: ()=>getPathParamSignature,
|
|
35
|
+
getPathPatternValidationIssue: ()=>getPathPatternValidationIssue,
|
|
36
|
+
getPhysicalPathPattern: ()=>getPhysicalPathPattern,
|
|
37
|
+
haveEqualPatternSpecificity: ()=>haveEqualPatternSpecificity,
|
|
38
|
+
matchPathPattern: ()=>matchPathPattern,
|
|
39
|
+
sortPatternsBySpecificity: ()=>sortPatternsBySpecificity
|
|
40
|
+
});
|
|
41
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
42
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
43
|
+
const getParamName = (segment)=>segment.slice(1).replace(/\?$/, '');
|
|
44
|
+
const getOrderedPathParamSignature = (pattern)=>(0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean).flatMap((segment)=>{
|
|
45
|
+
if ('*' === segment) return [
|
|
46
|
+
'*'
|
|
47
|
+
];
|
|
48
|
+
if (!segment.startsWith(':')) return [];
|
|
49
|
+
return [
|
|
50
|
+
`:${getParamName(segment)}${segment.endsWith('?') ? '?' : ''}`
|
|
51
|
+
];
|
|
52
|
+
});
|
|
53
|
+
const getPathParamSignature = (pattern)=>getOrderedPathParamSignature(pattern).sort((left, right)=>left < right ? -1 : left > right ? 1 : 0);
|
|
54
|
+
const getPathPatternValidationIssue = (pattern)=>{
|
|
55
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
56
|
+
const seenParams = new Set();
|
|
57
|
+
for (const [index, segment] of segments.entries()){
|
|
58
|
+
if ('*' === segment) {
|
|
59
|
+
if (index !== segments.length - 1) return 'splat parameter "*" must be the final segment';
|
|
60
|
+
if (seenParams.has('*')) return 'duplicate splat parameter "*"';
|
|
61
|
+
seenParams.add('*');
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!segment.startsWith(':')) continue;
|
|
65
|
+
const paramName = getParamName(segment);
|
|
66
|
+
if (seenParams.has(paramName)) return `duplicate path parameter ":${paramName}"`;
|
|
67
|
+
seenParams.add(paramName);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const getPhysicalPathPattern = (pattern)=>{
|
|
71
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
72
|
+
const physicalSegments = segments.map((segment)=>{
|
|
73
|
+
if ('*' === segment) return '*';
|
|
74
|
+
if (segment.startsWith(':')) return segment.endsWith('?') ? ':param?' : ':param';
|
|
75
|
+
return segment;
|
|
76
|
+
});
|
|
77
|
+
return `/${physicalSegments.join('/')}`;
|
|
78
|
+
};
|
|
79
|
+
const compiledPathPatternCache = new Map();
|
|
80
|
+
const compilePathPattern = (pattern)=>{
|
|
81
|
+
const normalizedPattern = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern);
|
|
82
|
+
const cached = compiledPathPatternCache.get(normalizedPattern);
|
|
83
|
+
if (cached) return cached;
|
|
84
|
+
const names = [];
|
|
85
|
+
const segments = normalizedPattern.split('/').filter(Boolean);
|
|
86
|
+
const source = segments.map((segment)=>{
|
|
87
|
+
if (segment.startsWith(':')) {
|
|
88
|
+
names.push(getParamName(segment));
|
|
89
|
+
const paramPattern = '([^/]+)';
|
|
90
|
+
return segment.endsWith('?') ? `(?:/${paramPattern})?` : `/${paramPattern}`;
|
|
91
|
+
}
|
|
92
|
+
if ('*' === segment) {
|
|
93
|
+
names.push('*');
|
|
94
|
+
return '(?:/(.*))?';
|
|
95
|
+
}
|
|
96
|
+
return `/${escapeRegExp(segment)}`;
|
|
97
|
+
}).join('');
|
|
98
|
+
const compiled = {
|
|
99
|
+
names,
|
|
100
|
+
regexp: new RegExp(`^${source || '/'}$`)
|
|
101
|
+
};
|
|
102
|
+
compiledPathPatternCache.set(normalizedPattern, compiled);
|
|
103
|
+
return compiled;
|
|
104
|
+
};
|
|
105
|
+
const getPatternSpecificity = (pattern)=>{
|
|
106
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
107
|
+
let staticSegments = 0;
|
|
108
|
+
let dynamicSegments = 0;
|
|
109
|
+
let optionalSegments = 0;
|
|
110
|
+
let splatSegments = 0;
|
|
111
|
+
for (const segment of segments)if ('*' === segment) splatSegments++;
|
|
112
|
+
else if (segment.startsWith(':')) {
|
|
113
|
+
dynamicSegments++;
|
|
114
|
+
if (segment.endsWith('?')) optionalSegments++;
|
|
115
|
+
} else staticSegments++;
|
|
116
|
+
return {
|
|
117
|
+
staticSegments,
|
|
118
|
+
dynamicSegments,
|
|
119
|
+
optionalSegments,
|
|
120
|
+
splatSegments,
|
|
121
|
+
totalSegments: segments.length
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
const comparePatternSpecificity = (left, right)=>{
|
|
125
|
+
const a = getPatternSpecificity(left);
|
|
126
|
+
const b = getPatternSpecificity(right);
|
|
127
|
+
return b.staticSegments - a.staticSegments || a.splatSegments - b.splatSegments || a.optionalSegments - b.optionalSegments || b.totalSegments - a.totalSegments || a.dynamicSegments - b.dynamicSegments;
|
|
128
|
+
};
|
|
129
|
+
const haveEqualPatternSpecificity = (left, right)=>0 === comparePatternSpecificity(left, right);
|
|
130
|
+
const doPathPatternsOverlap = (left, right)=>{
|
|
131
|
+
const leftSegments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(left).split('/').filter(Boolean);
|
|
132
|
+
const rightSegments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(right).split('/').filter(Boolean);
|
|
133
|
+
if (leftSegments.length !== rightSegments.length) return false;
|
|
134
|
+
return leftSegments.every((leftSegment, index)=>{
|
|
135
|
+
const rightSegment = rightSegments[index];
|
|
136
|
+
const leftIsDynamic = '*' === leftSegment || leftSegment.startsWith(':');
|
|
137
|
+
const rightIsDynamic = '*' === rightSegment || rightSegment.startsWith(':');
|
|
138
|
+
return leftIsDynamic || rightIsDynamic || leftSegment === rightSegment;
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const comparePatternNames = (left, right)=>{
|
|
142
|
+
const normalizedLeft = (0, external_normalise_js_namespaceObject.normalisePathPattern)(left);
|
|
143
|
+
const normalizedRight = (0, external_normalise_js_namespaceObject.normalisePathPattern)(right);
|
|
144
|
+
return normalizedLeft < normalizedRight ? -1 : normalizedLeft > normalizedRight ? 1 : 0;
|
|
145
|
+
};
|
|
146
|
+
const sortPatternsBySpecificity = (patterns)=>patterns.map((pattern, index)=>({
|
|
147
|
+
pattern,
|
|
148
|
+
index
|
|
149
|
+
})).sort((left, right)=>comparePatternSpecificity(left.pattern.pattern, right.pattern.pattern) || comparePatternNames(left.pattern.pattern, right.pattern.pattern) || left.index - right.index).map(({ pattern })=>pattern);
|
|
150
|
+
const decodePathParam = (value)=>{
|
|
151
|
+
try {
|
|
152
|
+
return decodeURIComponent(value);
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const encodeSplatParam = (value)=>value.split('/').map(encodeURIComponent).join('/');
|
|
158
|
+
const matchPathPattern = (pathname, pattern)=>{
|
|
159
|
+
const { names, regexp } = compilePathPattern(pattern);
|
|
160
|
+
const match = regexp.exec((0, external_normalise_js_namespaceObject.normalisePathname)(pathname));
|
|
161
|
+
if (!match) return null;
|
|
162
|
+
const params = {};
|
|
163
|
+
for(let index = 0; index < names.length; index++){
|
|
164
|
+
const decoded = decodePathParam(match[index + 1] || '');
|
|
165
|
+
if (null === decoded) return null;
|
|
166
|
+
Object.defineProperty(params, names[index], {
|
|
167
|
+
configurable: true,
|
|
168
|
+
enumerable: true,
|
|
169
|
+
value: decoded,
|
|
170
|
+
writable: true
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return params;
|
|
174
|
+
};
|
|
175
|
+
const buildPathFromPattern = (pattern, params)=>{
|
|
176
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
177
|
+
const path = segments.map((segment)=>{
|
|
178
|
+
if (segment.startsWith(':')) {
|
|
179
|
+
const paramName = getParamName(segment);
|
|
180
|
+
const param = Object.hasOwn(params, paramName) ? params[paramName] : void 0;
|
|
181
|
+
if (void 0 === param || '' === param) {
|
|
182
|
+
if (segment.endsWith('?')) return '';
|
|
183
|
+
throw new Error(`Missing required path parameter "${paramName}" for pattern "${(0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern)}".`);
|
|
184
|
+
}
|
|
185
|
+
return encodeURIComponent(param);
|
|
186
|
+
}
|
|
187
|
+
if ('*' === segment) return encodeSplatParam(params['*'] || '');
|
|
188
|
+
return segment;
|
|
189
|
+
}).filter(Boolean).join('/');
|
|
190
|
+
return `/${path}`;
|
|
191
|
+
};
|
|
192
|
+
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
193
|
+
exports.doPathPatternsOverlap = __webpack_exports__.doPathPatternsOverlap;
|
|
194
|
+
exports.getOrderedPathParamSignature = __webpack_exports__.getOrderedPathParamSignature;
|
|
195
|
+
exports.getPathParamSignature = __webpack_exports__.getPathParamSignature;
|
|
196
|
+
exports.getPathPatternValidationIssue = __webpack_exports__.getPathPatternValidationIssue;
|
|
197
|
+
exports.getPhysicalPathPattern = __webpack_exports__.getPhysicalPathPattern;
|
|
198
|
+
exports.haveEqualPatternSpecificity = __webpack_exports__.haveEqualPatternSpecificity;
|
|
199
|
+
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
200
|
+
exports.sortPatternsBySpecificity = __webpack_exports__.sortPatternsBySpecificity;
|
|
201
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
202
|
+
"buildPathFromPattern",
|
|
203
|
+
"doPathPatternsOverlap",
|
|
204
|
+
"getOrderedPathParamSignature",
|
|
205
|
+
"getPathParamSignature",
|
|
206
|
+
"getPathPatternValidationIssue",
|
|
207
|
+
"getPhysicalPathPattern",
|
|
208
|
+
"haveEqualPatternSpecificity",
|
|
209
|
+
"matchPathPattern",
|
|
210
|
+
"sortPatternsBySpecificity"
|
|
211
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
212
|
+
Object.defineProperty(exports, '__esModule', {
|
|
213
|
+
value: true
|
|
214
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
DEFAULT_LOCALE_REDIRECT_SKIP_RULES: ()=>DEFAULT_LOCALE_REDIRECT_SKIP_RULES,
|
|
32
|
+
isDefaultLocaleRedirectSkipPath: ()=>isDefaultLocaleRedirectSkipPath,
|
|
33
|
+
matchesPathPrefix: ()=>matchesPathPrefix,
|
|
34
|
+
shouldSkipLocaleRedirect: ()=>shouldSkipLocaleRedirect
|
|
35
|
+
});
|
|
36
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
37
|
+
const external_pathname_js_namespaceObject = require("./pathname.js");
|
|
38
|
+
const DEFAULT_LOCALE_REDIRECT_SKIP_RULES = [
|
|
39
|
+
{
|
|
40
|
+
type: 'exact',
|
|
41
|
+
path: '/backend-mf-manifest.json'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'exact',
|
|
45
|
+
path: '/backendRemoteEntry.cjs'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'exact',
|
|
49
|
+
path: '/mf-manifest.json'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'exact',
|
|
53
|
+
path: '/mf-stats.json'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'exact',
|
|
57
|
+
path: '/remoteEntry.js'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'prefix',
|
|
61
|
+
path: '/static/'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'prefix',
|
|
65
|
+
path: '/upload/'
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
const stripTrailingSlash = (pathname)=>pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname;
|
|
69
|
+
const matchesPathPrefix = (pathname, prefix)=>{
|
|
70
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
71
|
+
const normalizedPrefix = stripTrailingSlash((0, external_normalise_js_namespaceObject.normalisePathname)(prefix));
|
|
72
|
+
return normalizedPathname === normalizedPrefix || normalizedPathname.startsWith(`${normalizedPrefix}/`);
|
|
73
|
+
};
|
|
74
|
+
const matchesSkipRule = (pathname, rule)=>{
|
|
75
|
+
if ('exact' === rule.type) return (0, external_normalise_js_namespaceObject.normalisePathname)(pathname) === (0, external_normalise_js_namespaceObject.normalisePathname)(rule.path);
|
|
76
|
+
return matchesPathPrefix(pathname, rule.path);
|
|
77
|
+
};
|
|
78
|
+
const isDefaultLocaleRedirectSkipPath = (pathname, languages = [])=>{
|
|
79
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
80
|
+
const pathWithoutLanguage = (0, external_pathname_js_namespaceObject.stripLanguagePrefix)(normalizedPathname, languages);
|
|
81
|
+
return DEFAULT_LOCALE_REDIRECT_SKIP_RULES.some((rule)=>matchesSkipRule(pathWithoutLanguage, rule));
|
|
82
|
+
};
|
|
83
|
+
const shouldSkipLocaleRedirect = (pathname, languages = [], ignoreRedirectRoutes)=>{
|
|
84
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
85
|
+
const pathWithoutLanguage = (0, external_pathname_js_namespaceObject.stripLanguagePrefix)(normalizedPathname, languages);
|
|
86
|
+
if (isDefaultLocaleRedirectSkipPath(pathWithoutLanguage)) return true;
|
|
87
|
+
if (!ignoreRedirectRoutes) return false;
|
|
88
|
+
if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(pathWithoutLanguage);
|
|
89
|
+
return ignoreRedirectRoutes.some((pattern)=>matchesPathPrefix(pathWithoutLanguage, pattern));
|
|
90
|
+
};
|
|
91
|
+
exports.DEFAULT_LOCALE_REDIRECT_SKIP_RULES = __webpack_exports__.DEFAULT_LOCALE_REDIRECT_SKIP_RULES;
|
|
92
|
+
exports.isDefaultLocaleRedirectSkipPath = __webpack_exports__.isDefaultLocaleRedirectSkipPath;
|
|
93
|
+
exports.matchesPathPrefix = __webpack_exports__.matchesPathPrefix;
|
|
94
|
+
exports.shouldSkipLocaleRedirect = __webpack_exports__.shouldSkipLocaleRedirect;
|
|
95
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
96
|
+
"DEFAULT_LOCALE_REDIRECT_SKIP_RULES",
|
|
97
|
+
"isDefaultLocaleRedirectSkipPath",
|
|
98
|
+
"matchesPathPrefix",
|
|
99
|
+
"shouldSkipLocaleRedirect"
|
|
100
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
101
|
+
Object.defineProperty(exports, '__esModule', {
|
|
102
|
+
value: true
|
|
103
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
resolveCanonicalLocalisedPath: ()=>resolveCanonicalLocalisedPath,
|
|
32
|
+
resolveLocalisedPath: ()=>resolveLocalisedPath
|
|
33
|
+
});
|
|
34
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
35
|
+
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
36
|
+
const getCanonicalCandidates = (localisedUrls)=>(0, external_patterns_js_namespaceObject.sortPatternsBySpecificity)(Object.entries(localisedUrls).map(([canonicalPattern, localisedUrlEntry])=>({
|
|
37
|
+
pattern: canonicalPattern,
|
|
38
|
+
canonicalPattern,
|
|
39
|
+
localisedUrlEntry
|
|
40
|
+
})));
|
|
41
|
+
const resolveLocalisedUrlPath = (pathname, languages, localisedUrls, options)=>{
|
|
42
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
43
|
+
const canonicalCandidates = getCanonicalCandidates(localisedUrls);
|
|
44
|
+
const candidates = (0, external_patterns_js_namespaceObject.sortPatternsBySpecificity)(canonicalCandidates.flatMap(({ canonicalPattern, localisedUrlEntry })=>{
|
|
45
|
+
const targetPattern = 'localised' === options.mode ? localisedUrlEntry[options.targetLanguage] : canonicalPattern;
|
|
46
|
+
if (!targetPattern) return [];
|
|
47
|
+
const sourcePatterns = new Set([
|
|
48
|
+
canonicalPattern,
|
|
49
|
+
...languages.map((language)=>localisedUrlEntry[language]).filter((sourcePattern)=>Boolean(sourcePattern))
|
|
50
|
+
]);
|
|
51
|
+
return Array.from(sourcePatterns, (sourcePattern)=>({
|
|
52
|
+
pattern: sourcePattern,
|
|
53
|
+
sourcePattern,
|
|
54
|
+
targetPattern
|
|
55
|
+
}));
|
|
56
|
+
}));
|
|
57
|
+
for (const { sourcePattern, targetPattern } of candidates){
|
|
58
|
+
const params = (0, external_patterns_js_namespaceObject.matchPathPattern)(normalizedPathname, sourcePattern);
|
|
59
|
+
if (params) return (0, external_patterns_js_namespaceObject.buildPathFromPattern)(targetPattern, params);
|
|
60
|
+
}
|
|
61
|
+
return normalizedPathname;
|
|
62
|
+
};
|
|
63
|
+
const resolveLocalisedPath = (pathname, targetLanguage, languages, localisedUrls)=>resolveLocalisedUrlPath(pathname, languages, localisedUrls, {
|
|
64
|
+
mode: 'localised',
|
|
65
|
+
targetLanguage
|
|
66
|
+
});
|
|
67
|
+
const resolveCanonicalLocalisedPath = (pathname, languages, localisedUrls)=>resolveLocalisedUrlPath(pathname, languages, localisedUrls, {
|
|
68
|
+
mode: 'canonical'
|
|
69
|
+
});
|
|
70
|
+
exports.resolveCanonicalLocalisedPath = __webpack_exports__.resolveCanonicalLocalisedPath;
|
|
71
|
+
exports.resolveLocalisedPath = __webpack_exports__.resolveLocalisedPath;
|
|
72
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
73
|
+
"resolveCanonicalLocalisedPath",
|
|
74
|
+
"resolveLocalisedPath"
|
|
75
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
76
|
+
Object.defineProperty(exports, '__esModule', {
|
|
77
|
+
value: true
|
|
78
|
+
});
|