-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
content(userland-migration
): make up to date
#8053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
--- | ||||||
title: Ecosystem to Node.js | ||||||
layout: learn | ||||||
authors: AugustinMauroy | ||||||
--- | ||||||
|
||||||
# Ecosystem to Node.js | ||||||
|
||||||
Sometimes the ecosystem creates awesome tools or libraries for node.js, but a native alternative is present in Node.js. So, this page shows you codemod that handle this case. | ||||||
|
||||||
## `correct-ts-specifiers` | ||||||
|
||||||
When you want to [run typescript natively in Node.js](/learn/typescript/run-natively), you need to have a correct "specifiers" in your [imports statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import). | ||||||
|
||||||
To run this codemdod, you have to use this command: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The word 'codemdod' should be 'codemod'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
```bash | ||||||
npx codemod@latest run correct-ts-specifiers | ||||||
``` | ||||||
|
||||||
> **Note:** This codemod use "legacy" codemod CLI, if you wan to undersant more about it, you can read the [new codemod CLI announcement](https://codemod.com/blog/new-codemod-cli). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple spelling errors: 'use' should be 'uses', 'wan' should be 'want', and 'undersant' should be 'understand'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can safely remove this "Note" section. it adds unnecessary confusion. Users don’t need to know which CLI is being used. When they run |
||||||
|
||||||
## Feedback | ||||||
|
||||||
If you have any tools that you would like to be handle by userland-migrations, please open an issue on the [Node.js Userland Migrations repository](https://github.com/nodejs/userland-migrations/issues). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The phrase 'to be handle' should be 'to be handled'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||||||||
--- | ||||||||||||
title: Userland Migrations | ||||||||||||
layout: learn | ||||||||||||
authors: JakobJingleheimer, AugustinMauroy | ||||||||||||
--- | ||||||||||||
|
||||||||||||
 | ||||||||||||
|
||||||||||||
# Userland Migrations | ||||||||||||
|
||||||||||||
Node.js provides migrations for "userland" (what you write vs node's own) source-code to facilitate adoption of new features and upgrading source-code affected by breaking changes. These are done in collaboration with [`codemod`](https://docs.codemod.com/introduction), who also work with other major projects like Next.js, React, and Tailwind. Node.js's migrations live in the [`nodejs/userland-migrations`](https://github.com/nodejs/userland-migrations) repository and are overseen by the `@nodejs/userland-migrations` team. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this paragraph was originally written by @JakobJingleheimer so let's see his opinon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some alternative: Node.js offers migrations for "userland" code (anything outside the |
||||||||||||
|
||||||||||||
<!-- | ||||||||||||
maintainer node: https://codemod.link/nodejs-official is pointing to legacy codemod registry | ||||||||||||
it's will point to new new one once codemod change the redirection of the short link | ||||||||||||
--> | ||||||||||||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that we have a maintainer note, can we can an ETA on this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed with Aviv. we don’t need to have such a note. We, the Codemod team, will update the same shortlink on August 8, 2025 to point to the new registry. (Besides link usage analytics, a key reason we use shortlinks is to avoid the maintenance overhead of updating links for users.) cc @mohebifar |
||||||||||||
|
||||||||||||
Official migrations are published under the `@nodejs` namespace within the [codemod registry](https://codemod.link/nodejs-official). These have been reviewed and/or authored by Node.js members. There are also unofficial migrations available which have not been reviewed by Node.js. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
## Our goal | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
First our goal is to help you to migrate your codebase to the latest Node.js version. We want to make it easier for you to adopt new features, deprecations, and breaking changes. In summary, we want to help you to migrate your codebase to the latest Node.js version. | ||||||||||||
|
||||||||||||
Second, we want to help you to adopt native Node.js features that are already available in the ecosystem. For example, if you are using a library that provides a feature that is already available in Node.js, we want to help you to migrate to the native Node.js feature. | ||||||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
## How to use a Codemod | ||||||||||||
|
||||||||||||
To use a codemod, you can run the following command in your terminal: | ||||||||||||
|
||||||||||||
```bash displayName="npm" | ||||||||||||
npx codemod@next <codemod-name> | ||||||||||||
``` | ||||||||||||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's only showcase npm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ? On download we explain how to install yarn pnpm so why not on this page show them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because if we showcase them, we are responsible for making that code work for our users. We are responsible for npm, not the other package managers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oof right |
||||||||||||
|
||||||||||||
```bash displayName="yarn" | ||||||||||||
yarn dlx codemod@next <codemod-name> | ||||||||||||
``` | ||||||||||||
|
||||||||||||
```bash displayName="pnpm" | ||||||||||||
pnpx codemod@next <codemod-name> | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Replace `<codemod-name>` with the name of the codemod you want to run. For example, if you want to run the `@nodejs/import-assertions-to-attributes` codemod on your project, you would run: | ||||||||||||
|
||||||||||||
```bash displayName="npm" | ||||||||||||
npx codemod@next @nodejs/import-assertions-to-attributes | ||||||||||||
``` | ||||||||||||
|
||||||||||||
```bash displayName="yarn" | ||||||||||||
yarn dlx codemod@next @nodejs/import-assertions-to-attributes | ||||||||||||
``` | ||||||||||||
|
||||||||||||
```bash displayName="pnpm" | ||||||||||||
pnpx codemod@next @nodejs/import-assertions-to-attributes | ||||||||||||
``` | ||||||||||||
|
||||||||||||
## Good Practices | ||||||||||||
|
||||||||||||
- **Run migrations in a separate branch**: If you are using a version control system like Git, it is a good practice to run migrations in a separate branch. This allows you to review the changes before merging them into your main branch. | ||||||||||||
- **Review changes**: After running a migration, review the changes made to your codebase. Ensure that the migration has not introduced any unintended side effects or issues. | ||||||||||||
- **Test your code**: After running a migration, it is important to test your code to ensure that everything is working as expected. Run your test suite and check for any errors or failures | ||||||||||||
|
||||||||||||
## Feedback | ||||||||||||
|
||||||||||||
If you have any feedback or suggestions for improvements, please open an issue on the [Node.js Userland Migrations repository](https://github.com/nodejs/userland-migrations/issues). | ||||||||||||
|
||||||||||||
## Follow the Userland Migrations Progression | ||||||||||||
|
||||||||||||
You can follow the progress of userland migrations on our [GitHub project board](https://github.com/orgs/nodejs/projects/13/views/1). | ||||||||||||
|
||||||||||||
This board tracks: | ||||||||||||
|
||||||||||||
- Codemod kind (deprecation, breaking change, ecosystem) | ||||||||||||
- Node.js version | ||||||||||||
- Status (backlog, todo, in progress, done, not planned) _If you want to contribute, please check the "todo" column_ |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to add an article for each version upgrade. IMO such articles should be blog posts / on the Codemod repository There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. react make it as a blog post https://react.dev/blog/2024/04/25/react-19-upgrade-guide So IMO here it's goo area. Also not that we cannot touch to release note There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's very different. A "doc" is different than an "article". The docs change from version to version. Articles here do not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #8053 (comment) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: Nodejs v14 to v16 | ||
layout: learn | ||
authors: AugustinMauroy | ||
--- | ||
|
||
# Nodejs v14 to v16 | ||
|
||
This page provides a list of codemods to help you migrate your code from Node.js v14 to v16. | ||
|
||
## `create-require-from-path` | ||
|
||
In Node.js v16, the `createRequire` function was introduced to allow you to create a `require` function that can be used in ESM modules. This codemod will help you replace the old `createRequireFromPath` function with the new `createRequire` function. | ||
|
||
So this codemod handle [DEP0130](https://nodejs.org/api/deprecations.html#DEP0130). | ||
|
||
```bash | ||
npx codemod@latest @nodejs/create-require-from-path | ||
``` | ||
|
||
Example: | ||
|
||
**Before:** | ||
|
||
```js | ||
import { createRequireFromPath } from 'node:module'; | ||
|
||
// Using createRequireFromPath | ||
const requireFromPath = createRequireFromPath('/path/to/module'); | ||
const myModule = requireFromPath('./myModule.cjs'); | ||
``` | ||
|
||
**After:** | ||
|
||
```js | ||
import { createRequire } from 'node:module'; | ||
|
||
// Using createRequire with a specific path | ||
const require = createRequire('/path/to/module'); | ||
const myModule = require('./myModule.cjs'); | ||
``` | ||
|
||
## `rmdir` | ||
|
||
In Node.js v16, the `fs.rmdir` function was deprecated in favor of `fs.rm` with the `{ recursive: true }` option. This codemod will help you replace the old `fs.rmdir` function with the new `fs.rm` function. | ||
|
||
so this codemod handle [DEP0147](https://nodejs.org/api/deprecations.html#DEP0147). | ||
|
||
```bash | ||
npx codemod@latest @nodejs/rmdir | ||
``` | ||
|
||
Example: | ||
|
||
**Before:** | ||
|
||
```js | ||
// Using fs.rmdir with the recursive option | ||
fs.rmdir(path, { recursive: true }, callback); | ||
|
||
// Using fs.rmdirSync with the recursive option | ||
fs.rmdirSync(path, { recursive: true }); | ||
|
||
// Using fs.promises.rmdir with the recursive option | ||
fs.promises.rmdir(path, { recursive: true }); | ||
``` | ||
|
||
**After:** | ||
|
||
```js | ||
// Using fs.rm with recursive and force options | ||
fs.rm(path, { recursive: true, force: true }, callback); | ||
|
||
// Using fs.rmSync with recursive and force options | ||
fs.rmSync(path, { recursive: true, force: true }); | ||
|
||
// Using fs.promises.rm with recursive and force options | ||
fs.promises.rm(path, { recursive: true, force: true }); | ||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||
--- | ||||||
title: Nodejs v20 to v22 | ||||||
layout: learn | ||||||
authors: AugustinMauroy | ||||||
--- | ||||||
|
||||||
# Nodejs v20 to v22 | ||||||
|
||||||
This page provides a list of codemods to help you migrate your code from Node.js v20 to v22. | ||||||
|
||||||
## `import-assertions-to-attributes` | ||||||
|
||||||
During the process of TC39 standardization, the `import assert` feature was introduced to allow importing [JSON modules](https://tc39.es/proposal-json-modules/) but during the during the transition to stage 4, the `assert` keyword was removed and replaced with an `with` attribute on the `import` statement. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The phrase 'but during the during the transition' contains a duplicated word 'during'. It should be 'but during the transition'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
So in [node.js v22](https://nodejs.org/fr/blog/release/v22.0.0#other-notable-changes), the `import assert` feature was removed and you need to use the `with` attribute instead. | ||||||
|
||||||
Also note that the `with` keyword as been introduce in [node.js v18.20](https://nodejs.org/fr/blog/release/v18.20.0#added-support-for-import-attributes) but it was not mandatory until v22. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The word 'introduce' should be 'introduced' (past participle form) and 'as' should be 'has'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
```bash | ||||||
npx codemod@latest @nodejs/import-assertions-to-attributes | ||||||
``` | ||||||
|
||||||
Example: | ||||||
|
||||||
```js | ||||||
import jsonData from './data.json' assert { type: 'json' }; | ||||||
// becomes | ||||||
import jsonData from './data.json' with { type: 'json' }; | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this file?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second part of your goal like. It's will host all codemod related to ecosystem not specific node version
jest-to-node-test
(pr opened)mocha-to-node-test
(issue opened)axios-to-fetch
(in my brain)correct-ts-specifiers
(released)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we outsource this list, since it'll change often, i.e. in the main file, have a paragraph about "Ecosystem" upgrades, and "Migration" upgrades, with a link to the list of each in the Codemod repository? This'll also resolve my concern at #8053 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it's solve that. But why I'm doing this pr is to use your cool UI to show our codemod