-
Notifications
You must be signed in to change notification settings - Fork 25
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
node:test
is not detected as <BUILTIN_MODULES>
#142
Comments
Digging into how Following this open node issue, it seems like the node maintainers can not (or will not?) add Suggestion My suggestion to fix would be to explicitly add a check for Though I think I've debugged the issue, I'm not much of a RegEx wizard so am not sure how best to fix the issue |
Thanks for digging into this. I'm a bit reluctant to hack around an open issue in node (I don't see anything in the issue indicating that it shouldn't be fixed, at least). But if this is important to you and you're willing to give it a shot, I'll be happy to review a PR, so long as it doesn't add a ton of complexity and ideally is something we can revert in the future if/when node fixes the issue on their end. In this case I think it's not too bad. The regex we're creating is something like: `^(?:node:)?(?:node:fs|node:path)$` After the module names are joined together. So, after the join, you'd need to add export const BUILTIN_MODULES_REGEX_STR = `^(?:node:)?(?:${builtinModules.join(
'|',
)}${|node:test})$`; If you try that (and maybe a comment as to why we need it), and add a test, and it works, I'd be happy to merge and release a new patch version. Thanks again! |
Cool, sounds good. Will try and get around to putting together a PR then. Thanks! 🙏🏾 |
Minor tweak, Instead of manually adding the import { builtinModules } from 'module';
// Patched to add node:test due to https://github.com/nodejs/node/issues/42785
const patchedBuiltIns = […builtinModules, “test”]; |
@fbartho My only issue with that approach is that the regex would then also match against I just opened a PR to address it with a slight regex change. From my testing this seems to be backwards compatible (its basically "the original regex" OR |
Nice catch @IsaiahByDayah — I didn’t realize No objections. |
Following discussion in #142 , this adds an explicit check for `"node:test"` to `BUILTIN_MODULES_REGEX_STR` in order to properly group it with other builtin modules. Test covers: - `"node:test"` correctly gets grouped in with other builtin node modules - `"node:test"` is correctly sorted among other builtin node modules - `"*node:test"` is NOT grouped in with builtin modules - `"node:test*"` is NOT grouped in with builtin modules - `"node"` is NOT grouped in with builtin modules - `"test"` is NOT grouped in with builtin modules Fixes #142
Your Environment
Describe the bug
Imports from
node:test
are not properly grouped with other builtin modulesTo Reproduce
Try to import from
node:test
and notice that it is not included with othernode:*
importsExpected behavior
imports from
node:test
would be grouped with the other builtin modulesScreenshots, code sample, etc
Screen.Recording.2024-01-29.at.11.35.45.PM.mov
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Error log
N/A
Contribute to @ianvs/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: