Skip to content

Commit 3e29641

Browse files
authored
feat: return runtime versions used by the application with a doctor hook (#1763)
1 parent 6ab1e68 commit 3e29641

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

packages/cli-hooks/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ installed.
5050
### Supported Hooks
5151

5252
The hooks that are currently supported for use within the Slack CLI include
53-
`check-update`, `get-hooks`, `get-manifest`, and `start`:
53+
`check-update`, `doctor`, `get-hooks`, `get-manifest`, and `start`:
5454

5555
| Hook Name | CLI Command | File |Description |
5656
| -------------- | ---------------- | ---- | ----------- |
5757
| `check-update` | `slack update` | [`check-update.js`](./src/check-update.js) | Checks the project's Slack dependencies to determine whether or not any packages need to be updated. |
58+
| `doctor` | `slack doctor` | [`doctor.js`](./src/doctor.js) | Returns runtime versions and other system dependencies required by the application. |
5859
| `get-hooks` | All | [`get-hooks.js`](./src/get-hooks.js) | Fetches the list of available hooks for the CLI from this repository. |
5960
| `get-manifest` | `slack manifest` | [`get-manifest.js`](./src/get-manifest.js) | Converts a `manifest.json` file into a valid manifest JSON payload. |
6061
| `start` | `slack run` | [`start.js`](./src/start.js) | While developing locally, the CLI manages a socket connection with Slack's backend and utilizes this hook for events received via this connection. |

packages/cli-hooks/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@slack/cli-hooks",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Node implementation of the contract between the Slack CLI and Bolt for JavaScript",
55
"author": "Slack Technologies, LLC",
66
"license": "MIT",
@@ -13,6 +13,7 @@
1313
"main": "src/get-hooks.js",
1414
"files": [
1515
"src/check-update.js",
16+
"src/doctor.js",
1617
"src/get-hooks.js",
1718
"src/get-manifest.js",
1819
"src/protocols.js",
@@ -42,9 +43,10 @@
4243
"test": "c8 mocha src/*.spec.js"
4344
},
4445
"bin": {
46+
"slack-cli-check-update": "src/check-update.js",
47+
"slack-cli-doctor": "src/doctor.js",
4548
"slack-cli-get-hooks": "src/get-hooks.js",
4649
"slack-cli-get-manifest": "src/get-manifest.js",
47-
"slack-cli-check-update": "src/check-update.js",
4850
"slack-cli-start": "src/start.js"
4951
},
5052
"dependencies": {

packages/cli-hooks/src/doctor.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
import { fileURLToPath } from 'url';
4+
import fs from 'fs';
5+
6+
import { getProtocol } from './protocols.js';
7+
8+
/**
9+
* Implementation of the optional doctor script hook for the Slack CLI.
10+
* Printed as an object containing information about the system runtime.
11+
*/
12+
13+
if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
14+
const protocol = getProtocol(process.argv.slice(1));
15+
protocol.respond(JSON.stringify(doctor())); // eslint-disable-line no-console
16+
}
17+
18+
/**
19+
* Standardized communication format between the SDK and CLI regarding runtimes.
20+
* @typedef DoctorResponse
21+
* @property {RuntimeVersion[]} versions - Existing system dependencies present.
22+
*/
23+
24+
/**
25+
* Information about all of the installed runtime dependencies.
26+
* @typedef RuntimeVersion
27+
* @property {string} name - Name of the runtime dependency.
28+
* @property {string} current - Version found on the system.
29+
*/
30+
31+
/**
32+
* Contains available hooks and other configurations available to the SDK.
33+
* @returns {DoctorResponse} Information about the hooks currently supported.
34+
*/
35+
export default function doctor() {
36+
return {
37+
versions: [
38+
{
39+
name: 'node',
40+
current: process.versions.node,
41+
},
42+
{
43+
name: 'v8',
44+
current: process.versions.v8,
45+
},
46+
{
47+
name: 'modules',
48+
current: process.versions.modules,
49+
},
50+
],
51+
};
52+
}

packages/cli-hooks/src/doctor.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, it } from 'mocha';
2+
import assert from 'assert';
3+
4+
import doctor from './doctor.js';
5+
6+
describe('doctor implementation', async () => {
7+
it('should return versions of runtime dependencies', async () => {
8+
const { versions } = doctor();
9+
assert(versions[0].name === 'node');
10+
assert(versions[0].current === process.versions.node);
11+
assert(versions[1].name === 'v8');
12+
assert(versions[1].current === process.versions.v8);
13+
assert(versions[2].name === 'modules');
14+
assert(versions[2].current === process.versions.modules);
15+
});
16+
});

packages/cli-hooks/src/get-hooks.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import fs from 'fs';
66
import { SUPPORTED_NAMED_PROTOCOLS } from './protocols.js';
77

88
/**
9-
* Implementation the get-hooks script hook required by the Slack CLI.
10-
* Printed as an object containing featured provided by the SDK.
9+
* Implementation of the get-hooks script hook required by the Slack CLI.
10+
* Printed as an object containing features provided by the SDK.
1111
*/
1212

1313
if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
@@ -45,8 +45,9 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
4545
export default function getHooks() {
4646
return {
4747
hooks: {
48-
'get-manifest': 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest',
48+
doctor: 'npx -q --no-install -p @slack/cli-hooks slack-cli-doctor',
4949
'check-update': 'npx -q --no-install -p @slack/cli-hooks slack-cli-check-update',
50+
'get-manifest': 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest',
5051
start: 'npx -q --no-install -p @slack/cli-hooks slack-cli-start',
5152
},
5253
config: {

packages/cli-hooks/src/get-hooks.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import getHooks from './get-hooks.js';
66
describe('get-hooks implementation', async () => {
77
it('should return scripts for required hooks', async () => {
88
const { hooks } = getHooks();
9-
assert(hooks['get-manifest'] === 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest');
9+
assert(hooks.doctor === 'npx -q --no-install -p @slack/cli-hooks slack-cli-doctor');
1010
assert(hooks['check-update'] === 'npx -q --no-install -p @slack/cli-hooks slack-cli-check-update');
11+
assert(hooks['get-manifest'] === 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest');
1112
assert(hooks.start === 'npx -q --no-install -p @slack/cli-hooks slack-cli-start');
1213
});
1314

0 commit comments

Comments
 (0)