diff --git a/.changeset/green-items-write.md b/.changeset/green-items-write.md new file mode 100644 index 000000000..d38009434 --- /dev/null +++ b/.changeset/green-items-write.md @@ -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. + +### 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. diff --git a/packages/cli-hooks/src/get-hooks.js b/packages/cli-hooks/src/get-hooks.js index af920a5a4..e8fe02c1d 100755 --- a/packages/cli-hooks/src/get-hooks.js +++ b/packages/cli-hooks/src/get-hooks.js @@ -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. */ @@ -52,8 +66,13 @@ export default function getHooks() { }, config: { watch: { - 'filter-regex': '^manifest\\.json$', - paths: ['.'], + app: { + 'filter-regex': '\\.js$', + paths: ['.'], + }, + manifest: { + paths: ['manifest.json'], + }, }, 'protocol-version': SUPPORTED_NAMED_PROTOCOLS, 'sdk-managed-connection-enabled': true, diff --git a/packages/cli-hooks/src/get-hooks.spec.js b/packages/cli-hooks/src/get-hooks.spec.js index 93527c17f..e83038f7a 100755 --- a/packages/cli-hooks/src/get-hooks.spec.js +++ b/packages/cli-hooks/src/get-hooks.spec.js @@ -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']); + }); });