clang-format-node 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.js +23 -1
- package/build/index.js +18 -1
- package/build/utils/clangFormatPath.js +34 -1
- package/build/utils/getClangFormatPath.js +47 -1
- package/package.json +3 -2
package/build/cli.js
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
// The shebang line `#!/usr/bin/env node` ensures the script runs with the correct Node.js interpreter across different environments.
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Entry file for the `npx clang-format` and `npx clang-format-node` command. See the `bin` property in `package.json`.
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
// Require
|
|
10
|
+
// --------------------------------------------------------------------------------
|
|
11
|
+
const { spawn } = require('child_process');
|
|
12
|
+
const { clangFormatPath } = require('./utils/clangFormatPath');
|
|
13
|
+
// --------------------------------------------------------------------------------
|
|
14
|
+
// Execution
|
|
15
|
+
// --------------------------------------------------------------------------------
|
|
16
|
+
const spawned = spawn(clangFormatPath, process.argv.slice(2), {
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
});
|
|
19
|
+
spawned.on('close', code => {
|
|
20
|
+
if (code !== 0) {
|
|
21
|
+
console.error(`Process exited with code: ${code}`); // eslint-disable-line no-console
|
|
22
|
+
process.exit(code);
|
|
23
|
+
}
|
|
24
|
+
});
|
package/build/index.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entry file for the `clang-format-node` package.
|
|
4
|
+
*/
|
|
5
|
+
// --------------------------------------------------------------------------------
|
|
6
|
+
// Require
|
|
7
|
+
// --------------------------------------------------------------------------------
|
|
8
|
+
const { clangFormatPath, clangFormatNodePath } = require('./utils/clangFormatPath');
|
|
9
|
+
const { getClangFormatPath, getClangFormatNodePath, } = require('./utils/getClangFormatPath');
|
|
10
|
+
// --------------------------------------------------------------------------------
|
|
11
|
+
// Exports
|
|
12
|
+
// --------------------------------------------------------------------------------
|
|
13
|
+
module.exports = {
|
|
14
|
+
clangFormatPath,
|
|
15
|
+
clangFormatNodePath,
|
|
16
|
+
getClangFormatPath,
|
|
17
|
+
getClangFormatNodePath,
|
|
18
|
+
};
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview `clangFormatPath` and `clangFormatNodePath` APIs.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
|
|
6
|
+
// --------------------------------------------------------------------------------
|
|
7
|
+
// Require
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
const { platform, arch } = require('os');
|
|
10
|
+
const { getClangFormatPath } = require('./getClangFormatPath');
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
// Declaration
|
|
13
|
+
// --------------------------------------------------------------------------------
|
|
14
|
+
/**
|
|
15
|
+
* The ABSOLUTE path to the `clang-format` executable binary based on the OS platform and architecture.
|
|
16
|
+
* @alias `clangFormatNodePath`. See {@link clangFormatNodePath}.
|
|
17
|
+
* @version `v1.2.0` Initial release.
|
|
18
|
+
* @see https://clang-format-node.lumir.page/docs/apis/clang-format-node
|
|
19
|
+
*/
|
|
20
|
+
const clangFormatPath = getClangFormatPath(platform(), arch());
|
|
21
|
+
/**
|
|
22
|
+
* Alias for `clangFormatPath`.
|
|
23
|
+
* @alias `clangFormatPath`. See {@link clangFormatPath}.
|
|
24
|
+
* @version `v1.2.0` Initial release.
|
|
25
|
+
* @see https://clang-format-node.lumir.page/docs/apis/clang-format-node
|
|
26
|
+
*/
|
|
27
|
+
const clangFormatNodePath = clangFormatPath;
|
|
28
|
+
// --------------------------------------------------------------------------------
|
|
29
|
+
// Exports
|
|
30
|
+
// --------------------------------------------------------------------------------
|
|
31
|
+
module.exports = {
|
|
32
|
+
clangFormatPath,
|
|
33
|
+
clangFormatNodePath,
|
|
34
|
+
};
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview `getClangFormatPath` and `getClangFormatNodePath` APIs.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable n/prefer-node-protocol -- DO NOT USE `node:` namespace for backward compatibility */
|
|
6
|
+
// --------------------------------------------------------------------------------
|
|
7
|
+
// Require
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
const { existsSync } = require('fs');
|
|
10
|
+
const { resolve } = require('path');
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
// Declaration
|
|
13
|
+
// --------------------------------------------------------------------------------
|
|
14
|
+
/**
|
|
15
|
+
* Returns the ABSOLUTE path to the `clang-format` executable binary based on the OS platform and architecture.
|
|
16
|
+
*
|
|
17
|
+
* The possible combinations are `darwin-arm64`, `darwin-x64`, `linux-arm`, `linux-arm64`, `linux-ppc64`, `linux-s390x`, `linux-x64`, `win32-x64`.
|
|
18
|
+
*
|
|
19
|
+
* Throws an error if the executable is not found.
|
|
20
|
+
* @param {string} osPlatform The current operating system platform. (e.g., `darwin`, `linux`, `win32`)
|
|
21
|
+
* @param {string} architecture The current system architecture. (e.g., `arm`, `arm64`, `ppc64`, `s390x`, `x64`)
|
|
22
|
+
* @returns {string} The ABSOLUTE path to the `clang-format` executable binary.
|
|
23
|
+
* @throws `Error` Throws an error if the executable binary is not found for the specified OS platform and architecture.
|
|
24
|
+
* @alias `getClangFormatNodePath`. See {@link getClangFormatNodePath}.
|
|
25
|
+
* @version `v1.2.0` Initial release.
|
|
26
|
+
* @see https://clang-format-node.lumir.page/docs/apis/clang-format-node
|
|
27
|
+
*/
|
|
28
|
+
function getClangFormatPath(osPlatform, architecture) {
|
|
29
|
+
const clangFormatPath = resolve(__dirname, `..`, `..`, `bin`, `cfn-${osPlatform}-${architecture}`, `clang-format${osPlatform === 'win32' ? '.exe' : ''}`);
|
|
30
|
+
if (!existsSync(clangFormatPath))
|
|
31
|
+
throw new Error(`No executable found for '${osPlatform}(OS platform)-${architecture}(architecture)'\nThe possible combinations are 'darwin-arm64', 'darwin-x64', 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-s390x', 'linux-x64', 'win32-x64'`);
|
|
32
|
+
return clangFormatPath;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Alias for `getClangFormatPath`.
|
|
36
|
+
* @alias `getClangFormatPath`. See {@link getClangFormatPath}.
|
|
37
|
+
* @version `v1.2.0` Initial release.
|
|
38
|
+
* @see https://clang-format-node.lumir.page/docs/apis/clang-format-node
|
|
39
|
+
*/
|
|
40
|
+
const getClangFormatNodePath = getClangFormatPath;
|
|
41
|
+
// --------------------------------------------------------------------------------
|
|
42
|
+
// Exports
|
|
43
|
+
// --------------------------------------------------------------------------------
|
|
44
|
+
module.exports = {
|
|
45
|
+
getClangFormatPath,
|
|
46
|
+
getClangFormatNodePath,
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clang-format-node",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Node wrapper for clang-format native binary inspired by angular/clang-format.🐉",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"c++"
|
|
32
32
|
],
|
|
33
33
|
"author": "루밀LuMir <rpfos@naver.com> (https://github.com/lumirlumir)",
|
|
34
|
+
"funding": "https://github.com/sponsors/lumirlumir",
|
|
34
35
|
"license": "MIT",
|
|
35
36
|
"homepage": "https://clang-format-node.lumir.page",
|
|
36
37
|
"repository": {
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"scripts": {
|
|
51
52
|
"postinstall": "node chmod.js || exit 0",
|
|
52
53
|
"prepublishOnly": "npm run build",
|
|
53
|
-
"build": "
|
|
54
|
+
"build": "tsc --emitDeclarationOnly false && node ../../scripts/cp.mjs ../../LICENSE.md LICENSE.md ../../README.md README.md",
|
|
54
55
|
"test": "node --test",
|
|
55
56
|
"dev": "node src/cli.js",
|
|
56
57
|
"start": "node build/cli.js"
|