Repository navigation
Conversation
mathiasrw
added this pull request to stack #787
October 23, 2026 04:29
…with names that differ only in case
… record only the renames that were done
…ith small examples in the README
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #780
Stacked on #784.
Change
--rename(-r) does the search and replace on the name of each file, and renames the file to the result. The folder and the content are not touched. A/in a new name stops the run with"/" is not allowed in names. Use --rename-path to move files.--rename-pathdoes it on the whole path, so a/in the replacement moves the file. Folders that are not there are made. The path is the one RexReplace works on: as found, or the full path with--full-path.--replacement-jsworks as for content: the name (or the path) is thetext, andfile,name,extand the rest are about the file before the rename.--keep-backupkeeps the old file, so the file is copied and not moved.--rename-forcewrites over a file that is there already.--renameand--rename-pathcan not be used together, and--rename-forceneeds one of them.Clashes
If planned renames clash the process is halted and no change is applied to any file (exit code 3). A clash is when
--rename-forceonly allows the last one. Each clash is one error, with each path on its own line so long paths can be read, and then a panic says that no change is applied to any file:The paths are compared as absolute paths, so
a.mdand./a.mdare the same, and the case is ignored, asX.mdandx.mdare the same file on macOS and Windows. A file can still change only the case of its own name, but only when the new path is really the same file (the same device and inode). On Linuxa.mdandA.mdcan be two files, so then it is a clash. Tests for this run only on a file system that is case-sensitive, so on Linux in CI. Just before each rename, the new path is checked again, as the files can have changed since.The check uses
Set.intersection().src/shim.tsadds it when the runtime does not have it (Node 18 and 20, which the CI tests). It is a few lines of our own, as the shims from es-shims and core-js are spread over many files.Output
--rename--rename --simulate--rename --output--rename --output-match--simulateand--outputthe old name is printed just before the new one, so they come in pairs in a terminal.--verbosetells each step before it is done:Make folder:,Write over:,Rename:orCopy:, andSame name:.renames, with{old, new}for each file that was renamed, or would be with--simulateand--output. A rename that fails is not in it.--output-matchonly shows what the pattern finds in the paths. The replacement is not used (it can be a dummy like_), so there is no clash check and nothing inrenames.The README has a section with small examples: renaming, moving,
--simulate, a clash and--output-match.Tests
yarn test-cipasses: the demo on Node and Bun (now with--rename), and 943 Bun tests.test/engine/rename.test.js,test/engine/rename-force.test.jsandtest/cli/rename.test.jsare new.