Skip to content

Commit 2890851

Browse files
authored
fix node patches in node 20.12 (#53)
2 parents 04d179e + a69bada commit 2890851

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

internal/node/node_patches.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ function patcher$1(fs = fs__namespace, roots) {
6262
if (err) {
6363
return cb(err);
6464
}
65-
path__namespace.resolve(args[0]);
65+
path__namespace.resolve(
66+
// node 20.12 tightened the constraints and requires the input to be a string
67+
String(args[0]));
6668
if (!stats.isSymbolicLink()) {
6769
return cb(null, stats);
6870
}
@@ -216,7 +218,9 @@ function patcher$1(fs = fs__namespace, roots) {
216218
return str;
217219
};
218220
fs.readdir = (...args) => {
219-
const p = path__namespace.resolve(args[0]);
221+
const p = path__namespace.resolve(
222+
// node 20.12 tightened the constraints and requires the input to be a string
223+
String(args[0]));
220224
let cb = args[args.length - 1];
221225
if (typeof cb !== 'function') {
222226
// this will likely throw callback required error.
@@ -229,8 +233,7 @@ function patcher$1(fs = fs__namespace, roots) {
229233
}
230234
// user requested withFileTypes
231235
if (result[0] && result[0].isSymbolicLink) {
232-
Promise
233-
.all(result.map((v) => handleDirent(p, v)))
236+
Promise.all(result.map((v) => handleDirent(p, v)))
234237
.then(() => {
235238
cb(null, result);
236239
})
@@ -247,7 +250,9 @@ function patcher$1(fs = fs__namespace, roots) {
247250
};
248251
fs.readdirSync = (...args) => {
249252
const res = origReaddirSync(...args);
250-
const p = path__namespace.resolve(args[0]);
253+
const p = path__namespace.resolve(
254+
// node 20.12 tightened the constraints and requires the input to be a string
255+
String(args[0]));
251256
res.forEach((v) => {
252257
handleDirentSync(p, v);
253258
});
@@ -561,21 +566,22 @@ const runfilesPathMatcher = '.runfiles';
561566
function inferRunfilesDirFromPath(maybeRunfilesSource) {
562567
while (maybeRunfilesSource !== '/') {
563568
if (maybeRunfilesSource.endsWith(runfilesPathMatcher)) {
564-
return maybeRunfilesSource + '/';
569+
return (maybeRunfilesSource + '/');
565570
}
566571
maybeRunfilesSource = path__namespace.dirname(maybeRunfilesSource);
567572
}
568573
throw new Error('Path does not contain a runfiles parent directory.');
569574
}
570-
const removeNulls = (value) => value != null;
575+
function removeNulls(value) {
576+
return value != null;
577+
}
571578
function runfilesLocator() {
572579
// Sometimes cwd is under runfiles
573580
const cwd = process.cwd();
574581
// Runfiles environment variables are the preferred reference point, but can fail
575-
const envRunfilesCanidates = [
576-
process.env.RUNFILES_DIR,
577-
process.env.RUNFILES,
578-
].filter(removeNulls).map(runfilesDir => {
582+
const envRunfilesCanidates = [process.env.RUNFILES_DIR, process.env.RUNFILES]
583+
.filter(removeNulls)
584+
.map(runfilesDir => {
579585
const adjustedRunfilesDir = fs__namespace.realpathSync(runfilesDir);
580586
if (runfilesDir !== adjustedRunfilesDir) {
581587
return adjustedRunfilesDir;
@@ -625,8 +631,7 @@ VERBOSE_LOGS, } = process.env;
625631
if (BAZEL_PATCH_ROOTS) {
626632
const roots = BAZEL_PATCH_ROOTS ? BAZEL_PATCH_ROOTS.split(',') : [];
627633
if (VERBOSE_LOGS) {
628-
console
629-
.error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`);
634+
console.error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`);
630635
}
631636
const fs = require('fs');
632637
patcher$1(fs, roots);

0 commit comments

Comments
 (0)