CodeVetter · Repo Unpack · Extension points
prettier/prettier
New languages are plugins: export languages/parsers/printers/options and load via --plugin, options.plugins, or config. Builtins are the same API, registered in the generated lazy-load tables. JS syntax work lands in src/language-js/parse and the printAngular/printJsx/printFlow/printTypescript/printEstree chain. Doc commands are the IR extension point. CLI flags are two tables (cli-options.evaluate.js and core-options.evaluate.js). Config file names are the CONFIG_FILES array.
- A plugin is a module (default or named exports) with languages, parsers (parse/astFormat/locStart/locEnd/hasPragma/preprocess), printers (print/embed/massageAstNode/hasPrettierIgnore/getVisitorKeys), options, defaultOptions.
- toLazyLoadPlugin turns {name, load, parsers[], printers[]} into objects whose parsers/printers entries are async thunks that import() the real module on first use — the intended way builtins stay tree-shakeable.
- Adding a production-bundled parser means adding src/plugins/<name>.js (see src/plugins/babel.js re-exporting language-js/parse/babel plus json parsers) and regenerating production-plugins.js. Dev mode loads language-*/index.js instead.
- JS printer extension: add a node-type handler in src/language-js/print/{estree,jsx,typescript,flow,angular}.js; printWithoutParentheses tries those five in order. Comment attachment hooks are canAttachComment/handleComments/willPrintOwnComments on the estree printer.
- JS parser extension: export from src/language-js/parse/<engine>.js via createParser, then re-export from parse/index.js. babel.js documents the add/remove plugin checklist (tests/format/js/babel-plugins + scripts/update-babel-plugin-tests.js).
- Doc IR extension for printers is the builders in src/document/builders (group, fill, ifBreak, indent, line, cursor, label, trim, …) plus printer.printDocToString. prettier.doc.utils exposes traverseDoc/mapDoc/willBreak. concat is a deprecated alias for identity on arrays, TODO remove in v4.
- CLI option tables: src/cli/cli-options.evaluate.js (CLI-only) merged with API options from getSupportInfo via apiOptionToCliOption in get-context-options.js. New forwarded flags belong in core-options.evaluate.js with cliName/cliCategory.
- CONFIG_FILES in config-searcher.js is the ordered list of config filenames; loaders.js maps extensions to load functions. Adding a config format means both arrays. Search uses search-closest FileSearcher with a stopDirectory mockable.
- Language metadata is linguist-languages plus createLanguage() in each languages.evaluate.js (extensions, filenames, vscodeLanguageIds, interpreters). inferParser matches basename, then extension, then shebang interpreter.
- In-repo extra plugins under packages/plugin-{oxc,hermes,yuku} are the template for shipping an alternate JS parser as a separate npm package: remap astFormat, reuse estree printer, export languages/options from the core tree. They are included in the dist build package list.
- __debug APIs (parse, formatAST, formatDoc, printToDoc, printDocToString) and __internal (shared with CLI) are the in-tree hooks tests and the CLI use; they are not documented as stable public API. mockable objects in src/common/mockable.js and src/cli/mockable.js exist so tests can stub writeFormattedFile/isTTY/getTimestamp.
- changelog_unreleased/<area>/<pr>.md plus yarn generate-changelog is the required contributor extension point for user-facing changes; PRs without it may be closed.