Ticket #2696: build.3.patch
| File build.3.patch, 12.5 kB (added by guest, 16 months ago) |
|---|
-
dojo/_base/_loader/bootstrap.js
97 97 dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){ 98 98 var obj=context||dojo.global; 99 99 for(var i=0, p; obj&&(p=parts[i]); i++){ 100 obj = ( p in obj? obj[p] : (create ? obj[p]={} : undefined));100 obj = (obj[p] ? obj[p] : (create ? obj[p]={} : undefined)); 101 101 } 102 102 return obj; // Any 103 103 } … … 219 219 =====*/ 220 220 221 221 // vim:ai:ts=4:noet 222 if(typeof dojo.global.OpenAjax == "undefined") { 223 OpenAjax = dojo; 224 } 225 OpenAjax._resourceToUri = {}; 226 OpenAjax.register = function(resources, overwrite){ 227 // Register / add resource information to our list 228 for(var r in resources){ 229 if(!this._resourceToUri[r] || (this._resourceToUri[r] && overwrite) ){ 230 this._resourceToUri[r] = resources[r]; 231 } 232 } 233 }; 234 235 236 // vim:ai:ts=4:noet:textwidth=80 -
dojo/_base/_loader/loader.js
253 253 254 254 dojo._loadModule = function( /*String*/moduleName, 255 255 /*Boolean?*/exactOnly, 256 /*Boolean?*/omitModuleCheck){ 256 /*Boolean?*/omitModuleCheck, 257 /*String*/resourceType){ 257 258 // summary: 258 259 // loads a Javascript module from the appropriate URI 259 260 // description: … … 283 284 // 284 285 // dj_load is an alias for dojo._loadModule 285 286 287 moduleType = resourceType || '.js' 288 286 289 omitModuleCheck = this._global_omit_module_check || omitModuleCheck; 290 287 291 var module = this._loadedModules[moduleName]; 288 292 if(module){ 289 293 return module; 290 294 } 291 295 292 // convert periods to slashes293 var nsyms = moduleName.split(".");294 var syms = this._getModuleSymbols(moduleName);295 var startedRelative = ((syms[0].charAt(0) != '/') && !syms[0].match(/^\w+:/));296 var last = syms[syms.length - 1];297 296 var relpath; 298 // figure out if we're looking for a full package, if so, we want to do 299 // things slightly diffrently 300 if(last=="*"){ 301 moduleName = nsyms.slice(0, -1).join('.'); 302 syms.pop(); 303 relpath = syms.join("/") + "/" + (djConfig["packageFileName"]||"__package__") + '.js'; 304 if(startedRelative && relpath.charAt(0)=="/"){ 305 relpath = relpath.slice(1); 297 var resourceUri = OpenAjax._resourceToUri[moduleName]; 298 299 if(resourceUri){ 300 301 // TODO: support other types of URI, i.e. http:// for CSS or other ressources 302 if(resourceUri.match(/^file:\/\//)) { 303 relpath = OpenAjax._resourceToUri[moduleName].replace(/^file:\/\//, ''); 304 if(relpath.charAt(0) != '/') { 305 306 307 var d = relpath.split("/"); 308 var modulePrefix = dojo._getModulePrefix(d[0]); 309 if(modulePrefix == d[0]){ 310 relpath = '../'+relpath; 311 }else{ 312 d.splice(0, 1); 313 relpath = modulePrefix+'/'+d.join('/'); 314 } 315 } 306 316 } 307 }else{ 308 relpath = syms.join("/") + '.js'; 309 moduleName = nsyms.join('.'); 317 318 } else { 319 320 // convert periods to slashes 321 var nsyms = moduleName.split("."); 322 var syms = this._getModuleSymbols(moduleName); 323 var startedRelative = ((syms[0].charAt(0) != '/') && !syms[0].match(/^\w+:/)); 324 var last = syms[syms.length - 1]; 325 326 // figure out if we're looking for a full package, if so, we want to do 327 // things slightly diffrently 328 if(last=="*"){ 329 moduleName = nsyms.slice(0, -1).join('.'); 330 syms.pop(); 331 relpath = syms.join("/") + "/" + (djConfig["packageFileName"]||"__package__") + moduleType; 332 if(startedRelative && relpath.charAt(0)=="/"){ 333 relpath = relpath.slice(1); 334 } 335 }else{ 336 relpath = syms.join("/") + moduleType; 337 moduleName = nsyms.join('.'); 338 } 310 339 } 311 340 var modArg = (!omitModuleCheck) ? moduleName : null; 312 var ok = this._loadPath(relpath, modArg);341 var ok = false; 313 342 343 switch(moduleType) { 344 case '.js' : ok = this._loadPath(relpath, modArg); 345 break; 346 // TODO, handle CSS resource / append to head of body 347 } 348 314 349 if((!ok)&&(!omitModuleCheck)){ 315 350 throw new Error("Could not load '" + moduleName + "'; last tried '" + relpath + "'"); 316 351 } 317 352 318 353 // check that the symbol was defined 319 354 // Don't bother if we're doing xdomain (asynchronous) loading. 320 if( (!omitModuleCheck)&&(!this["_isXDomain"])){355 if(moduleType == '.js' && (!omitModuleCheck)&&(!this["_isXDomain"])){ 321 356 // pass in false so we can give better error 322 357 module = this._loadedModules[moduleName]; 323 358 if(!module){ … … 328 363 return module; 329 364 } 330 365 331 dojo.require = dojo._loadModule; 366 dojo.require = function(resourceId, resourceType) { 367 return dojo._loadModule(resourceId, null, null, resourceType); 368 }; 332 369 333 370 dojo.provide = function(/*String*/ packageName){ 334 371 // summary: -
util/buildscripts/build.js
263 263 } 264 264 //********* End release ********* 265 265 266 //********* Start Minimal ********* 267 function minimal(){ 268 logger.info("Using profile: " + kwArgs.profileFile); 269 logger.info("Using version number: " + kwArgs.version + " for the release."); 270 271 clean(); 272 273 var dependencies = kwArgs.profileProperties.dependencies; 274 var prefixes = dependencies.prefixes; 275 var lineSeparator = fileUtil.getLineSeparator(); 276 var copyrightText = fileUtil.readFile("copyright.txt"); 277 var buildNoticeText = fileUtil.readFile("build_notice.txt"); 278 279 //Find the dojo prefix path. Need it to process other module prefixes. 280 var dojoPrefixPath = buildUtil.getDojoPrefixPath(prefixes) + '/'; 281 282 logger.trace("Building dojo.js and layer files"); 283 var result = buildUtil.makeDojoJs(buildUtil.loadDependencyList(kwArgs.profileProperties), kwArgs.version); 284 285 //Save the build layers. The first layer is dojo.js. 286 var layerLegalText = copyrightText + buildNoticeText; 287 var dojoReleaseDir = kwArgs.releaseDir + "/dojo/"; 288 289 var optimizeIgnoreString = ""; 290 for(var i = 0; i < result.length; i++){ 291 var layerName = result[i].layerName; 292 var srcFilePath = dojoPrefixPath + result[i].layerName; 293 var dstFilePath = dojoReleaseDir + result[i].layerName; 294 var fileContents = result[i].contents; 295 296 // make sure directory exists 297 var dir = dstFilePath.substr(0,dstFilePath.lastIndexOf('/')); 298 var d = new java.io.File(dir); 299 d.mkdirs(); 300 301 //Build up string of files to ignore for the directory optimization step 302 var ignoreName = layerName.replace(/\.\.\//g, ""); 303 optimizeIgnoreString += (optimizeIgnoreString ? "|" : "") + buildUtil.regExpEscape(ignoreName) + "$"; 304 optimizeIgnoreString += "|" + buildUtil.regExpEscape(ignoreName + ".uncompressed.js") + "$"; 305 306 //Burn in xd path for dojo if requested, and only do this in dojo.xd.js. 307 if(layerName.match(/dojo\.xd\.js/) && kwArgs.xdDojoPath){ 308 fileContents = buildUtilXd.setXdDojoConfig(fileContents, kwArgs.xdDojoPath); 309 } 310 311 // Remove require statements, TODO: move this to build util? 312 fileContents = fileContents.replace( /(dojo|wti)\.require\(([\w\W]*?)\)/mg , ""); 313 314 //Flatten resources 315 //FIXME: Flatten resources. Only do the top level flattening for bundles 316 //in the layer files. How to do this for layers? only do one nls file for 317 //all layers, or a different one for each layer? 318 /* 319 if(layerName == "dojo.js"){ 320 i18nUtil.flattenLayerFileBundles(dstFilePath, dojoReleaseDir + "nls", "nls", kwArgs); 321 }*/ 322 323 //Save uncompressed file. 324 var uncompressedFilePath = dstFilePath + ".uncompressed.js"; 325 var uncompressedContents = layerLegalText + fileContents; 326 if(layerName.match(/\.xd\.js$/) && !layerName.match(/dojo(\.xd)?\.js/)){ 327 uncompressedContents = buildUtilXd.makeXdContents(uncompressedContents, prefixes); 328 } 329 fileUtil.saveFile(uncompressedFilePath, uncompressedContents); 330 331 //Intern strings if desired. Do this before compression, since, in the xd case, 332 //"dojo" gets converted to a shortened name. 333 if(kwArgs.internStrings){ 334 logger.info("Interning strings for file: " + dstFilePath); 335 var prefixes = dependencies["prefixes"] || []; 336 var skiplist = dependencies["internSkipList"] || []; 337 buildUtil.internTemplateStringsInFile(uncompressedFilePath, dojoReleaseDir, prefixes, skiplist); 338 339 //Load the file contents after string interning, to pick up interned strings. 340 fileContents = fileUtil.readFile(uncompressedFilePath); 341 } 342 343 //Save compressed file. 344 logger.trace("Optimizing (" + kwArgs.layerOptimize + ") file: " + dstFilePath); 345 var compressedContents = buildUtil.optimizeJs(dstFilePath, fileContents, layerLegalText, kwArgs.layerOptimize); 346 if(layerName.match(/\.xd\.js$/) && !layerName.match(/dojo(\.xd)?\.js/)){ 347 compressedContents = buildUtilXd.makeXdContents(compressedContents, prefixes); 348 } 349 fileUtil.saveFile(dstFilePath, compressedContents); 350 351 // Remove uncompressed file 352 fileUtil.deleteFile(uncompressedFilePath); 353 } 354 355 //Remove _base from the release. 356 fileUtil.deleteFile(dojoReleaseDir + "_base"); 357 fileUtil.deleteFile(dojoReleaseDir + "_base.js"); 358 359 360 //Save the dependency lists to build.txt 361 var buildText = "Files baked into this build:" + lineSeparator; 362 for(var i = 0; i < result.length; i++){ 363 buildText += lineSeparator + result[i].layerName + ":" + lineSeparator; 364 buildText += result[i].depList.join(lineSeparator) + lineSeparator; 365 } 366 fileUtil.saveFile(kwArgs.releaseDir + "/dojo/build.txt", buildText); 367 logger.info(buildText); 368 369 logger.info("Build is in directory: " + kwArgs.releaseDir); 370 } 371 //********* End release ********* 372 266 373 //********* Start _copyToRelease ********* 267 374 function _copyToRelease(/*String*/prefixName, /*String*/prefixPath, /*Object*/kwArgs){ 268 375 //summary: copies modules and supporting files from the prefix path to the release -
util/buildscripts/jslib/buildUtil.js
160 160 // string, but rather a Java string, which will cause the replace() method 161 161 // to bomb. 162 162 contents = contents ? new String(contents) : ""; 163 // clobber all comments 164 return contents.replace( /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg , ""); 163 164 // Properly remove comments 165 var context = Packages.org.mozilla.javascript.Context.enter(); 166 try{ 167 context.setOptimizationLevel(-1); 168 169 var fileName = java.lang.System.getProperty("java.io.tmpdir")+'/tmp.js'; 170 var script = context.compileString(contents, fileName, 1, null); 171 172 // Strip comments 173 contents = new String(context.decompileScript(script, 0)); 174 }finally{ 175 Packages.org.mozilla.javascript.Context.exit(); 176 } 177 178 return contents; 165 179 } 166 180 167 181 // over-write dojo.eval to prevent actual loading of subsequent files … … 170 184 var old_load = load; 171 185 load = function(uri){ 172 186 try{ 187 173 188 var text = removeComments((isWebBuild ? dojo._getText(uri) : fileUtil.readFile(uri))); 189 190 // Eval registrations so the loader knows where to get these resources 191 var register =new String(text.match(/OpenAjax.register\(([^)]*?)\)/)); 192 if(register) { 193 eval(register.replace(/[\s]*/g, '')); 194 } 195 174 196 var requires = dojo._getRequiresAndProvides(text); 175 197 eval(requires.join(";")); 176 198 dojo._loadedUrls.push(uri); … … 201 223 var deps = []; 202 224 var tmp; 203 225 RegExp.lastIndex = 0; 204 var testExp = / dojo.(require|platformRequire|provide)\([\w\W]*?\)/mg;226 var testExp = /(dojo|OpenAjax).(require|platformRequire|provide)\([\w\W]*?\)/mg; 205 227 while((tmp = testExp.exec(contents)) != null){ 206 228 deps.push(tmp[0]); 207 229 } … … 222 244 var deps = []; 223 245 var tmp; 224 246 RegExp.lastIndex = 0; 225 var testExp = / dojo.(requireAfterIf|requireIf)\([\w\W]*?\)/mg;247 var testExp = /(dojo|OpenAjax).(requireAfterIf|requireIf)\([\w\W]*?\)/mg; 226 248 while((tmp = testExp.exec(contents)) != null){ 227 249 deps.push(tmp[0]); 228 250 } … … 607 629 } 608 630 609 631 //The regular expressions that will help find dependencies in the file contents. 610 buildUtil.masterDependencyRegExpString = " dojo.(requireLocalization|require|requireIf|provide|requireAfterIf|platformRequire|i18n\._preloadLocalizations)\\(([\\w\\W]*?)\\)";632 buildUtil.masterDependencyRegExpString = "(dojo|OpenAjax).(requireLocalization|require|requireIf|provide|requireAfterIf|platformRequire|i18n\._preloadLocalizations)\\(([\\w\\W]*?)\\)"; 611 633 buildUtil.globalDependencyRegExp = new RegExp(buildUtil.masterDependencyRegExpString, "mg"); 612 634 buildUtil.dependencyPartsRegExp = new RegExp(buildUtil.masterDependencyRegExpString); 613 635