vscode-find-up 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,40 +15,70 @@ npm install vscode-find-up
15
15
  ## Usage
16
16
 
17
17
  ```ts
18
- import { findUp, walkUp } from 'vscode-find-up'
18
+ import { accessOk, findAny, findUp, walkUp } from 'vscode-find-up'
19
19
 
20
20
  // Find a file by walking up from cwd
21
21
  const uri = await findUp('package.json', {
22
22
  cwd: currentFileUri,
23
23
  })
24
24
 
25
+ // Find the first match from multiple names
26
+ const config = await findAny(
27
+ ['tsconfig.json', 'jsconfig.json'],
28
+ { cwd: currentFileUri },
29
+ )
30
+
31
+ // Check if a file exists
32
+ const exists = await accessOk(fileUri)
33
+
25
34
  // Walk parent directories as a generator
26
35
  for (const dir of walkUp(startUri)) {
27
36
  // ...
28
37
  }
29
38
  ```
30
39
 
40
+ Subpath imports are also available:
41
+
42
+ ```ts
43
+ import { ok as accessOk } from 'vscode-find-up/access'
44
+ import { up as findUp } from 'vscode-find-up/find'
45
+ import { up as walkUp } from 'vscode-find-up/walk'
46
+ ```
47
+
31
48
  ## API
32
49
 
33
50
  ### `findUp(name, options?): Promise<Uri | undefined>`
34
51
 
35
- Find a file by name, walking parent directories until found.
52
+ Find a file by name, walking parent directories until found. If `cwd` is not provided, searches from all workspace folders.
53
+
54
+ ### `findAny(names, options?): Promise<Uri | undefined>`
55
+
56
+ Get the first path that matches any of the names provided. If `cwd` is not provided, searches from all workspace folders.
36
57
 
37
58
  ### `walkUp(base, options?): Generator<Uri>`
38
59
 
39
- Generator that yields each directory from `base` up to the root (or `last`).
60
+ Generator that yields each directory from `base` up to the root (or `stopAt`).
61
+
62
+ ### `accessOk(uri, type?): Promise<boolean>`
63
+
64
+ Check if a file or directory exists. Optionally check for a specific `FileType`.
40
65
 
41
66
  ### Options
42
67
 
43
68
  | Option | Type | Default | Description |
44
69
  | --- | --- | --- | --- |
45
- | `cwd` | `Uri` | | The starting directory |
46
- | `last` | `string \| Uri` | `"/"` | Stop directory (inclusive) |
70
+ | `cwd` | `Uri` | workspace folders | The starting directory |
71
+ | `stopAt` | `string \| Uri` | `cwd` | Stop directory (inclusive) |
47
72
 
48
73
  ## License
49
74
 
50
75
  [MIT](./LICENSE) License &copy; 2026-PRESENT [Vida Xie](https://github.com/9romise)
51
76
 
77
+ ## Credits
78
+
79
+ - [find-up](https://npmx.dev/package/find-up) - [MIT](https://github.com/sindresorhus/find-up/blob/main/license)
80
+ - [empathic](https://npmx.dev/package/empathic) - [MIT](https://github.com/lukeed/empathic/blob/main/license)
81
+
52
82
  <!-- Badges -->
53
83
 
54
84
  [npm-version-src]: https://npmx.dev/api/registry/badge/version/vscode-find-up
@@ -0,0 +1,6 @@
1
+ import { FileType, Uri } from "vscode";
2
+
3
+ //#region src/access.d.ts
4
+ declare function ok(uri: Uri, type?: FileType): Promise<boolean>;
5
+ //#endregion
6
+ export { ok };
package/dist/access.js ADDED
@@ -0,0 +1,13 @@
1
+ import { workspace } from "vscode";
2
+ //#region src/access.ts
3
+ async function ok(uri, type) {
4
+ try {
5
+ const stat = await workspace.fs.stat(uri);
6
+ if (type) return stat.type === type;
7
+ return true;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+ //#endregion
13
+ export { ok };
@@ -1,22 +1,6 @@
1
- import { FileType, Uri } from "vscode";
1
+ import { Options } from "./walk.js";
2
+ import { Uri } from "vscode";
2
3
 
3
- //#region src/access.d.ts
4
- declare function ok(uri: Uri, type?: FileType): Promise<boolean>;
5
- //#endregion
6
- //#region src/walk.d.ts
7
- interface Options {
8
- /**
9
- *
10
- * @default workspace.getWorkspaceFolder(base)?.uri ?? Uri.file('/')
11
- */
12
- cwd?: Uri;
13
- /**
14
- * @default options.cwd
15
- */
16
- stopAt?: Uri | string;
17
- }
18
- declare function up$1(base: Uri, options?: Options): Generator<Uri>;
19
- //#endregion
20
4
  //#region src/find.d.ts
21
5
  /**
22
6
  * Find an item by name, walking parent directories until found.
@@ -33,4 +17,4 @@ declare function up(name: string, options?: Options): Promise<Uri | undefined>;
33
17
  */
34
18
  declare function any(names: string[], options?: Options): Promise<Uri | undefined>;
35
19
  //#endregion
36
- export { type Options, ok as accessOk, any as findAny, up as findUp, up$1 as walkUp };
20
+ export { any, up };
@@ -1,33 +1,6 @@
1
+ import { ok } from "./access.js";
2
+ import { up as up$1 } from "./walk.js";
1
3
  import { Uri, workspace } from "vscode";
2
-
3
- //#region src/access.ts
4
- async function ok(uri, type) {
5
- try {
6
- const stat = await workspace.fs.stat(uri);
7
- if (type) return stat.type === type;
8
- return true;
9
- } catch {
10
- return false;
11
- }
12
- }
13
-
14
- //#endregion
15
- //#region src/walk.ts
16
- function* up$1(base, options = {}) {
17
- const { cwd } = options;
18
- const root = (cwd ? workspace.getWorkspaceFolder(cwd)?.uri : workspace.workspaceFolders?.[0].uri) ?? Uri.file("/");
19
- const last = typeof options.stopAt === "string" ? Uri.joinPath(root, options.stopAt) : options.stopAt ?? root;
20
- let current = base;
21
- while (true) {
22
- yield current;
23
- if (current.path === last.path) return;
24
- const parent = Uri.joinPath(current, "..");
25
- if (parent.path === current.path) return;
26
- current = parent;
27
- }
28
- }
29
-
30
- //#endregion
31
4
  //#region src/find.ts
32
5
  /**
33
6
  * Find an item by name, walking parent directories until found.
@@ -63,6 +36,5 @@ async function any(names, options = {}) {
63
36
  if (await ok(tmp)) return tmp;
64
37
  }
65
38
  }
66
-
67
39
  //#endregion
68
- export { ok as accessOk, any as findAny, up as findUp, up$1 as walkUp };
40
+ export { any, up };
@@ -0,0 +1,4 @@
1
+ import { ok } from "./access.js";
2
+ import { Options, up as up$1 } from "./walk.js";
3
+ import { any, up } from "./find.js";
4
+ export { type Options, ok as accessOk, any as findAny, up as findUp, up$1 as walkUp };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { ok } from "./access.js";
2
+ import { up as up$1 } from "./walk.js";
3
+ import { any, up } from "./find.js";
4
+ export { ok as accessOk, any as findAny, up as findUp, up$1 as walkUp };
package/dist/walk.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Uri } from "vscode";
2
+
3
+ //#region src/walk.d.ts
4
+ interface Options {
5
+ /**
6
+ *
7
+ * @default workspace.getWorkspaceFolder(base)?.uri ?? Uri.file('/')
8
+ */
9
+ cwd?: Uri;
10
+ /**
11
+ * @default options.cwd
12
+ */
13
+ stopAt?: Uri | string;
14
+ }
15
+ declare function up(base: Uri, options?: Options): Generator<Uri>;
16
+ //#endregion
17
+ export { Options, up };
package/dist/walk.js ADDED
@@ -0,0 +1,17 @@
1
+ import { Uri, workspace } from "vscode";
2
+ //#region src/walk.ts
3
+ function* up(base, options = {}) {
4
+ const { cwd } = options;
5
+ const root = (cwd ? workspace.getWorkspaceFolder(cwd)?.uri : workspace.workspaceFolders?.[0].uri) ?? Uri.file("/");
6
+ const last = typeof options.stopAt === "string" ? Uri.joinPath(root, options.stopAt) : options.stopAt ?? root;
7
+ let current = base;
8
+ while (true) {
9
+ yield current;
10
+ if (current.path === last.path) return;
11
+ const parent = Uri.joinPath(current, "..");
12
+ if (parent.path === current.path) return;
13
+ current = parent;
14
+ }
15
+ }
16
+ //#endregion
17
+ export { up };
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "vscode-find-up",
3
3
  "type": "module",
4
- "version": "0.0.1",
5
- "packageManager": "pnpm@10.30.3",
4
+ "version": "0.1.1",
6
5
  "author": {
7
6
  "name": "Vida Xie",
8
7
  "email": "vida_2020@163.com",
@@ -19,44 +18,50 @@
19
18
  },
20
19
  "keywords": [
21
20
  "vscode",
21
+ "find",
22
+ "up",
23
+ "findup",
22
24
  "find-up"
23
25
  ],
24
26
  "sideEffects": false,
25
27
  "exports": {
26
- ".": "./dist/index.mjs",
28
+ ".": "./dist/index.js",
29
+ "./access": "./dist/access.js",
30
+ "./find": "./dist/find.js",
31
+ "./walk": "./dist/walk.js",
27
32
  "./package.json": "./package.json"
28
33
  },
29
- "types": "./dist/index.d.mts",
30
34
  "files": [
31
35
  "dist"
32
36
  ],
33
- "scripts": {
34
- "dev": "tsdown --watch",
35
- "build": "tsdown",
36
- "test": "vitest",
37
- "lint": "eslint .",
38
- "lint:fix": "pnpm lint --fix",
39
- "typecheck": "tsc --noEmit",
40
- "prepublishOnly": "npm run build"
41
- },
42
37
  "peerDependencies": {
43
38
  "@types/vscode": "*"
44
39
  },
45
40
  "devDependencies": {
46
- "@types/node": "catalog:dev",
47
- "@vida0905/eslint-config": "catalog:dev",
48
- "eslint": "catalog:dev",
49
- "jest-mock-vscode": "catalog:dev",
50
- "nano-staged": "catalog:dev",
51
- "simple-git-hooks": "catalog:dev",
52
- "tsdown": "catalog:dev",
53
- "typescript": "catalog:dev",
54
- "vitest": "catalog:dev"
41
+ "@arethetypeswrong/core": "^0.18.2",
42
+ "@types/node": "^25.3.5",
43
+ "@vida0905/eslint-config": "^2.10.1",
44
+ "eslint": "^10.0.3",
45
+ "jest-mock-vscode": "^4.11.0",
46
+ "nano-staged": "^0.9.0",
47
+ "publint": "^0.3.18",
48
+ "simple-git-hooks": "^2.13.1",
49
+ "tsdown": "^0.21.0",
50
+ "typescript": "^5.9.3",
51
+ "vitest": "^4.0.18"
55
52
  },
56
53
  "simple-git-hooks": {
57
54
  "pre-commit": "npx nano-staged"
58
55
  },
59
56
  "nano-staged": {
60
57
  "*": "eslint --fix"
58
+ },
59
+ "scripts": {
60
+ "dev": "tsdown --watch",
61
+ "build": "tsdown",
62
+ "test": "vitest",
63
+ "lint": "eslint .",
64
+ "lint:fix": "pnpm lint --fix",
65
+ "typecheck": "tsc --noEmit"
61
66
  }
62
- }
67
+ }