bgantzler / ember-mirage

Aids in setting up mirage for ember testing
MIT License
4 stars 5 forks source link

Explore if import.meta.glob can replace import boilerplate #25

Open NullVoxPopuli opened 8 months ago

NullVoxPopuli commented 8 months ago

babel plugin: https://www.npmjs.com/package/babel-plugin-transform-vite-meta-glob

cah-brian-gantzler commented 7 months ago

This would be used when reading ember-data models and auto creating mirage models. It would also be used in doing the same for serializers.

This auto generation was not included (opting for manual creation) because of the following reasons.

  1. Was not embroider compatible
  2. Models in ember-data are going to be deprecated. The replacement most likely would not be available at startup time. Its my understanding the concept of serializers will be implemented differently to the point it would not be auto generatable.
  3. Only works when your real backend models looks like your front end, (your not using serializers). Mirage is supposed to be simulating your backend. Any use of serializers causes your mirage generated models not work with your data requests. Mirage serializers need to be created for each ember-data serializer, (hence the addition of generating serializers). This just masks the issue.

The mentioned babel plugin really only solves problem 1. For 2 and 3, I have also heard that ember-data plans (via the cache) to implement a mirage like behavior in ember-data itself. This would also make this addon only used my people who dont use ember-data in the future, so supporting this functionality doesnt make sense in the long run.

Should we instead provide a code mod that creates all the mirage models and serializers that the addon consumer has now, then going forward the consumer would just create the models by hand (could always re-run the code mod). Creating models by hand hopefully would encourage them to create models that actually look like the backend. This would prevent the need to mirage serializers and would allow the ember-data serializers to work as intended.

NullVoxPopuli commented 4 months ago

Here is import.meta.glob for classic: https://github.com/NullVoxPopuli/ember-classic-import-meta-glob

I still need to add support for embroider and auto-import's allowAppImports, but it's closer