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

Fix for addons using ember-cli-typescript 4x #529

Merged
merged 1 commit into from
Sep 17, 2020

Conversation

jamescdavis
Copy link
Contributor

@jamescdavis jamescdavis commented Sep 16, 2020

Fixes #528

We need to trigger a custom Babel run for any addons using ember-cli-typescript 4.

Copy link
Contributor

@ef4 ef4 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@@ -429,6 +444,10 @@ export default class V1Addon {
if (this.templateCompiler) {
babelConfig.plugins.push(this.templateCompiler.inlineTransformsBabelPlugin());
}

if (this.needsTypeScriptTransform) {
babelConfig.plugins.push(require.resolve('@babel/plugin-transform-typescript'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think this would be necessary, because ember-cli-babel adds the typescript plugin when it sees that ember-cli-typescript 4x is present?

Your fix above in needsCustomBabel should ensure that we allow ember-cli-babel to do its usual thing (other than the changes we make to its own settings like compileModules: false).

If this line is really needed to make it work, we should debug why because then I don't understand it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if we do keep this line, we should probably guard against double insertion of the plugin. If anybody else has already inserted it, babel will throw when it sees the duplicate.

For an example of where we already do this, see

if (!options.plugins.some(pluginMatches(/@babel\/plugin-proposal-optional-chaining/))) {
options.plugins.push(require.resolve('@babel/plugin-proposal-optional-chaining'));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is resolving the plugin relative to @embroider/compat, which doesn't have a dependency on @babel/plugin-transform-typescript. It needs to resolve relative to ember-cli-babel's root, because AFAIK that is the package that depends on the plugin. But again, this is one more reason I think it's suspicious to add the plugin here -- I think ember-cli-babel should probably be doing it.

Copy link
Contributor Author

@jamescdavis jamescdavis Sep 17, 2020

Choose a reason for hiding this comment

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

You're totally right. All it needed was a6567f2!

I'm not sure how I ended up down the rabbit hole where I thought I needed to have Embroider add the plugin. ¯\_(ツ)_/¯

@jamescdavis jamescdavis force-pushed the e-c-ts-4-addon-fix branch 2 times, most recently from 701009a to 4bdec90 Compare September 17, 2020 04:51
@ef4
Copy link
Contributor

ef4 commented Sep 17, 2020

This is marked draft still but I think it's ready?

@jamescdavis
Copy link
Contributor Author

jamescdavis commented Sep 17, 2020

@ef4 I've been trying to add an app that tests this test-packages, but having some issues getting it to properly fail without this fix. I was able to basically airlift https://github.com/scalvert/a11y-embroider-repro/tree/broken and it fails the build without the fix (with the same issue seen in that repro) and builds correctly with the fix, but the tests end up failing due to other issues (can't find @ember/destroyable). I think it's a weird workspaces issue. I'll go ahead and take this out of draft and work on getting a proper test-case in later.

@jamescdavis jamescdavis marked this pull request as ready for review September 17, 2020 13:32
@ef4
Copy link
Contributor

ef4 commented Sep 17, 2020

I'm hesitant to keep adding separate test apps anyway. It's a lot to maintain and it's slow. People keep doing it because it's more obvious, but I'd encourage more tests that look like these:

https://github.com/embroider-build/embroider/blob/master/packages/compat/tests/app-import.test.ts
https://github.com/embroider-build/embroider/blob/master/packages/compat/tests/addon-styles.test.ts

@ef4 ef4 merged commit e21b186 into embroider-build:master Sep 17, 2020
@jamescdavis jamescdavis deleted the e-c-ts-4-addon-fix branch September 17, 2020 14:06
@jamescdavis
Copy link
Contributor Author

Yeah, it's very slow. Those tests are a much better strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Addons using ember-cli-typescript@4 do not get their TypeScript transpiled
2 participants