Skip to content

Commit 2c4ce1a

Browse files
authored
fix(repo): local astro integration tests (#7510)
1 parent c8c5086 commit 2c4ce1a

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

.changeset/bold-spoons-act.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/presets/astro.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ const astroNode = applicationConfig()
1111
.addScript('build', 'pnpm build')
1212
.addScript('serve', 'pnpm preview')
1313
.addDependency('@clerk/astro', linkPackage('astro'))
14+
.addDependency('@clerk/backend', linkPackage('backend'))
1415
.addDependency('@clerk/shared', linkPackage('shared'))
15-
.addDependency('@clerk/localizations', linkPackage('localizations'));
16+
.addDependency('@clerk/localizations', linkPackage('localizations'))
17+
// Resolutions ensure the tarball's transitive dependencies use our local packages
18+
.addResolution('@clerk/backend', linkPackage('backend'))
19+
.addResolution('@clerk/shared', linkPackage('shared'));
1620

1721
const astroStatic = astroNode.clone().setName('astro-hybrid').useTemplate(templates['astro-hybrid']);
1822

integration/presets/utils.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
1+
import { execSync } from 'node:child_process';
2+
import fs from 'node:fs';
3+
import os from 'node:os';
14
import path from 'node:path';
25

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) {
438
// eslint-disable-next-line turbo/no-undeclared-env-vars
539
if (process.env.CI === 'true') {
640
// In CI, use '*' to get the latest version from Verdaccio
741
// which will be the snapshot version we just published
842
return '*';
943
}
1044

45+
// See: https://github.com/withastro/astro/issues/8312
46+
if (PACKAGES_REQUIRING_TARBALL.includes(pkg)) {
47+
return createPackageTarball(pkg);
48+
}
49+
1150
return `link:${path.resolve(process.cwd(), `packages/${pkg}`)}`;
1251
}

0 commit comments

Comments
 (0)