Skip to content

feat: store incremental file in node_modules and use a binary format - #1473

Merged
dsherret merged 4 commits into
mainfrom
incremental-node-modules-binary
Nov 29, 2026
Merged

dsherret merged 4 commits into
mainfrom
incremental-node-modules-binary

Conversation

@dsherret

@dsherret dsherret commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

The incremental file is now stored in the .cache/dprint folder of the nearest node_modules folder, so it lives with the project (like other JS tools' caches) and is cleaned up along with it:

  • The nearest node_modules is the one in the config file's directory or, within a git repository, the closest one in an ancestor directory (ex. the root of a monorepo that hoists its dependencies). Ancestors aren't searched outside a git repository so a stray node_modules (ex. in the home directory) is never used.
  • The file is named incremental-<hash>-v1, where the hash is of the config file's directory relative to the folder containing node_modules (with forward slashes). So each config file in a workspace gets its own file, and the name is the same when the folder is moved or shared between systems (ex. Windows and WSL).
  • When there's no node_modules or the folder can't be created, it's stored in the cache directory like before, as <root path hash>-v1.

The incremental file is also now a binary file instead of JSON:

  • The format is the plugins hash followed by the file hashes, each a little endian u64. This is smaller and faster to read than JSON and avoids precision issues with hashes above 2^53 if a JS tool reads it.
  • The file hashes are sorted, so the same data always produces the same bytes.
  • The format version is in the file name, so a file in a different format is never read.
  • A file with an invalid length logs a warning and is treated as missing.
  • JSON incremental files from previous versions stay in the cache directory until dprint clear-cache is run.

Existing incremental files aren't read after upgrading, so each project does one full format run.

When the root directory has a node_modules folder, the incremental file is
now stored at node_modules/.cache/dprint/incremental-v1. Otherwise it's stored
in the cache directory like before.

The file is now binary (the plugins hash followed by the sorted file hashes,
each a little endian u64) instead of JSON, and its format version is in the
file name. The legacy JSON file in the cache directory is removed.
… incremental file

The incremental file is now stored in the nearest node_modules folder, which is
the one in the root directory or, within a git repository, the closest one in an
ancestor directory (ex. the root of a monorepo). It's named with a hash of the
root directory's path relative to that folder so the config files of a
workspace each get their own file and the name is the same across systems.
Running `dprint clear-cache` deletes it.
@dsherret
dsherret merged commit 02eef3e into main Nov 29, 2026
6 checks passed
@dsherret
dsherret deleted the incremental-node-modules-binary branch November 29, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant