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

Add cjs build alongside esm #51

Merged
merged 6 commits into from
Jan 28, 2025
Merged

Add cjs build alongside esm #51

merged 6 commits into from
Jan 28, 2025

Conversation

microbit-matt-hillsdon
Copy link
Contributor

@microbit-matt-hillsdon microbit-matt-hillsdon commented Jan 27, 2025

  • Introduced cjs build alongside (not bundled, unlike other Foundation projects)
  • Drop dapjs fork (on GitHub) by adding import workaround until they have exports support (which we can do a PR for soon)
  • Reluctantly use node10 module resolution to sidestep an issue with nrf-intel-hex (likely also fixed by introducing exports there)
    • Using NodeNext with type: module in this package causes the ESM build to fail with errors about MemoryMap being a namespace not a type. I think this is what the MemoryMap.default cludges we've had to remove were addressing.
      • I still don't entirely understand it. If you hack in type: module and the obvious exports into nrf-intel-hex then it builds cleanly so I think that's the best route forward but we'll need this in the interim.

We've verified that the built package can be consumed by our Vite builds, Vitest tests (which use Node) and a Webpack 5 project that mirrors code.org's configuration.

Because this cjs build depends on nrf-intel-hex we're also going to modernise microbit-fs to have a CJS build that doesn't bundle nrf-intel-hex.

Still seem to be issues for the integration I'm testing.
One to pick up with more motivation in the New Year!
This seems to be the simplest way to get ESM and CJS without throwing up issues
due to the intel hex library. It's more similar to microbit-fs.
Copy link

cloudflare-workers-and-pages bot commented Jan 28, 2025

Deploying microbit-connection with  Cloudflare Pages  Cloudflare Pages

Latest commit: f572847
Status: ✅  Deploy successful!
Preview URL: https://81730a3f.microbit-connection.pages.dev
Branch Preview URL: https://commonjs.microbit-connection.pages.dev

View logs

Copy link
Contributor

@microbit-robert microbit-robert left a comment

Choose a reason for hiding this comment

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

LGTM.

@microbit-matt-hillsdon microbit-matt-hillsdon merged commit f2714b6 into main Jan 28, 2025
2 checks passed
@microbit-matt-hillsdon microbit-matt-hillsdon deleted the commonjs branch January 28, 2025 17:05
microbit-grace pushed a commit to microbit-foundation/microbit-fs that referenced this pull request Jan 29, 2025
- Remove DeviceVersion exported const enum in favour of a union (breaking change due for code like `DeviceVersion.V1` but not expected to have wide impact. The values are unchanged.).
- Remove UMD build. Stop offering a browser oriented bundle.
    - If we know of any real-world script-tag-only users then I'm open to reinstating this but I'm really dubious it's worth it.
- CJS now uses dependencies rather than bundles to aid use alongside microbit-connection (avoiding duplicating nrf-intel-hex in that scenario).
- Fix ES module so it works with Node's ES module support (exports in package.json, .js file extensions on imports)
- Emit more modern JavaScript (ES2021, consistent with microbit-connection).
- Consolidate documentation into typedoc 
    - Move the markdown content into typedoc's build so we don't have separation and simplify
    - Drop the unmaintained theme
    - Move to GHA publishing it to GitHub pages
    - This is now simple enough I can imaging rolling it out to other libraries
- Update linting, TypeScript etc.
    - Intending to port most of this to typescript-library-starter, but hopefully using NodeNext there.
- Stuck on "node10" TypeScript bundleResolution for the same reason as microbit-foundation/microbit-connection#51

Other than DeviceVersion there's no code-level behaviour change but it's likely also a breaking change due to the ES2020 emit and the packaging changes so bumping version to 0.10.0. I think it should generally be easier to consume in modern projects while still working in CJS/webpack 5 type setups.
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.

2 participants