Skip to content

Commit

Permalink
build: cache tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Aug 25, 2021
1 parent de49150 commit bc5da06
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/plugin-compat/extra/typescript/gen-typescript-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,16 @@ async function run({from, to, onto, range}) {
}

async function validate(version, patchFile) {
const tarball = path.join(TMP_DIR, `tarballs/typescript-${version}.tgz`);
if (!fs.existsSync(tarball)) {
const data = await fetch(`https://registry.yarnpkg.com/typescript/-/typescript-${version}.tgz`);
await fs.promises.mkdir(path.dirname(tarball), {recursive: true});
await fs.promises.writeFile(tarball, data);
}

const code = Math.floor(Math.random() * 0x100000000).toString(16).padStart(8, `0`);
const tmpDir = path.join(TMP_DIR, `${code}`);

const data = await fetch(`https://registry.yarnpkg.com/typescript/-/typescript-${version}.tgz`);
const tarball = path.join(tmpDir, `typescript.tgz`);

await fs.promises.mkdir(tmpDir, {recursive: true});
await fs.promises.writeFile(tarball, data);

let patch = await fs.promises.readFile(patchFile, `utf8`);
patch = patch.replace(/^semver .*\n/gm, ``);
Expand Down

0 comments on commit bc5da06

Please sign in to comment.