/usr/lib/nodejs/find-up/index.js is in node-find-up 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 'use strict';
const path = require('path');
const pathExists = require('path-exists');
module.exports = (filename, opts) => {
opts = opts || {};
const startDir = path.resolve(opts.cwd || '');
const root = path.parse(startDir).root;
return new Promise(resolve => {
(function find(dir) {
const fp = path.join(dir, filename);
pathExists(fp).then(exists => {
if (exists) {
resolve(fp);
} else if (dir === root) {
resolve(null);
} else {
find(path.dirname(dir));
}
});
})(startDir);
});
};
module.exports.sync = (filename, opts) => {
opts = opts || {};
let dir = path.resolve(opts.cwd || '');
const root = path.parse(dir).root;
// eslint-disable-next-line no-constant-condition
while (true) {
const fp = path.join(dir, filename);
if (pathExists.sync(fp)) {
return fp;
} else if (dir === root) {
return null;
}
dir = path.dirname(dir);
}
};
|