From bea65d59c4f51a4e506a684a3081bd4e9392ed9b Mon Sep 17 00:00:00 2001 From: HerambInamke <178374507+HerambInamke@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:09:51 +0530 Subject: [PATCH] [heft-sass-plugin] Make the incremental cache file name machine-independent The cache file name was a hash of all processor options, including the absolute build folder, other absolute paths, and the core count. Exclude the logger and concurrency from the hash and make absolute paths relative to the build folder. Fixes #6126 --- ...sass-cache-file-name_2026-11-14-00-00.json | 11 ++++++ .../heft-sass-plugin/src/SassProcessor.ts | 13 ++++++- .../src/test/SassProcessor.test.ts | 35 +++++++++++++++++++ .../__snapshots__/SassProcessor.test.ts.snap | 18 ++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 common/changes/@rushstack/heft-sass-plugin/fix-issue-6126-sass-cache-file-name_2026-11-14-00-00.json diff --git a/common/changes/@rushstack/heft-sass-plugin/fix-issue-6126-sass-cache-file-name_2026-11-14-00-00.json b/common/changes/@rushstack/heft-sass-plugin/fix-issue-6126-sass-cache-file-name_2026-11-14-00-00.json new file mode 100644 index 0000000000..348dfff80c --- /dev/null +++ b/common/changes/@rushstack/heft-sass-plugin/fix-issue-6126-sass-cache-file-name_2026-11-14-00-00.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-sass-plugin", + "comment": "Make the incremental cache file name independent of the machine: it no longer depends on the absolute build folder or the core count.", + "type": "patch" + } + ], + "packageName": "@rushstack/heft-sass-plugin", + "email": "178374507+HerambInamke@users.noreply.github.com" +} diff --git a/heft-plugins/heft-sass-plugin/src/SassProcessor.ts b/heft-plugins/heft-sass-plugin/src/SassProcessor.ts index f71f32b5e3..96ade2ac26 100644 --- a/heft-plugins/heft-sass-plugin/src/SassProcessor.ts +++ b/heft-plugins/heft-sass-plugin/src/SassProcessor.ts @@ -327,9 +327,20 @@ export class SassProcessor { } public async loadCacheAsync(tempFolderPath: string): Promise { + const { buildFolder } = this.#options; + // Hash only options that affect the output, so the cache file name is the same on every machine: + // skip the logger and concurrency, and make absolute paths relative to the build folder. const configHash: string = getContentsHash( 'sass.json', - JSON.stringify({ version: 2, options: this.#options }) + JSON.stringify({ version: 2, options: this.#options }, (key: string, value: unknown) => { + if (key === 'logger' || key === 'concurrency') { + return undefined; + } + if (typeof value === 'string' && path.isAbsolute(value)) { + return Path.convertToSlashes(path.relative(buildFolder, value)); + } + return value; + }) ).slice(0, 8); this.#configFilePath = path.join(tempFolderPath, `sass_${configHash}.json`); diff --git a/heft-plugins/heft-sass-plugin/src/test/SassProcessor.test.ts b/heft-plugins/heft-sass-plugin/src/test/SassProcessor.test.ts index eb4565aa79..f25e0496a5 100644 --- a/heft-plugins/heft-sass-plugin/src/test/SassProcessor.test.ts +++ b/heft-plugins/heft-sass-plugin/src/test/SassProcessor.test.ts @@ -1389,6 +1389,41 @@ describe(SassProcessor.name, () => { }); }); + describe('loadCacheAsync', () => { + async function getCacheFileNameAsync( + root: string, + overrides: Partial = {} + ): Promise { + const readSpy: jest.SpyInstance = jest.spyOn(FileSystem, 'readFileAsync').mockResolvedValue(''); + const buildFolder: string = path.resolve(root, 'project'); + const processor: SassProcessor = new SassProcessor({ + logger: new MockScopedLogger(new Terminal(terminalProvider)), + buildFolder, + concurrency: 4, + srcFolder: path.resolve(buildFolder, 'src'), + dtsOutputFolders: [path.resolve(buildFolder, 'temp/sass-ts')], + cssOutputFolders: [{ folder: path.resolve(buildFolder, 'lib'), shimModuleFormat: undefined }], + loadPaths: [path.resolve(buildFolder, 'node_modules')], + exportAsDefault: true, + ...overrides + }); + await processor.loadCacheAsync(path.resolve(buildFolder, 'temp/build/sass')); + return path.basename(readSpy.mock.lastCall[0]); + } + + it('uses a cache file name that does not depend on the build folder or concurrency', async () => { + const fileName: string = await getCacheFileNameAsync('/machine-a'); + expect(fileName).toMatch(/^sass_.{8}\.json$/); + expect(await getCacheFileNameAsync('/machine-b/checkout', { concurrency: 16 })).toBe(fileName); + }); + + it('uses a different cache file name when an option that affects the output changes', async () => { + expect(await getCacheFileNameAsync('/machine-a', { exportAsDefault: false })).not.toBe( + await getCacheFileNameAsync('/machine-a') + ); + }); + }); + describe('loadPaths option', () => { it('resolves a bare specifier from a configured load path', async () => { const { processor, logger } = createProcessor(terminalProvider, { diff --git a/heft-plugins/heft-sass-plugin/src/test/__snapshots__/SassProcessor.test.ts.snap b/heft-plugins/heft-sass-plugin/src/test/__snapshots__/SassProcessor.test.ts.snap index 808f48fa25..d2225f8052 100644 --- a/heft-plugins/heft-sass-plugin/src/test/__snapshots__/SassProcessor.test.ts.snap +++ b/heft-plugins/heft-sass-plugin/src/test/__snapshots__/SassProcessor.test.ts.snap @@ -1622,6 +1622,24 @@ h1 { } `; +exports[`SassProcessor loadCacheAsync uses a cache file name that does not depend on the build folder or concurrency: terminal-output 1`] = ` +Array [ + "[verbose] Error reading cache file: SyntaxError: Unexpected end of JSON input[n]", + "[verbose] Error reading cache file: SyntaxError: Unexpected end of JSON input[n]", +] +`; + +exports[`SassProcessor loadCacheAsync uses a cache file name that does not depend on the build folder or concurrency: written-files 1`] = `Map {}`; + +exports[`SassProcessor loadCacheAsync uses a different cache file name when an option that affects the output changes: terminal-output 1`] = ` +Array [ + "[verbose] Error reading cache file: SyntaxError: Unexpected end of JSON input[n]", + "[verbose] Error reading cache file: SyntaxError: Unexpected end of JSON input[n]", +] +`; + +exports[`SassProcessor loadCacheAsync uses a different cache file name when an option that affects the output changes: written-files 1`] = `Map {}`; + exports[`SassProcessor loadPaths option does not resolve a bare specifier from an unconfigured folder: terminal-output 1`] = ` Array [ "[verbose] Checking for changes to 1 files...[n]",