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",