Socket
Socket
Sign inDemoInstall

builder

Package Overview
Dependencies
Maintainers
5
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

builder - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

lib/utils/json.js

3

bin/builder-core.js

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

config: config,
env: opts.env
env: opts.env,
argv: opts.argv
});

@@ -34,0 +35,0 @@

History
=======
## 3.1.0
* Add `--env` environment variable flag.
[#45](https://github.com/FormidableLabs/builder/issues/45)
## 3.0.0

@@ -5,0 +10,0 @@

@@ -75,2 +75,12 @@ "use strict";

default: "info"
},
env: {
desc: "JSON string of environment variables to add to process",
types: [String],
default: null
},
"env-path": {
desc: "JSON file path of environment variables to add to process",
types: [path],
default: null
}

@@ -102,3 +112,3 @@ },

"envs-path": {
desc: "Path to JSON env variable array file (default: `null`)",
desc: "JSON File path to `envs` array",
types: [path],

@@ -105,0 +115,0 @@ default: null

@@ -11,3 +11,5 @@ "use strict";

var path = require("path");
var args = require("./args");
var clone = require("./utils/clone");
var jsonParse = require("./utils/json").parse;

@@ -37,2 +39,6 @@ // OS-specific helpers

// Arguments
this.argv = opts.argv || process.argv;
var parsed = args.general(this.argv);
// Clone if real process env to avoid direct mutation.

@@ -58,2 +64,5 @@ this.env = opts.env || process.env;

this.updateConfigVars(this.config.pkgConfigs);
// Add command-line `--env|--env-path` environment overrides.
this.updateEnvFlag(parsed);
};

@@ -131,1 +140,30 @@

};
/**
* Update environment `--env` / `--env-path` command line options.
*
* @param {Object} opts Options
* @param {String} opts.env Stringified JSON object
* @param {String} opts.envPath Path to JSON file
* @returns {Object} Mutated environment variable.
*/
Environment.prototype.updateEnvFlag = function (opts) {
// Nothing to parse.
if (!(opts.env || opts.envPath)) {
return this.env;
}
// Parse envs.
var envsObj = jsonParse({
str: opts.env,
path: opts.envPath
});
// Validation
if (!_.isPlainObject(envsObj)) {
throw new Error("Non-object JSON environment: " + JSON.stringify(envsObj));
}
// Mutate environment and return.
return _.merge(this.env, envsObj);
};
"use strict";
var fs = require("fs");
var path = require("path");

@@ -10,2 +9,3 @@ var _ = require("lodash");

var log = require("./log");
var jsonParse = require("./utils/json").parse;

@@ -252,20 +252,2 @@ /**

Task.prototype._parseJson = function (objStr) {
try {
return JSON.parse(objStr);
} catch (err) {
log.error(this._action + ":json-obj", "Failed to load JSON object: " + objStr);
throw err;
}
};
Task.prototype._parseJsonFile = function (filePath) {
try {
return JSON.parse(fs.readFileSync(filePath));
} catch (err) {
log.error(this._action + ":json-file", "Failed to load JSON file: " + filePath);
throw err;
}
};
/**

@@ -285,31 +267,31 @@ * Run multiple environments.

// Get task environment array.
var envsStr = this._commands[1];
// Parse envs.
var envsObj;
var err;
try {
if (envsStr) {
// Try string on command line first:
// $ builder envs <task> '[{ "FOO": "VAL1" }, { "FOO": "VAL2" }]'
opts._envs = this._parseJson(envsStr);
} else if (opts.envsPath) {
// Try JSON file path next:
// $ builder envs <task> --envs-path=my-environment-vars.json
opts._envs = this._parseJsonFile(opts.envsPath);
}
envsObj = jsonParse({
str: this._commands[1], // Get task environment array.
path: opts.envsPath
});
} catch (parseErr) {
return callback(parseErr);
err = parseErr;
}
// Validation
var err;
if (_.isEmpty(opts._envs)) {
if (!err && _.isEmpty(envsObj)) {
err = new Error("Empty/null JSON environments array.");
} else if (!_.isArray(opts._envs)) {
err = new Error("Non-array JSON environments object: " + JSON.stringify(opts._envs));
} else if (!err && !_.isArray(envsObj)) {
err = new Error("Non-array JSON environments object: " + JSON.stringify(envsObj));
}
if (err) {
log.error("envs:json-error", err);
log.error(this._action + ":json-error",
"Failed to load environments string / path with error: " + err);
return callback(err);
}
// Stash for use in runner options.
opts._envs = envsObj;
// Run.
this._runner.envs(task.cmd, { env: env }, opts, callback);

@@ -316,0 +298,0 @@ };

{
"name": "builder",
"version": "3.0.0",
"version": "3.1.0",
"description": "An NPM-based task runner",

@@ -5,0 +5,0 @@ "repository": {

@@ -62,4 +62,4 @@ [![Travis Status][trav_img]][trav_site]

- [builder envs](#builder-envs)
- [Custom Flags](#custom-flags)
- [Expanding the Archetype Path](#expanding-the-archetype-path)
- [Custom Flags](#custom-flags)
- [Expanding the Archetype Path](#expanding-the-archetype-path)
- [Tasks](#tasks)

@@ -97,3 +97,2 @@ - [npm Config](#npm-config)

- [I Give Up. How Do I Abandon Builder?](#i-give-up-how-do-i-abandon-builder)
- [Versions v1, v2, v3](#versions-v1-v2-v3)

@@ -284,2 +283,4 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

* `--log-level`: Level to log at (`info`, `warn`, `error`, `none`)
* `--env`: JSON object of keys to add to environment.
* `--env-path`: JSON file path of keys to add to environment.
* `--expand-archetype`: Expand `node_modules/<archetype>` with full path (default: `false`)

@@ -308,2 +309,4 @@ * `--builderrc`: Path to builder config file (default: `.builderrc`)

* `--log-level`: Level to log at (`info`, `warn`, `error`, `none`)
* `--env`: JSON object of keys to add to environment.
* `--env-path`: JSON file path of keys to add to environment.
* `--expand-archetype`: Expand `node_modules/<archetype>` with full path (default: `false`)

@@ -351,2 +354,4 @@ * `--builderrc`: Path to builder config file (default: `.builderrc`)

* `--log-level`: Level to log at (`info`, `warn`, `error`, `none`)
* `--env`: JSON object of keys to add to environment.
* `--env-path`: JSON file path of keys to add to environment.
* `--expand-archetype`: Expand `node_modules/<archetype>` with full path (default: `false`)

@@ -356,6 +361,17 @@ * `--builderrc`: Path to builder config file (default: `.builderrc`)

_Note_: The environments JSON array will overwrite **existing** values in the
environment.
environment. This includes environment variables provided to / from `builder`
from things such as `npm` `config` and the `--env`/`--env-path` flags.
###### Custom Flags
So, for example, if you invoke `builder` with:
```js
$ builder envs <task> '[{"FOO": "ENVS"}]' --env='{"FOO": "FLAG"}'
```
The environment variable `FOO` will have a value of `"ENVS"` with the single
environment object array item given to `builder envs` overriding the `--env`
flag value.
#### Custom Flags
Just like [`npm run <task> [-- <args>...]`](https://docs.npmjs.com/cli/run-script),

@@ -401,3 +417,3 @@ flags after a ` -- ` token in a builder task or from the command line are passed

###### Expanding the Archetype Path
#### Expanding the Archetype Path

@@ -1409,15 +1425,2 @@ Builder tasks often refer to configuration files in the archetype itself like:

### Versions v1, v2, v3
The `builder` project effectively starts at `v2.x.x`. Prior to that Builder was
a small DOM utility that fell into disuse, so we re-purposed it for a new
wonderful destiny! But, because we follow semver, that means everything starts
at `v2` and as a helpful tip / warning:
> Treat `v2.x` as a `v0.x` release
We'll try hard to keep it tight, but at our current velocity there are likely
to be some bumps and API changes that won't adhere strictly to semver until
things settle down in `v3.x`-on.
[builder-react-component]: https://github.com/FormidableLabs/builder-react-component

@@ -1424,0 +1427,0 @@ [trav_img]: https://api.travis-ci.org/FormidableLabs/builder.svg

Sorry, the diff of this file is not supported yet

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