Repository navigation
Replace the grammar submodule with packages/liquid-tm-grammar - #1461
Merged
Merged
Conversation
The VS Code extension took its Liquid TextMate grammar from a git submodule of Shopify/liquid-tm-grammar at df3989f. A plain copy in the workspace removes the submodule step from installs, builds and CI, and lets the grammar change in the same pull request as the extension. packages/liquid-tm-grammar holds every file of Shopify/liquid-tm-grammar at df3989f except .github/ and yarn.lock, which stay in that repository. Its package.json only adds "private": true, so the package is versioned but never published. Shopify/liquid-tm-grammar main is 5 commits ahead of df3989f, and they change only its .github/workflows/ci.yml. The extension's webpack build copies the grammar's JSON into dist/grammars, as it does for the theme-check configs, and package.json contributes the grammars from there. build:syntax regenerates the JSON from the YAML first. The grammar is a workspace dependency of the extension, so a grammar release also patches the extension. CI runs the grammar's baseline tests and fails when the committed JSON does not match its YAML. The checkouts no longer fetch submodules. Adding the first new package to the lockfile makes pnpm 11 write the optional supports-color peer of debug into existing entries. Any new dependency does the same.
Shopify/liquid-tm-grammar stays as a copy of packages/liquid-tm-grammar, because GitHub Linguist highlights Liquid with it. After a release that changes the grammar's version reaches GitHub main, the person who merged it runs the script from a clone of Shopify/theme-tools. The script copies the files of a theme-tools commit (HEAD by default), not the working tree, into a clone of Shopify/liquid-tm-grammar. It keeps that repository's .github/ and yarn.lock and leaves itself out. It commits with a link to the theme-tools commit and opens a pull request with gh. A real run stops when the commit is not on GitHub main. --dry-run prints the change, the commit message and the pull request, and pushes nothing. It needs only git, tar, node and gh.
The guide still told contributors to clone theme-check-vscode with its submodules, to use yarn, and to work in its syntaxes folder. None of that is true now that the grammar is a workspace package here. It now says where the grammar's source is, and gives the setup, the F5 loop and the baseline tests with the workspace's pnpm commands. The copy script carries this file to Shopify/liquid-tm-grammar, so it uses absolute links and reads true in both repositories.
The extension used to read the grammar's JSON in the submodule, so the YAML watcher and a window reload were enough. It now reads a copy in dist/grammars, and the F5 task only copied the committed JSON. A YAML change needed a separate watcher and a restart to show up. The vscode dev task now builds the grammar first, so a restart of the debug session picks up a YAML change. CONTRIBUTING.md drops the watcher step.
Git can't remove an initialized submodule's folder when it checks out a commit without it, so older clones keep packages/vscode-extension/syntaxes. Without the old .vscodeignore entry, pnpm package shipped it in the .vsix, and git add -A added it back as an embedded repository. Both files ignore it again.
The grammar's tests asked for the latest versions of both, so a lockfile refresh could move them to a release that the minimum release age policy rejects. They now ask for the versions the lockfile already has.
Shopify/liquid-tm-grammar is now a copy of packages/liquid-tm-grammar, and nothing updates it on its own. The release steps now say when to run the copy script.
Shopify/theme-tools is now a read-only mirror that takes issues and no pull requests, and this guide is copied to Shopify/liquid-tm-grammar. It now points readers to the theme-tools issues, keeps the local build and test steps, and adds the changeset step that releases a grammar change.
Shopify/liquid-tm-grammar now exists for GitHub Linguist, which reads the built grammars and the license. A full copy of the package kept a second build, test suite, CI workflow and lockfile there, which nothing uses and which drift from this package. The copy script now replaces that repository's files with grammars/, LICENSE.md, ThirdPartyNotices.txt and a README that points to this package and its issues. The grammar files keep their paths, so Linguist's grammars.yml entry still matches.
The package's repository, bugs and homepage fields and its README logo pointed at Shopify/liquid-tm-grammar, which no longer holds the source or the images. They now point at this package in Shopify/theme-tools.
The package kept the setup of its old repository: a JavaScript build, mocha and chai tests with copyfiles to accept baselines, js-yaml, and its own CI step. It now follows this workspace's conventions. - src/build.ts builds grammars/*.tmLanguage.json from the YAML with the yaml package, which parses these files the same way. It rejects on an invalid file, and the build command then exits with 1. - src/grammar.spec.ts runs each case in tests/cases against its baseline with toMatchFileSnapshot, so `vitest -u` accepts new baselines. The baselines are byte for byte the ones from mocha. - src/build.spec.ts checks that the committed JSON matches the YAML and that an invalid file fails the build. pnpm test runs both, so the two grammar steps in CI are gone. - src/watch.ts watches the whole package, so a change to liquid/*.yml rebuilds too, and reads the tag and object lists on every build. The built grammars don't change. Adding @types/node to the package lets pnpm resolve the root's optional @types/node peers to 22.18.8, the version the other packages use, instead of 26.1.1.
Shopify/liquid-tm-grammar takes no pull requests from forks, like this repository, and its .github/ holds the workflow and templates that say so. The copy now keeps that folder and replaces everything else.
charlespwd
commented
Dec 1, 2026
charlespwd
commented
Dec 1, 2026
The logo came from the grammar's own repository, and this package's README doesn't need one. The README now starts with a plain title.
The build and the watcher ran their TypeScript through ts-node with --transpile-only, which skips type checking. They now follow the other packages: build:ts compiles src/ to dist/ with tsc, and build and dev run the compiled JavaScript with node.
charlespwd
force-pushed
the
cpc-29/liquid-tm-grammar-package
branch
from
December 1, 2026 20:03
3e45587 to
d927308
Compare
js-yaml merged a `<<: *anchor` mapping, and the yaml package keeps it as a literal `<<` key unless asked. No source uses one today, so the built grammars don't change.
The copy accepted any commit on main, so a run from a stale main could replace Shopify/liquid-tm-grammar's grammar with an older one. The README there names the copied version, and a real run now stops when that version is newer than the one it would copy. A dry run warns.
…mar-package # Conflicts: # pnpm-lock.yaml
EvilGenius13
approved these changes
Dec 1, 2026
EvilGenius13
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fixing this up @charlespwd! I also pulled down the branch, made sure the build worked, and also ran the dev server along with some tests to see syntax highlighting and other checks. Everything worked on my end!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR
The Liquid TextMate grammar moves from the
packages/vscode-extension/syntaxessubmodule into the workspace aspackages/liquid-tm-grammar, with a TypeScript build and Vitest tests. The VS Code extension bundles it from there. Shopify/liquid-tm-grammar becomes a copy of the built grammar for GitHub Linguist, which a script updates after a release.Problem
The extension takes its grammar from a git submodule of Shopify/liquid-tm-grammar. Every clone, install and CI checkout has to fetch it, a grammar change needs a pull request in each repository, and the grammar's tests don't run here. That repository also keeps a build, tests, CI and a yarn lockfile of its own.
Solution
packages/vscode-extension/syntaxespackages/liquid-tm-grammar.vsixsyntaxes/grammars/*.tmLanguage.jsondist/grammars/*.tmLanguage.json, same bytespnpm testThe package
packages/liquid-tm-grammarholds the YAML sources, test cases and baselines of Shopify/liquid-tm-grammar atdf3989f, the commit the submodule points at. The built grammars are the same bytes.src/build.tsbuildsgrammars/*.tmLanguage.jsonfrom the YAML, and fails on an invalid YAML file.src/grammar.spec.tstokenizes each file intests/casesand compares the result with its baseline intests/baselineswithtoMatchFileSnapshot.pnpm vitest run packages/liquid-tm-grammar -uaccepts new baselines.src/build.spec.tschecks that the committed JSON matches its YAML, and that an invalid file fails the build.pnpm --filter @shopify/liquid-tm-grammar devrebuilds the grammar when any of its YAML files changes, includingliquid/*.yml.CONTRIBUTING.mdgives the F5 loop, the tests and the changeset step, and sends bug reports to the theme-tools issues.The extension
dist/grammars, as it does for the theme-check configs, andpackage.jsoncontributes the grammars from there.build:cibuilds the grammar first..vscode/tasks.jsonbuilds the grammar before the extension, so a YAML change shows up after Restart Debugging..gitmodules, the gitlink,scripts/fetch-syntaxes.sh, the install hooks that ran it, andsubmodules: truein the workflows are gone.packages/vscode-extension/syntaxes/on disk in a clone that had the submodule checked out..vscodeignoreand the extension's.gitignoreskip it, so it stays out of the.vsixand out ofgit add -A.rm -rf packages/vscode-extension/syntaxesremoves it.Shopify/liquid-tm-grammar
GitHub Linguist highlights Liquid with the grammar files in that repository: its
grammars.ymlreadstext.html.liquidandliquid.injectionfromvendor/grammars/liquid-tm-grammar.packages/liquid-tm-grammar/scripts/copy-to-liquid-tm-grammar.shcopiesgrammars/,LICENSE.mdandThirdPartyNotices.txtfrom a theme-tools commit onmaininto that repository, with a README that points to this package and names the version. It keeps that repository's.github/and replaces everything else, then opens a pull request there. It stops when that repository already has a newer version.--dry-runcommits, pushes and opens nothing.docs/releasing.mdsays to run it after a release that changes the grammar's version.After merging
This pull request ships the grammar at 0.1.0 with no changeset, so no release triggers the first copy. Shopify/liquid-tm-grammar#58 is merged, so that repository's
.github/, which the copy keeps, no longer runs a CI that needspackage.json. Runcopy-to-liquid-tm-grammar.shonce frommainafter this pull request merges. That copy removes the YAML, the build, the tests,package.jsonandyarn.lockfrom Shopify/liquid-tm-grammar.No changeset: the grammar and the extension's behavior don't change.
The lockfile
The lockfile adds the package and its
vscode-textmate,vscode-onigurumaandyamldev dependencies. The package's@types/nodemakes the root's optional@types/nodepeers resolve to 22.18.8, the version the other packages use, instead of 26.1.1. No direct dependency changes version.Validation
pnpm build, thenpnpm packageinpackages/vscode-extension, builds a.vsixwith the same 76 files as one frommain. The two grammar files move fromextension/syntaxes/grammars/toextension/dist/grammars/and keep the same bytes, andcontributes.grammarspoints at the new paths..vsix, in VS Code Web 1.148.0 through@vscode/test-web, highlights Liquid, Liquid in<style>and Liquid in<script>asmaindoes. Developer: Inspect Editor Tokens and Scopes on{% for %}showskeyword.control.for.liquidintext.html.liquid.pnpm testruns the grammar's 33 tests, on Ubuntu and Windows.copy-to-liquid-tm-grammar.sh --dry-run