Skip to content

Commit

Permalink
fix node patches in node 20.12 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher authored Apr 24, 2024
2 parents 04d179e + a69bada commit 2890851
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions internal/node/node_patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ function patcher$1(fs = fs__namespace, roots) {
if (err) {
return cb(err);
}
path__namespace.resolve(args[0]);
path__namespace.resolve(
// node 20.12 tightened the constraints and requires the input to be a string
String(args[0]));
if (!stats.isSymbolicLink()) {
return cb(null, stats);
}
Expand Down Expand Up @@ -216,7 +218,9 @@ function patcher$1(fs = fs__namespace, roots) {
return str;
};
fs.readdir = (...args) => {
const p = path__namespace.resolve(args[0]);
const p = path__namespace.resolve(
// node 20.12 tightened the constraints and requires the input to be a string
String(args[0]));
let cb = args[args.length - 1];
if (typeof cb !== 'function') {
// this will likely throw callback required error.
Expand All @@ -229,8 +233,7 @@ function patcher$1(fs = fs__namespace, roots) {
}
// user requested withFileTypes
if (result[0] && result[0].isSymbolicLink) {
Promise
.all(result.map((v) => handleDirent(p, v)))
Promise.all(result.map((v) => handleDirent(p, v)))
.then(() => {
cb(null, result);
})
Expand All @@ -247,7 +250,9 @@ function patcher$1(fs = fs__namespace, roots) {
};
fs.readdirSync = (...args) => {
const res = origReaddirSync(...args);
const p = path__namespace.resolve(args[0]);
const p = path__namespace.resolve(
// node 20.12 tightened the constraints and requires the input to be a string
String(args[0]));
res.forEach((v) => {
handleDirentSync(p, v);
});
Expand Down Expand Up @@ -561,21 +566,22 @@ const runfilesPathMatcher = '.runfiles';
function inferRunfilesDirFromPath(maybeRunfilesSource) {
while (maybeRunfilesSource !== '/') {
if (maybeRunfilesSource.endsWith(runfilesPathMatcher)) {
return maybeRunfilesSource + '/';
return (maybeRunfilesSource + '/');
}
maybeRunfilesSource = path__namespace.dirname(maybeRunfilesSource);
}
throw new Error('Path does not contain a runfiles parent directory.');
}
const removeNulls = (value) => value != null;
function removeNulls(value) {
return value != null;
}
function runfilesLocator() {
// Sometimes cwd is under runfiles
const cwd = process.cwd();
// Runfiles environment variables are the preferred reference point, but can fail
const envRunfilesCanidates = [
process.env.RUNFILES_DIR,
process.env.RUNFILES,
].filter(removeNulls).map(runfilesDir => {
const envRunfilesCanidates = [process.env.RUNFILES_DIR, process.env.RUNFILES]
.filter(removeNulls)
.map(runfilesDir => {
const adjustedRunfilesDir = fs__namespace.realpathSync(runfilesDir);
if (runfilesDir !== adjustedRunfilesDir) {
return adjustedRunfilesDir;
Expand Down Expand Up @@ -625,8 +631,7 @@ VERBOSE_LOGS, } = process.env;
if (BAZEL_PATCH_ROOTS) {
const roots = BAZEL_PATCH_ROOTS ? BAZEL_PATCH_ROOTS.split(',') : [];
if (VERBOSE_LOGS) {
console
.error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`);
console.error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`);
}
const fs = require('fs');
patcher$1(fs, roots);
Expand Down

0 comments on commit 2890851

Please sign in to comment.