Skip to content

Commit

Permalink
fix(mfsu.eager): 🐛 mfsu.eager 缓存增加 cache dep 字段。 (#9604)
Browse files Browse the repository at this point in the history
* fix: 🐛  mfsu.eager  缓存增加 cache dep 字段。

* build: 👷 off patch

Co-authored-by: pshu <pishu.spf@antfin.com>
  • Loading branch information
stormslowly and stormslowly authored Oct 25, 2022
1 parent 2492a58 commit d4621a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage:
status:
patch: off
project:
default:
threshold: 5%
Expand Down
30 changes: 28 additions & 2 deletions packages/mfsu/src/staticDepInfo/staticDepInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class StaticDepInfo {
private readonly include: string[];
private currentDep: Record<string, Match> = {};
private builtWithDep: Record<string, Match> = {};
private cacheDependency: object = {};

private produced: { changes: unknown[] }[] = [];
private readonly cwd: string;
Expand Down Expand Up @@ -89,6 +90,20 @@ export class StaticDepInfo {
}

shouldBuild() {
const currentCacheDep = this.opts.mfsu.opts.getCacheDependency!();

if (!lodash.isEqual(this.cacheDependency, currentCacheDep)) {
if (process.env.DEBUG_UMI) {
const reason = why(this.cacheDependency, currentCacheDep);
logger.info(
'[MFSU][eager]: isEqual(cacheDependency,currentCacheDep) === false, because ',
reason,
);
}

return 'cacheDependency has changed';
}

if (lodash.isEqual(this.builtWithDep, this.currentDep)) {
return false;
} else {
Expand Down Expand Up @@ -120,14 +135,18 @@ export class StaticDepInfo {

snapshot() {
this.builtWithDep = this.currentDep;
this.cacheDependency = this.mfsu.opts.getCacheDependency!();
}

loadCache() {
if (existsSync(this.cacheFilePath)) {
try {
this.builtWithDep = JSON.parse(
const { dep = {}, cacheDependency = {} } = JSON.parse(
readFileSync(this.cacheFilePath, 'utf-8'),
);

this.builtWithDep = dep;
this.cacheDependency = cacheDependency;
logger.info('[MFSU][eager] restored cache');
} catch (e) {
logger.warn(
Expand All @@ -140,7 +159,14 @@ export class StaticDepInfo {

writeCache() {
fsExtra.mkdirpSync(dirname(this.cacheFilePath));
const newContent = JSON.stringify(this.builtWithDep, null, 2);
const newContent = JSON.stringify(
{
dep: this.builtWithDep,
cacheDependency: this.cacheDependency,
},
null,
2,
);
if (
existsSync(this.cacheFilePath) &&
readFileSync(this.cacheFilePath, 'utf-8') === newContent
Expand Down

0 comments on commit d4621a6

Please sign in to comment.