Skip to content

Commit fa8d79e

Browse files
content(migrations): update
1 parent b5ccb5f commit fa8d79e

File tree

1 file changed

+143
-68
lines changed

1 file changed

+143
-68
lines changed

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

Lines changed: 143 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -69,86 +69,132 @@ Node.js' `configure` script will warn if you attempt to build Node.js with a com
6969

7070
Some breaking changes or End of Life (EOL) deprecations in Node.js 23 and 24 have associated codemods to help you update your codebase. Below is a list of the available codemods for this migration:
7171

72-
### `fs-access-mode-constants`
73-
74-
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.
72+
### `crypto-rsa-pss-update`
7573

76-
This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176).
74+
In [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154), the `generateKeyPair` and `generateKeyPairSync` methods in the `crypto` module deprecated the `hash`, `mgf1Hash`, and `saltLength` options for the `'rsa-pss'` key type in favor of `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` respectively.
7775

78-
The source code for this codemod can be found in the [fs-access-mode-constants directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/fs-access-mode-constants).
76+
The source code for this codemod can be found in the [crypto-rsa-pss-update directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/crypto-rsa-pss-update).
7977

80-
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants).
78+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update).
8179

8280
```bash
83-
npx codemod run @nodejs/fs-access-mode-constants
81+
npx codemod run @nodejs/crypto-rsa-pss-update
8482
```
8583

8684
#### Example:
8785

8886
```js displayName="Before"
89-
const fs = require('node:fs');
87+
const crypto = require('node:crypto');
9088

91-
fs.access('/path/to/file', fs.F_OK, callback);
92-
fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback);
89+
crypto.generateKeyPair(
90+
'rsa-pss',
91+
{
92+
modulusLength: 2048,
93+
hash: 'sha256',
94+
mgf1Hash: 'sha1',
95+
saltLength: 32,
96+
},
97+
(err, publicKey, privateKey) => {
98+
// callback
99+
}
100+
);
93101
```
94102

95103
```js displayName="After"
96-
const fs = require('node:fs');
104+
const crypto = require('node:crypto');
97105

98-
fs.access('/path/to/file', fs.constants.F_OK, callback);
99-
fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback);
106+
crypto.generateKeyPair(
107+
'rsa-pss',
108+
{
109+
modulusLength: 2048,
110+
hashAlgorithm: 'sha256',
111+
mgf1HashAlgorithm: 'sha1',
112+
saltLength: 32,
113+
},
114+
(err, publicKey, privateKey) => {
115+
// callback
116+
}
117+
);
100118
```
101119

102-
### `util-log-to-console-log`
120+
### `dirent-path-to-parent-path`
121+
122+
This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`.
103123

104-
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.
124+
See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178).
105125

106-
So this codemod handle [DEP0059](https://nodejs.org/api/deprecations.html#DEP0059).
126+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path).
107127

108128
```bash
109-
npx codemod run @nodejs/util-log-to-console-log
129+
npx codemod run @nodejs/dirent-path-to-parent-path
110130
```
111131

112-
#### Example:
132+
#### Examples
133+
134+
##### readdir
113135

114136
```js displayName="Before"
115-
const util = require('node:util');
137+
const { readdir } = require('node:fs/promises');
138+
const entries = await readdir('/some/path', { withFileTypes: true });
139+
for (const dirent of entries) {
140+
console.log(dirent.path);
141+
}
142+
```
143+
144+
```js displayName="After"
145+
const { readdir } = require('node:fs/promises');
146+
const entries = await readdir('/some/path', { withFileTypes: true });
147+
for (const dirent of entries) {
148+
console.log(dirent.parentPath);
149+
}
150+
```
116151

117-
util.log('Hello world');
152+
##### opendir
153+
154+
```js displayName="Before"
155+
import { opendir } from 'node:fs/promises';
156+
const dir = await opendir('./');
157+
for await (const dirent of dir) {
158+
console.log(`Found ${dirent.name} in ${dirent.path}`);
159+
}
118160
```
119161

120162
```js displayName="After"
121-
console.log(new Date().toLocaleString(), 'Hello world');
163+
import { opendir } from 'node:fs/promises';
164+
const dir = await opendir('./');
165+
for await (const dirent of dir) {
166+
console.log(`Found ${dirent.name} in ${dirent.parentPath}`);
167+
}
122168
```
123169

124-
### `zlib-bytesRead-to-bytesWritten`
170+
### `fs-access-mode-constants`
125171

126-
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.
172+
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.
127173

128-
The source code for this codemod can be found in the [zlib-bytesRead-to-bytesWritten directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/zlib-bytesread-to-byteswritten).
174+
This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176).
175+
176+
The source code for this codemod can be found in the [fs-access-mode-constants directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/fs-access-mode-constants).
129177

130-
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/zlib-bytesread-to-byteswritten).
178+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants).
131179

132180
```bash
133-
npx codemod run @nodejs/zlib-bytesread-to-byteswritten
181+
npx codemod run @nodejs/fs-access-mode-constants
134182
```
135183

136184
#### Example:
137185

138186
```js displayName="Before"
139-
const zlib = require('node:zlib');
140-
const gzip = zlib.createGzip();
141-
gzip.on('end', () => {
142-
console.log('Bytes processed:', gzip.bytesRead);
143-
});
187+
const fs = require('node:fs');
188+
189+
fs.access('/path/to/file', fs.F_OK, callback);
190+
fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback);
144191
```
145192

146193
```js displayName="After"
147-
const zlib = require('node:zlib');
148-
const gzip = zlib.createGzip();
149-
gzip.on('end', () => {
150-
console.log('Bytes processed:', gzip.bytesWritten);
151-
});
194+
const fs = require('node:fs');
195+
196+
fs.access('/path/to/file', fs.constants.F_OK, callback);
197+
fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback);
152198
```
153199

154200
### `fs-truncate-to-ftruncate`
@@ -189,50 +235,79 @@ open('file.txt', 'w', (err, fd) => {
189235
});
190236
```
191237

192-
### `crypto-rsa-pss-update`
238+
### `process-assert-to-node-assert`
193239

194-
In [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154), the `generateKeyPair` and `generateKeyPairSync` methods in the `crypto` module deprecated the `hash`, `mgf1Hash`, and `saltLength` options for the `'rsa-pss'` key type in favor of `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` respectively.
240+
This recipe transforms the usage of `process.assert` to use `node:assert` module.
195241

196-
The source code for this codemod can be found in the [crypto-rsa-pss-update directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/crypto-rsa-pss-update).
242+
See [DEP0100](https://nodejs.org/api/deprecations.html#DEP0100).
197243

198-
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update).
244+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/process-assert-to-node-assert).
199245

200246
```bash
201-
npx codemod run @nodejs/crypto-rsa-pss-update
247+
npx codemod run @nodejs/process-assert-to-node-assert
202248
```
203249

204-
#### Example:
250+
## Example
205251

206252
```js displayName="Before"
207-
const crypto = require('node:crypto');
253+
process.assert(condition, 'Assertion failed');
254+
```
208255

209-
crypto.generateKeyPair(
210-
'rsa-pss',
211-
{
212-
modulusLength: 2048,
213-
hash: 'sha256',
214-
mgf1Hash: 'sha1',
215-
saltLength: 32,
216-
},
217-
(err, publicKey, privateKey) => {
218-
// callback
219-
}
220-
);
256+
```js displayName="After"
257+
import assert from 'node:assert';
258+
assert(condition, 'Assertion failed');
259+
```
260+
261+
## Additional Notes
262+
263+
This codemod use [`fs` capability](https://docs.codemod.com/jssg/security) to read the `package.json` file and determine if the project is using ES modules or CommonJS. Based on this information, it adds the appropriate import statement for the `assert` module.
264+
265+
#### `dirent-path-to-parent-path`
266+
267+
This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`.
268+
269+
See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178).
270+
271+
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path).
272+
273+
```bash
274+
npx codemod run @nodejs/dirent-path-to-parent-path
275+
```
276+
277+
#### Examples
278+
279+
##### readdir
280+
281+
```js displayName="Before"
282+
const { readdir } = require('node:fs/promises');
283+
const entries = await readdir('/some/path', { withFileTypes: true });
284+
for (const dirent of entries) {
285+
console.log(dirent.path);
286+
}
221287
```
222288

223289
```js displayName="After"
224-
const crypto = require('node:crypto');
290+
const { readdir } = require('node:fs/promises');
291+
const entries = await readdir('/some/path', { withFileTypes: true });
292+
for (const dirent of entries) {
293+
console.log(dirent.parentPath);
294+
}
295+
```
225296

226-
crypto.generateKeyPair(
227-
'rsa-pss',
228-
{
229-
modulusLength: 2048,
230-
hashAlgorithm: 'sha256',
231-
mgf1HashAlgorithm: 'sha1',
232-
saltLength: 32,
233-
},
234-
(err, publicKey, privateKey) => {
235-
// callback
236-
}
237-
);
297+
##### opendir
298+
299+
```js displayName="Before"
300+
import { opendir } from 'node:fs/promises';
301+
const dir = await opendir('./');
302+
for await (const dirent of dir) {
303+
console.log(`Found ${dirent.name} in ${dirent.path}`);
304+
}
305+
```
306+
307+
```js displayName="After"
308+
import { opendir } from 'node:fs/promises';
309+
const dir = await opendir('./');
310+
for await (const dirent of dir) {
311+
console.log(`Found ${dirent.name} in ${dirent.parentPath}`);
312+
}
238313
```

0 commit comments

Comments
 (0)