Skip to content

Commit ba1f9af

Browse files
committed
fix: bypass SFW shim for test installs (SFW strips registry time metadata)
1 parent 263ce37 commit ba1f9af

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

scripts/npm/install-npm-packages.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import {
104104
import { filterPackagesByChanges } from '../utils/git.mjs'
105105
import {
106106
copySocketOverride,
107+
PNPM_REAL_BIN,
107108
PNPM_HOISTED_INSTALL_FLAGS,
108109
PNPM_INSTALL_ENV,
109110
} from '../utils/package.mjs'
@@ -524,7 +525,7 @@ async function installPackage(packageInfo) {
524525
// If Socket override has different dependencies, install them.
525526
// Always use pnpm for installation to avoid npm override conflicts.
526527
if (overridePkgJson.dependencies) {
527-
await runCommandQuietStrict('pnpm', ['install'], {
528+
await runCommandQuietStrict(PNPM_REAL_BIN, ['install'], {
528529
cwd: installedPath,
529530
env: {
530531
...process.env,
@@ -539,7 +540,7 @@ async function installPackage(packageInfo) {
539540
// The hoisted install at parent level makes test runners available to nested package.
540541
// Always use pnpm for installation to avoid npm override conflicts.
541542
await runCommandQuietStrict(
542-
'pnpm',
543+
PNPM_REAL_BIN,
543544
['install', ...PNPM_HOISTED_INSTALL_FLAGS],
544545
{
545546
cwd: packageTempDir,
@@ -778,7 +779,7 @@ async function installPackage(packageInfo) {
778779
await pRetry(
779780
async () => {
780781
await runCommandQuietStrict(
781-
'pnpm',
782+
PNPM_REAL_BIN,
782783
['install', ...PNPM_HOISTED_INSTALL_FLAGS],
783784
{
784785
cwd: packageTempDir,
@@ -816,7 +817,7 @@ async function installPackage(packageInfo) {
816817
// Always use pnpm for installation to avoid npm override conflicts.
817818
writeProgress('👷')
818819
await runCommandQuietStrict(
819-
'pnpm',
820+
PNPM_REAL_BIN,
820821
['install', ...PNPM_HOISTED_INSTALL_FLAGS],
821822
{
822823
cwd: packageTempDir,
@@ -940,7 +941,7 @@ async function installPackage(packageInfo) {
940941
// If Socket override has different dependencies, install them.
941942
// Always use pnpm for installation to avoid npm override conflicts.
942943
if (overridePkgJson.dependencies) {
943-
await runCommandQuietStrict('pnpm', ['install'], {
944+
await runCommandQuietStrict(PNPM_REAL_BIN, ['install'], {
944945
cwd: installedPath,
945946
env: {
946947
...process.env,
@@ -955,7 +956,7 @@ async function installPackage(packageInfo) {
955956
// The hoisted install at parent level makes test runners available to nested package.
956957
// Always use pnpm for installation to avoid npm override conflicts.
957958
await runCommandQuietStrict(
958-
'pnpm',
959+
PNPM_REAL_BIN,
959960
['install', ...PNPM_HOISTED_INSTALL_FLAGS],
960961
{
961962
cwd: packageTempDir,

scripts/utils/package.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,37 @@ import { readPackageJson } from '@socketsecurity/lib/packages/operations'
1414
import { pEach } from '@socketsecurity/lib/promises'
1515
import { withSpinner } from '@socketsecurity/lib/spinner'
1616

17+
import { whichSync } from '@socketsecurity/lib/bin'
18+
1719
import { cleanTestScript } from '../../test/utils/script-cleaning.mjs'
1820
import { testRunners } from '../../test/utils/test-runners.mjs'
1921
import { DEFAULT_CONCURRENCY } from '../constants/core.mjs'
2022
import { ROOT_PATH } from '../constants/paths.mjs'
2123
import { spawn } from './spawn.mjs'
2224
import process from 'node:process'
2325

26+
// Resolve real pnpm binary, bypassing SFW shim.
27+
// SFW shims intercept pnpm and proxy registry requests, stripping metadata
28+
// fields (e.g. "time") which causes pnpm v11 ERR_PNPM_MISSING_TIME failures.
29+
// Strip the SFW shim dir from PATH to find the real binary.
30+
function getRealPnpmBin() {
31+
const sfwShimDir = process.env['SFW_SHIM_DIR']
32+
if (sfwShimDir) {
33+
const cleanPath = (process.env['PATH'] ?? '')
34+
.split(path.delimiter)
35+
.filter(p => p !== sfwShimDir)
36+
.join(path.delimiter)
37+
const real = whichSync('pnpm', { nothrow: true, path: cleanPath })
38+
if (real && typeof real === 'string') {
39+
return real
40+
}
41+
}
42+
return 'pnpm'
43+
}
44+
45+
/** Real pnpm binary path (bypasses SFW shim if present). */
46+
export const PNPM_REAL_BIN = getRealPnpmBin()
47+
2448
// Shared pnpm flags to make it behave like npm with hoisting.
2549
const PNPM_NPM_LIKE_FLAGS = [
2650
'--config.shamefully-hoist=true',

0 commit comments

Comments
 (0)