File tree 2 files changed +24
-4
lines changed
packages/next-intl/src/plugin
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 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 : ( ) => void ) {
6
7
if ( process . env . _NEXT_INTL_COMPILE_MESSAGES === '1' ) {
@@ -40,10 +41,8 @@ export default function createMessagesDeclaration(messagesPath: string) {
40
41
}
41
42
42
43
function startWatching ( messagesPath : string ) {
43
- const watcher = fs . watch ( messagesPath , ( eventType ) => {
44
- if ( eventType === 'change' ) {
45
- compileDeclaration ( messagesPath , true ) ;
46
- }
44
+ const watcher = watchFile ( messagesPath , ( ) => {
45
+ compileDeclaration ( messagesPath , true ) ;
47
46
} ) ;
48
47
49
48
process . on ( 'exit' , ( ) => {
Original file line number Diff line number Diff line change
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
+ export default function watchFile ( filepath : string , callback : ( ) => void ) {
9
+ const directory = path . dirname ( filepath ) ;
10
+ const filename = path . basename ( filepath ) ;
11
+
12
+ return fs . watch (
13
+ directory ,
14
+ { persistent : false , recursive : false } ,
15
+ ( event , changedFilename ) => {
16
+ if ( changedFilename === filename ) {
17
+ callback ( ) ;
18
+ }
19
+ }
20
+ ) ;
21
+ }
You can’t perform that action at this time.
0 commit comments