Skip to content

Commit 27b71a7

Browse files
Merge branch 'main' into augustin/dep0194
2 parents 6946d10 + 1f3efd3 commit 27b71a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2092
-865
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
persist-credentials: false
6969
show-progress: false
7070
- name: Set up Node.js
71-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
71+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
7272
with:
7373
cache: "npm"
7474
check-latest: true
@@ -120,7 +120,7 @@ jobs:
120120
persist-credentials: false
121121
show-progress: false
122122
- name: Set up Node.js
123-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
123+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
124124
with:
125125
cache: "npm"
126126
check-latest: true
@@ -156,7 +156,7 @@ jobs:
156156
persist-credentials: false
157157
show-progress: false
158158
- name: Set up Node.js ${{ matrix.node-version }}
159-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
159+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
160160
with:
161161
cache: "npm"
162162
check-latest: true

.github/workflows/codemod_publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
ls -lah "$CODEMOD_PATH"
8787
8888
- name: Setup Node.js environment
89-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
89+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
9090
with:
9191
node-version-file: ".nvmrc"
9292
cache: npm

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"[markdown]": {
99
"editor.wordWrap": "off"
1010
},
11+
"[typescript][javascript]": {
12+
"editor.defaultFormatter": "biomejs.biome"
13+
},
1114
"typescript.experimental.useTsgo": true
1215
}

package-lock.json

Lines changed: 159 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
},
2828
"homepage": "https://nodejs.org/learn/userland-migrations",
2929
"devDependencies": {
30-
"@biomejs/biome": "2.2.6",
31-
"@types/node": "^24.7.2",
32-
"@typescript/native-preview": "^7.0.0-dev.20251013.1"
30+
"@biomejs/biome": "2.3.3",
31+
"@types/node": "^24.10.0",
32+
"@typescript/native-preview": "^7.0.0-dev.20251104.1"
3333
},
3434
"workspaces": [
3535
"./recipes/*",

recipes/buffer-atob-btoa/src/workflow.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Edit, Kinds, Range, SgNode, SgRoot } from '@codemod.com/jssg-types/main';
1+
import type { Edit, Range, SgNode, SgRoot } from '@codemod.com/jssg-types/main';
22
import type Js from '@codemod.com/jssg-types/langs/javascript';
33
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
44
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
@@ -8,30 +8,37 @@ import { removeBinding } from '@nodejs/codemod-utils/ast-grep/remove-binding';
88

99
export default function transform(root: SgRoot<Js>): string | null {
1010
const rootNode = root.root();
11-
const bindingStatementFnTuples: [string, SgNode<Js>, (arg: string) => string][] = [];
11+
const bindingStatementFnTuples: [
12+
string,
13+
SgNode<Js>,
14+
(arg: string) => string,
15+
][] = [];
1216
const edits: Edit[] = [];
1317
const linesToRemove: Range[] = [];
1418

1519
const updates = [
1620
{
17-
oldBind: "$.atob",
18-
replaceFn: (arg: string) => `Buffer.from(${arg}, 'base64').toString('binary')`
21+
oldBind: '$.atob',
22+
replaceFn: (arg: string) =>
23+
`Buffer.from(${arg}, 'base64').toString('binary')`,
1924
},
2025
{
21-
oldBind: "$.btoa",
22-
replaceFn: (arg: string) => `Buffer.from(${arg}, 'binary').toString('base64')`
23-
}
26+
oldBind: '$.btoa',
27+
replaceFn: (arg: string) =>
28+
`Buffer.from(${arg}, 'binary').toString('base64')`,
29+
},
2430
];
2531

2632
const statements = [
2733
...getNodeRequireCalls(root, 'buffer'),
28-
...getNodeImportStatements(root, 'buffer')
34+
...getNodeImportStatements(root, 'buffer'),
2935
];
3036

3137
for (const statement of statements) {
3238
for (const update of updates) {
3339
const binding = resolveBindingPath(statement, update.oldBind);
34-
if (binding) bindingStatementFnTuples.push([binding, statement, update.replaceFn]);
40+
if (binding)
41+
bindingStatementFnTuples.push([binding, statement, update.replaceFn]);
3542
}
3643
}
3744

@@ -43,32 +50,32 @@ export default function transform(root: SgRoot<Js>): string | null {
4350
// Check for calls to the specified binding
4451
const calls = rootNode.findAll({
4552
rule: {
46-
pattern: `${binding}($ARG)`
47-
}
53+
pattern: `${binding}($ARG)`,
54+
},
4855
});
4956
// Check for any other calls, so as to not remove a statement that is still being used
5057
const otherCalls = rootNode.findAll({
5158
rule: {
5259
all: [
5360
{
54-
pattern: 'buffer.$FN'
61+
pattern: 'buffer.$FN',
5562
},
5663
{
5764
not: {
58-
pattern: '$.btoa($ARG)'
59-
}
65+
pattern: '$.btoa($ARG)',
66+
},
6067
},
6168
{
6269
not: {
63-
pattern: '$.atob($ARG)'
64-
}
65-
}
66-
]
67-
}
70+
pattern: '$.atob($ARG)',
71+
},
72+
},
73+
],
74+
},
6875
});
6976

7077
for (const call of calls) {
71-
const argMatch = call.getMatch("ARG");
78+
const argMatch = call.getMatch('ARG');
7279
if (argMatch) edits.push(call.replace(fn(argMatch.text())));
7380
}
7481

recipes/correct-ts-specifiers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
},
3737
"devDependencies": {
3838
"@nodejs/codemod-utils": "*",
39-
"@types/node": "^24.7.2"
39+
"@types/node": "^24.10.0"
4040
}
4141
}

recipes/create-require-from-path/src/workflow.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import type JS from "@codemod.com/jssg-types/langs/javascript";
99
*
1010
* Handles:
1111
* 1. Updates import/require statements that import `createRequireFromPath`:
12-
* - `const { createRequireFromPath } = require('module')` -> `const { createRequire } = require('module')`
13-
* - `const { createRequireFromPath } = require('node:module')` -> `const { createRequire } = require('node:module')`
14-
* - `import { createRequireFromPath } from 'module'` -> `import { createRequire } from 'module'`
15-
* - `import { createRequireFromPath } from 'node:module'` -> `import { createRequire } from 'node:module'`
12+
* - `const { createRequireFromPath } = require('module')` `const { createRequire } = require('module')`
13+
* - `const { createRequireFromPath } = require('node:module')` `const { createRequire } = require('node:module')`
14+
* - `import { createRequireFromPath } from 'module'` `import { createRequire } from 'module'`
15+
* - `import { createRequireFromPath } from 'node:module'` `import { createRequire } from 'node:module'`
1616
*
1717
* 2. Updates variable declarations that use `createRequireFromPath`:
18-
* - `const myRequire = createRequireFromPath(arg)` -> `const myRequire = createRequire(arg)`
19-
* - `let myRequire = createRequireFromPath(arg)` -> `let myRequire = createRequire(arg)`
20-
* - `var myRequire = createRequireFromPath(arg)` -> `var myRequire = createRequire(arg)`
18+
* - `const myRequire = createRequireFromPath(arg)` `const myRequire = createRequire(arg)`
19+
* - `let myRequire = createRequireFromPath(arg)` `let myRequire = createRequire(arg)`
20+
* - `var myRequire = createRequireFromPath(arg)` `var myRequire = createRequire(arg)`
2121
*
2222
* 3. Preserves original variable names and declaration types.
2323
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# `crypto.fips` DEP0093
2+
3+
This recipe transforms the usage from the deprecated `crypto.fips` to `crypto.getFips()` and `crypto.setFips()`.
4+
5+
See [DEP0093](https://nodejs.org/api/deprecations.html#DEP0093).
6+
7+
## Examples
8+
9+
**Before:**
10+
11+
```js
12+
import crypto from "node:crypto";
13+
import { fips } from "node:crypto";
14+
15+
// Using crypto.fips
16+
crypto.fips;
17+
fips;
18+
19+
// Using crypto.fips = true
20+
crypto.fips = true;
21+
fips = true;
22+
23+
// Using crypto.fips = false
24+
crypto.fips = false;
25+
fips = false;
26+
```
27+
28+
**After:**
29+
30+
```js
31+
import crypto from "node:crypto";
32+
import { getFips, setFips } from "node:crypto";
33+
34+
// Using crypto.getFips()
35+
crypto.getFips();
36+
getFips();
37+
38+
// Using crypto.setFips(true)
39+
crypto.setFips(true);
40+
setFips(true);
41+
42+
// Using crypto.setFips(false)
43+
crypto.setFips(false);
44+
setFips(false);
45+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
schema_version: "1.0"
2+
name: "@nodejs/crypto-fips-to-getFips"
3+
version: 1.0.0
4+
description: Handle DEP0093 via transforming `crypto.fips` to `crypto.getFips()` and `crypto.setFips()`
5+
author: Usman S.
6+
license: MIT
7+
workflow: workflow.yaml
8+
category: migration
9+
10+
targets:
11+
languages:
12+
- javascript
13+
- typescript
14+
15+
keywords:
16+
- transformation
17+
- migration
18+
19+
registry:
20+
access: public
21+
visibility: public

0 commit comments

Comments
 (0)