From 0bafea6d5102271b9fc37d43e94c526cec44e331 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 13 Sep 2022 14:08:45 -0400 Subject: [PATCH] [tests] Fix tarball lookup with sha contains 0 (#8552) This PR fixes an issue when the sha begins with `0` and causes [an error](https://vercel.com/vercel/vercel/EP7fVcXKsoodzWRy3fwG8AoeQcs6) when looking up the tarball: > Error: ENOENT: no such file or directory, > copyfile '/vercel/path0/packages/build-utils/vercel-build-utils-v5.4.2-0251253.tgz' > -> '/vercel/path0/public/tarballs/@vercel/build-utils.tgz' The fix is to no longer rely on the exact tarball name because we can't guarantee the name from `yarn pack` and instead rely on a pattern for the tarball name. --- api/_lib/script/build.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/_lib/script/build.ts b/api/_lib/script/build.ts index 38c627e14..10bc86fd8 100644 --- a/api/_lib/script/build.ts +++ b/api/_lib/script/build.ts @@ -1,6 +1,5 @@ import fs from 'fs/promises'; import { join, dirname } from 'path'; -import execa from 'execa'; import { getExampleList } from '../examples/example-list'; import { mapOldToNew } from '../examples/map-old-to-new'; @@ -47,10 +46,6 @@ async function main() { JSON.stringify([...existingExamples, ...oldExamples]) ); - const { stdout: sha } = await execa('git', ['rev-parse', '--short', 'HEAD'], { - cwd: repoRoot, - }); - const tarballsDir = join(pubDir, 'tarballs'); const packagesDir = join(repoRoot, 'packages'); const packages = await fs.readdir(packagesDir); @@ -61,12 +56,21 @@ async function main() { 'utf-8' ); const packageJson = JSON.parse(packageJsonRaw); - const tarballName = `${packageJson.name - .replace('@', '') - .replace('/', '-')}-v${packageJson.version}-${sha.trim()}.tgz`; + const files = await fs.readdir(fullDir); + const tarballName = files.find(f => /^vercel-.+\.tgz$/.test(f)); + if (!tarballName) { + throw new Error( + `Expected vercel-*.tgz in ${fullDir} but found ${JSON.stringify( + files, + null, + 2 + )}` + ); + } + const srcTarballPath = join(fullDir, tarballName); const destTarballPath = join(tarballsDir, `${packageJson.name}.tgz`); await fs.mkdir(dirname(destTarballPath), { recursive: true }); - await fs.copyFile(join(fullDir, tarballName), destTarballPath); + await fs.copyFile(srcTarballPath, destTarballPath); } console.log('Completed building static frontend.');