Comparing version 3.1.0 to 3.2.0
@@ -26,3 +26,6 @@ "use strict"; | ||
// Configuration | ||
var config = new Config(); | ||
var config = new Config({ | ||
env: opts.env, | ||
argv: opts.argv | ||
}); | ||
@@ -29,0 +32,0 @@ // Set up environment |
History | ||
======= | ||
## 3.2.0 | ||
* Add in `NODE_PATH` and `PATH` from _actual resolved paths_ of prod and dev | ||
archetypes instead of guessed paths. This will better support `yarn`, which | ||
flattens `node_modules/.bin` in different ways than real `npm`. It is also | ||
likely more correct than before. | ||
[#134](https://github.com/FormidableLabs/builder/issues/134) | ||
* Add extra higher level directory check when `LOCAL_DEV=true` and | ||
`--expand-archetype` specified. | ||
* Make config loading failure a simple `log.info` instead of `log.warn`. | ||
## 3.1.0 | ||
@@ -5,0 +16,0 @@ |
@@ -16,2 +16,3 @@ "use strict"; | ||
var log = require("./log"); | ||
var expandFlag = require("./utils/archetype").expandFlag; | ||
@@ -21,6 +22,8 @@ /** | ||
* | ||
* @param {Object} cfg Configuration object or JSON/YAML file (Default: `.builderrc`) | ||
* @param {Object} opts Options object | ||
* @param {Object} opts.env Raw environment (Default `process.env`) | ||
* @param {Array} opts.argv Raw arguments array (Default: `process.argv`) | ||
* @returns {void} | ||
*/ | ||
var Config = module.exports = function (cfg) { | ||
var Config = module.exports = function (opts) { | ||
log.info("config:environment", JSON.stringify({ | ||
@@ -31,10 +34,12 @@ cwd: process.cwd(), | ||
this.cfg = this._loadConfig(cfg); | ||
// Internal global state. | ||
opts = opts || {}; | ||
this._args = args.general(opts.argv || process.argv); | ||
this.expandArchetype = expandFlag(opts); | ||
this.cfg = this._loadConfig(); | ||
this.archetypes = this.cfg.archetypes || []; | ||
// Include the `-dev` packages. | ||
this.allArchetypes = this.archetypes.reduce(function (memo, name) { | ||
return memo.concat([name, name + "-dev"]); | ||
}, []); | ||
// Array of `{ name, path }` | ||
this.devPkgs = this._loadDevPkgs(this.archetypes); | ||
// Array of `{ name, mod, path, scripts, config }` | ||
@@ -65,22 +70,17 @@ this.pkgs = this._loadPkgs(this.archetypes); | ||
* | ||
* @param {Object} cfg Configuration object or JSON/YAML file (Default: `.builderrc`) | ||
* @returns {Object} Configuration object | ||
* @returns {Object} Configuration object | ||
*/ | ||
Config.prototype._loadConfig = function (cfg) { | ||
cfg = cfg || ".builderrc"; | ||
Config.prototype._loadConfig = function () { | ||
// Override from command line. | ||
var parsed = args.general(); | ||
if (parsed.builderrc) { | ||
cfg = parsed.builderrc; | ||
} | ||
var cfgObj = this._args.builderrc || ".builderrc"; | ||
var cfg = {}; | ||
// Load from builderrc. | ||
if (typeof cfg === "string") { | ||
if (typeof cfgObj === "string") { | ||
try { | ||
cfg = yaml.safeLoad(fs.readFileSync(cfg, "utf8")); | ||
cfg = yaml.safeLoad(fs.readFileSync(cfgObj, "utf8")); | ||
} catch (err) { | ||
if (err.code === "ENOENT") { | ||
log.warn("config", "Unable to load config file: " + cfg); | ||
} else { | ||
log.info("config", "Unable to load config file: " + cfgObj); | ||
if (err.code !== "ENOENT") { | ||
log.error("config", err.toString()); | ||
@@ -90,4 +90,2 @@ throw err; | ||
} | ||
cfg = cfg || {}; | ||
} | ||
@@ -116,2 +114,13 @@ | ||
} | ||
// Allow a lower directory peek if expanding archetype. | ||
if (this.expandArchetype) { | ||
try { | ||
pkg = pkg || this._lazyRequire( | ||
path.join(process.cwd(), "../../node_modules", name, "package.json")); | ||
} catch (err) { | ||
/*eslint-disable no-empty*/ | ||
// Pass through error | ||
} | ||
} | ||
} | ||
@@ -155,14 +164,41 @@ | ||
// Add scripts, config. | ||
pkgs = _.mapValues(pkgs, function (pkg) { | ||
var mod = pkg.mod || {}; | ||
return _.chain(pkgs) | ||
.mapValues(function (pkg) { | ||
var mod = pkg.mod || {}; | ||
return _.extend({ | ||
config: mod.config, | ||
scripts: pkg.name === "ROOT" ? mod.scripts || {} : self._loadArchetypeScripts(pkg) | ||
}, pkg); | ||
}); | ||
return _.extend({ | ||
config: mod.config, | ||
scripts: pkg.name === "ROOT" ? mod.scripts || {} : self._loadArchetypeScripts(pkg) | ||
}, pkg); | ||
}) | ||
.toArray() | ||
.value(); | ||
}; | ||
return pkgs; | ||
/** | ||
* Load dev packages (if available). | ||
* | ||
* @param {Array} archetypes Archetype names | ||
* @returns {Array} Array of `{ name, path }` | ||
*/ | ||
Config.prototype._loadDevPkgs = function (archetypes) { | ||
var self = this; | ||
return _.chain(archetypes) | ||
.map(function (baseName) { | ||
var name = baseName + "-dev"; | ||
try { | ||
return _.extend({ name: name }, self._loadArchetypePkg(name)); | ||
} catch (err) { | ||
// Pass through error | ||
return null; | ||
} | ||
}) | ||
.filter(_.identity) | ||
.reverse() | ||
.value(); | ||
}; | ||
/** | ||
@@ -279,4 +315,4 @@ * Archetype package scripts. | ||
get: function () { | ||
return _.map(this.allArchetypes, function (name) { | ||
return path.join(process.cwd(), "node_modules", name, "node_modules/.bin"); | ||
return _.map([].concat(this.pkgs, this.devPkgs), function (pkg) { | ||
return path.join(pkg.path, "node_modules/.bin"); | ||
}); | ||
@@ -293,4 +329,4 @@ } | ||
get: function () { | ||
return _.map(this.allArchetypes, function (name) { | ||
return path.join(process.cwd(), "node_modules", name, "node_modules"); | ||
return _.map([].concat(this.pkgs, this.devPkgs), function (pkg) { | ||
return path.join(pkg.path, "node_modules"); | ||
}); | ||
@@ -297,0 +333,0 @@ } |
@@ -14,2 +14,3 @@ "use strict"; | ||
var clone = require("./utils/clone"); | ||
var expandFlag = require("./utils/archetype").expandFlag; | ||
var runner; | ||
@@ -106,3 +107,3 @@ | ||
// Short-circuit if no expansion. | ||
var expand = opts.expandArchetype || env._BUILDER_ARGS_EXPAND_ARCHETYPE === "true"; | ||
var expand = opts.expandArchetype || expandFlag({ env: env }); | ||
if (expand !== true) { | ||
@@ -293,3 +294,5 @@ return cmd; | ||
// something that could be reused by `builder-core.js` | ||
var config = new Config(); | ||
var config = new Config({ | ||
env: shOpts.env | ||
}); | ||
var env = new Environment({ | ||
@@ -296,0 +299,0 @@ config: config, |
{ | ||
"name": "builder", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "An NPM-based task runner", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
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
114475
20
1694
12