npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@monochromatic-dev/module-fs-path

v0.2.0

Published

POSIX path operations and upward root discovery (findRoot with marker values: mise monorepo, Git repository, pnpm workspace, named package, file, or directory) for Node, Bun, and browsers over the origin private file system, with an in-memory filesystem f

Downloads

57

Readme

module-fs-path

POSIX path operations and repository-root discovery that run under Node, Bun, and browsers, plus Node-only directory and file helpers. The package was extracted from @monochromatic-dev/module-es's path/ submodule so consumers that need only filesystem and path utilities can depend on it directly.

Entries

. (platform-neutral)

Path operations:

  • dirname, join, resolve, normalize, isAbsolute, sep: POSIX path operations. join and resolve take one array of segments.
  • trimLeadingSlash, trimTrailingSlash: strip one leading or trailing / unless the path is /.

Root discovery, one walker driven by marker values:

  • findRoot({ marker, cwd?, fs? }): nearest ancestor of cwd (itself included) that marker accepts, spelled as the caller spelled cwd. cwd defaults to the process working directory, or / where no process exists; fs defaults to the runtime adapter. Rejects with RootNotFoundError, which carries marker (the marker name) and startDir.
  • findRootCached({ marker, cwd? }): memoised variant over the runtime adapter, keyed by marker name and start directory resolved at call time. Concurrent first callers share one walk; a rejection stays memoised for its key.
  • MISE_MONOREPO: nearest ancestor whose mise.toml has a [monorepo] table header on its own line (CRLF endings, trailing spaces, and a trailing comment tolerated; a header quoted inside a value refused).
  • GIT_REPOSITORY: nearest ancestor with a structurally usable .git directory or gitfile (HEAD, objects, refs, relative targets, and linked-worktree commondir pointers are validated; invalid nearer markers are skipped).
  • PNPM_WORKSPACE: nearest ancestor holding a pnpm-workspace.yaml file.
  • packageNamed(name): nearest ancestor whose package.json declares that name, anchoring a package on its own root in source and built modes; an unparsable or differently named manifest is walked past.
  • fileNamed(name), directoryNamed(name): nearest ancestor holding a regular file, or a directory, with that name.
  • RootMarker: { name, matches({ dir, fs }) }. A custom marker is one object literal; its name must differ from the shipped ones because it keys the memo.
  • createMemoryRootFilesystem({ files, directories, links }): a RootFilesystem over a tree held in memory. Every ancestor of a declared path is a directory; exists and readSymbolicLink look at the entry itself, the other probes look through links.
  • RootFilesystem, ABSENT: the seam the adapters fill (readTextFile, readSymbolicLink, exists, isDirectory, isFile) and the sentinel readTextFile and readSymbolicLink return for an absent path.

./node (Node and Bun only)

  • ensureDir, ensureFile, ensurePath: create the path when missing (parents included) and verify owner read and write access when it exists, granting the owner bits when the mode denies them. ensurePath picks file or directory by whether the path has an extension.
  • emptyDir, emptyFile, emptyPath, removeEmptyFilesInDir: clear a directory's entries, truncate a file (a ?query suffix is stripped first), dispatch by extension, or delete files that are empty after trimming.

Usage

import {
  findRoot,
  findRootCached,
  GIT_REPOSITORY,
  join,
  MISE_MONOREPO,
  packageNamed,
} from '@monochromatic-dev/module-fs-path';

const repoRoot = await findRootCached({ marker: MISE_MONOREPO, },);
const gitRoot = await findRoot({ cwd: import.meta.dirname, marker: GIT_REPOSITORY, },);
const packageRoot = await findRootCached({
  cwd: import.meta.dirname,
  marker: packageNamed('@scope/pkg',),
},);
const manifest = join([repoRoot, 'package.json',],);

A custom marker, and a test that walks a tree without touching a disk:

import {
  createMemoryRootFilesystem,
  findRoot,
  type RootMarker,
} from '@monochromatic-dev/module-fs-path';

const QUARANTINE_WARD: RootMarker = {
  name: 'quarantine ward',
  matches: async ({ dir, fs, },) => await fs.isDirectory(`${dir}/quarantine`,),
};

const fs = createMemoryRootFilesystem({
  directories: ['/registry/quarantine', '/registry/north/3',],
},);
await findRoot({ cwd: '/registry/north/3', fs, marker: QUARANTINE_WARD, },); // '/registry'
import {
  emptyDir,
  ensureDir,
} from '@monochromatic-dev/module-fs-path/node';

await ensureDir('dist',);
await emptyDir('dist',);

Runtime support

The backends are chosen when the package is resolved, not at runtime. package.json imports maps two private aliases by export condition:

  • #posix-path: node:path/posix under the node condition, a pure-JS implementation with the same semantics under default.
  • #root-filesystem: node:fs/promises under the node condition; under default, the origin private file system through navigator.storage.getDirectory() where the platform grants it, and otherwise an empty backend that finds no marker, so the finder rejects.

Node and Bun resolve the node condition (Bun's order is bun, node-addons, node, require, import, default), so they get dist/final/node/index.mjs. Browsers and bundlers targeting them resolve default and get dist/final/neutral/index.mjs, which names no node: module. Neither build contains a dynamic import(); a unit test reads every built chunk and rejects leaks in either direction, and a Playwright test drives the neutral build over OPFS in Chromium and Firefox (headless WebKit refuses OPFS writes and reports itself skipped).

In browsers, paths are absolute POSIX strings rooted at the OPFS root: /repo/mise.toml is the file mise.toml in the directory repo under navigator.storage.getDirectory(). Marker files must exist there to be found.

A Node consumer whose bundler resolves the default condition gets the neutral build: path operations work, root discovery finds no filesystem and rejects. Point the bundler at the node condition to keep node:fs.

Logging

Diagnostics go through @monochromatic-dev/module-logger, inlined into both builds under the tags rootDiscovery (one line per walk), rootFilesystem, rootMarker, path/ensure, and path/empty. The inlined logger builds its default sinks on first use; a consumer that also installs @monochromatic-dev/module-logger runs a second, independent logger instance.

Source files

  • src/index.ts: platform-neutral entry.
  • src/node.ts: Node-only entry.
  • src/posix-path.node.ts, src/posix-path.neutral.ts: the #posix-path backends.
  • src/root-filesystem-contract.ts, src/root-filesystem.node.ts, src/root-filesystem.neutral.ts, src/memory-root-filesystem.ts: the RootFilesystem seam and its three adapters.
  • src/root-discovery.ts: findRoot, findRootCached, RootNotFoundError.
  • src/root-marker-contract.ts, src/root-marker.ts, src/git-marker.ts: the RootMarker type, the shipped markers, and Git administrative marker validation.
  • src/ensure.ts, src/empty.ts, src/trim.ts: the remaining helpers.

Decisions: DECISIONS.md.