Skip to content

Commit

Permalink
fix(hook): handle node module path os agnostically (#114)
Browse files Browse the repository at this point in the history
* fix(hook): detemine hook name path separator agnostically

Former `hook` name determination was a simple regex using *nix style path separator `/`, using `path.basename`, the required last part gets returned, independent of an os specific path separator.

* fix(hook): correctly escape rendered `node_modules_path` string
  • Loading branch information
ta2edchimp authored and Kent C. Dodds committed Jul 4, 2016
1 parent 32edf9c commit 26b5fa7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/hook.template.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const fs = require('fs')
const resolve = require('path').resolve
const path = require('path')
const {resolve, join} = require('path')

exports.generatedMessage = 'Generated by ghooks. Do not edit this file.'

exports.content = fs
.readFileSync(resolve(`${__dirname}/hook.template.raw`), 'UTF-8')
.replace('{{generated_message}}', exports.generatedMessage)
.replace('{{node_modules_path}}', path.join(process.cwd(), '..'))
.replace('{{node_modules_path}}', join(process.cwd(), '..').replace(/\\/g, '\\'))
4 changes: 2 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const clone = require('lodash.clone')
const managePath = require('manage-path')
const spawn = require('spawn-command')
const resolve = require('path').resolve
const {resolve, basename} = require('path')
const findup = require('findup')
const fs = require('fs')

Expand All @@ -13,7 +13,7 @@ module.exports = function run(nodeModulesPath, filename, env) {
}

function hook(filename) {
return filename.match(/\/([^\/]+)\/?$/)[1]
return basename(filename)
}

// replace any instance of $1 or $2 etc. to that item as an process.argv
Expand Down

0 comments on commit 26b5fa7

Please sign in to comment.