Skip to content

Commit

Permalink
Switch from ember-template-tag to content-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Apr 5, 2024
1 parent b069062 commit 2513f62
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"commander": "8",
"core-js": "^3.6.5",
"ember-template-recast": "^6.1.4",
"ember-template-tag": "^2.3.16",
"emoji-regex": "^10.2.1",
"eslint": "7 || 8",
"fast-glob": "^3.2.7",
Expand Down Expand Up @@ -175,6 +174,7 @@
"author": "Seth Bertalotto <sbertal@verizonmedia.com>",
"dependencies": {
"@swc/helpers": "^0.5.1",
"content-tag": "^2.0.1",
"jest-cli": "^29.5.0",
"jest-junit": "^16.0.0",
"magic-string": "^0.30.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GLIMMER_HBS_DEPS = [
"//:node_modules/@glimmer/reference",
"//:node_modules/@glimmer/syntax",
"//:node_modules/@glimmer/validator",
"//:node_modules/ember-template-tag",
"//:node_modules/content-tag",
"//:node_modules/ember-template-recast",
":node_modules/@babel/parser",
]
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"url": "https://github.com/formatjs/formatjs/issues"
},
"dependencies": {
"@babel/parser": "^7.22.10",
"@formatjs/icu-messageformat-parser": "workspace:*",
"@formatjs/ts-transformer": "workspace:*",
"@babel/parser": "^7.22.10",
"@glimmer/env": "^0.1.7",
"@glimmer/reference": "^0.89.0",
"@glimmer/syntax": "^0.89.0",
Expand All @@ -45,7 +45,6 @@
"chalk": "^4.0.0",
"commander": "8",
"ember-template-recast": "^6.1.4",
"ember-template-tag": "^2.3.16",
"fast-glob": "^3.2.7",
"fs-extra": "10",
"json-stable-stringify": "^1.0.1",
Expand Down
27 changes: 17 additions & 10 deletions packages/cli-lib/src/gts_extractor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// @ts-ignore
import {transform, parseTemplates} from 'ember-template-tag'
import {parseFile as parseHbsFile} from './hbs_extractor'
import {parseScript} from './parse_script'
import { parseFile as parseHbsFile } from './hbs_extractor'
import { parseScript } from './parse_script'
// We can't use an import here because the gts_extractor.ts file
// is FAKE TS -- in that it's actually CJS.
//
// So we have to use require because content-tag is a real type=module package
// and we need TypeScript to recognize that it has to choose the node/require
// condition of package.json#exports
// https://github.com/embroider-build/content-tag/blob/main/package.json#L18
let { Preprocessor } = require('content-tag');
let p = new Preprocessor();

export function parseFile(source: string, fileName: string, options: any) {
const scriptParseFn = parseScript(options, fileName)
const {output: transformedSource} = transform({
input: source,
relativePath: '',
})
const transformedSource = p.process(source, { filename: fileName })

scriptParseFn(transformedSource)

// extract template from transformed source to then run through hbs processor
const [templateSource] = parseTemplates(source, '')
const parseResult = p.parse(source, { filename: fileName });

for (let parsed of parseResult) {
parseHbsFile(parsed.contents, fileName, options)
}

parseHbsFile(templateSource.contents, fileName, options)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ exports[`gts_extractor 1`] = `
"defaultMessage": "in gjs file",
"id": "YCDlzq",
},
{
"defaultMessage": "hello",
"description": undefined,
"id": "m3HSJL",
},
{
"defaultMessage": "in template",
"description": "in template desc",
Expand Down
5 changes: 5 additions & 0 deletions packages/cli-lib/tests/unit/fixtures/comp.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import or from 'ember-truth-helpers/helpers/or';
import Component from '@glimmer/component';
import {service} from '@ember/service';

const Header = <template>
<header>{{formatMessage 'hello'}}</header>
</template>;

export default class Comp extends Component {
@service intl;

Expand All @@ -13,6 +17,7 @@ export default class Comp extends Component {
}

<template>
<Header />
<p>
{{formatMessage 'in template' 'in template desc'}}
</p>
Expand Down
50 changes: 8 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2513f62

Please sign in to comment.