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

feature: shebang banner #957

Closed
wants to merge 1 commit into from
Closed

Conversation

huozhi
Copy link

@huozhi huozhi commented Jan 18, 2021

Use rolloup.output.banner to add shebang header into bundle. Resolves #338

Changes

  • add --bin flag
  • if bin is specified in package.json, output with shebang header

@vercel

This comment has been minimized.

@huozhi
Copy link
Author

huozhi commented Jan 18, 2021

not sure why it's failed with node 12 + macOS, I'm currently using those as my local development env and installation + tests are passed locally.. 😂

Copy link
Collaborator

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but this approach does not work -- per the comments in #338 , the central problem is that the dev/prod entry, index.js was not written as a Rollup plugin and as such is written out-of-band without knowledge of shebangs.
Per the in-line comments below, index.js, which is the bin entry is not changed and the tests do not check for it properly

The correct approach, as I wrote there, is to convert that to a Rollup plugin and do shebang detection as well (no need for a --bin flag, though it could potentially be useful for newbies). Shebang detection was also partially removed at some point in time.

The plugin I'm working on does both of these things

@@ -41,6 +41,13 @@ describe('tsdx build :: zero-config defaults', () => {
expect(output.code).toBe(0);
});

it('should add shebang', async () => {
const output = execWithCache('node ../dist/index.js build');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test shebangs, you'd want to exec . ./dist/index.js so that the shebang gets used

it('should add shebang', async () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
const matched = grep(/#!\/usr\/bin\/env/, ['dist/build-default.*.js']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't checking the most important file, index.js, which will not have it, which is why this PR will not work

@@ -5,6 +5,8 @@ interface SharedOpts {
tsconfig?: string;
// Is error extraction running?
extractErrors?: boolean;
// Is executive?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Is executive?
// Is executable?

"executive" means something different

@@ -52,6 +54,7 @@ export interface TsdxOptions extends SharedOpts {
export interface PackageJson {
name: string;
source?: string;
bin?: string | { [binary: string]: string };
Copy link
Collaborator

@agilgur5 agilgur5 Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be boolean like the docs and like transpileOnly

@agilgur5 agilgur5 added the solution: invalid This doesn't seem right label Jan 18, 2021
@agilgur5 agilgur5 closed this Jan 18, 2021
@huozhi
Copy link
Author

huozhi commented Jan 19, 2021

got it, thanks for clarifying @agilgur5

@huozhi
Copy link
Author

huozhi commented Jan 22, 2021

@agilgur5 is that ok to use rollup-plugin-preserve-shebang to implement this feature? I can file another PR for it if the idea is acceptable for you

@agilgur5
Copy link
Collaborator

@huozhi unfortunately that will run into the same issue, it won't fix the index.js file. You might notice from the codebase/repo that TSDX actually used it at one point (before it was partially removed).

The optimal solution is a good bit more complicated as it requires a nuanced Rollup plugin and refactoring several internals. I have a branch that does it, but haven't gotten around to testing it or prioritizing it (mostly because of issues written in my current status)

@huozhi
Copy link
Author

huozhi commented Jan 23, 2021

understood, manually generating index.js of cjs bundle is definitely a blocker for that solution. thanks for your patient explanation! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Insert bin prefix for script packages
2 participants