Comparing version 2.7.0 to 2.7.1
History | ||
======= | ||
## 2.7.1 | ||
* Propagate `--` flags via environment instead of command line mutation. | ||
[#92](https://github.com/FormidableLabs/builder/issues/92) | ||
## 2.7.0 | ||
@@ -5,0 +10,0 @@ |
@@ -128,7 +128,7 @@ "use strict"; | ||
// See: https://docs.npmjs.com/cli/run-script#description | ||
var customArgs = []; | ||
var customFlags = []; | ||
var customIdx = argv.indexOf("--"); | ||
if (customIdx > -1) { | ||
// Update custom args. | ||
customArgs = argv.slice(customIdx + 1); | ||
customFlags = argv.slice(customIdx + 1); | ||
@@ -157,3 +157,3 @@ // Remove custom args from input. | ||
// Add in custom flags if found earlier. | ||
.merge(customArgs.length > 0 ? { _customArgs: customArgs } : {}) | ||
.merge(customFlags.length > 0 ? { _customFlags: customFlags } : {}) | ||
.value(); | ||
@@ -160,0 +160,0 @@ }; |
@@ -8,3 +8,2 @@ "use strict"; | ||
var chalk = require("chalk"); | ||
var argvSplit = require("argv-split"); | ||
var log = require("./log"); | ||
@@ -37,36 +36,38 @@ var Tracker = require("./utils/tracker"); | ||
// Helper for merging in custom options. | ||
var cmdWithCustom = function (cmd, opts) { | ||
/** | ||
* Merge custom commands (`--`) into chosen script command + add to environment. | ||
* | ||
* Always reads and updates `_BUILDER_ARGS_CUSTOM_FLAGS` env var. | ||
* _May_ also append `-- <extra args>` to command. | ||
* | ||
* @param {String} cmd Command | ||
* @param {Object} opts Options object | ||
* @param {Object} env Environment object | ||
* @returns {String} Updated command | ||
*/ | ||
var cmdWithCustom = function (cmd, opts, env) { | ||
opts = opts || {}; | ||
var customArgs = (opts || {})._customArgs || []; | ||
env = env || {}; | ||
// Start with command line flags. | ||
var customFlags = (opts || {})._customFlags || []; | ||
try { | ||
// Extract custom flags from environment | ||
customFlags = customFlags.concat(JSON.parse(env._BUILDER_ARGS_CUSTOM_FLAGS) || []); | ||
} catch (err) { | ||
// Ignore parsing errors. | ||
} | ||
// Base case: No custom arguments to add. | ||
if (customArgs.length === 0) { | ||
if (customFlags.length === 0) { | ||
return cmd; | ||
} | ||
// Scenario: A base command may have `--` already like `foo -- --bar` which | ||
// we need to add to. The hard part is the command may alternately be | ||
// something perverse like: `foo "totally -- not extra args"` where we need | ||
// to add the `--` to. | ||
// | ||
// This means _parsing_ a full command string, which we've tried to avoid | ||
// doing. So, current library of choice is: | ||
// - https://github.com/kaelzhang/node-argv-split | ||
// | ||
// Other working candidates: | ||
// - https://github.com/gabrieleds/node-argv (brings in `minimist` too) | ||
// | ||
// All of these libraries are a bit wonky / incomplete, so we only _detect_ | ||
// if `--` is pre-existing before appending to the existing command. But, | ||
// for safety we don't mutate the original command (besides appending). | ||
var parsed = argvSplit(cmd); | ||
var haveCustom = parsed.indexOf("--") > 0; | ||
// If we have custom flag commands from here, then add them to env. | ||
env._BUILDER_ARGS_CUSTOM_FLAGS = JSON.stringify(customFlags); | ||
// Only add the `--` token if _not_ already there and _is_ a builder task. | ||
var isBuilderTask = opts._isBuilderTask === true; | ||
var addCustomToken = isBuilderTask && !haveCustom; | ||
// Add in the custom args with/without `--` token. | ||
return cmd + (addCustomToken ? " -- " : " ") + customArgs.join(" "); | ||
// Only add the custom flags to non-builder tasks. | ||
return opts._isBuilderTask === true ? | ||
cmd : | ||
cmd + " " + customFlags.join(" "); | ||
}; | ||
@@ -84,9 +85,11 @@ | ||
var run = function (cmd, shOpts, opts, callback) { | ||
cmd = cmdWithCustom(cmd, opts); | ||
// Update shell options. | ||
// Update shell options and ensure basic structure. | ||
shOpts = _.extend({ | ||
maxBuffer: MAX_BUFFER | ||
maxBuffer: MAX_BUFFER, | ||
env: {} | ||
}, shOpts); | ||
// Mutate environment and return new command with `--` custom flags. | ||
cmd = cmdWithCustom(cmd, opts, shOpts.env); | ||
// Check if buffered output or piped. | ||
@@ -93,0 +96,0 @@ var buffer = opts.buffer; |
@@ -77,2 +77,5 @@ "use strict"; | ||
* | ||
* _Note_: Naive. Only captures `builder` at start of command. | ||
* See: https://github.com/FormidableLabs/builder/issues/93 | ||
* | ||
* @param {String} task Task | ||
@@ -79,0 +82,0 @@ * @returns {Boolean} Is this task a passthrough? |
{ | ||
"name": "builder", | ||
"version": "2.7.0", | ||
"version": "2.7.1", | ||
"description": "An NPM-based task runner", | ||
@@ -28,3 +28,2 @@ "repository": { | ||
"dependencies": { | ||
"argv-split": "^1.0.0", | ||
"async": "^1.4.2", | ||
@@ -31,0 +30,0 @@ "chalk": "^1.1.1", |
@@ -326,3 +326,4 @@ [![Travis Status][trav_img]][trav_site] | ||
1. If a `builder <action>` command, append with ` -- ` to pass through. | ||
1. If a `builder <action>` command, pass through using builder-specific | ||
environment variables. (Builder uses `_BUILDER_ARGS_CUSTOM_FLAGS`). | ||
2. If a non-`builder` command, then append without ` -- ` token. | ||
@@ -329,0 +330,0 @@ |
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
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
78629
6
1268
1038
- Removedargv-split@^1.0.0
- Removedargv-split@1.0.1(transitive)