mem-fs-editor
mem-fs-editor copied to clipboard
Add option to skip write of unchanged file
Stumbling across this in a Yeoman generator in repos with Makefiles. When generating files that already exist, even if the generated contents are identical to those on disk, they are still unconditionally written with updated timestamps.
I can see use cases for wanting that timestamp updated anyway, so I don't strongly suggest unconditionally skipping this as a default. Perhaps something like forceWrite: false
should be an option that can be passed to .copy
/.copyTpl
/etc.?
.copy
calls .write
here:
https://github.com/SBoudrias/mem-fs-editor/blob/a75c5e7a922ded188d80d0d211e7107b1e6f434a/lib/actions/copy.js#L66
File state unconditionally set as modified
here:
https://github.com/SBoudrias/mem-fs-editor/blob/a75c5e7a922ded188d80d0d211e7107b1e6f434a/lib/actions/write.js#L13
Which is checked here before writing: https://github.com/SBoudrias/mem-fs-editor/blob/a75c5e7a922ded188d80d0d211e7107b1e6f434a/lib/actions/commit.js#L42-L43
I think it'd make sense to just skip the write if the content is the same; I don't quite see the value of updating the file timestamp. Seems you already dug into the relevant code, would you be willing to send a PR?