Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/find-up
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.1.0
Choose a base ref
...
head repository: sindresorhus/find-up
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.0.0
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on May 27, 2020

  1. Meta tweaks

    Closes #50
    sindresorhus committed May 27, 2020
    Copy the full SHA
    8f40a21 View commit details

Commits on Aug 11, 2020

  1. Require Node.js 10

    sindresorhus committed Aug 11, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b0bf065 View commit details
  2. 5.0.0

    sindresorhus committed Aug 11, 2020
    Copy the full SHA
    e852e9c View commit details
Showing with 89 additions and 92 deletions.
  1. +1 −1 .travis.yml
  2. +70 −69 index.d.ts
  3. +2 −2 index.test-d.ts
  4. +1 −1 license
  5. +8 −7 package.json
  6. +5 −10 readme.md
  7. +2 −2 test.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@ os:
- windows
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
139 changes: 70 additions & 69 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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: ''}));
@@ -74,4 +74,4 @@ expectType<string | undefined>(findUp.sync((): findUp.StopSymbol => findUp.stop,
expectType<Promise<boolean>>(findUp.exists('unicorn.png'));
expectType<boolean>(findUp.sync.exists('unicorn.png'));

expectType<Symbol>(findUp.stop);
expectType<findUp.StopSymbol>(findUp.stop);
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "find-up",
"version": "4.1.0",
"version": "5.0.0",
"description": "Find a file or directory by walking up parent directories",
"license": "MIT",
"repository": "sindresorhus/find-up",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
@@ -40,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.7.3",
"xo": "^0.24.0"
"tempy": "^0.6.0",
"tsd": "^0.13.1",
"xo": "^0.33.0"
}
}
15 changes: 5 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
# find-up [![Build Status](https://travis-ci.com/sindresorhus/find-up.svg?branch=master)](https://travis-ci.com/github/sindresorhus/find-up)

> Find a file or directory by walking up parent directories

## Install

```
$ npm install find-up
```


## Usage

```
@@ -44,7 +42,6 @@ const findUp = require('find-up');
})();
```


## API

### findUp(name, options?)
@@ -85,22 +82,22 @@ Type: `object`

##### cwd

Type: `string`<br>
Type: `string`\
Default: `process.cwd()`

Directory to start from.

##### type

Type: `string`<br>
Default: `'file'`<br>
Type: `string`\
Default: `'file'`\
Values: `'file'` `'directory'`

The type of paths that can match.

##### allowSymlinks

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

Allow symbolic links to match if they point to the chosen path type.
@@ -134,15 +131,13 @@ const findUp = require('find-up');
})();
```


## Related

- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path


---

<div align="center">
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -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 => {