Comparing version 3.2.4 to 4.0.0-beta.0
#!/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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18837
8
141
167
1
4