Commit ee44634
authored
[build-utils] Optimize getAvailableNodeVersions to skip discontinued versions (#14686)
## Summary
- Optimize `isNodeVersionAvailable` to use `statSync` with `{
throwIfNoEntry: false }` instead of try-catch pattern for better
efficiency
- Skip old Node versions (< 18) in `getAvailableNodeVersions` to avoid
unnecessary filesystem checks for versions that don't exist in the build
container
- Update error message to mention "discontinued" versions for better
user guidance
## Changes
1. **Non-throwing `statSync`**: Replace try-catch block with
`statSync(path, { throwIfNoEntry: false })` which returns `undefined`
instead of throwing when the path doesn't exist
2. **Filter old versions**: Add a filter to skip Node versions < 18
(e.g., Node 8, 10, 12, 14, 16) before checking filesystem availability,
as these versions don't have directories in the build container. This
reduces unnecessary `statSync` calls while preserving behavior for Node
18+ which still have directories available.
3. **Improved error message**: Change error from `"Found invalid Node.js
Version"` to `"Found invalid or discontinued Node.js Version"` to give
users a hint that their requested version may have been discontinued1 parent 583c052 commit ee44634
3 files changed
Lines changed: 16 additions & 11 deletions
File tree
- .changeset
- packages/build-utils
- src/fs
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 82 | + | |
| 83 | + | |
88 | 84 | | |
89 | 85 | | |
90 | 86 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
0 commit comments