Skip to content

Conversation

techflare641
Copy link

This PR adds a new codemod to handle DEP0187 deprecation warnings by validating and converting invalid argument types to fs.existsSync().

Changes

  • Implements automatic conversion of invalid argument types (numbers, objects, null, etc.) to valid types (string, Buffer, or URL)
  • Handles both CommonJS (require) and ESM (import) syntax
  • Supports namespace imports, destructured imports, and direct usage
  • Adds type checks for variable arguments
  • Includes comprehensive test cases covering various scenarios

Examples

  • Literal values: fs.existsSync(123)fs.existsSync(String(123))
  • Null values: fs.existsSync(null)fs.existsSync(String(null || ''))
  • Variables: Adds runtime type check before the call
  • Valid arguments (strings, Buffer, URL) are left unchanged

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good starting ! to fix the red ci you have to run npm install on root of the repo to sync the npm lock file

@AugustinMauroy AugustinMauroy added the awaiting author Reviewer has requested something from the author label Oct 9, 2025
@avivkeller
Copy link
Member

I'm a little confused why this is needed? It fundamentally changes the output of pre-modded code, since it coercing previously non-String values to strings. I don't think this is a needed mod, wdyt @nodejs/userland-migrations @nodejs/fs

@AugustinMauroy AugustinMauroy added blocked:upstream Depends on another PR or external change/fix and removed awaiting author Reviewer has requested something from the author labels Oct 10, 2025
@JakobJingleheimer
Copy link
Member

Based on the examples in the OP, I think these are not something we should do: node itself could do this but doesn't, presumably, because there is too much assumption, and in some cases, those are smells of real problems (this would sweep those real problems under the rug, making the situation worse / harder to find).

If I've misunderstood, please do let me know.

@AugustinMauroy
Copy link
Member

So what is action point here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked:upstream Depends on another PR or external change/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: handle DEP0187: Passing invalid argument types to fs.existsSync

4 participants