Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 12 additions & 1 deletion heft-plugins/heft-sass-plugin/src/SassProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,20 @@ export class SassProcessor {
}

public async loadCacheAsync(tempFolderPath: string): Promise<void> {
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`);
Expand Down
35 changes: 35 additions & 0 deletions heft-plugins/heft-sass-plugin/src/test/SassProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,41 @@ describe(SassProcessor.name, () => {
});
});

describe('loadCacheAsync', () => {
async function getCacheFileNameAsync(
root: string,
overrides: Partial<ISassProcessorOptions> = {}
): Promise<string> {
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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
Loading