Stricter typing, prevent force exit of systems, return string for base64 encoding etc #231
+320
−84
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.
Goal
Primary goal is to fix the issue where base64 strings incorrectly gets wrapped within a Buffer object.
On top of that providing some additional fixes with the typing to make the user experience better.
I did also notice that apps exit with code 1 (error). This would be a problem for most use cases of the library and therefore removed this from the catch clause of the function call.
To futher increase the user experience also added JS Doc for the exposed function, to give code editors context on the function and what parameters mean what.
Related issue
This PR does not only fix some issues that I have ran into, but after reviewing the code also found some other pitfalls which I have fixed.
#230
Issue raised by me regarding the base64 string issue, where it is always wrapped in a Buffer object instead of returning the base64 string similar to v4 of node-html-to-image
#228
Issue describing that the exposed
nodeHtmlToImagefunction is missing handlebarsHelpers. In order to provide handlebarsHelpers you have to pass it without typing and mark it as i.e@ts-expect-error.#165 | #221
These issues both describe an issue where they are unable to handle try-catch. This is due to the process.exit(1) leading a force close of the parent process.
Changes
rimrafpackage since the current one didn't include typing declarations, but never versions does"--no-sandbox"option topuppeteerArgs.argswithin all test cases since a lot of systems and enclosed systems doesn't support this sandboxing environment. The processed data is test case controlled and therefore safe either way so no negatives for the test casesstring | Buffer | (string | Buffer)[]. Now it will be one of the following and always only one which is declared via the provided options payload:string,Buffer,string[],Buffer[]nodeHtmlToImage), leading to easier use for end usersThank you for providing us all this open source library!
Best regards and wishes,
Yazaar / Jesper