eternagame / EternaJS

Eterna game/RNA design interface
Other
12 stars 10 forks source link

Move from require to new URL with import.meta, update Jest to use ESM + config cleanup #752

Closed luxaritas closed 1 week ago

luxaritas commented 1 week ago

Summary

This PR does two related things (each of which is required for the other): 1) Instead of using require to synchronouosly get references to assets (triggering webpack to either inline the asset as a data URL or provide the dist output URL), we now use the pattern new URL(path, import.meta.url).href. This brings us in line with modern standards (ie, ESM, which we use everywhere else) and allows us to remove a linter exclusion 2) We update our Jest configuration to use ESM instead of CommonJS - again modernizing a bit. In order for Jest to use ESM we have to drop require, and in order to use import.meta.url we have to use the ESM module mode.

Implementation Notes

While I was here I also cleaned up a bit of the jest config that was duplicatous from its preset. Additionally importing from loglevel had to be changed to use a default import instead of a * import - it looks like due to commonjs interop it was wrapped with a default export twice.

This also requires Node's --experimental-vm-modules option which creates a bit of noise in the console (and could potentially make this a bit brittle if Node breaks backward compat somewhere), but felt this was the right way to go - we can backtrack if necessary, and if/when we migrate to vite/vitest that should be a nonissue.

Testing

Ran unit tests + launched puzzlemaker

Related Issues

Started using import.meta.url in #748 which broke tests - this resolves that