zpl-viewer¶
Label Studio's direction is to become the ultimate open home for all things thermal labels: data, tools, resources and transparency, with offline ZPL II and EPL2 preview, authoring, analysis, merge and deploy for everyone (constitution §1).
What this repo is¶
Label Studio (package name zpl-viewer, kept for extension-identity stability) is a VS Code extension for everything that happens to a thermal label before it reaches the printer: read, create, modify, analyze, import, merge and deploy, in ZPL II (.zpl, .zpl2, .prn, .lbl) and EPL2 (.epl, .epl2). Everything except deployment runs offline and in-process: each language parses into the shared drawing-op IR (src/renderer/ir.ts), src/renderer/draw.ts renders it to Canvas 2D, and pure-JS libraries (bwip-js for barcodes, pdf-lib for PDF) do the rest. The only socket in the codebase is src/deploy/transports.ts, used when a user explicitly deploys. It serves developers and warehouse/IT staff who write or troubleshoot labels.
"Done" means ESLint is clean, both webpack bundles (dist/extension.js, dist/webview/) build, and the test pipeline is green — unit plus renderer draw-call geometry (which also checks the generated reference docs), VS Code extension-host integration, and Playwright e2e — as run by the 3-OS CI matrix (.github/workflows/ci.yml, Node 20).
Stack & commands¶
TypeScript + webpack (two configs: the extension host, and a webview config with preview + studio entries); tests are mocha/chai + c8, @vscode/test-electron, and Playwright.
npm ci # install dependencies (Node 20)
npm run watch # webpack watch for both bundles; then F5 to launch the Extension Development Host
npm run compile # webpack build → dist/extension.js + dist/webview/
npm run lint # eslint src --ext ts
npm run test:unit # unit + renderer draw-call tests (compile-tests + c8/mocha)
npm run test:integration # VS Code extension-host suite (@vscode/test-electron)
npm run test:e2e # Playwright webview tests (first: npx playwright install chromium)
npm test # full pipeline: unit + integration + e2e
npm run docs:reference # regenerate docs/reference/*.md from package.json contributes
Docs gates: python3 tools/unwrap-prose.py --check (one paragraph per line) and python3 tools/docs_index.py --check (the docs/README.md index).
Layout¶
| Path | What lives there |
|---|---|
src/ |
Extension source; src/README.md is the module guide. Tests in src/test/{unit,renderer,integration,e2e} with fixtures in src/test/fixtures/ |
syntaxes/, snippets/, language-configuration*.json |
TextMate grammars, snippets and editor behaviour for ZPL and EPL |
samples/ |
Example labels and a sample data source (opened by the Run Extension launch config) |
docs/ |
Docs index, ADRs (docs/adr/), the testing guide, and generated reference (docs/reference/) |
scripts/ |
Node maintenance scripts: gen-reference-docs.mjs, gen-verify-harness.mjs (the preview harness page for e2e and the verify kit), smoke-test.mjs |
tools/ |
Vendored fleet tools (unwrap-prose.py, docs_index.py) |
features/, verify/ |
Feature index (features/v1) and the user-scenario verification kit |
public/ |
Vendored fleet feedback widget scripts |
images/ |
Extension and file icons |
Conventions¶
- Backlog of record: GitHub Issues with the fleet labels (
.github/sdlc.ymlbacklog.mode: issues). Pick up issues labelledagent:ready; never touchagent:holdorhuman-review. - Definition of Done: the fleet default PR checklist (this repo has no
.github/pull_request_template.md), plus the "done" bar above. - Decisions: ADRs in
docs/adr/NNNN-slug.md, indexed indocs/adr/README.md. Add one for anything hard to reverse. - Commits: Conventional Commits (
feat fix docs style refactor test chore perf ci build). The PR title is the squash subject. - Branches:
feature/,fix/,docs/,refactor/,test/orchore/offmain; open a PR, never push tomaindirectly. - Releases: release-please (
.github/workflows/release.yml) opens a release PR from the Conventional Commit titles; merging it tagsvX.Y.Z, creates the GitHub Release and apackagejob runsvsce packageand attaches the.vsixto it (nothing is published to npm). Version source ispackage.json(.release-please-manifest.json,release-please-config.json). An optionalRELEASE_PLEASE_TOKENPAT lets the release PR trigger CI. Marketplace / Open VSX publishing is not wired yet: it needs a registered publisher and the owner'sVSCE_PAT/OVSX_PATsecrets. Never editCHANGELOG.mdor a version number by hand. - Generated:
docs/reference/{commands,settings,keybindings}.mdcome frompackage.jsoncontributes— after changing a command, setting or keybinding runnpm run docs:reference;src/test/unit/referenceDocs.test.tsfailsnpm run test:unitwhile they are stale. Thedocs/README.mdindex span comes from each document's summary line (python3 tools/docs_index.py --write). - Vendored, never edited here:
tools/unwrap-prose.py,tools/docs_index.py,public/fleet-feedback*.js— change them in the hub and re-vendor. - README-First, README-Last: read the nearest
README.mdbefore changing a directory, and update it after. - Markdown is one paragraph per line (
python3 tools/unwrap-prose.py --write); CI enforces it. - Never: suppress type errors (
as any,@ts-ignore,# type: ignore), leave empty exception handlers, or hand-edit generated files.
Architecture rules¶
src/README.mdis the module guide — read it before adding code.- Pure layer (
core/,formats/,renderer/,image/,barcode/,data/,emit/,analysis/) must not importvscode,fs,netorzlib: it is compiled into the webview bundle and exercised directly by unit tests. Anything it needs goes intsconfig.webview.json. - Node-only code lives in
importers/anddeploy/; VS Code code inextension.ts,config.ts,diagnostics.ts,previewPanel.ts,providers/andui/. Commands stay thin — logic belongs below them, where it can be unit-tested. - Add a printer language by creating
src/formats/<id>/and registering it insrc/core/formats.ts; parse into the existing IR rather than inventing a second one. src/barcode/symbologies.tsis the single source of truth for symbologies (encoder id, ZPL command, EPL selector, charset, length, check digit). Never hard-code a symbology mapping elsewhere.- Settings are read through
src/config.tsso the legacyzplViewer.*keys keep working; new commands use thelabelStudio.*namespace and keep an alias if they replace an old id. - Never add pixel goldens. A rendered label depends on the host's fonts and the Skia build behind the canvas, and the goldens once hid a broken barcode encoder (why). Cover rendering by recording Canvas 2D calls instead (
src/test/helpers/recordingContext.ts, used bysrc/test/unit/render.test.tsandsrc/test/renderer/draw.test.ts). - The pure layer has no
zliband noBuffer:core/inflate.tsandcore/base64.tsexist so decompression and base64 work in the webview too. Reach for those, not the Node built-ins, anywhere under the pure layer. - Graphics decoding belongs in
src/renderer/graphics.tsand image decoding insrc/image/; both are registries, so a new encoding or file format is one entry plus its decoder. - The
labelStudio._test.waitForPreviewReadyhook (and itszplViewer.*alias) is registered only whenVSCODE_ZPL_TEST=1, whichnpm run test:integrationsets; keep test-only surfaces behind that flag.
Fleet context¶
Member of the bamr87 fleet, managed by the bamr87/bamr87 hub (registry _data/projects.yml; standards in specs/, the Universal Project Standard). It is vendored there as a git submodule: commit and push changes here first — the hub only bumps its pointer afterwards. Shared CI, release, schema, and agent kits are seeded from the hub's templates/; prefer adopting those over hand-rolling equivalents. Loops that act on this repo: @claude mentions (claude.yml), the shared conformance check (conformance.yml, advisory), the user-scenario verify pass (verify.yml), the markdown one-line gate (markdown-oneline.yml), release-please (release.yml) and Dependabot.
Standard deviations¶
none (.github/sdlc.yml declares deviations: [])
Governance¶
Read docs/constitution.md before changing anything: it is the highest-precedence rule set here and wins over this file when they disagree. It changes only through a numbered record in docs/amendments/, ratified by the maintainer merging the PR; agents propose, never merge. Every user-facing feature has a stable id in features/features.yml with status, location and the PRD requirement ids it serves; the PRD's "Feature catalog" block is generated from it (python3 <bamr87/bamr87>/tools/governance_lint.py prd-sync . --write; check with … check .). Never hand-edit that block or CHANGELOG.md.