77 * @see https://github.com/babel/babel-loader/issues/34
88 * @see https://github.com/babel/babel-loader/pull/41
99 */
10+ const nodeModule = require ( "node:module" ) ;
1011const os = require ( "os" ) ;
1112const path = require ( "path" ) ;
1213const zlib = require ( "zlib" ) ;
@@ -21,6 +22,15 @@ let defaultCacheDirectory = null;
2122const gunzip = promisify ( zlib . gunzip ) ;
2223const gzip = promisify ( zlib . gzip ) ;
2324
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+
2434/**
2535 * Read the contents from the compressed file.
2636 *
@@ -136,7 +146,7 @@ const handleCache = async function (directory, params) {
136146 `discarded cache file '${ file } ' due to changes in external dependencies` ,
137147 ) ;
138148 } catch {
139- // conitnue if cache can't be read
149+ // continue if cache can't be read
140150 logger . debug ( `discarded cache as it can not be read` ) ;
141151 }
142152
@@ -219,7 +229,7 @@ function findCacheDir(name) {
219229 if ( env . CACHE_DIR && ! [ "true" , "false" , "1" , "0" ] . includes ( env . CACHE_DIR ) ) {
220230 return path . join ( env . CACHE_DIR , name ) ;
221231 }
222- const rootPkgJSONPath = path . dirname ( findUpSync ( "package.json" ) ) ;
232+ const rootPkgJSONPath = path . dirname ( findRootPackageJSON ( ) ) ;
223233 if ( rootPkgJSONPath ) {
224234 return path . join ( rootPkgJSONPath , "node_modules" , ".cache" , name ) ;
225235 }
0 commit comments