forked from vercel/vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Create tarballs of all packages in Vercel deployment (vercel#…
…7967) For the Vercel deployment, run `yarn pack` in each of the packages in the monorepo and place them in the "public/tarballs" directory so that we can have npm-installable URLs of each package for every commit. The `package.json` of each package is also updated to reference the tarball when a package depends on other packages within the monorepo. Try it out like: ``` $ npm i -g https://vercel-biww73ffq.vercel.sh/tarballs/vercel.tgz # Notice how the package.json has the monorepo dependencies # updated to point to the related tarballs from the same deployment: $ cat /usr/local/lib/node_modules/vercel/package.json | grep biww "@vercel/build-utils": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/build-utils.tgz", "@vercel/go": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/go.tgz", "@vercel/next": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/next.tgz", "@vercel/node": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/node.tgz", "@vercel/python": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/python.tgz", "@vercel/redwood": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/redwood.tgz", "@vercel/remix": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/remix.tgz", "@vercel/ruby": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/ruby.tgz", "@vercel/static-build": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/static-build.tgz", "@vercel/client": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/client.tgz", "@vercel/frameworks": "https://vercel-biww73ffq.vercel.sh/tarballs/@vercel/frameworks.tgz", # Also notice that the "version" in `package.json` gets updated to include the commit # SHA so that we can easily identify which commit a given tarball was generated from: $ vercel --version 25.1.1-canary.1-727b290 ```
- Loading branch information
1 parent
32ee6ab
commit 8167233
Showing
7 changed files
with
127 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1 @@ | ||
* | ||
|
||
# general | ||
!utils/ | ||
!utils/run.js | ||
!.yarnrc | ||
!yarn.lock | ||
!package.json | ||
!turbo.json | ||
|
||
# api | ||
!api/ | ||
!api/** | ||
|
||
# packages | ||
!packages/ | ||
!packages/frameworks | ||
!packages/frameworks/** | ||
packages/*/test/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import _pkg from '../../package.json'; | ||
import fs from 'fs'; | ||
import { join } from 'path'; | ||
import { PackageJson } from '@vercel/build-utils'; | ||
|
||
const pkg: PackageJson & typeof _pkg = _pkg; | ||
let rootDir = __dirname; | ||
while (!fs.existsSync(join(rootDir, 'package.json'))) { | ||
rootDir = join(rootDir, '..'); | ||
} | ||
|
||
const pkgPath = join(rootDir, 'package.json'); | ||
const pkg: PackageJson & typeof import('../../package.json') = JSON.parse( | ||
fs.readFileSync(pkgPath, 'utf8') | ||
); | ||
export default pkg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import execa from 'execa'; | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import { TurboDryRun } from './types'; | ||
|
||
const rootDir = path.join(__dirname, '..'); | ||
|
||
async function main() { | ||
const { stdout: sha } = await execa('git', ['rev-parse', '--short', 'HEAD'], { | ||
cwd: rootDir, | ||
}); | ||
const { stdout: turboStdout } = await execa( | ||
'turbo', | ||
['run', 'build', '--dry=json'], | ||
{ | ||
cwd: rootDir, | ||
} | ||
); | ||
const turboJson: TurboDryRun = JSON.parse(turboStdout); | ||
for (const task of turboJson.tasks) { | ||
const dir = path.join(rootDir, task.directory); | ||
const packageJsonPath = path.join(dir, 'package.json'); | ||
const originalPackageObj = await fs.readJson(packageJsonPath); | ||
const packageObj = await fs.readJson(packageJsonPath); | ||
packageObj.version += `-${sha.trim()}`; | ||
|
||
if (task.dependencies.length > 0) { | ||
for (const dependency of task.dependencies) { | ||
const name = dependency.split('#')[0]; | ||
const tarballUrl = `https://${process.env.VERCEL_URL}/tarballs/${name}.tgz`; | ||
if (packageObj.dependencies && name in packageObj.dependencies) { | ||
packageObj.dependencies[name] = tarballUrl; | ||
} | ||
if (packageObj.devDependencies && name in packageObj.devDependencies) { | ||
packageObj.devDependencies[name] = tarballUrl; | ||
} | ||
} | ||
} | ||
await fs.writeJson(packageJsonPath, packageObj, { spaces: 2 }); | ||
|
||
await execa('yarn', ['pack'], { | ||
cwd: dir, | ||
stdio: 'inherit', | ||
}); | ||
await fs.writeJson(packageJsonPath, originalPackageObj, { spaces: 2 }); | ||
} | ||
} | ||
|
||
main().catch(err => { | ||
console.log('error running pack:', err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"noEmitOnError": true, | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true | ||
}, | ||
"include": ["*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface TurboDryRun { | ||
packages: Array<string>; | ||
tasks: Array<Task>; | ||
} | ||
|
||
export interface Task { | ||
taskId: string; | ||
task: string; | ||
package: string; | ||
hash: string; | ||
command: string; | ||
outputs: Array<string>; | ||
logFile: string; | ||
directory: string; | ||
dependencies: Array<string>; | ||
dependents: Array<string>; | ||
} |