mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 04:22:01 +00:00
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 ```
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
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';
|
|
|
|
const repoRoot = join(__dirname, '..', '..', '..');
|
|
const pubDir = join(repoRoot, 'public');
|
|
|
|
async function main() {
|
|
console.log(`Building static frontend ${repoRoot}...`);
|
|
|
|
await fs.rm(pubDir, { recursive: true, force: true });
|
|
await fs.mkdir(pubDir);
|
|
|
|
const examples = await getExampleList();
|
|
const pathListAll = join(pubDir, 'list-all.json');
|
|
await fs.writeFile(pathListAll, JSON.stringify(examples));
|
|
|
|
const exampleDirs = await fs.readdir(join(repoRoot, 'examples'), {
|
|
withFileTypes: true,
|
|
});
|
|
|
|
const existingExamples = exampleDirs
|
|
.filter(dir => dir.isDirectory())
|
|
.map(dir => ({
|
|
name: dir.name,
|
|
visible: true,
|
|
suggestions: [],
|
|
}));
|
|
|
|
const oldExamples = Object.keys(mapOldToNew).map(key => ({
|
|
name: key,
|
|
visible: false,
|
|
suggestions: mapOldToNew[key],
|
|
}));
|
|
|
|
const pathList = join(pubDir, 'list.json');
|
|
await fs.writeFile(
|
|
pathList,
|
|
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);
|
|
for (const pkg of packages) {
|
|
const fullDir = join(packagesDir, pkg);
|
|
const packageJsonRaw = await fs.readFile(
|
|
join(fullDir, 'package.json'),
|
|
'utf-8'
|
|
);
|
|
const packageJson = JSON.parse(packageJsonRaw);
|
|
const tarballName = `${packageJson.name
|
|
.replace('@', '')
|
|
.replace('/', '-')}-v${packageJson.version}-${sha.trim()}.tgz`;
|
|
const destTarballPath = join(tarballsDir, `${packageJson.name}.tgz`);
|
|
await fs.mkdir(dirname(destTarballPath), { recursive: true });
|
|
await fs.copyFile(join(fullDir, tarballName), destTarballPath);
|
|
}
|
|
|
|
console.log('Completed building static frontend.');
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.log('error running build:', err);
|
|
process.exit(1);
|
|
});
|