-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
feat: add option to cache pattern.transform
(pattern.cache
)
#176
Conversation
920de2a
to
8ef8d5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using memoization
instead and make it the default for transform
?
src/writeFile.js
Outdated
}; | ||
|
||
if (pattern.cache) { | ||
const cacheKey = pattern.cacheKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to ability to customize the cacheKey
via pattern.options
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky yep, we can use package inside transform
function which get options, to invalidate cache you should pass this variables as cacheKey
src/writeFile.js
Outdated
if (pattern.cache) { | ||
const cacheKey = pattern.cacheKey | ||
? pattern.cacheKey | ||
: JSON.stringify(serialize({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use/generate an id
or hash
for patterns to avoid serialization ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky we can generate md5 or sha algo for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky after testing with difference arguments and platform, seems serialize
is best solution, btw we can do this in uglify
plugin
@michael-ciniawsky to allow cache between webpack builds, we do this in |
38e700c
to
7c0e7c4
Compare
@michael-ciniawsky friendly ping |
transform
functiontransform
function
src/writeFile.js
Outdated
globalRef.cacheDir = findCacheDir({ name: 'copy-webpack-plugin' }); | ||
} | ||
|
||
const cacheKey = pattern.cacheKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need pattern.cacheKey
(Custom cacheKey
) ? I'm not in favor of it, seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky we need another opinion 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky btw we can remove this option, because we use pattern
as part of cache key and if you want invalidate cache you can use cache
option (example cache: '/path/to/' + crypto.createHash('md5').update(JSON.stringify(something) || serialize(something)).digest("hex")
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi If you add it to the cache
pattern option itself { cache: { key: '...' } } || { cache: key }
I'm ok with it, but adding to many (related) options 'top scope' of a pattern is unnecessary (bloat) and can be confusing for folks new to copy-webpack-plugin
e.g if they assume pattern.cacheKey
is mandatory to use for some reason (many don't fully read the docs). There are already too many options for patterns and most folks will tend to use simple patterns like { from: '', to: '' } || { from: '', to: '', cache: true }
which is sufficient && straight forward for most of the plugin use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky btw, sometimes i have external variables for function inside in transofrm
and i can't invalidate cache without this option, i can only enable or disable cache, but this not convenient. Example i use nunjucks
inside transform
, some template render long time and i want to cache this operation, also i know when i should invalidate cache and cacheKey solve this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but this already goes under 'advanced' usage in the scope of copy-webpack-plugin
imo and wouldn't this work with { cache: ${customCacheKey}
instead of { cache: true, cacheKey:
${customCacheKey} }
for some reason ?
src/writeFile.js
Outdated
const cacheKey = pattern.cacheKey | ||
? pattern.cacheKey | ||
: serialize({ | ||
name: name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialize({
name,
version,
pattern,
content
})
tests/index.js
Outdated
.then(() => { | ||
return cacache | ||
.ls(cacheDir) | ||
.then((cacheEntriesList) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cacheEntriesList
=> cacheEntries
tests/index.js
Outdated
return cacache | ||
.ls(cacheDir) | ||
.then((cacheEntriesList) => { | ||
const cacheEntriesListKeys = Object.keys(cacheEntriesList); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cacheEntriesListKeys
=> cacheKeys
const cacheKeys = Object.keys(cacheEntries)
7c0e7c4
to
5c849c2
Compare
src/writeFile.js
Outdated
globalRef.cacheDir = findCacheDir({ name: 'copy-webpack-plugin' }); | ||
} | ||
|
||
const cacheKey = pattern.cacheKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi If you add it to the cache
pattern option itself { cache: { key: '...' } } || { cache: key }
I'm ok with it, but adding to many (related) options 'top scope' of a pattern is unnecessary (bloat) and can be confusing for folks new to copy-webpack-plugin
e.g if they assume pattern.cacheKey
is mandatory to use for some reason (many don't fully read the docs). There are already too many options for patterns and most folks will tend to use simple patterns like { from: '', to: '' } || { from: '', to: '', cache: true }
which is sufficient && straight forward for most of the plugin use cases.
tests/index.js
Outdated
|
||
expect(cacheKeys).to.have.lengthOf(1); | ||
|
||
cacheKeys.forEach((serializedCacheEntry) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cacheKeys.forEach((cacheKey) => {
// eslint-disable-next-line no-eval
cacheKey = eval(`(${cacheKey})`);
expect(cacheKey.pattern.from).to.equal(from);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky done
5c849c2
to
8969493
Compare
8969493
to
48c19ff
Compare
@michael-ciniawsky friendly ping, move key inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
transform
functionpattern.transform
(pattern.cache
)
Notable Changes
serialize
for cache key to invalidate cache afterpattern.transform
changed