From 6bae3b129157fd002aa191c42f1827f17bbdc429 Mon Sep 17 00:00:00 2001 From: Enric Morales Date: Wed, 10 Jul 2024 11:00:00 +0200 Subject: [PATCH] utils: Use shelljs.which to get the path for an executable --- app/package-lock.json | 173 ++++++++++++++++++++++++++++++++++ app/package.json | 1 + app/scripts/factories/node.js | 3 + app/scripts/services/utils.js | 20 ++-- 4 files changed, 184 insertions(+), 13 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index b6cd32d13..987a43827 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -42,6 +42,7 @@ "rsyncwrapper": "~2.0.1", "select2": "~4.1.0-rc.0", "sha1": "~1.1.1", + "shelljs": "^0.8.5", "snapsvg": "~0.5.1", "spark-md5": "^3.0.1", "ssh-exec": "~2.0.0", @@ -559,6 +560,15 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/getos": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/getos/-/getos-3.0.1.tgz", @@ -620,6 +630,18 @@ "node": ">=0.10.0" } }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/htmlparser2": { "version": "3.8.3", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", @@ -671,6 +693,15 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/is": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/is/-/is-0.2.7.tgz", @@ -679,6 +710,21 @@ "node": "*" } }, + "node_modules/is-core-module": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", + "license": "MIT", + "dependencies": { + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -927,6 +973,12 @@ "node": ">=0.10.0" } }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "license": "MIT" + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -962,6 +1014,34 @@ "string_decoder": "~0.10.x" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/resolve": { + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "license": "MIT", + "dependencies": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/rmdir": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/rmdir/-/rmdir-1.2.0.tgz", @@ -1021,6 +1101,23 @@ "node": "*" } }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "license": "BSD-3-Clause", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/snapsvg": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/snapsvg/-/snapsvg-0.5.1.tgz", @@ -1151,6 +1248,18 @@ "node": ">=0.8.0" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/svg-pan-zoom": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/svg-pan-zoom/-/svg-pan-zoom-3.4.1.tgz", @@ -1708,6 +1817,11 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" + }, "getos": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/getos/-/getos-3.0.1.tgz", @@ -1767,6 +1881,14 @@ "ansi-regex": "^2.0.0" } }, + "hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "requires": { + "function-bind": "^1.1.2" + } + }, "htmlparser2": { "version": "3.8.3", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", @@ -1817,11 +1939,24 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, "is": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/is/-/is-0.2.7.tgz", "integrity": "sha1-OzSixI81mXLzUEKEkZOucmS2NWI=" }, + "is-core-module": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", + "requires": { + "hasown": "^2.0.2" + } + }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -2035,6 +2170,11 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -2066,6 +2206,24 @@ "string_decoder": "~0.10.x" } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "requires": { + "resolve": "^1.1.6" + } + }, + "resolve": { + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "requires": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, "rmdir": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/rmdir/-/rmdir-1.2.0.tgz", @@ -2118,6 +2276,16 @@ "crypt": ">= 0.0.1" } }, + "shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "snapsvg": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/snapsvg/-/snapsvg-0.5.1.tgz", @@ -2234,6 +2402,11 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" + }, "svg-pan-zoom": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/svg-pan-zoom/-/svg-pan-zoom-3.4.1.tgz", diff --git a/app/package.json b/app/package.json index a2c49f5da..f85045ae3 100644 --- a/app/package.json +++ b/app/package.json @@ -79,6 +79,7 @@ "rsyncwrapper": "~2.0.1", "select2": "~4.1.0-rc.0", "sha1": "~1.1.1", + "shelljs": "^0.8.5", "snapsvg": "~0.5.1", "spark-md5": "^3.0.1", "ssh-exec": "~2.0.0", diff --git a/app/scripts/factories/node.js b/app/scripts/factories/node.js index b6ef8c6ed..66147cf67 100644 --- a/app/scripts/factories/node.js +++ b/app/scripts/factories/node.js @@ -77,6 +77,9 @@ angular.module('icestudio') .factory('nodeDebounce', function() { return require('lodash.debounce'); }) + .factory('shelljs', function() { + return require('shelljs'); + }) .factory('SVGO', function() { var config = { full: true, diff --git a/app/scripts/services/utils.js b/app/scripts/services/utils.js index d937ac77e..2bc44d27b 100644 --- a/app/scripts/services/utils.js +++ b/app/scripts/services/utils.js @@ -19,6 +19,7 @@ angular.module('icestudio') nodeLangInfo, SVGO, fastCopy, + shelljs, sparkMD5) { let _pythonExecutableCached = null; @@ -112,24 +113,17 @@ angular.module('icestudio') } //--------------------------------------------------------- - //-- Get the path of an executable using the `which` utility + //-- Get the path of an executable using the `which` shelljs module //-- //-- INPUTS: //-- -executable: string for an executable //-- OUTPUTS: //-- string: the path to the executable - //-- null: `which` is unavailable or execution error + //-- null: executable not found function getExecutablePath(executable) { - const command = `which ${executable}`; - try { - const result = nodeChildProcess.execSync(command); - if (result !== false && result !== null) { - return result.toString(); - } - } catch (e) { - console.error(e); - } - return null; + // split executable at first space to account for e.g. `python.exe -3` + executable = executable.split(" ")[0] + return shelljs.which(executable) } @@ -1683,4 +1677,4 @@ angular.module('icestudio') }, 50); }; - }); \ No newline at end of file + });