Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

cross-env

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cross-env - npm Package Compare versions

Comparing version 3.2.4 to 4.0.0-beta.0

dist/variable.js

8

dist/bin/cross-env.js
#!/usr/bin/env node
'use strict';
var _ = require('../');
var crossEnv = require('..');
var _2 = _interopRequireDefault(_);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
(0, _2.default)(process.argv.slice(2));
crossEnv(process.argv.slice(2));

@@ -15,6 +15,2 @@ 'use strict';

var envUseUnixRegex = /\$(\w+)/; // $my_var
var envUseWinRegex = /%(.*?)%/; // %my_var%
/**

@@ -25,10 +21,9 @@ * Converts an environment variable usage to be appropriate for the current OS

*/
function commandConvert(command) {
var isWin = (0, _isWindows2.default)();
var envExtract = isWin ? envUseUnixRegex : envUseWinRegex;
var match = envExtract.exec(command);
if (match) {
command = isWin ? `%${match[1]}%` : `$${match[1]}`;
if (!(0, _isWindows2.default)()) {
return command;
}
return command;
var envUnixRegex = /\$(\w+)|\${(\w+)}/g; // $my_var or ${my_var}
return command.replace(envUnixRegex, '%$1$2%');
}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

@@ -15,18 +11,25 @@

var _variable = require('./variable');
var _variable2 = _interopRequireDefault(_variable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = crossEnv;
module.exports = crossEnv;
var envSetterRegex = /(\w+)=('(.+)'|"(.+)"|(.+))/;
function crossEnv(args) {
var _getCommandArgsAndEnv = getCommandArgsAndEnvVars(args),
_getCommandArgsAndEnv2 = _slicedToArray(_getCommandArgsAndEnv, 3),
command = _getCommandArgsAndEnv2[0],
commandArgs = _getCommandArgsAndEnv2[1],
env = _getCommandArgsAndEnv2[2];
var _parseCommand = parseCommand(args),
_parseCommand2 = _slicedToArray(_parseCommand, 3),
envSetters = _parseCommand2[0],
command = _parseCommand2[1],
commandArgs = _parseCommand2[2];
if (command) {
var proc = (0, _crossSpawn.spawn)(command, commandArgs, { stdio: 'inherit', env });
var proc = (0, _crossSpawn.spawn)((0, _command2.default)(command), commandArgs.map(_command2.default), {
stdio: 'inherit',
shell: true,
env: getEnvVars(envSetters)
});
process.on('SIGTERM', function () {

@@ -50,23 +53,21 @@ return proc.kill('SIGTERM');

function getCommandArgsAndEnvVars(args) {
var envVars = getEnvVars();
var commandArgs = args.map(_command2.default);
var command = getCommand(commandArgs, envVars);
return [command, commandArgs, envVars];
}
function getCommand(commandArgs, envVars) {
while (commandArgs.length) {
var shifted = commandArgs.shift();
var match = envSetterRegex.exec(shifted);
function parseCommand(args) {
var envSetters = {};
var command = null;
var commandArgs = [];
for (var i = 0; i < args.length; i++) {
var match = envSetterRegex.exec(args[i]);
if (match) {
envVars[match[1]] = match[3] || match[4] || match[5];
envSetters[match[1]] = match[3] || match[4] || match[5];
} else {
return shifted;
// No more env setters, the rest of the line must be the command and args
command = args[i];
commandArgs = args.slice(i + 1);
break;
}
}
return null;
return [envSetters, command, commandArgs];
}
function getEnvVars() {
function getEnvVars(envSetters) {
var envVars = Object.assign({}, process.env);

@@ -76,3 +77,6 @@ if (process.env.APPDATA) {

}
Object.keys(envSetters).forEach(function (varName) {
envVars[varName] = (0, _variable2.default)(envSetters[varName]);
});
return envVars;
}
{
"name": "cross-env",
"version": "3.2.4",
"version": "4.0.0-beta.0",
"description": "Run scripts that set and use environment variables across platforms",

@@ -93,2 +93,2 @@ "main": "dist/index.js",

"homepage": "https://github.com/kentcdodds/cross-env#readme"
}
}

@@ -10,6 +10,7 @@ # cross-env

[![version][version-badge]][package]
[![node-version][node-version-badge]][node]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]

@@ -40,6 +41,2 @@ [![Donate][donate-badge]][donate]

## Prerequisites
- [NodeJS][node] version 4.0 or greater.
## Installation

@@ -92,2 +89,15 @@

## Gotchas
If you want to have the environment variable apply to several commands in series
then you will need to wrap those in quotes in your script. For example:
```json
{
"scripts": {
"greet": "cross-env GREETING=Hi NAME=Joe \"echo $GREETING && echo $NAME\""
}
}
```
## Inspiration

@@ -108,4 +118,5 @@

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) πŸš‡ [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) | [<img src="https://avatars1.githubusercontent.com/u/499038?v=3" width="100px;"/><br /><sub>Ya Zhuang </sub>](https://zhuangya.me)<br />πŸ”Œ [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya) | [<img src="https://avatars3.githubusercontent.com/u/3440094?v=3" width="100px;"/><br /><sub>James Harris</sub>](https://wopian.me)<br />[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian) | [<img src="https://avatars1.githubusercontent.com/u/8941730?v=3" width="100px;"/><br /><sub>compumike08</sub>](https://github.com/compumike08)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08) | [<img src="https://avatars1.githubusercontent.com/u/2270425?v=3" width="100px;"/><br /><sub>Daniel RodrΓ­guez Rivero</sub>](https://github.com/danielo515)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515) | [<img src="https://avatars2.githubusercontent.com/u/1508477?v=3" width="100px;"/><br /><sub>Jonas Keinholz</sub>](https://github.com/inyono)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono) | [<img src="https://avatars3.githubusercontent.com/u/1656170?v=3" width="100px;"/><br /><sub>Hugo Wood</sub>](https://github.com/hgwood/blog)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood) |
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) πŸš‡ [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) | [<img src="https://avatars1.githubusercontent.com/u/499038?v=3" width="100px;"/><br /><sub>Ya Zhuang </sub>](https://zhuangya.me)<br />πŸ”Œ [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya) | [<img src="https://avatars3.githubusercontent.com/u/3440094?v=3" width="100px;"/><br /><sub>James Harris</sub>](https://wopian.me)<br />[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian) | [<img src="https://avatars1.githubusercontent.com/u/8941730?v=3" width="100px;"/><br /><sub>compumike08</sub>](https://github.com/compumike08)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08) | [<img src="https://avatars1.githubusercontent.com/u/2270425?v=3" width="100px;"/><br /><sub>Daniel RodrΓ­guez Rivero</sub>](https://github.com/danielo515)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515) | [<img src="https://avatars2.githubusercontent.com/u/1508477?v=3" width="100px;"/><br /><sub>Jonas Keinholz</sub>](https://github.com/inyono)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono) | [<img src="https://avatars3.githubusercontent.com/u/1656170?v=3" width="100px;"/><br /><sub>Hugo Wood</sub>](https://github.com/hgwood)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/3715715?v=3" width="100px;"/><br /><sub>Thiebaud Thomas</sub>](https://github.com/thomasthiebaud)<br />[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Athomasthiebaud) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud) | [<img src="https://avatars1.githubusercontent.com/u/1715800?v=3" width="100px;"/><br /><sub>Daniel Rey LΓ³pez</sub>](https://daniel.blog)<br />[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop) |
<!-- ALL-CONTRIBUTORS-LIST:END -->

@@ -135,2 +146,3 @@

[package]: https://www.npmjs.com/package/cross-env
[node-version-badge]: https://img.shields.io/badge/node-%3E%3D%204.0-orange.svg?style=flat-square
[downloads-badge]: https://img.shields.io/npm/dm/cross-env.svg?style=flat-square

@@ -137,0 +149,0 @@ [npm-stat]: http://npm-stat.com/charts.html?package=cross-env&from=2016-04-01

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