# vscode-find-up

[![npm version][npm-version-src]][npm-version-href]
[![npm bundle size][npm-bundle-size-src]][npm-bundle-size-href]
[![License][license-src]][license-href]

Zero-dependency [find-up](https://github.com/sindresorhus/find-up) for VS Code extension environment. Uses `vscode.workspace.fs` API to support all [file system providers](https://code.visualstudio.com/api/references/vscode-api#FileSystemProvider) (local, remote, virtual, etc.).

## Install

```bash
npm install vscode-find-up
```

## Usage

```ts
import { accessOk, findAny, findUp, walkUp } from 'vscode-find-up'

// Find a file by walking up from cwd
const uri = await findUp('package.json', {
  cwd: currentFileUri,
})

// Find the first match from multiple names
const config = await findAny(
  ['tsconfig.json', 'jsconfig.json'],
  { cwd: currentFileUri },
)

// Check if a file exists
const exists = await accessOk(fileUri)

// Walk parent directories as a generator
for (const dir of walkUp(startUri)) {
  // ...
}
```

Subpath imports are also available:

```ts
import { ok as accessOk } from 'vscode-find-up/access'
import { up as findUp } from 'vscode-find-up/find'
import { up as walkUp } from 'vscode-find-up/walk'
```

## API

### `findUp(name, options?): Promise<Uri | undefined>`

Find a file by name, walking parent directories until found. If `cwd` is not provided, searches from all workspace folders.

### `findAny(names, options?): Promise<Uri | undefined>`

Get the first path that matches any of the names provided. If `cwd` is not provided, searches from all workspace folders.

### `walkUp(base, options?): Generator<Uri>`

Generator that yields each directory from `base` up to the root (or `stopAt`).

### `accessOk(uri, type?): Promise<boolean>`

Check if a file or directory exists. Optionally check for a specific `FileType`.

### Options

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `cwd` | `Uri` | workspace folders | The starting directory |
| `stopAt` | `string \| Uri` | `cwd` | Stop directory (inclusive) |

## License

[MIT](./LICENSE) License &copy; 2026-PRESENT [Vida Xie](https://github.com/9romise)

## Credits

- [find-up](https://npmx.dev/package/find-up) - [MIT](https://github.com/sindresorhus/find-up/blob/main/license)
- [empathic](https://npmx.dev/package/empathic) - [MIT](https://github.com/lukeed/empathic/blob/main/license)

<!-- Badges -->

[npm-version-src]: https://npmx.dev/api/registry/badge/version/vscode-find-up
[npm-version-href]: https://npmx.dev/package/vscode-find-up
[npm-bundle-size-src]: https://npmx.dev/api/registry/badge/size/vscode-find-up
[npm-bundle-size-href]: https://npmx.dev/package/vscode-find-up
[license-src]: https://npmx.dev/api/registry/badge/license/vscode-find-up
[license-href]: https://opensource.org/licenses/MIT
