Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .changeset/green-items-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
"@slack/cli-hooks": minor
---

feat(cli-hooks): add default app and manifest watch config

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.

**Requirements:** These features require Slack CLI v3.12.0+ with [file watching support](https://github.com/slackapi/slack-cli/pull/310).

### Default Configuration

The following watch settings are provided automatically when using this package:

```json
{
"config": {
"watch": {
"app": {
"filter-regex": "\\.js$",
"paths": ["."]
},
"manifest": {
"paths": ["manifest.json"]
}
}
}
}
```

- **app**: Watches for JavaScript file changes to restart the app server
- **manifest**: Watches the manifest file for changes to reinstall the app

**Note:** Manifest watching requires a local manifest source in your `.slack/config.json` file. Remote manifests will not be updated on file changes.

```json
{
"manifest": {
"source": "local"
}
}
```

### Custom Configurations

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩


### TypeScript Development

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.
27 changes: 23 additions & 4 deletions packages/cli-hooks/src/get-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,23 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
*/

/**
* Information about the files to watch for specific changes.
* Information about file changes for CLI actions.
* @typedef SDKConfigWatch
* @property {string} filter-regex - Regex pattern for finding filtered files.
* @property {AppConfigWatch} app - Watch config for server restarts.
* @property {ManifestConfigWatch} manifest - Watch config for app reinstalls.
*/

/**
* Information about the app files to watch for server restarts.
* @typedef AppConfigWatch
* @property {string} [filter-regex] - Regex pattern for finding filtered files.
* @property {string[]} paths - Specific locations to begin searching for files.
*/

/**
* Information about the manifest files to watch for app reinstalls.
* @typedef ManifestConfigWatch
* @property {string} [filter-regex] - Regex pattern for finding filtered files.
* @property {string[]} paths - Specific locations to begin searching for files.
*/

Expand All @@ -52,8 +66,13 @@ export default function getHooks() {
},
config: {
watch: {
'filter-regex': '^manifest\\.json$',
paths: ['.'],
app: {
'filter-regex': '\\.js$',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Non-blocker. Not sure if we want to include, this but we could ignore node_modules to avoid restarting the server when the developer runs npm install.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks Our current CLI implementations don't support "not" paths AFAICT. We might want to follow up with this, since changes to the test directories might also be odd to cause restarts! 🤖

paths: ['.'],
},
manifest: {
paths: ['manifest.json'],
},
},
'protocol-version': SUPPORTED_NAMED_PROTOCOLS,
'sdk-managed-connection-enabled': true,
Expand Down
15 changes: 15 additions & 0 deletions packages/cli-hooks/src/get-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ describe('get-hooks implementation', async () => {
const { config } = getHooks();
assert(config['sdk-managed-connection-enabled']);
});

it('should return watch config for app files', async () => {
const { config } = getHooks();
assert(config.watch);
assert(config.watch.app);
assert.equal(config.watch.app['filter-regex'], '\\.js$');
assert.deepEqual(config.watch.app.paths, ['.']);
});

it('should return watch config for manifest files', async () => {
const { config } = getHooks();
assert(config.watch);
assert(config.watch.manifest);
assert.deepEqual(config.watch.manifest.paths, ['manifest.json']);
Comment on lines +25 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty for good tests 👾!

});
});