Visitar URL original
refactor(commons): Replace the `_` utilities with standalone functions (v6) by fratzinger · Pull Request #3724 · feathersjs/feathers · GitHub
Skip to content

refactor(commons): Replace the _ utilities with standalone functions (v6) - #3724

Open
fratzinger wants to merge 1 commit into
feathersjs:v6from
fratzinger:refactor/commons
Open

fratzinger wants to merge 1 commit into
feathersjs:v6from
fratzinger:refactor/commons

Conversation

@fratzinger

Copy link
Copy Markdown
Member

Summary

feathers/commons exported a lodash-like _ object. Feathers itself only uses _.pick (once, in the fetch client) and stripSlashes. Most of the other helpers have native replacements. Even the v5 ecosystem (adapter-commons, knex, mongodb, schema, rest-client, oauth) only used _.omit, _.pick and _.isObject. The commons are now a folder of standalone, typed functions:

 packages/feathers/src/
-├── commons.ts          # _ { each, some, every, keys, values, isMatch, isEmpty, isObject,
-│                       #     isObjectOrArray, extend, omit, pick, merge }, stripSlashes,
-│                       #     isPromise, createSymbol, export * from './debug.js'
-├── commons.test.ts
+└── commons/
+    ├── index.ts
+    ├── object.ts       # isObject, pick, omit (typed with generics)
+    ├── object.test.ts
+    ├── path.ts         # stripSlashes
+    └── path.test.ts
  • feathers/commons now exports exactly isObject, pick, omit and stripSlashes, in both the ESM and CJS builds.
  • _ is removed, together with isPromise, createSymbol and the debug re-export. The debug functions (createDebug, setDebug) are still exported from feathers.
  • SERVICE now uses Symbol.for('@feathersjs/service') directly instead of createSymbol(). The value is the same.
  • The typed pick found that toError in the fetch client picks address, port and config from a value whose type has none of them, so those fields are now declared on its parameter type. The ECONNREFUSED branch there looks like a leftover from the axios/request clients, since fetch rejects with a TypeError that has a cause. That is left for a follow-up.
  • Dropping merge also removes the code path that needed the prototype pollution fix in fix(feathers): skip prototype-polluting keys in _.merge #3689.

Since there is no _ object any more, bundlers can tree-shake unused helpers.

No related issues, and no dependencies on other PRs.

Evidence

import * as c from 'feathers/commons'   ->  isObject, omit, pick, stripSlashes
require('feathers/commons')             ->  isObject, omit, pick, stripSlashes
SERVICE === Symbol.for('@feathersjs/service')  ->  true
  • Before: Test Files 30 passed, Tests 497 passed | 1 skipped
    After: Test Files 31 passed, Tests 484 passed | 1 skipped. The 17 tests for _, isPromise and createSymbol are removed, and 4 tests for stripSlashes, isObject, pick and omit are added. npm test passes on Node.js 24 and 26, and CI is green on 20.x and 24.x.

Merge Danger

Door: two-way

Blast Radius: small

  • This is a breaking change for anyone using _, isPromise or createSymbol from feathers/commons in the v6 prereleases. Replacements for the migration guide:
    • _.keys / _.values / _.extend → Object.keys / Object.values / Object.assign
    • _.each / _.some / _.every → Object.entries() / Object.values().some() / .every()
    • _.isEmpty(x) → Object.keys(x).length === 0
    • _.merge → structuredClone or a custom deep merge
    • isPromise(x) → typeof x?.then === 'function'
    • createSymbol(name) → Symbol.for(name)
  • There are small conflicts with chore: Migrate to ESLint 10 flat config with @feathers-community/eslint-config (v6) #3721, which edits commons.test.ts and client/fetch.ts, and chore: Publish feathers as ESM only (v6) #3723, which edits the ./commons export. Whichever PR is merged second needs a rebase.

🤖 Generated with Claude Code

…s (v6)

`feathers/commons` exported a lodash-like `_` object. Feathers itself only
used `_.pick` and most of the other helpers have native replacements
(`Object.keys`, `Object.values`, `Object.assign`). The commons are now a
folder of standalone, typed functions:

- `feathers/commons` exports `isObject`, `pick`, `omit` and `stripSlashes`
- Remove `_` (`each`, `some`, `every`, `keys`, `values`, `isMatch`, `isEmpty`,
  `isObjectOrArray`, `extend`, `merge`), `isPromise`, `createSymbol` and the
  debug re-export (still available from `feathers`)
- `SERVICE` uses `Symbol.for()` directly (same value as before)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fratzinger
fratzinger requested a review from daffl October 22, 2026 06:57

This branch has not been deployed

No deployments
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.

1 participant