Skip to content

Conversation

@jdalton
Copy link
Contributor

@jdalton jdalton commented Nov 14, 2025

Summary

Fixes #911

The socket-npm and socket-npx commands were failing with "rawBinArgs.findLast is not a function" errors. The root cause was incorrect argument passing in the shadow bin wrapper scripts.

Problem

The shadow-bin/npm and shadow-bin/npx wrapper scripts were incorrectly passing the bin name as the first argument:

// Before - WRONG
shadowNpmBin('npm', process.argv.slice(2), { stdio: 'inherit' })
shadowNpmBin('npx', process.argv.slice(2), { stdio: 'inherit' })

This caused the function parameters to shift:

  • args parameter received the string 'npm' or 'npx' instead of an array
  • When the code executed args.slice(0, terminatorPos), it returned a string
  • Strings don't have the findLast() method, causing the error

Solution

shadow-bin/npm: Removed the 'npm' argument since it's already hardcoded in shadowNpmBin()

shadow-bin/npx:

  • Switched to use the correct shadowNpxBin function instead of shadowNpmBin
  • Removed the 'npx' argument since it's already hardcoded in shadowNpxBin()

Testing

Added comprehensive unit tests for both functions:

  • Array argument handling
  • Readonly array support
  • Empty array handling
  • Terminator (--) handling
  • Validates findLast() works correctly
  • Progress flag identification using findLast()

All 12 new tests pass.

Changes

  • Modified 2 files (shadow-bin wrappers)
  • Added 2 test files (254 lines of tests)
  • Total: 257 insertions, 3 deletions

Note

Fixes argument passing in shadow-bin/npm and shadow-bin/npx and adds tests to validate array handling and findLast behavior.

  • CLI wrappers:
    • Update shadow-bin/npm to call shadowNpmBin(process.argv.slice(2), ...) (remove hardcoded bin arg).
    • Update shadow-bin/npx to require dist/shadow-npx-bin.js and call shadowNpxBin(process.argv.slice(2), ...).
  • Tests:
    • Add src/shadow/npm/bin.test.mts and src/shadow/npx/bin.test.mts covering:
      • Array/readonly args, empty args, -- terminator handling.
      • No findLast errors and correct progress flag resolution.

Written by Cursor Bugbot for commit 99f023f. Configure here.

The shadow-bin/npm and shadow-bin/npx files were incorrectly passing the
bin name ('npm'/'npx') as the first argument, which caused args to be
set to a string instead of an array. This resulted in 'findLast is not
a function' errors because strings don't have the findLast method.

- shadow-bin/npm: Remove 'npm' argument (already hardcoded in shadowNpmBin)
- shadow-bin/npx: Use correct shadowNpxBin function and remove 'npx' argument

Fixes #911
Tests validate that args parameter is correctly passed as an array and
that Array.prototype.findLast() works properly. These tests prevent
regression of issue #911 where incorrect argument passing caused args
to be a string instead of an array.

Tests cover:
- Array argument handling
- Readonly array support
- Empty array handling
- Terminator (--) handling
- findLast method availability
- Progress flag identification using findLast
@jdalton jdalton merged commit 245c1e8 into v1.x Nov 15, 2025
7 checks passed
@jdalton jdalton deleted the jdalton/issue-911 branch November 15, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants