Skip to content

Commit a3f50fa

Browse files
azuclaude
andauthored
refactor: drop unused/replaceable deps (clone, mkdirp, shelljs) (#1994)
## Summary Removes unused or easily replaceable dependencies (`clone`, `mkdirp`, `shelljs`) across the monorepo. Replaces their usages with Node.js built-ins (`structuredClone`, `fs.mkdirSync({ recursive: true })`, `fs`/`child_process`) to slim down the dependency graph. ## Changes - Drop `clone`, `mkdirp`, and `shelljs` from affected `package.json` files and `pnpm-lock.yaml` - Replace `clone()` with `structuredClone()` in tests - Replace `mkdirp` with `fs.mkdirSync(path, { recursive: true })` - Replace `shelljs` usages in scripts/tests with Node.js built-ins - Remove the obsolete `packages/@textlint/kernel/tools/migrate-core-to-kernel.js` script - Adjust `pnpm-workspace.yaml` accordingly ## Breaking Changes None. Only internal scripts, tests, and dev/runtime dependencies are affected. ## Test Plan - [ ] `pnpm install` - [ ] `pnpm -r run build` - [ ] `pnpm -r run test` - [ ] CI passes --------- Co-authored-by: Claude <[email protected]>
1 parent bd5236d commit a3f50fa

15 files changed

Lines changed: 55 additions & 232 deletions

File tree

examples/perf/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"perf": "node perf.js"
1616
},
1717
"devDependencies": {
18-
"shelljs": "catalog:",
1918
"textlint": "workspace:*",
2019
"textlint-rule-max-ten": "catalog:",
2120
"textlint-rule-no-mix-dearu-desumasu": "catalog:",

examples/perf/perf.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// LICENSE : MIT
22
"use strict";
3-
require("shelljs/make");
43
const os = require("node:os");
5-
/* eslint-env shelljs */
4+
const path = require("node:path");
5+
const { execFile } = require("node:child_process");
66
/*
77
* A little bit fuzzy. My computer has a first CPU speed of 3093 and the perf test
88
* always completes in < 2000ms. However, Travis is less predictable due to
@@ -12,25 +12,27 @@ const os = require("node:os");
1212
const PERF_MULTIPLIER = 7.5e6;
1313
/**
1414
* Calculates the time for each run for performance
15-
* @param {string} cmd cmd
15+
* @param {string} file executable to run
16+
* @param {string[]} args arguments to pass to the executable
1617
* @param {int} runs Total number of runs to do
1718
* @param {int} runNumber Current run number
1819
* @param {int[]} results Collection results from each run
1920
* @param {function} cb Function to call when everything is done
2021
* @returns {int[]} calls the cb with all the results
2122
* @private
2223
*/
23-
function time(cmd, runs, runNumber, results, cb) {
24+
function time(file, args, runs, runNumber, results, cb) {
2425
const start = process.hrtime();
25-
// eslint-disable-next-line no-undef
26-
exec(cmd, { silent: true }, function () {
26+
// textlint exits with a non-zero code when lint errors are found; this perf
27+
// test only measures execution time, so the exit code is intentionally ignored.
28+
execFile(file, args, function () {
2729
const diff = process.hrtime(start),
2830
actual = diff[0] * 1e3 + diff[1] / 1e6; // ms
2931

3032
results.push(actual);
31-
echo(`Performance Run #${runNumber}: %dms`, actual); // eslint-disable-line no-undef
33+
console.log(`Performance Run #${runNumber}: %dms`, actual);
3234
if (runs > 1) {
33-
time(cmd, runs - 1, runNumber + 1, results, cb);
35+
time(file, args, runs - 1, runNumber + 1, results, cb);
3436
} else {
3537
return cb(results);
3638
}
@@ -40,10 +42,9 @@ function time(cmd, runs, runNumber, results, cb) {
4042
function run() {
4143
const cpuSpeed = os.cpus()[0].speed;
4244
const max = PERF_MULTIPLIER / cpuSpeed;
43-
const TEXTLINT = `node ${__dirname}/node_modules/.bin/textlint`;
44-
const target = `${__dirname}/md/`;
45-
const cmd = `${TEXTLINT} ${target}`;
46-
time(cmd, 5, 1, [], function (results) {
45+
const textlintBin = path.join(__dirname, "node_modules", ".bin", "textlint");
46+
const target = path.join(__dirname, "md");
47+
time("node", [textlintBin, target], 5, 1, [], function (results) {
4748
results.sort(function (a, b) {
4849
return a - b;
4950
});

packages/@textlint/kernel/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"@types/debug": "catalog:",
5454
"@types/node": "catalog:",
5555
"rimraf": "catalog:",
56-
"shelljs": "catalog:",
5756
"textlint-rule-preset-ja-spacing": "catalog:",
5857
"typescript": "catalog:",
5958
"unist-util-select": "catalog:",

packages/@textlint/kernel/tools/migrate-core-to-kernel.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/@textlint/markdown-to-ast/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@types/debug": "catalog:",
5151
"@types/node": "catalog:",
5252
"@types/unist": "catalog:",
53-
"mkdirp": "catalog:",
5453
"rimraf": "catalog:",
5554
"typescript": "catalog:",
5655
"vitest": "catalog:"

packages/@textlint/markdown-to-ast/tools/create-fixtures.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
const fs = require("node:fs");
99
const path = require("node:path");
10-
const mkdirp = require("mkdirp");
1110
const parse = require("../lib/src/index").parse;
1211
const testDir = path.join(__dirname, "..", "test");
1312
// remark_fixtures to fixtures
@@ -20,7 +19,7 @@ fs.readdirSync(remarkFixtures).forEach(function (filePath) {
2019
const originalPath = path.join(remarkFixtures, filePath);
2120
const dirName = path.basename(filePath);
2221
const testCaseDir = path.join(fixtureDir, dirName);
23-
mkdirp.sync(testCaseDir);
22+
fs.mkdirSync(testCaseDir, { recursive: true });
2423
const testInputFilePath = path.join(fixtureDir, dirName, "input.md");
2524
fs.renameSync(originalPath, testInputFilePath);
2625
const input = fs.readFileSync(testInputFilePath, "utf-8");

packages/textlint-scripts/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
},
6161
"devDependencies": {
6262
"lint-staged": "catalog:",
63-
"prettier": "catalog:",
64-
"shelljs": "catalog:"
63+
"prettier": "catalog:"
6564
},
6665
"peerDependencies": {
6766
"ts-node": "*",
Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
11
const path = require("path");
2-
const shell = require("shelljs");
2+
const fs = require("node:fs");
3+
const { execSync } = require("child_process");
34

45
const exampleDir = path.join(__dirname, "../examples/example");
56
const exampleTsDir = path.join(__dirname, "../examples/example-ts");
67
const exampleDynamicImport = path.join(__dirname, "../examples/example-dynamic-import");
78
const examples = [exampleDir, exampleTsDir, exampleDynamicImport];
9+
810
const exec = (command, { cwd }) => {
911
// eslint-disable-next-line no-console
1012
console.log(`$ ${command}`);
11-
if (
12-
shell.exec(command, {
13-
cwd
14-
}).code !== 0
15-
) {
16-
shell.exit(1);
17-
}
18-
};
19-
const cd = (command) => {
20-
// eslint-disable-next-line no-console
21-
console.log(`$ ${command}`);
22-
if (shell.cd(exampleDir).code !== 0) {
23-
shell.exit(1);
13+
try {
14+
execSync(command, { cwd, stdio: "inherit" });
15+
} catch {
16+
process.exit(1);
2417
}
2518
};
19+
2620
for (const example of examples) {
27-
// example
28-
cd(exampleDir);
29-
// installed in monorepo root
30-
// exec("npm install");
31-
exec("rm -f ./README.md", {
32-
cwd: exampleDir
33-
});
34-
exec("npm run init-readme", {
35-
cwd: exampleDir
36-
});
37-
exec("npm run build", {
38-
cwd: exampleDir
39-
});
40-
exec("npm test", {
41-
cwd: exampleDir
42-
});
21+
fs.rmSync(path.join(example, "README.md"), { force: true });
22+
exec("npm run init-readme", { cwd: example });
23+
exec("npm run build", { cwd: example });
24+
exec("npm test", { cwd: example });
4325
}
44-
// exit
45-
shell.exit(0);

packages/textlint/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,9 @@
7575
},
7676
"devDependencies": {
7777
"@textlint/legacy-textlint-core": "workspace:*",
78-
"@types/clone": "catalog:",
7978
"@types/debug": "catalog:",
8079
"@types/node": "catalog:",
81-
"@types/shelljs": "catalog:",
82-
"clone": "catalog:",
8380
"rimraf": "catalog:",
84-
"shelljs": "catalog:",
8581
"textlint-plugin-html": "catalog:",
8682
"textlint-rule-helper": "catalog:",
8783
"textlint-rule-no-todo": "catalog:",

packages/textlint/test/config-initializer/config-initializer.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { afterEach, beforeEach, describe, it } from "vitest";
55
import { Logger } from "../../src/util/logger.js";
66
import path from "node:path";
77
import os from "node:os";
8-
import sh from "shelljs";
98
import assert from "node:assert";
109
import fs from "node:fs";
1110

@@ -18,22 +17,22 @@ describe("config-initializer-test", function () {
1817
const timestamp = Date.now();
1918
const random = Math.random().toString(36).substring(7);
2019
configDir = `${os.tmpdir()}/textlint-config-${timestamp}-${random}`;
21-
sh.mkdir("-p", configDir);
20+
fs.mkdirSync(configDir, { recursive: true });
2221
});
2322

2423
afterEach(function () {
2524
if (fs.existsSync(configDir)) {
26-
sh.rm("-rf", configDir);
25+
fs.rmSync(configDir, { recursive: true, force: true });
2726
}
2827
});
2928
describe("when package.json has textlint-rule-* packages", function () {
3029
beforeEach(function () {
3130
// Ensure directory exists and is accessible
3231
if (!fs.existsSync(configDir)) {
33-
sh.mkdir("-p", configDir);
32+
fs.mkdirSync(configDir, { recursive: true });
3433
}
3534
const packageFilePath = path.resolve(process.cwd(), "test/config-initializer/fixtures/package.json");
36-
sh.cp(packageFilePath, configDir);
35+
fs.cpSync(packageFilePath, path.join(configDir, path.basename(packageFilePath)));
3736
});
3837
it("should create new file with packages", function () {
3938
return createConfigFile({

0 commit comments

Comments
 (0)