cherry-pick(#11521): chore: include transpilation mode in the compute cache hash

This commit is contained in:
Pavel Feldman 2022-01-20 13:33:40 -08:00
parent e7a35c3f16
commit 6f857e0a00

View file

@ -48,7 +48,7 @@ sourceMapSupport.install({
}); });
function calculateCachePath(content: string, filePath: string): string { function calculateCachePath(content: string, filePath: string): string {
const hash = crypto.createHash('sha1').update(content).update(filePath).update(String(version)).digest('hex'); const hash = crypto.createHash('sha1').update(process.env.PW_EXPERIMENTAL_TS_ESM ? 'esm' : 'no_esm').update(content).update(filePath).update(String(version)).digest('hex');
const fileName = path.basename(filePath, path.extname(filePath)).replace(/\W/g, '') + '_' + hash; const fileName = path.basename(filePath, path.extname(filePath)).replace(/\W/g, '') + '_' + hash;
return path.join(cacheDir, hash[0] + hash[1], fileName); return path.join(cacheDir, hash[0] + hash[1], fileName);
} }
@ -60,7 +60,7 @@ export function transformHook(code: string, filename: string, tsconfig: TsConfig
const codePath = cachePath + '.js'; const codePath = cachePath + '.js';
const sourceMapPath = cachePath + '.map'; const sourceMapPath = cachePath + '.map';
sourceMaps.set(filename, sourceMapPath); sourceMaps.set(filename, sourceMapPath);
if (fs.existsSync(codePath)) if (!process.env.PW_IGNORE_COMPILE_CACHE && fs.existsSync(codePath))
return fs.readFileSync(codePath, 'utf8'); return fs.readFileSync(codePath, 'utf8');
// We don't use any browserslist data, but babel checks it anyway. // We don't use any browserslist data, but babel checks it anyway.
// Silence the annoying warning. // Silence the annoying warning.