embroider-build / ember-auto-import

Zero config import from npm packages
Other
361 stars 110 forks source link

v2 addons are not bundled when listed in dependencies of lazy-loading engine (weirdo fix attached) #619

Open SergeAstapov opened 3 months ago

SergeAstapov commented 3 months ago

We found out a strange issue when v2 addons are used by engines https://github.com/villander/ember-engines-router-service/issues/67

Given

Result

any entries of v2 addon listed under addon.appReexports() in rollup.config.mjs file of the addon are not available for the engine.

Fix competing for "mystery award of the month"

@anehx somehow came up with a tiny change in v2 addon output that fixes things https://github.com/villander/ember-engines-router-service/issues/67#issuecomment-1253285115

Minimal reproduction

Here https://github.com/SergeAstapov/v2-addons-as-deps-of-lazy-engines-repro/commits/main/ I split steps to reproduce an issue and applying fix in commits:

  1. just creating a minimal test app: it boots and runs via ember s visiting http://localhost/
  2. checked in /dist folder so we see what goes into result (as it's tiniest app possible with ember-cli, there are not much going on)
  3. created a minimal test engine, and injected it into test app from step 1: engine boots and runs via ember s visiting http://localhost/test-lazy-engine
  4. created a minimal v2 addon that exports single tiny component: it's referenced in engine but it does not get bundled into /dist folder anywhere
  5. applied small patch via pnpm and now v2 addon code at least gets bundled into chunk.app and engine has proper re-export

Questions

tbh I'd love to find root cause and provide a fix but confused which area should actually be fixed:

  1. IMO, the patch even can be applied to @embroider/addon-dev itself as it's a real tiny change but seems it's not needed there
  2. is it ember-auto-import or even webpack responsible for v2 addon discovery and bundling? I would guess it's ember-auto-import missing something? but where I'm not sure, any clues appreciated.
  3. Should we just speak about elephant in the room and solely focus on Embroider? (I'm gonna extend my repro and create two branches testing what happens in case of .gts/.gjs files and in case of Embroider with .hbs)