Skip to content

Commit 011eda1

Browse files
content(migrations): update (#8420)
* content(`migrations`): update * Update CODEOWNERS * Update v22-to-v24.mdx --------- Signed-off-by: Claudio Wunder <cwunder@gnome.org> Co-authored-by: Claudio Wunder <cwunder@gnome.org>
1 parent d7ac93d commit 011eda1

File tree

2 files changed

+106
-73
lines changed

2 files changed

+106
-73
lines changed

.github/CODEOWNERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ apps/site/pages/en/blog/announcements @nodejs/releasers
4444
# The following users DO NOT have write access, and their review is requested
4545
# via a GitHub action.
4646
apps/site/pages/en/learn/diagnostics @nodejs/diagnostics
47+
4748
apps/site/pages/en/learn/getting-started/security-best-practices.md @nodejs/security-wg
49+
4850
apps/site/pages/en/learn/manipulating-files @nodejs/fs
51+
4952
apps/site/pages/en/learn/test-runner @nodejs/test_runner
53+
5054
apps/site/pages/en/learn/typescript @nodejs/typescript
55+
5156
apps/site/pages/en/about/partners.mdx @nodejs/marketing
5257
apps/site/pages/en/about/branding.mdx @nodejs/marketing
58+
59+
apps/site/pages/en/learn/getting-started/userland-migrations.md @nodejs/userland-migrations
60+
apps/site/pages/en/blog/migrations @nodejs/userland-migrations

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

Lines changed: 98 additions & 73 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

86-
#### Example:
84+
#### 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+
```
151+
152+
##### opendir
116153

117-
util.log('Hello world');
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).
129175

130-
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/zlib-bytesread-to-byteswritten).
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).
177+
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

136-
#### Example:
184+
#### 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`
@@ -163,7 +209,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi
163209
npx codemod run @nodejs/fs-truncate-fd-deprecation
164210
```
165211

166-
#### Example:
212+
#### Example
167213

168214
```js displayName="Before"
169215
const { truncate, open, close } = require('node:fs');
@@ -189,50 +235,29 @@ 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');
208-
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-
);
253+
process.assert(condition, 'Assertion failed');
221254
```
222255

223256
```js displayName="After"
224-
const crypto = require('node:crypto');
225-
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-
);
257+
import assert from 'node:assert';
258+
assert(condition, 'Assertion failed');
238259
```
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.

0 commit comments

Comments
 (0)