{"id":26683,"library":"zerotier-rule-compiler","title":"ZeroTier Rule Compiler","description":"A tool to compile human-readable ZeroTier rule scripts into the binary format required by ZeroTier network controllers. Current stable version is 1.2.2-2. This package is part of the ZeroTier ecosystem and is used internally by ZeroTier Central's rules editor. It provides both a library API and a CLI interface. Unlike manual rule construction, this compiler validates syntax and ensures correct encoding. The package is available on npm and has minimal dependencies. Release cadence is irregular, tied to ZeroTierOne updates.","status":"active","version":"1.2.2-2","language":"javascript","source_language":"en","source_url":"https://github.com/zerotier/ZeroTierOne/rule-compiler","tags":["javascript","ZeroTier"],"install":[{"cmd":"npm install zerotier-rule-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add zerotier-rule-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add zerotier-rule-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The package is self-contained, no external runtime dependencies.","package":"zerotier-rule-compiler","optional":false}],"imports":[{"note":"ESM-only since v1.0.0, no CJS support.","wrong":"const compile = require('zerotier-rule-compiler').compile","symbol":"compile","correct":"import { compile } from 'zerotier-rule-compiler'"},{"note":"Utility to convert binary rules back to human-readable format.","wrong":"import { stringify } from 'zerotier-rule-compiler' (no common mistake)","symbol":"stringify","correct":"import { stringify } from 'zerotier-rule-compiler'"},{"note":"Type error for debugging rule compilation failures.","wrong":"const parseError = require('zerotier-rule-compiler').parseError","symbol":"parseError","correct":"import { parseError } from 'zerotier-rule-compiler'"}],"quickstart":{"code":"import { compile, stringify } from 'zerotier-rule-compiler';\nconst script = `# accept all traffic on VLAN 1\ndrop\naccept`;\ntry {\n  const binaryRules = compile(script);\n  console.log('Binary rules:', binaryRules);\n  const reString = stringify(binaryRules);\n  console.log('Stringified:', reString);\n} catch (err) {\n  console.error('Compilation error:', err);\n}","lang":"typescript","description":"Compiles a simple ZeroTier rule script and then stringifies the result back to human-readable format."},"warnings":[{"fix":"Wrap calls to compile in try/catch blocks.","message":"The compile function throws on invalid syntax; always use try/catch.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the programmatic API with async I/O for large scripts.","message":"The CLI script cli.js uses synchronous file reading; may block event loop on large files.","severity":"deprecated","affected_versions":"<=1.2.2-2"},{"fix":"Upgrade to >=1.0.0 and update imports to ESM.","message":"Versions prior to 1.0.0 used a different AST representation; compatibility broken.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure each rule statement is on its own line or separated by semicolons.","cause":"Rule scripts require line breaks or semicolons between statements; missing newline.","error":"SyntaxError: Unexpected token at line 3: 'accept'"},{"fix":"Use 'import' syntax, or if using Node <13, set 'type': 'module' in package.json.","cause":"Using CommonJS require instead of ESM import; package is ESM-only.","error":"TypeError: compile is not a function"},{"fix":"Optimize rules by reducing complexity or combining conditions.","cause":"Compiled rule set too large for ZeroTier network controller limit.","error":"RangeError: Rule length exceeds 4096 bytes"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}