diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a85c19045..f530dba42 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,6 +71,7 @@ on: - "scripts/linux/**" - "scripts/mosh-extra-resources.cjs" - "scripts/nodePtyConptyPatch.cjs" + - "scripts/patch-xterm-macos-column-selection.cjs" - "scripts/patch-xterm-webgl-atlas.cjs" - "scripts/patch-xterm-macos-column-selection.cjs" - "scripts/rebuildPatchedNodePty.cjs" diff --git a/scripts/patch-xterm-macos-column-selection.cjs b/scripts/patch-xterm-macos-column-selection.cjs index dbd55956c..3a984bf75 100644 --- a/scripts/patch-xterm-macos-column-selection.cjs +++ b/scripts/patch-xterm-macos-column-selection.cjs @@ -87,6 +87,16 @@ function patchXtermSource(source, patch) { ); } +/** + * @param {string} root + * @param {Pick} fsImpl + */ +function invalidateViteCache(root = process.cwd(), fsImpl = fs) { + const cachePath = path.resolve(root, "node_modules/.vite"); + fsImpl.rmSync(cachePath, { recursive: true, force: true }); + return cachePath; +} + function patchInstalledXterm(root = process.cwd()) { const packageJsonPath = path.resolve(root, "node_modules/@xterm/xterm/package.json"); const version = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version; @@ -106,7 +116,8 @@ function patchInstalledXterm(root = process.cwd()) { changed++; } } - return { changed, checked: PATCHES.length, version }; + const viteCachePath = invalidateViteCache(root); + return { changed, checked: PATCHES.length, version, viteCachePath }; } if (require.main === module) { @@ -114,7 +125,7 @@ if (require.main === module) { const result = patchInstalledXterm(); console.log( `[patch-xterm-macos-column-selection] version=${result.version} ` + - `changed=${result.changed} checked=${result.checked}`, + `changed=${result.changed} checked=${result.checked} vite-cache=invalidated`, ); } catch (error) { console.error(`[patch-xterm-macos-column-selection] ERROR: ${error.message}`); @@ -125,6 +136,7 @@ if (require.main === module) { module.exports = { EXPECTED_XTERM_VERSION, PATCHES, + invalidateViteCache, patchInstalledXterm, patchXtermSource, replacementForPatch, diff --git a/scripts/patch-xterm-macos-column-selection.test.cjs b/scripts/patch-xterm-macos-column-selection.test.cjs index 7b3dc8aab..e3432c2fa 100644 --- a/scripts/patch-xterm-macos-column-selection.test.cjs +++ b/scripts/patch-xterm-macos-column-selection.test.cjs @@ -1,10 +1,12 @@ "use strict"; const assert = require("node:assert/strict"); +const path = require("node:path"); const test = require("node:test"); const { PATCHES, + invalidateViteCache, patchXtermSource, replacementForPatch, sameLengthExpression, @@ -54,3 +56,18 @@ test("fails closed when a generated-bundle replacement would shift offsets", () /replacement expression is too long/, ); }); + +test("invalidates Vite's optimized dependency cache after patching xterm", () => { + const calls = []; + const cachePath = invalidateViteCache("/repo", { + rmSync(target, options) { + calls.push({ target, options }); + }, + }); + + assert.equal(cachePath, path.resolve("/repo/node_modules/.vite")); + assert.deepEqual(calls, [{ + target: cachePath, + options: { recursive: true, force: true }, + }]); +});