Skip to content

DEV: introduce <template> tag support (.gjs)#21899

Closed
chancancode wants to merge 9 commits intodiscourse:mainfrom
tildeio:gjs
Closed

DEV: introduce <template> tag support (.gjs)#21899
chancancode wants to merge 9 commits intodiscourse:mainfrom
tildeio:gjs

Conversation

@chancancode
Copy link
Copy Markdown
Contributor

@chancancode chancancode commented Jun 1, 2023

This is intended to be a starting point for a conversation/playground, where the Discourse team members can checkout the branch and play with it to evaluate whether this is something we want to start adopting at this stage.

Some notable things:

  • Because it's a new file extension, some configurations is needed for editor and tooling support. This PR includes what's necessary for VSCode as well as the CLI stuff used in the project (e.g. prettier).

  • Template tags do not support "global resolutions" so everything needs to be imported. This may require some refactoring and/or boilerplate code for some existing code (the PR includes example changes to the d-icon and html-safe helpers used by <DButton>). Note that some of the boilerplate is somewhat offset by the ability to invoke plain JS functions from within the template (Ember 4.5+, or polyfill available).

  • This also sets up Glint (https://typed-ember.gitbook.io/glint/) to get back the basic language server support, but also sets the stage for more adoption down the road (either with more rigorous JSDoc or TypeScript).

  • TODO: check eslint support.

For prosperity, here is the same information but in the form of a rap song:

(Verse 1)
Yo, we're takin' a chance, in the code we dance,
With Ember's `.gjs`, bringin' a new romance.
We're ridin' the wave, makin' the brave,
DButton migration, the path we pave.

Support in the build for `.gjs`, no guilt,
Help from `truth-helpers`, the castle we built.
Exportin' helpers, from `d-icon` and `html-safe`,
Movin' to the beat, in the code, we rave.

(Chorus)
In the land of the code, on the GitHub road,
`.gjs` highlightin', the knowledge flowed.
Prettier for `.gjs`, we bestow,
Maintainin' the style, keepin' the flow.

(Verse 2)
In the world of Glint, not a hint,
Got basic JS language server support in the lint.
VSCode settin', no bettin',
For `.gjs` files, the stage is settin'.

(Chorus)
In the git of the hub, no need for a club,
Lock file changes, no rub.
Template tags demand, import command,
Boilerplate code may expand.

(Bridge)
Checkin' eslint support, no need to abort,
We're in this code game, it's our favorite sport.
Discourse team, explore the theme,
The `.gjs` feature, could it be a dream?

(Outro)
So here's the PR, whether near or far,
Check it out, see if it's up to par.
Feedback we invite, in the code we write,
In this digital night, we ignite the light.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you click View file you can preview the half-baked syntax highlighting (the JS stuff is fine, the <template> tag is somewhat working due to JSX support). It's probably not working here on the PR because it needs to be merged into main to fully take effect? (It's a guess, but @gitKrystan said she'd seen the same thing elsewhere)

@davidtaylorhq davidtaylorhq added the js-modernization Tasks related to our JS modernization project, including the Ember 4.0+ upgrade label Jun 2, 2023
@chancancode chancancode force-pushed the gjs branch 2 times, most recently from c7198c9 to 4e7006f Compare June 13, 2023 23:21
@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Jun 13, 2023
@chancancode
Copy link
Copy Markdown
Contributor Author

chancancode commented Jun 13, 2023

Rebased on #22023 (which is rebased on #22095) so there are more commits here for the time being, once those are merged I'll rebase again

@github-actions github-actions bot removed the chat PRs which include a change to Chat plugin label Jun 15, 2023
@chancancode chancancode force-pushed the gjs branch 2 times, most recently from ec5710b to 9910085 Compare June 21, 2023 19:44
@chancancode
Copy link
Copy Markdown
Contributor Author

@cvx updated with the latest ESLint stuff and added .vscode to .gitignore for now as discussed

chancancode and others added 8 commits June 22, 2023 18:40
This enables support for .gjs files in the build

Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
* Add missing `truth-helpers` dependencies

This addon is in the workspace but not explicitly referenced in
package.json (should it be in devDependencies?)

* Export helpers from `d-icon` in discourse-common

In order to use helpers in `<template>` they need to be imported.
Not sure what's the semantics of the `registerUnbound` internal helper
and if this refactor changed anything important.

Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
This tells GitHub to use js/ts mode for gjs/gts syntax highlighting,
which is hopefully better than nothing?

Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
This adds Glint to the project in JS mode (as opposed to TS). This
brings back the basic JS language server support in .gjs files in
VSCode (if you have the Glint extension installed).

For other editors, it should be possible to integrate directly via the
`glint-language-server` executable.

Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
Change the sample vscode settings:

extensions.json – this "recommends" the appropriate VSCode extensions
for use with .gjs development

settings.json – this sets the default formatter for .gjs files (without
this setting the user will be prompted to select one the first time),
also sets up the ESLint extension to check .gjs files.

Note that – the .vscode-sample directory doesn't do anything by itself.
These changes need to be pulled into your local `.vscode` directory.

Added the `.vscode` directory to `.gitignore` for now, but feel free to
improve on that setup.

Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
Co-authored-by: Krystan HuffMenne <kmenne+github@gmail.com>
@chancancode chancancode changed the title Showcase for <template> (.gjs) DEV: introduce <template> tag support (.gjs`) Jun 23, 2023
@chancancode chancancode changed the title DEV: introduce <template> tag support (.gjs`) DEV: introduce <template> tag support (.gjs) Jun 23, 2023
@davidtaylorhq
Copy link
Copy Markdown
Member

Landed via #22719 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

js-modernization Tasks related to our JS modernization project, including the Ember 4.0+ upgrade

Development

Successfully merging this pull request may close these issues.

3 participants