(meta: Meta, gemfileContents: string)
| 107 | } |
| 108 | |
| 109 | function getRubyPath(meta: Meta, gemfileContents: string) { |
| 110 | let selection: RubyVersion | null = null; |
| 111 | try { |
| 112 | selection = getLatestRubyVersion(); |
| 113 | } catch { |
| 114 | selection = null; |
| 115 | } |
| 116 | if (meta.isDev) { |
| 117 | const sys = resolveSystemRuby(); |
| 118 | if (sys) { |
| 119 | const result = makeLocalRubyEnv(sys); |
| 120 | debug( |
| 121 | `ruby: using system ruby for local dev: ${JSON.stringify({ ruby: sys.rubyPath, gem: sys.gemPath, version: `${sys.major}.${sys.minor}` })}` |
| 122 | ); |
| 123 | return result; |
| 124 | } |
| 125 | throw new NowBuildError({ |
| 126 | code: 'RUBY_INVALID_VERSION', |
| 127 | link: 'http://vercel.link/ruby-version', |
| 128 | message: |
| 129 | 'Unable to find any supported Ruby versions (local). Ensure ruby and gem are on PATH.', |
| 130 | }); |
| 131 | } else if (gemfileContents) { |
| 132 | const line = gemfileContents |
| 133 | .split('\n') |
| 134 | .find(line => line.startsWith('ruby')); |
| 135 | if (line) { |
| 136 | const strVersion = line.slice(4).trim().slice(1, -1).replace(/~>\s*/, ''); |
| 137 | const found = allOptions.some(o => { |
| 138 | // The array is already in order so return the first |
| 139 | // match which will be the newest version. |
| 140 | selection = o; |
| 141 | return intersects(o.range, strVersion); |
| 142 | }); |
| 143 | if (!found) { |
| 144 | throw new NowBuildError({ |
| 145 | code: 'RUBY_INVALID_VERSION', |
| 146 | message: `Found \`Gemfile\` with invalid Ruby version: \`${line}.\``, |
| 147 | link: 'http://vercel.link/ruby-version', |
| 148 | }); |
| 149 | } |
| 150 | |
| 151 | if ( |
| 152 | !selection || |
| 153 | selection.state === 'discontinued' || |
| 154 | !isInstalled(selection) |
| 155 | ) { |
| 156 | const sys = resolveSystemRuby(); |
| 157 | if (sys) { |
| 158 | const sysRange = `${sys.major}.${sys.minor}.x`; |
| 159 | if (!strVersion || intersects(sysRange, strVersion)) { |
| 160 | const result = makeLocalRubyEnv(sys); |
| 161 | debug( |
| 162 | `ruby: using system ruby (Gemfile) version=${sys.major}.${sys.minor} ruby=${sys.rubyPath}` |
| 163 | ); |
| 164 | return result; |
| 165 | } |
| 166 | } |
no test coverage detected