Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 11, 2020
1 parent 8f40a21 commit b0bf065
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 78 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -7,4 +7,3 @@ node_js:
- '14'
- '12'
- '10'
- '8'
139 changes: 70 additions & 69 deletions index.d.ts
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unified-signatures */
import {Options as LocatePathOptions} from 'locate-path';

declare const stop: unique symbol;
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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;
2 changes: 1 addition & 1 deletion index.test-d.ts
Expand Up @@ -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: ''}));
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -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 => {
Expand Down

0 comments on commit b0bf065

Please sign in to comment.