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

Avoid conflicts with ember-cli-htmlbars-inline-precompile #317

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Oct 1, 2019

Both ember-cli-htmlbars-inline-precompile and ember-cli-htmlbars used the same exact check to determine if babel-plugin-htmlbars-inline-precompile was registered. When the build was parallelizable we would properly detect that the babel-plugin-htmlbars-inline-precompile was or was not the one added by each respective addon (because the addon's own __dirname is included in the check) but when the build was not parallelizable the babel plugins array contains a standard Babel plugins array. In that case, both addons were only checking if the plugin path matched (via require.resolve) which was completely insufficient.

This issue resulted in ember-cli-htmlbars-inline-precompile thinking that it was already registered when the build was not parallelizable, which would subsequently make it not register its own instance of the plugin (to support import paths other than ember-cli-htmlbars).

The fix here is:

  1. This forces any instances of ember-cli-htmlbars-inline-precompile addon to be completely inert if it is part of the same parent addon or app as ember-cli-htmlbars itself.
  2. Emit a deprecation notice when we identify that ember-cli-htmlbars-inline-precompile should be removed.
  3. Updating the _isInlinePrecompileBabelPluginRegistered method to properly check if the plugin ember-cli-htmlbars is registering is already registered (with our configuration).

Fixes #312
Fixes #297
Closes #319
Fixes ember-cli/ember-cli#8868

@rwjblue rwjblue requested a review from Turbo87 October 1, 2019 14:52
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds reasonable 👍

rwjblue added a commit to rwjblue/ember-cli-htmlbars that referenced this pull request Oct 1, 2019
…s-inline-precompile

We **specifically** had tests for the scenario that ultimately was
reported as failing. The description in ember-cli#317 explains the scenario
better, but the failure scenario was only exposed IFF the same version
of babel-plugin-htmlbars-inline-precompile was used (because both
ember-cli-htmlbars-inline-precompile and ember-cli-htmlbars were
comparing `require.resolve('babel-plugin-htmlbars-inline-precompile')`
to determine if they should append the plugin again, so if they didn't
use the same version ember-cli#312 wasn't possible).

This updates the ember-try scenario to use
ember-cli-htmlbars-inline-precompile@3.0.0, in order to replicate the
error.
@rwjblue
Copy link
Member Author

rwjblue commented Oct 1, 2019

FYI - We had tests specifically for this but they didn't work 😭. I've updated those tests in #319 in order to replicate the original failure (and have confidence that this is fixing things).

@rwjblue
Copy link
Member Author

rwjblue commented Oct 1, 2019

Turns out that I was wrong, ember-cli-htmlbars-inline-precompile does not use this.parent.addons, it instead checks this.project.findAddonsByName('ember-cli-htmlbars'). The fact that it checks the project and not its direct parent means that the path chosen here will not work (shown by failing test cases).

https://github.com/ember-cli/ember-cli-htmlbars-inline-precompile/blob/ae928fe449309b82636520e7b2d5f21ce5837386/index.js#L34-L38

Both ember-cli-htmlbars-inline-precompile and ember-cli-htmlbars used
the same _exact_ check to determine if
`babel-plugin-htmlbars-inline-precompile` was registered. When the build
was parallelizable we would properly detect that the
babel-plugin-htmlbars-inline-precompile was or was not the one added by
each respective addon (because the addon's own `__dirname` is included
in the check) **but** when the build was not parallelizable the babel
plugins array contains a standard Babel plugins array. In that case,
both addons were _only_ checking if the plugin _path_ matched (via
`require.resolve`) which was completely insufficient.

This issue resulted in `ember-cli-htmlbars-inline-precompile` _thinking_
that it was already registered _when_ the build was not parallelizable,
which would subsequently make it not register its own instance of the
plugin (to support import paths other than `ember-cli-htmlbars`).

The fix here s twofold:

1. This forces any instances of ember-cli-htmlbars-inline-precompile
   addon to be completely inert if it is part of the same parent addon
   or app as ember-cli-htmlbars itself.  In addition, we emit a
   deprecation notice when applicable.
2. Updating the `_isInlinePrecompileBabelPluginRegistered` method to
   properly check if the plugin ember-cli-htmlbars is registering is
   already registered (with our configuration).
@rwjblue rwjblue force-pushed the prevent-conflicts-with-legacy-inline-compiler branch from 7c969ab to 2c3121f Compare October 1, 2019 19:27
@rwjblue
Copy link
Member Author

rwjblue commented Oct 1, 2019

Updated this PR now to use a different strategy:

  1. This forces any instances of ember-cli-htmlbars-inline-precompile addon to be completely inert if it is part of the same parent addon or app as ember-cli-htmlbars itself.
  2. Emit a deprecation notice when we identify that ember-cli-htmlbars-inline-precompile should be removed.
  3. Updating the _isInlinePrecompileBabelPluginRegistered method to properly check if the plugin ember-cli-htmlbars is registering is already registered (with our configuration).

…s-inline-precompile

We **specifically** had tests for the scenario that ultimately was
reported as failing. The description in ember-cli#317 explains the scenario
better, but the failure scenario was only exposed IFF the same version
of babel-plugin-htmlbars-inline-precompile was used (because both
ember-cli-htmlbars-inline-precompile and ember-cli-htmlbars were
comparing `require.resolve('babel-plugin-htmlbars-inline-precompile')`
to determine if they should append the plugin again, so if they didn't
use the same version ember-cli#312 wasn't possible).

This updates the ember-try scenario to use
ember-cli-htmlbars-inline-precompile@3.0.0, in order to replicate the
error.

(cherry picked from commit 79e953e)
@rwjblue
Copy link
Member Author

rwjblue commented Oct 1, 2019

The last commit here cherry-pick's the commit from #319 and demonstrates that this PR fixes the issue.

@rwjblue rwjblue merged commit 15ca4ea into ember-cli:master Oct 1, 2019
@rwjblue rwjblue deleted the prevent-conflicts-with-legacy-inline-compiler branch October 1, 2019 20:01
@rwjblue rwjblue added the bug label Oct 1, 2019
HeroicEric added a commit to HeroicEric/ember-cli that referenced this pull request Oct 5, 2019
- Drops `ember-cli-htmlbars-inline-precompile` from both app and addon
  blueprints
- Bumps `ember-cli-htmlbars` from
  [4.0.1](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.1)
  to [4.0.5](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.5)

Why?

Currently, generating a new ember app or addon and running it will
result in the following deprecation:

```
DEPRECATION: ember-cli-htmlbars-inline-precompile is no longer needed with ember-cli-htmlbars versions 4.0.0 and higher, please remove it from `/Users/eric/code/foo/package.json`
```

See ember-cli/ember-cli-htmlbars#317
for more details.

Steps to reproduce the current issue:

```bash
npm install -g ember-cli
ember new foo-app
cd foo-app
ember s
```
HeroicEric added a commit to HeroicEric/ember-cli that referenced this pull request Oct 5, 2019
- Drops `ember-cli-htmlbars-inline-precompile` from both app and addon
  blueprints
- Bumps `ember-cli-htmlbars` from
  [4.0.1](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.1)
  to [4.0.5](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.5)

Why?

Currently, generating a new ember app or addon and running it will
result in the following deprecation:

```
DEPRECATION: ember-cli-htmlbars-inline-precompile is no longer needed with ember-cli-htmlbars versions 4.0.0 and higher, please remove it from `/Users/eric/code/foo/package.json`
```

See ember-cli/ember-cli-htmlbars#317
for more details.

Steps to reproduce the current issue:

```bash
npm install -g ember-cli
ember new foo-app
cd foo-app
ember s
```
rwjblue pushed a commit to HeroicEric/ember-cli that referenced this pull request Oct 7, 2019
- Drops `ember-cli-htmlbars-inline-precompile` from both app and addon
  blueprints
- Bumps `ember-cli-htmlbars` from
  [4.0.1](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.1)
  to [4.0.5](https://github.com/ember-cli/ember-cli-htmlbars/releases/tag/v4.0.5)

Why?

Currently, generating a new ember app or addon and running it will
result in the following deprecation:

```
DEPRECATION: ember-cli-htmlbars-inline-precompile is no longer needed with ember-cli-htmlbars versions 4.0.0 and higher, please remove it from `/Users/eric/code/foo/package.json`
```

See ember-cli/ember-cli-htmlbars#317
for more details.

Steps to reproduce the current issue:

```bash
npm install -g ember-cli
ember new foo-app
cd foo-app
ember s
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants