Ticket #2696: build.3.patch

File build.3.patch, 12.5 kB (added by guest, 16 months ago)

OpenAjax? patch + fixes for YUI and add support for loading other resources like css?

  • dojo/_base/_loader/bootstrap.js

     
    9797dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){ 
    9898        var obj=context||dojo.global; 
    9999        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)); 
    101101        } 
    102102        return obj; // Any 
    103103} 
     
    219219=====*/ 
    220220 
    221221// vim:ai:ts=4:noet 
     222if(typeof dojo.global.OpenAjax == "undefined") { 
     223        OpenAjax = dojo; 
     224} 
     225OpenAjax._resourceToUri = {}; 
     226OpenAjax.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

     
    253253 
    254254dojo._loadModule = function(    /*String*/moduleName,  
    255255                                                                /*Boolean?*/exactOnly,  
    256                                                                 /*Boolean?*/omitModuleCheck){ 
     256                                                                /*Boolean?*/omitModuleCheck, 
     257                                                                /*String*/resourceType){ 
    257258        //      summary: 
    258259        //              loads a Javascript module from the appropriate URI 
    259260        //      description: 
     
    283284        //       
    284285        //              dj_load is an alias for dojo._loadModule 
    285286 
     287        moduleType = resourceType || '.js' 
     288         
    286289        omitModuleCheck = this._global_omit_module_check || omitModuleCheck; 
     290 
    287291        var module = this._loadedModules[moduleName]; 
    288292        if(module){ 
    289293                return module; 
    290294        } 
    291295 
    292         // convert periods to slashes 
    293         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]; 
    297296        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                        } 
    306316                } 
    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                } 
    310339        } 
    311340        var modArg = (!omitModuleCheck) ? moduleName : null; 
    312         var ok = this._loadPath(relpath, modArg); 
     341        var ok = false; 
    313342 
     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 
    314349        if((!ok)&&(!omitModuleCheck)){ 
    315350                throw new Error("Could not load '" + moduleName + "'; last tried '" + relpath + "'"); 
    316351        } 
    317352 
    318353        // check that the symbol was defined 
    319354        // Don't bother if we're doing xdomain (asynchronous) loading. 
    320         if((!omitModuleCheck)&&(!this["_isXDomain"])){ 
     355        if(moduleType == '.js' && (!omitModuleCheck)&&(!this["_isXDomain"])){ 
    321356                // pass in false so we can give better error 
    322357                module = this._loadedModules[moduleName]; 
    323358                if(!module){ 
     
    328363        return module; 
    329364} 
    330365 
    331 dojo.require = dojo._loadModule; 
     366dojo.require = function(resourceId, resourceType) { 
     367        return dojo._loadModule(resourceId, null, null, resourceType); 
     368}; 
    332369 
    333370dojo.provide = function(/*String*/ packageName){ 
    334371        //      summary: 
  • util/buildscripts/build.js

     
    263263} 
    264264//********* End release ********* 
    265265 
     266//********* Start Minimal ********* 
     267function 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 
    266373//********* Start _copyToRelease ********* 
    267374function _copyToRelease(/*String*/prefixName, /*String*/prefixPath, /*Object*/kwArgs){ 
    268375        //summary: copies modules and supporting files from the prefix path to the release 
  • util/buildscripts/jslib/buildUtil.js

     
    160160                                // string, but rather a Java string, which will cause the replace() method 
    161161                                // to bomb. 
    162162                                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; 
    165179                        } 
    166180                         
    167181                        // over-write dojo.eval to prevent actual loading of subsequent files 
     
    170184                        var old_load = load; 
    171185                        load = function(uri){ 
    172186                                try{ 
     187                                         
    173188                                        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                                         
    174196                                        var requires = dojo._getRequiresAndProvides(text); 
    175197                                        eval(requires.join(";")); 
    176198                                        dojo._loadedUrls.push(uri); 
     
    201223                                var deps = []; 
    202224                                var tmp; 
    203225                                RegExp.lastIndex = 0; 
    204                                 var testExp = /dojo.(require|platformRequire|provide)\([\w\W]*?\)/mg; 
     226                                var testExp = /(dojo|OpenAjax).(require|platformRequire|provide)\([\w\W]*?\)/mg; 
    205227                                while((tmp = testExp.exec(contents)) != null){ 
    206228                                        deps.push(tmp[0]); 
    207229                                } 
     
    222244                                var deps = []; 
    223245                                var tmp; 
    224246                                RegExp.lastIndex = 0; 
    225                                 var testExp = /dojo.(requireAfterIf|requireIf)\([\w\W]*?\)/mg; 
     247                                var testExp = /(dojo|OpenAjax).(requireAfterIf|requireIf)\([\w\W]*?\)/mg; 
    226248                                while((tmp = testExp.exec(contents)) != null){ 
    227249                                        deps.push(tmp[0]); 
    228250                                } 
     
    607629} 
    608630 
    609631//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]*?)\\)"; 
     632buildUtil.masterDependencyRegExpString = "(dojo|OpenAjax).(requireLocalization|require|requireIf|provide|requireAfterIf|platformRequire|i18n\._preloadLocalizations)\\(([\\w\\W]*?)\\)"; 
    611633buildUtil.globalDependencyRegExp = new RegExp(buildUtil.masterDependencyRegExpString, "mg"); 
    612634buildUtil.dependencyPartsRegExp = new RegExp(buildUtil.masterDependencyRegExpString); 
    613635