diff --git a/.changeset/bold-spoons-act.md b/.changeset/bold-spoons-act.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/bold-spoons-act.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/integration/presets/astro.ts b/integration/presets/astro.ts index e9e310bf5fc..5b6b941485e 100644 --- a/integration/presets/astro.ts +++ b/integration/presets/astro.ts @@ -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']); diff --git a/integration/presets/utils.ts b/integration/presets/utils.ts index 21672d16b5b..b776eb91bfe 100644 --- a/integration/presets/utils.ts +++ b/integration/presets/utils.ts @@ -1,6 +1,40 @@ +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(); + +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 @@ -8,5 +42,10 @@ export function linkPackage(pkg: string, tag?: string) { 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}`)}`; }