@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.31 → 3.5.0-ultramodern.32
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/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.5.0-ultramodern.
|
|
20
|
+
"version": "3.5.0-ultramodern.32",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -97,15 +97,15 @@
|
|
|
97
97
|
"i18next-fs-backend": "^2.6.6",
|
|
98
98
|
"i18next-http-backend": "^4.0.0",
|
|
99
99
|
"i18next-http-middleware": "^3.9.7",
|
|
100
|
-
"@modern-js/
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.
|
|
103
|
-
"@modern-js/
|
|
104
|
-
"@modern-js/
|
|
105
|
-
"@modern-js/
|
|
100
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.32",
|
|
101
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.32",
|
|
102
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.32",
|
|
103
|
+
"@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.32",
|
|
104
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.32",
|
|
105
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.32"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@modern-js/runtime": "3.5.0-ultramodern.
|
|
108
|
+
"@modern-js/runtime": "3.5.0-ultramodern.32",
|
|
109
109
|
"i18next": ">=26.3.1",
|
|
110
110
|
"react": "^19.2.7",
|
|
111
111
|
"react-dom": "^19.2.7",
|
|
@@ -129,8 +129,8 @@
|
|
|
129
129
|
"react-i18next": "17.0.8",
|
|
130
130
|
"ts-node": "^10.9.2",
|
|
131
131
|
"typescript": "^6.0.3",
|
|
132
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.
|
|
133
|
-
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.
|
|
132
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.32",
|
|
133
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.32"
|
|
134
134
|
},
|
|
135
135
|
"sideEffects": false,
|
|
136
136
|
"publishConfig": {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": ":lang",
|
|
4
|
+
"path": ":lang",
|
|
5
|
+
"type": "nested",
|
|
6
|
+
"origin": "file-system",
|
|
7
|
+
"routeType": "layout",
|
|
8
|
+
"_component": ":lang.tsx",
|
|
9
|
+
"children": [
|
|
10
|
+
{
|
|
11
|
+
"id": "about",
|
|
12
|
+
"path": "about",
|
|
13
|
+
"type": "nested",
|
|
14
|
+
"origin": "file-system",
|
|
15
|
+
"routeType": "page",
|
|
16
|
+
"_component": "about.tsx",
|
|
17
|
+
"modernCanonicalPath": "/about"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "about__localised_o-nas",
|
|
21
|
+
"path": "o-nas",
|
|
22
|
+
"type": "nested",
|
|
23
|
+
"origin": "file-system",
|
|
24
|
+
"routeType": "page",
|
|
25
|
+
"_component": "about.tsx",
|
|
26
|
+
"modernCanonicalPath": "/about"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "about__localised_ueber-uns",
|
|
30
|
+
"path": "ueber-uns",
|
|
31
|
+
"type": "nested",
|
|
32
|
+
"origin": "file-system",
|
|
33
|
+
"routeType": "page",
|
|
34
|
+
"_component": "about.tsx",
|
|
35
|
+
"modernCanonicalPath": "/about"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "products",
|
|
39
|
+
"path": "products",
|
|
40
|
+
"type": "nested",
|
|
41
|
+
"origin": "file-system",
|
|
42
|
+
"routeType": "layout",
|
|
43
|
+
"_component": "products.tsx",
|
|
44
|
+
"children": [
|
|
45
|
+
{
|
|
46
|
+
"id": ":slug",
|
|
47
|
+
"path": ":slug",
|
|
48
|
+
"type": "nested",
|
|
49
|
+
"origin": "file-system",
|
|
50
|
+
"routeType": "page",
|
|
51
|
+
"_component": ":slug.tsx",
|
|
52
|
+
"modernCanonicalPath": "/products/:slug"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"modernCanonicalPath": "/products"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "products__localised_produkty",
|
|
59
|
+
"path": "produkty",
|
|
60
|
+
"type": "nested",
|
|
61
|
+
"origin": "file-system",
|
|
62
|
+
"routeType": "layout",
|
|
63
|
+
"_component": "products.tsx",
|
|
64
|
+
"children": [
|
|
65
|
+
{
|
|
66
|
+
"id": ":slug__localised_produkty",
|
|
67
|
+
"path": ":slug",
|
|
68
|
+
"type": "nested",
|
|
69
|
+
"origin": "file-system",
|
|
70
|
+
"routeType": "page",
|
|
71
|
+
"_component": ":slug.tsx",
|
|
72
|
+
"modernCanonicalPath": "/products/:slug"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"modernCanonicalPath": "/products"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "products__localised_produkte",
|
|
79
|
+
"path": "produkte",
|
|
80
|
+
"type": "nested",
|
|
81
|
+
"origin": "file-system",
|
|
82
|
+
"routeType": "layout",
|
|
83
|
+
"_component": "products.tsx",
|
|
84
|
+
"children": [
|
|
85
|
+
{
|
|
86
|
+
"id": ":slug__localised_produkte",
|
|
87
|
+
"path": ":slug",
|
|
88
|
+
"type": "nested",
|
|
89
|
+
"origin": "file-system",
|
|
90
|
+
"routeType": "page",
|
|
91
|
+
"_component": ":slug.tsx",
|
|
92
|
+
"modernCanonicalPath": "/products/:slug"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"modernCanonicalPath": "/products"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "docs",
|
|
99
|
+
"path": "docs",
|
|
100
|
+
"type": "nested",
|
|
101
|
+
"origin": "file-system",
|
|
102
|
+
"routeType": "layout",
|
|
103
|
+
"_component": "docs.tsx",
|
|
104
|
+
"children": [
|
|
105
|
+
{
|
|
106
|
+
"id": "*",
|
|
107
|
+
"path": "*",
|
|
108
|
+
"type": "nested",
|
|
109
|
+
"origin": "file-system",
|
|
110
|
+
"routeType": "page",
|
|
111
|
+
"_component": "*.tsx"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"modernCanonicalPath": "/docs"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"id": "docs__localised_dokumenty",
|
|
118
|
+
"path": "dokumenty",
|
|
119
|
+
"type": "nested",
|
|
120
|
+
"origin": "file-system",
|
|
121
|
+
"routeType": "layout",
|
|
122
|
+
"_component": "docs.tsx",
|
|
123
|
+
"children": [
|
|
124
|
+
{
|
|
125
|
+
"id": "*__localised_dokumenty",
|
|
126
|
+
"path": "*",
|
|
127
|
+
"type": "nested",
|
|
128
|
+
"origin": "file-system",
|
|
129
|
+
"routeType": "page",
|
|
130
|
+
"_component": "*.tsx"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"modernCanonicalPath": "/docs"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "docs__localised_dokumente",
|
|
137
|
+
"path": "dokumente",
|
|
138
|
+
"type": "nested",
|
|
139
|
+
"origin": "file-system",
|
|
140
|
+
"routeType": "layout",
|
|
141
|
+
"_component": "docs.tsx",
|
|
142
|
+
"children": [
|
|
143
|
+
{
|
|
144
|
+
"id": "*__localised_dokumente",
|
|
145
|
+
"path": "*",
|
|
146
|
+
"type": "nested",
|
|
147
|
+
"origin": "file-system",
|
|
148
|
+
"routeType": "page",
|
|
149
|
+
"_component": "*.tsx"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"modernCanonicalPath": "/docs"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import type { NestedRouteForCli } from '@modern-js/types';
|
|
2
4
|
import { describe, expect, test } from '@rstest/core';
|
|
3
5
|
import { i18nPlugin as i18nCliPlugin } from '../src/cli';
|
|
@@ -17,6 +19,12 @@ import {
|
|
|
17
19
|
validateLocalisedUrls,
|
|
18
20
|
} from '../src/shared/localisedUrls';
|
|
19
21
|
|
|
22
|
+
const localisedRoutesGoldenPath = path.join(
|
|
23
|
+
__dirname,
|
|
24
|
+
'fixtures',
|
|
25
|
+
'localised-routes.golden.json',
|
|
26
|
+
);
|
|
27
|
+
|
|
20
28
|
const createRoute = (
|
|
21
29
|
path: string,
|
|
22
30
|
children?: NestedRouteForCli[],
|
|
@@ -37,6 +45,9 @@ const createRequestContext = (pathname: string) =>
|
|
|
37
45
|
},
|
|
38
46
|
}) as any;
|
|
39
47
|
|
|
48
|
+
const serializeRoutesForGolden = (routes: unknown): string =>
|
|
49
|
+
`${JSON.stringify(routes, null, 2)}\n`;
|
|
50
|
+
|
|
40
51
|
describe('resolveLocalisedUrlsConfig', () => {
|
|
41
52
|
test('is opt-in: only a non-empty map enables the feature', () => {
|
|
42
53
|
const map = { '/about': { en: '/about', cs: '/o-nas' } };
|
|
@@ -108,6 +119,70 @@ describe('cli modifyFileSystemRoutes', () => {
|
|
|
108
119
|
return modifyRoutes!;
|
|
109
120
|
};
|
|
110
121
|
|
|
122
|
+
const generateLocalisedRoutesGolden = (): string => {
|
|
123
|
+
const modifyRoutes = setupModifyRoutes({
|
|
124
|
+
localePathRedirect: true,
|
|
125
|
+
languages: ['en', 'cs', 'de'],
|
|
126
|
+
localisedUrls: {
|
|
127
|
+
'/about': {
|
|
128
|
+
en: '/about',
|
|
129
|
+
cs: '/o-nas',
|
|
130
|
+
de: '/ueber-uns',
|
|
131
|
+
},
|
|
132
|
+
'/products': {
|
|
133
|
+
en: '/products',
|
|
134
|
+
cs: '/produkty',
|
|
135
|
+
de: '/produkte',
|
|
136
|
+
},
|
|
137
|
+
'/products/:slug': {
|
|
138
|
+
en: '/products/:slug',
|
|
139
|
+
cs: '/produkty/:slug',
|
|
140
|
+
de: '/produkte/:slug',
|
|
141
|
+
},
|
|
142
|
+
'/docs': {
|
|
143
|
+
en: '/docs',
|
|
144
|
+
cs: '/dokumenty',
|
|
145
|
+
de: '/dokumente',
|
|
146
|
+
},
|
|
147
|
+
'/docs/*': {
|
|
148
|
+
en: '/docs/*',
|
|
149
|
+
cs: '/dokumenty/*',
|
|
150
|
+
de: '/dokumente/*',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const routes = [
|
|
155
|
+
createRoute(':lang', [
|
|
156
|
+
createRoute('about'),
|
|
157
|
+
createRoute('products', [createRoute(':slug')]),
|
|
158
|
+
createRoute('docs', [createRoute('*')]),
|
|
159
|
+
]),
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const result = modifyRoutes({
|
|
163
|
+
entrypoint: { entryName: 'main' },
|
|
164
|
+
routes,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return serializeRoutesForGolden(result.routes);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
test('matches checked-in localised routes golden output', async () => {
|
|
171
|
+
const localisedRoutes = generateLocalisedRoutesGolden();
|
|
172
|
+
const repeatedLocalisedRoutes = generateLocalisedRoutesGolden();
|
|
173
|
+
|
|
174
|
+
expect(repeatedLocalisedRoutes).toBe(localisedRoutes);
|
|
175
|
+
|
|
176
|
+
if (process.env.UPDATE_I18N_LOCALISED_ROUTES_GOLDEN === '1') {
|
|
177
|
+
await mkdir(path.dirname(localisedRoutesGoldenPath), { recursive: true });
|
|
178
|
+
await writeFile(localisedRoutesGoldenPath, localisedRoutes);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
await expect(readFile(localisedRoutesGoldenPath, 'utf8')).resolves.toBe(
|
|
182
|
+
localisedRoutes,
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
111
186
|
test('upstream-style configs without a map keep routes untouched', () => {
|
|
112
187
|
const modifyRoutes = setupModifyRoutes({
|
|
113
188
|
localePathRedirect: true,
|