From 1de84e810d14d046f260be9eb07c774ca1673f62 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 8 Sep 2015 20:50:53 +0400 Subject: [PATCH 1/2] allow whitespace after define( --- node_modules/architect-build/module-deps.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node_modules/architect-build/module-deps.js b/node_modules/architect-build/module-deps.js index 107a4420..083429bd 100644 --- a/node_modules/architect-build/module-deps.js +++ b/node_modules/architect-build/module-deps.js @@ -279,7 +279,7 @@ function getReqDeps(src, name) { }); } function getAmdDeps(src, name) { - var m = src.match(/define\(\[[^\]]+\]/gm); + var m = src.match(/define\(\s*\[[^\]]+\]/gm); if (!m) return []; @@ -360,12 +360,12 @@ function removeLicenceCommentsKeepLines(module) { function wrapUMD(module) { if (module.loaderModule || module.noRequire) return; - var firstDefineCall = module.source.match(/define\([^)]*/); + var firstDefineCall = module.source.match(/define\(\s*[^)]*/); if (firstDefineCall) { // check if it is a normal define or some crazy umd trick - if (/define\(function\s*\(/.test(firstDefineCall[0])) + if (/define\(\s*function\s*\(/.test(firstDefineCall[0])) return; - if (/define\(\[[^\]]*\],\s*function\(/.test(firstDefineCall[0])) + if (/define\(\s*\[[^\]]*\],\s*function\(/.test(firstDefineCall[0])) return; } console.log("wrapping module " + module.id); From 9cfaadcdf80880ce37e91a21dc3f371b2449b45b Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 8 Sep 2015 22:38:00 +0400 Subject: [PATCH 2/2] do not break require path with config of disabled plugins --- plugins/c9.ide.plugins/loader.js | 149 ++++++++++++++++--------------- 1 file changed, 75 insertions(+), 74 deletions(-) diff --git a/plugins/c9.ide.plugins/loader.js b/plugins/c9.ide.plugins/loader.js index 95742ad0..6d8791af 100644 --- a/plugins/c9.ide.plugins/loader.js +++ b/plugins/c9.ide.plugins/loader.js @@ -43,6 +43,63 @@ define(function(require, exports, module) { /***** Methods *****/ + // TODO the resolution alghoritm used here is very inefficient + // ideally we will use a simpler method that doesn't need to scan directories + function loadPlugins(loaderConfig){ + if (!vfs.connected) { + vfs.once("connect", loadPlugins.bind(this, loaderConfig)); + return; + } + + if (!loaderConfig.length && !loadFromDisk) + return; + + listAllPackages(function(err, resolved) { + if (err) return console.error(err); + + var extraPackages = {}; + // convert old format from db to the new one + loaderConfig.forEach(function(p) { + if (!extraPackages[p.packageName]) { + var path = "plugins/" + p.packageName; + extraPackages[path] = { + apiKey: p.apiKey, + packagePath: path, + version: p.version, + name: p.packageName + }; + } + }); + if (!loadFromDisk) { + // filter packages by config instead of loading + // everything from disk + resolved = resolved.filter(function(config) { + if (extraPackages[config.packagePath]) + return true; + + console.warn("[c9.ide.loader] Not loading package " + + config.path + " because it is not installed, " + + "according to the database"); + return false; + }); + } + resolved.filter(function(config) { + if (extraPackages[config.packagePath]) + delete extraPackages[config.packagePath]; + }); + Object.keys(extraPackages).forEach(function(extraConfig) { + console.warn("[c9.ide.loader] Package " + + extraConfig.packagePath + " should be installed, according " + + "to the database, but was not found on the filesystem. " + + "Try reinstalling it."); + }); + + async.each(resolved, loadPackage, function(err) { + if (err) console.error(err); + }); + }); + } + /** * List all packages on disk by scanning `~/.c9` and resolve the * detected packages by order of override priority: @@ -134,16 +191,11 @@ define(function(require, exports, module) { // check and load package.json var config = { name: stat.name, - path: absolutePath([ dirPath, stat.name ].join("/")), - packagePath: [ "plugins", stat.name ].join("/"), + path: absolutePath([dirPath, stat.name].join("/")), + packagePath: ["plugins", stat.name].join("/"), staticPrefix: stat.href.replace(/\/$/, ""), }; - - loadPackageMetadata(config, function(err, metadata) { - if (err) return done(err); - config.metadata = metadata; - done(null, config); - }); + done(null, config); }, callback); }); } @@ -158,13 +210,7 @@ define(function(require, exports, module) { * @param {Object} callback.metadata */ function loadPackageMetadata(config, callback) { - var paths = {}; - paths[config.packagePath] = config.staticPrefix; - - requirejs.config({ paths: paths }); - requirejs.undef([config.packagePath, "package.json"].join("/")); - - require([("text!" + [config.packagePath, "package.json" ].join("/"))], function(metadataStr) { + fs.readfile([config.path, "package.json" ].join("/"), function(metadataStr) { var metadata; try { @@ -195,7 +241,7 @@ define(function(require, exports, module) { requirejs.config({ paths: paths }); requirejs.undef([config.packagePath, "__installed__.js"].join("/")); - require([[config.packagePath, "__installed__" ].join("/")], function(installed) { + require([[config.packagePath, "__installed__"].join("/")], function(installed) { callback(null, installed); }, function(err) { callback(err); @@ -212,12 +258,19 @@ define(function(require, exports, module) { * @param {Error=} callback.err */ function loadPackage(config, callback) { - loadPackageInstalledJs(config, function(err, installed) { + loadPackageInstalledJs(config, function addToArchitect(err, installed) { var plugins = installed; if (err) { - plugins = _.map(config.metadata.plugins, function(value, key) { - return [ "plugins", config.name, key ].join("/"); - }); + return callback(err); + // TODO disbled since this doesn't handle bundles and breaks debug=2 + // loadPackageMetadata(config, function(err, metadata) { + // if (err) return callback(err); + // config.metadata = metadata; + // var plugins = _.map(config.metadata.plugins, function(value, key) { + // return [ "plugins", config.name, key ].join("/"); + // }); + // addToArchitect(err, plugins); + // }); } var architectConfig = plugins.map(function(plugin) { @@ -234,6 +287,8 @@ define(function(require, exports, module) { return plugin; }); + + names.push(config.name); architect.loadAdditionalPlugins(architectConfig, function(err) { callback(err); @@ -241,60 +296,6 @@ define(function(require, exports, module) { }); } - function loadPlugins(loaderConfig){ - if (!vfs.connected) { - vfs.once("connect", loadPlugins.bind(this, loaderConfig)); - return; - } - - listAllPackages(function(err, resolved) { - if (err) return console.error(err); - - var extraPackages = {}; - // convert old format from db to the new one - loaderConfig.forEach(function(p) { - if (!extraPackages[p.packageName]) { - var path = "plugins/" + p.packageName; - extraPackages[path] = { - apiKey: p.apiKey, - packagePath: path, - version: p.version, - name: p.packageName - }; - } - }); - if (!loadFromDisk) { - // filter packages by config instead of loading - // everything from disk - resolved = resolved.filter(function(config) { - if (extraPackages[config.packagePath]) - return true; - - console.warn("[c9.ide.loader] Not loading package " - + config.path + " because it is not installed, " - + "according to the database"); - return false; - }); - } - resolved.filter(function(config) { - if (extraPackages[config.packagePath]) - delete extraPackages[config.packagePath]; - }); - Object.keys(extraPackages).forEach(function(extraConfig) { - console.warn("[c9.ide.loader] Package " - + extraConfig.packagePath + " should be installed, according " - + "to the database, but was not found on the filesystem. " - + "Try reinstalling it."); - }); - - names = _.pluck(resolved, "name"); - - async.each(resolved, loadPackage, function(err) { - if (err) console.error(err); - }); - }); - } - function absolutePath(fromPath) { var toPath = fromPath.replace(/^~/, c9.home); return toPath;