From fa8d79e024778f1f64d0c3f54519dbad09c6c34c Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Mon, 15 Dec 2025 14:38:29 +0100 Subject: [PATCH 1/3] content(`migrations`): update --- .../pages/en/blog/migrations/v22-to-v24.mdx | 211 ++++++++++++------ 1 file changed, 143 insertions(+), 68 deletions(-) diff --git a/apps/site/pages/en/blog/migrations/v22-to-v24.mdx b/apps/site/pages/en/blog/migrations/v22-to-v24.mdx index 80bf1f7f7ea53..b512207863086 100644 --- a/apps/site/pages/en/blog/migrations/v22-to-v24.mdx +++ b/apps/site/pages/en/blog/migrations/v22-to-v24.mdx @@ -69,86 +69,132 @@ Node.js' `configure` script will warn if you attempt to build Node.js with a com 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: -### `fs-access-mode-constants` - -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. +### `crypto-rsa-pss-update` -This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176). +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. -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). +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). -You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants). +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update). ```bash -npx codemod run @nodejs/fs-access-mode-constants +npx codemod run @nodejs/crypto-rsa-pss-update ``` #### Example: ```js displayName="Before" -const fs = require('node:fs'); +const crypto = require('node:crypto'); -fs.access('/path/to/file', fs.F_OK, callback); -fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback); +crypto.generateKeyPair( + 'rsa-pss', + { + modulusLength: 2048, + hash: 'sha256', + mgf1Hash: 'sha1', + saltLength: 32, + }, + (err, publicKey, privateKey) => { + // callback + } +); ``` ```js displayName="After" -const fs = require('node:fs'); +const crypto = require('node:crypto'); -fs.access('/path/to/file', fs.constants.F_OK, callback); -fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback); +crypto.generateKeyPair( + 'rsa-pss', + { + modulusLength: 2048, + hashAlgorithm: 'sha256', + mgf1HashAlgorithm: 'sha1', + saltLength: 32, + }, + (err, publicKey, privateKey) => { + // callback + } +); ``` -### `util-log-to-console-log` +### `dirent-path-to-parent-path` + +This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`. -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. +See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178). -So this codemod handle [DEP0059](https://nodejs.org/api/deprecations.html#DEP0059). +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path). ```bash -npx codemod run @nodejs/util-log-to-console-log +npx codemod run @nodejs/dirent-path-to-parent-path ``` -#### Example: +#### Examples + +##### readdir ```js displayName="Before" -const util = require('node:util'); +const { readdir } = require('node:fs/promises'); +const entries = await readdir('/some/path', { withFileTypes: true }); +for (const dirent of entries) { + console.log(dirent.path); +} +``` + +```js displayName="After" +const { readdir } = require('node:fs/promises'); +const entries = await readdir('/some/path', { withFileTypes: true }); +for (const dirent of entries) { + console.log(dirent.parentPath); +} +``` -util.log('Hello world'); +##### opendir + +```js displayName="Before" +import { opendir } from 'node:fs/promises'; +const dir = await opendir('./'); +for await (const dirent of dir) { + console.log(`Found ${dirent.name} in ${dirent.path}`); +} ``` ```js displayName="After" -console.log(new Date().toLocaleString(), 'Hello world'); +import { opendir } from 'node:fs/promises'; +const dir = await opendir('./'); +for await (const dirent of dir) { + console.log(`Found ${dirent.name} in ${dirent.parentPath}`); +} ``` -### `zlib-bytesRead-to-bytesWritten` +### `fs-access-mode-constants` -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. +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. -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). +This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176). + +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). -You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/zlib-bytesread-to-byteswritten). +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants). ```bash -npx codemod run @nodejs/zlib-bytesread-to-byteswritten +npx codemod run @nodejs/fs-access-mode-constants ``` #### Example: ```js displayName="Before" -const zlib = require('node:zlib'); -const gzip = zlib.createGzip(); -gzip.on('end', () => { - console.log('Bytes processed:', gzip.bytesRead); -}); +const fs = require('node:fs'); + +fs.access('/path/to/file', fs.F_OK, callback); +fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback); ``` ```js displayName="After" -const zlib = require('node:zlib'); -const gzip = zlib.createGzip(); -gzip.on('end', () => { - console.log('Bytes processed:', gzip.bytesWritten); -}); +const fs = require('node:fs'); + +fs.access('/path/to/file', fs.constants.F_OK, callback); +fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback); ``` ### `fs-truncate-to-ftruncate` @@ -189,50 +235,79 @@ open('file.txt', 'w', (err, fd) => { }); ``` -### `crypto-rsa-pss-update` +### `process-assert-to-node-assert` -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. +This recipe transforms the usage of `process.assert` to use `node:assert` module. -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). +See [DEP0100](https://nodejs.org/api/deprecations.html#DEP0100). -You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update). +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/process-assert-to-node-assert). ```bash -npx codemod run @nodejs/crypto-rsa-pss-update +npx codemod run @nodejs/process-assert-to-node-assert ``` -#### Example: +## Example ```js displayName="Before" -const crypto = require('node:crypto'); +process.assert(condition, 'Assertion failed'); +``` -crypto.generateKeyPair( - 'rsa-pss', - { - modulusLength: 2048, - hash: 'sha256', - mgf1Hash: 'sha1', - saltLength: 32, - }, - (err, publicKey, privateKey) => { - // callback - } -); +```js displayName="After" +import assert from 'node:assert'; +assert(condition, 'Assertion failed'); +``` + +## Additional Notes + +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. + +#### `dirent-path-to-parent-path` + +This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`. + +See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178). + +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path). + +```bash +npx codemod run @nodejs/dirent-path-to-parent-path +``` + +#### Examples + +##### readdir + +```js displayName="Before" +const { readdir } = require('node:fs/promises'); +const entries = await readdir('/some/path', { withFileTypes: true }); +for (const dirent of entries) { + console.log(dirent.path); +} ``` ```js displayName="After" -const crypto = require('node:crypto'); +const { readdir } = require('node:fs/promises'); +const entries = await readdir('/some/path', { withFileTypes: true }); +for (const dirent of entries) { + console.log(dirent.parentPath); +} +``` -crypto.generateKeyPair( - 'rsa-pss', - { - modulusLength: 2048, - hashAlgorithm: 'sha256', - mgf1HashAlgorithm: 'sha1', - saltLength: 32, - }, - (err, publicKey, privateKey) => { - // callback - } -); +##### opendir + +```js displayName="Before" +import { opendir } from 'node:fs/promises'; +const dir = await opendir('./'); +for await (const dirent of dir) { + console.log(`Found ${dirent.name} in ${dirent.path}`); +} +``` + +```js displayName="After" +import { opendir } from 'node:fs/promises'; +const dir = await opendir('./'); +for await (const dirent of dir) { + console.log(`Found ${dirent.name} in ${dirent.parentPath}`); +} ``` From 6e7e30afae8a668a16bf72ae1b9587a35284712e Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Mon, 15 Dec 2025 14:45:11 +0100 Subject: [PATCH 2/3] Update CODEOWNERS --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7037998ac1bd6..16a37a72dbaf0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -48,3 +48,5 @@ apps/site/pages/en/learn/getting-started/security-best-practices.md @nodejs/secu apps/site/pages/en/learn/manipulating-files @nodejs/fs apps/site/pages/en/learn/test-runner @nodejs/test_runner apps/site/pages/en/learn/typescript @nodejs/typescript +apps/site/pages/en/learn/getting-started/userland-migrations.md @nodejs/userland-migrations +apps/site/pages/en/blog/migrations @nodejs/userland-migrations From c6761e3c909356a28eea51e968f481ae0d4a693d Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Mon, 15 Dec 2025 20:31:47 +0100 Subject: [PATCH 3/3] Update v22-to-v24.mdx --- .../pages/en/blog/migrations/v22-to-v24.mdx | 60 ++----------------- 1 file changed, 5 insertions(+), 55 deletions(-) diff --git a/apps/site/pages/en/blog/migrations/v22-to-v24.mdx b/apps/site/pages/en/blog/migrations/v22-to-v24.mdx index b512207863086..f6655aeadbdbd 100644 --- a/apps/site/pages/en/blog/migrations/v22-to-v24.mdx +++ b/apps/site/pages/en/blog/migrations/v22-to-v24.mdx @@ -81,7 +81,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi npx codemod run @nodejs/crypto-rsa-pss-update ``` -#### Example: +#### Example ```js displayName="Before" const crypto = require('node:crypto'); @@ -181,7 +181,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi npx codemod run @nodejs/fs-access-mode-constants ``` -#### Example: +#### Example ```js displayName="Before" const fs = require('node:fs'); @@ -209,7 +209,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi npx codemod run @nodejs/fs-truncate-fd-deprecation ``` -#### Example: +#### Example ```js displayName="Before" const { truncate, open, close } = require('node:fs'); @@ -247,7 +247,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi npx codemod run @nodejs/process-assert-to-node-assert ``` -## Example +#### Example ```js displayName="Before" process.assert(condition, 'Assertion failed'); @@ -258,56 +258,6 @@ import assert from 'node:assert'; assert(condition, 'Assertion failed'); ``` -## Additional Notes +#### Additional Notes 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. - -#### `dirent-path-to-parent-path` - -This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`. - -See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178). - -You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path). - -```bash -npx codemod run @nodejs/dirent-path-to-parent-path -``` - -#### Examples - -##### readdir - -```js displayName="Before" -const { readdir } = require('node:fs/promises'); -const entries = await readdir('/some/path', { withFileTypes: true }); -for (const dirent of entries) { - console.log(dirent.path); -} -``` - -```js displayName="After" -const { readdir } = require('node:fs/promises'); -const entries = await readdir('/some/path', { withFileTypes: true }); -for (const dirent of entries) { - console.log(dirent.parentPath); -} -``` - -##### opendir - -```js displayName="Before" -import { opendir } from 'node:fs/promises'; -const dir = await opendir('./'); -for await (const dirent of dir) { - console.log(`Found ${dirent.name} in ${dirent.path}`); -} -``` - -```js displayName="After" -import { opendir } from 'node:fs/promises'; -const dir = await opendir('./'); -for await (const dirent of dir) { - console.log(`Found ${dirent.name} in ${dirent.parentPath}`); -} -```