Skip to content

Commit

Permalink
Rewrite if else statements into for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhade3 committed Mar 28, 2022
1 parent 05f341e commit 562de04
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,36 @@ module.exports = function ({
'zlib'
]

if (semver.lt(version, '6.0.0')) coreModules.push('freelist')
if (semver.gte(version, '1.0.0')) coreModules.push('v8')
if (semver.gte(version, '1.1.0')) coreModules.push('process')
if (semver.gte(version, '8.0.0')) coreModules.push('inspector')
if (semver.gte(version, '8.1.0')) coreModules.push('async_hooks')
if (semver.gte(version, '8.4.0')) coreModules.push('http2')
if (semver.gte(version, '8.5.0')) coreModules.push('perf_hooks')
if (semver.gte(version, '10.0.0')) coreModules.push('trace_events')

if (
semver.gte(version, '10.5.0') &&
(experimental || semver.gte(version, '12.0.0'))
) {
coreModules.push('worker_threads')
var versionLockedModules = {
'freelist': '<6.0.0',
'v8': '>=1.0.0',
'process': '>=1.1.0',
'inspector': '>=8.0.0',
'async_hooks': '>=8.1.0',
'http2': '>=8.4.0',
'perf_hooks': '>=8.5.0',
'trace_events': '>=10.0.0',
'worker_threads': '>=12.0.0',
}
if (semver.gte(version, '12.16.0') && experimental) {
coreModules.push('wasi')

Object.entries(versionLockedModules).forEach(([name, v]) => {
if (semver.satisfies(version, v)) {
coreModules.push(name)
}
})

var experimentalModules = {
'worker_threads': '>=10.5.0',
'wasi': '>=12.16.0',
'diagnostics_channel': '^14.17.0 || >=15.1.0',
}

if (
experimental &&
(
semver.gte(version, '14.17.0') && semver.lt(version, '15.0.0') ||
semver.gte(version, '15.1.0')
)
) {
coreModules.push('diagnostics_channel')
if (experimental) {
Object.entries(experimentalModules).forEach(([name, v]) => {
if (!coreModules.includes(name) && semver.satisfies(version, v)) {
coreModules.push(name)
}
})
}

return coreModules
Expand Down

0 comments on commit 562de04

Please sign in to comment.