@e2b/dockerfile-utils

中文文档
0.1.1发布于 2026/10/13Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 241.4万

E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby

原始使用文档

@e2b/dockerfile-utils

Dockerfile parser and shell lexer ported from BuildKit and a .dockerignore matcher ported from moby/patternmatcher, with no runtime dependencies. Used by the E2B SDK to implement Template.fromDockerfile and to filter the build context.

import { parseDockerfileAst, ShellLex } from '@e2b/dockerfile-utils'

const ast = parseDockerfileAst(`
FROM node:24 AS build
ENV KEY="a  b" OTHER=c
RUN <<EOF
npm ci
npm run build
EOF
`)

for (const instruction of ast.instructions) {
  console.log(instruction.name, instruction.flags, instruction.args)
}

const lex = new ShellLex(ast.escapeToken)
lex.processWords('KEY="a  b" OTHER=c') // ['KEY=a  b', 'OTHER=c']

parseDockerfileAst handles parser directives (# escape=, # syntax=), comments (including inside line continuations), builder flags, JSON/exec forms and heredocs, and reports line numbers and warnings. ShellLex splits and unquotes words the way BuildKit does, preserving $VAR / ${VAR:-default} references for later expansion.

import { PatternMatcher } from '@e2b/dockerfile-utils'

const matcher = new PatternMatcher(['node_modules', '*.log', '!keep.log'])
matcher.matches('node_modules/pkg/index.js') // true
matcher.matches('keep.log') // false

PatternMatcher applies .dockerignore semantics to slash-separated paths relative to the context root: a pattern matching a directory excludes everything under it, and ! patterns re-include paths (the last matching pattern wins). An invalid pattern throws a plain Error.

版本与发布记录

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

版本发布日期距今
0.1.1latest2026/10/131 个月前
0.1.02026/10/091 个月前
0.0.02026/10/091 个月前
0.0.0-stage2026/10/091 个月前

关于 @e2b/dockerfile-utils 的常见问题

@e2b/dockerfile-utils 是什么?

E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby

如何安装 @e2b/dockerfile-utils?

在项目目录运行 npm install @e2b/dockerfile-utils,或使用 pnpm add / yarn add / bun add。

@e2b/dockerfile-utils 支持 TypeScript 吗?

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

@e2b/dockerfile-utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@e2b/dockerfile-utils 需要什么版本的 Node.js?

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

@e2b/dockerfile-utils 可以商用吗?

@e2b/dockerfile-utils 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@e2b/dockerfile-utils 的下载量有多少?

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

@e2b/dockerfile-utils 还在维护吗?

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