Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @see https://github.com/babel/babel-loader/issues/34
* @see https://github.com/babel/babel-loader/pull/41
*/
const nodeModule = require("node:module");
const os = require("os");
const path = require("path");
const zlib = require("zlib");
Expand All @@ -21,6 +22,15 @@ let defaultCacheDirectory = null;
const gunzip = promisify(zlib.gunzip);
const gzip = promisify(zlib.gzip);

const findRootPackageJSON = () => {
if (nodeModule.findPackageJSON) {
return nodeModule.findPackageJSON("..", __filename);
} else {
// todo: remove this fallback when dropping support for Node.js < 22.14
return findUpSync("package.json");
}
};

/**
* Read the contents from the compressed file.
*
Expand Down Expand Up @@ -136,7 +146,7 @@ const handleCache = async function (directory, params) {
`discarded cache file '${file}' due to changes in external dependencies`,
);
} catch {
// conitnue if cache can't be read
// continue if cache can't be read
logger.debug(`discarded cache as it can not be read`);
}

Expand Down Expand Up @@ -219,7 +229,7 @@ function findCacheDir(name) {
if (env.CACHE_DIR && !["true", "false", "1", "0"].includes(env.CACHE_DIR)) {
return path.join(env.CACHE_DIR, name);
}
const rootPkgJSONPath = path.dirname(findUpSync("package.json"));
const rootPkgJSONPath = path.dirname(findRootPackageJSON());
if (rootPkgJSONPath) {
return path.join(rootPkgJSONPath, "node_modules", ".cache", name);
}
Expand Down