All jobs

Fix _.pluck Is Not a Function After a Lodash 4 Upgrade

Yes. An agent bumps lodash from 3 to 4, runs the suite to catch the removed _.pluck, rewrites each call as _.map with a property name and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how lodash is used before touching the version. In a Node library like dthree/vantage, a CLI, SSH and REPL framework at 1.7.0, package.json pins "lodash": "3.10.0" exactly, with mocha ^2.2.5 and should as the test tools and "test": "mocha" as the script. A search of lib/ finds nine lodash helpers in use: _.isFunction, _.isObject, _.isArray, _.toArray, _.isString, _.defaults, _.extend, _.clone and, once, _.pluck, at lib/server.js line 149, inside the socket.io connection handler: if (_.pluck(self.sessions, "id").indexOf(ssnId) > -1) refuses a client that is already connected.

Then it runs the suite twice. On the pinned 3.10.0, test/client.js and test/firewall.js pass; test/integration.js, which starts servers on ports 8040 to 8042 and connects to them, passes its command and validation tests and can fail its navigation tests with Connection Error: 503 Service Unavailable in a sandbox, which the agent records as the baseline rather than a regression. After npm install lodash@4, the same npm test reports new failures, and they quote Uncaught TypeError: _.pluck is not a function, from the connection handler every later remote test depends on. A one-liner confirms it: typeof _.pluck is "undefined" on lodash 4 while _.map is a function.

The fix is the rename lodash 4 made: _.pluck(collection, "id") becomes _.map(collection, "id"), since _.map with a string iteratee reads that property from each element. The agent checks the other eight helpers against lodash 4 and finds them all present with the same meaning, so lib/server.js line 149 is the only code change, next to the version bump in package.json. With that one line changed, test/client.js and test/firewall.js pass again on lodash 4, and the integration suite is back to the baseline it had on 3.10.0.

It also writes down what else the upgrade run surfaced but did not fix. Node 22 prints [DEP0044] DeprecationWarning: The util.isArray API is deprecated while the integration tests run, from a dependency rather than lib/, which has no such call, and npm install lists the old hapi, joi and mkdirp releases as deprecated. Those go in the pull request as findings with their lines, so the lodash change stays one change.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Upgrade lodash from 3 to the current 4 release. Read package.json and list every lodash helper the code uses first. Run the test suite on the pinned version and record the result, then install lodash 4 and run it again, quoting the first failure with its file and line. For each helper lodash 4 renamed or removed, rewrite the call with the lodash 4 equivalent and say which rename it was; do not add a compatibility shim. Run the suite again to show it matches the baseline. Report any other deprecation the run prints, with its line, without fixing it. Open a pull request that quotes the failing and passing runs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request touching package.json and lib/server.js: the lodash range moved to the current 4 release and the single _.pluck call rewritten as _.map(self.sessions, "id"). The description lists the nine helpers found, marks _.pluck as the one lodash 4 removed, quotes TypeError: _.pluck is not a function from the upgraded run with its line, and shows the client and firewall suites passing again, with the integration suite's baseline identical before and after.

A reviewer checks that _.map with a property name returns the same array _.pluck did, that no other lodash 3 name slipped through (_.contains, _.where and _.any are the usual ones, and this library uses none), and that the baseline failures the agent quoted are environmental rather than new. The run's record has both test runs with their full output, so the failing run and the fixed run can be opened rather than taken on trust.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run bumps lodash, runs the suite and opens one pull request on its own branch; a week where a removed helper has no clean replacement ends needs_review with the failing test attached, and a week already on the current release opens nothing.

The same body works from your own code with POST /o/{org}/sessions and an API key when a dependency bot's lodash bump turns red; the key's webhook_url receives run.completed or run.failed with the session URL and the pull request when the run ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A major bump of a utility library fails at runtime, not at install: lodash 4 installs cleanly and the crash waits until the first client connects. The agent runs the suite in its sandbox at the old and the new version, so the pull request shows the exact helper that broke and the exact test that proved the rename, and every command with its output stays in the run's record.

The upgrade also depends on knowing which baseline failures are yours and which are the sandbox's. Because the agent runs the suite before changing anything, it can tell a navigation test that cannot open a port apart from a test the upgrade broke, and says so in the description instead of either hiding the failures or blaming the bump for them.

Frequently asked questions

Why was _.pluck removed?

Lodash 4 folded it into _.map: a string iteratee now means "read this property", so _.map(list, "id") does what _.pluck(list, "id") did. The same release renamed or merged several other helpers, which is why the agent lists every lodash call before upgrading rather than fixing failures one at a time.

Will it add lodash-migrate or a shim?

No. A shim keeps the lodash 3 names alive and hides the next removal. The prompt asks for the lodash 4 equivalent at each call site, and with one call to change there is nothing a shim would save.

What if more helpers are affected in my codebase?

The agent's first step is a list of every _. helper in use, checked against lodash 4. Each rename gets its own line in the pull request with the old and new name, so a reviewer can scan them, and the suite run after the change shows they behave the same.

Why does it report the util.isArray warning but not fix it?

Because it is Node's deprecation of a different API, unrelated to lodash, and it traces into a dependency rather than the library's own code. Mixing it into the upgrade would make the pull request harder to review; the agent names it so it can be its own change.

More jobs like this: Upgrade dependencies weekly

Keep reading