Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 16, 2023
1 parent ba19153 commit 187b2a1
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 139 deletions.
2 changes: 0 additions & 2 deletions .github/funding.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
11 changes: 5 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/unified-signatures */
import {Options as LocatePathOptions} from 'locate-path';
import {type Options as LocatePathOptions} from 'locate-path';

/**
Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
Expand All @@ -8,14 +7,14 @@ export const findUpStop: unique symbol;

export type Match = string | typeof findUpStop | undefined;

export interface Options extends LocatePathOptions {
export type Options = {
/**
The path to the directory to stop the search before reaching root if there were no matches before the `stopAt` directory.
A directory path where the search halts if no matches are found before reaching this point.
@default path.parse(cwd).root
Default: Root directory
*/
readonly stopAt?: string;
}
} & LocatePathOptions;

/**
Find a file or directory by walking up parent directories.
Expand Down
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {locatePath, locatePathSync} from 'locate-path';

const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
import {toPath} from 'unicorn-magic';

export const findUpStop = Symbol('findUpStop');

export async function findUpMultiple(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) || '');
let directory = path.resolve(toPath(options.cwd) ?? '');
const {root} = path.parse(directory);
const stopAt = path.resolve(directory, toPath(options.stopAt ?? root));
const limit = options.limit || Number.POSITIVE_INFINITY;
const limit = options.limit ?? Number.POSITIVE_INFINITY;
const paths = [name].flat();

const runMatcher = async locateOptions => {
Expand Down Expand Up @@ -51,10 +49,10 @@ export async function findUpMultiple(name, options = {}) {
}

export function findUpMultipleSync(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) || '');
let directory = path.resolve(toPath(options.cwd) ?? '');
const {root} = path.parse(directory);
const stopAt = path.resolve(directory, toPath(options.stopAt) ?? root);
const limit = options.limit || Number.POSITIVE_INFINITY;
const limit = options.limit ?? Number.POSITIVE_INFINITY;
const paths = [name].flat();

const runMatcher = locateOptions => {
Expand Down
10 changes: 9 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {expectType, expectError} from 'tsd';
import {findUp, findUpSync, findUpMultiple, findUpMultipleSync, findUpStop, pathExists, pathExistsSync} from './index.js';
import {
findUp,
findUpSync,
findUpMultiple,
findUpMultipleSync,
findUpStop,
pathExists,
pathExistsSync,
} from './index.js';

expectType<Promise<string | undefined>>(findUp('unicorn.png'));
expectType<Promise<string | undefined>>(findUp('unicorn.png', {cwd: ''}));
Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -43,14 +47,15 @@
"path"
],
"dependencies": {
"locate-path": "^7.1.0",
"path-exists": "^5.0.0"
"locate-path": "^7.2.0",
"path-exists": "^5.0.0",
"unicorn-magic": "^0.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
"ava": "^5.3.1",
"is-path-inside": "^4.0.0",
"tempy": "^3.0.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
"tempy": "^3.1.0",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}
32 changes: 10 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## Install

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

## Usage
Expand Down Expand Up @@ -45,7 +45,7 @@ console.log(await findUp(async directory => {
### findUp(name, options?)
### findUp(matcher, options?)

Returns a `Promise` for either the path or `undefined` if it couldn't be found.
Returns a `Promise` for either the path or `undefined` if it could not be found.

### findUp([...name], options?)

Expand All @@ -63,7 +63,7 @@ Returns a `Promise` for either an array of the first paths found (by respecting
### findUpSync(name, options?)
### findUpSync(matcher, options?)

Returns a path or `undefined` if it couldn't be found.
Returns a path or `undefined` if it could not be found.

### findUpSync([...name], options?)

Expand Down Expand Up @@ -107,9 +107,9 @@ The directory to start from.

Type: `string`\
Default: `'file'`\
Values: `'file'` `'directory'`
Values: `'file' | 'directory'`

The type of paths that can match.
The type of path to match.

##### allowSymlinks

Expand All @@ -120,10 +120,10 @@ Allow symbolic links to match if they point to the chosen path type.

##### stopAt

Type: `string`\
Default: `path.parse(cwd).root`
Type: `URL | string`\
Default: Root directory

The path to the directory to stop the search before reaching root if there were no matches before the `stopAt` directory.
A directory path where the search halts if no matches are found before reaching this point.

### pathExists(path)

Expand Down Expand Up @@ -155,18 +155,6 @@ await findUp(directory => {
## 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
- [package-up](https://github.com/sindresorhus/package-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">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
Loading

0 comments on commit 187b2a1

Please sign in to comment.