zengm-games / zengm

Basketball GM (and other ZenGM games) are single-player sports management simulation games, made entirely in client-side JavaScript.
https://zengm.com
Other
349 stars 127 forks source link

update esbuild to work with babel #448

Closed ldrobner closed 1 year ago

ldrobner commented 1 year ago

Summary

It was noticed that errors were being improperly reported when trying to debug the code. This was due to an issue with the esbuild configuration, and the babel plugin callbacks used during bundling.

See the discussion here


Description

  1. It was noticed that any files that used babel to inline bySport or isSport configurations were being listed as unknown in the debugger. It was also noticed that these babel transformed files were unlisted within the debugger.

    To solved this issue, a onResolve callback was added to the esbuild plugin function defined in the configuration.


  1. Once the onResolve callback was added, we needed to make sure that the files being filtered by the callback were transformed properly.

    To solve this problem, we added a namespace field to the onResolve callback result, and filtered files that passed through the onLoad callback to files within the namespace set during onResolve.


  1. Finally, as good practice, dead code was removed from the onLoad callback.

    Now that only certain files were being passed through the onLoad callback, we no longer need to check if the file should be babel transformed. We removed logic to filter out files to be transformed or not, since the only files coming through to the onLoad callback need to be transformed.


Continuing the Discussion