Skip to content

Commit cf95346

Browse files
NullVoxPopuliknownasilya
authored andcommitted
Finish setting up TS Infra
1 parent a676907 commit cf95346

19 files changed

Lines changed: 278 additions & 72 deletions

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ jobs:
6060
run: pnpm test:ember --launch ${{ matrix.browser }}
6161
working-directory: test-app
6262

63+
typecheck:
64+
name: '${{ matrix.typescript-scenario }}'
65+
runs-on: ubuntu-latest
66+
timeout-minutes: 2
67+
continue-on-error: true
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
typescript-scenario:
72+
73+
74+
75+
76+
- typescript@next
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
- uses: wyvox/action-setup-pnpm@v3
81+
- run: pnpm build
82+
- run: pnpm i -f # just in case
83+
- name: 'Change TS to ${{ matrix.typescript-scenario }}'
84+
working-directory: ./test-types
85+
run: 'pnpm add --save-dev ${{ matrix.typescript-scenario}}'
86+
87+
- name: 'Type checking'
88+
working-directory: ./test-types
89+
run: |
90+
pnpm tsc -v
91+
pnpm tsc --noEmit
92+
6393
try-scenarios:
6494
name: Tests - ${{ matrix.ember-try-scenario }}
6595
runs-on: ubuntu-latest

addon/.eslintrc.cjs

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

addon/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# compiled output
44
/dist/
5+
/declarations/
56
/tmp/
67

78
# dependencies

addon/babel.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"plugins": [
33
["@babel/plugin-transform-typescript", {
44
"allExtensions": true,
5-
"onlyRemoveTypeImports": true,
6-
"allowDeclareFields": true
5+
"allowDeclareFields": true,
6+
"onlyRemoveTypeImports": true
77
}],
88
"@embroider/addon-dev/template-colocation-plugin",
99
["@babel/plugin-proposal-decorators", { "legacy": true }],

addon/package.json

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,39 @@
1212
"license": "MIT",
1313
"author": "Tim Evans <[email protected]>",
1414
"exports": {
15-
".": "./dist/index.js",
16-
"./*": "./dist/*",
17-
"./test-support": "./dist/test-support/index.js",
15+
".": {
16+
"types": "./declarations/index.d.ts",
17+
"default": "./dist/index.js"
18+
},
19+
"./*": {
20+
"types": "./declarations/*",
21+
"default": "./dist/*"
22+
},
23+
"./test-support": {
24+
"types": "./declarations/test-support/index.d.ts",
25+
"default": "./dist/test-support/index.js"
26+
},
1827
"./addon-main.js": "./addon-main.js"
1928
},
2029
"files": [
2130
"addon-main.js",
22-
"dist"
31+
"dist",
32+
"declarations"
2333
],
2434
"repository": "https://github.com/ember-cli/ember-page-title",
2535
"scripts": {
2636
"build": "concurrently 'npm:build:*'",
37+
"build:js": "rollup --config",
38+
"build:types": "glint --declaration",
2739
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
2840
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
2941
"lint:js": "eslint . --cache",
3042
"lint:js:fix": "eslint . --fix",
43+
"lint:types": "glint",
44+
"prepack": "rollup --config",
3145
"start": "concurrently 'npm:start:*'",
32-
"start:types": "glint --declaration --watch",
3346
"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"
47+
"start:types": "glint --declaration --watch"
3848
},
3949
"dependencies": {
4050
"@embroider/addon-shim": "^1.8.7"
@@ -48,27 +58,28 @@
4858
"@babel/plugin-proposal-class-properties": "^7.18.6",
4959
"@babel/plugin-proposal-decorators": "^7.23.6",
5060
"@embroider/addon-dev": "^4.1.3",
61+
"@glint/core": "^1.2.1",
62+
"@glint/environment-ember-loose": "^1.2.1",
63+
"@glint/environment-ember-template-imports": "^1.2.1",
64+
"@glint/template": "^1.2.1",
5165
"@rollup/plugin-babel": "^6.0.4",
66+
"@tsconfig/ember": "^3.0.3",
67+
"@types/rsvp": "^4.0.8",
5268
"@typescript-eslint/eslint-plugin": "^6.15.0",
5369
"@typescript-eslint/parser": "^6.15.0",
70+
"concurrently": "^8.2.2",
71+
"ember-source": "^5.5.0",
5472
"ember-template-lint": "^5.13.0",
5573
"eslint": "^8.56.0",
5674
"eslint-config-prettier": "^9.1.0",
5775
"eslint-plugin-ember": "^11.12.0",
76+
"eslint-plugin-jsonc": "^2.11.2",
5877
"eslint-plugin-node": "^11.1.0",
5978
"eslint-plugin-prettier": "^5.1.2",
6079
"npm-run-all": "^4.1.5",
6180
"prettier": "^3.1.1",
6281
"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"
82+
"typescript": "^5.3.3"
7283
},
7384
"engines": {
7485
"node": "16.* || >= 18"
@@ -87,4 +98,4 @@
8798
"volta": {
8899
"extends": "../package.json"
89100
}
90-
}
101+
}

addon/src/helpers/page-title.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
// @ts-nocheck
12
import { inject as service } from '@ember/service';
23
import Helper from '@ember/component/helper';
34
import { guidFor } from '@ember/object/internals';
45

56
import type PageTitleService from '../services/page-title.ts';
7+
import type { PageTitleToken } from '../services/page-title.ts';
8+
9+
export type PageTitleHelperOptions = Pick<
10+
PageTitleToken,
11+
'prepend' | 'front' | 'replace' | 'separator'
12+
>;
13+
14+
interface Signature {
15+
Args: {
16+
Positional: string[];
17+
Named: PageTitleHelperOptions;
18+
};
19+
Return: void;
20+
}
621

722
/**
8-
`{{page-title}}` helper used to set the title of the current route context.
9-
10-
@public
11-
@method page-title
23+
* `{{pageTitle}}` helper used to set the title of the current route context.
24+
*
25+
* ```gjs
26+
* import { pageTitle } from 'ember-page-title';
27+
*
28+
* <template>
29+
* {{pageTitle "the text to set the tab's title to"}}
30+
* {{pageTitle \@model.post.title}}
31+
* </template>
32+
* ```
1233
*/
13-
export default class PageTitle extends Helper {
34+
export default class PageTitle extends Helper<Signature> {
1435
@service('page-title') declare tokens: PageTitleService;
1536

1637
get tokenId(): string {

addon/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as pageTitle } from './helpers/page-title';
1+
export { default as pageTitle } from './helpers/page-title.ts';

addon/src/services/page-title.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
import { getOwner } from '@ember/application';
23
import { scheduleOnce } from '@ember/runloop';
34
import Service, { inject as service } from '@ember/service';
@@ -11,6 +12,28 @@ const RouterEvent = {
1112
ROUTE_DID_CHANGE: 'routeDidChange',
1213
} as const;
1314

15+
interface PageTitleConfig {
16+
/** The default separator to use between tokens. */
17+
separator?: string;
18+
19+
/** The default prepend value to use. */
20+
prepend?: boolean;
21+
22+
/** The default replace value to use. */
23+
replace?: boolean | null;
24+
}
25+
26+
export interface PageTitleToken extends PageTitleConfig {
27+
id: string;
28+
title?: string;
29+
separator?: string;
30+
prepend?: boolean;
31+
replace?: boolean;
32+
front?: unknown;
33+
previous?: PageTitleToken | null;
34+
next?: PageTitleToken | null;
35+
}
36+
1437
/**
1538
@class page-title
1639
@extends Ember.Service

addon/src/template-registry.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { pageTitle } from './helpers/page-title';
1+
import { default as pageTitle } from './helpers/page-title.ts';
22

33
export default interface Registry {
4-
'page-title': HelperLike<PageTitleHelperSignature>;
4+
/**
5+
* `{{page-title}}` helper used to set the title of the current route context
6+
*
7+
* ```hbs
8+
* {{page-title "the text to set the tab's title to"}}
9+
* {{page-title \@model.post.title}}
10+
* ```
11+
*/
12+
'page-title': typeof pageTitle;
513
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// Testem appends progress to the title...
22
// and there's no way to stop this at the moment
33

4-
export function getPageTitle(doc) {
4+
export function getPageTitle(doc: Document) {
55
// In Fastboot context we get 2 title elements if we don't remove one from app/index.html
66
// In real world applications, it is mandatory to remove <title> from app/index.html
77
// We are keeping both for sake for testing browser and fastboot scenarios
88
let element = [
99
...(doc || window.document).querySelectorAll('head title'),
1010
].pop();
11-
return element && element.innerText.trim().replace(/^\(\d+\/\d+\)/, '');
11+
12+
return (
13+
element &&
14+
element instanceof HTMLTitleElement &&
15+
element.innerText.trim().replace(/^\(\d+\/\d+\)/, '')
16+
);
1217
}

0 commit comments

Comments
 (0)