@koine/i18n 2.0.0-beta.76 → 2.0.0-beta.78

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.
Files changed (260) hide show
  1. package/README.md +1 -0
  2. package/api.cjs.js +2203 -0
  3. package/api.esm.js +2179 -0
  4. package/compiler-sync.cjs.d.ts +1 -0
  5. package/compiler-sync.cjs.default.js +1 -0
  6. package/compiler-sync.cjs.js +20 -0
  7. package/compiler-sync.cjs.mjs +2 -0
  8. package/compiler-sync.esm.js +16 -0
  9. package/compiler-worker.cjs.d.ts +1 -0
  10. package/compiler-worker.cjs.default.js +1 -0
  11. package/compiler-worker.cjs.js +18 -0
  12. package/compiler-worker.cjs.mjs +2 -0
  13. package/compiler-worker.esm.js +16 -0
  14. package/compiler.cjs.d.ts +1 -0
  15. package/compiler.cjs.default.js +1 -0
  16. package/compiler.cjs.js +21 -0
  17. package/compiler.cjs.mjs +2 -0
  18. package/compiler.esm.js +13 -0
  19. package/formatRoutePathname.cjs.js +12 -0
  20. package/formatRoutePathname.esm.js +10 -0
  21. package/index.cjs.d.ts +1 -0
  22. package/index.cjs.default.js +1 -0
  23. package/index.cjs.js +47 -0
  24. package/index.cjs.mjs +2 -0
  25. package/index.esm.js +42 -0
  26. package/next.cjs.d.ts +1 -0
  27. package/next.cjs.default.js +1 -0
  28. package/next.cjs.js +377 -0
  29. package/next.cjs.mjs +2 -0
  30. package/next.esm.js +353 -0
  31. package/package.json +22 -305
  32. package/actions/helpers-git.js +0 -45
  33. package/actions/helpers-i18n.js +0 -27
  34. package/actions/i18n.js +0 -17
  35. package/adapter-js/code/config.cjs.js +0 -14
  36. package/adapter-js/code/config.js +0 -14
  37. package/adapter-js/code/defaultLocale.js +0 -7
  38. package/adapter-js/code/deriveLocalisedPathnames.js +0 -78
  39. package/adapter-js/code/index.js +0 -123
  40. package/adapter-js/code/isLocale.js +0 -9
  41. package/adapter-js/code/locales.js +0 -8
  42. package/adapter-js/code/pathnameToRouteId.js +0 -20
  43. package/adapter-js/code/routes.js +0 -11
  44. package/adapter-js/code/routesSlim.js +0 -11
  45. package/adapter-js/code/routesSpa.js +0 -11
  46. package/adapter-js/code/tFns.js +0 -34
  47. package/adapter-js/code/tInterpolateParams.js +0 -18
  48. package/adapter-js/code/tPluralise.js +0 -10
  49. package/adapter-js/code/to.js +0 -32
  50. package/adapter-js/code/toFns.js +0 -25
  51. package/adapter-js/code/toFormat.js +0 -56
  52. package/adapter-js/code/toSpa.js +0 -42
  53. package/adapter-js/code/types.js +0 -327
  54. package/adapter-next/code/index.js +0 -54
  55. package/adapter-next/code/next-redirects.js +0 -5
  56. package/adapter-next/code/next-rewrites.js +0 -5
  57. package/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
  58. package/adapter-next/code/useLocale.js +0 -8
  59. package/adapter-next/code/useRouteId.js +0 -10
  60. package/adapter-next/code/useTo.js +0 -26
  61. package/adapter-next/code/useToSpa.js +0 -34
  62. package/adapter-next/plugin-async.js +0 -11
  63. package/adapter-next/plugin-legacy.js +0 -187
  64. package/adapter-next/plugin-shared.js +0 -39
  65. package/adapter-next/plugin.js +0 -13
  66. package/adapter-next/redirects.js +0 -51
  67. package/adapter-next/rewrites.js +0 -50
  68. package/adapter-next/transformPathname.js +0 -3
  69. package/adapter-next/webpackPluginI18n.js +0 -11
  70. package/adapter-next-translate/code/DynamicNamespaces.js +0 -9
  71. package/adapter-next-translate/code/T.js +0 -31
  72. package/adapter-next-translate/code/TransText.js +0 -9
  73. package/adapter-next-translate/code/getT.js +0 -15
  74. package/adapter-next-translate/code/index.js +0 -49
  75. package/adapter-next-translate/code/nextTranslateI18n.js +0 -19
  76. package/adapter-next-translate/code/useT.js +0 -43
  77. package/cjs/adapter-js/code/config.cjs.d.ts +0 -3
  78. package/cjs/adapter-js/code/config.d.ts +0 -3
  79. package/cjs/adapter-js/code/defaultLocale.d.ts +0 -3
  80. package/cjs/adapter-js/code/deriveLocalisedPathnames.d.ts +0 -2
  81. package/cjs/adapter-js/code/index.d.ts +0 -3
  82. package/cjs/adapter-js/code/isLocale.d.ts +0 -2
  83. package/cjs/adapter-js/code/locales.d.ts +0 -3
  84. package/cjs/adapter-js/code/pathnameToRouteId.d.ts +0 -3
  85. package/cjs/adapter-js/code/routes.d.ts +0 -3
  86. package/cjs/adapter-js/code/routesSlim.d.ts +0 -3
  87. package/cjs/adapter-js/code/routesSpa.d.ts +0 -3
  88. package/cjs/adapter-js/code/tFns.d.ts +0 -3
  89. package/cjs/adapter-js/code/tInterpolateParams.d.ts +0 -3
  90. package/cjs/adapter-js/code/tPluralise.d.ts +0 -2
  91. package/cjs/adapter-js/code/to.d.ts +0 -3
  92. package/cjs/adapter-js/code/toFns.d.ts +0 -3
  93. package/cjs/adapter-js/code/toFormat.d.ts +0 -3
  94. package/cjs/adapter-js/code/toSpa.d.ts +0 -3
  95. package/cjs/adapter-js/code/types.d.ts +0 -3
  96. package/cjs/adapter-next/code/index.d.ts +0 -3
  97. package/cjs/adapter-next/code/next-redirects.d.ts +0 -3
  98. package/cjs/adapter-next/code/next-rewrites.d.ts +0 -3
  99. package/cjs/adapter-next/code/useCurrentLocalisedPathnames.d.ts +0 -2
  100. package/cjs/adapter-next/code/useLocale.d.ts +0 -3
  101. package/cjs/adapter-next/code/useRouteId.d.ts +0 -2
  102. package/cjs/adapter-next/code/useTo.d.ts +0 -2
  103. package/cjs/adapter-next/code/useToSpa.d.ts +0 -2
  104. package/cjs/adapter-next/plugin-async.d.ts +0 -9
  105. package/cjs/adapter-next/plugin-legacy.d.ts +0 -22
  106. package/cjs/adapter-next/plugin-shared.d.ts +0 -13
  107. package/cjs/adapter-next/plugin.d.ts +0 -7
  108. package/cjs/adapter-next/redirects.d.ts +0 -4
  109. package/cjs/adapter-next/rewrites.d.ts +0 -4
  110. package/cjs/adapter-next/transformPathname.d.ts +0 -1
  111. package/cjs/adapter-next/webpackPluginI18n.d.ts +0 -7
  112. package/cjs/adapter-next-translate/code/DynamicNamespaces.d.ts +0 -2
  113. package/cjs/adapter-next-translate/code/T.d.ts +0 -2
  114. package/cjs/adapter-next-translate/code/TransText.d.ts +0 -2
  115. package/cjs/adapter-next-translate/code/getT.d.ts +0 -2
  116. package/cjs/adapter-next-translate/code/index.d.ts +0 -3
  117. package/cjs/adapter-next-translate/code/nextTranslateI18n.d.ts +0 -3
  118. package/cjs/adapter-next-translate/code/useT.d.ts +0 -2
  119. package/cjs/client/formatRoutePathname.d.ts +0 -4
  120. package/cjs/client/index.d.ts +0 -3
  121. package/cjs/client/interpolateTo.d.ts +0 -4
  122. package/cjs/client/routeHasDynamicPortion.d.ts +0 -2
  123. package/cjs/compiler/api.d.ts +0 -30
  124. package/cjs/compiler/code/data-routes.d.ts +0 -19
  125. package/cjs/compiler/code/data-translations.d.ts +0 -13
  126. package/cjs/compiler/code/data.d.ts +0 -33
  127. package/cjs/compiler/code/generate.d.ts +0 -14
  128. package/cjs/compiler/code/index.d.ts +0 -3
  129. package/cjs/compiler/code/tsCompile.d.ts +0 -2
  130. package/cjs/compiler/code/write.d.ts +0 -11
  131. package/cjs/compiler/config.d.ts +0 -12
  132. package/cjs/compiler/helpers.d.ts +0 -2
  133. package/cjs/compiler/input/data-local.d.ts +0 -4
  134. package/cjs/compiler/input/data-remote.d.ts +0 -7
  135. package/cjs/compiler/input/data.d.ts +0 -4
  136. package/cjs/compiler/input/index.d.ts +0 -4
  137. package/cjs/compiler/input/types.d.ts +0 -14
  138. package/cjs/compiler/input/write.d.ts +0 -8
  139. package/cjs/compiler/pluralisation.d.ts +0 -37
  140. package/cjs/compiler/summary/data.d.ts +0 -6
  141. package/cjs/compiler/summary/generate.d.ts +0 -4
  142. package/cjs/compiler/summary/index.d.ts +0 -3
  143. package/cjs/compiler/summary/write.d.ts +0 -10
  144. package/cjs/compiler/types.d.ts +0 -82
  145. package/cjs/compiler-sync.d.ts +0 -4
  146. package/cjs/compiler-worker.d.ts +0 -1
  147. package/cjs/compiler.d.ts +0 -2
  148. package/cjs/i18n/actions/helpers-git.js +0 -45
  149. package/cjs/i18n/actions/helpers-i18n.js +0 -27
  150. package/cjs/i18n/actions/i18n.js +0 -17
  151. package/cjs/i18n/adapter-js/code/config.cjs.js +0 -14
  152. package/cjs/i18n/adapter-js/code/config.js +0 -14
  153. package/cjs/i18n/adapter-js/code/defaultLocale.js +0 -7
  154. package/cjs/i18n/adapter-js/code/deriveLocalisedPathnames.js +0 -78
  155. package/cjs/i18n/adapter-js/code/index.js +0 -123
  156. package/cjs/i18n/adapter-js/code/isLocale.js +0 -9
  157. package/cjs/i18n/adapter-js/code/locales.js +0 -8
  158. package/cjs/i18n/adapter-js/code/pathnameToRouteId.js +0 -20
  159. package/cjs/i18n/adapter-js/code/routes.js +0 -11
  160. package/cjs/i18n/adapter-js/code/routesSlim.js +0 -11
  161. package/cjs/i18n/adapter-js/code/routesSpa.js +0 -11
  162. package/cjs/i18n/adapter-js/code/tFns.js +0 -34
  163. package/cjs/i18n/adapter-js/code/tInterpolateParams.js +0 -18
  164. package/cjs/i18n/adapter-js/code/tPluralise.js +0 -10
  165. package/cjs/i18n/adapter-js/code/to.js +0 -32
  166. package/cjs/i18n/adapter-js/code/toFns.js +0 -25
  167. package/cjs/i18n/adapter-js/code/toFormat.js +0 -56
  168. package/cjs/i18n/adapter-js/code/toSpa.js +0 -42
  169. package/cjs/i18n/adapter-js/code/types.js +0 -327
  170. package/cjs/i18n/adapter-next/code/index.js +0 -54
  171. package/cjs/i18n/adapter-next/code/next-redirects.js +0 -5
  172. package/cjs/i18n/adapter-next/code/next-rewrites.js +0 -5
  173. package/cjs/i18n/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
  174. package/cjs/i18n/adapter-next/code/useLocale.js +0 -8
  175. package/cjs/i18n/adapter-next/code/useRouteId.js +0 -10
  176. package/cjs/i18n/adapter-next/code/useTo.js +0 -26
  177. package/cjs/i18n/adapter-next/code/useToSpa.js +0 -34
  178. package/cjs/i18n/adapter-next/plugin-async.js +0 -11
  179. package/cjs/i18n/adapter-next/plugin-legacy.js +0 -187
  180. package/cjs/i18n/adapter-next/plugin-shared.js +0 -39
  181. package/cjs/i18n/adapter-next/plugin.js +0 -13
  182. package/cjs/i18n/adapter-next/redirects.js +0 -51
  183. package/cjs/i18n/adapter-next/rewrites.js +0 -50
  184. package/cjs/i18n/adapter-next/transformPathname.js +0 -3
  185. package/cjs/i18n/adapter-next/webpackPluginI18n.js +0 -11
  186. package/cjs/i18n/adapter-next-translate/code/DynamicNamespaces.js +0 -9
  187. package/cjs/i18n/adapter-next-translate/code/T.js +0 -31
  188. package/cjs/i18n/adapter-next-translate/code/TransText.js +0 -9
  189. package/cjs/i18n/adapter-next-translate/code/getT.js +0 -15
  190. package/cjs/i18n/adapter-next-translate/code/index.js +0 -49
  191. package/cjs/i18n/adapter-next-translate/code/nextTranslateI18n.js +0 -19
  192. package/cjs/i18n/adapter-next-translate/code/useT.js +0 -43
  193. package/cjs/i18n/client/formatRoutePathname.js +0 -5
  194. package/cjs/i18n/client/index.js +0 -3
  195. package/cjs/i18n/client/interpolateTo.js +0 -14
  196. package/cjs/i18n/client/routeHasDynamicPortion.js +0 -2
  197. package/cjs/i18n/compiler/api.js +0 -18
  198. package/cjs/i18n/compiler/code/data-routes.js +0 -99
  199. package/cjs/i18n/compiler/code/data-translations.js +0 -86
  200. package/cjs/i18n/compiler/code/data.js +0 -20
  201. package/cjs/i18n/compiler/code/generate.js +0 -46
  202. package/cjs/i18n/compiler/code/index.js +0 -2
  203. package/cjs/i18n/compiler/code/tsCompile.js +0 -27
  204. package/cjs/i18n/compiler/code/write.js +0 -39
  205. package/cjs/i18n/compiler/config.js +0 -13
  206. package/cjs/i18n/compiler/helpers.js +0 -14
  207. package/cjs/i18n/compiler/input/data-local.js +0 -60
  208. package/cjs/i18n/compiler/input/data-remote.js +0 -41
  209. package/cjs/i18n/compiler/input/data.js +0 -11
  210. package/cjs/i18n/compiler/input/index.js +0 -3
  211. package/cjs/i18n/compiler/input/types.js +0 -1
  212. package/cjs/i18n/compiler/input/write.js +0 -15
  213. package/cjs/i18n/compiler/pluralisation.js +0 -59
  214. package/cjs/i18n/compiler/summary/data.js +0 -28
  215. package/cjs/i18n/compiler/summary/generate.js +0 -27
  216. package/cjs/i18n/compiler/summary/index.js +0 -2
  217. package/cjs/i18n/compiler/summary/write.js +0 -18
  218. package/cjs/i18n/compiler/types.js +0 -1
  219. package/cjs/i18n/compiler-sync.js +0 -2
  220. package/cjs/i18n/compiler-worker.js +0 -3
  221. package/cjs/i18n/compiler.js +0 -1
  222. package/cjs/i18n/index.js +0 -2
  223. package/cjs/i18n/next.js +0 -3
  224. package/cjs/i18n/types.js +0 -1
  225. package/cjs/index.d.ts +0 -2
  226. package/cjs/next.d.ts +0 -3
  227. package/cjs/package.json +0 -34
  228. package/cjs/types.d.ts +0 -48
  229. package/client/formatRoutePathname.js +0 -5
  230. package/client/index.js +0 -3
  231. package/client/interpolateTo.js +0 -14
  232. package/client/routeHasDynamicPortion.js +0 -2
  233. package/compiler/api.js +0 -18
  234. package/compiler/code/data-routes.js +0 -99
  235. package/compiler/code/data-translations.js +0 -86
  236. package/compiler/code/data.js +0 -20
  237. package/compiler/code/generate.js +0 -46
  238. package/compiler/code/index.js +0 -2
  239. package/compiler/code/tsCompile.js +0 -27
  240. package/compiler/code/write.js +0 -39
  241. package/compiler/config.js +0 -13
  242. package/compiler/helpers.js +0 -14
  243. package/compiler/input/data-local.js +0 -60
  244. package/compiler/input/data-remote.js +0 -41
  245. package/compiler/input/data.js +0 -11
  246. package/compiler/input/index.js +0 -3
  247. package/compiler/input/types.js +0 -1
  248. package/compiler/input/write.js +0 -15
  249. package/compiler/pluralisation.js +0 -59
  250. package/compiler/summary/data.js +0 -28
  251. package/compiler/summary/generate.js +0 -27
  252. package/compiler/summary/index.js +0 -2
  253. package/compiler/summary/write.js +0 -18
  254. package/compiler/types.js +0 -1
  255. package/compiler-sync.js +0 -2
  256. package/compiler-worker.js +0 -3
  257. package/compiler.js +0 -1
  258. package/index.js +0 -2
  259. package/next.js +0 -3
  260. package/types.js +0 -1
@@ -0,0 +1 @@
1
+ export * from "./compiler-sync";
@@ -0,0 +1 @@
1
+ exports._default = require('./compiler-sync.cjs.js').default;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var synckit = require('synckit');
6
+ require('@koine/utils');
7
+ require('node:fs');
8
+ require('node:path');
9
+ require('@koine/node');
10
+ require('typescript');
11
+ require('minimatch');
12
+ require('next/dist/shared/lib/utils');
13
+ require('node:fs/promises');
14
+ require('glob');
15
+ require('node:child_process');
16
+ require('node:https');
17
+
18
+ let i18nCompilerSync = synckit.createSyncFn(require.resolve("./compiler-worker.cjs"));
19
+
20
+ exports.i18nCompilerSync = i18nCompilerSync;
@@ -0,0 +1,2 @@
1
+ export * from './compiler-sync.cjs.js';
2
+ export { _default as default } from './compiler-sync.cjs.default.js';
@@ -0,0 +1,16 @@
1
+ import { createSyncFn } from 'synckit';
2
+ import '@koine/utils';
3
+ import 'node:fs';
4
+ import 'node:path';
5
+ import '@koine/node';
6
+ import 'typescript';
7
+ import 'minimatch';
8
+ import 'next/dist/shared/lib/utils';
9
+ import 'node:fs/promises';
10
+ import 'glob';
11
+ import 'node:child_process';
12
+ import 'node:https';
13
+
14
+ let i18nCompilerSync = createSyncFn(require.resolve("./compiler-worker.cjs"));
15
+
16
+ export { i18nCompilerSync };
@@ -0,0 +1 @@
1
+ export * from "./compiler-worker";
@@ -0,0 +1 @@
1
+ exports._default = require('./compiler-worker.cjs.js').default;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var synckit = require('synckit');
4
+ var api = require('./api.cjs.js');
5
+ require('@koine/utils');
6
+ require('node:fs');
7
+ require('node:path');
8
+ require('@koine/node');
9
+ require('./formatRoutePathname.cjs.js');
10
+ require('typescript');
11
+ require('minimatch');
12
+ require('next/dist/shared/lib/utils');
13
+ require('node:fs/promises');
14
+ require('glob');
15
+ require('node:child_process');
16
+ require('node:https');
17
+
18
+ synckit.runAsWorker(api.i18nCompiler);
@@ -0,0 +1,2 @@
1
+ export * from './compiler-worker.cjs.js';
2
+ export { _default as default } from './compiler-worker.cjs.default.js';
@@ -0,0 +1,16 @@
1
+ import { runAsWorker } from 'synckit';
2
+ import { i as i18nCompiler } from './api.esm.js';
3
+ import '@koine/utils';
4
+ import 'node:fs';
5
+ import 'node:path';
6
+ import '@koine/node';
7
+ import './formatRoutePathname.esm.js';
8
+ import 'typescript';
9
+ import 'minimatch';
10
+ import 'next/dist/shared/lib/utils';
11
+ import 'node:fs/promises';
12
+ import 'glob';
13
+ import 'node:child_process';
14
+ import 'node:https';
15
+
16
+ runAsWorker(i18nCompiler);
@@ -0,0 +1 @@
1
+ export * from "./compiler";
@@ -0,0 +1 @@
1
+ exports._default = require('./compiler.cjs.js').default;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var api = require('./api.cjs.js');
6
+ require('@koine/utils');
7
+ require('node:fs');
8
+ require('node:path');
9
+ require('@koine/node');
10
+ require('./formatRoutePathname.cjs.js');
11
+ require('typescript');
12
+ require('minimatch');
13
+ require('next/dist/shared/lib/utils');
14
+ require('node:fs/promises');
15
+ require('glob');
16
+ require('node:child_process');
17
+ require('node:https');
18
+
19
+
20
+
21
+ exports.i18nCompiler = api.i18nCompiler;
@@ -0,0 +1,2 @@
1
+ export * from './compiler.cjs.js';
2
+ export { _default as default } from './compiler.cjs.default.js';
@@ -0,0 +1,13 @@
1
+ export { i as i18nCompiler } from './api.esm.js';
2
+ import '@koine/utils';
3
+ import 'node:fs';
4
+ import 'node:path';
5
+ import '@koine/node';
6
+ import './formatRoutePathname.esm.js';
7
+ import 'typescript';
8
+ import 'minimatch';
9
+ import 'next/dist/shared/lib/utils';
10
+ import 'node:fs/promises';
11
+ import 'glob';
12
+ import 'node:child_process';
13
+ import 'node:https';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ let formatRoutePathname = (pathname = "", options) => {
4
+ const { trailingSlash } = options || {};
5
+ pathname = ("/" + pathname + "/").replace(/\/+/g, "/");
6
+ if (!trailingSlash) {
7
+ pathname = pathname.replace(/\/*$/, "");
8
+ }
9
+ return pathname || "/";
10
+ };
11
+
12
+ exports.formatRoutePathname = formatRoutePathname;
@@ -0,0 +1,10 @@
1
+ let formatRoutePathname = (pathname = "", options) => {
2
+ const { trailingSlash } = options || {};
3
+ pathname = ("/" + pathname + "/").replace(/\/+/g, "/");
4
+ if (!trailingSlash) {
5
+ pathname = pathname.replace(/\/*$/, "");
6
+ }
7
+ return pathname || "/";
8
+ };
9
+
10
+ export { formatRoutePathname as f };
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./index";
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var formatRoutePathname = require('./formatRoutePathname.cjs.js');
6
+ var utils = require('@koine/utils');
7
+
8
+ function interpolateTo(value, params) {
9
+ let pathname = value.replace(/\./g, "/");
10
+ if (process.env["NODE_ENV"] === "development") {
11
+ if (params) {
12
+ pathname.replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g, (_, dynamicKey) => {
13
+ const key = dynamicKey;
14
+ if (!(key in params)) {
15
+ throw new Error("[@koine/i18n]::interpolateTo, using '" +
16
+ value +
17
+ "' without param '" +
18
+ key +
19
+ "'");
20
+ }
21
+ if (!["string", "number"].includes(typeof params[key])) {
22
+ throw new Error("[@koine/i18n]::interpolateTo, using '" +
23
+ value +
24
+ "' with unserializable param '" +
25
+ key +
26
+ "' (type '" +
27
+ utils.getType(params[key]) +
28
+ "')");
29
+ }
30
+ return "";
31
+ });
32
+ }
33
+ }
34
+ pathname = pathname
35
+ ? params
36
+ ? pathname.replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g, (_, dynamicKey) => params[dynamicKey.trim()] + "")
37
+ : pathname
38
+ :
39
+ "/";
40
+ return formatRoutePathname.formatRoutePathname(pathname);
41
+ }
42
+
43
+ let routeHasDynamicPortion = (routeIdOrPortion) => /\[/.test(routeIdOrPortion);
44
+
45
+ exports.formatRoutePathname = formatRoutePathname.formatRoutePathname;
46
+ exports.interpolateTo = interpolateTo;
47
+ exports.routeHasDynamicPortion = routeHasDynamicPortion;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.esm.js ADDED
@@ -0,0 +1,42 @@
1
+ import { f as formatRoutePathname } from './formatRoutePathname.esm.js';
2
+ export { f as formatRoutePathname } from './formatRoutePathname.esm.js';
3
+ import { getType } from '@koine/utils';
4
+
5
+ function interpolateTo(value, params) {
6
+ let pathname = value.replace(/\./g, "/");
7
+ if (process.env["NODE_ENV"] === "development") {
8
+ if (params) {
9
+ pathname.replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g, (_, dynamicKey) => {
10
+ const key = dynamicKey;
11
+ if (!(key in params)) {
12
+ throw new Error("[@koine/i18n]::interpolateTo, using '" +
13
+ value +
14
+ "' without param '" +
15
+ key +
16
+ "'");
17
+ }
18
+ if (!["string", "number"].includes(typeof params[key])) {
19
+ throw new Error("[@koine/i18n]::interpolateTo, using '" +
20
+ value +
21
+ "' with unserializable param '" +
22
+ key +
23
+ "' (type '" +
24
+ getType(params[key]) +
25
+ "')");
26
+ }
27
+ return "";
28
+ });
29
+ }
30
+ }
31
+ pathname = pathname
32
+ ? params
33
+ ? pathname.replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g, (_, dynamicKey) => params[dynamicKey.trim()] + "")
34
+ : pathname
35
+ :
36
+ "/";
37
+ return formatRoutePathname(pathname);
38
+ }
39
+
40
+ let routeHasDynamicPortion = (routeIdOrPortion) => /\[/.test(routeIdOrPortion);
41
+
42
+ export { interpolateTo, routeHasDynamicPortion };
package/next.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./next";
@@ -0,0 +1 @@
1
+ exports._default = require('./next.cjs.js').default;
package/next.cjs.js ADDED
@@ -0,0 +1,377 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('@koine/utils');
6
+ var webpack = require('webpack');
7
+ var api = require('./api.cjs.js');
8
+ var node_module = require('node:module');
9
+ var compilerSync = require('./compiler-sync.cjs.js');
10
+ require('node:fs');
11
+ require('node:path');
12
+ require('@koine/node');
13
+ require('./formatRoutePathname.cjs.js');
14
+ require('typescript');
15
+ require('minimatch');
16
+ require('next/dist/shared/lib/utils');
17
+ require('node:fs/promises');
18
+ require('glob');
19
+ require('node:child_process');
20
+ require('node:https');
21
+ require('synckit');
22
+
23
+ function _interopNamespace(e) {
24
+ if (e && e.__esModule) return e;
25
+ var n = Object.create(null);
26
+ if (e) {
27
+ Object.keys(e).forEach(function (k) {
28
+ if (k !== 'default') {
29
+ var d = Object.getOwnPropertyDescriptor(e, k);
30
+ Object.defineProperty(n, k, d.get ? d : {
31
+ enumerable: true,
32
+ get: function () { return e[k]; }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ n["default"] = e;
38
+ return Object.freeze(n);
39
+ }
40
+
41
+ function orderRoutes(routes, defaultLocale) {
42
+ const { [defaultLocale]: routesForDefaultLocale, ...restRoutes } = routes;
43
+ return {
44
+ [defaultLocale]: routesForDefaultLocale,
45
+ ...restRoutes,
46
+ };
47
+ }
48
+ function transformRoute(route) {
49
+ const { pathname: rawPathname, template: rawTemplate } = route;
50
+ const pathnameParts = rawPathname.split("/").filter((part) => !!part);
51
+ const templateParts = rawTemplate.split("/").filter((part) => !!part);
52
+ const mapPartsByIdx = {};
53
+ const pathname = pathnameParts
54
+ .map((part) => {
55
+ const hasWildcard = part.endsWith("*");
56
+ part = part.replace("*", "");
57
+ const isDynamic = part.startsWith("{{") && part.endsWith("}}");
58
+ const asValue = isDynamic
59
+ ? part.match(/{{(.+)}}/)?.[1].trim() ?? ""
60
+ : part.trim();
61
+ const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
62
+ mapPartsByIdx[asValue] = {
63
+ isDynamic,
64
+ hasWildcard,
65
+ };
66
+ return isDynamic ? `:${asPath}` : asPath;
67
+ })
68
+ .join("/");
69
+ const template = templateParts
70
+ .map((part) => {
71
+ const isDynamic = part.startsWith("[") && part.endsWith("]");
72
+ const asValue = isDynamic
73
+ ? part.match(/\[(.+)\]/)?.[1].trim() ?? ""
74
+ : part.trim();
75
+ const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
76
+ const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
77
+ return isDynamic ? `:${asPath}` : asPath;
78
+ })
79
+ .join("/");
80
+ return { pathname, template };
81
+ }
82
+ function getRoutesMap(map = {}, routesByLocale, pathnameBuffer = "", templateBuffer = "") {
83
+ const isSpaRoute = Object.keys(routesByLocale).includes("[spa]");
84
+ for (const key in routesByLocale) {
85
+ const pathOrNestedRoutes = routesByLocale[key];
86
+ const template = `${templateBuffer}/${key}`;
87
+ if (typeof pathOrNestedRoutes === "string") {
88
+ if (!isSpaRoute || (isSpaRoute && ["[spa]", "index"].includes(key))) {
89
+ map[template] = {
90
+ template,
91
+ pathname: pathOrNestedRoutes,
92
+ wildcard: pathOrNestedRoutes.includes("*"),
93
+ };
94
+ }
95
+ }
96
+ else {
97
+ if (!isSpaRoute) {
98
+ getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
99
+ }
100
+ }
101
+ }
102
+ return map;
103
+ }
104
+ function getWithoutIndex(template) {
105
+ return template.replace(/\/index$/, "");
106
+ }
107
+ function getPathRedirect(arg) {
108
+ const { localeSource, localeDestination, route, usePathnameAsSource, permanent, } = arg;
109
+ const { template: routeTemplate, pathname } = transformRoute(route);
110
+ const template = usePathnameAsSource ? pathname : routeTemplate;
111
+ const sourcePrefix = localeSource ? `${localeSource}/` : "";
112
+ const source = getWithoutIndex(`/${utils.normaliseUrlPathname(sourcePrefix + template)}`);
113
+ const destinationPrefix = localeDestination ? `${localeDestination}/` : "";
114
+ const destination = `/${utils.normaliseUrlPathname(destinationPrefix + pathname)}`;
115
+ if (source === destination)
116
+ return;
117
+ const redirect = {
118
+ source,
119
+ destination,
120
+ permanent: Boolean(permanent),
121
+ };
122
+ return redirect;
123
+ }
124
+ function generateRedirects(arg) {
125
+ const { routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, permanent, debug, } = arg;
126
+ const orderedRoutes = orderRoutes(routes, defaultLocale);
127
+ const redirects = [];
128
+ for (const locale in orderedRoutes) {
129
+ const routesByLocale = routes[locale];
130
+ const routesMap = getRoutesMap({}, routesByLocale);
131
+ for (const template in routesMap) {
132
+ const route = routesMap[template];
133
+ if (route.pathname !== getWithoutIndex(template)) {
134
+ const isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
135
+ const isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
136
+ if (localeParam) {
137
+ if (isVisibleDefaultLocale) {
138
+ redirects.push(getPathRedirect({ localeDestination: locale, route, permanent }));
139
+ }
140
+ else if (isHiddenDefaultLocale) {
141
+ redirects.push(getPathRedirect({ localeSource: locale, route, permanent }));
142
+ }
143
+ else if (locale !== defaultLocale) {
144
+ redirects.push(getPathRedirect({
145
+ localeSource: locale,
146
+ localeDestination: locale,
147
+ route,
148
+ permanent,
149
+ }));
150
+ }
151
+ else {
152
+ redirects.push(getPathRedirect({ route, permanent }));
153
+ }
154
+ }
155
+ else {
156
+ if (isVisibleDefaultLocale) {
157
+ redirects.push(getPathRedirect({ localeDestination: locale, route, permanent }));
158
+ }
159
+ else if (locale !== defaultLocale) {
160
+ redirects.push(getPathRedirect({
161
+ localeSource: locale,
162
+ localeDestination: locale,
163
+ route,
164
+ permanent,
165
+ }));
166
+ }
167
+ else {
168
+ redirects.push(getPathRedirect({ route, permanent }));
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ const cleaned = utils.arrayUniqueByProperties(redirects.filter(Boolean), ["source", "destination"]).map((rewrite) => localeParam ? rewrite : { ...rewrite, locale: false });
175
+ if (debug)
176
+ console.info("[@koine/next/plugin-legacy:generateRedirects]", cleaned);
177
+ return cleaned;
178
+ }
179
+ function getPathRewrite(arg) {
180
+ const { localeSource, localeDestination, localeParam, route } = arg;
181
+ const { pathname, template } = transformRoute(route);
182
+ let sourcePrefix = "";
183
+ if (localeSource)
184
+ sourcePrefix = `${localeSource}/`;
185
+ else if (localeParam)
186
+ sourcePrefix = `:${localeParam}/`;
187
+ const source = `/${utils.normaliseUrlPathname(sourcePrefix + pathname)}`;
188
+ let destinationPrefix = "";
189
+ if (localeDestination)
190
+ destinationPrefix = `${localeDestination}/`;
191
+ else if (localeParam)
192
+ destinationPrefix = `:${localeParam}/`;
193
+ const destination = getWithoutIndex(`/${utils.normaliseUrlPathname(destinationPrefix + template)}`);
194
+ if (source === destination)
195
+ return;
196
+ return {
197
+ source,
198
+ destination,
199
+ };
200
+ }
201
+ function generateRewrites(arg) {
202
+ const { routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, debug } = arg;
203
+ const orderedRoutes = orderRoutes(routes, defaultLocale);
204
+ const rewrites = [];
205
+ for (const locale in orderedRoutes) {
206
+ const routesByLocale = routes[locale];
207
+ const routesMap = getRoutesMap({}, routesByLocale);
208
+ for (const template in routesMap) {
209
+ const route = routesMap[template];
210
+ const isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
211
+ const isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
212
+ if (localeParam) {
213
+ if (isHiddenDefaultLocale) {
214
+ rewrites.push(getPathRewrite({ localeDestination: locale, route }));
215
+ }
216
+ else {
217
+ rewrites.push(getPathRewrite({ localeParam, route }));
218
+ }
219
+ }
220
+ else {
221
+ if (route.pathname !== getWithoutIndex(template)) {
222
+ if (locale !== defaultLocale || isVisibleDefaultLocale) {
223
+ rewrites.push(getPathRewrite({ localeSource: locale, route }));
224
+ }
225
+ else {
226
+ rewrites.push(getPathRewrite({ route }));
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+ const cleaned = utils.arrayUniqueByProperties(rewrites.filter(Boolean), ["source", "destination"]);
233
+ if (debug)
234
+ console.info("[@koine/next/plugin-legacy:generateRewrites]", cleaned);
235
+ return cleaned;
236
+ }
237
+ let withI18nLegacy = (config) => {
238
+ const { i18nRoutes, ...restNextConfig } = config;
239
+ if (!i18nRoutes)
240
+ return restNextConfig;
241
+ const { locales = ["en"], defaultLocale = "en", ...restI18n } = config.i18n || {};
242
+ restNextConfig.i18n = { ...restI18n, locales, defaultLocale };
243
+ const options = {
244
+ hideDefaultLocaleInUrl: true,
245
+ localeParam: "",
246
+ ...i18nRoutes,
247
+ locales,
248
+ defaultLocale,
249
+ };
250
+ const nextConfig = { ...restNextConfig };
251
+ if (options.routes) {
252
+ const { redirects, rewrites } = nextConfig;
253
+ nextConfig.redirects = async () => {
254
+ const defaults = generateRedirects(options);
255
+ if (redirects) {
256
+ const customs = await redirects();
257
+ return [...defaults, ...customs];
258
+ }
259
+ return defaults;
260
+ };
261
+ nextConfig.rewrites = async () => {
262
+ const defaults = generateRewrites(options);
263
+ if (rewrites) {
264
+ const customs = await rewrites();
265
+ if (Array.isArray(customs)) {
266
+ return {
267
+ beforeFiles: defaults,
268
+ afterFiles: customs,
269
+ fallback: [],
270
+ };
271
+ }
272
+ return {
273
+ ...customs,
274
+ beforeFiles: [...defaults, ...(customs.beforeFiles || [])],
275
+ };
276
+ }
277
+ return {
278
+ beforeFiles: defaults,
279
+ afterFiles: [],
280
+ fallback: [],
281
+ };
282
+ };
283
+ }
284
+ return nextConfig;
285
+ };
286
+
287
+ let tweakNextConfig = (options, nextConfig) => {
288
+ const { defaultLocale, locales, appRouterLocaleParamName } = options;
289
+ if (appRouterLocaleParamName) {
290
+ delete nextConfig.i18n;
291
+ }
292
+ else {
293
+ nextConfig.i18n = nextConfig.i18n || { locales, defaultLocale };
294
+ nextConfig.i18n.locales = locales;
295
+ nextConfig.i18n.defaultLocale = defaultLocale;
296
+ }
297
+ nextConfig.webpack = (webpackConfig) => {
298
+ webpackConfig.plugins.push(new webpack.ContextReplacementPlugin(/^date-fns[/\\]locale$/, new RegExp(`\\.[/\\\\](${locales.join("|")})[/\\\\]index\\.js$`)));
299
+ return webpackConfig;
300
+ };
301
+ return nextConfig;
302
+ };
303
+ let getRedirects = async (prevRedirects, { appRouterLocaleParamName, permanentRedirects }, i18nResult) => {
304
+ const defaultRedirects = api.generateRedirects(i18nResult.config, i18nResult.code.routes.byId, i18nResult.code.options.routes, appRouterLocaleParamName, permanentRedirects);
305
+ if (prevRedirects) {
306
+ const custom = await prevRedirects();
307
+ return [...defaultRedirects, ...custom];
308
+ }
309
+ return defaultRedirects;
310
+ };
311
+ let getRewrites = async (prevRewrites, { appRouterLocaleParamName }, i18nResult) => {
312
+ const defaultRewrites = api.generateRewrites(i18nResult.config, i18nResult.code.routes.byId, i18nResult.code.options.routes, appRouterLocaleParamName);
313
+ if (prevRewrites) {
314
+ const custom = await prevRewrites();
315
+ if (Array.isArray(custom)) {
316
+ return {
317
+ beforeFiles: defaultRewrites,
318
+ afterFiles: custom,
319
+ fallback: [],
320
+ };
321
+ }
322
+ return {
323
+ ...custom,
324
+ beforeFiles: [...defaultRewrites, ...(custom.beforeFiles || [])],
325
+ };
326
+ }
327
+ return {
328
+ beforeFiles: defaultRewrites,
329
+ afterFiles: [],
330
+ fallback: [],
331
+ };
332
+ };
333
+
334
+ let withI18nAsync = (config = {}) => async () => {
335
+ const { i18nCompiler: i18nConfig, redirects, rewrites, ...restNextConfig } = config;
336
+ let nextConfig = restNextConfig;
337
+ if (!i18nConfig)
338
+ return nextConfig;
339
+ const i18nResult = await api.i18nCompiler(i18nConfig);
340
+ nextConfig = tweakNextConfig(i18nResult.config, nextConfig);
341
+ nextConfig.redirects = () => getRedirects(redirects, i18nConfig, i18nResult);
342
+ nextConfig.rewrites = () => getRewrites(rewrites, i18nConfig, i18nResult);
343
+ if (i18nConfig.code.adapter === "next-translate") {
344
+ try {
345
+ const withNextTranslate = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('next-translate-plugin')); }).then((m) => m.default);
346
+ nextConfig = withNextTranslate(nextConfig);
347
+ }
348
+ catch (e) {
349
+ }
350
+ }
351
+ return nextConfig;
352
+ };
353
+
354
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('next.cjs.js', document.baseURI).href)));
355
+ let withI18n = (config = {}) => {
356
+ const { i18nCompiler: i18nConfig, redirects, rewrites, ...restNextConfig } = config;
357
+ let nextConfig = restNextConfig;
358
+ if (!i18nConfig)
359
+ return nextConfig;
360
+ const i18nResult = compilerSync.i18nCompilerSync(i18nConfig);
361
+ nextConfig = tweakNextConfig(i18nResult.config, nextConfig);
362
+ nextConfig.redirects = () => getRedirects(redirects, i18nConfig, i18nResult);
363
+ nextConfig.rewrites = () => getRewrites(rewrites, i18nConfig, i18nResult);
364
+ if (i18nConfig.code.adapter === "next-translate") {
365
+ try {
366
+ const withNextTranslate = require$1("next-translate-plugin");
367
+ nextConfig = withNextTranslate(nextConfig);
368
+ }
369
+ catch (e) {
370
+ }
371
+ }
372
+ return nextConfig;
373
+ };
374
+
375
+ exports.withI18n = withI18n;
376
+ exports.withI18nAsync = withI18nAsync;
377
+ exports.withI18nLegacy = withI18nLegacy;
package/next.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './next.cjs.js';
2
+ export { _default as default } from './next.cjs.default.js';