Skip to content

Conversation

@AugustinMauroy
Copy link
Member

Description

Yeah it's not cover all possible case but I want to furnish a v1 for this codemod.

Thing to think

  • how to handle file ext
    • if a .cjs file is processed we need to update his importation on other file
    • update package.json export in conséquence
  • how can we detect when we need to do import pkg from 'pkg'; const { foo } = pkg;
    ...

Comment on lines 8 to 11
- `__filename` → `import.meta.filename` (Node.js v20.11.0 / v21.2.0)
- `__dirname` → `import.meta.dirname` (Node.js v20.11.0 / v21.2.0)
- `require.main` → `import.meta.main` (Node.js v22.18.0 / v24.2.0)
- `require.resolve` → `import.meta.resolve` (available)
Copy link
Member

Choose a reason for hiding this comment

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

These variables behave a bit differently. Wouldn't it be more one-to-one to use createRequire().resolve?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't pull this transformation out of thin air; it comes from this resource) that I decided to follow to the letter.

@AugustinMauroy AugustinMauroy mentioned this pull request Jan 22, 2026
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