Find the first path matching a glob pattern, walking up from a given directory.
import fs from "node:fs/promises"
import {matchup} from "@danielbayley/matchup"
const cwd = import.meta.dirname
const metadata = await matchup("package.*", { cwd }) // package.json
.then(fs.readFile)
.then(JSON.parse)
.catch(console.error)
console.log(metadata.type) // module| Option | Default | Description |
|---|---|---|
cwd |
import.meta.dirname |
Search starting point. |
ignore |
["node_modules"] |
ignore paths containing these patterns. |
parse |
return a node:path object. |
|
max |
10 |
Maximum upward traversal depth. |
symlinks |
false will not match symbolic links. |
pnpm install @danielbayley/matchupImportant
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: