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

Add babel plugin for preprocessing templates with ast transforms #1199

Merged

Conversation

wondersloth
Copy link
Contributor

@wondersloth wondersloth commented Apr 29, 2022

In v2 addons there is no way to apply template transforms to components. This is common in addons that use ember-cli-preprocessor-registry and register transforms for modifying templates.

  • Needs some documentation somewhere on how to use this in the sample-babel.config.json or in a sample-babel.config.js file.

@ef4
Copy link
Contributor

ef4 commented May 3, 2022

Hi @wondersloth, thanks for tackling this.

This plugin does the same thing as babel-plugin-stage1-inline-hbs. So perhaps instead you could

  • move that plugin into @embroider/shared-internals so it would be available both to @embroider/core and to @embroider/addon-dev.
  • reexport it from @embroider/addon-dev (there is already an example of another plugin that works this way) so it's convenient for addon authors
  • document how to use it from the sample babel config.

@ef4
Copy link
Contributor

ef4 commented May 3, 2022

Oh, also be aware that there are two separate files related to that plugin:

  • babel-plugin-stage1-inline-hbs.ts is the actual implementation, written in a way that isn't tied to any node APIs so it's portable to other environments
  • babel-plugin-stage1-inline-hbs-node.ts is a wrapper around that for convenient usage from Node (it can load the ember template compiler from the filesystem, for example).

@wondersloth
Copy link
Contributor Author

wondersloth commented May 26, 2022

@ef4

I don't think I entirely understand your ask, and I want to clarify what you're suggestions are:

Move babel-plugin-stage1-inline-hbs.ts into @embroider/shared-internals

If I move this file into shared-internals:

  • I need to hoist a TemplateCompiler type/interface.
  • I need to have a compiler in addon-dev so that I can properly make() the babel-plugin-state1-inline-hbs plugin.

At this point I need to hoist more code from @embroider/core to @embroider/shared-internals to make that work across packages. FIles like template-compiler-common.ts, resolver.ts, babel-pluign-adjust-imports.ts

OR...

Refactor the pieces of template-transform-plugin.ts and babel-plugin-stage1-inline-hbs.ts to shared-internals

I suppose for this it's doable, just requires abstracting out the visitors?

@wondersloth
Copy link
Contributor Author

wondersloth commented May 26, 2022

Discussed concerns in Embroider Office Hours with @ef4

Moving babel-plugin-stage1-inline-hbs.ts to shared-internals will require many files to be hoisted to shared, which will cause a couple issues.

  • It will gut @embroider/core of a lot of features.
  • It will bloat @embroider/shared-internals which is consumed by ember-auto-imports.

Recommended path

  • Refactor template-transform-plugin to depend on babel-plugin-stage1-inline-hbs.ts via @embroider/core.
  • In @embroider/add-dev drop shared-internals as a dep.

@NullVoxPopuli
Copy link
Collaborator

Can this be rebased? looks like a lot of stuff from main is (for some reason) showing up in this PR's diff

@wondersloth wondersloth force-pushed the medwards/babel-template-transform-plugin branch from 0c97fc1 to 52f89a7 Compare June 1, 2022 18:33
@wondersloth wondersloth force-pushed the medwards/babel-template-transform-plugin branch from 52f89a7 to a4f70a0 Compare June 1, 2022 18:35
@wondersloth wondersloth requested a review from ef4 June 5, 2022 20:48
@wondersloth
Copy link
Contributor Author

@ef4 is there any additional work needed before merge?

@Kaceykaso
Copy link

@ef4 @wondersloth any chance we can get this merged today or tomorrow? Looking to announce internally ;)
Thanks a bunch!

@ef4 ef4 merged commit 871bb24 into embroider-build:main Jun 9, 2022
@ef4 ef4 added the enhancement New feature or request label Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants