Skip to content

Commit 6caf1a7

Browse files
scaffold codemod
1 parent 56d8262 commit 6caf1a7

File tree

15 files changed

+200
-0
lines changed

15 files changed

+200
-0
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# `fs.rmdir` DEP0147
2+
3+
This recipe provides a guide for migrating from the deprecated `fs.rmdir` and its synchronous and promise-based counterparts to the new `fs.rm` method in Node.js.
4+
5+
See [DEP0147](https://nodejs.org/api/deprecations.html#DEP0147).
6+
7+
## Examples
8+
9+
**Before:**
10+
11+
```js
12+
// Using fs.rmdir with the recursive option
13+
fs.rmdir(path, { recursive: true }, callback);
14+
15+
// Using fs.rmdirSync with the recursive option
16+
fs.rmdirSync(path, { recursive: true });
17+
18+
// Using fs.promises.rmdir with the recursive option
19+
fs.promises.rmdir(path, { recursive: true });
20+
```
21+
22+
**After:**
23+
24+
```js
25+
// Using fs.rm with recursive and force options
26+
fs.rm(path, { recursive: true, force: true }, callback);
27+
28+
// Using fs.rmSync with recursive and force options
29+
fs.rmSync(path, { recursive: true, force: true });
30+
31+
// Using fs.promises.rm with recursive and force options
32+
fs.promises.rm(path, { recursive: true, force: true });
33+
```
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/repl-builtin-modules"
3+
version: 1.0.0
4+
description: Handle DEP0191 via transforming `repl.builtinModules` usage to `module.builtinModules`.
5+
author: Augustin Mauroy
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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@nodejs/repl-builtin-modules",
3+
"version": "1.0.0",
4+
"description": "Handle DEP0191 via transforming `repl.builtinModules` usage to `module.builtinModules`.",
5+
"type": "module",
6+
"scripts": {
7+
"test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./",
8+
"test:update-snapshots": "npx codemod@next jssg test --update-snapshots -l typescript ./src/workflow.ts ./ "
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/nodejs/userland-migrations.git",
13+
"directory": "recipes/rmdirs",
14+
"bugs": "https://github.com/nodejs/userland-migrations/issues"
15+
},
16+
"author": "Augustin Mauroy",
17+
"license": "MIT",
18+
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/rmdirs/README.md",
19+
"devDependencies": {
20+
"@types/node": "^24.0.3",
21+
"@codemod.com/jssg-types": "^1.0.3"
22+
},
23+
"dependencies": {
24+
"@nodejs/codemod-utils": "*"
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement";
2+
import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call";
3+
import type { SgRoot, Edit } from "@codemod.com/jssg-types/main";
4+
5+
/**
6+
* Transform function that converts deprecated fs.rmdir calls
7+
* with recursive: true option to the new fs.rm API.
8+
*
9+
* Handles:
10+
* 1. ...
11+
*/
12+
export default function transform(root: SgRoot): string | null {
13+
const rootNode = root.root();
14+
let hasChanges = false;
15+
const edits: Edit[] = [];
16+
17+
// do things
18+
19+
if (!hasChanges) return null;
20+
21+
return rootNode.commitEdits(edits);
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const repl = require('node:repl');
2+
3+
console.log(repl.builtinModules);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { builtinModules } = require('node:module');
2+
3+
console.log(builtinModules);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { foo } = require('node:repl');
2+
const { builtinModules } = require('node:module');
3+
4+
console.log(builtinModules);
5+
6+
foo(); // does something else
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { foo } from 'node:repl';
2+
import { builtinModules } from 'node:module';
3+
4+
console.log(builtinModules);
5+
6+
foo(); // does something else
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const module = require('node:module');
2+
3+
console.log(module.builtinModules);

0 commit comments

Comments
 (0)