-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compatibility cache feature with webpack@5
- Loading branch information
1 parent
2a5acaa
commit 5d2bd29
Showing
14 changed files
with
677 additions
and
1,668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ npm-debug.log* | |
/local | ||
/reports | ||
/node_modules | ||
/test/outputs | ||
|
||
.DS_Store | ||
Thumbs.db | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ | |
"prettier": "^2.0.5", | ||
"standard-version": "^8.0.2", | ||
"uglify-js": "^3.10.0", | ||
"webpack": "^4.44.1", | ||
"webpack": "^5.0.0-beta.23", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alexander-akait
Member
|
||
"worker-loader": "^2.0.0" | ||
}, | ||
"keywords": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,28 @@ | ||
// eslint-disable-next-line import/extensions,import/no-unresolved | ||
import getLazyHashedEtag from 'webpack/lib/cache/getLazyHashedEtag'; | ||
import serialize from 'serialize-javascript'; | ||
|
||
import { util } from 'webpack'; | ||
|
||
export default class Cache { | ||
// eslint-disable-next-line no-unused-vars | ||
constructor(compilation, ignored) { | ||
this.compilation = compilation; | ||
this.cache = compilation.getCache('TerserWebpackPlugin'); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
isEnabled() { | ||
return Boolean(this.compilation.cache); | ||
} | ||
|
||
createCacheIdent(task) { | ||
const { | ||
outputOptions: { hashSalt, hashDigest, hashDigestLength, hashFunction }, | ||
} = this.compilation; | ||
|
||
const hash = util.createHash(hashFunction); | ||
|
||
if (hashSalt) { | ||
hash.update(hashSalt); | ||
} | ||
|
||
hash.update(serialize(task.cacheKeys)); | ||
|
||
const digest = hash.digest(hashDigest); | ||
const cacheKeys = digest.substr(0, hashDigestLength); | ||
|
||
return `${this.compilation.compilerPath}/TerserWebpackPlugin/${cacheKeys}/${task.file}`; | ||
return true; | ||
} | ||
|
||
get(task) { | ||
async get(task) { | ||
// eslint-disable-next-line no-param-reassign | ||
task.cacheIdent = task.cacheIdent || this.createCacheIdent(task); | ||
task.cacheIdent = | ||
task.cacheIdent || `${task.file}|${serialize(task.cacheKeys)}`; | ||
// eslint-disable-next-line no-param-reassign | ||
task.cacheETag = task.cacheETag || getLazyHashedEtag(task.assetSource); | ||
task.cacheETag = | ||
task.cacheETag || this.cache.getLazyHashedEtag(task.assetSource); | ||
|
||
return new Promise((resolve, reject) => { | ||
this.compilation.cache.get( | ||
task.cacheIdent, | ||
task.cacheETag, | ||
(err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else if (result) { | ||
resolve(result); | ||
} else { | ||
reject(); | ||
} | ||
} | ||
); | ||
}); | ||
return this.cache.getPromise(task.cacheIdent, task.cacheETag); | ||
} | ||
|
||
store(task, data) { | ||
return new Promise((resolve, reject) => { | ||
this.compilation.cache.store( | ||
task.cacheIdent, | ||
task.cacheETag, | ||
data, | ||
(err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
} | ||
); | ||
}); | ||
async store(task, data) { | ||
return this.cache.storePromise(task.cacheIdent, task.cacheETag, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I think this was added by accident