Skip to content

Commit

Permalink
chore: reuse files in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Aug 25, 2021
1 parent de49150 commit f88cc7c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/plugin-compat/extra/typescript/gen-typescript-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,24 @@ async function run({from, to, onto, range}) {
}

async function validate(version, patchFile) {
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`);
const tmpDir = path.join(TMP_DIR, `v${version}`);
const tarball = path.join(tmpDir, `package.tgz`);

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

if (!fs.existsSync(tarball)) {
const data = await fetch(`https://registry.yarnpkg.com/typescript/-/typescript-${version}.tgz`);
await fs.promises.writeFile(tarball, data);
}

if (!fs.existsSync(path.join(tmpDir, `package`)))
await execFile(`tar`, [`xvf`, tarball], {cwd: tmpDir});

let patch = await fs.promises.readFile(patchFile, `utf8`);
patch = patch.replace(/^semver .*\n/gm, ``);
await fs.promises.writeFile(path.join(tmpDir, `patch.diff`), patch);

await execFile(`tar`, [`xvf`, tarball], {cwd: tmpDir});
await execFile(`git`, [`apply`, `../patch.diff`], {cwd: path.join(tmpDir, `package`)});
await execFile(`git`, [`apply`, `--check`, `../patch.diff`], {cwd: path.join(tmpDir, `package`)});
}

async function main() {
Expand Down

0 comments on commit f88cc7c

Please sign in to comment.