Skip to content

Commit

Permalink
Merge pull request #432 from qonto/typescript-setup
Browse files Browse the repository at this point in the history
Add TypeScript configuration
  • Loading branch information
dannycalleri authored Oct 2, 2023
2 parents 3abb435 + f50d744 commit 925ea22
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# compiled output
dist/
.pnpm-store/
declarations/

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

# compiled output
/dist/
/declarations/

# misc
/coverage/
108 changes: 93 additions & 15 deletions ember-autofocus-modifier/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';
"use strict";

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
legacyDecorators: true,
},
babelOptions: {
root: __dirname,
},
},
plugins: ['ember'],
plugins: ["ember"],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
"eslint:recommended",
"plugin:ember/recommended",
"plugin:prettier/recommended",
],
env: {
browser: true,
Expand All @@ -27,20 +27,98 @@ module.exports = {
// node files
{
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./addon-main.js',
"./.eslintrc.js",
"./.prettierrc.js",
"./.template-lintrc.js",
"./addon-main.js",
],
parserOptions: {
sourceType: 'script',
sourceType: "script",
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
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-autofocus-modifier/.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-autofocus-modifier/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
38 changes: 33 additions & 5 deletions ember-autofocus-modifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,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",
"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 @@ -39,8 +45,16 @@
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.23.0",
"@babel/plugin-syntax-decorators": "^7.17.0",
"@babel/preset-typescript": "^7.23.0",
"@embroider/addon-dev": "^4.1.0",
"@glimmer/component": "^1.1.2",
"@glint/core": "^1.2.0",
"@glint/environment-ember-loose": "^1.2.0",
"@glint/template": "^1.2.0",
"@rollup/plugin-babel": "^6.0.3",
"@tsconfig/ember": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"concurrently": "^8.2.1",
"ember-template-lint": "^5.11.2",
"eslint": "^8.49.0",
Expand All @@ -51,7 +65,8 @@
"prettier": "^3.0.3",
"release-it": "^15.11.0",
"rollup": "^2.67.0",
"rollup-plugin-copy": "^3.5.0"
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.2.2"
},
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0"
Expand All @@ -71,8 +86,21 @@
}
},
"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/*"
]
}
}
}
28 changes: 16 additions & 12 deletions ember-autofocus-modifier/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { babel } from '@rollup/plugin-babel';
import copy from 'rollup-plugin-copy';
import { Addon } from '@embroider/addon-dev/rollup';
import { babel } from "@rollup/plugin-babel";
import copy from "rollup-plugin-copy";
import { Addon } from "@embroider/addon-dev/rollup";

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
srcDir: "src",
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,12 +18,12 @@ 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(["modifiers/**/*.js"]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports(['components/**/*.js', "modifiers/**/*.js"]),
addon.appReexports(["modifiers/**/*.js"]),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
Expand All @@ -34,25 +37,26 @@ export default {
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
extensions,
babelHelpers: "bundled",
}),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),
addon.keepAssets(["**/*.css"]),

// Remove leftover build artifacts when starting a new build.
addon.clean(),

// Copy Readme and License into published package
copy({
targets: [
{ src: '../README.md', dest: '.' },
{ src: '../LICENSE.md', dest: '.' },
{ src: '../CHANGELOG.md', dest: '.' },
{ src: "../README.md", dest: "." },
{ src: "../LICENSE.md", dest: "." },
{ src: "../CHANGELOG.md", dest: "." },
],
}),
],
Expand Down
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
}
}
12 changes: 12 additions & 0 deletions ember-autofocus-modifier/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": ["src/**/*", "unpublished-development-types/**/*"],
"glint": {
"environment": "ember-loose"
},
"compilerOptions": {
"allowJs": true,
"declarationDir": "declarations",
"skipLibCheck": true
}
}
Loading

0 comments on commit 925ea22

Please sign in to comment.