Skip to content

Commit d82670c

Browse files
committed
[utils] [refactor] switch to an internal replacement for find-up
1 parent 53a9d5d commit d82670c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

utils/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
},
2727
"homepage": "https://github.com/import-js/eslint-plugin-import#readme",
2828
"dependencies": {
29-
"debug": "^3.2.7",
30-
"find-up": "^2.1.0"
29+
"debug": "^3.2.7"
3130
}
3231
}

utils/pkgUp.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,56 @@
11
'use strict';
22
exports.__esModule = true;
33

4-
const findUp = require('find-up');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
/**
8+
* Derived significantly from package [email protected]. See license below.
9+
*
10+
* @copyright Sindre Sorhus
11+
* MIT License
12+
*
13+
* Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
14+
*
15+
* Permission is hereby granted, free of charge, to any person obtaining a copy
16+
* of this software and associated documentation files (the "Software"), to deal
17+
* in the Software without restriction, including without limitation the rights
18+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
* copies of the Software, and to permit persons to whom the Software is
20+
* furnished to do so, subject to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be included in
23+
* all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31+
* THE SOFTWARE.
32+
*/
33+
function findUp(filename, cwd) {
34+
let dir = path.resolve(cwd || '');
35+
const root = path.parse(dir).root;
36+
37+
const filenames = [].concat(filename);
38+
39+
// eslint-disable-next-line no-constant-condition
40+
while (true) {
41+
const file = filenames.find((el) => fs.existsSync(path.resolve(dir, el)));
42+
43+
if (file) {
44+
return path.join(dir, file);
45+
}
46+
if (dir === root) {
47+
return null;
48+
}
49+
50+
dir = path.dirname(dir);
51+
}
52+
}
553

654
exports.default = function pkgUp(opts) {
7-
return findUp.sync('package.json', opts);
55+
return findUp('package.json', opts && opts.cwd);
856
};

0 commit comments

Comments
 (0)