{"id":27251,"library":"prettier-plugin-pdx-script","title":"Prettier Plugin for PDXScript (Paradox Game Script)","description":"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.","status":"active","version":"0.1.0-rc.6","language":"javascript","source_language":"en","source_url":"https://github.com/Myriad4Link/prettier-plugin-pdx-script","tags":["javascript","prettier","prettier-plugin","pdxscript","paradox","hoi4","tree-sitter","formatter","typescript"],"install":[{"cmd":"npm install prettier-plugin-pdx-script","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-pdx-script","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-pdx-script","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required to use the plugin; Prettier must be installed separately.","package":"prettier","optional":true}],"imports":[{"note":"Default import works for ESM. For CJS, use require('prettier-plugin-pdx-script'). The plugin is auto-discovered by Prettier; explicit import only needed for programmatic use.","wrong":"const prettierPluginPdxScript = require('prettier-plugin-pdx-script')","symbol":"default","correct":"import prettierPluginPdxScript from 'prettier-plugin-pdx-script'"},{"note":"Exported since v0.1.0-rc.5. Used to reset parser state (e.g., between files).","wrong":"import resetParser from 'prettier-plugin-pdx-script/resetParser'","symbol":"resetParser","correct":"import { resetParser } from 'prettier-plugin-pdx-script'"},{"note":"Exported since v0.1.0-rc.5. Cleanup function for parser resources.","wrong":"import { dispose } from 'prettier-plugin-pdx-script'","symbol":"disposeParser","correct":"import { disposeParser } from 'prettier-plugin-pdx-script'"},{"note":"Exported since v0.1.0-rc.5. Returns path to WASM grammar file for custom loading.","wrong":"import { getWasmPath } from 'prettier-plugin-pdx-script'","symbol":"getGrammarWasmPath","correct":"import { getGrammarWasmPath } from 'prettier-plugin-pdx-script'"},{"note":"Exported constant with parser name, useful for language detection.","wrong":"const PARSER_NAME = 'pdx-script'","symbol":"PARSER_NAME","correct":"import { PARSER_NAME } from 'prettier-plugin-pdx-script'"}],"quickstart":{"code":"// Install: npm install --save-dev prettier prettier-plugin-pdx-script\n\n// Format via CLI:\n// npx prettier --write \"path/to/**/*.txt\"\n\n// Programmatic usage:\nimport prettier from 'prettier';\n\nconst code = `my_declaration={\n    key1= value1\n    nested={\n        inner_key = \"hello world\"\n    }\n    # a comment\n}\n`;\n\nconst formatted = await prettier.format(code, {\n  parser: 'pdx-script',\n  plugins: ['prettier-plugin-pdx-script'],\n  tabWidth: 4 // Not used; plugin uses tabs\n});\n\nconsole.log(formatted);\n// Output:\n// my_declaration = {\n// \\tkey1 = value1\n// \\tnested = {\n// \\t\\tinner_key = \"hello world\"\n// \\t}\n// \\t# a comment\n// }","lang":"typescript","description":"Quickstart: install, CLI usage, and programmatic formatting with Prettier and the PDXScript plugin."},"warnings":[{"fix":"Pin exact version in package.json. Check changelog before upgrading.","message":"Pre-1.0 breaking changes in minor/pre-release versions. API surface may change without major version bump.","severity":"breaking","affected_versions":">=0.1.0-rc.2 <1.0.0"},{"fix":"Upgrade to v0.1.0-rc.6 or later which fixed the double map in convertTree().","message":"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.","severity":"gotcha","affected_versions":">=0.1.0-rc.2 <0.1.0-rc.6"},{"fix":"Use default import only for plugin. Upgrade to v0.1.0-rc.5+ if programmatic parser management needed.","message":"Prior to v0.1.0-rc.5, the only export was the default plugin. Utility functions (resetParser, disposeParser) were internal.","severity":"deprecated","affected_versions":"<0.1.0-rc.5"},{"fix":"Use dynamic import or upgrade Node to >=18. In tsconfig, set moduleResolution to bundler or node16.","message":"CJS require() may load wrong entry point in older Node versions without proper 'exports' field support. Use Node 18+ or ESM import.","severity":"gotcha","affected_versions":">=0.1.0-rc.2"},{"fix":"Specify parser explicitly: 'prettier --parser pdx-script file.txt' or configure overrides in .prettierrc: { 'overrides': [{ 'files': '*.txt', 'options': { 'parser': 'pdx-script' } }] }","message":"Plugin automatically discovers .txt files; ensure they are PDXScript files, not other text formats, or Prettier may misparse.","severity":"gotcha","affected_versions":">=0.1.0-rc.2"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"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().","cause":"WASM grammar file not found or not bundled correctly; file may be missing after npm install due to npm ignore or broken build.","error":"Error: ENOENT: no such file or directory, open '.../node_modules/prettier-plugin-pdx-script/dist/grammar.wasm'"},{"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'] }","cause":"Plugin not installed or Prettier not configured to resolve the plugin.","error":"Error: Cannot find module 'prettier-plugin-pdx-script' from '...'"},{"fix":"Check input file for syntax errors (unclosed blocks, invalid keys). The plugin relies on valid PDXScript grammar.","cause":"Invalid PDXScript syntax causing tree-sitter parser to return undefined or incomplete AST.","error":"TypeError: Cannot read properties of undefined (reading 'children')"},{"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","cause":"Likely the double traversal bug in versions <0.1.0-rc.6 causing memory explosion on files with 2000+ nodes.","error":"Heap out of memory (FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}