Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip file write if file content isn't changed #320

Closed
MartijnCuppens opened this issue Mar 24, 2020 · 2 comments · Fixed by #417
Closed

Skip file write if file content isn't changed #320

MartijnCuppens opened this issue Mar 24, 2020 · 2 comments · Fixed by #417

Comments

@MartijnCuppens
Copy link

If the input is the same as the output CSS and the --replace flag is passed, the file is always overridden. Can we somehow prevent this from happening?

The issue I have now is that I have another watcher on these files which detect file changes even if the content is not changed.

postcss-cli/index.js

Lines 222 to 227 in 42fc85e

tasks.push(fs.outputFile(options.to, result.css))
if (result.map) {
const mapfile = getMapfile(options)
tasks.push(fs.outputFile(mapfile, result.map))
}

We could wrap these lines with a simple check to prevent the file write from happening:

if (result.css !== css.toString('utf8')) {
  tasks.push(fs.outputFile(options.to, result.css))

  if (result.map) {
    const mapfile = getMapfile(options)
    tasks.push(fs.outputFile(mapfile, result.map))
  }
}

Not sure if we can better add a new option or do this check by default, what do you think?

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 24, 2020

Don't see a good reason not to do this by default; PR welcome.

@kentcdodds
Copy link
Contributor

@MartijnCuppens, I've opened #417 which solves this in a more general way. If I'm not mistaken, what you were asking for is:

if the input is the same as the output then don't save the file

What I built is:

if the output is the same as what's currently in the output then don't save the file.

I think what I have in #417 satisfies what you're looking for and solves a significant annoyance for me at the same time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants