|
1 | 1 | 'use strict';
|
2 | 2 | exports.__esModule = true;
|
3 | 3 |
|
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 | +} |
5 | 53 |
|
6 | 54 | exports.default = function pkgUp(opts) {
|
7 |
| - return findUp.sync('package.json', opts); |
| 55 | + return findUp('package.json', opts && opts.cwd); |
8 | 56 | };
|
0 commit comments