@ultirequiem/is-installed 0.0.0-stage → 1.0.0

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/lib/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Check whether a program is installed, by trying to run it.
3
+ *
4
+ * @param program - The command to look for.
5
+ * @param args - Arguments used for the probe run, defaults to `--help`.
6
+ *
7
+ * @example
8
+ * ```javascript
9
+ * import { isInstalled } from "@ultirequiem/is-installed";
10
+ *
11
+ * await isInstalled("ls"); //=> true
12
+ * await isInstalled("non-existing-command"); //=> false
13
+ * ```
14
+ */
15
+ export declare function isInstalled(program: string, args?: string[]): Promise<boolean>;
16
+ /**
17
+ * Synchronous version of {@link isInstalled}.
18
+ *
19
+ * @param program - The command to look for.
20
+ * @param args - Arguments used for the probe run, defaults to `--help`.
21
+ */
22
+ export declare function isInstalledSync(program: string, args?: string[]): boolean;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAe,GAC1B,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAe,GAC1B,OAAO,CAQT"}
package/lib/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ const isNotFound = (error) => error?.code === "ENOENT";
3
+ /**
4
+ * Check whether a program is installed, by trying to run it.
5
+ *
6
+ * @param program - The command to look for.
7
+ * @param args - Arguments used for the probe run, defaults to `--help`.
8
+ *
9
+ * @example
10
+ * ```javascript
11
+ * import { isInstalled } from "@ultirequiem/is-installed";
12
+ *
13
+ * await isInstalled("ls"); //=> true
14
+ * await isInstalled("non-existing-command"); //=> false
15
+ * ```
16
+ */
17
+ export function isInstalled(program, args = ["--help"]) {
18
+ return new Promise((resolve, reject) => {
19
+ const child = spawn(program, args, { stdio: "ignore" });
20
+ child.once("error", (error) => {
21
+ if (isNotFound(error)) {
22
+ resolve(false);
23
+ }
24
+ else {
25
+ reject(error);
26
+ }
27
+ });
28
+ child.once("close", () => {
29
+ resolve(true);
30
+ });
31
+ });
32
+ }
33
+ /**
34
+ * Synchronous version of {@link isInstalled}.
35
+ *
36
+ * @param program - The command to look for.
37
+ * @param args - Arguments used for the probe run, defaults to `--help`.
38
+ */
39
+ export function isInstalledSync(program, args = ["--help"]) {
40
+ const { error } = spawnSync(program, args, { stdio: "ignore" });
41
+ if (error && !isNotFound(error)) {
42
+ throw error;
43
+ }
44
+ return !error;
45
+ }
package/license ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Eliaz Bobadilla <eliaz.bobadilla@gmail.com>
4
+ (https://ultirequiem.com)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@ultirequiem/is-installed",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Check whether a program is installed.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "import": "./lib/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "lib/**/*"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "keywords": [
21
+ "cli",
22
+ "binary",
23
+ "which",
24
+ "esm",
25
+ "typescript"
26
+ ],
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/UltiRequiem/is_installed.git"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "lint": "eslint 'src/**/*.ts' && prettier --check 'src/**/*.ts'",
35
+ "fmt": "prettier --write 'src/**/*.ts'",
36
+ "test": "vitest run",
37
+ "test:coverage": "vitest run --coverage"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^26.6.5",
41
+ "@vitest/coverage-v8": "^5.0.5",
42
+ "eslint": "^10.13.0",
43
+ "eslint-plugin-tsdoc": "^0.5.4",
44
+ "eslint-plugin-unicorn": "^78.0.0",
45
+ "prettier": "^3.9.10",
46
+ "typescript": "^6.0.3",
47
+ "typescript-eslint": "^8.72.0",
48
+ "vitest": "^5.0.5"
49
+ },
50
+ "packageManager": "pnpm@12.6.0"
51
+ }
package/readme.md ADDED
@@ -0,0 +1,34 @@
1
+ # is_installed
2
+
3
+ Check whether a program is installed.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@ultirequiem/is-installed?logo=npm&color=cb3837)](https://www.npmjs.com/package/@ultirequiem/is-installed)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@ultirequiem/is-installed?color=cb3837)](https://www.npmjs.com/package/@ultirequiem/is-installed)
7
+ [![CI](https://github.com/UltiRequiem/is_installed/actions/workflows/ci.yaml/badge.svg)](https://github.com/UltiRequiem/is_installed/actions/workflows/ci.yaml)
8
+ [![codecov](https://codecov.io/gh/UltiRequiem/is_installed/graph/badge.svg)](https://codecov.io/gh/UltiRequiem/is_installed)
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install @ultirequiem/is-installed
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ESM only, types included: the same import works in Node.js, Bun and browsers.
19
+
20
+ ```javascript
21
+ import { isInstalled } from "@ultirequiem/is-installed";
22
+
23
+ await isInstalled("ls"); //=> true
24
+ await isInstalled("non-existing-command"); //=> false
25
+ ```
26
+
27
+ ## Versioning
28
+
29
+ We use [Semantic Versioning](http://semver.org). For the versions available, see
30
+ the [tags](https://github.com/UltiRequiem/is_installed/tags) 🏷️
31
+
32
+ ## Licence
33
+
34
+ MIT License 📄
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.