@danielbayley/uproot
v0.1.3
Published
Reliable method to find the root path of your git repo, [p]npm/yarn package or app.
Downloads
9
Maintainers
Readme
Uproot
Reliable method to find the root path of your git repository,
[p]npm/yarn package, or app.
The algorithm is primarily reliant on git rev-parse --show-toplevel,
but will fallback on the following glob patterns to determine the root path:
| Path/pattern | Examples |
|:------------------------|:-------------------------------------------------|
| pnpm-*.yaml | pnpm-workspace.yaml, pnpm-lock.yaml |
| package.{yaml,json} | package.json, package.yaml |
| package-lock.json | |
| npm-shrinkwrap.json | |
| yarn.lock | |
| .git* | .gitignore, .gitattributes, .github/ |
| .npmrc | |
| .editorconfig | |
| LICEN[SC]E* | LICENSE.md |
| .vscode/ | |
| packages/ | |
| src/ | |
| public/ | |
Examples
import {root} from "@danielbayley/uproot"
console.log(root) // ~/path/to/project/rootimport {uproot} from "@danielbayley/uproot"
const cwd = import.meta.dirname
const root = await uproot({ cwd })You can override the above search patterns with the match option:
const root = await uproot({ match: ["tsconfig.json"] })or append an additional pattern to find:
import { uproot, match } from "@danielbayley/uproot"
match.push("tsconfig.json")
const root = await uproot({ match })Any additional options will be passed onto matchup:
import path from "node:path"
const object = await uproot({ cwd, parse: true })
const root = path.format(object)
console.log(root) // ~/path/to/project/rootInstall
pnpm install @danielbayley/matchup[!IMPORTANT] This package is ESM only, so must be
imported instead ofrequired, and depends on Node.js>=20.
Specify this requirement with engines and/or devEngines:
// package.json
"type": "module",
"engines": {
"node": ">=20"
},
"devEngines": {
"runtime": {
"name": "node",
"version": ">=20"
}
},