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

[beta] template-tag code mod #1842

Merged
merged 22 commits into from
Jul 18, 2024
Merged

[beta] template-tag code mod #1842

merged 22 commits into from
Jul 18, 2024

Conversation

void-mAlex
Copy link
Collaborator

@void-mAlex void-mAlex commented Mar 14, 2024

still WIP but sharing for progress tracking/early feedback
compatBuild alternative for running an app code through embroider… to get gjs/gts files

//ember-cli-build.js

const { templateTagCodemod } = require('@embroider/compat');

-return compatBuild(app, Webpack, opts);
+return templateTagCodemod(app, {shouldTransformPath: (component_path) => true, dryRun: false});

builds upon base branch to get correct importable paths for 'builtIn' helpers/modifiers/components

@mansona mansona force-pushed the emit-imports-for-known-built-ins branch 3 times, most recently from 213f90f to 8bde7b9 Compare April 2, 2024 15:55
@ef4
Copy link
Contributor

ef4 commented Apr 2, 2024

Generally has the right shape.

It would be good not to need to know about the structure of #embroider_compat/ imports. Ideally all imports would be passed to the resolver to decide what to do with and based on the output path discovered the codemod would decide to inline that result or leave it unresolved.

Base automatically changed from emit-imports-for-known-built-ins to stable April 2, 2024 17:43
Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

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

I know this is still draft but we tried it on a reasonably large app and came up with a few problems 🙈 I'll list them here but please ignore if you're not in the mode for feedback 👍

  • there are a few places where you're using __dirname to find the embroider build but it should be using process.cwd()
  • this whole system seems to break if you have a babel config file (i.e. for a vite run) so we need to figure out the babel config setup for running files
  • if you have a basic babel config file with just a typescript plugin this process fails because it needs to parse your app using your app's babel config e.g. ember-concurrency transform. We probably need to use the same process that embroider uses to load the config
  • we're missing an export from @embroider/compat
  • babel-plugin-ember-template-comilation is being looked for relative to the app rather than relative to @embroider/compat so we probably need to find it using require.resolve before passing it to babel

@void-mAlex void-mAlex marked this pull request as ready for review July 16, 2024 22:48
<h1> this is a gjs file</h1>
</template>;`
);
// TODO figure out how to get around the protection in place to not delete unversioned files
Copy link
Member

Choose a reason for hiding this comment

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

this brings me back to what I said during the call. I imagine having a remove function that verifies that the file is in the repo (maybe after following links) before it tries to delete anything would be good enough for most people 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

anything can happen between the time the function verifies that, and actual actioning of the remove opration, git rm handles all of that very nicely for us which is perfectly.

even if we had a function to test it's within the repo, what the current implementation does is not remove anything that isn't backed up (read source controlled) which is WAY safer than removing things that happen to be in the repo. and only creates things that don't already exist.

I always error on the side of safer when it comes to removing things on behalf of users and in this case it's the test that can't cope with the solution, so we shouldn't implement a lesser solution so the test is happier

Copy link
Member

Choose a reason for hiding this comment

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

how about inverting it? make it have an optional config that you can pass a remove function to and we can add it to the docs that if you want it to do a git remove for reasons then you just pass a function that does git remove

thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

configuration is to be avoided if possible.
convention is that code mod does the right thing by default

if anything we need to make scenario tester source control aware/capable

@mansona mansona added the enhancement New feature or request label Jul 18, 2024
@mansona mansona changed the title template-tag code mod [beta] template-tag code mod Jul 18, 2024
Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

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

:shipit: on a personal note I'm very excited to see this 😍

@void-mAlex void-mAlex merged commit 40eb106 into stable Jul 18, 2024
217 checks passed
@void-mAlex void-mAlex deleted the template-tag-codemod branch July 18, 2024 12:45
@github-actions github-actions bot mentioned this pull request Jul 18, 2024
@bartocc
Copy link

bartocc commented Sep 6, 2024

Very excited about this codemod too!!

Just tried it in our codebase and hit this error

Build Error (TemplateTagCodemodPlugin)

unknown: Unexpected reserved word 'interface'. (8:0)

   6 | import SessionService from "core/services/session";
   7 |
>  8 | interface Signature {
     | ^
   9 |   Element: HTMLButtonElement;
  10 |   Args: {
  11 |     patient: Patient;

Is this codemod supposed to work with TS?

@mansona
Copy link
Member

mansona commented Sep 6, 2024

we've discussed this a few times but we have been struggling to find an Open Source Ember app that is using Typescript that we can test this on 🤔 do you happen to know any?

@bartocc
Copy link

bartocc commented Sep 9, 2024

Nope, I don't… but I guess https://github.com/ember-learn/super-rentals should not be too hard to port to TS and then test this codemode on 🤔…

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
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants