vscode-find-up
v0.1.1
Published
[![npm version][npm-version-src]][npm-version-href] [![npm bundle size][npm-bundle-size-src]][npm-bundle-size-href] [![License][license-src]][license-href]
Readme
vscode-find-up
Zero-dependency find-up for VS Code extension environment. Uses vscode.workspace.fs API to support all file system providers (local, remote, virtual, etc.).
Install
npm install vscode-find-upUsage
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:
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 © 2026-PRESENT Vida Xie
