Created
July 4, 2011 01:44
-
-
Save matthewfl/1062801 to your computer and use it in GitHub Desktop.
npm safe attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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