Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/bold-spoons-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
6 changes: 5 additions & 1 deletion integration/presets/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ const astroNode = applicationConfig()
.addScript('build', 'pnpm build')
.addScript('serve', 'pnpm preview')
.addDependency('@clerk/astro', linkPackage('astro'))
.addDependency('@clerk/backend', linkPackage('backend'))
.addDependency('@clerk/shared', linkPackage('shared'))
.addDependency('@clerk/localizations', linkPackage('localizations'));
.addDependency('@clerk/localizations', linkPackage('localizations'))
// Resolutions ensure the tarball's transitive dependencies use our local packages
.addResolution('@clerk/backend', linkPackage('backend'))
.addResolution('@clerk/shared', linkPackage('shared'));

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

Expand Down
41 changes: 40 additions & 1 deletion integration/presets/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

export function linkPackage(pkg: string, tag?: string) {
const tarballCache = new Map<string, string>();

const PACKAGES_REQUIRING_TARBALL = ['astro'];

/**
* Creates a tarball of a package and returns the file: protocol path to it.
* This is needed for packages containing .astro files because Astro's Vite
* plugin cannot properly resolve paths in symlinked packages.
*/
function createPackageTarball(pkg: string): string {
if (tarballCache.has(pkg)) {
return tarballCache.get(pkg);
}

const pkgPath = path.resolve(process.cwd(), `packages/${pkg}`);
const tmpDir = path.join(os.tmpdir(), '.clerk-integration-tarballs');

fs.mkdirSync(tmpDir, { recursive: true });

const result = execSync('pnpm pack --pack-destination ' + tmpDir, {
cwd: pkgPath,
encoding: 'utf-8',
});

const tgzPath = result.trim().split('\n').pop();
const tarballPath = `file:${tgzPath}`;

tarballCache.set(pkg, tarballPath);
return tarballPath;
}

export function linkPackage(pkg: string) {
// eslint-disable-next-line turbo/no-undeclared-env-vars
if (process.env.CI === 'true') {
// In CI, use '*' to get the latest version from Verdaccio
// which will be the snapshot version we just published
return '*';
}

// See: https://github.com/withastro/astro/issues/8312
if (PACKAGES_REQUIRING_TARBALL.includes(pkg)) {
return createPackageTarball(pkg);
}

return `link:${path.resolve(process.cwd(), `packages/${pkg}`)}`;
}
Loading