Skip to content

Replace the grammar submodule with packages/liquid-tm-grammar - #1461

Merged
charlespwd merged 17 commits into
mainfrom
cpc-29/liquid-tm-grammar-package
Dec 1, 2026
Merged

charlespwd merged 17 commits into
mainfrom
cpc-29/liquid-tm-grammar-package

Conversation

@charlespwd

@charlespwd charlespwd commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

In this PR

The Liquid TextMate grammar moves from the packages/vscode-extension/syntaxes submodule into the workspace as packages/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

Before After
Grammar source Submodule at packages/vscode-extension/syntaxes packages/liquid-tm-grammar
Grammar in the .vsix syntaxes/grammars/*.tmLanguage.json dist/grammars/*.tmLanguage.json, same bytes
Build and tests JavaScript, mocha and yarn, in Shopify/liquid-tm-grammar TypeScript and Vitest, in pnpm test
Shopify/liquid-tm-grammar The source The built grammars, their licenses, and a README that points here

The package

packages/liquid-tm-grammar holds the YAML sources, test cases and baselines of Shopify/liquid-tm-grammar at df3989f, the commit the submodule points at. The built grammars are the same bytes.

  • src/build.ts builds grammars/*.tmLanguage.json from the YAML, and fails on an invalid YAML file.
  • src/grammar.spec.ts tokenizes each file in tests/cases and compares the result with its baseline in tests/baselines with toMatchFileSnapshot. pnpm vitest run packages/liquid-tm-grammar -u accepts new baselines.
  • src/build.spec.ts checks that the committed JSON matches its YAML, and that an invalid file fails the build.
  • pnpm --filter @shopify/liquid-tm-grammar dev rebuilds the grammar when any of its YAML files changes, including liquid/*.yml.
  • The package is private. It gets versions and a changelog from changesets and is never published. The extension depends on it, so the release orchestrator patches the extension when the grammar's version changes.
  • CONTRIBUTING.md gives the F5 loop, the tests and the changeset step, and sends bug reports to the theme-tools issues.

The extension

  • The 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:ci builds the grammar first.
  • The F5 task in .vscode/tasks.json builds 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, and submodules: true in the workflows are gone.
  • Git leaves packages/vscode-extension/syntaxes/ on disk in a clone that had the submodule checked out. .vscodeignore and the extension's .gitignore skip it, so it stays out of the .vsix and out of git add -A. rm -rf packages/vscode-extension/syntaxes removes it.

Shopify/liquid-tm-grammar

GitHub Linguist highlights Liquid with the grammar files in that repository: its grammars.yml reads text.html.liquid and liquid.injection from vendor/grammars/liquid-tm-grammar.

  • packages/liquid-tm-grammar/scripts/copy-to-liquid-tm-grammar.sh copies grammars/, LICENSE.md and ThirdPartyNotices.txt from a theme-tools commit on main into 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-run commits, pushes and opens nothing.
  • docs/releasing.md says to run it after a release that changes the grammar's version.
  • Shopify/liquid-tm-grammar#58 closes pull requests from forks and sends issues here, as this repository does.

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 needs package.json. Run copy-to-liquid-tm-grammar.sh once from main after this pull request merges. That copy removes the YAML, the build, the tests, package.json and yarn.lock from 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-oniguruma and yaml dev dependencies. The package's @types/node makes the root's optional @types/node peers resolve to 22.18.8, the version the other packages use, instead of 26.1.1. No direct dependency changes version.

Validation

  • pnpm build, then pnpm package in packages/vscode-extension, builds a .vsix with the same 76 files as one from main. The two grammar files move from extension/syntaxes/grammars/ to extension/dist/grammars/ and keep the same bytes, and contributes.grammars points at the new paths.
  • That .vsix, in VS Code Web 1.148.0 through @vscode/test-web, highlights Liquid, Liquid in <style> and Liquid in <script> as main does. Developer: Inspect Editor Tokens and Scopes on {% for %} shows keyword.control.for.liquid in text.html.liquid.
  • pnpm test runs the grammar's 33 tests, on Ubuntu and Windows.
  • The copy script's dry run at this branch's head:
copy-to-liquid-tm-grammar.sh --dry-run
Warning: 873360fffd22c4af0b8245e331690306454c8329 is not on Shopify/theme-tools main. A real run stops here.
Cloning Shopify/liquid-tm-grammar...

Dry run: these files would change in Shopify/liquid-tm-grammar:
D	.gitignore
D	CODE_OF_CONDUCT.md
D	CONTRIBUTING.md
M	README.md
D	base-syntax.yml
D	build/build.js
D	build/index.js
D	build/liquid.js
D	build/watch.js
D	images/shopify_glyph.png
D	images/vscode-extension-development.png
D	liquid-injection.yml
D	liquid.yml
D	liquid/objects.yml
D	liquid/operators.yml
D	liquid/tags.yml
D	package.json
D	showcase.liquid
D	tests/.theme-check.yml
D	tests/baselines/basic-types.baseline.txt
D	tests/baselines/comment-block.baseline.txt
D	tests/baselines/css.baseline.txt
D	tests/baselines/filter.baseline.txt
D	tests/baselines/html.baseline.txt
D	tests/baselines/injection-comment.baseline.txt
D	tests/baselines/injection-raw.baseline.txt
D	tests/baselines/invalid-range.baseline.txt
D	tests/baselines/javascript.baseline.txt
D	tests/baselines/json.baseline.txt
D	tests/baselines/language-constants.baseline.txt
D	tests/baselines/liquid-as-html-attribute.baseline.txt
D	tests/baselines/liquid-doc.baseline.txt
D	tests/baselines/object.baseline.txt
D	tests/baselines/operators.baseline.txt
D	tests/baselines/tag-assign.baseline.txt
D	tests/baselines/tag-capture.baseline.txt
D	tests/baselines/tag-case.baseline.txt
D	tests/baselines/tag-conditional.baseline.txt
D	tests/baselines/tag-cycle.baseline.txt
D	tests/baselines/tag-for.baseline.txt
D	tests/baselines/tag-form.baseline.txt
D	tests/baselines/tag-liquid-comment.baseline.txt
D	tests/baselines/tag-paginate.baseline.txt
D	tests/baselines/tag-raw.baseline.txt
D	tests/baselines/tag-render.baseline.txt
D	tests/baselines/tag-sections.baseline.txt
D	tests/baselines/tag-tablerow.baseline.txt
D	tests/baselines/tag.baseline.txt
D	tests/baselines/variable-lookup.baseline.txt
D	tests/build.js
D	tests/cases/basic-types.liquid
D	tests/cases/comment-block.liquid
D	tests/cases/css.liquid
D	tests/cases/filter.liquid
D	tests/cases/html.liquid
D	tests/cases/injection-comment.liquid
D	tests/cases/injection-raw.liquid
D	tests/cases/invalid-range.liquid
D	tests/cases/javascript.liquid
D	tests/cases/json.liquid
D	tests/cases/language-constants.liquid
D	tests/cases/liquid-as-html-attribute.liquid
D	tests/cases/liquid-doc.liquid
D	tests/cases/object.liquid
D	tests/cases/operators.liquid
D	tests/cases/tag-assign.liquid
D	tests/cases/tag-capture.liquid
D	tests/cases/tag-case.liquid
D	tests/cases/tag-conditional.liquid
D	tests/cases/tag-cycle.liquid
D	tests/cases/tag-for.liquid
D	tests/cases/tag-form.liquid
D	tests/cases/tag-liquid-comment.liquid
D	tests/cases/tag-paginate.liquid
D	tests/cases/tag-raw.liquid
D	tests/cases/tag-render.liquid
D	tests/cases/tag-sections.liquid
D	tests/cases/tag-tablerow.liquid
D	tests/cases/tag.liquid
D	tests/cases/variable-lookup.liquid
D	tests/syntaxes/css.tmLanguage.json
D	tests/syntaxes/html.tmLanguage.json
D	tests/syntaxes/javascript.tmLanguage.json
D	tests/syntaxes/json.tmLanguage.json
D	tests/test.js
D	tests/tsconfig.json
D	yarn.lock

 87 files changed, 8 insertions(+), 18644 deletions(-)

Commit on branch copy-theme-tools-873360fffd22:
  Copy the grammar from Shopify/theme-tools (version 0.1.0)
  
  Copied from packages/liquid-tm-grammar at
  https://github.com/Shopify/theme-tools/tree/873360fffd22c4af0b8245e331690306454c8329/packages/liquid-tm-grammar

Pull request on Shopify/liquid-tm-grammar, base main: Copy the grammar from Shopify/theme-tools (version 0.1.0)
  This pull request copies the Liquid grammar, version 0.1.0, from [`packages/liquid-tm-grammar` in Shopify/theme-tools](https://github.com/Shopify/theme-tools/tree/873360fffd22c4af0b8245e331690306454c8329/packages/liquid-tm-grammar) at Shopify/theme-tools@873360fffd22.
  
  The grammar's source is `packages/liquid-tm-grammar` in Shopify/theme-tools. This repository keeps the built grammar for GitHub Linguist.

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.
@charlespwd charlespwd self-assigned this Dec 1, 2026
@charlespwd
charlespwd marked this pull request as ready for review December 1, 2026 17:57
@charlespwd
charlespwd requested a review from a team as a code owner December 1, 2026 17:57
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.
Comment thread packages/liquid-tm-grammar/package.json Resolved
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
charlespwd force-pushed the cpc-29/liquid-tm-grammar-package branch from 3e45587 to d927308 Compare December 1, 2026 20:03
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.

@EvilGenius13 EvilGenius13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@charlespwd
charlespwd enabled auto-merge (squash) December 1, 2026 20:47
@charlespwd
charlespwd merged commit 32316c0 into main Dec 1, 2026
9 checks passed
@charlespwd
charlespwd deleted the cpc-29/liquid-tm-grammar-package branch December 1, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants