+1
-0
@@ -0,1 +1,2 @@ | ||
| // re-export existsSync? | ||
| const { accessSync, constants } = require("node:fs"); | ||
@@ -2,0 +3,0 @@ /** |
+1
-0
@@ -0,1 +1,2 @@ | ||
| // re-export existsSync? | ||
| import { accessSync, constants } from "node:fs"; | ||
@@ -2,0 +3,0 @@ /** |
+22
-0
@@ -20,1 +20,23 @@ import type { Options } from "empathic/walk"; | ||
| export declare function any(names: string[], options?: Options): string | undefined; | ||
| /** | ||
| * Find a file by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for file matches. | ||
| * > A directory match with the same name will be ignored. | ||
| * | ||
| * @param name The file name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| export declare function file(name: string, options?: Options): string | undefined; | ||
| /** | ||
| * Find a directory by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for directory matches. | ||
| * > A file match with the same name will be ignored. | ||
| * | ||
| * @param name The directory name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| export declare function dir(name: string, options?: Options): string | undefined; |
+44
-2
| const { join } = require("node:path"); | ||
| const { existsSync } = require("node:fs"); | ||
| const { existsSync, statSync } = require("node:fs"); | ||
| const walk = require("empathic/walk"); | ||
@@ -37,4 +37,46 @@ /** | ||
| } | ||
| /** | ||
| * Find a file by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for file matches. | ||
| * > A directory match with the same name will be ignored. | ||
| * | ||
| * @param name The file name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| function file(name, options) { | ||
| let dir, tmp; | ||
| let start = options && options.cwd || ""; | ||
| for (dir of walk.up(start, options)) { | ||
| try { | ||
| tmp = join(dir, name); | ||
| if (statSync(tmp).isFile()) return tmp; | ||
| } catch {} | ||
| } | ||
| } | ||
| /** | ||
| * Find a directory by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for directory matches. | ||
| * > A file match with the same name will be ignored. | ||
| * | ||
| * @param name The directory name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| function dir(name, options) { | ||
| let dir, tmp; | ||
| let start = options && options.cwd || ""; | ||
| for (dir of walk.up(start, options)) { | ||
| try { | ||
| tmp = join(dir, name); | ||
| if (statSync(tmp).isDirectory()) return tmp; | ||
| } catch {} | ||
| } | ||
| } | ||
| exports.up = up; | ||
| exports.any = any; | ||
| exports.any = any; | ||
| exports.file = file; | ||
| exports.dir = dir; |
+41
-1
| import { join } from "node:path"; | ||
| import { existsSync } from "node:fs"; | ||
| import { existsSync, statSync } from "node:fs"; | ||
| import * as walk from "empathic/walk"; | ||
@@ -37,1 +37,41 @@ /** | ||
| } | ||
| /** | ||
| * Find a file by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for file matches. | ||
| * > A directory match with the same name will be ignored. | ||
| * | ||
| * @param name The file name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| export function file(name, options) { | ||
| let dir, tmp; | ||
| let start = options && options.cwd || ""; | ||
| for (dir of walk.up(start, options)) { | ||
| try { | ||
| tmp = join(dir, name); | ||
| if (statSync(tmp).isFile()) return tmp; | ||
| } catch {} | ||
| } | ||
| } | ||
| /** | ||
| * Find a directory by name, walking parent directories until found. | ||
| * | ||
| * > [NOTE] | ||
| * > This function only returns a value for directory matches. | ||
| * > A file match with the same name will be ignored. | ||
| * | ||
| * @param name The directory name to find. | ||
| * @returns The absolute path to the file, if found. | ||
| */ | ||
| export function dir(name, options) { | ||
| let dir, tmp; | ||
| let start = options && options.cwd || ""; | ||
| for (dir of walk.up(start, options)) { | ||
| try { | ||
| tmp = join(dir, name); | ||
| if (statSync(tmp).isDirectory()) return tmp; | ||
| } catch {} | ||
| } | ||
| } |
+1
-1
@@ -26,3 +26,3 @@ import * as find from "empathic/find"; | ||
| export declare function cache(name: string, options?: find.Options & { | ||
| create?: boolean | ||
| create?: boolean; | ||
| }): string | undefined; |
+2
-0
@@ -39,2 +39,4 @@ const { env } = require("node:process"); | ||
| let exists = existsSync(mods); | ||
| // exit cuz exists but not writable | ||
| // or cuz missing but parent not writable | ||
| if (!writable(exists ? mods : dir)) return; | ||
@@ -41,0 +43,0 @@ dir = join(mods, ".cache"); |
+1
-1
| { | ||
| "name": "empathic", | ||
| "version": "1.1.0", | ||
| "version": "2.0.0-next.0", | ||
| "repository": "lukeed/empathic", | ||
@@ -5,0 +5,0 @@ "description": "A set of small and fast Node.js utilities to understand your pathing needs.", |
+2
-0
@@ -39,2 +39,4 @@ import { env } from "node:process"; | ||
| let exists = existsSync(mods); | ||
| // exit cuz exists but not writable | ||
| // or cuz missing but parent not writable | ||
| if (!writable(exists ? mods : dir)) return; | ||
@@ -41,0 +43,0 @@ dir = join(mods, ".cache"); |
+3
-3
@@ -51,3 +51,3 @@ # empathic [](https://github.com/lukeed/empathic/actions?query=workflow%3ACI) [](https://licenses.dev/npm/empathic) | ||
| > [Source](/src/find.ts) · [Benchmark](/benchmarks.md#find) · **Size:** `321b` | ||
| > [Source](/src/find.ts) · [Benchmark](/benchmarks.md#find) · **Size:** `569b` | ||
@@ -70,5 +70,5 @@ Find files and/or directories by walking up parent directories. | ||
| > [Source](/src/walk.ts) · [Benchmark](/benchmarks.md#walk) · **Size:** `218b` | ||
| > [Source](/src/walk.ts) · [Benchmark](/benchmarks.md#walk) · **Size:** `208b` | ||
| Collect all the parent directories of a target. Controlled via `cwd` and `stop` options. | ||
| Collect all the parent directories of a target. Controlled via `cwd` and `last` options. | ||
@@ -75,0 +75,0 @@ |
+2
-0
@@ -17,2 +17,4 @@ const { createRequire } = require("node:module"); | ||
| try { | ||
| // NOTE: dirs need a trailing "/" OR filename. With "/" route, | ||
| // Node adds "noop.js" as main file, so just do "noop.js" anyway. | ||
| let r = root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js"); | ||
@@ -19,0 +21,0 @@ return createRequire(r).resolve(ident); |
+2
-0
@@ -17,2 +17,4 @@ import { createRequire } from "node:module"; | ||
| try { | ||
| // NOTE: dirs need a trailing "/" OR filename. With "/" route, | ||
| // Node adds "noop.js" as main file, so just do "noop.js" anyway. | ||
| let r = root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js"); | ||
@@ -19,0 +21,0 @@ return createRequire(r).resolve(ident); |
+6
-6
@@ -6,16 +6,16 @@ export type Options = { | ||
| */ | ||
| cwd?: string | ||
| cwd?: string; | ||
| /** | ||
| * The directory to stop at. | ||
| * The last directory to traverse. | ||
| * | ||
| * > [NOTE] | ||
| * > This directory WILL NOT be included in the results. | ||
| * > This directory is INCLUSIVE. | ||
| * | ||
| * @default <none> (continue to system root) | ||
| * @default "/" | ||
| */ | ||
| stop?: string | ||
| last?: string; | ||
| }; | ||
| /** | ||
| * Get all parent directories of {@link base}. | ||
| * Stops at {@link Options['stop']} else system root ("/"). | ||
| * Stops after {@link Options['last']} is processed. | ||
| * | ||
@@ -22,0 +22,0 @@ * @returns An array of absolute paths of all parent directories. |
+5
-5
@@ -5,3 +5,3 @@ const { dirname } = require("node:path"); | ||
| * Get all parent directories of {@link base}. | ||
| * Stops at {@link Options['stop']} else system root ("/"). | ||
| * Stops after {@link Options['last']} is processed. | ||
| * | ||
@@ -11,7 +11,7 @@ * @returns An array of absolute paths of all parent directories. | ||
| function up(base, options) { | ||
| let { stop, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd), root = !stop; | ||
| let { last, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd); | ||
| let root = absolute(last || "/", cwd); | ||
| let prev, arr = []; | ||
| if (stop) stop = absolute(stop, cwd); | ||
| while (root || tmp !== stop) { | ||
| while (prev !== root) { | ||
| arr.push(tmp); | ||
@@ -18,0 +18,0 @@ tmp = dirname(prev = tmp); |
+5
-5
@@ -5,3 +5,3 @@ import { dirname } from "node:path"; | ||
| * Get all parent directories of {@link base}. | ||
| * Stops at {@link Options['stop']} else system root ("/"). | ||
| * Stops after {@link Options['last']} is processed. | ||
| * | ||
@@ -11,7 +11,7 @@ * @returns An array of absolute paths of all parent directories. | ||
| export function up(base, options) { | ||
| let { stop, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd), root = !stop; | ||
| let { last, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd); | ||
| let root = absolute(last || "/", cwd); | ||
| let prev, arr = []; | ||
| if (stop) stop = absolute(stop, cwd); | ||
| while (root || tmp !== stop) { | ||
| while (prev !== root) { | ||
| arr.push(tmp); | ||
@@ -18,0 +18,0 @@ tmp = dirname(prev = tmp); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
21229
18.37%567
25.17%0
-100%2
100%