Skip to content

Commit 257b523

Browse files
committed
Fixes requirejs#94: dir command line override was not working.
1 parent a502e59 commit 257b523

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

build/jslib/build.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
* see: http://github.com/jrburke/requirejs for details
55
*/
66

7-
/*jslint regexp: false, plusplus: false, nomen: false, strict: false */
8-
/*global define: false, require: false */
7+
/*jslint plusplus: true, nomen: true */
8+
/*global define, require */
99

1010

1111
define([ 'lang', 'logger', 'env!env/file', 'parse', 'optimize', 'pragma',
1212
'env!env/load', 'requirePatch'],
1313
function (lang, logger, file, parse, optimize, pragma,
1414
load, requirePatch) {
15+
'use strict';
16+
1517
var build, buildBaseConfig,
1618
endsWithSemiColonRegExp = /;\s*$/;
1719

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

537539
props = ["appDir", "dir", "baseUrl"];
538540
for (i = 0; (prop = props[i]); i++) {
539541
if (config[prop]) {
540542
//Add abspath if necessary, make sure these paths end in
541543
//slashes
542544
if (prop === "baseUrl") {
543-
originalBaseUrl = config.baseUrl;
545+
config.originalBaseUrl = config.baseUrl;
544546
if (config.appDir) {
545547
//If baseUrl with an appDir, the baseUrl is relative to
546548
//the appDir, *not* the absFilePath. appDir and dir are
547549
//made absolute before baseUrl, so this will work.
548-
config.baseUrl = build.makeAbsPath(originalBaseUrl, config.appDir);
549-
//Set up dir output baseUrl.
550-
config.dirBaseUrl = build.makeAbsPath(originalBaseUrl, config.dir);
550+
config.baseUrl = build.makeAbsPath(config.originalBaseUrl, config.appDir);
551551
} else {
552552
//The dir output baseUrl is same as regular baseUrl, both
553553
//relative to the absFilePath.
554554
config.baseUrl = build.makeAbsPath(config[prop], absFilePath);
555-
config.dirBaseUrl = config.dir || config.baseUrl;
556555
}
557-
558-
//Make sure dirBaseUrl ends in a slash, since it is
559-
//concatenated with other strings.
560-
config.dirBaseUrl = endsWithSlash(config.dirBaseUrl);
561556
} else {
562557
config[prop] = build.makeAbsPath(config[prop], absFilePath);
563558
}
@@ -630,12 +625,13 @@ function (lang, logger, file, parse, optimize, pragma,
630625
var config = {}, buildFileContents, buildFileConfig, mainConfig,
631626
mainConfigFile, prop, buildFile, absFilePath;
632627

633-
lang.mixin(config, buildBaseConfig);
634-
lang.mixin(config, cfg, true);
635-
636628
//Make sure all paths are relative to current directory.
637629
absFilePath = file.absPath('.');
638-
build.makeAbsConfig(config, absFilePath);
630+
build.makeAbsConfig(cfg, absFilePath);
631+
build.makeAbsConfig(buildBaseConfig, absFilePath);
632+
633+
lang.mixin(config, buildBaseConfig);
634+
lang.mixin(config, cfg, true);
639635

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

696+
697+
//Set final output dir
698+
if (config.hasOwnProperty("baseUrl")) {
699+
if (config.appDir) {
700+
config.dirBaseUrl = build.makeAbsPath(config.originalBaseUrl, config.dir);
701+
} else {
702+
config.dirBaseUrl = config.dir || config.baseUrl;
703+
}
704+
//Make sure dirBaseUrl ends in a slash, since it is
705+
//concatenated with other strings.
706+
config.dirBaseUrl = endsWithSlash(config.dirBaseUrl);
707+
}
708+
700709
//Check for errors in config
701710
if (config.cssIn && !config.out) {
702711
throw new Error("ERROR: 'out' option missing.");

build/tests/builds.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ define(['build', 'env!env/file'], function (build, file) {
127127
);
128128
doh.run();
129129

130+
doh.register("buildSimpleOverride",
131+
[
132+
function buildSimple(t) {
133+
//Do the build
134+
build(["simple.build.js", "dir=builds/simpleOverride"]);
135+
136+
t.is(nol(oneResult), nol(c("builds/simpleOverride/one.js")));
137+
138+
//Reset require internal state for the contexts so future
139+
//builds in these tests will work correctly.
140+
require._buildReset();
141+
}
142+
]
143+
);
144+
doh.run();
145+
130146
doh.register("buildExcludeShallow",
131147
[
132148
function buildExcludeShallow(t) {

0 commit comments

Comments
 (0)