Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel plugin runs on v2 addon code where it shouldn't #1462

Open
simonihmig opened this issue Jun 6, 2023 · 1 comment
Open

Babel plugin runs on v2 addon code where it shouldn't #1462

simonihmig opened this issue Jun 6, 2023 · 1 comment
Labels
bug Something isn't working has reproduction

Comments

@simonihmig
Copy link
Collaborator

simonihmig commented Jun 6, 2023

Context:

  • app is using Embroider and has ember-cached-decorator-polyfill (it wouldn't need to actually, but also it shouldn't do any harm, right?)
  • ember-headless-form uses @cached, but only supports Ember >= 4.4, so has no need for ember-cached-decorator-polyfill and no reference to it whatsoever
  • reported also in error about cached-decorator-polyfill? CrowdStrike/ember-headless-form#146
  • app is using Embroider 2.x, but I have seen this also happen for 3.0! It is not happening for a classic build!

Reproduction:

While debugging, I found:

  • the polyfill's babel plugin is only added once to the "parent" here, and parent is the app (as expected)
  • putting a breakpoint here in the babel plugin shows that the plugin also runs for the v2 addons use of @cached here. I believe this is unexpected, as the polyfill should only run on the app's code, shouldn't it?
  • you can clearly see that the addon's code is transformed afterwards, applying the stuff the polyfill does (... importSync('ember-cached-decorator-polyfill').cached)
  • when the module resolver run, it throws with ember-headless-form is trying to import from ember-cached-decorator-polyfill but that is not one of its explicit dependencies
@ef4
Copy link
Contributor

ef4 commented Jun 6, 2023

Under embroider there is only one babel config during the final stage app build. So it's true that a transform added to the app is also going to run over the addons. In general babel plugins should try not to break code that doesn't need the feature they add.

We offer skipBabel to disable all babel transpilation of a given package, but that is rather extreme as you also lose preset-env, etc.

Perhaps the cached decorator polyfill could behave more like @babel/runtime, which has the option to emit an absolute or relative path in the import, so that it's resolvable regardless of which package it appear in.

@mansona mansona added has reproduction bug Something isn't working labels Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has reproduction
Projects
None yet
Development

No branches or pull requests

3 participants