0.1.2 • Published 8 months ago

@danielbayley/uproot v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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/patternExamples
pnpm-*.yamlpnpm-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 >=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

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago