From ac03cb7d18ed0b67859fd440399a039df4839344 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 25 Sep 2021 13:45:43 +0200 Subject: [PATCH] Use .test() instead of .match() where possible --- bundler.js | 4 ++-- dist/index.js | 10 +++++----- index.js | 4 ++-- windows.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bundler.js b/bundler.js index 3d76046..c79d192 100644 --- a/bundler.js +++ b/bundler.js @@ -74,7 +74,7 @@ export async function installBundler(bundlerVersionInput, lockFile, platform, ru if (engine === 'ruby' && common.floatVersion(rubyVersion) <= 2.2) { console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2') bundlerVersion = '1' - } else if (engine === 'ruby' && rubyVersion.match(/^2\.3\.[01]/)) { + } else if (engine === 'ruby' && /^2\.3\.[01]/.test(rubyVersion)) { console.log('Ruby 2.3.0 and 2.3.1 have shipped with an old rubygems that only works with Bundler 1') bundlerVersion = '1' } else if (engine === 'jruby' && rubyVersion.startsWith('9.1')) { // JRuby 9.1 targets Ruby 2.3, treat it the same @@ -90,7 +90,7 @@ export async function installBundler(bundlerVersionInput, lockFile, platform, ru console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`) } else { const gem = path.join(rubyPrefix, 'bin', 'gem') - const bundlerVersionConstraint = bundlerVersion.match(/^\d+\.\d+\.\d+/) ? bundlerVersion : `~> ${bundlerVersion}` + const bundlerVersionConstraint = /^\d+\.\d+\.\d+/.test(bundlerVersion) ? bundlerVersion : `~> ${bundlerVersion}` await exec.exec(gem, ['install', 'bundler', '-v', bundlerVersionConstraint]) } diff --git a/dist/index.js b/dist/index.js index 3e9dee3..417db9b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -88,7 +88,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi if (engine === 'ruby' && common.floatVersion(rubyVersion) <= 2.2) { console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2') bundlerVersion = '1' - } else if (engine === 'ruby' && rubyVersion.match(/^2\.3\.[01]/)) { + } else if (engine === 'ruby' && /^2\.3\.[01]/.test(rubyVersion)) { console.log('Ruby 2.3.0 and 2.3.1 have shipped with an old rubygems that only works with Bundler 1') bundlerVersion = '1' } else if (engine === 'jruby' && rubyVersion.startsWith('9.1')) { // JRuby 9.1 targets Ruby 2.3, treat it the same @@ -104,7 +104,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`) } else { const gem = path.join(rubyPrefix, 'bin', 'gem') - const bundlerVersionConstraint = bundlerVersion.match(/^\d+\.\d+\.\d+/) ? bundlerVersion : `~> ${bundlerVersion}` + const bundlerVersionConstraint = /^\d+\.\d+\.\d+/.test(bundlerVersion) ? bundlerVersion : `~> ${bundlerVersion}` await exec.exec(gem, ['install', 'bundler', '-v', bundlerVersionConstraint]) } @@ -59127,7 +59127,7 @@ function addVCVARSEnv() { let newEnv = new Map() let cmd = `cmd.exe /c "${vcVars} && set"` let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/) - newSet = newSet.filter(line => line.match(/\S=\S/)) + newSet = newSet.filter(line => /\S=\S/.test(line)) newSet.forEach(s => { let [k,v] = common.partition(s, '=') newEnv.set(k,v) @@ -59500,13 +59500,13 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .ruby-version`) } else if (rubyVersion === '.tool-versions') { // Read from .tool-versions const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => e.match(/^ruby\s/))[0] + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) } let engine, version - if (rubyVersion.match(/^(\d+)/) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z + if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion diff --git a/index.js b/index.js index a66e0fc..7a1b0c8 100644 --- a/index.js +++ b/index.js @@ -91,13 +91,13 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .ruby-version`) } else if (rubyVersion === '.tool-versions') { // Read from .tool-versions const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => e.match(/^ruby\s/))[0] + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) } let engine, version - if (rubyVersion.match(/^(\d+)/) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z + if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion diff --git a/windows.js b/windows.js index 050777c..b987dc4 100644 --- a/windows.js +++ b/windows.js @@ -134,7 +134,7 @@ export function addVCVARSEnv() { let newEnv = new Map() let cmd = `cmd.exe /c "${vcVars} && set"` let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/) - newSet = newSet.filter(line => line.match(/\S=\S/)) + newSet = newSet.filter(line => /\S=\S/.test(line)) newSet.forEach(s => { let [k,v] = common.partition(s, '=') newEnv.set(k,v)