-
-
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
Open
AugustinMauroy
wants to merge
6
commits into
main
Choose a base branch
from
content(`userland-migration`)
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a85ba97
content(`userland-migration`): make up to date
AugustinMauroy 79e1961
Update introduction.md
AugustinMauroy c938bbb
update
AugustinMauroy e870fa1
Update navigation.json
AugustinMauroy c4cc994
Update
AugustinMauroy e98d32d
use correct casing
AugustinMauroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
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 codemod, you have to use this command: | ||
|
||
```bash | ||
npx codemod run @nodejs/correct-ts-specifiers | ||
``` | ||
|
||
## 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). | ||
AugustinMauroy marked this conversation as resolved.
Show resolved
Hide resolved
|
52 changes: 52 additions & 0 deletions
52
apps/site/pages/en/learn/userland-migrations/introduction.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: Userland Migrations | ||
layout: learn | ||
authors: JakobJingleheimer, AugustinMauroy | ||
--- | ||
|
||
 | ||
|
||
# Userland Migrations | ||
|
||
Node.js offers migrations for "userland" code (anything outside the node executable) to help adopt new features and handle breaking changes. These are built in collaboration with [Codemod](https://codemod.com), a platform focused on making it easy to build, share, and run codemods. | ||
|
||
Official migrations are published under the `@nodejs` scope within the [Codemod registry](https://codemod.link/nodejs-official). These have been reviewed and/or authored by Node.js members. | ||
|
||
## Goal | ||
|
||
The Node.js Userland Migrations team seeks to help developers migrate their codebases to the latest Node.js versions, making it easier to handle deprecations, new features, and breaking changes. | ||
|
||
## How to use a Codemod | ||
|
||
To use a codemod, you can run the following command in your terminal: | ||
|
||
```bash | ||
npx codemod <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 | ||
npx codemod @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 | ||
- **Format and or lint your code**: After running a migration, it is a good practice to format and lint your code. This ensures that your code follows the project's coding standards and is easier to read and maintain. | ||
|
||
## 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_ |
123 changes: 123 additions & 0 deletions
123
apps/site/pages/en/learn/userland-migrations/v14-to-v16.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: Node.js v14 to v16 | ||
layout: learn | ||
authors: AugustinMauroy | ||
--- | ||
|
||
# Node.js 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 run @nodejs/create-require-from-path | ||
``` | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
import { createRequireFromPath } from 'node:module'; | ||
|
||
// Using createRequireFromPath | ||
const requireFromPath = createRequireFromPath('/path/to/module'); | ||
const myModule = requireFromPath('./myModule.cjs'); | ||
``` | ||
|
||
```js displayName="After" | ||
import { createRequire } from 'node:module'; | ||
|
||
// Using createRequire with a specific path | ||
const require = createRequire('/path/to/module'); | ||
const myModule = require('./myModule.cjs'); | ||
``` | ||
|
||
## `process-main-module` | ||
|
||
The `process.mainModule` property was deprecated in favor of `require.main`. This codemod will help you replace the old `process.mainModule` usage with the new `require.main` usage. | ||
|
||
So the codemod handle [DEP0138](https://nodejs.org/api/deprecations.html#DEP0138). | ||
|
||
```bash | ||
npx codemod run @nodejs/process-main-module | ||
``` | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
if (process.mainModule === 'mod.js') { | ||
// cli thing | ||
} else { | ||
// module thing | ||
} | ||
``` | ||
|
||
```js displayName="After" | ||
if (require.main === 'mod.js') { | ||
// cli thing | ||
} else { | ||
// module thing | ||
} | ||
``` | ||
|
||
## `rmdir` | ||
|
||
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 run @nodejs/rmdir | ||
``` | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
// 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 }); | ||
``` | ||
|
||
```js displayName="After" | ||
// 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 }); | ||
``` | ||
|
||
## `tmpDir-to-tmpdir` | ||
|
||
The `tmpDir` function was renamed to `tmpdir` in Node.js v16. This codemod will help you replace all instances of `tmpDir` with `tmpdir`. | ||
|
||
So the codemod handles [DEP0022](https://nodejs.org/docs/latest/api/deprecations.html#dep0022-ostmpdir). | ||
|
||
```bash | ||
npx codemod run @nodejs/tmpDir-to-tmpdir | ||
``` | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
import { tmpDir } from 'node:os'; | ||
|
||
const foo = tmpDir(); | ||
``` | ||
|
||
```js displayName="After" | ||
import { tmpdir } from 'node:os'; | ||
|
||
const foo = tmpdir(); | ||
``` |
31 changes: 31 additions & 0 deletions
31
apps/site/pages/en/learn/userland-migrations/v20-to-v22.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: Node.js v20 to v22 | ||
layout: learn | ||
authors: AugustinMauroy | ||
--- | ||
|
||
# Node.js 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. | ||
AugustinMauroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. | ||
AugustinMauroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
npx codemod run @nodejs/import-assertions-to-attributes | ||
``` | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
import jsonData from './data.json' assert { type: 'json' }; | ||
``` | ||
|
||
```js displayName="After" | ||
import jsonData from './data.json' with { type: 'json' }; | ||
``` |
47 changes: 47 additions & 0 deletions
47
apps/site/pages/en/learn/userland-migrations/v22-to-v24.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Node.js v22 to v24 | ||
layout: learn | ||
authors: AugustinMauroy | ||
--- | ||
|
||
# Node.js v22 to v24 | ||
|
||
This page provides a list of codemods to help you migrate your code from Node.js v22 to v24. | ||
|
||
## `fs-access-mode-constants` | ||
|
||
In Node.js 24, the `fs` module introduced a runtime deprecation for `F_OK`, `R_OK`, `W_OK`, and `X_OK` getters exposed directly on `node:fs`. Get them from `fs.constants` or `fs.promises.constants` instead. | ||
|
||
So this codemod handle [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176). | ||
|
||
```js displayName="Before" | ||
const fs = require('node:fs'); | ||
|
||
fs.access('/path/to/file', fs.F_OK, callback); | ||
fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback); | ||
``` | ||
|
||
```js displayName="After" | ||
const fs = require('node:fs'); | ||
|
||
fs.access('/path/to/file', fs.constants.F_OK, callback); | ||
fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback); | ||
``` | ||
|
||
## `util-log-to-console-log` | ||
|
||
In Node.js v23, the `util.log` function was deprecated in favor of using `console.log` directly. Because it's an unmaintained legacy API that was exposed to user land by accident | ||
|
||
So this codemod handle [DEP0059](https://nodejs.org/api/deprecations.html#DEP0059). | ||
|
||
### Example: | ||
|
||
```js displayName="Before" | ||
const util = require('node:util'); | ||
|
||
util.log('Hello world'); | ||
``` | ||
|
||
```js displayName="After" | ||
console.log(new Date().toLocaleString(), 'Hello world'); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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