7
7
* @see https://github.com/babel/babel-loader/issues/34
8
8
* @see https://github.com/babel/babel-loader/pull/41
9
9
*/
10
+ const nodeModule = require ( "node:module" ) ;
10
11
const os = require ( "os" ) ;
11
12
const path = require ( "path" ) ;
12
13
const zlib = require ( "zlib" ) ;
@@ -21,6 +22,15 @@ let defaultCacheDirectory = null;
21
22
const gunzip = promisify ( zlib . gunzip ) ;
22
23
const gzip = promisify ( zlib . gzip ) ;
23
24
25
+ const findRootPackageJSON = ( ) => {
26
+ if ( nodeModule . findPackageJSON ) {
27
+ return nodeModule . findPackageJSON ( ".." , __filename ) ;
28
+ } else {
29
+ // todo: remove this fallback when dropping support for Node.js < 22.14
30
+ return findUpSync ( "package.json" ) ;
31
+ }
32
+ } ;
33
+
24
34
/**
25
35
* Read the contents from the compressed file.
26
36
*
@@ -136,7 +146,7 @@ const handleCache = async function (directory, params) {
136
146
`discarded cache file '${ file } ' due to changes in external dependencies` ,
137
147
) ;
138
148
} catch {
139
- // conitnue if cache can't be read
149
+ // continue if cache can't be read
140
150
logger . debug ( `discarded cache as it can not be read` ) ;
141
151
}
142
152
@@ -219,7 +229,7 @@ function findCacheDir(name) {
219
229
if ( env . CACHE_DIR && ! [ "true" , "false" , "1" , "0" ] . includes ( env . CACHE_DIR ) ) {
220
230
return path . join ( env . CACHE_DIR , name ) ;
221
231
}
222
- const rootPkgJSONPath = path . dirname ( findUpSync ( "package.json" ) ) ;
232
+ const rootPkgJSONPath = path . dirname ( findRootPackageJSON ( ) ) ;
223
233
if ( rootPkgJSONPath ) {
224
234
return path . join ( rootPkgJSONPath , "node_modules" , ".cache" , name ) ;
225
235
}
0 commit comments