Skip to content

Commit 56267bd

Browse files
lint:fix
1 parent 34d5395 commit 56267bd

4 files changed

Lines changed: 46 additions & 46 deletions

File tree

apps/site/pages/en/blog/migrations/axios-to-fetch.mdx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ The codemod supports the following Axios methods and converts them to their Fetc
4646
### GET Request
4747

4848
```diff
49-
const base = 'https://dummyjson.com/todos';
49+
const base = 'https://dummyjson.com/todos';
5050

5151
- const all = await axios.get(base);
5252
+ const all = await fetch(base).then(async (res) => Object.assign(res, { data: await res.json() })).catch(() => null);
53-
console.log('\nGET /todos ->', all.status);
54-
console.log(`Preview: ${all.data.todos.length} todos`);
53+
console.log('\nGET /todos ->', all.status);
54+
console.log(`Preview: ${all.data.todos.length} todos`);
5555
```
5656

5757
### POST Request
5858

5959
```diff
60-
const base = 'https://dummyjson.com/todos';
60+
const base = 'https://dummyjson.com/todos';
6161

6262
- const created = await axios.post(
6363
- `${base}/add`, {
@@ -77,14 +77,14 @@ The codemod supports the following Axios methods and converts them to their Fetc
7777
+ userId: 5,
7878
+ }),
7979
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
80-
console.log('\nPOST /todos/add ->', created.status);
81-
console.log('Preview:', created.data?.id ? `created id ${created.data.id}` : JSON.stringify(created.data).slice(0,200));
80+
console.log('\nPOST /todos/add ->', created.status);
81+
console.log('Preview:', created.data?.id ? `created id ${created.data.id}` : JSON.stringify(created.data).slice(0,200));
8282
```
8383

8484
### POST Form Request
8585

8686
```diff
87-
const formEndpoint = '/submit';
87+
const formEndpoint = '/submit';
8888

8989
- const created = await axios.postForm(formEndpoint, {
9090
- title: 'Form Demo',
@@ -97,13 +97,13 @@ The codemod supports the following Axios methods and converts them to their Fetc
9797
+ completed: false,
9898
+ }),
9999
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
100-
console.log('Preview:', created.data);
100+
console.log('Preview:', created.data);
101101
```
102102

103103
### PUT Request
104104

105105
```diff
106-
const base = 'https://dummyjson.com/todos';
106+
const base = 'https://dummyjson.com/todos';
107107

108108
- const updatedPut = await axios.put(
109109
- `${base}/1`,
@@ -115,26 +115,26 @@ The codemod supports the following Axios methods and converts them to their Fetc
115115
+ headers: { 'Content-Type': 'application/json' },
116116
+ body: JSON.stringify({ completed: false }),
117117
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
118-
console.log('\nPUT /todos/1 ->', updatedPut.status);
119-
console.log('Preview:', updatedPut.data?.completed !== undefined ? `completed=${updatedPut.data.completed}` : JSON.stringify(updatedPut.data).slice(0,200));
118+
console.log('\nPUT /todos/1 ->', updatedPut.status);
119+
console.log('Preview:', updatedPut.data?.completed !== undefined ? `completed=${updatedPut.data.completed}` : JSON.stringify(updatedPut.data).slice(0,200));
120120
```
121121

122122
### DELETE Request
123123

124124
```diff
125-
const base = 'https://dummyjson.com/todos';
125+
const base = 'https://dummyjson.com/todos';
126126

127127
- const deleted = await axios.delete(`${base}/1`);
128128
+ const deleted = await fetch(`${base}/1`, { method: 'DELETE' })
129129
+ .then(async (res) => Object.assign(res, { data: await res.json() }));
130-
console.log('\nDELETE /todos/1 ->', deleted.status);
131-
console.log('Preview:', deleted.data ? JSON.stringify(deleted.data).slice(0,200) : typeof deleted.data);
130+
console.log('\nDELETE /todos/1 ->', deleted.status);
131+
console.log('Preview:', deleted.data ? JSON.stringify(deleted.data).slice(0,200) : typeof deleted.data);
132132
```
133133

134134
### `request` Axios Method
135135

136136
```diff
137-
const base = 'https://dummyjson.com/todos';
137+
const base = 'https://dummyjson.com/todos';
138138

139139
- const customRequest = await axios.request({
140140
- url: `${base}/1`,
@@ -147,8 +147,8 @@ The codemod supports the following Axios methods and converts them to their Fetc
147147
+ headers: { 'Content-Type': 'application/json' },
148148
+ body: JSON.stringify({ completed: true }),
149149
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
150-
console.log('\nPATCH /todos/1 ->', customRequest.status);
151-
console.log('Preview:', customRequest.data?.completed !== undefined ? `completed=${customRequest.data.completed}` : JSON.stringify(customRequest.data).slice(0,200));
150+
console.log('\nPATCH /todos/1 ->', customRequest.status);
151+
console.log('Preview:', customRequest.data?.completed !== undefined ? `completed=${customRequest.data.completed}` : JSON.stringify(customRequest.data).slice(0,200));
152152
```
153153

154154
## Unsupported APIs

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ npx codemod run @nodejs/process-main-module
6060
```diff
6161
- if (process.mainModule === "mod.js") {
6262
+ if (require.main === "mod.js") {
63-
// cli thing
63+
// cli thing
6464
} else {
65-
// module thing
65+
// module thing
6666
}
6767
```
6868

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ npx codemod run @nodejs/crypto-createcipheriv-migration
6363
### Example
6464

6565
```diff
66-
-const cipher = crypto.createCipher(algorithm, password);
67-
+const cipher = (() => {
68-
+ const __dep0106Salt = crypto.randomBytes(16);
69-
+ const __dep0106Key = crypto.scryptSync(password, __dep0106Salt, 32);
70-
+ const __dep0106Iv = crypto.randomBytes(16);
71-
+ // DEP0106: Persist __dep0106Salt and __dep0106Iv alongside the ciphertext so it can be decrypted later.
72-
+ return crypto.createCipheriv(algorithm, __dep0106Key, __dep0106Iv);
73-
+})();
66+
- const cipher = crypto.createCipher(algorithm, password);
67+
+ const cipher = (() => {
68+
+ const __dep0106Salt = crypto.randomBytes(16);
69+
+ const __dep0106Key = crypto.scryptSync(password, __dep0106Salt, 32);
70+
+ const __dep0106Iv = crypto.randomBytes(16);
71+
+ // DEP0106: Persist __dep0106Salt and __dep0106Iv alongside the ciphertext so it can be decrypted later.
72+
+ return crypto.createCipheriv(algorithm, __dep0106Key, __dep0106Iv);
73+
+ })();
7474
```
7575

7676
### Important notes

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ author: AugustinMauroy, Richard Lau
1313
userland migrations team is working on more codemods to help you with the
1414
migration.
1515

16-
Missing codemods will be added over time. If you have specific needs.
16+
Missing codemods will be added over time. If you have specific needs.
1717

1818
<a href="https://github.com/nodejs/userland-migrations/issues/239">
1919
Read this issue to learn where we are in the process. And how to manually migrate your code.
@@ -87,24 +87,24 @@ npx codemod run @nodejs/crypto-rsa-pss-update
8787
const crypto = require("node:crypto");
8888

8989
crypto.generateKeyPair(
90-
"rsa-pss",
91-
{
92-
modulusLength: 2048,
93-
- hash: "sha256",
94-
- mgf1Hash: "sha1",
95-
+ hashAlgorithm: "sha256",
96-
+ mgf1HashAlgorithm: "sha1",
97-
saltLength: 32,
98-
},
99-
(err, publicKey, privateKey) => {
100-
// callback
101-
},
90+
"rsa-pss",
91+
{
92+
modulusLength: 2048,
93+
- hash: "sha256",
94+
- mgf1Hash: "sha1",
95+
+ hashAlgorithm: "sha256",
96+
+ mgf1HashAlgorithm: "sha1",
97+
saltLength: 32,
98+
},
99+
(err, publicKey, privateKey) => {
100+
// callback
101+
},
102102
);
103103

104104
crypto.generateKeyPairSync("rsa-pss", {
105-
modulusLength: 2048,
106-
- hash: "sha256",
107-
+ hashAlgorithm: "sha256",
105+
modulusLength: 2048,
106+
- hash: "sha256",
107+
+ hashAlgorithm: "sha256",
108108
});
109109
```
110110

@@ -128,8 +128,8 @@ npx codemod run @nodejs/dirent-path-to-parent-path
128128
const { readdir } = require('node:fs/promises');
129129
const entries = await readdir('/some/path', { withFileTypes: true });
130130
for (const dirent of entries) {
131-
- console.log(dirent.path);
132-
+ console.log(dirent.parentPath);
131+
- console.log(dirent.path);
132+
+ console.log(dirent.parentPath);
133133
}
134134
```
135135

@@ -229,7 +229,7 @@ const session = http2.connect("https://example.com", {
229229
});
230230

231231
const stream = session.request({
232-
":path": "/api/data",
232+
":path": "/api/data",
233233
- priority: { weight: 32 }
234234
});
235235
- stream.priority({ exclusive: true, parent: 0, weight: 128 });

0 commit comments

Comments
 (0)