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

Switch to ESM where possible, publish release for @minecraft/math #49

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

rlandav
Copy link
Collaborator

@rlandav rlandav commented Jan 3, 2025

The core of this change is twofold:

  1. Switch to ESM everywhere possible, since we natively support ESM for JS in Minecraft. Previously, if using CommonJS, it forced unnatural patterns when being imported for use in MC.
  2. Add support for a new publish release task, and use it to publish releases for @minecraft/math which contain the pre-bundled script and declaration files.

The nuance is a bit trickier though, so as a guide for review.

  • Core build tasks was adjusted to output both CJS and ESM because of how it is used in build steps. Specifically, just.js can only ingest CJS modules and will be unable to process imports that are ESM only. So to deal with this, all just config files are given the .cts extension to make them explicitly parse as CJS, downstream packages are made into ESM (by specifying "type: module" in their package.json), and core-build-tasks pre-bundles some dependencies that are ESM only. This latter point is particularly important for the @octokit/rest package, which is used for interfacing with the github APIs but is ESM only.
  • For the new ESM packages, all imports now explicitly specify the .js extension. This is per recommendation of the latest typescript guidelines for ESM packages that are not always bundled. While we pre-bundle minecraft math, it is also expected that people will use the library as an import, and for compatibility with the broadest setups, specifying the file extension is most suitable.
  • Update ESLint to latest version. This needed updates to the rule creator and tests, and now the tests better integrate with vitest for better reporting.

These changes are major version bumps, and will later be integrated into the scripting starters.

to specify "type: module" in their package.json, and having the upstream
core-build-tasks package support both ESM and CJS due to just.js requiring
commonjs for the most part.

Also updates ESLint to latest, including flat configs, and updates the
rule tester for better integration with vitest.
dependencies from commonjs invocations. Add release publishing task to
core-build-tasks and integrate it into minecraft math so that the pre-built
bundle is included in releases. Integrate this release publish into the
release pipeline.
Copy link
Contributor

@SBLMikeDemone SBLMikeDemone left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple clarifying questions

tools/tsconfig/base.json Show resolved Hide resolved
libraries/math/package.json Show resolved Hide resolved
@rlandav
Copy link
Collaborator Author

rlandav commented Jan 9, 2025

Confirmed samples in minecraft-scripting-samples work properly with v2 of the core-build-tasks as well as with eslint 9 and the new ESM based minecraft/math.

@rlandav rlandav merged commit 55a4e19 into main Jan 9, 2025
2 checks passed
@rlandav rlandav deleted the rlanda/switchToESM branch January 9, 2025 19:23
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.

3 participants