Skip to content

Commit

Permalink
Partial TypeScript upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyATW committed Apr 28, 2023
1 parent eaa72ca commit f5dcaa2
Show file tree
Hide file tree
Showing 155 changed files with 3,875 additions and 2,448 deletions.
19 changes: 15 additions & 4 deletions .eslintrc.js
Expand Up @@ -10,17 +10,18 @@
// ESLint configuration
// http://eslint.org/docs/user-guide/configuring
module.exports = {
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',

extends: [
'airbnb',
'plugin:flowtype/recommended',
'plugin:css-modules/recommended',
'plugin:@typescript-eslint/recommended'
],

plugins: [
'flowtype',
'css-modules',
'@typescript-eslint',
'import'
],

globals: {
Expand All @@ -31,16 +32,18 @@ module.exports = {
browser: true,
},

root: true,

rules: {
// `js` and `jsx` are common extensions
// `mjs` is for `universal-router` only, for now
'import/extensions': [
'error',
'always',
{
js: 'never',
jsx: 'never',
mjs: 'never',
ts: 'never',
},
],

Expand Down Expand Up @@ -103,8 +106,16 @@ module.exports = {
// https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
moduleDirectory: ['node_modules', 'src'],
},
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
extensions: ['.ts', '.tsx'],
}
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
};
3 changes: 2 additions & 1 deletion .mocharc.js
@@ -1,5 +1,6 @@
module.exports = {
require: ['@babel/register', './test/setup'],
extension: ['ts'],
require: ['./test/setup'],
exit: true,
file: './test/mocha-setup',
};
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
3 changes: 1 addition & 2 deletions babel.config.js
Expand Up @@ -11,11 +11,11 @@
// https://babeljs.io/docs/usage/api/
module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-modules-commonjs',
],
presets: [
['@babel/preset-typescript', { allowDeclareFields: true }],
[
'@babel/preset-env',
{
Expand All @@ -24,7 +24,6 @@ module.exports = {
},
},
],
'@babel/preset-flow',
'@babel/preset-react',
],
ignore: ['node_modules', 'build'],
Expand Down
9 changes: 7 additions & 2 deletions cypress.config.js
@@ -1,11 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const { defineConfig } = require('cypress');
require('dotenv').config({ path: './.env.test' });

module.exports = defineConfig({
port: 4000,
env: {
subdomain: 'https://integration-test.local.lunch.pink:3000/',
subdomain: 'http://integration-test.local.lunch.pink:3000/',
superuserEmail: process.env.SUPERUSER_EMAIL,
superuserPassword: process.env.SUPERUSER_PASSWORD,
},
e2e: {
baseUrl: 'https://local.lunch.pink:3000/',
baseUrl: 'http://local.lunch.pink:3000/',
},
});
7 changes: 5 additions & 2 deletions cypress/e2e/lunch_tests/login.cy.js
@@ -1,6 +1,9 @@
/* eslint-disable no-undef */
import * as helpers from '../../support/helpers';

const superuserEmail = Cypress.env('superuserEmail');
const superuserPassword = Cypress.env('superuserPassword');

describe('login page', () => {
beforeEach(() => {
cy.visit('/login');
Expand All @@ -13,8 +16,8 @@ describe('login page', () => {
});

it('logs in and out successfully', () => {
cy.get('#login-email').type('test@lunch.pink');
cy.get('#login-password').type('test');
cy.get('#login-email').type(superuserEmail);
cy.get('#login-password').type(superuserPassword);
cy.get('button[type="submit"]').click();
helpers.deleteTeam();
cy.contains('You’re not currently a part of any teams!');
Expand Down
7 changes: 5 additions & 2 deletions cypress/support/helpers/login.js
@@ -1,7 +1,10 @@
/* eslint-disable no-undef */
const superuserEmail = Cypress.env('superuserEmail');
const superuserPassword = Cypress.env('superuserPassword');

export default () => {
const email = 'test@lunch.pink';
const password = 'test';
const email = superuserEmail;
const password = superuserPassword;
cy.request('POST', '/login', {
email,
password
Expand Down
67 changes: 67 additions & 0 deletions global.d.ts
@@ -0,0 +1,67 @@
import { Action } from 'redux';
import WebSocket from 'ws';
import { Team, User as UserModel } from './src/models';

declare global {
interface Window { App: any; }
namespace Express {
export interface Request {
broadcast: (teamId: number, data: Action) => void;
subdomain?: string;
team?: Team;
user?: UserModel;
wss?: Server
}
}
}

interface ExtWebSocket extends WebSocket {
teamId?: number;
}

type Dispose = () => void
type InsertCssItem = () => Dispose
type GetCSSItem = () => string
type GetContent = () => string

interface Style {
[key: string]: InsertCssItem | GetCSSItem | GetContent | string
_insertCss: InsertCssItem
_getCss: GetCSSItem
_getContent: GetContent
}

declare module '*.scss' {
const style: Style
export default style
}

declare module '*.css' {
const style: Style
export default style
}

declare module 'isomorphic-style-loader/useStyles' {
function useStyles(...styles: Style[]): void
export default useStyles
}

declare module 'isomorphic-style-loader/StyleContext' {
import { Context } from 'react'

type RemoveGlobalCss = () => void
type InsertCSS = (...styles: Style[]) => RemoveGlobalCss | void
interface StyleContextValue {
insertCss: InsertCSS
}

const StyleContext: Context<StyleContextValue>

export { StyleContext as default, InsertCSS }
}

declare module 'express-serve-static-core' {
interface Express {
hot: __WebpackModuleApi.Hot;
}
}
64 changes: 46 additions & 18 deletions package.json
Expand Up @@ -22,41 +22,41 @@
"bootstrap": "^5.2.3",
"classnames": "^2.2.6",
"common-password": "^0.1.2",
"compression": "^1.6.1",
"compression": "^1.7.4",
"connect-flash": "^0.1.1",
"connect-session-sequelize": "^7.1.5",
"cookie-parser": "^1.4.3",
"cookie-parser": "^1.4.6",
"core-js": "^2.5.4",
"cors": "^2.8.3",
"dayjs": "^1.11.7",
"dotenv": "^2.0.0",
"eventemitter3": "^1.2.0",
"express": "^4.17.3",
"express-jwt": "^8.4.1",
"express-session": "^1.15.2",
"express-session": "^1.17.3",
"express-sslify": "^1.2.0",
"express-ws": "^5.0.2",
"fastclick": "^1.0.6",
"fbjs": "^3.0.4",
"fetch-mock": "^9.11.0",
"google-map-react": "^2.2.0",
"history": "^4.7.2",
"immutability-helper": "^2.1.2",
"history": "^5.3.0",
"immutability-helper": "^3.1.1",
"isomorphic-fetch": "^3.0.0",
"isomorphic-style-loader": "^5.3.2",
"jsonwebtoken": "^9.0.0",
"method-override": "^2.3.8",
"method-override": "^3.0.0",
"mocha-junit-reporter": "^2.2.0",
"morgan": "^1.10.0",
"node-fetch": "^2.6.9",
"normalizr": "^3.2.2",
"passport": "^0.6.0",
"passport-google-oauth20": "^1.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"pg": "^8.9.0",
"pretty-error": "^3.0.4",
"prop-types": "^15.8.1",
"query-string": "^6.1.0",
"query-string": "^7.1.3",
"react": "^16.14.0",
"react-autosuggest": "^10.0.2",
"react-bootstrap": "^2.7.0",
Expand All @@ -73,15 +73,15 @@
"reselect": "^2.3.0",
"reserved-usernames": "^1.0.3",
"robust-websocket": "^0.2.1",
"rotating-file-stream": "^1.2.1",
"rotating-file-stream": "^3.1.0",
"sendgrid": "^5.2.3",
"sequelize": "^6.29.0",
"sequelize-cli": "^6.6.0",
"serialize-javascript": "^6.0.1",
"source-map-support": "^0.5.9",
"sqlite3": "^5.1.5",
"universal-router": "^8.1.0",
"uuid": "^3.0.1",
"uuid": "^9.0.0",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
Expand All @@ -94,10 +94,36 @@
"@babel/plugin-transform-react-constant-elements": "^7.20.2",
"@babel/plugin-transform-react-inline-elements": "^7.18.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-flow": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@babel/register": "^7.18.9",
"@jedmao/redux-mock-store": "^3.0.5",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@redux-devtools/extension": "^3.2.5",
"@types/bcrypt": "^5.0.0",
"@types/chai": "^4.3.4",
"@types/compression": "^1.7.2",
"@types/connect-flash": "^0.0.37",
"@types/cookie-parser": "^1.4.3",
"@types/express-session": "^1.17.6",
"@types/express-sslify": "^1.2.2",
"@types/express-ws": "^3.0.1",
"@types/fbjs": "^3.0.4",
"@types/google-map-react": "^2.1.7",
"@types/google.analytics": "^0.0.42",
"@types/google.maps": "^3.52.1",
"@types/method-override": "^0.0.32",
"@types/mocha": "^10.0.1",
"@types/morgan": "^1.9.4",
"@types/node-fetch": "^2.6.2",
"@types/passport": "^1.0.11",
"@types/passport-google-oauth20": "^2.0.11",
"@types/passport-local": "^1.0.35",
"@types/react-dom": "16.9.8",
"@types/uuid": "^9.0.0",
"@types/webpack-env": "^1.18.0",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"assets-webpack-plugin": "^7.1.1",
"autoprefixer": "^9.1.5",
"babel-core": "^7.0.0-bridge.0",
Expand All @@ -112,7 +138,7 @@
"babel-template": "^6.25.0",
"babel-types": "^6.25.0",
"browser-sync": "2.27.11",
"chai": "4.1.2",
"chai": "4.3.7",
"chokidar": "^3.5.3",
"cross-env": "^5.0.1",
"css-loader": "^6.7.3",
Expand All @@ -125,12 +151,13 @@
"eslint": "^8.34.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-import-resolver-node": "^0.3.7",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-css-modules": "^2.11.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^7.3.0",
"git-repository": "^0.1.4",
"glob": "^7.1.3",
"husky": "^8.0.3",
Expand All @@ -147,11 +174,10 @@
"postcss-loader": "^7.0.2",
"proxyquire": "^1.7.11",
"raw-loader": "^0.5.1",
"react-deep-force-update": "^2.1.3",
"react-dev-utils": "^12.0.1",
"react-error-overlay": "^4.0.1",
"react-refresh": "^0.14.0",
"react-test-renderer": "^16.14.0",
"redux-mock-store": "^1.5.1",
"rimraf": "^2.6.2",
"sass": "^1.58.0",
"sass-loader": "^13.2.0",
Expand All @@ -163,6 +189,8 @@
"stylelint-order": "^6.0.2",
"supertest": "^6.3.3",
"svg-url-loader": "^8.0.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"url-loader": "^4.1.1",
"webpack": "^5.76.0",
"webpack-assets-manifest": "^5.1.0",
Expand Down Expand Up @@ -199,8 +227,8 @@
"fix": "npm run fix-js && npm run fix-css",
"test-file": "mocha",
"test-file-ci": "mocha --reporter mocha-junit-reporter",
"test": "npm run test-file \"./src/**/*.test.js\"",
"test-ci": "npm run test-file-ci \"./src/**/*.test.js\"",
"test": "npm run test-file \"./src/**/*.test.{js,ts}\"",
"test-ci": "npm run test-file-ci \"./src/**/*.test.{js,ts}\"",
"test-watch": "npm run test --watch --notify",
"test-cover": "nyc npm run test",
"coverage": "npm run test-cover && open-cli coverage/lcov-report/index.html",
Expand Down Expand Up @@ -231,4 +259,4 @@
"start": "babel-node tools/run start",
"prepare": "husky install"
}
}
}
Empty file added react-deep-force-update.d.ts
Empty file.

0 comments on commit f5dcaa2

Please sign in to comment.