From f91746eb5362f28321bca1bbe9e65a7967a2a1b2 Mon Sep 17 00:00:00 2001 From: Zvi Grinberg Date: Wed, 10 Jul 2024 13:21:55 +0300 Subject: [PATCH 1/4] fix: bug of windows os for python and npm ecosystems Signed-off-by: Zvi Grinberg --- src/providers/javascript_npm.js | 2 +- src/providers/python_controller.js | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/providers/javascript_npm.js b/src/providers/javascript_npm.js index a46f154..cd4b9fe 100644 --- a/src/providers/javascript_npm.js +++ b/src/providers/javascript_npm.js @@ -109,7 +109,7 @@ function provideComponent(data, opts = {}, path = '') { * @return {string} returns a string containing the result output. */ function getNpmListing(npm, allFilter, manifestDir) { - return `${handleSpacesInPath(npm)} ls${allFilter} --omit=dev --package-lock-only --json --prefix ${manifestDir}`; + return `${handleSpacesInPath(npm)} ls${allFilter} --omit=dev --package-lock-only --json --prefix ${handleSpacesInPath(manifestDir)}`; } diff --git a/src/providers/python_controller.js b/src/providers/python_controller.js index 2981a25..113abd4 100644 --- a/src/providers/python_controller.js +++ b/src/providers/python_controller.js @@ -1,7 +1,7 @@ import {execSync} from "node:child_process"; import fs from "node:fs"; import path from 'node:path'; -import {EOL} from "os"; +import os, {EOL} from "os"; import {environmentVariableIsPopulated,getCustom, handleSpacesInPath} from "../tools.js"; @@ -55,19 +55,19 @@ export default class Python_controller { { if(!this.realEnvironment) { this.pythonEnvDir = path.join(path.sep,"tmp","exhort_env_js") - execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m venv ${this.pythonEnvDir} `, err => { + execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m venv ${handleSpacesInPath(this.pythonEnvDir)} `, err => { if (err) { throw new Error('failed creating virtual python environment - ' + err.message) } }) if(this.pathToPythonBin.includes("python3")) { - this.pathToPipBin = path.join(this.pythonEnvDir,"bin","pip3"); - this.pathToPythonBin = path.join(this.pythonEnvDir,"bin","python3") + this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("pip3")) + this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("python3")) } else { - this.pathToPipBin = path.join(this.pythonEnvDir,"bin","pip"); - this.pathToPythonBin = path.join(this.pythonEnvDir,"bin","python") + this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("pip")); + this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("python")) } // upgrade pip version to latest execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m pip install --upgrade pip `, err => { @@ -87,6 +87,14 @@ export default class Python_controller { } } + #decideIfWindowsOrLinuxPath(fileName) { + if (os.platform() === "win32") { + return fileName + ".exe" + } + else { + return fileName + } + } /** * * @param {boolean} includeTransitive - whether to return include in returned object transitive dependencies or not From ab74fc3eab40c7674edd3fe910a39b813bdb8080 Mon Sep 17 00:00:00 2001 From: Zvi Grinberg Date: Wed, 10 Jul 2024 14:50:06 +0300 Subject: [PATCH 2/4] fix: adjust windows paths correctly for python and pip in venv after testing in windows 10 Signed-off-by: Zvi Grinberg --- src/providers/python_controller.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/providers/python_controller.js b/src/providers/python_controller.js index 113abd4..51cf659 100644 --- a/src/providers/python_controller.js +++ b/src/providers/python_controller.js @@ -62,12 +62,22 @@ export default class Python_controller { }) if(this.pathToPythonBin.includes("python3")) { - this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("pip3")) - this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("python3")) + this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip3")) + this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python3")) + if(os.platform() === 'win32') { + let driveLetter = path.parse(process.cwd()).root + this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` + this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` + } } else { - this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("pip")); - this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,"bin",this.#decideIfWindowsOrLinuxPath("python")) + this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip")); + this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python")) + if(os.platform() === 'win32') { + let driveLetter = path.parse(process.cwd()).root + this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` + this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` + } } // upgrade pip version to latest execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m pip install --upgrade pip `, err => { From d9007605921fc96a13ca37aecd8c7d85471d2da5 Mon Sep 17 00:00:00 2001 From: Zvi Grinberg Date: Wed, 10 Jul 2024 16:09:07 +0300 Subject: [PATCH 3/4] fix: npm commands for building dependency tree not working in windows os" Signed-off-by: Zvi Grinberg --- src/providers/javascript_npm.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/providers/javascript_npm.js b/src/providers/javascript_npm.js index cd4b9fe..46a4081 100644 --- a/src/providers/javascript_npm.js +++ b/src/providers/javascript_npm.js @@ -23,11 +23,20 @@ export var npmInteractions = { }) }, createPackageLock: function createPackageLock(npm, manifestDir) { + // in windows os, --prefix flag doesn't work, it behaves really weird , instead of installing the package.json fromm the prefix folder, + // it's installing package.json (placed in current working directory of process) into prefix directory, so + let originalDir = process.cwd() + if(os.platform() === 'win32') { + process.chdir(manifestDir) + } execSync(`${handleSpacesInPath(npm)} i --package-lock-only --prefix ${handleSpacesInPath(manifestDir)}`, err => { if (err) { throw new Error('failed to create npmOutput list') } }) + if(os.platform() === 'win32') { + process.chdir(originalDir) + } } } export default { isSupported, provideComponent, provideStack, npmInteractions } @@ -109,7 +118,7 @@ function provideComponent(data, opts = {}, path = '') { * @return {string} returns a string containing the result output. */ function getNpmListing(npm, allFilter, manifestDir) { - return `${handleSpacesInPath(npm)} ls${allFilter} --omit=dev --package-lock-only --json --prefix ${handleSpacesInPath(manifestDir)}`; + return `${handleSpacesInPath(npm)} ls${allFilter} --omit=dev --package-lock-only --json --prefix ${manifestDir}`; } From 3861ed20850fc3678152e40c7ece20bb8bfc8e7b Mon Sep 17 00:00:00 2001 From: Zvi Grinberg Date: Wed, 10 Jul 2024 16:15:59 +0300 Subject: [PATCH 4/4] fix: linting errors Signed-off-by: Zvi Grinberg --- src/providers/javascript_npm.js | 14 +++++++------- src/providers/python_controller.js | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/providers/javascript_npm.js b/src/providers/javascript_npm.js index 46a4081..982e894 100644 --- a/src/providers/javascript_npm.js +++ b/src/providers/javascript_npm.js @@ -25,18 +25,18 @@ export var npmInteractions = { createPackageLock: function createPackageLock(npm, manifestDir) { // in windows os, --prefix flag doesn't work, it behaves really weird , instead of installing the package.json fromm the prefix folder, // it's installing package.json (placed in current working directory of process) into prefix directory, so - let originalDir = process.cwd() - if(os.platform() === 'win32') { - process.chdir(manifestDir) - } + let originalDir = process.cwd() + if(os.platform() === 'win32') { + process.chdir(manifestDir) + } execSync(`${handleSpacesInPath(npm)} i --package-lock-only --prefix ${handleSpacesInPath(manifestDir)}`, err => { if (err) { throw new Error('failed to create npmOutput list') } }) - if(os.platform() === 'win32') { - process.chdir(originalDir) - } + if(os.platform() === 'win32') { + process.chdir(originalDir) + } } } export default { isSupported, provideComponent, provideStack, npmInteractions } diff --git a/src/providers/python_controller.js b/src/providers/python_controller.js index 51cf659..6ca1136 100644 --- a/src/providers/python_controller.js +++ b/src/providers/python_controller.js @@ -65,18 +65,18 @@ export default class Python_controller { this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip3")) this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python3")) if(os.platform() === 'win32') { - let driveLetter = path.parse(process.cwd()).root - this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` - this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` + let driveLetter = path.parse(process.cwd()).root + this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` + this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` } } else { this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip")); this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python")) if(os.platform() === 'win32') { - let driveLetter = path.parse(process.cwd()).root - this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` - this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` + let driveLetter = path.parse(process.cwd()).root + this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}` + this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}` } } // upgrade pip version to latest