fix: fallback when console.createTask returns undefined#147
Conversation
Some runtimes expose console.createTask but return undefined from it, which caused parallel and serial hook callers to crash on task.run. Fixes unjs#114
📝 WalkthroughWalkthroughThe PR adds a nullish safeguard to the ChangesNullish fallback for console.createTask
🎯 2 (Simple) | ⏱️ ~8 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils.ts (1)
66-67: ⚡ Quick winMove internal helper to file end to match repo convention.
defaultTaskis an internal helper and should be placed at the end of the file per project rule.As per coding guidelines, "Place internal helpers at end of file".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils.ts` around lines 66 - 67, The helper constant defaultTask (typed as ReturnType<CreateTask>) is an internal helper and must be moved to the end of the file to follow the project convention; relocate the declaration of defaultTask to the bottom of src/utils.ts (after all exported functions/classes) and ensure any references to CreateTask or defaultTask still resolve (no change to its name or type) so imports/exports remain unaffected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils.ts`:
- Around line 66-67: The helper constant defaultTask (typed as
ReturnType<CreateTask>) is an internal helper and must be moved to the end of
the file to follow the project convention; relocate the declaration of
defaultTask to the bottom of src/utils.ts (after all exported functions/classes)
and ensure any references to CreateTask or defaultTask still resolve (no change
to its name or type) so imports/exports remain unaffected.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 29850c77-a487-41e1-a8dc-a4512b27130c
📒 Files selected for processing (2)
src/utils.tstest/hookable.test.ts
Summary
console.createTaskso a missing/undefined task falls back to a no-op runnerCannot read properties of undefined (reading 'run')in serial and parallel hook callersExample
Fixes #114
Test plan
console.createTaskreturn valuepnpm exec vitest run— 44 passingpnpm lint— cleanSummary by CodeRabbit
Bug Fixes
Tests