node-hooks
Advanced tools
+95
-97
@@ -8,132 +8,130 @@ var fs = require("fs"); | ||
| var main = function(args){ | ||
| var main = function(args) { | ||
| var hook = args[0]; | ||
| var hook = args[0]; | ||
| var hooks = require("../lib/possible-hooks"); | ||
| var hooks = require("../lib/possible-hooks"); | ||
| if(hooks.indexOf(hook)==-1){ | ||
| console.error(hook.blue+" is not a valid git-hook".red); | ||
| process.exit(1); | ||
| } | ||
| if (hooks.indexOf(hook) == -1) { | ||
| console.error(hook.blue + " is not a valid git-hook".red); | ||
| process.exit(1); | ||
| } | ||
| fs.readFile("hooks.json", function(err, data){ | ||
| if(err){ | ||
| console.error("ERROR READING `hook.json`".red); | ||
| console.log(">> "+"Has hooks been merged into this branch?".blue); | ||
| process.exit(0); | ||
| } | ||
| else{ | ||
| var options; | ||
| fs.readFile("hooks.json", function(err, data) { | ||
| try{ | ||
| options = JSON.parse(data); | ||
| } | ||
| catch(err){ | ||
| console.error("ERROR PARSING `hook.json`".red, err); | ||
| process.exit(1); | ||
| } | ||
| if (err) { | ||
| console.error("ERROR READING `hook.json`".red); | ||
| console.log(">> " + "Has hooks been merged into this branch?".blue); | ||
| process.exit(0); | ||
| } else { | ||
| var options; | ||
| if(options[hook]!=undefined){ | ||
| queue(args, Object.keys(options[hook]), options[hook]); | ||
| } | ||
| } | ||
| try { | ||
| options = JSON.parse(data); | ||
| } catch (err) { | ||
| console.error("ERROR PARSING `hook.json`".red, err); | ||
| process.exit(1); | ||
| } | ||
| }); | ||
| if (options[hook] != undefined) { | ||
| queue(args, Object.keys(options[hook]), options[hook]); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| var queue = function(args, keys, commands){ | ||
| var queue = function(args, keys, commands) { | ||
| var key = keys[0]; | ||
| var key = keys[0]; | ||
| open(args, key, commands[key], function(err, exit_code){ | ||
| if(err){ | ||
| console.error("ERROR ENACTING `", key, "`", err); | ||
| process.exit(1); | ||
| } | ||
| else if(exit_code!=0){ | ||
| process.exit(exit_code); | ||
| } | ||
| open(args, key, commands[key], function(err, exit_code) { | ||
| if (err) { | ||
| console.error("ERROR ENACTING `", key, "`", err); | ||
| process.exit(1); | ||
| } else if (exit_code != 0) { | ||
| process.exit(exit_code); | ||
| } | ||
| keys = keys.slice(1); | ||
| keys = keys.slice(1); | ||
| if(keys.length==0){ | ||
| process.exit(0); | ||
| } | ||
| else{ | ||
| queue(keys, commands); | ||
| } | ||
| }); | ||
| if (keys.length == 0) { | ||
| process.exit(0); | ||
| } else { | ||
| queue(args, keys, commands); | ||
| } | ||
| }); | ||
| } | ||
| var open = function(args, name, path, callback){ | ||
| var folder = "node_modules/"+name; | ||
| fs.readFile(folder+"/package.json", function(err, data){ | ||
| if(err){ | ||
| fs.readFile(path+"/package.json", function(err, data){ | ||
| if(err){ | ||
| callback("CANNOT FIND `", name, "`"); | ||
| } | ||
| else{ | ||
| prep(args, data, path, callback); | ||
| } | ||
| }); | ||
| } | ||
| else{ | ||
| prep(args, data, folder, callback); | ||
| } | ||
| }); | ||
| var open = function(args, name, path, callback) { | ||
| var folder = "node_modules/" + name; | ||
| fs.readFile(folder + "/package.json", function(err, data) { | ||
| if (err) { | ||
| fs.readFile(path + "/package.json", function(err, data) { | ||
| if (err) { | ||
| callback("CANNOT FIND `", name, "`"); | ||
| } else { | ||
| prep(args, data, path, callback); | ||
| } | ||
| }); | ||
| } else { | ||
| prep(args, data, folder, callback); | ||
| } | ||
| }); | ||
| } | ||
| var prep = function(args, data, folder, callback){ | ||
| var options = undefined; | ||
| var prep = function(args, data, folder, callback) { | ||
| var options = undefined; | ||
| try{ | ||
| options = JSON.parse(data); | ||
| } | ||
| catch(err){ | ||
| callback(err); | ||
| } | ||
| try { | ||
| options = JSON.parse(data); | ||
| } catch (err) { | ||
| callback(err); | ||
| } | ||
| if(options){ | ||
| var file = options["main"] || "index.js"; | ||
| var type = options["hook-module"]!=undefined ? options["hook-module"]["script-type"] || "node" : "node"; | ||
| if (options) { | ||
| var file = options["main"] || "index.js"; | ||
| var type = options["hook-module"] != undefined ? options["hook-module"]["script-type"] || "node" : "node"; | ||
| enact(args, type, folder+"/"+file, callback); | ||
| } | ||
| enact(args, type, folder + "/" + file, callback); | ||
| } | ||
| } | ||
| var enact = function(args, type, file, callback){ | ||
| var enact = function(args, type, file, callback) { | ||
| var command = type == "shell" ? file : type; | ||
| var command = type == "shell" ? file : type; | ||
| var commandArgs = []; | ||
| if(command!=file){ | ||
| commandArgs.push(file); | ||
| } | ||
| var commandArgs = []; | ||
| if (command != file) { | ||
| commandArgs.push(file); | ||
| } | ||
| commandArgs = commandArgs.concat(args); | ||
| commandArgs = commandArgs.concat(args); | ||
| var hook = spawn(command, commandArgs); | ||
| hook.stderr.on("data", function(data){ | ||
| process.stderr.write(data); | ||
| }); | ||
| var hook = spawn(command, commandArgs); | ||
| hook.stdout.on("data", function(data){ | ||
| process.stdout.write(data); | ||
| }); | ||
| hook.stdin.on("data", function(data) { | ||
| process.stdin.write(data); | ||
| console.log("woot"); | ||
| }); | ||
| hook.on("error", function(err){ | ||
| console.error("HOOKS:", err.message); | ||
| }) | ||
| hook.stderr.on("data", function(data) { | ||
| process.stderr.write(data); | ||
| }); | ||
| hook.on("close", function(code){ | ||
| callback(undefined, code); | ||
| }); | ||
| hook.stdout.on("data", function(data) { | ||
| process.stdout.write(data); | ||
| }); | ||
| hook.on("error", function(err) { | ||
| console.error("HOOKS:", err.message); | ||
| }) | ||
| hook.on("close", function(code) { | ||
| callback(undefined, code); | ||
| }); | ||
| } | ||
| module.exports = main; |
+5
-1
@@ -1,1 +0,5 @@ | ||
| {} | ||
| { | ||
| "pre-commit": { | ||
| "beautify.hks": "0.0.1" | ||
| } | ||
| } |
+17
-9
@@ -5,11 +5,19 @@ { | ||
| "valid-for": [ | ||
| "post-merge", | ||
| "post-checkout" | ||
| ], | ||
| "sources": { | ||
| "npm": "pull-checkout-merge-command.hook", | ||
| "github": "https://github.com/mcwhittemore/pull-checkout-merge-command.hook/tarball/master" | ||
| }, | ||
| "author": "Matthew Chase Whittemore <mcwhittemore@gmail.com>" | ||
| "post-merge", | ||
| "post-checkout" | ||
| ], | ||
| "sources": { | ||
| "npm": "pull-checkout-merge-command.hook", | ||
| "github": "https://github.com/mcwhittemore/pull-checkout-merge-command.hook/tarball/master" | ||
| }, | ||
| "author": "Matthew Chase Whittemore <mcwhittemore@gmail.com>" | ||
| }, | ||
| "beautify.hks": { | ||
| "desc": "Beautify your javascript with each commit", | ||
| "valid-for": ["pre-commit"], | ||
| "sources": { | ||
| "npm": "beautify.hks" | ||
| }, | ||
| "author": "Matthew Chase Whittemore <mcwhittemore@gmail.com>" | ||
| } | ||
| } | ||
| } |
+3
-2
| { | ||
| "name": "node-hooks", | ||
| "version": "0.0.9", | ||
| "version": "0.0.10", | ||
| "preferGlobal": true, | ||
@@ -16,3 +16,4 @@ "description": "An NPM for git hooks.", | ||
| "mocha": "~1.12.0", | ||
| "should": "1.2.2" | ||
| "should": "1.2.2", | ||
| "beautify.hks": "0.0.1" | ||
| }, | ||
@@ -19,0 +20,0 @@ "scripts": { |
+6
-0
@@ -5,2 +5,4 @@ # Hooks | ||
|  | ||
| ## Terms | ||
@@ -136,1 +138,5 @@ | ||
| * Bug fix concerning adding npm data to the hooks.json file | ||
| ### 0.0.10 | ||
| * Bug fix concerning multiple hook-modules running from the same hook |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
54813
2.14%1457
0.69%141
4.44%25
-3.85%3
50%