Skip to content

Commit 0abdc91

Browse files
zimegmwbrooks
andauthored
feat(cli-hooks): add default app and manifest watch config (#2480)
Co-authored-by: Michael Brooks <[email protected]>
1 parent f34cdba commit 0abdc91

3 files changed

Lines changed: 88 additions & 4 deletions

File tree

.changeset/green-items-write.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
"@slack/cli-hooks": minor
3+
---
4+
5+
feat(cli-hooks): add default app and manifest watch config
6+
7+
This package now provides default watch configurations for automatic file watching during [`slack run`](https://docs.slack.dev/tools/slack-cli/reference/commands/slack_platform_run). The CLI will restart your app server when source files change and reinstall your app when the manifest changes.
8+
9+
**Requirements:** These features require Slack CLI v3.12.0+ with [file watching support](https://github.com/slackapi/slack-cli/pull/310).
10+
11+
### Default Configuration
12+
13+
The following watch settings are provided automatically when using this package:
14+
15+
```json
16+
{
17+
"config": {
18+
"watch": {
19+
"app": {
20+
"filter-regex": "\\.js$",
21+
"paths": ["."]
22+
},
23+
"manifest": {
24+
"paths": ["manifest.json"]
25+
}
26+
}
27+
}
28+
}
29+
```
30+
31+
- **app**: Watches for JavaScript file changes to restart the app server
32+
- **manifest**: Watches the manifest file for changes to reinstall the app
33+
34+
**Note:** Manifest watching requires a local manifest source in your `.slack/config.json` file. Remote manifests will not be updated on file changes.
35+
36+
```json
37+
{
38+
"manifest": {
39+
"source": "local"
40+
}
41+
}
42+
```
43+
44+
### Custom Configurations
45+
46+
You can override these defaults in your `.slack/hooks.json` file to reduce the paths searched or change the file patterns. Read [Watch Configurations](https://docs.slack.dev/tools/slack-cli/reference/hooks/#watch-configurations) for more options.
47+
48+
### TypeScript Development
49+
50+
TypeScript developers should run `tsc --watch` in a separate terminal during development. This compiles `.ts` files to `.js` on changes, and the default watch configuration will detect changes to the compiled `dist/*.js` files and restart the app server. This approach works best with the default settings.

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,23 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
3232
*/
3333

3434
/**
35-
* Information about the files to watch for specific changes.
35+
* Information about file changes for CLI actions.
3636
* @typedef SDKConfigWatch
37-
* @property {string} filter-regex - Regex pattern for finding filtered files.
37+
* @property {AppConfigWatch} app - Watch config for server restarts.
38+
* @property {ManifestConfigWatch} manifest - Watch config for app reinstalls.
39+
*/
40+
41+
/**
42+
* Information about the app files to watch for server restarts.
43+
* @typedef AppConfigWatch
44+
* @property {string} [filter-regex] - Regex pattern for finding filtered files.
45+
* @property {string[]} paths - Specific locations to begin searching for files.
46+
*/
47+
48+
/**
49+
* Information about the manifest files to watch for app reinstalls.
50+
* @typedef ManifestConfigWatch
51+
* @property {string} [filter-regex] - Regex pattern for finding filtered files.
3852
* @property {string[]} paths - Specific locations to begin searching for files.
3953
*/
4054

@@ -52,8 +66,13 @@ export default function getHooks() {
5266
},
5367
config: {
5468
watch: {
55-
'filter-regex': '^manifest\\.json$',
56-
paths: ['.'],
69+
app: {
70+
'filter-regex': '\\.js$',
71+
paths: ['.'],
72+
},
73+
manifest: {
74+
paths: ['manifest.json'],
75+
},
5776
},
5877
'protocol-version': SUPPORTED_NAMED_PROTOCOLS,
5978
'sdk-managed-connection-enabled': true,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,19 @@ describe('get-hooks implementation', async () => {
2121
const { config } = getHooks();
2222
assert(config['sdk-managed-connection-enabled']);
2323
});
24+
25+
it('should return watch config for app files', async () => {
26+
const { config } = getHooks();
27+
assert(config.watch);
28+
assert(config.watch.app);
29+
assert.equal(config.watch.app['filter-regex'], '\\.js$');
30+
assert.deepEqual(config.watch.app.paths, ['.']);
31+
});
32+
33+
it('should return watch config for manifest files', async () => {
34+
const { config } = getHooks();
35+
assert(config.watch);
36+
assert(config.watch.manifest);
37+
assert.deepEqual(config.watch.manifest.paths, ['manifest.json']);
38+
});
2439
});

0 commit comments

Comments
 (0)