Skip to content

Commit a676907

Browse files
NullVoxPopuliknownasilya
authored andcommitted
Begin converting to TypeScript
Woo type errors, deprecations! Add test-types project Rename files Upgrade and install updated lint config / dependencies Add test script to test-types Update more deps
1 parent 51a3468 commit a676907

21 files changed

Lines changed: 867 additions & 66 deletions
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ module.exports = {
1919
},
2020
// node files
2121
{
22-
files: ['./*.cjs', './addon-main.js'],
22+
files: [
23+
'./*.cjs',
24+
'./addon-main.js',
25+
],
2326
parserOptions: {
2427
sourceType: 'script',
2528
},

addon/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ module('Acceptance | Register Page', function (hooks) {
106106
});
107107
```
108108

109+
### TypeScript and Glint
110+
111+
If your project uses loose-mode templates, you can merge in the template registry interface provided by ember-page-title,
112+
```ts
113+
// <your-app>/types/glint.d.ts
114+
import '@glint/environment-ember-loose';
115+
import '@glint/environment-ember-template-imports';
116+
117+
import type PageTitle from 'ember-page-title/template-registry';
118+
119+
declare module '@glint/environment-ember-loose/registry' {
120+
export default interface Registry extends PageTitle {
121+
/* your local loose-mode entries here */
122+
}
123+
}
124+
```
125+
109126
### Upgrading notes for 5.x to 6.x
110127

111128
- `ember-page-title` no longer requires the usage of `ember-cli-head`.

addon/babel.config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"plugins": [
3+
["@babel/plugin-transform-typescript", {
4+
"allExtensions": true,
5+
"onlyRemoveTypeImports": true,
6+
"allowDeclareFields": true
7+
}],
38
"@embroider/addon-dev/template-colocation-plugin",
49
["@babel/plugin-proposal-decorators", { "legacy": true }],
510
"@babel/plugin-proposal-class-properties"
611
]
7-
}
12+
}

addon/package.json

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@
2323
],
2424
"repository": "https://github.com/ember-cli/ember-page-title",
2525
"scripts": {
26-
"build": "rollup --config",
27-
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
28-
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
29-
"lint:hbs": "ember-template-lint .",
30-
"lint:hbs:fix": "ember-template-lint . --fix",
26+
"build": "concurrently 'npm:build:*'",
27+
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
28+
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
3129
"lint:js": "eslint . --cache",
3230
"lint:js:fix": "eslint . --fix",
33-
"prepublishOnly": "rollup --config",
34-
"start": "rollup --config --watch"
31+
"start": "concurrently 'npm:start:*'",
32+
"start:types": "glint --declaration --watch",
33+
"start:js": "rollup --config --watch --no-watch.clearScreen",
34+
"prepack": "rollup --config",
35+
"lint:types": "glint",
36+
"build:types": "glint --declaration",
37+
"build:js": "rollup --config"
3538
},
3639
"dependencies": {
3740
"@embroider/addon-shim": "^1.8.7"
@@ -52,12 +55,20 @@
5255
"eslint": "^8.56.0",
5356
"eslint-config-prettier": "^9.1.0",
5457
"eslint-plugin-ember": "^11.12.0",
55-
"eslint-plugin-jsonc": "^2.11.2",
5658
"eslint-plugin-node": "^11.1.0",
5759
"eslint-plugin-prettier": "^5.1.2",
5860
"npm-run-all": "^4.1.5",
5961
"prettier": "^3.1.1",
60-
"rollup": "^4.9.1"
62+
"rollup": "^4.9.1",
63+
"typescript": "^5.3.3",
64+
"eslint-plugin-jsonc": "^2.11.2",
65+
"ember-source": "^5.5.0",
66+
"concurrently": "^8.2.2",
67+
"@tsconfig/ember": "^3.0.3",
68+
"@glint/template": "^1.2.1",
69+
"@glint/environment-ember-template-imports": "^1.2.1",
70+
"@glint/environment-ember-loose": "^1.2.1",
71+
"@glint/core": "^1.2.1"
6172
},
6273
"engines": {
6374
"node": "16.* || >= 18"
@@ -76,4 +87,4 @@
7687
"volta": {
7788
"extends": "../package.json"
7889
}
79-
}
90+
}

addon/rollup.config.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import babel from '@rollup/plugin-babel';
1+
import { babel } from '@rollup/plugin-babel';
22
import { Addon } from '@embroider/addon-dev/rollup';
33

44
const addon = new Addon({
@@ -30,6 +30,7 @@ export default {
3030
// It exists only to provide development niceties for you, like automatic
3131
// template colocation.
3232
babel({
33+
extensions: ['.js', '.gjs', '.ts', '.gts'],
3334
babelHelpers: 'bundled',
3435
}),
3536

@@ -38,13 +39,6 @@ export default {
3839
// package names.
3940
addon.dependencies(),
4041

41-
// Ensure that standalone .hbs files are properly integrated as Javascript.
42-
addon.hbs(),
43-
44-
// addons are allowed to contain imports of .css files, which we want rollup
45-
// to leave alone and keep in the published output.
46-
addon.keepAssets(['**/*.css']),
47-
4842
// Remove leftover build artifacts when starting a new build.
4943
addon.clean(),
5044
],
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import { inject as service } from '@ember/service';
22
import Helper from '@ember/component/helper';
33
import { guidFor } from '@ember/object/internals';
44

5+
import type PageTitleService from '../services/page-title.ts';
6+
57
/**
68
`{{page-title}}` helper used to set the title of the current route context.
79
810
@public
911
@method page-title
1012
*/
1113
export default class PageTitle extends Helper {
12-
@service('page-title')
13-
tokens;
14+
@service('page-title') declare tokens: PageTitleService;
1415

15-
get tokenId() {
16+
get tokenId(): string {
1617
return guidFor(this);
1718
}
1819

File renamed without changes.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@ import { scheduleOnce } from '@ember/runloop';
33
import Service, { inject as service } from '@ember/service';
44
import { isEmpty } from '@ember/utils';
55
import { assert } from '@ember/debug';
6+
import type RouterService from '@ember/routing/router-service';
67

78
let isFastBoot = typeof FastBoot !== 'undefined';
89

910
const RouterEvent = {
1011
ROUTE_DID_CHANGE: 'routeDidChange',
11-
};
12+
} as const;
1213

1314
/**
1415
@class page-title
1516
@extends Ember.Service
1617
*/
1718
export default class PageTitleService extends Service {
18-
@service('router')
19-
router;
19+
@service('router') declare router: RouterService;
2020

2121
// in fastboot context "document" is instance of
2222
// ember-fastboot/simple-dom document
23-
@service('-document')
24-
document;
23+
@service('-document') declare document: Document;
2524

2625
tokens = [];
2726

0 commit comments

Comments
 (0)