Skip to content
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: add TypeScript configuration #543

Merged
merged 10 commits into from
Sep 22, 2023
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# compiled output
dist/
declarations/
.pnpm-store/

# dependencies
Expand Down
1 change: 1 addition & 0 deletions ember-amount-input/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# compiled output
/dist/
/declarations/

# misc
/coverage/
80 changes: 79 additions & 1 deletion ember-amount-input/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
Expand Down Expand Up @@ -42,5 +42,83 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
// ts files
{
files: ['**/*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-unused-vars': 'error',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict.ts
'@typescript-eslint/array-type': [
'error',
{
default: 'array',
readonly: 'array',
},
],
'@typescript-eslint/ban-tslint-comment': 'error',
'@typescript-eslint/class-literal-property-style': 'error',
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'no-public',
},
],
'no-restricted-syntax': [
'error',
{
selector:
':matches(PropertyDefinition, MethodDefinition)[accessibility="private"]',
message: 'Use #private instead',
},
{
selector:
':matches(PropertyDefinition, MethodDefinition)[accessibility="protected"]',
message: 'Use #private instead',
},
],
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/member-delimiter-style': 'error',
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-duplicate-enum-values': 'error',
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-type-alias': [
'error',
{
allowGenerics: 'always',
},
],
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/parameter-properties': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-literal-enum-member': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/sort-type-constituents': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/typedef': 'error',
'@typescript-eslint/unified-signatures': 'error',
},
},
],
};
1 change: 1 addition & 0 deletions ember-amount-input/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# compiled output
/dist/
/declarations/
/tmp/

# dependencies
Expand Down
1 change: 1 addition & 0 deletions ember-amount-input/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"presets": [["@babel/preset-typescript"]],
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
Expand Down
39 changes: 33 additions & 6 deletions ember-amount-input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
"author": "",
"files": [
"addon-main.cjs",
"declarations",
"dist"
],
"scripts": {
"build": "rollup --config",
"build": "concurrently 'pnpm:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:types": "glint",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",
"start": "rollup --config --watch",
"start": "concurrently 'pnpm:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
dannycalleri marked this conversation as resolved.
Show resolved Hide resolved
"start:types": "glint -d --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"prepack": "rollup --config",
"prepare": "rollup --config"
Expand All @@ -34,12 +40,19 @@
},
"devDependencies": {
"@babel/core": "^7.17.0",
"@babel/eslint-parser": "^7.18.2",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.21.0",
"@babel/plugin-syntax-decorators": "^7.17.0",
"@babel/preset-typescript": "^7.22.11",
"@embroider/addon-dev": "^3.0.0",
"@glimmer/component": "^1.1.2",
"@glint/core": "^1.1.0",
"@glint/environment-ember-loose": "^1.1.0",
"@glint/template": "^1.1.0",
"@rollup/plugin-babel": "^6.0.3",
"@tsconfig/ember": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"concurrently": "^8.0.1",
"ember-template-lint": "^5.7.3",
"eslint": "^8.40.0",
Expand All @@ -49,7 +62,8 @@
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"rollup": "^3.22.0",
"rollup-plugin-copy": "^3.4.0"
"rollup-plugin-copy": "^3.4.0",
"typescript": "^5.2.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand All @@ -66,10 +80,23 @@
}
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js",
".": {
"types": "./declarations/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./declarations/*.d.ts",
"default": "./dist/*.js"
},
"./addon-main.js": "./addon-main.cjs"
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
},
"peerDependencies": {
"ember-source": "^4.0.0"
}
Expand Down
10 changes: 6 additions & 4 deletions ember-amount-input/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const addon = new Addon({
destDir: 'dist',
});

// Add extensions here, such as ts, gjs, etc that you may import
const extensions = ['.js', '.ts'];

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
Expand All @@ -15,7 +18,7 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(['index.js', '**/*.js']),
addon.publicEntrypoints(['components/**/*.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand All @@ -30,10 +33,9 @@ export default {
// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
// See `babel.config.json` for the actual Babel configuration!
babel({
extensions,
babelHelpers: 'bundled',
}),

Expand Down
7 changes: 4 additions & 3 deletions ember-amount-input/src/components/amount-input.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{! @glint-nocheck: not typesafe yet }}
<div class='amount-input' ...attributes>
<span class="amount-input__currency {{if @value 'black'}}">
<span class='amount-input__currency {{if @value "black"}}'>
{{this.currency}}
</span>

<input
class="amount-input__value {{@inputClass}} {{if @disabled 'disabled'}}"
class='amount-input__value {{@inputClass}} {{if @disabled "disabled"}}'
id={{this.inputId}}
type='number'
value={{@value}}
Expand All @@ -18,4 +19,4 @@
{{on 'input' this.onInput}}
{{on 'focusout' this.onFocusOut}}
/>
</div>
</div>
10 changes: 10 additions & 0 deletions ember-amount-input/src/unpublished-development-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '@glint/environment-ember-loose';
import 'ember-source/types';
import 'ember-source/types/preview';

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
}
}
15 changes: 15 additions & 0 deletions ember-amount-input/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": [
"src/**/*",
"unpublished-development-types/**/*",
],
"glint": {
"environment": "ember-loose"
},
"compilerOptions": {
"allowJs": true,
"declarationDir": "declarations",
"skipLibCheck": true,
}
}
Loading