ast-grep language support for Dockerfile, using tree-sitter-containerfile.
npm install ast-grep-lang-dockerfile
# or
bun add ast-grep-lang-dockerfileAdd to your sgconfig.yml:
customLanguages:
dockerfile:
libraryPath: node_modules/ast-grep-lang-dockerfile/parser.so
extensions: [Dockerfile, .dockerfile]
languageSymbol: tree_sitter_containerfile
expandoChar: $Then use ast-grep as usual:
sg run -l dockerfile -p 'FROM $IMG' .import dockerfile from 'ast-grep-lang-dockerfile'
import { registerDynamicLanguage, parse } from '@ast-grep/napi'
registerDynamicLanguage({ dockerfile })
const sg = parse('dockerfile', `FROM node:18
RUN npm install
CMD ["node", "app.js"]`)
console.log(sg.root().kind()) // source_fileIf no prebuild is available for your platform, the package will attempt to build the parser from source during installation. This requires tree-sitter-cli:
npm install tree-sitter-cli --save-dev