You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implements the feature requested in #71 to add support for sorting Node.js builtin modules using the <BUILTIN_MODULES> placeholder in the importOrder array.
This PR introduces support for the <BUILTIN_MODULES> special word that allows users to explicitly control where Node.js builtin modules (both traditional fs, path etc. and new node:fs, node:path prefixed variants) appear in their import order.
Changes
Special Word Support: Added <BUILTIN_MODULES> placeholder for use in importOrder array
Builtin Detection: Created utility function to detect Node.js builtin modules using module.builtinModules
Support for both formats: Handles both traditional (fs) and modern (node:fs) import styles
Flexible Positioning: Users have full control over where builtin modules appear in their import order
Implementation Details
Detection Logic: Uses require('module').builtinModules to identify all Node.js builtin modules
Format Support: Recognizes both fs and node:fs import formats
Opt-in Behavior: Builtin modules are only sorted separately when <BUILTIN_MODULES> is included in importOrder
Flexible Placement: Can be positioned anywhere in the import order for maximum flexibility
Hello @sdotson! I really like this feature, I think it might be useful. I'm wondering, is it possible to keep only <BUILTIN_MODULES>, without special option importOrderBuiltinModulesToTop in config? If someone wants to see them on top, they just would write config like
importOrder: ['<BUILTIN_MODULES>', ....]
otherwise they wouldn't mention it in importOrder at all and plugin wouldn't group plugins by this trait.
sdotson
changed the title
Add importOrderBuiltinModulesToTop option for Node.js builtin modules
Add <BUILTIN_MODULES> option for Node.js builtin modules
Oct 17, 2025
Hello @sdotson! I really like this feature, I think it might be useful. I'm wondering, is it possible to keep only <BUILTIN_MODULES>, without special option importOrderBuiltinModulesToTop in config? If someone wants to see them on top, they just would write config like
importOrder: ['<BUILTIN_MODULES>', ....]
otherwise they wouldn't mention it in importOrder at all and plugin wouldn't group plugins by this trait.
Had a few hiccups with the v6 branch but I think everything is good now @vladislavarsenev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements the feature requested in #71 to add support for sorting Node.js builtin modules using the
<BUILTIN_MODULES>placeholder in theimportOrderarray.This PR introduces support for the
<BUILTIN_MODULES>special word that allows users to explicitly control where Node.js builtin modules (both traditionalfs,pathetc. and newnode:fs,node:pathprefixed variants) appear in their import order.Changes
<BUILTIN_MODULES>placeholder for use inimportOrderarraymodule.builtinModulesfs) and modern (node:fs) import stylesImplementation Details
require('module').builtinModulesto identify all Node.js builtin modulesfsandnode:fsimport formats<BUILTIN_MODULES>is included inimportOrderExample Usage
Builtin modules at the top:
{ "importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "^@core/(.*)$", "^[./]"], "importOrderSeparation": true, "importOrderSortSpecifiers": true }Builtin modules after third-party:
{ "importOrder": ["<THIRD_PARTY_MODULES>", "<BUILTIN_MODULES>", "^@core/(.*)$", "^[./]"] }Before:
After (with builtin modules at top):
Testing
node:prefixed importsBackward Compatibility
This change is fully backward compatible:
<BUILTIN_MODULES>inimportOrder, builtin modules are treated as regular third-party importsDocumentation
.jsextensions for ESM compatibility (v6)Fixes #71
Checklist