From d4621a6a14720d9e0a7db39d30d51c1d5292b0bc Mon Sep 17 00:00:00 2001 From: pshu Date: Tue, 25 Oct 2022 10:16:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(mfsu.eager):=20=F0=9F=90=9B=20=20mfsu.eager?= =?UTF-8?q?=20=20=E7=BC=93=E5=AD=98=E5=A2=9E=E5=8A=A0=20cache=20dep=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E3=80=82=20(#9604)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 mfsu.eager 缓存增加 cache dep 字段。 * build: 👷 off patch Co-authored-by: pshu --- codecov.yml | 1 + .../mfsu/src/staticDepInfo/staticDepInfo.ts | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index 67a0d65a19c7..9eda480dd463 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,6 @@ coverage: status: + patch: off project: default: threshold: 5% diff --git a/packages/mfsu/src/staticDepInfo/staticDepInfo.ts b/packages/mfsu/src/staticDepInfo/staticDepInfo.ts index 94688d616b9a..017d845e70ce 100644 --- a/packages/mfsu/src/staticDepInfo/staticDepInfo.ts +++ b/packages/mfsu/src/staticDepInfo/staticDepInfo.ts @@ -42,6 +42,7 @@ export class StaticDepInfo { private readonly include: string[]; private currentDep: Record = {}; private builtWithDep: Record = {}; + private cacheDependency: object = {}; private produced: { changes: unknown[] }[] = []; private readonly cwd: string; @@ -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 { @@ -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( @@ -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