Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli-hooks): silence node warnings that can break @slack/cli-hooks #2096

Merged
merged 3 commits into from
Nov 21, 2024
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
2 changes: 1 addition & 1 deletion packages/cli-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Below is an example `slack.json` file that overrides the default `start` hook:
```json
{
"hooks": {
"get-hooks": "npx -q --no-install -p @slack/cli-hooks slack-cli-get-hooks",
"get-hooks": "NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-get-hooks",
"start": "npm run dev"
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/cli-hooks/src/get-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
* @returns {SDKInterface} Information about the hooks currently supported.
*/
export default function getHooks() {
// NODE_NO_WARNINGS=1 silences node process warnings. These warnings can occur
// on some node version (e.g. v23.2.0) and cause invalid JSON hook responses.
return {
hooks: {
doctor: 'npx -q --no-install -p @slack/cli-hooks slack-cli-doctor',
'check-update': 'npx -q --no-install -p @slack/cli-hooks slack-cli-check-update',
'get-manifest': 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest',
doctor: 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-doctor',
'check-update': 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-check-update',
'get-manifest': 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest',
Copy link
Member

Choose a reason for hiding this comment

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

🙏 Nice find! I hadn't noticed these warnings in the versions we officially support - 18, 20, 22 for now - but think this is a nice and quick guard for those on the cutting edge.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I'm honestly a little confused around why the warnings are happening only 23. A long time ago, node used odd majors as "experimental" releases and even majors as "stable" releases, but I thought they stopped that pattern.

Copy link
Member

Choose a reason for hiding this comment

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

The Node release schedule is so interesting to me!

I believe odd versions are treated as a "current" release and act as an upgrading version to the next even version. These odd versions never get long term support 😅

We might want to discuss testing with the latest current version across the SDKs to make sure bumping to the next current LTS goes smooth.

Supporting that version IMO is another question 🤔

start: 'npx -q --no-install -p @slack/cli-hooks slack-cli-start',
},
config: {
Expand Down
10 changes: 7 additions & 3 deletions packages/cli-hooks/src/get-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import getHooks from './get-hooks.js';
describe('get-hooks implementation', async () => {
it('should return scripts for required hooks', async () => {
const { hooks } = getHooks();
assert(hooks.doctor === 'npx -q --no-install -p @slack/cli-hooks slack-cli-doctor');
assert(hooks['check-update'] === 'npx -q --no-install -p @slack/cli-hooks slack-cli-check-update');
assert(hooks['get-manifest'] === 'npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest');
assert(hooks.doctor === 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-doctor');
assert(
hooks['check-update'] === 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-check-update',
);
assert(
hooks['get-manifest'] === 'NODE_NO_WARNINGS=1 npx -q --no-install -p @slack/cli-hooks slack-cli-get-manifest',
);
assert(hooks.start === 'npx -q --no-install -p @slack/cli-hooks slack-cli-start');
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-hooks/src/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function DefaultProtocol(args) {
// If the particular hook invocation is requesting manifest generation we
// ensure any logging is a no-op to prevent littering stdout with logging
// and confusing the CLI's manifest JSON payload parsing.
const loggerMethod = manifestOnly ? () => { } : console.log;
Copy link
Member Author

Choose a reason for hiding this comment

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

Linter auto-pilot

const loggerMethod = manifestOnly ? () => {} : console.log;
return {
name: DEFAULT_PROTOCOL,
log: loggerMethod,
Expand Down