Comparing version 3.1.4 to 3.2.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports['default'] = commandConvert; | ||
var _isWindows = require('is-windows'); | ||
var _isWindows2 = _interopRequireDefault(_isWindows); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = commandConvert; | ||
var envUseUnixRegex = /\$(\w+)/g; // $my_var | ||
var envUseWinRegex = /\%(.*?)\%/g; // %my_var% | ||
var isWin = process.platform === 'win32'; | ||
var envExtract = isWin ? envUseUnixRegex : envUseWinRegex; | ||
var envUseWinRegex = /%(.*?)%/g; // %my_var% | ||
@@ -19,8 +25,9 @@ /** | ||
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]; | ||
command = isWin ? `%${match[1]}%` : `$${match[1]}`; | ||
} | ||
return command; | ||
} | ||
module.exports = exports['default']; | ||
} |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
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'); } }; })(); | ||
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"); } }; }(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _crossSpawn = require('cross-spawn'); | ||
@@ -17,45 +15,44 @@ | ||
exports['default'] = crossEnv; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = crossEnv; | ||
var envSetterRegex = /(\w+)=('(.+)'|"(.+)"|(.+))/; | ||
function crossEnv(args) { | ||
var _getCommandArgsAndEnvVars = getCommandArgsAndEnvVars(args); | ||
var _getCommandArgsAndEnv = getCommandArgsAndEnvVars(args), | ||
_getCommandArgsAndEnv2 = _slicedToArray(_getCommandArgsAndEnv, 3), | ||
command = _getCommandArgsAndEnv2[0], | ||
commandArgs = _getCommandArgsAndEnv2[1], | ||
env = _getCommandArgsAndEnv2[2]; | ||
var _getCommandArgsAndEnvVars2 = _slicedToArray(_getCommandArgsAndEnvVars, 3); | ||
var command = _getCommandArgsAndEnvVars2[0]; | ||
var commandArgs = _getCommandArgsAndEnvVars2[1]; | ||
var env = _getCommandArgsAndEnvVars2[2]; | ||
if (command) { | ||
var _ret = (function () { | ||
var proc = (0, _crossSpawn.spawn)(command, commandArgs, { stdio: 'inherit', env: env }); | ||
process.on('SIGTERM', function () { | ||
return proc.kill('SIGTERM'); | ||
}); | ||
process.on('SIGINT', function () { | ||
return proc.kill('SIGINT'); | ||
}); | ||
process.on('SIGBREAK', function () { | ||
return proc.kill('SIGBREAK'); | ||
}); | ||
process.on('SIGHUP', function () { | ||
return proc.kill('SIGHUP'); | ||
}); | ||
proc.on('exit', process.exit); | ||
return { | ||
v: proc | ||
}; | ||
})(); | ||
if (typeof _ret === 'object') return _ret.v; | ||
var proc = (0, _crossSpawn.spawn)(command, commandArgs, { stdio: 'inherit', env }); | ||
process.on('SIGTERM', function () { | ||
return proc.kill('SIGTERM'); | ||
}); | ||
process.on('SIGINT', function () { | ||
return proc.kill('SIGINT'); | ||
}); | ||
process.on('SIGBREAK', function () { | ||
return proc.kill('SIGBREAK'); | ||
}); | ||
process.on('SIGHUP', function () { | ||
return proc.kill('SIGHUP'); | ||
}); | ||
proc.on('exit', process.exit); | ||
return proc; | ||
} | ||
return null; | ||
} | ||
function getCommandArgsAndEnvVars(args) { | ||
// eslint-disable-line | ||
var command = undefined; | ||
var envVars = Object.assign({}, process.env); | ||
var commandArgs = args.map(_command2['default']); | ||
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) { | ||
@@ -67,11 +64,14 @@ var shifted = commandArgs.shift(); | ||
} else { | ||
command = shifted; | ||
break; | ||
return shifted; | ||
} | ||
if (process.env.APPDATA) { | ||
envVars.APPDATA = process.env.APPDATA; | ||
} | ||
} | ||
return [command, commandArgs, envVars]; | ||
return null; | ||
} | ||
module.exports = exports['default']; | ||
function getEnvVars() { | ||
var envVars = Object.assign({}, process.env); | ||
if (process.env.APPDATA) { | ||
envVars.APPDATA = process.env.APPDATA; | ||
} | ||
return envVars; | ||
} |
118
package.json
{ | ||
"name": "cross-env", | ||
"version": "3.1.4", | ||
"description": "Run commands that set environment variables across platforms", | ||
"version": "3.2.0", | ||
"description": "Run scripts that set and use environment variables across platforms", | ||
"main": "dist/index.js", | ||
@@ -13,58 +13,82 @@ "bin": { | ||
"scripts": { | ||
"start": "npm run test:watch", | ||
"prebuild": "rimraf dist && mkdir dist", | ||
"build": "babel --copy-files --out-dir dist --ignore *.test.js src", | ||
"commit": "git-cz", | ||
"eslint": "eslint src/ -c other/src.eslintrc --ignore-path other/src.eslintignore && eslint src/*.test.js", | ||
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
"report-coverage": "cat ./coverage/lcov.info | codecov", | ||
"test:watch": "mocha src/*.test.js -w --compilers js:babel/register", | ||
"test": "istanbul cover -x *.test.js node_modules/mocha/bin/_mocha -- -R spec src/*.test.js --compilers js:babel/register", | ||
"prepublish": "npm run build", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
"start": "nps", | ||
"test": "nps test", | ||
"commitmsg": "opt --in commit-msg --exec \"validate-commit-msg\"", | ||
"precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kentcdodds/cross-env.git" | ||
}, | ||
"keywords": [ | ||
"environment variables", | ||
"cross platform" | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [], | ||
"author": "Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/kentcdodds/cross-env/issues" | ||
"dependencies": { | ||
"cross-spawn": "^5.1.0", | ||
"is-windows": "^1.0.0" | ||
}, | ||
"homepage": "https://github.com/kentcdodds/cross-env#readme", | ||
"devDependencies": { | ||
"babel": "5.8.23", | ||
"chai": "3.3.0", | ||
"codecov.io": "0.1.6", | ||
"commitizen": "2.4.4", | ||
"cz-conventional-changelog": "1.1.4", | ||
"eslint": "1.5.1", | ||
"eslint-config-kentcdodds": "4.0.1", | ||
"eslint-plugin-mocha": "1.0.0", | ||
"ghooks": "1.0.0", | ||
"istanbul": "0.3.21", | ||
"mocha": "2.3.3", | ||
"proxyquire": "1.7.2", | ||
"rimraf": "^2.5.2", | ||
"semantic-release": "4.3.5", | ||
"sinon": "1.17.1", | ||
"sinon-chai": "2.8.0", | ||
"validate-commit-msg": "1.0.0" | ||
"all-contributors-cli": "^4.0.1", | ||
"babel-cli": "^6.23.0", | ||
"babel-core": "^6.23.1", | ||
"babel-jest": "^19.0.0", | ||
"babel-preset-env": "^1.2.0", | ||
"babel-preset-stage-2": "^6.22.0", | ||
"babel-register": "^6.23.0", | ||
"codecov": "^1.0.1", | ||
"commitizen": "^2.9.6", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"eslint": "^3.17.0", | ||
"eslint-config-kentcdodds": "^12.0.0", | ||
"husky": "^0.13.2", | ||
"jest-cli": "^19.0.2", | ||
"lint-staged": "^3.3.1", | ||
"nps": "^5.0.3", | ||
"nps-utils": "^1.1.2", | ||
"opt-cli": "^1.5.1", | ||
"prettier-eslint-cli": "^3.1.2", | ||
"semantic-release": "^6.3.6", | ||
"validate-commit-msg": "^2.11.1" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"kentcdodds", | ||
"kentcdodds/jest" | ||
], | ||
"rules": { | ||
"max-len": [ | ||
"error", | ||
80 | ||
] | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier-eslint --write", | ||
"git add" | ||
] | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
} | ||
} | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog/" | ||
}, | ||
"ghooks": { | ||
"commit-msg": "validate-commit-msg && npm run eslint && npm t && npm run check-coverage && echo 'pre-commit checks good 👍'" | ||
"path": "node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"dependencies": { | ||
"cross-spawn": "^3.0.1" | ||
} | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kentcdodds/cross-env.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/kentcdodds/cross-env/issues" | ||
}, | ||
"homepage": "https://github.com/kentcdodds/cross-env#readme" | ||
} |
133
README.md
# cross-env | ||
Status: | ||
[![npm version](https://img.shields.io/npm/v/cross-env.svg?style=flat-square)](https://www.npmjs.org/package/cross-env) | ||
[![npm downloads](https://img.shields.io/npm/dm/cross-env.svg?style=flat-square)](http://npm-stat.com/charts.html?package=cross-env&from=2015-09-01) | ||
[![Build Status](https://img.shields.io/travis/kentcdodds/cross-env.svg?style=flat-square)](https://travis-ci.org/kentcdodds/cross-env) | ||
[![Code Coverage](https://img.shields.io/codecov/c/github/kentcdodds/cross-env.svg?style=flat-square)](https://codecov.io/github/kentcdodds/cross-env) | ||
Run scripts that set and use environment variables across platforms | ||
[![Build Status][build-badge]][build] | ||
[![Code Coverage][coverage-badge]][coverage] | ||
[![Dependencies][dependencyci-badge]][dependencyci] | ||
[![version][version-badge]][package] | ||
[![downloads][downloads-badge]][npm-stat] | ||
[![MIT License][license-badge]][LICENSE] | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
[![Donate][donate-badge]][donate] | ||
[![Code of Conduct][coc-badge]][coc] | ||
[![Roadmap][roadmap-badge]][roadmap] | ||
[![Examples][examples-badge]][examples] | ||
This micro-lib allows you to provide a script which sets an environment using unix style and have it work on windows too | ||
[![Watch on GitHub][github-watch-badge]][github-watch] | ||
[![Star on GitHub][github-star-badge]][github-star] | ||
[![Tweet][twitter-badge]][twitter] | ||
## The problem | ||
Most Windows command prompts will choke when you set environment variables with | ||
`NODE_ENV=production` like that. (The exception is [Bash on Windows][win-bash], | ||
which uses native Bash.) Similarly, there's a difference in how windows and | ||
POSIX commands utilize environment variables. With POSIX, you use: `$ENV_VAR` | ||
and on windows you use `%ENV_VAR%`. | ||
## This solution | ||
`cross-env` makes it so you can have a single command without worrying about | ||
setting or using the environment variable properly for the platform. Just set it | ||
like you would if it's running on a POSIX system, and `cross-env` will take care | ||
of setting it properly. | ||
## Prerequisites | ||
- [Node.js](https://nodejs.org/) version 4.0 or greater. | ||
- [NodeJS][node] version 4.0 or greater. | ||
## Installation | ||
This module is distributed via [npm][npm] which is bundled with [node][node] and | ||
should be installed as one of your project's `devDependencies`: | ||
``` | ||
npm install --save-dev cross-env | ||
``` | ||
## Usage | ||
@@ -28,3 +63,3 @@ | ||
Ultimately, the command that is executed (using `spawn`) is: | ||
Ultimately, the command that is executed (using `cross-spawn`) is: | ||
@@ -37,29 +72,45 @@ ``` | ||
You can also split a command into several ones, or separate the environment | ||
variables declaration from the actual command execution. You can do it this way: | ||
## Why? | ||
```json | ||
{ | ||
"scripts": { | ||
"parentScript": "cross-env GREET=\"Joe\" npm run childScript", | ||
"childScript": "echo Hello $GREET" | ||
} | ||
} | ||
``` | ||
Windows will choke when you set environment variables with `NODE_ENV=production` like that. This makes it so you can | ||
have a single command without worrying about setting the environment variable properly for the platform. Just set it | ||
like you would if it's running on a unix system, and `cross-env` will take care of setting it properly. | ||
Where `childScript` holds the actual command to execute and `parentScript` sets | ||
the environment variables to use. Then instead of run the childScript you run | ||
the parent. This is quite useful for launching the same command with different | ||
env variables or when the environment variables are too long to have everything | ||
in one line. | ||
## Known limitations | ||
## Inspiration | ||
If you plan to do something like this: | ||
I originally created this to solve a problem I was having with my npm scripts in | ||
[angular-formly][angular-formly]. This made it made contributing to the project | ||
much easier for windows users. | ||
``` | ||
cross-env FOO=bar && echo $FOO | ||
``` | ||
## Other Solutions | ||
And expect it to output `bar` you're going to be sad, for two reasons: | ||
- [`env-cmd`](https://github.com/toddbluhm/env-cmd) - Reads environment variables from a file instead | ||
1. Technically, those will run as two separate commands, so even though `FOO` will properly be set to `bar` in the first command, the `echo $FOO` will not. | ||
2. When `echo $FOO` runs, the `$FOO` variable is replaced with the variable value, before it's even passed to `cross-env` (though, as indicated in #1, that doesn't happen anyway) | ||
## Contributors | ||
The main use case for this package is to simply run another script which will (itself) respond to the environment | ||
variable. These limitations are not a problem in that scenario (like in the example). | ||
Thanks goes to these people ([emoji key][emojis]): | ||
## Related Projects | ||
<!-- 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) | | ||
| :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
[`env-cmd`](https://github.com/toddbluhm/env-cmd) - Reads environment variables from a file instead | ||
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! | ||
> Note: this was added late into the project. If you've contributed to this | ||
> project in any way, please make a pull request to add yourself to the list | ||
> by following the instructions in the `CONTRIBUTING.md` | ||
## LICENSE | ||
@@ -69,5 +120,35 @@ | ||
[npm]: https://www.npmjs.com/ | ||
[node]: https://nodejs.org | ||
[build-badge]: https://img.shields.io/travis/kentcdodds/cross-env.svg?style=flat-square | ||
[build]: https://travis-ci.org/kentcdodds/cross-env | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/cross-env.svg?style=flat-square | ||
[coverage]: https://codecov.io/github/kentcdodds/cross-env | ||
[dependencyci-badge]: https://dependencyci.com/github/kentcdodds/cross-env/badge?style=flat-square | ||
[dependencyci]: https://dependencyci.com/github/kentcdodds/cross-env | ||
[version-badge]: https://img.shields.io/npm/v/cross-env.svg?style=flat-square | ||
[package]: https://www.npmjs.com/package/cross-env | ||
[downloads-badge]: https://img.shields.io/npm/dm/cross-env.svg?style=flat-square | ||
[npm-stat]: http://npm-stat.com/charts.html?package=cross-env&from=2016-04-01 | ||
[license-badge]: https://img.shields.io/npm/l/cross-env.svg?style=flat-square | ||
[license]: https://github.com/kentcdodds/cross-env/blob/master/other/LICENSE | ||
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square | ||
[prs]: http://makeapullrequest.com | ||
[donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square | ||
[donate]: http://kcd.im/donate | ||
[dependencyci-badge]: https://dependencyci.com/github/kentcdodds/cross-env/badge?style=flat-square | ||
[dependencyci]: https://dependencyci.com/github/kentcdodds/cross-env | ||
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square | ||
[coc]: https://github.com/kentcdodds/cross-env/blob/master/other/CODE_OF_CONDUCT.md | ||
[roadmap-badge]: https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square | ||
[roadmap]: https://github.com/kentcdodds/cross-env/blob/master/other/ROADMAP.md | ||
[examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square | ||
[examples]: https://github.com/kentcdodds/cross-env/blob/master/other/EXAMPLES.md | ||
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/cross-env.svg?style=social | ||
[github-watch]: https://github.com/kentcdodds/cross-env/watchers | ||
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/cross-env.svg?style=social | ||
[github-star]: https://github.com/kentcdodds/cross-env/stargazers | ||
[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20cross-env!%20https://github.com/kentcdodds/cross-env%20%F0%9F%91%8D | ||
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/cross-env.svg?style=social | ||
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors | ||
[win-bash]: https://msdn.microsoft.com/en-us/commandline/wsl/about | ||
[angular-formly]: https://github.com/formly-js/angular-formly |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
151
3
13379
2
21
7
87
1
+ Addedis-windows@^1.0.0
+ Addedcross-spawn@5.1.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
- Removedcross-spawn@3.0.1(transitive)
Updatedcross-spawn@^5.1.0