From 0379f824bcdb84241d55f4d59886ceca69b36d75 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Thu, 21 May 2026 17:36:06 +0100 Subject: [PATCH] chore: add a tool to decompress cache keys As a means to make it more straightforward when testing. --- tools/uncache.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/uncache.ts diff --git a/tools/uncache.ts b/tools/uncache.ts new file mode 100644 index 00000000000..73a1eace732 --- /dev/null +++ b/tools/uncache.ts @@ -0,0 +1,42 @@ +/** + * Decompress and unencode values from the Package Cache or Repository Cache. + * + * Usage: + * + * node tools/uncache.ts "$(redis-cli get "datasource-npm:cache-provider-https://registry.npmjs.org/nock")" + * node tools/uncache.ts ~/Downloads/cache.json + * node tools/uncache.ts G0ohAAQi1GVVr/....... + * + * Supports: + * + * - cache values from the Package Cache + * - cache values from the Repository Cache + */ +import fs from 'fs-extra'; +import { decompressFromBase64 } from '../lib/util/compress.ts'; + +const input = process.argv[2]; + +let toDecode = undefined; + +if (input.startsWith('{')) { + const encoded = JSON.parse(input); + toDecode = + // if it's from the Package Cache + encoded.value ?? + // if it's from the Repository Cache + encoded.payload; +} else if (await fs.exists(input)) { + const encoded = JSON.parse(await fs.readFile(input, 'utf8')); + + toDecode = + // if it's from the Package Cache + encoded.value ?? + // if it's from the Repository Cache + encoded.payload; +} else { + toDecode = input; +} + +// oxlint-disable-next-line no-console -- intentional: not production code +console.log(await decompressFromBase64(toDecode));