jmurphyau / ember-truth-helpers

Ember HTMLBars Helpers for {{if}} & {{unless}}: not, and, or, eq & is-array
MIT License
706 stars 95 forks source link

Importing from package root does not work in classic builds + `.gts` #206

Open chancancode opened 6 months ago

chancancode commented 6 months ago

This is really https://github.com/embroider-build/ember-auto-import/issues/611, but opening an issue here for visibility

In a classic app build with .gts, this works:

import and from 'ember-truth-helpers/helpers/and';

export default <template>{{if (and true true) "true true"}}</template>;

But this does not:

import { and } from 'ember-truth-helpers';

export default <template>{{if (and true true) "true true"}}</template>;

The reason is that (h/t @patricklx) the babel TypeScript plugin does not see the values inside the template tags as being "used" (likely because it is still in the eval() form), so that it drops the imports and prevents ember-auto-import's analyzer from "seeing" them.

This actually happens in both cases! However because of the "app-re-export" (v1 shim), the addons/* modules are forced into the build/the AMD registry regardless of whether they are used, so then it accidentally works. By that logic I think adding a side-effectful import "ember-truth-helpers"; in your app.ts or something would also have the same effect.