next-intl 3.0.3 → 3.1.0

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.
@@ -10,38 +10,72 @@ var path__default = /*#__PURE__*/_interopDefault(path);
10
10
 
11
11
  /* eslint-env node */
12
12
 
13
- function resolveI18nPath(cwd, providedPath) {
14
- let i18nPath = providedPath;
15
- if (i18nPath) {
16
- i18nPath = path__default.default.resolve(i18nPath);
17
- if (!fs__default.default.existsSync(i18nPath)) {
18
- throw new Error("Could not find i18n config at ".concat(i18nPath, ", please provide a valid path."));
13
+ function resolveI18nPath(providedPath, cwd) {
14
+ function resolvePath(pathname) {
15
+ const parts = [];
16
+ if (cwd) parts.push(cwd);
17
+ parts.push(pathname);
18
+ return path__default.default.resolve(...parts);
19
+ }
20
+ function pathExists(pathname) {
21
+ return fs__default.default.existsSync(resolvePath(pathname));
22
+ }
23
+ if (providedPath) {
24
+ if (!pathExists(providedPath)) {
25
+ throw new Error("Could not find i18n config at ".concat(providedPath, ", please provide a valid path."));
19
26
  }
27
+ return providedPath;
20
28
  } else {
21
- i18nPath = ['./i18n.tsx', './i18n.ts', './i18n.js', './i18n.jsx', './src/i18n.tsx', './src/i18n.ts', './src/i18n.js', './src/i18n.jsx'].map(cur => path__default.default.resolve(cwd, cur)).find(cur => fs__default.default.existsSync(cur));
22
- if (!i18nPath) {
23
- throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n");
29
+ for (const candidate of ['./i18n.tsx', './i18n.ts', './i18n.js', './i18n.jsx', './src/i18n.tsx', './src/i18n.ts', './src/i18n.js', './src/i18n.jsx']) {
30
+ if (pathExists(candidate)) {
31
+ return candidate;
32
+ }
24
33
  }
34
+ throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n");
25
35
  }
26
- return i18nPath;
27
36
  }
28
37
  function initPlugin(i18nPath, nextConfig) {
29
38
  if ((nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.i18n) != null) {
30
39
  console.warn("\nnext-intl has found an `i18n` config in your next.config.js. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the `pages` folder, you can refer to this example: https://github.com/amannn/next-intl/tree/main/packages/example-app-router-migration\n");
31
40
  }
32
- return Object.assign({}, nextConfig, {
33
- webpack() {
34
- for (var _len = arguments.length, _ref = new Array(_len), _key = 0; _key < _len; _key++) {
35
- _ref[_key] = arguments[_key];
41
+ const useTurbo = process.env.TURBOPACK != null;
42
+ let nextIntlConfig;
43
+ if (useTurbo) {
44
+ var _nextConfig$experimen, _nextConfig$experimen2;
45
+ if (i18nPath && i18nPath.startsWith('/')) {
46
+ throw new Error("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: " + i18nPath + '\n');
47
+ }
48
+ nextIntlConfig = {
49
+ experimental: {
50
+ ...(nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental),
51
+ turbo: {
52
+ ...(nextConfig === null || nextConfig === void 0 || (_nextConfig$experimen = nextConfig.experimental) === null || _nextConfig$experimen === void 0 ? void 0 : _nextConfig$experimen.turbo),
53
+ resolveAlias: {
54
+ ...(nextConfig === null || nextConfig === void 0 || (_nextConfig$experimen2 = nextConfig.experimental) === null || _nextConfig$experimen2 === void 0 || (_nextConfig$experimen2 = _nextConfig$experimen2.turbo) === null || _nextConfig$experimen2 === void 0 ? void 0 : _nextConfig$experimen2.resolveAlias),
55
+ // Turbo aliases don't work with absolute
56
+ // paths (see error handling above)
57
+ 'next-intl/config': resolveI18nPath(i18nPath)
58
+ }
59
+ }
36
60
  }
37
- let [config, options] = _ref;
38
- config.resolve.alias['next-intl/config'] = require.resolve(resolveI18nPath(config.context, i18nPath));
39
- if (typeof (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.webpack) === 'function') {
40
- return nextConfig.webpack(config, options);
61
+ };
62
+ } else {
63
+ nextIntlConfig = {
64
+ webpack() {
65
+ for (var _len = arguments.length, _ref = new Array(_len), _key = 0; _key < _len; _key++) {
66
+ _ref[_key] = arguments[_key];
67
+ }
68
+ let [config, options] = _ref;
69
+ // Webpack requires absolute paths
70
+ config.resolve.alias['next-intl/config'] = path__default.default.resolve(config.context, resolveI18nPath(i18nPath, config.context));
71
+ if (typeof (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.webpack) === 'function') {
72
+ return nextConfig.webpack(config, options);
73
+ }
74
+ return config;
41
75
  }
42
- return config;
43
- }
44
- });
76
+ };
77
+ }
78
+ return Object.assign({}, nextConfig, nextIntlConfig);
45
79
  }
46
80
  module.exports = function withNextIntl(i18nPath) {
47
81
  return nextConfig => initPlugin(i18nPath, nextConfig);
@@ -1 +1 @@
1
- import n from"fs";import e from"path";function t(t,o){return null!=(null==o?void 0:o.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the `pages` folder, you can refer to this example: https://github.com/amannn/next-intl/tree/main/packages/example-app-router-migration\n"),Object.assign({},o,{webpack(){for(var i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];let[a,l]=r;return a.resolve.alias["next-intl/config"]=require.resolve(function(t,o){let i=o;if(i){if(i=e.resolve(i),!n.existsSync(i))throw new Error("Could not find i18n config at ".concat(i,", please provide a valid path."))}else if(i=["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"].map((n=>e.resolve(t,n))).find((e=>n.existsSync(e))),!i)throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n");return i}(a.context,t)),"function"==typeof(null==o?void 0:o.webpack)?o.webpack(a,l):a}})}module.exports=function(n){return e=>t(n,e)};
1
+ import n from"fs";import e from"path";function t(t,o){function r(t){return n.existsSync(function(n){const t=[];return o&&t.push(o),t.push(n),e.resolve(...t)}(t))}if(t){if(!r(t))throw new Error("Could not find i18n config at ".concat(t,", please provide a valid path."));return t}for(const n of["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"])if(r(n))return n;throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n")}module.exports=function(n){return o=>function(n,o){let r;if(null!=(null==o?void 0:o.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the `pages` folder, you can refer to this example: https://github.com/amannn/next-intl/tree/main/packages/example-app-router-migration\n"),null!=process.env.TURBOPACK){var i,s;if(n&&n.startsWith("/"))throw new Error("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: "+n+"\n");r={experimental:{...null==o?void 0:o.experimental,turbo:{...null==o||null===(i=o.experimental)||void 0===i?void 0:i.turbo,resolveAlias:{...null==o||null===(s=o.experimental)||void 0===s||null===(s=s.turbo)||void 0===s?void 0:s.resolveAlias,"next-intl/config":t(n)}}}}}else r={webpack(){for(var r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];let[l,a]=i;return l.resolve.alias["next-intl/config"]=e.resolve(l.context,t(n,l.context)),"function"==typeof(null==o?void 0:o.webpack)?o.webpack(l,a):l}};return Object.assign({},o,r)}(n,o)};
@@ -1 +1 @@
1
- "use strict";var n=require("fs"),e=require("path");function t(n){return n&&n.__esModule?n:{default:n}}var r=t(n),i=t(e);function o(n,e){return null!=(null==e?void 0:e.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the `pages` folder, you can refer to this example: https://github.com/amannn/next-intl/tree/main/packages/example-app-router-migration\n"),Object.assign({},e,{webpack(){for(var t=arguments.length,o=new Array(t),s=0;s<t;s++)o[s]=arguments[s];let[a,l]=o;return a.resolve.alias["next-intl/config"]=require.resolve(function(n,e){let t=e;if(t){if(t=i.default.resolve(t),!r.default.existsSync(t))throw new Error("Could not find i18n config at ".concat(t,", please provide a valid path."))}else if(t=["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"].map((e=>i.default.resolve(n,e))).find((n=>r.default.existsSync(n))),!t)throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n");return t}(a.context,n)),"function"==typeof(null==e?void 0:e.webpack)?e.webpack(a,l):a}})}module.exports=function(n){return e=>o(n,e)};
1
+ "use strict";var n=require("fs"),e=require("path");function t(n){return n&&n.__esModule?n:{default:n}}var o=t(n),r=t(e);function i(n,e){function t(n){return o.default.existsSync(function(n){const t=[];return e&&t.push(e),t.push(n),r.default.resolve(...t)}(n))}if(n){if(!t(n))throw new Error("Could not find i18n config at ".concat(n,", please provide a valid path."));return n}for(const n of["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"])if(t(n))return n;throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n")}module.exports=function(n){return e=>function(n,e){let t;if(null!=(null==e?void 0:e.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the `pages` folder, you can refer to this example: https://github.com/amannn/next-intl/tree/main/packages/example-app-router-migration\n"),null!=process.env.TURBOPACK){var o,s;if(n&&n.startsWith("/"))throw new Error("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: "+n+"\n");t={experimental:{...null==e?void 0:e.experimental,turbo:{...null==e||null===(o=e.experimental)||void 0===o?void 0:o.turbo,resolveAlias:{...null==e||null===(s=e.experimental)||void 0===s||null===(s=s.turbo)||void 0===s?void 0:s.resolveAlias,"next-intl/config":i(n)}}}}}else t={webpack(){for(var t=arguments.length,o=new Array(t),s=0;s<t;s++)o[s]=arguments[s];let[l,u]=o;return l.resolve.alias["next-intl/config"]=r.default.resolve(l.context,i(n,l.context)),"function"==typeof(null==e?void 0:e.webpack)?e.webpack(l,u):l}};return Object.assign({},e,t)}(n,e)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.0.3",
3
+ "version": "3.1.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "A minimal, but complete solution for internationalization in Next.js apps.",
@@ -73,7 +73,7 @@
73
73
  "dependencies": {
74
74
  "@formatjs/intl-localematcher": "^0.2.32",
75
75
  "negotiator": "^0.6.3",
76
- "use-intl": "^3.0.3"
76
+ "use-intl": "^3.1.0"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -89,7 +89,7 @@
89
89
  "eslint": "^8.46.0",
90
90
  "eslint-config-molindo": "^7.0.0",
91
91
  "eslint-plugin-deprecation": "^1.4.1",
92
- "next": "14.0.1",
92
+ "next": "14.0.3",
93
93
  "path-to-regexp": "^6.2.1",
94
94
  "react": "^18.2.0",
95
95
  "react-dom": "^18.2.0",
@@ -125,5 +125,5 @@
125
125
  "limit": "5.7 KB"
126
126
  }
127
127
  ],
128
- "gitHead": "30b62603b4df925d69ec7111e4167fcee628ab33"
128
+ "gitHead": "12d1bb5ea05e2e41b036d0d68c59ff13a946f841"
129
129
  }