Skip to content

Commit

Permalink
chore: add some comments and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jun 21, 2022
1 parent 7963ab5 commit 0a351e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ Functionally, this means:
hook scripts, then they can override the default package script with an
explicit `cmd` option pointing to the `node_modules/.hook/${event}`
script.

## Escaping

In order to ensure that arguments are handled consistently, this module
writes a temporary script file containing the command as it exists in
the package.json, followed by the user supplied arguments having been
escaped to ensure they are processed as literal strings. We then instruct
the shell to execute the script file, and when the process exits we remove
the temporary file.

The actual implementation of the escaping is in `lib/escape.js`.
2 changes: 2 additions & 0 deletions lib/escape.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

// eslint-disable-next-line max-len
// this code adapted from: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
const cmd = (input) => {
if (!input.length) {
return '""'
Expand Down

0 comments on commit 0a351e9

Please sign in to comment.