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

[FEATURE] Add template tag component blueprints via --strict flag as per RFC #779 #20511

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

IgnaceMaes
Copy link

@IgnaceMaes IgnaceMaes commented Jul 27, 2023

Implements step one of the blueprint work as per RFC #779

Allows e.g.:

ember generate component foo-bar --strict

Prior syntax is still enabled by default, or by passing the loose flag:

ember generate component foo-bar --loose

@NullVoxPopuli
Copy link
Contributor

very excited for this!

@IgnaceMaes IgnaceMaes changed the title feat: template tag component blueprints [WIP] [FEATURE] Add template tag component blueprints via --strict flag as per RFC #779 Jul 30, 2023
@kategengler
Copy link
Member

@IgnaceMaes What is the status here?

@IgnaceMaes
Copy link
Author

IgnaceMaes commented Dec 21, 2023

@kategengler This should be good to go, functionality wise. But I could use some guidance on how to move this ahead.

This MR depended on ember-cli/ember-cli#10332 which got merged and released in [email protected]. (yey 🎉) But can this functionality be merged already, considering it now requires a peerDependency on ember-cli@^5.5.0? Or should it be backported in ember-cli to older LTS's?

@IgnaceMaes IgnaceMaes force-pushed the template-tag-blueprints branch from 0081fc9 to 5d1c505 Compare December 21, 2023 10:16
@kategengler
Copy link
Member

Does it work without the --strict flag for earlier ember-cli?

it('component-test x-foo --strict', function () {
return emberGenerateDestroy(['component-test', 'x-foo', '--strict'], (_file) => {
expect(_file('tests/integration/components/x-foo-test.gjs')).to.equal(
fixture('component-test/rfc232.gjs')
Copy link
Author

Choose a reason for hiding this comment

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

This fails when running the TypeScript blueprint tests:

  1) Blueprint: component-test
       in app
         with default setup
           component-test x-foo --strict:
     AssertionError: expected "tests/integration/components/x-foo-test.gjs" to exist

parent path "tests/integration/components" exists and contains:
- x-foo-test.gts
      at /.../ember.js/node-tests/blueprints/component-test-test.js:44:75
      at /.../ember.js/node_modules/.pnpm/[email protected]/node_modules/ember-cli-blueprint-test-helpers/lib/ember-generate-destroy.js:34:17
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I'm not sure what the next step is here. The other tests don't check on TypeScript-specific files. Is the expect assumed to automatically work for TS too, but it doesn't here?

Welcoming any input 😄

Copy link
Author

Choose a reason for hiding this comment

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

Validating the path dynamically would work:

const filePath = fs.existsSync('tests/integration/components/x-foo-test.gts')
  ? 'tests/integration/components/x-foo-test.gts'
  : 'tests/integration/components/x-foo-test.gjs';

But that seems like logic which shouldn't be in the test.

Copy link
Member

Choose a reason for hiding this comment

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

You're getting TypeScript output when the TypeScript blueprints should be converted to JS by the blueprint system (unless it is a typescript project).

I believe this https://github.com/ember-polyfills/ember-cli-typescript-blueprint-polyfill/blob/main/src/utils.js#L13-L15 needs to include gts, but there may be other changes needed for the blueprint system to convert gts to gjs.

Copy link
Member

Choose a reason for hiding this comment

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

Ping @IgnaceMaes on ^

I'd love for this to land in 5.x

Copy link
Contributor

Choose a reason for hiding this comment

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

I can try to find some time to push this over the finish line as well 👍

Copy link
Author

Choose a reason for hiding this comment

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

That would be much appreciated. Realistically, I won't have time to look into this in the near future :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that was confusing.. 😄

I updated the polyfill and used the branch here, but that still didn't work because the polyfill disables itself if it thinks it's no longer needed. It seems we are depending on ember-cli 4.10 which does support .ts -> .js in the blueprints, but not .gts -> .gjs (which was released in 5.5 I think). Once I bump the version to 5.12 the test no longer seems to fail.

What was extra confusing is that there are no tests that verify the .ts version of the blueprints: #20362

@IgnaceMaes
Copy link
Author

Does it work without the --strict flag for earlier ember-cli?

It does! So I suppose this is fine then.

Comment on lines +1 to +3
<template>
{{yield}}
</template>
Copy link
Contributor

Choose a reason for hiding this comment

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

@Windvis
Copy link
Contributor

Windvis commented Oct 4, 2024

In Octane the component-class defaults to --no-component-class. I'm wondering if that's the most useful default for .gts components though, especially since switching from template only .gts files to class based ones isn't as easy due to the types.

Since this is a new flag, and the RFC doesn't specify it, would it make sense to generate a class based .gts file by default, and a TO version if the --component-class=@ember/component/template-only is provided?

In any case, even if we stick with the "TO" by default, we should probably still generate a class based version if a class is provided (and throw an error if it's not glimmer)?

@NullVoxPopuli
Copy link
Contributor

isn't as easy due to the types.

I think we can do:

<template>
 ...
</template> satisfies TOC<...>

@NullVoxPopuli
Copy link
Contributor

Linting for gjs/gts has landed in ember-cli

@Windvis Windvis mentioned this pull request Mar 1, 2025
3 tasks
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.

5 participants