Skip to content

Commit

Permalink
Improved Ruby version detection
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Jan 17, 2025
1 parent 168487b commit 02bcb5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ atom -o app.atom -l java --export-atom --export-dir <export dir> --with-data-dep
- TypeScript
- Python
- PHP (Requires PHP >= 7.0. Supports PHP 5.2 to 8.3)
- Ruby (Requires Ruby >= 3.1.4. Supports Ruby 1.8 - 3.3 syntax)
- Ruby (Requires Ruby 3.4.1. Supports Ruby 1.8 - 3.3 syntax)

## Atom Specification

Expand Down
5 changes: 3 additions & 2 deletions wrapper/nodejs/rbastgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const dirName = import.meta ? dirname(fileURLToPath(url)) : __dirname;
export const PLUGINS_HOME = join(dirName, "plugins");
const RUBY_ASTGEN_BIN =
process.env.RUBY_ASTGEN_BIN || join(PLUGINS_HOME, "bin", "ruby_ast_gen");

// Ruby version needed
const RUBY_VERSION_NEEDED = "3.4.1";
function main(argvs) {
const cwd = process.env.ATOM_CWD || process.cwd();
argvs.splice(
Expand All @@ -38,7 +39,7 @@ function main(argvs) {
env.PATH = `${rubyBinDir}${delimiter}${env.PATH}`;
}
}
if (!detectRuby()) {
if (!detectRuby(RUBY_VERSION_NEEDED)) {
console.warn("Ruby is not installed!");
return false;
}
Expand Down
8 changes: 7 additions & 1 deletion wrapper/nodejs/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ export const detectPhp = () => {
return true;
};

export const detectRuby = () => {
export const detectRuby = (versionNeeded) => {
let result = spawnSync(process.env.RUBY_CMD || "ruby", ["--version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
const stdout = result.stdout;
if (versionNeeded && stdout) {
const cmdOutput = Buffer.from(stdout).toString();
const versionStr = cmdOutput.trim().replaceAll("\r", "");
return versionStr.startsWith(`ruby ${versionNeeded} `);
}
return true;
};

0 comments on commit 02bcb5d

Please sign in to comment.