forked from vercel/vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.ts
52 lines (47 loc) · 1.62 KB
/
pack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
});