Skip to content

Commit 9310143

Browse files
update
1 parent 464acd9 commit 9310143

4 files changed

Lines changed: 133 additions & 8 deletions

File tree

apps/site/mdx/components.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default {
4747
blockquote: Blockquote,
4848
pre: MDXCodeBox,
4949
img: MDXImage,
50-
// Allow the writter to use an pretty alert box
50+
// Renders a CSS-enhanced Alert Box
5151
AlertBox,
5252
// Renders MDX CodeTabs
5353
CodeTabs: MDXCodeTabs,

apps/site/pages/en/blog/migrations/v12-to-v14.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ This page provides a list of codemods to help you migrate your code from Node.js
1818

1919
## `util-print-to-console-log`
2020

21-
This recipe transforms the usage of log functions from util, `print`, `puts`, `debug`, `error` to use `console.log()` or `console.error()`.
21+
This recipe transforms calls of various now-deprecated `node:util` log functions into the modern alternative, `console.log` and `console.error`:
2222

23-
So this codemod handle [DEP0026](https://nodejs.org/api/deprecations.html#DEP0026), [DEP0027](https://nodejs.org/api/deprecations.html#DEP0027), [DEP0028](https://nodejs.org/api/deprecations.html#DEP0028) and [DEP0029](https://nodejs.org/api/deprecations.html#DEP0029).
23+
- ([DEP0026](https://nodejs.org/api/deprecations.html#DEP0026)) [`util.print`](https://nodejs.org/api/util.html#util_util_print) - `console.log`
24+
- ([DEP0027](https://nodejs.org/api/deprecations.html#DEP0027)) [`util.puts`](https://nodejs.org/api/util.html#util_util_puts) - `console.log`
25+
- ([DEP0028](https://nodejs.org/api/deprecations.html#DEP0028)) [`util.debug`](https://nodejs.org/api/util.html#util_util_debug) - `console.error`
26+
- ([DEP0029](https://nodejs.org/api/deprecations.html#DEP0029)) [`util.error`](https://nodejs.org/api/util.html#util_util_error) - `console.error`
2427

2528
```bash
2629
npx codemod run @nodejs/create-require-from-path

apps/site/pages/en/blog/migrations/v14-to-v16.mdx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ This page provides a list of codemods to help you migrate your code from Node.js
1717

1818
## `create-require-from-path`
1919

20-
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.
21-
22-
So this codemod handle [DEP0130](https://nodejs.org/api/deprecations.html#DEP0130).
20+
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.
2321

2422
```bash
2523
npx codemod run @nodejs/create-require-from-path
@@ -30,15 +28,13 @@ npx codemod run @nodejs/create-require-from-path
3028
```js displayName="Before"
3129
import { createRequireFromPath } from 'node:module';
3230

33-
// Using createRequireFromPath
3431
const requireFromPath = createRequireFromPath('/path/to/module');
3532
const myModule = requireFromPath('./myModule.cjs');
3633
```
3734

3835
```js displayName="After"
3936
import { createRequire } from 'node:module';
4037

41-
// Using createRequire with a specific path
4238
const require = createRequire('/path/to/module');
4339
const myModule = require('./myModule.cjs');
4440
```
@@ -71,6 +67,28 @@ if (require.main === 'mod.js') {
7167
}
7268
```
7369

70+
## `process-mainModule-to-require-main`
71+
72+
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.
73+
74+
```bash
75+
npx codemod run @nodejs/process-mainModule-to-require-main
76+
```
77+
78+
### Example:
79+
80+
```js displayName="Before"
81+
if (process.mainModule) {
82+
console.log('This script is the main module');
83+
}
84+
```
85+
86+
```js displayName="After"
87+
if (require.main === module) {
88+
console.log('This script is the main module');
89+
}
90+
```
91+
7492
## `rmdir`
7593

7694
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.

apps/site/pages/en/blog/migrations/v22-to-v24.mdx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,107 @@ util.log('Hello world');
5353
```js displayName="After"
5454
console.log(new Date().toLocaleString(), 'Hello world');
5555
```
56+
57+
## `zlib-bytesRead-to-bytesWritten`
58+
59+
The [`zlib.bytesRead`](https://nodejs.org/api/zlib.html#zlib_bytesread) property was deprecated ([DEP0108](https://nodejs.org/api/deprecations.html#DEP0108)) in favor of [`zlib.bytesWritten`](https://nodejs.org/api/zlib.html#zlib_byteswritten). This codemod replaces `zlib.bytesRead` with `zlib.bytesWritten` for consistent stream property naming. It handles both CommonJS and ESM imports.
60+
61+
```bash
62+
npx codemod run @nodejs/zlib-bytesRead-to-bytesWritten
63+
```
64+
65+
### Example:
66+
67+
```js displayName="Before"
68+
const zlib = require('node:zlib');
69+
const gzip = zlib.createGzip();
70+
gzip.on('end', () => {
71+
console.log('Bytes processed:', gzip.bytesRead);
72+
});
73+
```
74+
75+
```js displayName="After"
76+
const zlib = require('node:zlib');
77+
const gzip = zlib.createGzip();
78+
gzip.on('end', () => {
79+
console.log('Bytes processed:', gzip.bytesWritten);
80+
});
81+
```
82+
83+
## `fs-truncate-to-ftruncate`
84+
85+
The [`fs.truncate`](https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback) function was deprecated ([DEP0081](https://nodejs.org/api/deprecations.html#DEP0081)) when used with a file descriptor. Use [`fs.ftruncate`](https://nodejs.org/api/fs.html#fs_fs_ftruncate_fd_len_callback) instead.
86+
87+
```bash
88+
npx codemod run @nodejs/fs-truncate-to-ftruncate
89+
```
90+
91+
### Example:
92+
93+
```js displayName="Before"
94+
const { truncate, open, close } = require('node:fs');
95+
96+
open('file.txt', 'w', (err, fd) => {
97+
if (err) throw err;
98+
truncate(fd, 10, err => {
99+
if (err) throw err;
100+
close(fd, () => {});
101+
});
102+
});
103+
```
104+
105+
```js displayName="After"
106+
const { ftruncate, open, close } = require('node:fs');
107+
108+
open('file.txt', 'w', (err, fd) => {
109+
if (err) throw err;
110+
ftruncate(fd, 10, err => {
111+
if (err) throw err;
112+
close(fd, () => {});
113+
});
114+
});
115+
```
116+
117+
## `crypto-rsa-pss-update`
118+
119+
Codemod to handle Node.js crypto deprecation [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154) by transforming deprecated RSA-PSS key generation options.
120+
121+
```bash
122+
npx codemod run @nodejs/crypto-rsa-pss-update
123+
```
124+
125+
### Example:
126+
127+
```js displayName="Before"
128+
const crypto = require('node:crypto');
129+
130+
crypto.generateKeyPair(
131+
'rsa-pss',
132+
{
133+
modulusLength: 2048,
134+
hash: 'sha256',
135+
mgf1Hash: 'sha1',
136+
saltLength: 32,
137+
},
138+
(err, publicKey, privateKey) => {
139+
// callback
140+
}
141+
);
142+
```
143+
144+
```js displayName="After"
145+
const crypto = require('crypto');
146+
147+
crypto.generateKeyPair(
148+
'rsa-pss',
149+
{
150+
modulusLength: 2048,
151+
hashAlgorithm: 'sha256',
152+
mgf1HashAlgorithm: 'sha1',
153+
saltLength: 32,
154+
},
155+
(err, publicKey, privateKey) => {
156+
// callback
157+
}
158+
);
159+
```

0 commit comments

Comments
 (0)