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
feat(cli-lib): adding support for gts, gjs and hbs files. #4376
Conversation
package.json
Outdated
@@ -86,6 +90,8 @@ | |||
"clsx": "2", | |||
"commander": "8", | |||
"core-js": "^3.6.5", | |||
"ember-template-recast": "^6.1.4", | |||
"ember-template-tag": "^2.3.16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ember-template-tag": "^2.3.16", | |
"content-tag": "^2.0.0", |
content-tag
is the official implementation of <template>
parsing (and has types!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved!
packages/cli-lib/package.json
Outdated
"@types/estree": "^1.0.0", | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/json-stable-stringify": "^1.0.32", | ||
"@types/node": "14 || 16 || 17", | ||
"chalk": "^4.0.0", | ||
"commander": "8", | ||
"ember-template-recast": "^6.1.4", | ||
"ember-template-tag": "^2.3.16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
scriptParseFn(transformedSource) | ||
|
||
// extract template from transformed source to then run through hbs processor | ||
const [templateSource] = parseTemplates(source, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gts can have multiple templates, so does this concatenate all of the different templates?
For example, looking at this type from content-tag
: https://github.com/embroider-build/content-tag/?tab=readme-ov-file
We have:
import { Preprocessor } from 'content-tag';
let p = new Preprocessor();
// ...
let output = p.parse(source);
for (let parseResult of output) {
parseHbsFile(parseResult.contents, filename, options);
}
import or from 'ember-truth-helpers/helpers/or'; | ||
import Component from '@glimmer/component'; | ||
import {service} from '@ember/service'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if a second component were added to this file, the implementation (as is) would break -- unless I misunderstanding something about how ember-template-tag
works opposed to content-tag
overall this needs more typings |
@@ -0,0 +1,31 @@ | |||
import {transform} from 'ember-template-recast' | |||
|
|||
function extractText(node: any, fileName: any, options: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do those params have real types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they do,
import type { AST } from '@glimmer/syntax';
function extractText(node: AST.MustacheStatement | AST.SubExpression, ...) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types have been resolved
010ca6b
to
a5ab55d
Compare
atm, I'm having issues with ESM compatibility in this CJS project hmmm |
it looks like esbuild is what's used to compile, and it does support the situation we have so, something else is goofy in formatjs 🤔
it seems a combination of typescript, esbuild, buildtime and runtime are all in disagreement with eachother with what valid imports are |
this might be blocked on moving away from jest? I'm running just the test command, and seeing:
|
not setup to handle modules.
we don't support |
It's pretty straight forward without jest, tbh. But i'll have another go at by pushing the module boundary into the functions, and make them all async (we previously had everything passing except for type checking, which is how things got to how they are now). I'll see if i can get this repo's ts config, jest, and esbuild all in agreement that way! 🎉 Also, in a separate pr, i can try moving this repo to vitest for ya, if that's of interest? |
Thanks for your contribution. Yeah I don't have a strong opinion on |
79631de
to
ba6a867
Compare
hmm getting vitest to work can be pretty hard, any reason you can't use just |
I cannot due to type checking failing. We can't require or await import (for some reason) from cjs(ts), even though it's allowed generally, it's just type checking that is failing, iirc. I discovered that this is exclusively a tsc problem tho. If i use vite for the build, as shown, everything is fine! 🎉 The last step i have to figure out is how to have cli-lib's different tools integrated into bazel |
what's failing typechecking? This PR now has tooling changes so I can't really tell from its logs |
from all the commits you pushed which one doesn't have the tooling changes? |
If you revert the most recent commit, you'll see |
@NullVoxPopuli I've manually merged this in after a bunch of patches. I basically remove |
I've added the integration tests in fd1e347#diff-0ead01fee706ec365313e79e65339cfa742bf05b2f05587d1e30815195fed00b |
looks like packaging issue |
ok latest version should fix this. Integration tests also passed. Releasing that now. |
Thanks for solving everything! Sorry I couldn't figure it out (i had full esm and cjs compat easily if it weren't for jest (vitest 'just works')). the ESM/CJS compat I've don is much simpler, but is also only using one cohesive build tool 😅 You are my hero, today @longlho <3 |
No worries. I know you contribute upstream so if there're things to make it easier to not have to patch on my side that'd be great :) |
@longlho thanks heaps for your work getting |
What linter do you guys use? Extractor is only 1 piece but we also have linter integration for react/vue as well. |
do you mean translations linter? (I'm a newbie to the tooling side of this space (translations), fwiw 😅 ) |
What's the eslint plugin for those extensions & do they use the same parser? |
ah! yes! For ESLint we use: which uses: which takes our gjs/gts parser, content-tag: And stitches together ESTree AST and uses our and prefixes those AST nodes with We still need to do the same for jscodeshift -- using a custom parser that is actually two parsers -- but that is pending on some cleanup work I need to get back to here: embroider-build/content-tag#75 For Prettier, all we do use this plugin: which also uses content-tag for parsing, but because prettier already supported formatting glimmer, we use invoke prettier on each All of this is pretty similar to how Svelte and Vue work, afaik -- but also afaik, we're the only ones more eagerly integrating ESM into our CJS tooling (and fairly seamlessly!)
|
Do you guys use ember-intl or formatjs directly? I was trying to get ember-intl merged into this monorepo but that doesn't pan out. That package is pretty old as well so thinking of just forking it. |
the community makes a lot of use of ember-intl, and my employer does as well, but we were thinking about convincing (or really making a solid case for) ember-intl to be a build-time plugin rather than more runtime focused as it is now -- at work, we don't do much special in our product code to author translations -- we extract all the strings and such at build time, and only do manual / translating if we have tokens/numbers/data/etc involved that end up splicing up the same translation string. This makes for a very good default experience where the source code is just authored in english, and we don't maintain translation files or anything. To do this, we use formatjs directly in our build time code. |
Can you describe that pipeline in a bit more details? |
Use case
Engineering using glimmerjs files
.gts
and.gjs
and handlebar files.hbs
want to use formatjs for internationalizationSolution
Follow the Vue example and use glimmer tooling and ember-template-recast to manage code transformation.
Thanks to @mansona and @candunaj for the initial work.