New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-shell-vars

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-shell-vars - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0

43

lib/index.js

@@ -7,3 +7,4 @@ "use strict";

_ = require("lodash"),
processWrapper = require("./process-wrapper");
processWrapper = require("./process-wrapper"),
temp = require("temp");

@@ -31,14 +32,16 @@ const addEtcPathToPath = (environmentVariables) => {

/**
* Gets all environment variables that the user has in the default terminal.
* @returns {object} Dictionary with key-value pairs of all environment variables.
*/
const getEnvironmentVariables = () => {
if (processWrapper.getProcessPlatform() === "win32") {
return process.env;
const getEnvironmentVariablesFromNodeProcess = (pathToShell) => {
try {
temp.track();
const pathToTempFile = temp.path("get-shell-vars-process-env");
const bashCommandSpawningNode = `${pathToShell} -ilc "node -e 'require(\\"fs\\").writeFileSync(\\"${pathToTempFile}\\", JSON.stringify(process.env))'"`;
childProcess.execSync(bashCommandSpawningNode);
const env = JSON.parse(fs.readFileSync(pathToTempFile));
return env;
} catch (err) {
console.log("Unable to get environment variables from node, will try another approach.");
}
};
const shell = process.env && process.env.SHELL && path.basename(process.env.SHELL) || "bash",
pathToShell = process.env && process.env.SHELL || "/bin/bash";
const getEnvironmentVariablesFromEnvCommand = (pathToShell) => {
try {

@@ -73,3 +76,3 @@ let sourcedEnvironmentVars = childProcess.execSync(`${pathToShell} -ilc env`);

return addEtcPathToPath(environmentVariables);
return environmentVariables;
}

@@ -79,4 +82,18 @@ } catch (err) {

}
}
return addEtcPathToPath(process.env);
/**
* Gets all environment variables that the user has in the default terminal.
* @returns {object} Dictionary with key-value pairs of all environment variables.
*/
const getEnvironmentVariables = () => {
if (processWrapper.getProcessPlatform() === "win32") {
return process.env;
}
const shell = process.env && process.env.SHELL && path.basename(process.env.SHELL) || "bash",
pathToShell = process.env && process.env.SHELL || "/bin/bash";
const environmentVariables = getEnvironmentVariablesFromNodeProcess(pathToShell) || getEnvironmentVariablesFromEnvCommand(pathToShell) || process.env;
return addEtcPathToPath(environmentVariables);
};

@@ -83,0 +100,0 @@

{
"name": "get-shell-vars",
"version": "1.2.1",
"version": "2.0.0",
"description": "Code that sources correct profiles, so that you can use all Environment variables declared in them.",

@@ -34,4 +34,5 @@ "main": "./lib/index.js",

"dependencies": {
"lodash": "4.16.4"
"lodash": "4.16.4",
"temp": "0.8.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc