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

Support Bundling with esbuild #19

Merged
merged 3 commits into from
Oct 4, 2022
Merged

Support Bundling with esbuild #19

merged 3 commits into from
Oct 4, 2022

Conversation

r-token
Copy link
Collaborator

@r-token r-token commented Sep 19, 2022

As mentioned in #18, esbuild fails to bundle this library (and other packages like hypercast-podcore-next that use this library) due to an issue in the batch dependency. This increases package/deployment sizes considerably.

I have forked the Batch repo, implemented the workaround, and published it as a standalone package scoped to my username. Those changes have been pulled into this repo. It should not introduce any breaking changes downstream.

The workaround implemented in my fork of the Batch repo simply changes this:

try {
  var EventEmitter = require('events').EventEmitter;
  if (!EventEmitter) throw new Error();
} catch (err) {
  var Emitter = require('emitter');
}

to this:

try {
  var EventEmitter = require('events').EventEmitter;
  if (!EventEmitter) throw new Error();
} catch (err) {
  try {
    var Emitter = require('emitter');
  } catch (err) {
    console.error('Unable to create an emitter')
    throw err
  }
}

You'll notice I now wrap the var Emitter = require('emitter'); line in a try/catch so that eslint doesn't complain when it sees that that emitter package does not exist and cannot resolve it. That is the extent of the changes.

If you can think of a better solution than using this forked version of Batch, I'm all for it. The main package hasn't been updated since April of 2021 though, so I don't think there's much risk in forking it and falling behind. Previous attempts by others to give it better bundler support have been declined by the maintainer.

Closes #18

@r-token
Copy link
Collaborator Author

r-token commented Sep 19, 2022

Don't merge this quite yet even if you're cool with it. I've submitted an issue and associated PR to the actual Batch repo that has already gotten the attention of the maintainer, so maybe we'll be able to get this fixed in the actual repo and use that.

@r-token
Copy link
Collaborator Author

r-token commented Sep 19, 2022

Update: they want to merge this in, hoping to do it either today or tomorrow.

Relevant comment from the maintainer: visionmedia/batch#43 (comment)

@r-token
Copy link
Collaborator Author

r-token commented Sep 29, 2022

My updates were merged into the main Batch repo with this commit. So Batch can now be built with esbuild!

All we need to do here is install the latest version of Batch and cut a new release of little-media-box that the serverless repo can update to.

@r-token
Copy link
Collaborator Author

r-token commented Oct 3, 2022

These changes were committed to GitHub via this commit.

I've updated little-media-box's package.json via this PR to use the latest version of Batch from GitHub, which includes these changes. That will allow us to build LMB with esbuild, drastically reducing package size.

I believe this is now ready to be merged and a new release can be cut @agrathwohl.

@agrathwohl agrathwohl merged commit daecdb4 into master Oct 4, 2022
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.

Support bundling with esbuild
2 participants