Prettier Plugin for PDXScript (Paradox Game Script)
raw JSON → 0.1.0-rc.6 verified Sat Apr 25 auth: no javascript
A Prettier plugin for formatting PDXScript files used by Paradox Interactive games (Victoria 3, Hearts of Iron IV, Stellaris, etc.). v0.1.0-rc.6, pre-release with pre-1.0 API. Uses tree-sitter WASM parser for reliable parsing and applies opinionated formatting rules (tab indentation, operator preservation, comment handling). Ships dual CJS/ESM builds and TypeScript types. Differentiates from manual formatting by providing automated, consistent formatting via Prettier ecosystem. Key design: converts tree-sitter AST to plain objects for Prettier traversal.
Common errors
error Error: ENOENT: no such file or directory, open '.../node_modules/prettier-plugin-pdx-script/dist/grammar.wasm' ↓
cause WASM grammar file not found or not bundled correctly; file may be missing after npm install due to npm ignore or broken build.
fix
Reinstall plugin: npm install prettier-plugin-pdx-script@latest. If using npm <7, ensure peer dependencies are met. Alternatively, set custom WASM path via getGrammarWasmPath().
error Error: Cannot find module 'prettier-plugin-pdx-script' from '...' ↓
cause Plugin not installed or Prettier not configured to resolve the plugin.
fix
Install as devDependency: npm install --save-dev prettier-plugin-pdx-script. Prettier auto-discover should work; if not, add plugins array in .prettierrc: { 'plugins': ['prettier-plugin-pdx-script'] }
error TypeError: Cannot read properties of undefined (reading 'children') ↓
cause Invalid PDXScript syntax causing tree-sitter parser to return undefined or incomplete AST.
fix
Check input file for syntax errors (unclosed blocks, invalid keys). The plugin relies on valid PDXScript grammar.
error Heap out of memory (FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory) ↓
cause Likely the double traversal bug in versions <0.1.0-rc.6 causing memory explosion on files with 2000+ nodes.
fix
Upgrade to v0.1.0-rc.6 or later. If already on that version, the file is extremely large; increase Node heap size: NODE_OPTIONS='--max-old-space-size=8192' prettier --write file.txt
Warnings
breaking Pre-1.0 breaking changes in minor/pre-release versions. API surface may change without major version bump. ↓
fix Pin exact version in package.json. Check changelog before upgrading.
gotcha Large files (2000+ AST nodes) may cause out-of-memory errors in versions prior to v0.1.0-rc.6 due to double traversal bug. ↓
fix Upgrade to v0.1.0-rc.6 or later which fixed the double map in convertTree().
deprecated Prior to v0.1.0-rc.5, the only export was the default plugin. Utility functions (resetParser, disposeParser) were internal. ↓
fix Use default import only for plugin. Upgrade to v0.1.0-rc.5+ if programmatic parser management needed.
gotcha CJS require() may load wrong entry point in older Node versions without proper 'exports' field support. Use Node 18+ or ESM import. ↓
fix Use dynamic import or upgrade Node to >=18. In tsconfig, set moduleResolution to bundler or node16.
gotcha Plugin automatically discovers .txt files; ensure they are PDXScript files, not other text formats, or Prettier may misparse. ↓
fix Specify parser explicitly: 'prettier --parser pdx-script file.txt' or configure overrides in .prettierrc: { 'overrides': [{ 'files': '*.txt', 'options': { 'parser': 'pdx-script' } }] }
Install
npm install prettier-plugin-pdx-script yarn add prettier-plugin-pdx-script pnpm add prettier-plugin-pdx-script Imports
- default wrong
const prettierPluginPdxScript = require('prettier-plugin-pdx-script')correctimport prettierPluginPdxScript from 'prettier-plugin-pdx-script' - resetParser wrong
import resetParser from 'prettier-plugin-pdx-script/resetParser'correctimport { resetParser } from 'prettier-plugin-pdx-script' - disposeParser wrong
import { dispose } from 'prettier-plugin-pdx-script'correctimport { disposeParser } from 'prettier-plugin-pdx-script' - getGrammarWasmPath wrong
import { getWasmPath } from 'prettier-plugin-pdx-script'correctimport { getGrammarWasmPath } from 'prettier-plugin-pdx-script' - PARSER_NAME wrong
const PARSER_NAME = 'pdx-script'correctimport { PARSER_NAME } from 'prettier-plugin-pdx-script'
Quickstart
// Install: npm install --save-dev prettier prettier-plugin-pdx-script
// Format via CLI:
// npx prettier --write "path/to/**/*.txt"
// Programmatic usage:
import prettier from 'prettier';
const code = `my_declaration={
key1= value1
nested={
inner_key = "hello world"
}
# a comment
}
`;
const formatted = await prettier.format(code, {
parser: 'pdx-script',
plugins: ['prettier-plugin-pdx-script'],
tabWidth: 4 // Not used; plugin uses tabs
});
console.log(formatted);
// Output:
// my_declaration = {
// \tkey1 = value1
// \tnested = {
// \t\tinner_key = "hello world"
// \t}
// \t# a comment
// }