|
| 1 | +import { execSync } from 'node:child_process'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import os from 'node:os'; |
1 | 4 | import path from 'node:path'; |
2 | 5 |
|
3 | | -export function linkPackage(pkg: string, tag?: string) { |
| 6 | +const tarballCache = new Map<string, string>(); |
| 7 | + |
| 8 | +const PACKAGES_REQUIRING_TARBALL = ['astro']; |
| 9 | + |
| 10 | +/** |
| 11 | + * Creates a tarball of a package and returns the file: protocol path to it. |
| 12 | + * This is needed for packages containing .astro files because Astro's Vite |
| 13 | + * plugin cannot properly resolve paths in symlinked packages. |
| 14 | + */ |
| 15 | +function createPackageTarball(pkg: string): string { |
| 16 | + if (tarballCache.has(pkg)) { |
| 17 | + return tarballCache.get(pkg); |
| 18 | + } |
| 19 | + |
| 20 | + const pkgPath = path.resolve(process.cwd(), `packages/${pkg}`); |
| 21 | + const tmpDir = path.join(os.tmpdir(), '.clerk-integration-tarballs'); |
| 22 | + |
| 23 | + fs.mkdirSync(tmpDir, { recursive: true }); |
| 24 | + |
| 25 | + const result = execSync('pnpm pack --pack-destination ' + tmpDir, { |
| 26 | + cwd: pkgPath, |
| 27 | + encoding: 'utf-8', |
| 28 | + }); |
| 29 | + |
| 30 | + const tgzPath = result.trim().split('\n').pop(); |
| 31 | + const tarballPath = `file:${tgzPath}`; |
| 32 | + |
| 33 | + tarballCache.set(pkg, tarballPath); |
| 34 | + return tarballPath; |
| 35 | +} |
| 36 | + |
| 37 | +export function linkPackage(pkg: string) { |
4 | 38 | // eslint-disable-next-line turbo/no-undeclared-env-vars |
5 | 39 | if (process.env.CI === 'true') { |
6 | 40 | // In CI, use '*' to get the latest version from Verdaccio |
7 | 41 | // which will be the snapshot version we just published |
8 | 42 | return '*'; |
9 | 43 | } |
10 | 44 |
|
| 45 | + // See: https://github.com/withastro/astro/issues/8312 |
| 46 | + if (PACKAGES_REQUIRING_TARBALL.includes(pkg)) { |
| 47 | + return createPackageTarball(pkg); |
| 48 | + } |
| 49 | + |
11 | 50 | return `link:${path.resolve(process.cwd(), `packages/${pkg}`)}`; |
12 | 51 | } |
0 commit comments