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
Jan Kassens committed
Oct 6, 2022 at 16:59 UTC
e575e22925f4dcb6e04cb21b98bf9dc6f90207ba
3 files changed
+19
-2
compiler/forget/package.json
+1
-1
@@ -8,7 +8,7 @@
8
"src"
9
],
10
"scripts": {
11
- "build": "tsc",
11
+ "build": "tsc && scripts/hash-dist.sh",
12
"bundle:meta": "scripts/bundle-meta.sh",
13
"dev": "concurrently \"yarn:build --watch\" \"yarn:playground\"",
14
"playground": "cd packages/playground && yarn && yarn dev",
compiler/forget/scripts/hash-dist.sh
new
+6
@@ -0,0 +1,6 @@
1
+#!/usr/bin/env bash
2
+set -eo pipefail
3
+
4
+# Hashes JS files in the dist directory to create a cache-breaker
5
+
6
+find dist -name '*.js' | sort | xargs shasum | shasum | awk '{ print $1 }' > dist/HASH
compiler/forget/scripts/jest/makeTransform.js
+12
-1
@@ -7,6 +7,7 @@
7
8
const ReactForgetBabelPlugin = require("../../dist").default;
9
const babelJest = require("babel-jest");
10
+const { readFileSync } = require("fs");
11
12
module.exports = (useForget) => {
13
function createTransformer() {
@@ -17,7 +18,17 @@ module.exports = (useForget) => {
18
{
19
plugins: [
20
"@babel/plugin-syntax-jsx",
20
- ...(useForget ? [ReactForgetBabelPlugin, {}] : []),
21
+ ...(useForget
22
+ ? [
23
+ [
24
+ ReactForgetBabelPlugin,
25
+ {
26
+ // Jest hashes the babel config as a cache breaker.
27
+ cacheBreaker: readFileSync("dist/HASH", "utf8"),
28
+ },
29
+ ],
30
+ ]
31
+ : []),
32
],
33
},
34
"@babel/preset-react",