-
-
Notifications
You must be signed in to change notification settings - Fork 29
feat(timers deprecation): introduce #255
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
base: main
Are you sure you want to change the base?
Conversation
|
I need review on test cases so I can finish/clean the implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive codemod recipe to migrate deprecated Node.js timers APIs to modern timer functions. The codemod replaces timers.enroll(), timers.unenroll(), timers.active(), and timers._unrefActive() with standard setTimeout(), clearTimeout(), and Timer#unref() constructs, addressing Node.js deprecations DEP0095, DEP0096, DEP0126, and DEP0127.
Key changes include:
- New utility functions for GCD calculation and indent detection in the codemod-utils package
- Five transformation modules that handle different deprecated APIs
- Comprehensive test suite covering various import/require patterns
- Automated cleanup of unused imports after transformations
Reviewed Changes
Copilot reviewed 45 out of 46 changed files in this pull request and generated 107 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/src/math.ts | Implements GCD function to calculate indentation units |
| utils/src/math.test.ts | Tests for GCD function including edge cases |
| utils/src/ast-grep/indent.ts | Detects indentation style and retrieves line indentation |
| utils/src/ast-grep/indent.test.ts | Tests for indentation detection utilities |
| utils/src/ast-grep/general.ts | Helper functions for AST manipulation |
| utils/src/ast-grep/general.test.ts | Tests for AST manipulation helpers |
| recipes/timers-deprecations/src/*.ts | Five transformation modules for each deprecated API |
| recipes/timers-deprecations/tests/** | Comprehensive test cases for all transformations |
| recipes/timers-deprecations/workflow.yaml | Workflow configuration for codemod execution |
| recipes/timers-deprecations/package.json | Package configuration and test scripts |
| recipes/timers-deprecations/codemod.yaml | Codemod metadata and registry configuration |
| recipes/timers-deprecations/README.md | Documentation with examples and caveats |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
recipes/timers-deprecations/tests/active/expected/active_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/active/expected/active_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/active/expected/active_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/unref/expected/unref_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/unref/expected/unref_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/unref/expected/unref_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/unref/expected/unref_import-variants.js
Show resolved
Hide resolved
recipes/timers-deprecations/tests/unref/expected/unref_import-variants.js
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this and sorry it's taken me a quite a while to get to it. It's been a helluva month :(
| **Before:** | ||
|
|
||
| ```js | ||
| const timers = require('node:timers'); | ||
| const resource = { _idleTimeout: 1500 }; | ||
| timers.enroll(resource, 1500); | ||
| ``` | ||
|
|
||
| **After:** | ||
|
|
||
| ```js | ||
| const resource = { timeout: setTimeout(() => { | ||
| // timeout handler | ||
| }, 1500) }; | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the content for timeout handler come from?
| **Before:** | |
| ```js | |
| const timers = require('node:timers'); | |
| const resource = { _idleTimeout: 1500 }; | |
| timers.enroll(resource, 1500); | |
| ``` | |
| **After:** | |
| ```js | |
| const resource = { timeout: setTimeout(() => { | |
| // timeout handler | |
| }, 1500) }; | |
| ``` | |
| ```diff | |
| - const timers = require('node:timers'); | |
| - const resource = { _idleTimeout: 1500 }; | |
| + const resource = { timeout: setTimeout(() => { | |
| + // timeout handler | |
| + }, 1500) }; | |
| - timers.enroll(resource, 1500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the content for timeout handler come from?
my brain 😅
| **Before:** | ||
|
|
||
| ```js | ||
| timers.unenroll(resource); | ||
| ``` | ||
|
|
||
| **After:** | ||
|
|
||
| ```js | ||
| clearTimeout(resource.timeout); | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| **Before:** | |
| ```js | |
| timers.unenroll(resource); | |
| ``` | |
| **After:** | |
| ```js | |
| clearTimeout(resource.timeout); | |
| ``` | |
| ```diff | |
| - timers.unenroll(resource); | |
| + clearTimeout(resource.timeout); |
| **Before:** | ||
|
|
||
| ```js | ||
| const timers = require('node:timers'); | ||
| timers.active(resource); | ||
| timers._unrefActive(resource); | ||
| ``` | ||
|
|
||
| **After:** | ||
|
|
||
| ```js | ||
| const handle = setTimeout(onTimeout, delay); | ||
| handle.unref(); | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do onTimeout and delay come from? they aren't in the original or new code
| **Before:** | |
| ```js | |
| const timers = require('node:timers'); | |
| timers.active(resource); | |
| timers._unrefActive(resource); | |
| ``` | |
| **After:** | |
| ```js | |
| const handle = setTimeout(onTimeout, delay); | |
| handle.unref(); | |
| ``` | |
| ```diff | |
| - const timers = require('node:timers'); | |
| - timers.active(resource); | |
| - timers._unrefActive(resource); | |
| + const handle = setTimeout(onTimeout, delay); | |
| + handle.unref(); |
|
@AugustinMauroy I tried to review the rest of this, but the browser tab crashes trying to load it (it's big, but I didn't think it was that big). Would it be possible to break this into smaller pieces? |
TODO