Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

GerHobbelt
Copy link

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!

- 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.
@GerHobbelt
Copy link
Author

BTW: comes including extra tests and adjusted README.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4fee2d3 on GerHobbelt:master into c8fc43d on hemanth:master.

}

function extractHashBang(text) {
const m = /^(#![^\r\n]+)/.exec(text.toString());
Copy link
Collaborator

@Richienb Richienb Aug 11, 2020

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.

index.js Show resolved Hide resolved
@@ -1,8 +1,8 @@
{
"name": "prepend-file",
"version": "1.3.1",
"name": "prepend-to-js-file",
Copy link
Collaborator

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.

Copy link
Author

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) {
Copy link
Collaborator

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:
Copy link
Collaborator

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.
Copy link
Collaborator

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.

@Richienb Richienb changed the title Recognize shebang in input file and append any text *after* the shebang: keep it intact Keep the shebang intact. Aug 11, 2020
@Richienb Richienb changed the title Keep the shebang intact. Keep the shebang intact Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When file has a shebang, it should be kept intact (just like the BOM prefix)
3 participants