From dc4270d2bac6e795a35e8cf5d7c3c5aeeac1771e Mon Sep 17 00:00:00 2001 From: Kirils L <9858620+kirjai@users.noreply.github.com> Date: Thu, 1 Jul 2021 21:00:24 +0100 Subject: [PATCH] fix(core): make missing output check more comprehensive (#6204) --- packages/workspace/src/tasks-runner/cache.ts | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/workspace/src/tasks-runner/cache.ts b/packages/workspace/src/tasks-runner/cache.ts index 6453ea931e18c..e6d6721fd5d6d 100644 --- a/packages/workspace/src/tasks-runner/cache.ts +++ b/packages/workspace/src/tasks-runner/cache.ts @@ -8,7 +8,7 @@ import { lstatSync, unlinkSync, } from 'fs'; -import { removeSync, ensureDirSync, copySync } from 'fs-extra'; +import { removeSync, ensureDirSync, copySync, readdirSync } from 'fs-extra'; import { join, resolve, sep } from 'path'; import { DefaultTasksRunnerOptions } from './default-tasks-runner'; import { spawn } from 'child_process'; @@ -190,11 +190,21 @@ export class Cache { cachedResult: CachedResult, outputs: string[] ): boolean { - return outputs.some( - (output) => - existsSync(join(cachedResult.outputsPath, output)) && - !existsSync(join(this.root, output)) - ); + return outputs.some((output) => { + const cacheOutputPath = join(cachedResult.outputsPath, output); + const rootOutputPath = join(this.root, output); + + const haveDifferentAmountOfFiles = + existsSync(cacheOutputPath) && + existsSync(rootOutputPath) && + readdirSync(cacheOutputPath).length !== + readdirSync(rootOutputPath).length; + + return ( + (existsSync(cacheOutputPath) && !existsSync(rootOutputPath)) || + haveDifferentAmountOfFiles + ); + }); } private getFileNameWithLatestRecordedHashForOutput(output: string): string {