Skip to content

danielbayley/uproot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/root
import {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/root

Install

pnpm install @danielbayley/matchup

Important

This package is ESM only, so must be imported instead of required, 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"
  }
},

License

MIT © Daniel Bayley