Skip to content

Commit df49101

Browse files
authored
fix(*): drop shx and replace it with Node.js native script (#402)
This pull request refactors the handling of file permissions across three packages (`clang-format-git-python`, `clang-format-git`, and `clang-format-node`) by replacing the use of the `shx` dependency with custom `chmod.js` scripts. These scripts ensure that the necessary files and binaries have the correct execution permissions. Additionally, the `postinstall` and `postbuild` scripts are updated to use these new `chmod.js` files, and the `shx` dependency is removed. ### File Permission Handling Updates: * [`packages/clang-format-git-python/chmod.js`](diffhunk://#diff-27b69f71118a60e9a2ad54a11e79e10b8485e6080af45ec037ee193fd598c77cR1-R26): Added a script to set execution permissions for the `git-clang-format` script using `chmodSync`. * [`packages/clang-format-git/chmod.js`](diffhunk://#diff-337db8b3485bbb276d0c1b16655b094b11cf7605b7adc8e52a4b3f06d0e9edabR1-R33): Added a script to set execution permissions for binaries in the `bin` directory, filtering for files containing `git-clang-format`. * [`packages/clang-format-node/chmod.js`](diffhunk://#diff-36fbb1ea12298f23d64d479606f6b239ed8a2ca3373684dbd49b5037f16bbfe6R1-R36): Added a script to set execution permissions for binaries in the `bin` directory, filtering for files containing `clang-format`. ### Package Configuration Updates: * [`packages/clang-format-git-python/package.json`](diffhunk://#diff-fb0eb5dba5b2656b3fdea4322c2ed2a691973f2e9ea536ce20b36c347ab1267eR9): Added `chmod.js` to the `files` array, replaced `npm run chmod` with `node chmod.js` in the `postinstall` script, and removed the `shx` dependency. [[1]](diffhunk://#diff-fb0eb5dba5b2656b3fdea4322c2ed2a691973f2e9ea536ce20b36c347ab1267eR9) [[2]](diffhunk://#diff-fb0eb5dba5b2656b3fdea4322c2ed2a691973f2e9ea536ce20b36c347ab1267eL52-R61) * [`packages/clang-format-git/package.json`](diffhunk://#diff-d85dcfb0934f579cff896723ab5eeb9a52668d2bb322338dddd93bc1241aa4f1R9): Added `chmod.js` to the `files` array, replaced `npm run chmod` with `node chmod.js` in the `postinstall` script, and removed the `shx` dependency. [[1]](diffhunk://#diff-d85dcfb0934f579cff896723ab5eeb9a52668d2bb322338dddd93bc1241aa4f1R9) [[2]](diffhunk://#diff-d85dcfb0934f579cff896723ab5eeb9a52668d2bb322338dddd93bc1241aa4f1L51-R60) * [`packages/clang-format-node/package.json`](diffhunk://#diff-6e04d643c57b851ab02ad78e41531387d2cc01caf6c4cfbaa536aadd37346a30R9): Added `chmod.js` to the `files` array, replaced `npm run chmod` with `node chmod.js` in the `postinstall` script, and removed the `shx` dependency. [[1]](diffhunk://#diff-6e04d643c57b851ab02ad78e41531387d2cc01caf6c4cfbaa536aadd37346a30R9) [[2]](diffhunk://#diff-6e04d643c57b851ab02ad78e41531387d2cc01caf6c4cfbaa536aadd37346a30L50-L60)
1 parent 168f217 commit df49101

File tree

8 files changed

+137
-228
lines changed

8 files changed

+137
-228
lines changed

package-lock.json

Lines changed: 32 additions & 210 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @fileoverview Script to change permissions of a script.
3+
*/
4+
5+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
6+
7+
// --------------------------------------------------------------------------------
8+
// Require
9+
// --------------------------------------------------------------------------------
10+
11+
const { resolve } = require('path');
12+
const { chmodSync } = require('fs');
13+
14+
// --------------------------------------------------------------------------------
15+
// Execution
16+
// --------------------------------------------------------------------------------
17+
18+
const scriptPath = resolve(__dirname, 'script', 'git-clang-format');
19+
20+
try {
21+
chmodSync(scriptPath, 0o755);
22+
} catch (error) {
23+
// eslint-disable-next-line no-console
24+
console.error(`Error changing permissions for ${scriptPath}:`, error.message);
25+
throw error;
26+
}

packages/clang-format-git-python/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"files": [
77
"build",
88
"script",
9+
"chmod.js",
910
"LICENSE.md",
1011
"README.md"
1112
],
@@ -49,17 +50,14 @@
4950
"provenance": true
5051
},
5152
"scripts": {
52-
"postinstall": "npm run chmod",
53+
"postinstall": "node chmod.js || exit 0",
5354
"prepublishOnly": "npm run build",
5455
"build": "npx babel src -d build && npx tsc && node ../../scripts/cp.mjs ../../LICENSE.md LICENSE.md ../../README.md README.md",
55-
"postbuild": "npm run chmod",
5656
"test": "node --test",
57-
"chmod": "shx chmod 755 ./script/**/* || exit 0",
5857
"dev": "node src/cli.js",
5958
"start": "node build/cli.js"
6059
},
6160
"dependencies": {
62-
"clang-format-node": "^1.3.4",
63-
"shx": "^0.4.0"
61+
"clang-format-node": "^1.3.4"
6462
}
6563
}

packages/clang-format-git/chmod.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @fileoverview Script to change permissions of binaries.
3+
*/
4+
5+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
6+
7+
// --------------------------------------------------------------------------------
8+
// Require
9+
// --------------------------------------------------------------------------------
10+
11+
const { resolve } = require('path');
12+
const { chmodSync, readdirSync } = require('fs');
13+
14+
// --------------------------------------------------------------------------------
15+
// Execution
16+
// --------------------------------------------------------------------------------
17+
18+
const binPath = resolve(__dirname, 'bin');
19+
const clangFormatGitPaths = readdirSync(binPath, {
20+
recursive: true,
21+
})
22+
.filter(path => path.includes('git-clang-format'))
23+
.map(path => resolve(binPath, path));
24+
25+
clangFormatGitPaths.forEach(clangFormatGitPath => {
26+
try {
27+
chmodSync(clangFormatGitPath, 0o755);
28+
} catch (error) {
29+
// eslint-disable-next-line no-console
30+
console.error(`Error changing permissions for ${clangFormatGitPath}:`, error.message);
31+
throw error;
32+
}
33+
});

packages/clang-format-git/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"files": [
77
"bin",
88
"build",
9+
"chmod.js",
910
"LICENSE.md",
1011
"README.md"
1112
],
@@ -48,17 +49,14 @@
4849
"provenance": true
4950
},
5051
"scripts": {
51-
"postinstall": "npm run chmod",
52+
"postinstall": "node chmod.js || exit 0",
5253
"prepublishOnly": "npm run build",
5354
"build": "npx babel src -d build && npx tsc && node ../../scripts/cp.mjs ../../LICENSE.md LICENSE.md ../../README.md README.md",
54-
"postbuild": "npm run chmod",
5555
"test": "node --test",
56-
"chmod": "shx chmod 755 ./bin/**/* || exit 0",
5756
"dev": "node src/cli.js",
5857
"start": "node build/cli.js"
5958
},
6059
"dependencies": {
61-
"clang-format-node": "^1.3.4",
62-
"shx": "^0.4.0"
60+
"clang-format-node": "^1.3.4"
6361
}
6462
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @fileoverview Script to change permissions of binaries.
3+
*/
4+
5+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
6+
7+
// --------------------------------------------------------------------------------
8+
// Require
9+
// --------------------------------------------------------------------------------
10+
11+
const { resolve } = require('path');
12+
const { chmodSync, readdirSync } = require('fs');
13+
14+
// --------------------------------------------------------------------------------
15+
// Execution
16+
// --------------------------------------------------------------------------------
17+
18+
const binPath = resolve(__dirname, 'bin');
19+
const clangFormatNodePaths = readdirSync(binPath, {
20+
recursive: true,
21+
})
22+
.filter(path => path.includes('clang-format'))
23+
.map(path => resolve(binPath, path));
24+
25+
clangFormatNodePaths.forEach(clangFormatNodePath => {
26+
try {
27+
chmodSync(clangFormatNodePath, 0o755);
28+
} catch (error) {
29+
// eslint-disable-next-line no-console
30+
console.error(
31+
`Error changing permissions for ${clangFormatNodePath}:`,
32+
error.message,
33+
);
34+
throw error;
35+
}
36+
});

packages/clang-format-node/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"files": [
77
"bin",
88
"build",
9+
"chmod.js",
910
"LICENSE.md",
1011
"README.md"
1112
],
@@ -47,16 +48,11 @@
4748
"provenance": true
4849
},
4950
"scripts": {
50-
"postinstall": "npm run chmod",
51+
"postinstall": "node chmod.js || exit 0",
5152
"prepublishOnly": "npm run build",
5253
"build": "npx babel src -d build && npx tsc && node ../../scripts/cp.mjs ../../LICENSE.md LICENSE.md ../../README.md README.md",
53-
"postbuild": "npm run chmod",
5454
"test": "node --test",
55-
"chmod": "shx chmod 755 ./bin/**/* || exit 0",
5655
"dev": "node src/cli.js",
5756
"start": "node build/cli.js"
58-
},
59-
"dependencies": {
60-
"shx": "^0.4.0"
6157
}
6258
}

website/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ features:
3232
linkText: Migration Guide
3333

3434
- icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 448 512" height="32px" width="32px" xmlns="http://www.w3.org/2000/svg"><path d="M224 508c-6.7 0-13.5-1.8-19.4-5.2l-61.7-36.5c-9.2-5.2-4.7-7-1.7-8 12.3-4.3 14.8-5.2 27.9-12.7 1.4-.8 3.2-.5 4.6.4l47.4 28.1c1.7 1 4.1 1 5.7 0l184.7-106.6c1.7-1 2.8-3 2.8-5V149.3c0-2.1-1.1-4-2.9-5.1L226.8 37.7c-1.7-1-4-1-5.7 0L36.6 144.3c-1.8 1-2.9 3-2.9 5.1v213.1c0 2 1.1 4 2.9 4.9l50.6 29.2c27.5 13.7 44.3-2.4 44.3-18.7V167.5c0-3 2.4-5.3 5.4-5.3h23.4c2.9 0 5.4 2.3 5.4 5.3V378c0 36.6-20 57.6-54.7 57.6-10.7 0-19.1 0-42.5-11.6l-48.4-27.9C8.1 389.2.7 376.3.7 362.4V149.3c0-13.8 7.4-26.8 19.4-33.7L204.6 9c11.7-6.6 27.2-6.6 38.8 0l184.7 106.7c12 6.9 19.4 19.8 19.4 33.7v213.1c0 13.8-7.4 26.7-19.4 33.7L243.4 502.8c-5.9 3.4-12.6 5.2-19.4 5.2zm149.1-210.1c0-39.9-27-50.5-83.7-58-57.4-7.6-63.2-11.5-63.2-24.9 0-11.1 4.9-25.9 47.4-25.9 37.9 0 51.9 8.2 57.7 33.8.5 2.4 2.7 4.2 5.2 4.2h24c1.5 0 2.9-.6 3.9-1.7s1.5-2.6 1.4-4.1c-3.7-44.1-33-64.6-92.2-64.6-52.7 0-84.1 22.2-84.1 59.5 0 40.4 31.3 51.6 81.8 56.6 60.5 5.9 65.2 14.8 65.2 26.7 0 20.6-16.6 29.4-55.5 29.4-48.9 0-59.6-12.3-63.2-36.6-.4-2.6-2.6-4.5-5.3-4.5h-23.9c-3 0-5.3 2.4-5.3 5.3 0 31.1 16.9 68.2 97.8 68.2 58.4-.1 92-23.2 92-63.4z"></path></svg>'
35-
title: Use only Node.js, no other dependencies needed
36-
details: No need for Python or C++. Just use Node.js with no additional dependencies required.
35+
title: Zero dependencies
36+
details: No need for Python, C++, or any npm sub-dependencies. Just use Node.js alone, with no extra dependencies.
3737
link: /docs/get-started/installation
3838
linkText: Installation
3939

0 commit comments

Comments
 (0)