From b0bf065e672fccba96c53cba6d4ff3e4b61a3143 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 11 Aug 2020 20:42:40 +0200 Subject: [PATCH] Require Node.js 10 --- .travis.yml | 1 - index.d.ts | 139 ++++++++++++++++++++++++------------------------ index.test-d.ts | 2 +- package.json | 10 ++-- test.js | 4 +- 5 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.travis.yml b/.travis.yml index b33fb72..0509c62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,3 @@ node_js: - '14' - '12' - '10' - - '8' diff --git a/index.d.ts b/index.d.ts index 41e3192..6746bb7 100644 --- a/index.d.ts +++ b/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; @@ -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; - - /** - 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), options?: findUp.Options): Promise; + 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; + exists: (path: string) => Promise; /** 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; + + /** + 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), options?: findUp.Options): Promise; }; export = findUp; diff --git a/index.test-d.ts b/index.test-d.ts index 474a33a..49cedfd 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -9,7 +9,7 @@ expectType>(findUp(['rainbow.png', 'unicorn.png'], { expectType>(findUp(['rainbow.png', 'unicorn.png'], {allowSymlinks: false})); expectType>(findUp(['rainbow.png', 'unicorn.png'], {type: 'file'})); expectType>(findUp(['rainbow.png', 'unicorn.png'], {type: 'directory'})); -expectError(findUp(['rainbow.png', 'unicorn.png'], {concurrency: 1})) +expectError(findUp(['rainbow.png', 'unicorn.png'], {concurrency: 1})); expectType>(findUp(() => 'unicorn.png')); expectType>(findUp(() => 'unicorn.png', {cwd: ''})); diff --git a/package.json b/package.json index c8f54c7..48f6284 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test.js b/test.js index 73578da..d0df4a0 100644 --- a/test.js +++ b/test.js @@ -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 => {