Repository navigation
fix: keep the library entry free of a shebang - #1080
Closed
blueDaydreaming725 wants to merge 1 commit into
Closed
blueDaydreaming725 wants to merge 1 commit into
blueDaydreaming725 wants to merge 1 commit into
Conversation
Owner
|
@blueDaydreaming725 thank you so much for this PR. I'm sorry I didn't see it first, but just patched the issue here: #1082. It additionally bundles the cli outside the library. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1079
The library entry is also the CLI executable, so its bundle starts with a shebang. With Vite and
nodePolyfills({ include: ["buffer"], globals: { Buffer: true } }), injected imports move that line into the middle of the served module. The browser throws a SyntaxError beforeparse()can run.Build the existing library and CLI entry files separately, point the npm command at
dist/cli.cjs, and keep the executable header and permissions there. The library entry no longer has a shebang. This reuses the existing CLI implementation while preserving the library exports, config preload paths and directnode dist/index.cjsbehaviour. CLI tests now resolve the executable frompackage.jsonso they exercise the installed entry.The new regression compiles the built library inside a CommonJS wrapper and calls
parse(): the original bundle fails with a SyntaxError and the repaired bundle passes.npm testpasses (build, Standard, TypeScript declarations and TAP; the Windows-only test is skipped on macOS). The issue's Vite 8.3.5 / polyfills 0.28.0 reproduction was also checked in real headless Chrome against current upstream and the fix: SyntaxError before, both parsed values and no browser errors after. The generated tarball was also installed in a temporary project: the npm executable, environment loading, child exit status, CJS/ESM imports and config preload paths all work.Validated on macOS with Node 24. Native Windows/Linux and older Node versions were not run locally.