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

using md5/sha1 for caches instead of / in addition to last modified time? #12

Open
xaviergonz opened this issue Jun 3, 2017 · 0 comments

Comments

@xaviergonz
Copy link

(Note: I'm using browserify-incremental CLI, which internally uses this module to create the cache)

The thing is that I use typescript sources that get compiled into new js files with new modified times even though the sources themselves do not change, which means that the incremental build always think they changed even when they actually didn't.

Could there be an option to switch from mtimes to md5/sha1 hashes?

Actually it could even be both for speed reasons:
if mtime did not change, file did not change
else if hash did not change file did not change and update mtime
else file did change and update mtime and hash

Helpful code

export const generateHashEntryAsync = (filePath) => {
  const hash = crypto.createHash('sha1');
  const stream = fs.createReadStream(filePath);

  return new Promise((resolve, reject) => {
    stream.once('error', (err: Error) => {
      reject(err);
    });

    stream.on('data', (data: Buffer) => {
      hash.update(data);
    });

    stream.once('end', () => {
      resolve(hash.digest('base64'));
    });
  });
};
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

No branches or pull requests

1 participant