Ignore missing modules for r.js
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 16 Aug 2016 11:40:01 +0000 (13:40 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 16 Aug 2016 11:40:22 +0000 (13:40 +0200)
wcfsetup/install/files/js/require.build-acp.js
wcfsetup/install/files/js/require.build.js

index 3d48a52aed662b4f88fc7e18c62b9c465a0cb105..a897786073ffaadfb571378630385e6c12c7f79c 100644 (file)
@@ -1,51 +1,74 @@
-({
-       mainConfigFile: 'require.config.js',
-       name: "WoltLabSuite/_Meta",
-       out: "WCF.ACP.min.js",
-       useStrict: true,
-       preserveLicenseComments: false,
-       optimize: 'uglify2',
-       uglify2: {},
-       excludeShallow: [
-               'WoltLabSuite/_Meta'
-       ],
-       exclude: [
-               'WoltLabSuite/Core/Bootstrap'
-       ],
-       rawText: {
-               'WoltLabSuite/_Meta': 'define([], function() {});'
-       },
-       onBuildRead: function(moduleName, path, contents) {
-               if (!process.versions.node) {
-                       throw new Error('You need to run node.js');
-               }
-               
-               if (moduleName === 'WoltLabSuite/_Meta') {
-                       if (global.allModules == undefined) {
-                               var fs   = module.require('fs'),
-                                   path = module.require('path');
-                               global.allModules = [];
-                               
-                               var queue = ['WoltLabSuite/Core/Acp'];
-                               var folder;
-                               while (folder = queue.shift()) {
-                                       var files = fs.readdirSync(folder);
-                                       for (var i = 0; i < files.length; i++) {
-                                               var filename = path.join(folder, files[i]);
-                                               
-                                               if (path.extname(filename) == '.js') {
-                                                       global.allModules.push(filename);
-                                               }
-                                               else if (fs.statSync(filename).isDirectory()) {
-                                                       queue.push(filename);
+(function () {
+       var config;
+       config = {
+               mainConfigFile: 'require.config.js',
+               name: "WoltLabSuite/_Meta",
+               out: "WCF.ACP.min.js",
+               useStrict: true,
+               preserveLicenseComments: false,
+               optimize: 'uglify2',
+               uglify2: {},
+               excludeShallow: [
+                       'WoltLabSuite/_Meta'
+               ],
+               exclude: [
+                       'WoltLabSuite/Core/Bootstrap'
+               ],
+               rawText: {
+                       'WoltLabSuite/_Meta': 'define([], function() {});'
+               },
+               onBuildRead: function(moduleName, path, contents) {
+                       if (!process.versions.node) {
+                               throw new Error('You need to run node.js');
+                       }
+                       
+                       if (moduleName === 'WoltLabSuite/_Meta') {
+                               if (global.allModules == undefined) {
+                                       var fs   = module.require('fs'),
+                                           path = module.require('path');
+                                       global.allModules = [];
+                                       
+                                       var queue = ['WoltLabSuite/Core/Acp'];
+                                       var folder;
+                                       while (folder = queue.shift()) {
+                                               var files = fs.readdirSync(folder);
+                                               for (var i = 0; i < files.length; i++) {
+                                                       var filename = path.join(folder, files[i]);
+                                                       
+                                                       if (path.extname(filename) == '.js') {
+                                                               global.allModules.push(filename);
+                                                       }
+                                                       else if (fs.statSync(filename).isDirectory()) {
+                                                               queue.push(filename);
+                                                       }
                                                }
                                        }
                                }
+                               
+                               return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
                        }
                        
-                       return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
+                       return contents;
+               }
+       };
+       
+       var _isSupportedBuildUrl = require._isSupportedBuildUrl;
+       require._isSupportedBuildUrl = function (url) {
+               var result = _isSupportedBuildUrl(url);
+               if (!result) return result;
+               if (Object.keys(config.rawText).map(function (item) { return process.cwd() + '/' + item + '.js'; }).indexOf(url) !== -1) return result;
+
+               var fs = module.require('fs');
+               try {
+                       fs.statSync(url);
+               }
+               catch (e) {
+                       console.log('Unable to find module:', url, 'ignoring.');
+
+                       return false;
                }
-               
-               return contents;
-       }
-});
+               return true;
+       };
+
+       return config;
+})();
index e3f2c1d4b2cfa23cec778a56d9c4debd4cf3bee6..a469ff3c3baf34f07734ac00cfc9d7585bb984a5 100644 (file)
@@ -1,62 +1,85 @@
-({
-       mainConfigFile: 'require.config.js',
-       name: "WoltLabSuite/_Meta",
-       out: "WCF.Core.min.js",
-       useStrict: true,
-       preserveLicenseComments: false,
-       optimize: 'uglify2',
-       uglify2: {},
-       paths: {
-               "requireLib": "require",
-               
-               "jquery": "empty:"
-       },
-       deps: [
-               "require.config",
-               "wcf.globalHelper"
-       ],
-       include: [
-               "requireLib",
-               "require.linearExecution"
-       ],
-       excludeShallow: [
-               'WoltLabSuite/_Meta'
-       ],
-       rawText: {
-               'WoltLabSuite/_Meta': 'define([], function() {});'
-       },
-       onBuildRead: function(moduleName, path, contents) {
-               if (!process.versions.node) {
-                       throw new Error('You need to run node.js');
-               }
-               
-               if (moduleName === 'WoltLabSuite/_Meta') {
-                       if (global.allModules == undefined) {
-                               var fs   = module.require('fs'),
-                                   path = module.require('path');
-                               global.allModules = [];
-                               
-                               var queue = ['WoltLabSuite'];
-                               var folder;
-                               while (folder = queue.shift()) {
-                                       var files = fs.readdirSync(folder);
-                                       for (var i = 0; i < files.length; i++) {
-                                               var filename = path.join(folder, files[i]);
-                                               if (filename === 'WoltLabSuite/Core/Acp') continue;
-                                               
-                                               if (path.extname(filename) == '.js') {
-                                                       global.allModules.push(filename);
-                                               }
-                                               else if (fs.statSync(filename).isDirectory()) {
-                                                       queue.push(filename);
+(function () {
+       var config;
+       config = {
+               mainConfigFile: 'require.config.js',
+               name: "WoltLabSuite/_Meta",
+               out: "WCF.Core.min.js",
+               useStrict: true,
+               preserveLicenseComments: false,
+               optimize: 'uglify2',
+               uglify2: {},
+               paths: {
+                       "requireLib": "require",
+                       
+                       "jquery": "empty:"
+               },
+               deps: [
+                       "require.config",
+                       "wcf.globalHelper"
+               ],
+               include: [
+                       "requireLib",
+                       "require.linearExecution"
+               ],
+               excludeShallow: [
+                       'WoltLabSuite/_Meta'
+               ],
+               rawText: {
+                       'WoltLabSuite/_Meta': 'define([], function() {});'
+               },
+               onBuildRead: function(moduleName, path, contents) {
+                       if (!process.versions.node) {
+                               throw new Error('You need to run node.js');
+                       }
+                       
+                       if (moduleName === 'WoltLabSuite/_Meta') {
+                               if (global.allModules == undefined) {
+                                       var fs   = module.require('fs'),
+                                           path = module.require('path');
+                                       global.allModules = [];
+                                       
+                                       var queue = ['WoltLabSuite'];
+                                       var folder;
+                                       while (folder = queue.shift()) {
+                                               var files = fs.readdirSync(folder);
+                                               for (var i = 0; i < files.length; i++) {
+                                                       var filename = path.join(folder, files[i]);
+                                                       if (filename === 'WoltLabSuite/Core/Acp') continue;
+                                                       
+                                                       if (path.extname(filename) == '.js') {
+                                                               global.allModules.push(filename);
+                                                       }
+                                                       else if (fs.statSync(filename).isDirectory()) {
+                                                               queue.push(filename);
+                                                       }
                                                }
                                        }
                                }
+                               
+                               return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
                        }
                        
-                       return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
+                       return contents;
+               }
+       };
+       
+       var _isSupportedBuildUrl = require._isSupportedBuildUrl;
+       require._isSupportedBuildUrl = function (url) {
+               var result = _isSupportedBuildUrl(url);
+               if (!result) return result;
+               if (Object.keys(config.rawText).map(function (item) { return process.cwd() + '/' + item + '.js'; }).indexOf(url) !== -1) return result;
+
+               var fs = module.require('fs');
+               try {
+                       fs.statSync(url);
+               }
+               catch (e) {
+                       console.log('Unable to find module:', url, 'ignoring.');
+
+                       return false;
                }
-               
-               return contents;
-       }
-});
+               return true;
+       };
+
+       return config;
+})();