Skip to content

Commit a9742b5

Browse files
content(userland-migration): make up to date
1 parent ef5dc84 commit a9742b5

File tree

7 files changed

+229
-35
lines changed

7 files changed

+229
-35
lines changed

apps/site/navigation.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,24 @@
332332
}
333333
}
334334
},
335-
"migrations": {
336-
"label": "components.navigation.learn.migrations.links.migrations",
335+
"userland-migrations": {
336+
"label": "components.navigation.learn.userland-migrations.links.userland-migrations",
337337
"items": {
338338
"introduction": {
339-
"link": "/learn/migrations/introduction",
340-
"label": "components.navigation.learn.migrations.links.introduction"
339+
"link": "/learn/userland-migrations/introduction",
340+
"label": "components.navigation.learn.userland-migrations.links.introduction"
341+
},
342+
"ecosystem": {
343+
"link": "/learn/userland-migrations/ecosystem",
344+
"label": "components.navigation.learn.userland-migrations.links.ecosystem"
345+
},
346+
"v20-to-v22": {
347+
"link": "/learn/userland-migrations/v20-to-v22",
348+
"label": "components.navigation.learn.userland-migrations.links.v20-to-v22"
349+
},
350+
"v14-to-v16": {
351+
"link": "/learn/userland-migrations/v14-to-v16",
352+
"label": "components.navigation.learn.userland-migrations.links.v14-to-v16"
341353
}
342354
}
343355
},

apps/site/pages/en/learn/migrations/introduction.md

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Ecosystem to Node.js
3+
layout: learn
4+
authors: AugustinMauroy
5+
---
6+
7+
# Ecosystem to Node.js
8+
9+
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.
10+
11+
## `correct-ts-specifiers`
12+
13+
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).
14+
15+
To run this codemdod, you have to use this command:
16+
17+
```bash
18+
npx codemod@latest run correct-ts-specifiers
19+
```
20+
21+
> **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).
22+
23+
## Feedback
24+
25+
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).
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Userland Migrations
3+
layout: learn
4+
authors: JakobJingleheimer, AugustinMauroy
5+
---
6+
7+
![Node.js Userland Migrations](https://raw.githubusercontent.com/nodejs/userland-migrations/main/.github/assets/Userland-Migration-Tagline.png)
8+
9+
# Userland Migrations
10+
11+
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.
12+
13+
<!--
14+
maintainer node: https://codemod.link/nodejs-official is pointing to legacy codemod registry
15+
it's will point to new new one once codemod change the redirection of the short link
16+
-->
17+
18+
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.
19+
20+
## Our goal
21+
22+
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.
23+
24+
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.
25+
26+
## How to use a Codemod
27+
28+
To use a codemod, you can run the following command in your terminal:
29+
30+
```bash displayName="npm"
31+
npx codemod@next <codemod-name>
32+
```
33+
34+
```bash displayName="yarn"
35+
yarn dlx codemod@next <codemod-name>
36+
```
37+
38+
```bash displayName="pnpm"
39+
pnpx codemod@next <codemod-name>
40+
```
41+
42+
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:
43+
44+
```bash displayName="npm"
45+
npx codemod@next @nodejs/import-assertions-to-attributes
46+
```
47+
48+
```bash displayName="yarn"
49+
yarn dlx codemod@next @nodejs/import-assertions-to-attributes
50+
```
51+
52+
```bash displayName="pnpm"
53+
pnpx codemod@next @nodejs/import-assertions-to-attributes
54+
```
55+
56+
## Good Practices
57+
58+
- **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.
59+
- **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.
60+
- **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
61+
62+
## Feedback
63+
64+
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).
65+
66+
## Follow the Userland Migrations Progression
67+
68+
You can follow the progress of userland migrations on our [GitHub project board](https://github.com/orgs/nodejs/projects/13/views/1).
69+
70+
This board tracks:
71+
72+
- Codemod kind (deprecation, breaking change, ecosystem)
73+
- Node.js version
74+
- Status (backlog, todo, in progress, done, not planned) _If you want to contribute, please check the "todo" column_
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Nodejs v14 to v16
3+
layout: learn
4+
authors: AugustinMauroy
5+
---
6+
7+
# Nodejs v14 to v16
8+
9+
This page provides a list of codemods to help you migrate your code from Node.js v14 to v16.
10+
11+
## `create-require-from-path`
12+
13+
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.
14+
15+
So this codemod handle [DEP0130](https://nodejs.org/api/deprecations.html#DEP0130).
16+
17+
```bash
18+
npx codemod@latest @nodejs/create-require-from-path
19+
```
20+
21+
Example:
22+
23+
**Before:**
24+
25+
```js
26+
import { createRequireFromPath } from 'node:module';
27+
28+
// Using createRequireFromPath
29+
const requireFromPath = createRequireFromPath('/path/to/module');
30+
const myModule = requireFromPath('./myModule.cjs');
31+
```
32+
33+
**After:**
34+
35+
```js
36+
import { createRequire } from 'node:module';
37+
38+
// Using createRequire with a specific path
39+
const require = createRequire('/path/to/module');
40+
const myModule = require('./myModule.cjs');
41+
```
42+
43+
## `rmdir`
44+
45+
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.
46+
47+
so this codemod handle [DEP0147](https://nodejs.org/api/deprecations.html#DEP0147).
48+
49+
```bash
50+
npx codemod@latest @nodejs/rmdir
51+
```
52+
53+
Example:
54+
55+
**Before:**
56+
57+
```js
58+
// Using fs.rmdir with the recursive option
59+
fs.rmdir(path, { recursive: true }, callback);
60+
61+
// Using fs.rmdirSync with the recursive option
62+
fs.rmdirSync(path, { recursive: true });
63+
64+
// Using fs.promises.rmdir with the recursive option
65+
fs.promises.rmdir(path, { recursive: true });
66+
```
67+
68+
**After:**
69+
70+
```js
71+
// Using fs.rm with recursive and force options
72+
fs.rm(path, { recursive: true, force: true }, callback);
73+
74+
// Using fs.rmSync with recursive and force options
75+
fs.rmSync(path, { recursive: true, force: true });
76+
77+
// Using fs.promises.rm with recursive and force options
78+
fs.promises.rm(path, { recursive: true, force: true });
79+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Nodejs v20 to v22
3+
layout: learn
4+
authors: AugustinMauroy
5+
---
6+
7+
# Nodejs v20 to v22
8+
9+
This page provides a list of codemods to help you migrate your code from Node.js v20 to v22.
10+
11+
## `import-assertions-to-attributes`
12+
13+
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.
14+
15+
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.
16+
17+
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.
18+
19+
```bash
20+
npx codemod@latest @nodejs/import-assertions-to-attributes
21+
```
22+
23+
Example:
24+
25+
```js
26+
import jsonData from './data.json' assert { type: 'json' };
27+
// becomes
28+
import jsonData from './data.json' with { type: 'json' };
29+
```

packages/i18n/src/locales/en.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@
9999
"acceptInputFromTheCommandLineInNodejs": "Accept input from the command line in Node.js"
100100
}
101101
},
102-
"migrations": {
102+
"userland-migrations": {
103103
"links": {
104-
"migrations": "Userland Migrations",
105-
"introduction": "Introduction to Userland Migrations"
104+
"userland-migrations": "Userland Migrations",
105+
"introduction": "Introduction to Userland Migrations",
106+
"ecosystem": "Ecosystem to Node.js",
107+
"v20-to-v22": "Node.js v20 to v22",
108+
"v14-to-v16": "Node.js v14 to v16"
106109
}
107110
},
108111
"modules": {

0 commit comments

Comments
 (0)