@binclusive/tree-sitter-swift-wasm

中文文档
0.1.0发布于 2026/07/26MITTypeScriptES Module零依赖近 30 天下载 4418

The tree-sitter Swift grammar (alex-pinkus/tree-sitter-swift 0.7.3) vendored as a checksum-pinned wasm asset, resolvable by package name.

原始使用文档
文档目录5 节
  1. Install
  2. Use
  3. Exports
  4. Publishing
  5. Licence

@binclusive/tree-sitter-swift-wasm

The tree-sitter Swift grammar vendored as a checksum-pinned .wasm asset, with zero runtime dependencies.

Upstream publishes the wasm only as a GitHub release asset, so there is nothing on npm to depend on. This package republishes the asset unmodified, which lets a consumer resolve the grammar by package name through ordinary module resolution instead of standing up a second acquisition mechanism for one language. Full provenance, the reproduce command and the upgrade procedure are in PROVENANCE.md.

Install

Pin it exactly. The grammar version decides what the scanner can see, so it is a correctness input, not a compatible-upgrade axis:

pnpm add -E @binclusive/tree-sitter-swift-wasm

Use

import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import {
  SWIFT_GRAMMAR,
  SWIFT_GRAMMAR_WASM_SPECIFIER,
} from "@binclusive/tree-sitter-swift-wasm";
import { Language, Parser } from "web-tree-sitter";

const wasmPath = fileURLToPath(import.meta.resolve(SWIFT_GRAMMAR_WASM_SPECIFIER));

// Verify before you parse: a wrong or truncated grammar under-parses SILENTLY, so it
// surfaces as missing findings rather than an error.
const bytes = await readFile(wasmPath);
const digest = Buffer.from(
  await crypto.subtle.digest("SHA-256", bytes),
).toString("hex");
if (digest !== SWIFT_GRAMMAR.sha256) throw new Error("Swift grammar digest mismatch");

await Parser.init();
const parser = new Parser();
parser.setLanguage(await Language.load(wasmPath));

import.meta.resolve is the load-bearing detail: resolution runs through this package's exports map by name. A directory join off the consumer's import.meta.url is the exact mechanism behind #3120 — it resolves on the machine that built the image and nowhere else.

Exports

SpecifierWhat
@binclusive/tree-sitter-swift-wasmSWIFT_GRAMMAR (upstream repo, release tag, asset name, byte length, SHA-256, ABI, licence) and SWIFT_GRAMMAR_WASM_SPECIFIER
@binclusive/tree-sitter-swift-wasm/tree-sitter-swift.wasmthe grammar bytes

The entry point is constants only — no node: imports, no runtime dependency — so it loads on Node, Workers and the browser alike.

Publishing

The workspace tests verify the committed bytes; verify:tarball verifies the artifact a customer actually receives. It packs, installs the tarball into a throwaway directory outside this repo, resolves the wasm by package name from that install and parses Swift with it — so a broken files list or publishConfig exports map fails here rather than at a consumer:

pnpm --filter @binclusive/tree-sitter-swift-wasm verify:tarball

Then publish the tarball (this workspace publishes packed tarballs rather than running pnpm publish in place):

cd packages/tree-sitter-swift-wasm
pnpm build
pnpm pack
npm publish --access public binclusive-tree-sitter-swift-wasm-<version>.tgz

A freshly published version is not installable in this workspace for about a day — the minimumReleaseAge supply-chain gate rejects it — so publish before the consumer bump that needs it, not alongside.

Licence

The grammar is MIT, © 2021 alex-pinkus. The upstream notice ships verbatim in LICENSE and applies to the vendored wasm, which is the unmodified upstream artifact. This package adds no separately-licensed code.

版本与发布记录

@binclusive/tree-sitter-swift-wasm 共发布 1 个版本,首次发布于 2026/07/26;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/07/263 个月前

关于 @binclusive/tree-sitter-swift-wasm 的常见问题

@binclusive/tree-sitter-swift-wasm 是什么?

The tree-sitter Swift grammar (alex-pinkus/tree-sitter-swift 0.7.3) vendored as a checksum-pinned wasm asset, resolvable by package name.

如何安装 @binclusive/tree-sitter-swift-wasm?

在项目目录运行 npm install @binclusive/tree-sitter-swift-wasm,或使用 pnpm add / yarn add / bun add。

@binclusive/tree-sitter-swift-wasm 支持 TypeScript 吗?

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

@binclusive/tree-sitter-swift-wasm 支持 ESM 还是 CommonJS?

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

@binclusive/tree-sitter-swift-wasm 需要什么版本的 Node.js?

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

@binclusive/tree-sitter-swift-wasm 可以商用吗?

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

@binclusive/tree-sitter-swift-wasm 的下载量有多少?

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

@binclusive/tree-sitter-swift-wasm 还在维护吗?

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