Skip to content

Commit

Permalink
Fixes #94: dir command line override was not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Feb 13, 2012
1 parent a502e59 commit 257b523
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
41 changes: 25 additions & 16 deletions build/jslib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
* see: http://github.com/jrburke/requirejs for details
*/

/*jslint regexp: false, plusplus: false, nomen: false, strict: false */
/*global define: false, require: false */
/*jslint plusplus: true, nomen: true */
/*global define, require */


define([ 'lang', 'logger', 'env!env/file', 'parse', 'optimize', 'pragma',
'env!env/load', 'requirePatch'],
function (lang, logger, file, parse, optimize, pragma,
load, requirePatch) {
'use strict';

var build, buildBaseConfig,
endsWithSemiColonRegExp = /;\s*$/;

Expand Down Expand Up @@ -532,32 +534,25 @@ function (lang, logger, file, parse, optimize, pragma,
* to the absFilePath passed in.
*/
build.makeAbsConfig = function (config, absFilePath) {
var props, prop, i, originalBaseUrl;
var props, prop, i;

props = ["appDir", "dir", "baseUrl"];
for (i = 0; (prop = props[i]); i++) {
if (config[prop]) {
//Add abspath if necessary, make sure these paths end in
//slashes
if (prop === "baseUrl") {
originalBaseUrl = config.baseUrl;
config.originalBaseUrl = config.baseUrl;
if (config.appDir) {
//If baseUrl with an appDir, the baseUrl is relative to
//the appDir, *not* the absFilePath. appDir and dir are
//made absolute before baseUrl, so this will work.
config.baseUrl = build.makeAbsPath(originalBaseUrl, config.appDir);
//Set up dir output baseUrl.
config.dirBaseUrl = build.makeAbsPath(originalBaseUrl, config.dir);
config.baseUrl = build.makeAbsPath(config.originalBaseUrl, config.appDir);
} else {
//The dir output baseUrl is same as regular baseUrl, both
//relative to the absFilePath.
config.baseUrl = build.makeAbsPath(config[prop], absFilePath);
config.dirBaseUrl = config.dir || config.baseUrl;
}

//Make sure dirBaseUrl ends in a slash, since it is
//concatenated with other strings.
config.dirBaseUrl = endsWithSlash(config.dirBaseUrl);
} else {
config[prop] = build.makeAbsPath(config[prop], absFilePath);
}
Expand Down Expand Up @@ -630,12 +625,13 @@ function (lang, logger, file, parse, optimize, pragma,
var config = {}, buildFileContents, buildFileConfig, mainConfig,
mainConfigFile, prop, buildFile, absFilePath;

lang.mixin(config, buildBaseConfig);
lang.mixin(config, cfg, true);

//Make sure all paths are relative to current directory.
absFilePath = file.absPath('.');
build.makeAbsConfig(config, absFilePath);
build.makeAbsConfig(cfg, absFilePath);
build.makeAbsConfig(buildBaseConfig, absFilePath);

lang.mixin(config, buildBaseConfig);
lang.mixin(config, cfg, true);

if (config.buildFile) {
//A build file exists, load it to get more config.
Expand Down Expand Up @@ -697,6 +693,19 @@ function (lang, logger, file, parse, optimize, pragma,
//args should take precedence over build file values.
mixConfig(config, cfg);


//Set final output dir
if (config.hasOwnProperty("baseUrl")) {
if (config.appDir) {
config.dirBaseUrl = build.makeAbsPath(config.originalBaseUrl, config.dir);
} else {
config.dirBaseUrl = config.dir || config.baseUrl;
}
//Make sure dirBaseUrl ends in a slash, since it is
//concatenated with other strings.
config.dirBaseUrl = endsWithSlash(config.dirBaseUrl);
}

//Check for errors in config
if (config.cssIn && !config.out) {
throw new Error("ERROR: 'out' option missing.");
Expand Down
16 changes: 16 additions & 0 deletions build/tests/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ define(['build', 'env!env/file'], function (build, file) {
);
doh.run();

doh.register("buildSimpleOverride",
[
function buildSimple(t) {
//Do the build
build(["simple.build.js", "dir=builds/simpleOverride"]);

t.is(nol(oneResult), nol(c("builds/simpleOverride/one.js")));

//Reset require internal state for the contexts so future
//builds in these tests will work correctly.
require._buildReset();
}
]
);
doh.run();

doh.register("buildExcludeShallow",
[
function buildExcludeShallow(t) {
Expand Down

0 comments on commit 257b523

Please sign in to comment.