-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep the shebang intact #16
base: master
Are you sure you want to change the base?
Conversation
…bang-carrying input files.
…g, IFF the file has any. This fixes silesky/prepend-header#5
- clean up *before* rather than *after*: we want to *start* clean, if we leave a bit of stuff for post-test scrutiny that's okay. Anyway, had a couple of nasty surprises by crashing tests and the *after* code not working, anyway.
BTW: comes including extra tests and adjusted README. |
} | ||
|
||
function extractHashBang(text) { | ||
const m = /^(#![^\r\n]+)/.exec(text.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use more descriptive variable names.
@@ -1,8 +1,8 @@ | |||
{ | |||
"name": "prepend-file", | |||
"version": "1.3.1", | |||
"name": "prepend-to-js-file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do unrelated changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the PR:
Hence you might want to cherry-pick instead of executing a straight merge of this work.
😉
Didn't have enough time to do a cleaned-up PR, alas.
test.after.always(async () => { | ||
await fsP.unlink(temporaryFile); | ||
await fsP.unlink(syncTemporaryFile); | ||
function ignoreFailure(f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably just use https://www.npmjs.com/package/del.
await prependFile(shebangTemporaryFile, Buffer.from('Yes ')); | ||
t.is(await fsP.readFile(shebangTemporaryFile, 'utf8'), '#! /bin/shebang\n\nYes Hello World'); | ||
|
||
// `prependFile()` does not recognize a BOM in the part to be appended, so we test BOM-prefixed files by using afresh one here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment won't be necessary.
@@ -1,6 +1,8 @@ | |||
# prepend-file [![Build Status][travis-image]][travis-url] [![Code Coverage][coveralls-image]][coveralls-url] | |||
|
|||
> Prepend data to a file, creating it if it doesn't exist. | |||
> | |||
> When the file (*to be prepended to*) has [a 'hash bang' a.k.a. *shebang* command](https://en.wikipedia.org/wiki/Shebang_(Unix)) at the first line, this will be kept intact. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be an option.
Same as for the UTF8 BOM recognition, only this time for
#!xyz...
shebangs.This was needed to fix silesky/prepend-header#5 -- I don't know if you like to incorporate this new behaviour in your module, so I forked the repo and created another npm package:
prepend-to-js-file
by renaming this one.Hence you might want to cherry-pick instead of executing a straight merge of this work.
Thanks!