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/matchup
Important
This package is ESM only, so must be import
ed instead of require
d,
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"
}
},