Skip to content

Commit ac8a2fe

Browse files
committed
fix: strip pnpm npm_config env vars before calling pkglab add
pnpm leaks npm_config_registry=https://registry.npmjs.org/ into child processes when running scripts. This overrides the .npmrc that pkglab writes, causing npm to resolve packages from the public registry instead of the local pkglab registry, resulting in ETARGET errors.
1 parent 8a52ae8 commit ac8a2fe

2 files changed

Lines changed: 8 additions & 41 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -390,40 +390,6 @@ jobs:
390390
- name: Edit .npmrc [link-workspace-packages=false]
391391
run: sed -i -E 's/link-workspace-packages=(deep|true)/link-workspace-packages=false/' .npmrc
392392

393-
# Install published packages from local registry to test against real npm install scenarios
394-
# rather than local monorepo builds. Validates package structure, dependencies, and entry points.
395-
- name: Debug pkglab registry
396-
if: ${{ steps.task-status.outputs.affected == '1' }}
397-
run: |
398-
echo "=== pkglab version ==="
399-
pkglab --version
400-
echo "=== pkglab status ==="
401-
pkglab status
402-
echo "=== resolve exact version ==="
403-
VERSION=$(curl -s http://127.0.0.1:16180/@clerk/nextjs | python3 -c "import sys,json; print(json.load(sys.stdin).get('dist-tags',{}).get('pkglab',''))")
404-
echo "Resolved version: $VERSION"
405-
echo "=== npm view exact version ==="
406-
npm view "@clerk/nextjs@$VERSION" version --registry http://127.0.0.1:16180 2>&1 || echo "npm view FAILED"
407-
echo "=== npm install exact version in temp dir ==="
408-
TESTDIR=$(mktemp -d)
409-
cd $TESTDIR
410-
npm init -y > /dev/null 2>&1
411-
echo "registry=http://127.0.0.1:16180" > .npmrc
412-
npm install "@clerk/nextjs@$VERSION" --ignore-scripts 2>&1 || echo "npm install FAILED"
413-
echo "=== npm install INSIDE pnpm exec ==="
414-
TESTDIR2=$(mktemp -d)
415-
cd $TESTDIR2
416-
npm init -y > /dev/null 2>&1
417-
echo "registry=http://127.0.0.1:16180" > .npmrc
418-
pnpm exec npm install "@clerk/nextjs@$VERSION" --ignore-scripts 2>&1 || echo "pnpm exec npm install FAILED"
419-
echo "=== env vars inside pnpm exec ==="
420-
pnpm exec env 2>&1 | grep -i "npm_config\|registry" || true
421-
echo "=== pkglab add inside pnpm exec ==="
422-
TESTDIR3=$(mktemp -d)
423-
cd $TESTDIR3
424-
npm init -y > /dev/null 2>&1
425-
pnpm exec pkglab add @clerk/nextjs 2>&1 || echo "pnpm exec pkglab add FAILED"
426-
427393
- name: Install @clerk/clerk-js in os temp
428394
if: ${{ steps.task-status.outputs.affected == '1' }}
429395
working-directory: ${{runner.temp}}

integration/models/application.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ export const application = (
5050
// Use pkglab add to pin @clerk/* packages to local registry versions and install
5151
const clerkDeps = config.clerkDependencies;
5252
if (clerkDeps.length > 0) {
53-
// Debug: capture environment that will be inherited by pkglab/npm
54-
log(`[debug] appDirPath: ${appDirPath}`);
55-
log(`[debug] npm_config env vars:`);
53+
// pnpm leaks npm_config_* env vars (e.g. npm_config_registry) into child
54+
// processes. These override the .npmrc that pkglab writes, causing npm to
55+
// resolve packages from the public registry instead of the local one.
56+
// Strip them so pkglab's .npmrc takes effect.
57+
const cleanEnv: Record<string, string> = {};
5658
for (const [k, v] of Object.entries(process.env)) {
57-
if (k.toLowerCase().startsWith('npm_config') || k.toLowerCase().includes('registry')) {
58-
log(`[debug] ${k}=${v}`);
59+
if (!k.startsWith('npm_config_') && !k.startsWith('npm_package_')) {
60+
cleanEnv[k] = v as string;
5961
}
6062
}
61-
await run('npm config get registry', { cwd: appDirPath, log });
62-
await run(`pkglab add ${clerkDeps.join(' ')} --verbose`, { cwd: appDirPath, log });
63+
await run(`pkglab add ${clerkDeps.join(' ')}`, { cwd: appDirPath, env: cleanEnv, log });
6364
} else {
6465
await run(scripts.setup, { cwd: appDirPath, log });
6566
}

0 commit comments

Comments
 (0)