MCPcopy Create free account
hub / github.com/vercel/vercel / getRubyPath

Function getRubyPath

packages/ruby/src/install-ruby.ts:109–223  ·  view source on GitHub ↗
(meta: Meta, gemfileContents: string)

Source from the content-addressed store, hash-verified

107}
108
109function 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 }

Callers 1

installBundlerFunction · 0.85

Calls 8

debugFunction · 0.90
getLatestRubyVersionFunction · 0.85
resolveSystemRubyFunction · 0.85
makeLocalRubyEnvFunction · 0.85
splitMethod · 0.80
replaceMethod · 0.80
isInstalledFunction · 0.70
findMethod · 0.45

Tested by

no test coverage detected