Skip to content

Commit dcb0ad5

Browse files
azuclaude
andauthored
refactor: replace npm dependencies with Node.js built-ins (#4)
- Replace meow with util.parseArgs for CLI argument parsing - Replace clone with structuredClone for object cloning - Replace concat-stream with node:stream/consumers - Remove unused cross-env dependency This reduces the package count by 41 dependencies while using standard Node.js APIs available since Node.js 16-17. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 69bf48b commit dcb0ad5

File tree

4 files changed

+49
-348
lines changed

4 files changed

+49
-348
lines changed

bin/cmd.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,56 @@
11
#!/usr/bin/env node
2-
import meow from "meow";
3-
import concat from "concat-stream";
2+
import { parseArgs } from "node:util";
3+
import { createRequire } from "node:module";
4+
import { text } from "node:stream/consumers";
45
import create from "../src/create-textlint-rule-example.js";
56
import fs from "fs";
67

7-
const cli = meow(
8-
`
8+
const require = createRequire(import.meta.url);
9+
const pkg = require("../package.json");
10+
11+
const helpText = `
912
Usage
1013
$ create-textlint-rule-example <file-path>
1114
1215
Options
1316
--separator separator between each examples
14-
`,
15-
{
16-
importMeta: import.meta
17-
}
18-
);
19-
const filePath = process.argv[2];
20-
const input = filePath && filePath !== "-" ? fs.createReadStream(process.argv[2]) : process.stdin;
21-
input.pipe(
22-
concat(function (buf) {
23-
const content = buf.toString("utf8");
24-
console.log(
25-
create(
26-
{ content, filePath },
27-
{
28-
exampleSeparator: cli.flags.separator
29-
}
30-
)
31-
);
32-
})
17+
--help Show this help
18+
--version Show version
19+
`;
20+
21+
const { values, positionals } = parseArgs({
22+
options: {
23+
separator: {
24+
type: "string"
25+
},
26+
help: {
27+
type: "boolean"
28+
},
29+
version: {
30+
type: "boolean"
31+
}
32+
},
33+
allowPositionals: true
34+
});
35+
36+
if (values.help) {
37+
console.log(helpText);
38+
process.exit(0);
39+
}
40+
41+
if (values.version) {
42+
console.log(pkg.version);
43+
process.exit(0);
44+
}
45+
46+
const filePath = positionals[0];
47+
const input = filePath && filePath !== "-" ? fs.createReadStream(filePath) : process.stdin;
48+
const content = await text(input);
49+
console.log(
50+
create(
51+
{ content, filePath },
52+
{
53+
exampleSeparator: values.separator
54+
}
55+
)
3356
);

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@
4040
"@babel/core": "^7.0.0",
4141
"@babel/preset-env": "^7.0.0",
4242
"@babel/preset-typescript": "^7.13.0",
43-
"clone": "^2.1.1",
44-
"concat-stream": "^2.0.0",
45-
"lodash.uniq": "^4.5.0",
46-
"meow": "^10.0.0"
43+
"lodash.uniq": "^4.5.0"
4744
},
4845
"devDependencies": {
49-
"cross-env": "^7.0.3",
5046
"lint-staged": "^11.0.0",
5147
"mocha": "^8.4.0",
5248
"prettier": "^2.3.0"

0 commit comments

Comments
 (0)