@alwith/module-fs

中文文档
0.6.2发布于 2026/11/03SEE LICENSE IN LICENSETypeScriptES Module零依赖构建来源已验证近 30 天下载 2009

A transport-independent filesystem contract and operation coordinator. The core has no React, DOM or Tauri dependency. Adapters enforce permissions; JavaScript capabilities only describe the UI's available actions.

原始使用文档
文档目录4 节
  1. Use
  2. Contract
  3. Native distribution
  4. Develop

@alwith/module-fs

A transport-independent filesystem contract and operation coordinator. The core has no React, DOM or Tauri dependency. Adapters enforce permissions; JavaScript capabilities only describe the UI's available actions.

Use

import { createFileSystem } from "@alwith/module-fs"
import { createMemoryAdapter } from "@alwith/module-fs/testing"
const fs = createFileSystem({
  adapter: createMemoryAdapter({ "/project/readme.md": "# Hello" }),
  reportError: error => console.error(error)
})
const stop = fs.subscribe(event => console.log(event))
await fs.writeFile("/project/readme.md", new TextEncoder().encode("# Changed"), { mode: "replace" })
stop()

Contract

  • FsAdapter implements stat, byte reads/writes, directory listing, mkdir, move, copy and remove. stat returns null only for an absent path; all other errors propagate.
  • WriteOptions.mode distinguishes create-only, replace-existing and upsert. expectedVersion rejects stale saves. Adapters must enforce both, not treat them as advisory.
  • createFileSystem serializes mutations and transaction calls in one instance. A transaction receives a non-queuing writer; never call the outer service's mutation methods from inside a transaction or guard.
  • beforeMutation can cancel move/remove/copy/mkdir. Editor controllers use it to protect unsaved deleted documents. A cancellation rejects with MutationCancelledError. A guard may return { allow, release } to hold an operation lease until commit/failure; releases always run and cannot change the disk result.
  • subscribe reports committed operations. Native/watch observations have a separate source: "watch"; they are invalidations, not proof a particular UI operation committed. reportError must not throw.
  • watch is optional. Hosts own and release the returned subscription. No polling or network access is started by importing the package.
  • Path helpers understand POSIX, Windows drive and UNC roots. joinPath accepts a single filename and rejects traversal. Helpers are lexical; adapters still must enforce canonical/symlink boundaries. Path identity is case-sensitive; native adapters must provide consistent canonical identities.

Native distribution

Native access is the Tauri plugin alwith-fs (crates.io); the implementation is a private library shipped in this package under native/, staged by the application.

.plugin(alwith_fs::init(alwith_fs::Config { development_directory, ..Default::default() }))

Grant alwith-fs:default (open, list, stat, read, watch) and, as needed, alwith-fs:workspace-write, alwith-fs:patches, alwith-fs:git (branch, file statuses, upstream sync summary, recent commits and changed files of an opened workspace, read with gix in the library, no system git), alwith-fs:exec (workspace_exec_bash: run a typed shell command in an opened workspace with the user's login shell, killed after five minutes; not sandboxed) and alwith-fs:capability in src-tauri/capabilities/*.json. @alwith/module-fs/commands holds the generated typed commands and the workspace:change event; @alwith/module-fs/tauri builds an FsAdapter over them from a root returned by commands.workspaceOpen.

Applications that synchronize files pass a Coordinator in Config: every mutation, with its canonical write and removed paths, runs inside it one at a time; reads never wait. Rust code uses FileSystem, watch, validate_patch_path, apply_patches, the Git readers current_branch, file_statuses, sync_status, recent_commits and changed_files (blocking) and exec_bash (async), which also work without a webview after alwith_native_client::configure_host or ALWITH_NATIVE_DIRECTORY, and shares authorization and ordering through app.state::<Workspace>() (open, root, lock).

The library limits reads/writes to 16 MiB, preserves binary bytes, checks versions, uses same-directory temporary writes, rejects root mutation and mutation of terminal symbolic links, and refuses existing copy/move destinations. A recursive copy is staged before exposing the destination. Patches are validated in full (paths, symlinks, .git, hunks, size) before the first change and applied with Git without touching the index. Version checks do not provide an OS-wide transaction against arbitrary external writers. Watch errors are reported explicitly.

Develop

From the repository root: bun run --cwd packages/fs build and bun test packages/fs/src; in rust/, cargo test (bindings current; UPDATE_BINDINGS=1 regenerates them) and, with the library built, ALWITH_NATIVE_DIRECTORY=<target/debug> cargo test -- --ignored. Publish authorization is separate.

版本与发布记录

@alwith/module-fs 共发布 8 个版本,首次发布于 2026/10/22;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.2latest2026/11/034 天前
0.5.22026/11/035 天前
0.5.12026/10/308 天前
0.5.02026/10/308 天前
0.1.0-rc.10next2026/10/2513 天前
0.1.0-rc.92026/10/2513 天前

关于 @alwith/module-fs 的常见问题

@alwith/module-fs 是什么?

A transport-independent filesystem contract and operation coordinator. The core has no React, DOM or Tauri dependency. Adapters enforce permissions; JavaScript capabilities only describe the UI's available actions.

如何安装 @alwith/module-fs?

在项目目录运行 npm install @alwith/module-fs,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@tauri-apps/api(^3.0.0-alpha.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alwith/module-fs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alwith/module-fs 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alwith/module-fs 可以商用吗?

@alwith/module-fs 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@alwith/module-fs 的下载量有多少?

根据 npm 官方下载统计,@alwith/module-fs 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,009 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alwith/module-fs 还在维护吗?

最新版本 0.6.2 发布于 2026/11/03(4 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/10/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。