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

Publish ESM-ready bundles of BCD #15916

Closed
queengooborg opened this issue Apr 20, 2022 · 6 comments · Fixed by #16232
Closed

Publish ESM-ready bundles of BCD #15916

queengooborg opened this issue Apr 20, 2022 · 6 comments · Fixed by #16232
Labels
infra 🏗️ Infrastructure issues (npm, GitHub Actions, releases) of this project

Comments

@queengooborg
Copy link
Collaborator

As the NodeJS realm transitions to ECMAScript Modules, we have been looking to do the same. We currently have a pull request open, #15775, that introduces ESM-compatible builds to the published version of browser-compat-data. We are not planning to break compatibility with existing setups -- that is, we will still maintain CommonJS support for existing consumers, whilst attempting to maintain compatibility across as many NodeJS versions as possible. Because of this, there will be one drawback:

ESM cannot import JSON, and so to ensure compatibility across NodeJS, Deno and browsers, we must double the size of the package.

We realize that this may put an additional burden upon our consumers, especially those with strict file size limitations. Before we proceed with this change, we would like to obtain feedback from our consumers.

@queengooborg queengooborg added the infra 🏗️ Infrastructure issues (npm, GitHub Actions, releases) of this project label Apr 20, 2022
@bershanskiy
Copy link
Contributor

Thanks for filing this and soliciting feedback.

We realize that this may put an additional burden upon our consumers, especially those with strict file size limitations.

This size increase is substantial, especially for a fundamental/deeply integrated package like BCD. Is it possible to publish two separate packages called browser-compat-data and, for example, browser-compat-data-esm? Then eventually consumers will migrate to browser-compat-data-esm and browser-compat-data could be eventually deprecated. I realize there is a risk of dependents failing to migrate (like happened with mdn-browser-compat-data), but please consider maintaining two separate packages and names until the entire ecosystem migrates to ESM.

@queengooborg
Copy link
Collaborator Author

Thank you for your feedback, this is exactly what I was looking for!

Ruth (@Rumyra) and I discussed this a little bit in a one-on-one, and releasing separate versions was one of the possibilities we had discussed. If at all possible though, I would love to provide some way that the raw JSON can still be accessible, such as for consumers using other languages (Python, C++, etc. -- especially as I'm one of such consumers), which has been a challenge considering that import assertions was only just released isn't available to all of the LTS NodeJS versions (at least, not yet). If it was, that'd solve all of the problems right there.

@queengooborg
Copy link
Collaborator Author

@antross @Fyrd @schalkneethling Do you guys have any feedback on this?

@queengooborg
Copy link
Collaborator Author

It looks like import assertions are available in NodeJS v16.15.0 and v17.5.0 (https://nodejs.org/api/esm.html#import-assertions), so I think it's safe for us to take advantage of it, perhaps? It would mean that we wouldn't support NodeJS v14 which is in LTS for the next year, though...

@schalkneethling
Copy link

@antross @Fyrd @schalkneethling Do you guys have any feedback on this?

@caugner is also working on getting Yari updated to ESM, so perhaps he will have some feedback here. Personally, I am just happy to see this work happening. Thanks, @queengooborg!

@queengooborg
Copy link
Collaborator Author

I figured out a solution that would allow for ESM imports on all NodeJS LTS versions without compromising on package size, which has been integrated into #16232! Basically, my solution is the following:

  • Main import: data.json, which can be imported using require() or imports with assertions
  • Sub import called 'NodeWrapper': a wrapper file for NodeJS v12 through v15 that will use fs and JSON.parse() to parse the data from data.json.

This way, all the data will remain in a single file, data.json, and will not be duplicated and increase the package's size!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra 🏗️ Infrastructure issues (npm, GitHub Actions, releases) of this project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants