Skip to content

Find the first path matching a glob pattern, walking up from a given directory.

License

Notifications You must be signed in to change notification settings

danielbayley/matchup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



Matchup

Find the first path matching a glob pattern, walking up from a given directory.

Example

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

Options

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.

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