Skip to content

Commit a5c7eae

Browse files
AugustinMauroyJakobJingleheimerrichardlaubmuenzenmeyer
authored
content(userland-migration): make up to date (#8053)
* content(`userland-migration`): make up to date * Update introduction.md * update * Update navigation.json * Update * use correct casing * update * update after meeting * fix link * feat(mdx): add alertBox * fix * update * update + improve * make date up to date * Delete next.mdx.use.mjs * apply sugession Co-Authored-By: Jacob Smith <[email protected]> * use sha for image * use alertBox as info * update Co-Authored-By: Richard Lau <[email protected]> * bump date * change date to order by version * i'm dum * Update apps/site/pages/en/blog/migrations/v22-to-v24.mdx Signed-off-by: Augustin Mauroy <[email protected]> * Update navigation.json * fix grammar Co-Authored-By: Brian Muenzenmeyer <[email protected]> --------- Signed-off-by: Augustin Mauroy <[email protected]> Co-authored-by: Jacob Smith <[email protected]> Co-authored-by: Richard Lau <[email protected]> Co-authored-by: Brian Muenzenmeyer <[email protected]>
1 parent a49f65c commit a5c7eae

File tree

10 files changed

+578
-45
lines changed

10 files changed

+578
-45
lines changed

apps/site/layouts/Blog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const BlogLayout: FC = () => {
6363
'announcements',
6464
'release',
6565
'vulnerability',
66+
'migrations',
6667
'events',
6768
])}
6869
/>

apps/site/mdx/components.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
import AlertBox from '@node-core/ui-components/Common/AlertBox';
34
import BadgeGroup from '@node-core/ui-components/Common/BadgeGroup';
45
import Blockquote from '@node-core/ui-components/Common/Blockquote';
56
import MDXCodeTabs from '@node-core/ui-components/MDX/CodeTabs';
@@ -54,6 +55,8 @@ export default {
5455
blockquote: Blockquote,
5556
pre: MDXCodeBox,
5657
img: MDXImage,
58+
// Renders a CSS-enhanced Alert Box
59+
AlertBox,
5760
// Renders MDX CodeTabs
5861
CodeTabs: MDXCodeTabs,
5962
// Renders Tooltips

apps/site/navigation.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@
205205
"securityBestPractices": {
206206
"link": "/learn/getting-started/security-best-practices",
207207
"label": "components.navigation.learn.gettingStarted.links.securityBestPractices"
208+
},
209+
"userlandMigrations": {
210+
"link": "/learn/getting-started/userland-migrations",
211+
"label": "components.navigation.learn.gettingStarted.links.userlandMigrations"
208212
}
209213
}
210214
},
@@ -336,15 +340,6 @@
336340
}
337341
}
338342
},
339-
"migrations": {
340-
"label": "components.navigation.learn.migrations.links.migrations",
341-
"items": {
342-
"introduction": {
343-
"link": "/learn/migrations/introduction",
344-
"label": "components.navigation.learn.migrations.links.introduction"
345-
}
346-
}
347-
},
348343
"modules": {
349344
"label": "components.navigation.learn.modules.links.modules",
350345
"items": {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
date: '2025-10-28T00:00:00.000Z'
3+
category: migrations
4+
title: Node.js v12 to v14
5+
layout: blog-post
6+
author: AugustinMauroy
7+
---
8+
9+
# Node.js v12 to v14
10+
11+
<AlertBox level="info" title="!">
12+
This article covers a part of the migration from Node.js v12 to v14. The
13+
userland migrations team is working on more codemods to help you with the
14+
migration.
15+
</AlertBox>
16+
17+
This page provides a list of codemods to help you migrate your code from Node.js v12 to v14.
18+
19+
## `util-print-to-console-log`
20+
21+
This recipe transforms calls of various now-deprecated `node:util` log functions into the modern alternative, `console.log` and `console.error`:
22+
23+
- [DEP0026](https://nodejs.org/api/deprecations.html#DEP0026): `util.print``console.log`
24+
- [DEP0027](https://nodejs.org/api/deprecations.html#DEP0027): `util.puts``console.log`
25+
- [DEP0028](https://nodejs.org/api/deprecations.html#DEP0028): `util.debug``console.error`
26+
- [DEP0029](https://nodejs.org/api/deprecations.html#DEP0029): `util.error``console.error`
27+
28+
The source code for this codemod can be found in the [util-print-to-console-log directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/util-print-to-console-log).
29+
30+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/util-print-to-console-log).
31+
32+
```bash
33+
npx codemod run @nodejs/create-require-from-path
34+
```
35+
36+
### Example:
37+
38+
```js displayName="Before"
39+
const util = require('node:util');
40+
41+
util.print('Hello world');
42+
util.puts('Hello world');
43+
util.debug('Hello world');
44+
util.error('Hello world');
45+
```
46+
47+
```js displayName="After"
48+
console.log('Hello world');
49+
console.log('Hello world');
50+
console.error('Hello world');
51+
console.error('Hello world');
52+
```
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
date: '2025-10-28T00:01:00.000Z'
3+
category: migrations
4+
title: Node.js v14 to v16
5+
layout: blog-post
6+
author: AugustinMauroy
7+
---
8+
9+
# Node.js v14 to v16
10+
11+
<AlertBox level="info" title="!">
12+
This article covers a part of the migration from Node.js v14 to v16. The
13+
userland migrations team is working on more codemods to help you with the
14+
migration.
15+
</AlertBox>
16+
17+
This page provides a list of codemods to help you migrate your code from Node.js v14 to v16.
18+
19+
## `create-require-from-path`
20+
21+
Node.js v16 replaced the [`createRequireFromPath`](https://nodejs.org/api/module.html#module_module_createrequirefrompath) function, deprecated in [DEP0148](https://nodejs.org/api/deprecations.html#DEP0148), with the modern [`createRequire`](https://nodejs.org/api/module.html#module_module_createrequire) function. This codemod replaces calls of the deprecated function with the modern alternative mentioned.
22+
23+
The source code for this codemod can be found in the [create-require-from-path directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/create-require-from-path).
24+
25+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/create-require-from-path).
26+
27+
```bash
28+
npx codemod run @nodejs/create-require-from-path
29+
```
30+
31+
### Example:
32+
33+
```js displayName="Before"
34+
import { createRequireFromPath } from 'node:module';
35+
36+
const requireFromPath = createRequireFromPath('/path/to/module');
37+
const myModule = requireFromPath('./myModule.cjs');
38+
```
39+
40+
```js displayName="After"
41+
import { createRequire } from 'node:module';
42+
43+
const require = createRequire('/path/to/module');
44+
const myModule = require('./myModule.cjs');
45+
```
46+
47+
## `process-main-module`
48+
49+
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.
50+
51+
So the codemod handle [DEP0138](https://nodejs.org/api/deprecations.html#DEP0138).
52+
53+
The source code for this codemod can be found in the [process-main-module directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/process-main-module).
54+
55+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/process-main-module).
56+
57+
```bash
58+
npx codemod run @nodejs/process-main-module
59+
```
60+
61+
### Example:
62+
63+
```js displayName="Before"
64+
if (process.mainModule === 'mod.js') {
65+
// cli thing
66+
} else {
67+
// module thing
68+
}
69+
```
70+
71+
```js displayName="After"
72+
if (require.main === 'mod.js') {
73+
// cli thing
74+
} else {
75+
// module thing
76+
}
77+
```
78+
79+
## `process-mainModule-to-require-main`
80+
81+
The [`process.mainModule`](https://nodejs.org/api/process.html#process_process_mainmodule) property was deprecated ([DEP0144](https://nodejs.org/api/deprecations.html#DEP0144)) in favor of [`require.main`](https://nodejs.org/api/modules.html#modules_accessing_the_main_module). This codemod replaces calls of the deprecated property with the modern alternative mentioned.
82+
83+
The source code for this codemod can be found in the [process-mainModule-to-require-main directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/process-main-module).
84+
85+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/process-mainModule-to-require-main).
86+
87+
```bash
88+
npx codemod run @nodejs/process-mainModule-to-require-main
89+
```
90+
91+
### Example:
92+
93+
```js displayName="Before"
94+
if (process.mainModule) {
95+
console.log('This script is the main module');
96+
}
97+
```
98+
99+
```js displayName="After"
100+
if (require.main === module) {
101+
console.log('This script is the main module');
102+
}
103+
```
104+
105+
## `rmdir`
106+
107+
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.
108+
109+
so this codemod handle [DEP0147](https://nodejs.org/api/deprecations.html#DEP0147).
110+
111+
The source code for this codemod can be found in the [rmdir directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/rmdir).
112+
113+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/rmdir).
114+
115+
```bash
116+
npx codemod run @nodejs/rmdir
117+
```
118+
119+
### Example:
120+
121+
```js displayName="Before"
122+
// Using fs.rmdir with the recursive option
123+
fs.rmdir(path, { recursive: true }, callback);
124+
125+
// Using fs.rmdirSync with the recursive option
126+
fs.rmdirSync(path, { recursive: true });
127+
128+
// Using fs.promises.rmdir with the recursive option
129+
fs.promises.rmdir(path, { recursive: true });
130+
```
131+
132+
```js displayName="After"
133+
// Using fs.rm with recursive and force options
134+
fs.rm(path, { recursive: true, force: true }, callback);
135+
136+
// Using fs.rmSync with recursive and force options
137+
fs.rmSync(path, { recursive: true, force: true });
138+
139+
// Using fs.promises.rm with recursive and force options
140+
fs.promises.rm(path, { recursive: true, force: true });
141+
```
142+
143+
## `tmpDir-to-tmpdir`
144+
145+
The `tmpDir` function was renamed to `tmpdir` in Node.js v16. This codemod will help you replace all instances of `tmpDir` with `tmpdir`.
146+
147+
So the codemod handles [DEP0022](https://nodejs.org/docs/latest/api/deprecations.html#dep0022-ostmpdir).
148+
149+
The source code for this codemod can be found in the [tmpdir-to-tmpdir directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/tmpdir-to-tmpdir).
150+
151+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/tmpDir-to-tmpdir).
152+
153+
```bash
154+
npx codemod run @nodejs/tmpDir-to-tmpdir
155+
```
156+
157+
### Example:
158+
159+
```js displayName="Before"
160+
import { tmpDir } from 'node:os';
161+
162+
const foo = tmpDir();
163+
```
164+
165+
```js displayName="After"
166+
import { tmpdir } from 'node:os';
167+
168+
const foo = tmpdir();
169+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
date: '2025-10-28T00:02:00.000Z'
3+
category: migrations
4+
title: Node.js v20 to v22
5+
layout: blog-post
6+
author: AugustinMauroy
7+
---
8+
9+
# Node.js v20 to v22
10+
11+
<AlertBox level="info" title="!">
12+
This article covers a part of the migration from Node.js v20 to v22. The
13+
userland migrations team is working on more codemods to help you with the
14+
migration.
15+
</AlertBox>
16+
17+
This page provides a list of codemods to help you migrate your code from Node.js v20 to v22.
18+
19+
## `import-assertions-to-attributes`
20+
21+
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 replaced with an `with` attribute on the `import` statement.
22+
23+
So in [node.js v22](https://nodejs.org/fr/blog/release/v22.0.0#other-notable-changes), the `import assert` feature was removed and the `with` attribute is required instead.
24+
25+
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.
26+
27+
The source code for this codemod can be found in the [import-assertions-to-attributes directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/import-assertions-to-attributes).
28+
29+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/import-assertions-to-attributes).
30+
31+
```bash
32+
npx codemod run @nodejs/import-assertions-to-attributes
33+
```
34+
35+
### Example:
36+
37+
```js displayName="Before"
38+
import jsonData from './data.json' assert { type: 'json' };
39+
```
40+
41+
```js displayName="After"
42+
import jsonData from './data.json' with { type: 'json' };
43+
```

0 commit comments

Comments
 (0)