Skip to content

Commit 3866a6a

Browse files
authored
Merge pull request #55 from ember-cli/nvp/allow-type-checking-in-tests
Fix TS support, allowing type-checking in tests
2 parents 2ad20e8 + 4cf6fd1 commit 3866a6a

24 files changed

Lines changed: 266 additions & 180 deletions

files/babel.config.cjs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* This babel.config is not used for publishing.
3+
* It's only for the local editing experience
4+
* (and linting)
5+
*/
16
const { buildMacros } = require('@embroider/macros/babel');
27

38
const {
@@ -12,11 +17,14 @@ const isCompat = Boolean(process.env.ENABLE_COMPAT_BUILD);
1217

1318
module.exports = {
1419
plugins: [<% if (typescript) { %>
15-
['@babel/plugin-transform-typescript', {
16-
allExtensions: true,
17-
allowDeclareFields: true,
18-
onlyRemoveTypeImports: true,
19-
}],<% } %>
20+
[
21+
'@babel/plugin-transform-typescript',
22+
{
23+
allExtensions: true,
24+
allowDeclareFields: true,
25+
onlyRemoveTypeImports: true,
26+
},
27+
],<% } %>
2028
[
2129
'babel-plugin-ember-template-compilation',
2230
{

files/babel.publish.config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* This babel.config is only used for publishing.
3+
*
4+
* For local dev experience, see the babel.config
5+
*/
16
module.exports = {
27
plugins: [<% if (typescript) { %>
38
[

files/package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,22 @@
3838
"@babel/plugin-transform-typescript": "^7.25.2",<% } %>
3939
"@babel/runtime": "^7.25.6",
4040
"@ember/test-helpers": "^5.2.1",
41-
"@embroider/addon-dev": "^8.0.1",
41+
"@embroider/addon-dev": "^8.1.0",
4242
"@embroider/core": "^4.1.0",
4343
"@embroider/compat": "^4.1.0",
4444
"@embroider/macros": "^1.18.0",
4545
"@embroider/vite": "^1.1.5",
4646
"@eslint/js": "^9.17.0",
4747
"@glimmer/component": "^2.0.0",<% if (typescript) { %>
48-
"@glint/core": "^1.4.0",
49-
"@glint/environment-ember-loose": "^1.4.0",
50-
"@glint/environment-ember-template-imports": "^1.4.0",
51-
"@glint/template": "^1.4.0",
48+
"@glint/core": "^2.0.0-alpha.2",
49+
"@glint/environment-ember-loose": "^2.0.0-alpha.2",
50+
"@glint/environment-ember-template-imports": "^2.0.0-alpha.2",
51+
"@glint/tsserver-plugin": "^2.0.0-alpha.2",
52+
"@glint/template": "^1.6.0-alpha.1",
53+
"@ember/app-tsconfig": "^1.0.0",
5254
"@ember/library-tsconfig": "^1.0.0",<% } %>
53-
"@rollup/plugin-babel": "^6.0.4",
55+
"@rollup/plugin-babel": "^6.0.4",<% if (typescript) { %>
56+
"@types/qunit": "^2.19.12",<% } %>
5457
"babel-plugin-ember-template-compilation": "^2.2.5",
5558
"concurrently": "^9.0.1",
5659
"ember-qunit": "^9.0.2",
@@ -70,7 +73,7 @@
7073
"rollup": "^4.22.5",
7174
"testem": "^3.15.1",<% if (typescript) { %>
7275
"typescript-eslint": "^8.19.1",
73-
"typescript": "~5.6.0",<% } %>
76+
"typescript": "~5.8.3",<% } %>
7477
"vite": "^6.2.4"
7578
},
7679
"ember": {

files/rollup.config.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const addon = new Addon({
88
destDir: 'dist',
99
});
1010

11+
const rootDirectory = dirname(fileURLToPath(import.meta.url));
12+
const babelConfig = resolve(rootDirectory, './babel.publish.config.cjs');<% if (typescript) { %>
13+
const tsConfig = resolve(rootDirectory, './tsconfig.publish.json');<% } %>
14+
1115
export default {
1216
// This provides defaults that work well alongside `publicEntrypoints` below.
1317
// You can augment this if you need to.
@@ -47,10 +51,7 @@ export default {
4751
babel({
4852
extensions: ['.js', '.gjs'<% if (typescript) { %>, '.ts', '.gts'<% } %>],
4953
babelHelpers: 'bundled',
50-
configFile: resolve(
51-
dirname(fileURLToPath(import.meta.url)),
52-
'./babel.publish.config.cjs',
53-
),
54+
configFile: babelConfig,
5455
}),
5556

5657
// Ensure that standalone .hbs files are properly integrated as Javascript.
@@ -60,7 +61,10 @@ export default {
6061
addon.gjs(),<% if (typescript) { %>
6162

6263
// Emit .d.ts declaration files
63-
addon.declarations('declarations'),<% } %>
64+
addon.declarations(
65+
'declarations',
66+
`npx glint --declaration --project ${tsConfig}`,
67+
),<% } %>
6468

6569
// addons are allowed to contain imports of .css files, which we want rollup
6670
// to leave alone and keep in the published output.

files/tsconfig.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1+
/**
2+
* This tsconfig is not used for publishing.
3+
* It's only for the local editing experience
4+
* (and linting)
5+
*/
16
{
2-
"extends": "@ember/library-tsconfig",
3-
"include": ["src/**/*", "unpublished-development-types/**/*"],
7+
"extends": "@ember/app-tsconfig",
48
"glint": {
59
"environment": ["ember-loose", "ember-template-imports"]
610
},
11+
"include": ["src/**/*", "tests/**/*", "unpublished-development-types/**/*"],
712
"compilerOptions": {
8-
"allowJs": true,
9-
"declarationDir": "declarations",
10-
11-
/**
12-
https://www.typescriptlang.org/tsconfig#rootDir
13-
"Default: The longest common path of all non-declaration input files."
14-
15-
Because we want our declarations' structure to match our rollup output,
16-
we need this "rootDir" to match the "srcDir" in the rollup.config.mjs.
17-
18-
This way, we can have simpler `package.json#exports` that matches
19-
imports to files on disk
20-
*/
21-
"rootDir": "./src",
22-
23-
"types": ["ember-source/types"]
13+
"rootDir": ".",
14+
"types": ["ember-source/types", "vite/client", "@embroider/core/virtual"]
2415
}
2516
}

files/tsconfig.publish.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* This tsconfig is only used for publishing.
3+
*
4+
* For local dev experience, see the tsconfig.json
5+
*/
6+
{
7+
"extends": "@ember/library-tsconfig",
8+
"include": ["./src/**/*", "./unpublished-development-types/**/*"],
9+
"glint": {
10+
"environment": ["ember-loose", "ember-template-imports"]
11+
},
12+
"compilerOptions": {
13+
"allowJs": true,
14+
"declarationDir": "declarations",
15+
16+
/**
17+
https://www.typescriptlang.org/tsconfig#rootDir
18+
"Default: The longest common path of all non-declaration input files."
19+
20+
Because we want our declarations' structure to match our rollup output,
21+
we need this "rootDir" to match the "srcDir" in the rollup.config.mjs.
22+
23+
This way, we can have simpler `package.json#exports` that matches
24+
imports to files on disk
25+
*/
26+
"rootDir": "./src",
27+
28+
"types": ["ember-source/types"]
29+
}
30+
}

pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/typescript/my-addon/src/components/co-located-ts.hbs

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/fixtures/typescript/my-addon/src/components/co-located-ts.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)