veryfront/fs

Runtime boundary

veryfront/fs uses the native process filesystem selected for Deno, Node, or Bun. It does not delegate to the runtime.get().fs adapter. Custom adapters configured with runtime.set() affect adapter-consuming APIs, not these compatibility functions.

veryfront/fs does not add a project-root sandbox, block .env or other secret-file names, or validate paths from untrusted input. Relative paths resolve from cwd(). Absolute paths and .. segments can reach any location that the runtime permits.

Runtime permissions remain the outer boundary. Hosted project secrets are supplied through request-owned environment data rather than .env files. Isolated Pages route ctx.fs is a separate, read-only, project-confined capability. Those protections do not change the contract of veryfront/fs.

Canonicalize a trusted root and candidate with realPath, then use validateLexicalPath from veryfront/security before reading a user-influenced path. Canonicalization follows existing symlinks before the containment check.

Path admission is not an operating-system sandbox. The trusted root must not be writable by untrusted or project code while a validated path is in use. Otherwise, concurrent filesystem changes can create a time-of-check/time-of-use race between validation and reading.

Import

TypeScript
import { exists, join, mkdir, readTextFile, resolve, writeTextFile } from "veryfront/fs";

Examples

File operations

TypeScript
import { exists, mkdir, readTextFile, writeTextFile } from "veryfront/fs"; const data = JSON.parse(await readTextFile("./data/config.json"));await mkdir("./output", { recursive: true });await writeTextFile("./output/result.json", JSON.stringify(data));

Path utilities

TypeScript
import { basename, dirname, extname, join, resolve } from "veryfront/fs"; const filePath = join("src", "pages", "index.tsx");const dir = dirname(filePath); // "src/pages"

Working directory

TypeScript
import { cwd, resolve } from "veryfront/fs"; const configPath = resolve(cwd(), "veryfront.config.ts");

Confine an untrusted path

TypeScript
import { cwd, readTextFile, realPath, resolve } from "veryfront/fs";import { validateLexicalPath } from "veryfront/security"; const publicFilesDir = await realPath(resolve(cwd(), "public-data")); export async function readPublicFile(requestedPath: string): Promise<string> {  const candidate = resolve(publicFilesDir, requestedPath);  const canonicalPath = await realPath(candidate);  const admitted = validateLexicalPath(canonicalPath, {    baseDir: publicFilesDir,    allowAbsolute: true,  });  if (!admitted.valid || !admitted.canonicalPath) {    throw new Error("Invalid path");  }  return await readTextFile(admitted.canonicalPath);}

Exports

Functions

NameDescriptionSource
basenameReturn the last path segment.source
createFileSystemCreate the runtime-native filesystem implementation.source
cwdReturn the current working directory.source
dirnameReturn the parent directory path.source
existsReturn false for a missing path and propagate every other filesystem error.source
extnameReturn the file extension for a path.source
isFileSnapshotChangedErrorReturn whether a value is a framework-created file snapshot change error.source
isNotFoundErrorsource
joinJoin and normalize path segments using their detected path flavor.source
lstatRead file metadata without following a terminal symbolic link.source
mkdirCreate a directory.source
readDirRead directory entries.source
readTextFileRead a file as text.source
realPathResolve a path to its canonical absolute form, following symlinks. Throws if the path does not exist. Useful for containment checks where a symlink could otherwise escape an intended directory.source
removeRemove a file or directory, rejecting when the path does not exist.source
resolveResolve path segments to an absolute, normalized path.source
writeTextFileWrite text to a file.source

Classes

NameDescriptionSource
FileSnapshotChangedErrorError raised when a file changes while a stable snapshot is being read.source

Types

NameDescriptionSource
FileSystemRuntime-neutral filesystem contract.source