Skip to content
Permalink
Browse files
Require Node.js 10
  • Loading branch information
sindresorhus committed Aug 11, 2020
1 parent 8f40a21 commit b0bf065e672fccba96c53cba6d4ff3e4b61a3143
Showing with 78 additions and 78 deletions.
  1. +0 −1 .travis.yml
  2. +70 −69 index.d.ts
  3. +1 −1 index.test-d.ts
  4. +5 −5 package.json
  5. +2 −2 test.js
@@ -7,4 +7,3 @@ node_js:
- '14'
- '12'
- '10'
- '8'
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unified-signatures */
import {Options as LocatePathOptions} from 'locate-path';

declare const stop: unique symbol;
@@ -11,67 +12,30 @@ declare namespace findUp {
}

declare const findUp: {
/**
Find a file or directory by walking up parent directories.
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
// example.js
import findUp = require('find-up');
(async () => {
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
console.log(await findUp(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
})();
```
*/
(name: string | string[], options?: findUp.Options): Promise<string | undefined>;

/**
Find a file or directory by walking up parent directories.
sync: {
/**
Synchronously check if a path exists.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@param path - Path to the file or directory.
@returns Whether the path exists.
@example
```
import path = require('path');
import findUp = require('find-up');
@example
```
import findUp = require('find-up');
(async () => {
console.log(await findUp(async directory => {
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
})();
```
*/
(matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
exists: (path: string) => boolean;

sync: {
/**
Synchronously find a file or directory by walking up parent directories.
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
*/
(name: string | string[], options?: findUp.Options): string | undefined;
(name: string | readonly string[], options?: findUp.Options): string | undefined;

/**
Synchronously find a file or directory by walking up parent directories.
@@ -92,23 +56,7 @@ declare const findUp: {
```
*/
(matcher: (directory: string) => findUp.Match, options?: findUp.Options): string | undefined;

/**
Synchronously check if a path exists.
@param path - Path to the file or directory.
@returns Whether the path exists.
@example
```
import findUp = require('find-up');
console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
exists(path: string): boolean;
}
};

/**
Check if a path exists.
@@ -126,12 +74,65 @@ declare const findUp: {
})();
```
*/
exists(path: string): Promise<boolean>;
exists: (path: string) => Promise<boolean>;

/**
Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
*/
readonly stop: findUp.StopSymbol;

/**
Find a file or directory by walking up parent directories.
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
// example.js
import findUp = require('find-up');
(async () => {
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
console.log(await findUp(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
})();
```
*/
(name: string | readonly string[], options?: findUp.Options): Promise<string | undefined>;

/**
Find a file or directory by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@example
```
import path = require('path');
import findUp = require('find-up');
(async () => {
console.log(await findUp(async directory => {
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
})();
```
*/
(matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
};

export = findUp;
@@ -9,7 +9,7 @@ expectType<Promise<string | undefined>>(findUp(['rainbow.png', 'unicorn.png'], {
expectType<Promise<string | undefined>>(findUp(['rainbow.png', 'unicorn.png'], {allowSymlinks: false}));
expectType<Promise<string | undefined>>(findUp(['rainbow.png', 'unicorn.png'], {type: 'file'}));
expectType<Promise<string | undefined>>(findUp(['rainbow.png', 'unicorn.png'], {type: 'directory'}));
expectError(findUp(['rainbow.png', 'unicorn.png'], {concurrency: 1}))
expectError(findUp(['rainbow.png', 'unicorn.png'], {concurrency: 1}));

expectType<Promise<string | undefined>>(findUp(() => 'unicorn.png'));
expectType<Promise<string | undefined>>(findUp(() => 'unicorn.png', {cwd: ''}));
@@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
@@ -41,14 +41,14 @@
"path"
],
"dependencies": {
"locate-path": "^5.0.0",
"locate-path": "^6.0.0",
"path-exists": "^4.0.0"
},
"devDependencies": {
"ava": "^2.1.0",
"is-path-inside": "^2.1.0",
"tempy": "^0.3.0",
"tsd": "^0.11.0",
"xo": "^0.24.0"
"tempy": "^0.6.0",
"tsd": "^0.13.1",
"xo": "^0.33.0"
}
}
@@ -42,8 +42,8 @@ absolute.directoryLink = path.join(absolute.fixtureDirectory, name.directoryLink

// Create a disjoint directory, used for the not-found tests
test.beforeEach(t => {
const tmpDir = tempy.directory();
t.context.disjoint = tmpDir;
const temporaryDirectory = tempy.directory();
t.context.disjoint = temporaryDirectory;
});

test.afterEach(t => {

0 comments on commit b0bf065

Please sign in to comment.