Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

feat(index): add support for a custom compare {Function} (options.compare) and generate {Function} (options.generate) #41

Closed
wants to merge 17 commits into from

Conversation

LukeSheard
Copy link

This add supports for a custom comparison function during the read phase, which allows the pitch phase to rely on something other than the stat of the module for comparison (e.g. the hash of the content of the file).

@jsf-clabot
Copy link

jsf-clabot commented Sep 18, 2018

CLA assistant check
All committers have signed the CLA.

package.json Outdated
@@ -25,7 +25,8 @@
"travis:lint": "npm run lint && npm run security",
"travis:test": "npm run test -- --runInBand",
"appveyor:test": "npm run test",
"defaults": "webpack-defaults"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what happened with this... something weird must have happened at npm install. I'll fix.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #41 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #41   +/-   ##
=======================================
  Coverage   17.47%   17.47%           
=======================================
  Files           2        2           
  Lines         103      103           
  Branches       13       13           
=======================================
  Hits           18       18           
  Misses         73       73           
  Partials       12       12
Impacted Files Coverage Δ
src/index.js 17.64% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74fccc4...a7a73f0. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #41 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #41   +/-   ##
=======================================
  Coverage   17.47%   17.47%           
=======================================
  Files           2        2           
  Lines         103      103           
  Branches       13       13           
=======================================
  Hits           18       18           
  Misses         73       73           
  Partials       12       12
Impacted Files Coverage Δ
src/index.js 17.64% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74fccc4...a7a73f0. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #41 into master will increase coverage by 23.11%.
The diff coverage is 21.42%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #41       +/-   ##
===========================================
+ Coverage   17.47%   40.59%   +23.11%     
===========================================
  Files           2        2               
  Lines         103      101        -2     
  Branches       13       12        -1     
===========================================
+ Hits           18       41       +23     
+ Misses         73       51       -22     
+ Partials       12        9        -3
Impacted Files Coverage Δ
src/index.js 41% <21.42%> (+23.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91d2a18...7f1cd95. Read the comment docs.

@michael-ciniawsky michael-ciniawsky changed the title (feat): Add support for custom-compare-fn feat(index): add support for a custom compare {Function} (options.compare) Sep 18, 2018
Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukeSheard Do you have a working solution using the file contents (hash) instead of mtime? If so I would love to see it :)

@@ -22,6 +22,7 @@ const defaults = {
cacheKey,
read,
write,
compare,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we may have a better name for this? (in)validate (but not sure)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, naming things is hard right? I like the idea of refactoring this so that it is validate and that you have to pas the validation status into the callback, i.e. true if the cache is still valid. Thoughts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the compare name is accurate. It's what "sort" uses, for example, as a name: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

@LukeSheard
Copy link
Author

@michael-ciniawsky I don't have anything I can share unfortunately - we currently run a slightly forked version of cache-loader and do our business logic elsewhere. The hash comment was just an example taken from #34 .

@luislobo
Copy link

👍 I think the PR as is works perfectly fine.

Is there a chance this can be merged in?

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but need tests

@luislobo
Copy link

@evilebottnawi Well, the functionallity didn't change at all, since it is defaulting to the previous comparing method, so the tests are there anyway, they didn't change. What test would you like to be added? Like adding a second test function? That is up to the user to provide one that works for them.

@luislobo
Copy link

One thing that I do think it needs is proper documentation in the README.md
@LukeSheard ?

@jraoult
Copy link

jraoult commented Oct 15, 2018

@evilebottnawi I'm super interested by this PR but I wonder what is the expected outcome here? I may be wrong, but if the idea is to offer a way to check file "fresheness" by comparing hashes, we probably need toDepDetails to be customizable as well. toDepDetails would store the hash value (like it does right now for mtime) and compare would read (and compare :)). Am I missing something?

@LukeSheard
Copy link
Author

@jraoult Yeah, I agree - I just haven't gotten around to updating my PR with the parity with toDepDetails yet. I'll try and put something together in the morning.

@LukeSheard
Copy link
Author

@evilebottnawi How do you propose testing this? The only tests I can see currently are for validation of the config options..

@alexander-akait
Copy link
Member

alexander-akait commented Oct 23, 2018

@LukeSheard we need add directory test and add couple simple test, the code grows and we should avoid regressions and bugs

@LukeSheard LukeSheard changed the title feat(index): add support for a custom compare {Function} (options.compare) feat(index): add support for a custom compare {Function} (options.compare) and generate {Function} (options.generate) Oct 23, 2018
@LukeSheard
Copy link
Author

@evilebottnawi I'm all for having a regression suite to test PRs agains. I've provided a working example in the /example directory, but I'm happy to wait for one of the maintainers to provide some basic tests if you're worried about this PR breaking something.

It makes me feel quite like a scapegoat to be told I have to write a whole regression suite for a library which doesn't have any real tests right now - just to move a couple of functions around. :(

@LukeSheard
Copy link
Author

Any reason why this can’t be merged now?

@LukeSheard LukeSheard closed this Jan 30, 2019
}

const compare = (data, callback) => {
return fs.readFile(data.depPath, (err, content) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be data.path

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

Successfully merging this pull request may close these issues.

None yet

7 participants