Skip to content
This repository
Browse code

Make sure only files that are loaded are included in the build, and t…

…hat each mapped file only gets in the build layer one time. Update snapshot of require.js
  • Loading branch information...
commit 4bbdba6fbcf3d21df498b8f465f767ab50b3b5e0 1 parent 4645ced
James Burke authored
42 build/jslib/requirePatch.js
@@ -67,7 +67,7 @@ function (file, pragma, parse) {
67 67 buildPathMap: {},
68 68 buildFileToModule: {},
69 69 buildFilePaths: [],
70   - loadedFiles: {},
  70 + pathAdded: {},
71 71 modulesWithNames: {},
72 72 needsDefine: {},
73 73 existingRequireUrl: "",
@@ -233,16 +233,24 @@ function (file, pragma, parse) {
233 233
234 234 //A plugin.
235 235 if (map.prefix) {
236   - layer.buildFilePaths.push(fullName);
237   - //For plugins the real path is not knowable, use the name
238   - //for both module to file and file to module mappings.
239   - layer.buildPathMap[fullName] = fullName;
240   - layer.buildFileToModule[fullName] = fullName;
241   - layer.modulesWithNames[fullName] = true;
  236 + if (!layer.pathAdded[fullName]) {
  237 + layer.buildFilePaths.push(fullName);
  238 + //For plugins the real path is not knowable, use the name
  239 + //for both module to file and file to module mappings.
  240 + layer.buildPathMap[fullName] = fullName;
  241 + layer.buildFileToModule[fullName] = fullName;
  242 + layer.modulesWithNames[fullName] = true;
  243 + layer.pathAdded[fullName] = true;
  244 + }
242 245 } else if (map.url) {
243   - url = normalizeUrlWithBase(context, map.fullName, map.url);
244   - //Remember the list of dependencies for this layer.
245   - layer.buildFilePaths.push(url);
  246 + //If the url has not been added to the layer yet, and it
  247 + //is from an actual file that was loaded, add it now.
  248 + if (!layer.pathAdded[url] && layer.buildPathMap[fullName]) {
  249 + url = normalizeUrlWithBase(context, map.fullName, map.url);
  250 + //Remember the list of dependencies for this layer.
  251 + layer.buildFilePaths.push(url);
  252 + layer.pathAdded[url] = true;
  253 + }
246 254 }
247 255 };
248 256
@@ -254,17 +262,11 @@ function (file, pragma, parse) {
254 262 layer.needsDefine[moduleName] = true;
255 263 };
256 264
257   - //Marks the module as part of the loaded set, and puts
258   - //it in the right position for output in the build layer,
259   - //since require() already did the dependency checks and should have
260   - //called this method already for those dependencies.
  265 + //Marks module has having a name, and optionally executes the
  266 + //callback, but only if it meets certain criteria.
261 267 require.execCb = function (name, cb, args, exports) {
262   - var url = name && layer.buildPathMap[name];
263   - if (url && !layer.loadedFiles[url]) {
264   - layer.loadedFiles[url] = true;
265   - if (!layer.needsDefine[name]) {
266   - layer.modulesWithNames[name] = true;
267   - }
  268 + if (!layer.needsDefine[name]) {
  269 + layer.modulesWithNames[name] = true;
268 270 }
269 271 if (cb.__requireJsBuild || layer.context.needFullExec[name]) {
270 272 return cb.apply(exports, args);
5 require.js
@@ -1190,6 +1190,11 @@ var requirejs, require, define;
1190 1190 require: function (deps, callback, relModuleMap) {
1191 1191 var moduleName, fullName, moduleMap;
1192 1192 if (typeof deps === "string") {
  1193 + if (isFunction(callback)) {
  1194 + //Invalid call
  1195 + return req.onError(makeError("requireargs", "Invalid require call"));
  1196 + }
  1197 +
1193 1198 //Synchronous access to one module. If require.get is
1194 1199 //available (as in the Node adapter), prefer that.
1195 1200 //In this case deps is the moduleName and callback is
2  tests/node/canvasTest.js
@@ -5,7 +5,7 @@
5 5 /*jslint strict: false */
6 6 /*global require: false, console: false */
7 7
8   -var require = require('r');
  8 +var require = require('../../r');
9 9
10 10 require(['canvas', 'express'], function (Canvas, express) {
11 11 var canvas = new Canvas(200, 200),

0 comments on commit 4bbdba6

Please sign in to comment.
Something went wrong with that request. Please try again.