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

Migrate Deno Bundle to ESbuild #71

Merged
merged 13 commits into from
Oct 26, 2023
Merged

Conversation

WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Oct 20, 2023

Summary

This PR aims to improve the behavior of the build hooks by adding a fallback to esbuild if deno bundle fails.

Testing

  1. Create a new sample application with the CLI
  2. Pull this branch migrate-deno-run-bundle
  3. add the following to the slack.json file
"build": "deno run -q --config=deno.jsonc --allow-read --allow-write --allow-net --allow-run --allow-env path/to/local/src/build.ts",
  1. Run slack deploy -vv
  2. Everything should work as expected with deno bundle
  3. In src/build.ts above line 81 add throw new BundleError() (this will force a fallback to esbuild)
  4. Run slack deploy in your app folder
  5. You should see this warning when executing Failed bundling with 'Deno Bundle' falling back to esbuild
  6. Bundling should work

Feedback

  • General code cleanliness, it was tricky to figure out when errors should be raised
  • User experience, should we warn the user that their app falls back to esbuild?
  • If the esbuild bundle fails should we mention to the user that first the deno bundle failed and then the esbuild failed or mention bundling failed?

Requirements

@WilliamBergamin WilliamBergamin added the enhancement New feature or request label Oct 20, 2023
@WilliamBergamin WilliamBergamin self-assigned this Oct 20, 2023
src/build.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

Merging #71 (d9277a8) into main (949bee3) will increase coverage by 2.04%.
The diff coverage is 90.21%.

@@            Coverage Diff             @@
##             main      #71      +/-   ##
==========================================
+ Coverage   75.20%   77.24%   +2.04%     
==========================================
  Files          12       16       +4     
  Lines         746      813      +67     
  Branches      104      111       +7     
==========================================
+ Hits          561      628      +67     
  Misses        182      182              
  Partials        3        3              
Files Coverage Δ
src/bundler/deno_bundler.ts 100.00% <100.00%> (ø)
src/bundler/esbuild_bundler.ts 100.00% <100.00%> (ø)
src/bundler/mods.ts 100.00% <100.00%> (ø)
src/deps.ts 100.00% <100.00%> (ø)
src/errors.ts 100.00% <100.00%> (ø)
src/build.ts 62.99% <76.92%> (+4.58%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor Author

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

An area of worry

const result = await esbuild.build({
entryPoints: [options.entrypoint],
platform: "neutral",
target: "deno1", // TODO: the versions should come from the user defined input
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Esbuild requires a deno version for the target value, currently the user is not able to specify the version their app should run on. Once they are able to, I believe the version they specify should be used here

@WilliamBergamin WilliamBergamin marked this pull request as ready for review October 25, 2023 13:59
@WilliamBergamin WilliamBergamin requested a review from a team as a code owner October 25, 2023 13:59
src/build.ts Outdated Show resolved Hide resolved
Copy link

@filmaj filmaj left a comment

Choose a reason for hiding this comment

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

Ran through the testing steps with the request-time-off app, works well! Something interesting I noticed re: the request-time-off app: the bundle size with Deno.bundle is 17kb and took 1.9 seconds to bundle. With esbuild, it ended up being 19kb and took 1.4 seconds.

I also tried it with my more involved / complex app interactive-approval app. esbuild increased the size by 2kb but the build time went from 1.1 seconds to 0.5 seconds!

This makes sense to me as I've heard esbuild is extremely fast. So, that's a nice thing here!

Very nicely done here, I left a few comments but you did an excellent job, especially with the tests. 💯

src/build.ts Outdated Show resolved Hide resolved
src/build.ts Show resolved Hide resolved
output: () => Promise.resolve({ code: 0 }),
} as Deno.Command;

// Stub out call to `Deno.Command` and fake return a success
Copy link

Choose a reason for hiding this comment

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

Nice!

Deno.test("Deno Bundler tests", async (t) => {
await t.step(DenoBundler.bundle.name, async (tt) => {
await tt.step(
"should invoke 'deno bundle' successfully",
Copy link

Choose a reason for hiding this comment

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

Technically we are not testing whether bundle is invoked here, we are testing whether Deno.Command was invoked. I think we may want to assert on the arguments passed into the Command stub to make sure it is bundle - assuming that's the right hypothesis we are testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, Ive added argument validation 💯

Promise.resolve({
code: 1,
stderr: new TextEncoder().encode(
"error: unrecognized subcommand 'bundle'",
Copy link

Choose a reason for hiding this comment

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

Love it

src/bundler/deno_bundler.ts Outdated Show resolved Hide resolved
src/bundler/esbuild_bundler.ts Outdated Show resolved Hide resolved
@WilliamBergamin WilliamBergamin merged commit a7c7cd6 into main Oct 26, 2023
3 checks passed
@WilliamBergamin WilliamBergamin deleted the migrate-deno-run-bundle branch October 26, 2023 15:55
@WilliamBergamin WilliamBergamin added the semver:minor requires a minor version number bump label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver:minor requires a minor version number bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants