@dirwell/core

中文文档
0.0.10发布于 2026/10/16MITTypeScriptES Module构建来源已验证近 30 天下载 2383

Framework-neutral directory listing and static publication kernel.

原始使用文档
文档目录3 节
  1. Stable runtime validation
  2. Directory URLs
  3. Optional byte formatting

@dirwell/core

Framework-neutral filesystem, listing and static-publication SDK. Requires Node.js 22.12 or newer. For this quick start, install npm install @dirwell/[email protected] @dirwell/[email protected].

Core owns filesystem selection, safe navigation, public listing projection and static publication. It requires an explicit theme and does not load a default theme, image renderer, frontend framework, config loader or watcher. Runtime matching uses picomatch for globs and ignore for Git-style ignore files.

import { generateExplorer } from "@dirwell/core";
import { createPlainTheme } from "@dirwell/theme-plain";
await generateExplorer({
  sourceDir: "./files",
  outputDir: "./generated",
  theme: createPlainTheme(),
});
console.log("Generated ./generated");

Create files/note.txt, save the code as build.mjs and run node build.mjs. Serve the complete generated output over HTTP.

Stable controls: ignoreFiles defaults to []; explicit files must exist unless marked optional. Relative paths resolve from cwd, and patterns resolve from each file's directory unless baseDir is set. outputPolicy: "owned" protects nonempty unmarked destinations; explicit "replace" permits replacement. dryRun: true returns the selected paths and page plan without writing output. See the API guide.

generateExplorer publishes a dedicated output tree. listing independently plans HTML pages and data blocks; a synchronous callback can select plans per directory. Metadata rendering is an injected Node-side provider. createDirectoryService performs live, one-directory reads without writing a generated tree. With filters, selection still walks physical names to preserve descendant inclusion; it is not a constant-cost indexed database query.

The service rejects dot segments, absolute paths, backslashes, reserved root paths and paths outside the physical root. Symlink metadata retains existing declared-target behavior. Node-side entries are private inputs; use projectListingEntry before public serialization. Reads are not a transactional filesystem snapshot and are not qualified against adversarial concurrent directory replacement.

Stable also adds validated public entryData annotations and static fileHref mapping for existing CDN files. See the API guide for callback timing and public-data boundaries.

Stable runtime validation

JavaScript callers receive the same recognized-option checks as typed consumers: unknown keys, invalid booleans/enums and malformed sort, symlink or listing plans fail before publication writes. Errors name the complete option path and suggest the closest known key. For example, exlcude is rejected with a suggestion for exclude; mirror: "false" is rejected rather than treated as truthy. A listing-policy callback runs after directory inspection, and its returned plan is validated before output replacement.

Custom theme objects may carry extra private fields. Their required name/render and known hooks must match the theme contract. Metadata and annotation callbacks remain trusted executable host code and are awaited where the public contract is asynchronous. These controls are included in 0.0.1.

The 0.0.x API may evolve. Pin your qualified version and upgrade the official family together. See support and verification for host, browser and device boundaries.

Directory URLs

Version 0.0.3 uses Core routing: { directoryUrls: "explicit" } by default for every theme. Choose slash for directory-index hosts or clean for a qualified extensionless host. Themes do not rewrite links. Existing source homepages and download names are preserved; output conflicts fail. CLI config puts routing at the top level, and --directory-urls overrides it. See directory URL guidance for output placement, host requirements, native Plain file navigation and migration.

Optional byte formatting

Themes receive raw byte counts. Use the browser-safe formatter only when useful:

import { formatBytes, sizeValue } from "@dirwell/core/format";

formatBytes(1536); // "1.5 KiB"
formatBytes(1536, { units: "decimal" }); // "1.54 kB"
formatBytes(1536, { units: "bytes" }); // "1,536 B"

formatBytes accepts units, locale (default en-US) and an optional maximumFractionDigits from 0 to 6. Converted values otherwise use up to three significant digits. Bytes remain exact integers. Invalid or unsafe byte counts throw; handle absent values before formatting.

sizeValue(entry) selects a regular file's bytes or an allowed symlink target's file bytes. It returns null for unavailable targets and directories. sizeValue(entry, "entry") selects the entry's own bytes, including a link's own size. It never calculates directory contents. Independent themes may ignore both helpers and format the original fields themselves.

Size sorting is explicit: sort.field: "size" compares entry sizes; "targetSize" compares target-file sizes for links. Missing/non-comparable values sort after numeric values in either direction, subject to folders-first.

版本与发布记录

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

版本发布日期距今
0.0.10latest2026/10/1628 天前
0.0.92026/10/1628 天前
0.0.82026/10/1628 天前
0.0.72026/10/1628 天前
0.0.62026/10/1628 天前
0.0.52026/10/1628 天前

其他发布通道:alpha → 0.0.1-alpha.1。

关于 @dirwell/core 的常见问题

@dirwell/core 是什么?

Framework-neutral directory listing and static publication kernel.

如何安装 @dirwell/core?

在项目目录运行 npm install @dirwell/core,或使用 pnpm add / yarn add / bun add。

@dirwell/core 支持 TypeScript 吗?

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

@dirwell/core 支持 ESM 还是 CommonJS?

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

@dirwell/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dirwell/core 可以商用吗?

@dirwell/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dirwell/core 的下载量有多少?

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

@dirwell/core 还在维护吗?

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