From e575e22925f4dcb6e04cb21b98bf9dc6f90207ba Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Thu, 6 Oct 2022 16:59:12 -0400 Subject: [PATCH] Add hash of Babel plugin to Jest transform Jest caches based on the hash of the babel config. This caused us to not break that cache when the we made changes to the plugin. Fixes #643 --- compiler/forget/package.json | 2 +- compiler/forget/scripts/hash-dist.sh | 6 ++++++ compiler/forget/scripts/jest/makeTransform.js | 13 ++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 compiler/forget/scripts/hash-dist.sh diff --git a/compiler/forget/package.json b/compiler/forget/package.json index 4b13049a0f..c2982f58e1 100644 --- a/compiler/forget/package.json +++ b/compiler/forget/package.json @@ -8,7 +8,7 @@ "src" ], "scripts": { - "build": "tsc", + "build": "tsc && scripts/hash-dist.sh", "bundle:meta": "scripts/bundle-meta.sh", "dev": "concurrently \"yarn:build --watch\" \"yarn:playground\"", "playground": "cd packages/playground && yarn && yarn dev", diff --git a/compiler/forget/scripts/hash-dist.sh b/compiler/forget/scripts/hash-dist.sh new file mode 100755 index 0000000000..8c060ac31d --- /dev/null +++ b/compiler/forget/scripts/hash-dist.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail + +# Hashes JS files in the dist directory to create a cache-breaker + +find dist -name '*.js' | sort | xargs shasum | shasum | awk '{ print $1 }' > dist/HASH diff --git a/compiler/forget/scripts/jest/makeTransform.js b/compiler/forget/scripts/jest/makeTransform.js index 99bce4bf21..8fe8112ae1 100644 --- a/compiler/forget/scripts/jest/makeTransform.js +++ b/compiler/forget/scripts/jest/makeTransform.js @@ -7,6 +7,7 @@ const ReactForgetBabelPlugin = require("../../dist").default; const babelJest = require("babel-jest"); +const { readFileSync } = require("fs"); module.exports = (useForget) => { function createTransformer() { @@ -17,7 +18,17 @@ module.exports = (useForget) => { { plugins: [ "@babel/plugin-syntax-jsx", - ...(useForget ? [ReactForgetBabelPlugin, {}] : []), + ...(useForget + ? [ + [ + ReactForgetBabelPlugin, + { + // Jest hashes the babel config as a cache breaker. + cacheBreaker: readFileSync("dist/HASH", "utf8"), + }, + ], + ] + : []), ], }, "@babel/preset-react",