next-intl 4.0.0-beta-bae1131 → 4.0.0-beta-c4c5986

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.
@@ -13,6 +13,23 @@ function warn(message) {
13
13
  console.warn(formatMessage(message));
14
14
  }
15
15
 
16
+ /**
17
+ * Wrapper around `fs.watch` that provides a workaround
18
+ * for https://github.com/nodejs/node/issues/5039.
19
+ */
20
+ function watchFile(filepath, callback) {
21
+ const directory = path.dirname(filepath);
22
+ const filename = path.basename(filepath);
23
+ return fs.watch(directory, {
24
+ persistent: false,
25
+ recursive: false
26
+ }, (event, changedFilename) => {
27
+ if (changedFilename === filename) {
28
+ callback();
29
+ }
30
+ });
31
+ }
32
+
16
33
  function runOnce(fn) {
17
34
  if (process.env._NEXT_INTL_COMPILE_MESSAGES === '1') {
18
35
  return;
@@ -43,10 +60,8 @@ function createMessagesDeclaration(messagesPath) {
43
60
  });
44
61
  }
45
62
  function startWatching(messagesPath) {
46
- const watcher = fs.watch(messagesPath, eventType => {
47
- if (eventType === 'change') {
48
- compileDeclaration(messagesPath, true);
49
- }
63
+ const watcher = watchFile(messagesPath, () => {
64
+ compileDeclaration(messagesPath, true);
50
65
  });
51
66
  process.on('exit', () => {
52
67
  watcher.close();
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { throwError } from './utils.js';
4
+ import watchFile from './watchFile.js';
4
5
 
5
6
  function runOnce(fn) {
6
7
  if (process.env._NEXT_INTL_COMPILE_MESSAGES === '1') {
@@ -32,10 +33,8 @@ function createMessagesDeclaration(messagesPath) {
32
33
  });
33
34
  }
34
35
  function startWatching(messagesPath) {
35
- const watcher = fs.watch(messagesPath, eventType => {
36
- if (eventType === 'change') {
37
- compileDeclaration(messagesPath, true);
38
- }
36
+ const watcher = watchFile(messagesPath, () => {
37
+ compileDeclaration(messagesPath, true);
39
38
  });
40
39
  process.on('exit', () => {
41
40
  watcher.close();
@@ -0,0 +1,21 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * Wrapper around `fs.watch` that provides a workaround
6
+ * for https://github.com/nodejs/node/issues/5039.
7
+ */
8
+ function watchFile(filepath, callback) {
9
+ const directory = path.dirname(filepath);
10
+ const filename = path.basename(filepath);
11
+ return fs.watch(directory, {
12
+ persistent: false,
13
+ recursive: false
14
+ }, (event, changedFilename) => {
15
+ if (changedFilename === filename) {
16
+ callback();
17
+ }
18
+ });
19
+ }
20
+
21
+ export { watchFile as default };
@@ -1,9 +1,4 @@
1
- import validateLocales from './validateLocales.js';
2
-
3
1
  function defineRouting(config) {
4
- {
5
- validateLocales(config.locales);
6
- }
7
2
  return config;
8
3
  }
9
4
 
@@ -2,6 +2,7 @@ import { cache } from 'react';
2
2
  import { _createIntlFormatters, _createCache, initializeConfig } from 'use-intl/core';
3
3
  import { getRequestLocale } from './RequestLocale.js';
4
4
  import getRuntimeConfig from 'next-intl/config';
5
+ import validateLocale from './validateLocale.js';
5
6
 
6
7
  // This is automatically inherited by `NextIntlClientProvider` if
7
8
  // the component is rendered from a Server Component
@@ -36,6 +37,9 @@ See also: https://next-intl.dev/docs/usage/configuration#i18n-request
36
37
  if (!result.locale) {
37
38
  throw new Error('No locale was returned from `getRequestConfig`.\n\nSee https://next-intl.dev/docs/usage/configuration#i18n-request');
38
39
  }
40
+ {
41
+ validateLocale(result.locale);
42
+ }
39
43
  return result;
40
44
  }
41
45
  const receiveRuntimeConfig = cache(receiveRuntimeConfigImpl);
@@ -0,0 +1,12 @@
1
+ function validateLocale(locale) {
2
+ try {
3
+ const constructed = new Intl.Locale(locale);
4
+ if (!constructed.language) {
5
+ throw new Error('Language is required');
6
+ }
7
+ } catch {
8
+ console.error(`An invalid locale was provided: "${locale}"\nPlease ensure you're using a valid Unicode locale identifier (e.g. "en-US").`);
9
+ }
10
+ }
11
+
12
+ export { validateLocale as default };
@@ -1 +1 @@
1
- import e from"fs";import t from"path";import{throwError as s}from"./utils.js";function n(n){const i=t.resolve(n);e.existsSync(i)||s(`\`createMessagesDeclaration\` points to a non-existent file: ${i}`),i.endsWith(".json")||s(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${i}`);const r=process.env["NODE_ENV".trim()];var c;c=()=>{o(n),"development"===r&&function(t){const s=e.watch(t,(e=>{"change"===e&&o(t,!0)}));process.on("exit",(()=>{s.close()}))}(n)},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",c())}function o(t,s=!1){const n=t.replace(/\.json$/,".d.json.ts");function o(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(s)return e.promises.readFile(t,"utf-8").then((t=>e.promises.writeFile(n,o(t))));const i=e.readFileSync(t,"utf-8");e.writeFileSync(n,o(i))}export{n as default};
1
+ import e from"fs";import t from"path";import{throwError as s}from"./utils.js";import n from"./watchFile.js";function o(o){const r=t.resolve(o);e.existsSync(r)||s(`\`createMessagesDeclaration\` points to a non-existent file: ${r}`),r.endsWith(".json")||s(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${r}`);const c=process.env["NODE_ENV".trim()];var a;a=()=>{i(o),"development"===c&&function(e){const t=n(e,(()=>{i(e,!0)}));process.on("exit",(()=>{t.close()}))}(o)},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",a())}function i(t,s=!1){const n=t.replace(/\.json$/,".d.json.ts");function o(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(s)return e.promises.readFile(t,"utf-8").then((t=>e.promises.writeFile(n,o(t))));const i=e.readFileSync(t,"utf-8");e.writeFileSync(n,o(i))}export{o as default};
@@ -0,0 +1 @@
1
+ import r from"fs";import t from"path";function e(e,a){const n=t.dirname(e),o=t.basename(e);return r.watch(n,{persistent:!1,recursive:!1},((r,t)=>{t===o&&a()}))}export{e as default};
@@ -0,0 +1,6 @@
1
+ import fs from 'fs';
2
+ /**
3
+ * Wrapper around `fs.watch` that provides a workaround
4
+ * for https://github.com/nodejs/node/issues/5039.
5
+ */
6
+ export default function watchFile(filepath: string, callback: () => void): fs.FSWatcher;
@@ -0,0 +1 @@
1
+ export default function validateLocale(locale: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.0.0-beta-bae1131",
3
+ "version": "4.0.0-beta-c4c5986",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -112,7 +112,7 @@
112
112
  "dependencies": {
113
113
  "@formatjs/intl-localematcher": "^0.5.4",
114
114
  "negotiator": "^1.0.0",
115
- "use-intl": "4.0.0-beta-bae1131"
115
+ "use-intl": "4.0.0-beta-c4c5986"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
@@ -124,5 +124,5 @@
124
124
  "optional": true
125
125
  }
126
126
  },
127
- "gitHead": "bef82f8d0200635fe32fd528072ef88031f79f93"
127
+ "gitHead": "a73e83b96977b9e56b1ea8fadcf4c67505d7c7d3"
128
128
  }
@@ -1,14 +0,0 @@
1
- function validateLocales(locales) {
2
- for (const locale of locales) {
3
- try {
4
- const constructed = new Intl.Locale(locale);
5
- if (!constructed.language) {
6
- throw new Error('Language is required');
7
- }
8
- } catch {
9
- console.error(`Found invalid locale within provided \`locales\`: "${locale}"\nPlease ensure you're using a valid Unicode locale identifier (e.g. "en-US").`);
10
- }
11
- }
12
- }
13
-
14
- export { validateLocales as default };
@@ -1,2 +0,0 @@
1
- import type { Locales } from './types.js';
2
- export default function validateLocales(locales: Locales): void;