Skip to content

Commit 6486a15

Browse files
committed
Fixes requirejs#56, a built layer's output could be picked up as part of another layer if the first layer is a dependency of the second one.
1 parent 32ddcd1 commit 6486a15

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

build/jslib/build.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,22 @@ function (lang, logger, file, parse, optimize, pragma,
312312

313313
//Flatten them and collect the build output for each module.
314314
builtModule = build.flattenModule(module, module.layer, config);
315-
file.saveUtf8File(module._buildPath, builtModule.text);
315+
316+
//Save it to a temp file for now, in case there are other layers that
317+
//contain optimized content that should not be included in later
318+
//layer optimizations. See issue #56.
319+
file.saveUtf8File(module._buildPath + '-temp', builtModule.text);
316320
buildFileContents += builtModule.buildText;
317321
});
322+
323+
//Now move the build layers to their final position.
324+
modules.forEach(function (module) {
325+
var finalPath = module._buildPath;
326+
if (file.exists(finalPath)) {
327+
file.deleteFile(finalPath);
328+
}
329+
file.renameFile(finalPath + '-temp', finalPath);
330+
});
318331
}
319332

320333
//Do other optimizations.

build/jslib/node/file.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define(['fs', 'path'], function (fs, path) {
3232

3333
function mkDir(dir) {
3434
if (!exists(dir)) {
35-
fs.mkdirSync(dir, 0777);
35+
fs.mkdirSync(dir, 511);
3636
}
3737
}
3838

@@ -193,6 +193,13 @@ define(['fs', 'path'], function (fs, path) {
193193
return true; //Boolean
194194
},
195195

196+
/**
197+
* Renames a file. May fail if "to" already exists or is on another drive.
198+
*/
199+
renameFile: function (from, to) {
200+
return fs.renameSync(from, to);
201+
},
202+
196203
/**
197204
* Reads a *text* file.
198205
*/

build/jslib/rhino/file.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ define(function () {
162162
return true; //Boolean
163163
},
164164

165+
/**
166+
* Renames a file. May fail if "to" already exists or is on another drive.
167+
*/
168+
renameFile: function (from, to) {
169+
return (new java.io.File(from)).renameTo((new java.io.File(to)));
170+
},
171+
165172
readFile: function (/*String*/path, /*String?*/encoding) {
166173
//A file read function that can deal with BOMs
167174
encoding = encoding || "utf-8";

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy