Skip to content

Instantly share code, notes, and snippets.

@matthewfl
Created July 4, 2011 01:44
Show Gist options
  • Save matthewfl/1062801 to your computer and use it in GitHub Desktop.
Save matthewfl/1062801 to your computer and use it in GitHub Desktop.
npm safe attempt
npm.load({}, function (err) {
//npm.commands.build = console.log; // failed because no setter was set
//npm.commands['run-script'] = console.log;
//Object.defineProperty(npm.commands, "build", { get: function () { return console.log; }}); // could not redefine the property
//Object.defineProperty(npm.commands, "run-script", { value: console.log });
// seems to work, but crashes after some point in the process
var original_npm = npm.commands;
npm.commands = {}; // more hacks, to make npm safe
for(var c in original_npm) {
(function (c) {
Object.defineProperty(npm.commands, c, { get : function () {
console.log("=======================================================================loading command", c);
if(c == "build" || c == "run-script")
return console.log;
return function () {
console.log.apply(this, arguments);
original_npm[c].apply(this, arguments);
};
}});
})(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment