Skip to content

Commit

Permalink
feat(clang-forma-node): add new API aliases clangFormatNodePath and…
Browse files Browse the repository at this point in the history
… `getClangFormatNodePath` (#83)

* chore: update `package.json`'s `bin`

* wip: update `clangFormatPath.js`

* wip: update `clangFormatPath.test.js`

* wip: update `getClangFormatPath.js`

* wip: update `getClangFormatPath.test.js`

* wip: update `index.js`

* wip: update `index.test.js`
  • Loading branch information
lumirlumir authored Nov 7, 2024
1 parent 610ac74 commit 7ad27e5
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/clang-format-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"README.md"
],
"bin": {
"clang-format": "build/cli.js"
"clang-format": "build/cli.js",
"clang-format-node": "build/cli.js"
},
"keywords": [
"clang-format",
Expand Down
9 changes: 7 additions & 2 deletions packages/clang-format-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const { clangFormatPath } = require('./utils/clangFormatPath');
const { getClangFormatPath } = require('./utils/getClangFormatPath');
const { clangFormatPath, clangFormatNodePath } = require('./utils/clangFormatPath');
const {
getClangFormatPath,
getClangFormatNodePath,
} = require('./utils/getClangFormatPath');

module.exports = {
clangFormatPath,
clangFormatNodePath,
getClangFormatPath,
getClangFormatNodePath,
};
13 changes: 12 additions & 1 deletion packages/clang-format-node/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
const { ok } = require('node:assert');
const { describe, it } = require('node:test');

const { clangFormatPath, getClangFormatPath } = require('./index');
const {
clangFormatPath,
clangFormatNodePath,
getClangFormatPath,
getClangFormatNodePath,
} = require('./index');

describe('index ok testing', () => {
it('clangFormatPath should be imported correctly', () => {
ok(clangFormatPath);
});
it('clangFormatNodePath should be imported correctly', () => {
ok(clangFormatNodePath);
});
it('getClangFormatPath should be imported correctly', () => {
ok(getClangFormatPath);
});
it('getClangFormatNodePath should be imported correctly', () => {
ok(getClangFormatNodePath);
});
});
12 changes: 12 additions & 0 deletions packages/clang-format-node/src/utils/clangFormatPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ const { getClangFormatPath } = require('./getClangFormatPath');

/**
* The ABSOLUTE path to the `clang-format` executable binary based on the OS platform and architecture.
*
* @alias `clangFormatNodePath`. See {@link clangFormatNodePath}.
* @version `v1.2.0` Initial release.
*/
const clangFormatPath = getClangFormatPath(platform(), arch());

/**
* Alias for `clangFormatPath`.
*
* @alias `clangFormatPath`. See {@link clangFormatPath}.
* @version `v1.2.0` Initial release.
*/
const clangFormatNodePath = clangFormatPath;

module.exports = {
clangFormatPath,
clangFormatNodePath,
};
5 changes: 4 additions & 1 deletion packages/clang-format-node/src/utils/clangFormatPath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ const { strictEqual } = require('node:assert');
const { platform, arch } = require('node:os');
const { describe, it } = require('node:test');

const { clangFormatPath } = require('./clangFormatPath');
const { clangFormatPath, clangFormatNodePath } = require('./clangFormatPath');
const { getClangFormatPath } = require('./getClangFormatPath');

describe('clangFormatPath strictEqual testing', () => {
it('clangFormatPath === getClangFormatPath(platform(), arch())', () => {
strictEqual(clangFormatPath, getClangFormatPath(platform(), arch()));
});
it('clangFormatNodePath === clangFormatPath', () => {
strictEqual(clangFormatNodePath, clangFormatPath);
});
});
11 changes: 11 additions & 0 deletions packages/clang-format-node/src/utils/getClangFormatPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const { resolve } = require('path');
* @param {string} architecture The current system architecture. (e.g., `arm`, `arm64`, `ppc64`, `s390x`, `x64`)
* @returns {string} The ABSOLUTE path to the `clang-format` executable binary.
* @throws `Error` Throws an error if the executable binary is not found for the specified OS platform and architecture.
* @alias `getClangFormatNodePath`. See {@link getClangFormatNodePath}.
* @version `v1.2.0` Initial release.
*/
function getClangFormatPath(osPlatform, architecture) {
const clangFormatPath = resolve(
Expand All @@ -30,6 +32,15 @@ function getClangFormatPath(osPlatform, architecture) {
return clangFormatPath;
}

/**
* Alias for `getClangFormatPath`.
*
* @alias `getClangFormatPath`. See {@link getClangFormatPath}.
* @version `v1.2.0` Initial release.
*/
const getClangFormatNodePath = getClangFormatPath;

module.exports = {
getClangFormatPath,
getClangFormatNodePath,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { doesNotThrow, throws } = require('node:assert');
const { describe, it } = require('node:test');

const { getClangFormatPath } = require('./getClangFormatPath');
const { getClangFormatPath, getClangFormatNodePath } = require('./getClangFormatPath');

/**
* See possible values in {@link https://nodejs.org/api/os.html#osplatform}.
Expand Down Expand Up @@ -44,10 +44,12 @@ describe('getClangFormatPath doesNotThrow and throws testing', () => {
if (allowed[osPlatform] && allowed[osPlatform].includes(architecture)) {
doesNotThrow(() => {
getClangFormatPath(osPlatform, architecture);
getClangFormatNodePath(osPlatform, architecture);
});
} else {
throws(() => {
getClangFormatPath(osPlatform, architecture);
getClangFormatNodePath(osPlatform, architecture);
});
}
});
Expand Down

0 comments on commit 7ad27e5

Please sign in to comment.