Merge pull request +9225 from c9/remove-npm-updater

Remove npm updater
pull/149/head
Harutyun Amirjanyan 2015-09-10 15:48:54 +04:00
commit cdc2f5bf41
2 zmienionych plików z 79 dodań i 78 usunięć

Wyświetl plik

@ -279,7 +279,7 @@ function getReqDeps(src, name) {
}); });
} }
function getAmdDeps(src, name) { function getAmdDeps(src, name) {
var m = src.match(/define\(\[[^\]]+\]/gm); var m = src.match(/define\(\s*\[[^\]]+\]/gm);
if (!m) if (!m)
return []; return [];
@ -360,12 +360,12 @@ function removeLicenceCommentsKeepLines(module) {
function wrapUMD(module) { function wrapUMD(module) {
if (module.loaderModule || module.noRequire) if (module.loaderModule || module.noRequire)
return; return;
var firstDefineCall = module.source.match(/define\([^)]*/); var firstDefineCall = module.source.match(/define\(\s*[^)]*/);
if (firstDefineCall) { if (firstDefineCall) {
// check if it is a normal define or some crazy umd trick // 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; return;
if (/define\(\[[^\]]*\],\s*function\(/.test(firstDefineCall[0])) if (/define\(\s*\[[^\]]*\],\s*function\(/.test(firstDefineCall[0]))
return; return;
} }
console.log("wrapping module " + module.id); console.log("wrapping module " + module.id);

Wyświetl plik

@ -43,6 +43,63 @@ define(function(require, exports, module) {
/***** Methods *****/ /***** 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 * List all packages on disk by scanning `~/.c9` and resolve the
* detected packages by order of override priority: * detected packages by order of override priority:
@ -134,16 +191,11 @@ define(function(require, exports, module) {
// check and load package.json // check and load package.json
var config = { var config = {
name: stat.name, name: stat.name,
path: absolutePath([ dirPath, stat.name ].join("/")), path: absolutePath([dirPath, stat.name].join("/")),
packagePath: [ "plugins", stat.name ].join("/"), packagePath: ["plugins", stat.name].join("/"),
staticPrefix: stat.href.replace(/\/$/, ""), staticPrefix: stat.href.replace(/\/$/, ""),
}; };
done(null, config);
loadPackageMetadata(config, function(err, metadata) {
if (err) return done(err);
config.metadata = metadata;
done(null, config);
});
}, callback); }, callback);
}); });
} }
@ -158,13 +210,7 @@ define(function(require, exports, module) {
* @param {Object} callback.metadata * @param {Object} callback.metadata
*/ */
function loadPackageMetadata(config, callback) { function loadPackageMetadata(config, callback) {
var paths = {}; fs.readfile([config.path, "package.json" ].join("/"), function(metadataStr) {
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) {
var metadata; var metadata;
try { try {
@ -195,7 +241,7 @@ define(function(require, exports, module) {
requirejs.config({ paths: paths }); requirejs.config({ paths: paths });
requirejs.undef([config.packagePath, "__installed__.js"].join("/")); requirejs.undef([config.packagePath, "__installed__.js"].join("/"));
require([[config.packagePath, "__installed__" ].join("/")], function(installed) { require([[config.packagePath, "__installed__"].join("/")], function(installed) {
callback(null, installed); callback(null, installed);
}, function(err) { }, function(err) {
callback(err); callback(err);
@ -212,12 +258,19 @@ define(function(require, exports, module) {
* @param {Error=} callback.err * @param {Error=} callback.err
*/ */
function loadPackage(config, callback) { function loadPackage(config, callback) {
loadPackageInstalledJs(config, function(err, installed) { loadPackageInstalledJs(config, function addToArchitect(err, installed) {
var plugins = installed; var plugins = installed;
if (err) { if (err) {
plugins = _.map(config.metadata.plugins, function(value, key) { return callback(err);
return [ "plugins", config.name, key ].join("/"); // 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) { var architectConfig = plugins.map(function(plugin) {
@ -234,6 +287,8 @@ define(function(require, exports, module) {
return plugin; return plugin;
}); });
names.push(config.name);
architect.loadAdditionalPlugins(architectConfig, function(err) { architect.loadAdditionalPlugins(architectConfig, function(err) {
callback(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) { function absolutePath(fromPath) {
var toPath = fromPath.replace(/^~/, c9.home); var toPath = fromPath.replace(/^~/, c9.home);
return toPath; return toPath;