From 1438905a0336d66350702f8d9575e96e2f606ccf Mon Sep 17 00:00:00 2001 From: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> Date: Mon, 15 Jun 2026 15:05:36 -0600 Subject: [PATCH] feat: add cwd to replacements --- docs/modules/cwd.md | 26 ++++++++++++++++++++++++++ manifests/preferred.json | 6 ++++++ 2 files changed, 32 insertions(+) create mode 100644 docs/modules/cwd.md diff --git a/docs/modules/cwd.md b/docs/modules/cwd.md new file mode 100644 index 0000000..c750a32 --- /dev/null +++ b/docs/modules/cwd.md @@ -0,0 +1,26 @@ +--- +description: Modern alternatives to the cwd package for resolving project-relative paths +--- + +# Replacements for `cwd` + +## `empathic` + +[`empathic`](https://github.com/lukeed/empathic) provides a more generic way to find files and directories upwards. + +[`cwd`](https://github.com/jonschlinkert/cwd) is not `process.cwd()`. It finds the nearest `package.json` and returns an absolute path anchored to that package root. Unlike [`pkg-dir`](./pkg-dir.md), which returns the package root directory, `cwd` returns a resolved path relative to that root. + +The main difference is that `empathic` is _synchronous_, so you should no longer `await` the result. + +Example: + +```ts +import { resolve, dirname } from 'node:path' // [!code ++] +import * as pkg from 'empathic/package' // [!code ++] +import cwd from 'cwd' // [!code --] + +const filepath = resolve('one/two.js') // [!code ++] +const pkgPath = pkg.up({ cwd: filepath }) // [!code ++] +const result = cwd('one/two.js') // [!code --] +const result = pkgPath ? resolve(dirname(pkgPath), filepath) : filepath // [!code ++] +``` diff --git a/manifests/preferred.json b/manifests/preferred.json index 5ffd675..4b266e9 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -186,6 +186,12 @@ "replacements": ["node:crypto", "crypto", "Bun.CryptoHasher"], "url": {"type": "e18e", "id": "crypto-js"} }, + "cwd": { + "type": "module", + "moduleName": "cwd", + "replacements": ["empathic"], + "url": {"type": "e18e", "id": "cwd"} + }, "debug": { "type": "module", "moduleName": "debug",