Skip to content

Commit

Permalink
[extended] convert server/ to TypeScript (#1232)
Browse files Browse the repository at this point in the history
* npm i typescript

* npm install typescript --save-dev

* add tsconfig.json

* configure tsconfig, add build script, ignore dist dir

* add license in packaged.json

* npm i --save-dev @types/node

* convert config.ts to typescript

* add npm run type:check:watch command

* convert log.ts with inferred types

* npm i --save-dev @types/underscore

* Revert "npm i --save-dev @types/underscore"

This reverts commit 0ef521b.

* npm i --save-dev @types/underscore

* fix errors in log.ts

* add type declaration for google-cloud__translate

* declare module 'boolean';

* convert comments

* Revert "convert comments"

This reverts commit c7f7e87.

* rename comment.js --> comment.ts

* convert comment

* common.js -> common.ts

* type utils/common

* constants.js -> constants.ts

* cookies.js -> cookies.ts

* type cookies

* metered.js -> metered.ts

* type metered.ts

* first pass type parameter.ts

* senders.js -> senders.ts

* convert email/senders

* password.js --> password.ts

* convert auth/password

* create-user.js -> create-user.ts

* convert auth/create-user

* sql.js --> sql.ts

* pg-query.js -> pg-query.ts

* prefer ts-ignore

* prettier format remaining js files with vscode prettier plugin

* npm i --save-dev prettier

* add prettier npm scripts and config

* check formatting in npm run test script

* session.js --> session.ts

* type session

* user.js --> user.ts

* add default export for log

* sort imports for user

* 0 ts errors for user

* conversation.js --> conversation.ts

* first pass at types for conversation. convert exports for user and conversation to ES2020

* server.js -> server.ts

* infer all types from usage for server

* use intermediate variable with type string[] to ensure that filename is in fact always a string and only a string

* server down to 355 ts errors

* down to 230 errors in server.ts

* fix object is possibly undefined errors. 218 ts errors in server.ts

* 143 errors in server.ts

* 132 errors, fix string | undefined errors

* 132 errors, fix deleted property must be optional errors

* 129 errors, fix Type 'undefined' cannot be used as an index type

* use intermediate variables to clean up referrer decoding

* first refParts, then resultRef

* add missing METRICS_IN_RAM import

* fix Argument of type 'string | any[]'... errors

* fix type mismatch in fb auth function

* fix new expression which lacks context types error

* widen User type

* fix expected number of arguments errors

* fix Object is possibly null errors

* fix Cannot find name err errors

* fix does not exist on type string errors

* untangle User and Conversation, fix collision between types and non-stander PascalCase imports

* fix property does not exist on error

* add Demo type

* fix possibly undefined

* add Vote type

* add Assignment type

* 20 errors in server

* 9 errors in server.ts

* 0 errors in server.ts

* app.js -> app.ts

* install missing types for bluebird and express libraries

* add @ts-nocheck and comment about refactoring for app.ts

* convert all module.exports and requires to import, export syntax. back up to 186 typescript errors

* add types for fb

* ignore new expression whose target lacks a construct signature errors for now

* down to 111 typescript errors

* fix argument of type typescript errors

* label object is of type unknown errors

* 0 typescript errors

* npm i typescript

* npm install typescript --save-dev

* add tsconfig.json

* configure tsconfig, add build script, ignore dist dir

* add license in packaged.json

* npm i --save-dev @types/node

* convert config.ts to typescript

* add npm run type:check:watch command

* convert log.ts with inferred types

* npm i --save-dev @types/underscore

* Revert "npm i --save-dev @types/underscore"

This reverts commit 0ef521b.

* npm i --save-dev @types/underscore

* fix errors in log.ts

* add type declaration for google-cloud__translate

* declare module 'boolean';

* convert comments

* Revert "convert comments"

This reverts commit c7f7e87.

* rename comment.js --> comment.ts

* convert comment

* common.js -> common.ts

* type utils/common

* constants.js -> constants.ts

* cookies.js -> cookies.ts

* type cookies

* metered.js -> metered.ts

* type metered.ts

* first pass type parameter.ts

* senders.js -> senders.ts

* convert email/senders

* password.js --> password.ts

* convert auth/password

* create-user.js -> create-user.ts

* convert auth/create-user

* sql.js --> sql.ts

* pg-query.js -> pg-query.ts

* prefer ts-ignore

* prettier format remaining js files with vscode prettier plugin

* npm i --save-dev prettier

* add prettier npm scripts and config

* check formatting in npm run test script

* session.js --> session.ts

* type session

* user.js --> user.ts

* add default export for log

* sort imports for user

* 0 ts errors for user

* conversation.js --> conversation.ts

* first pass at types for conversation. convert exports for user and conversation to ES2020

* server.js -> server.ts

* infer all types from usage for server

* use intermediate variable with type string[] to ensure that filename is in fact always a string and only a string

* server down to 355 ts errors

* down to 230 errors in server.ts

* fix object is possibly undefined errors. 218 ts errors in server.ts

* 143 errors in server.ts

* 132 errors, fix string | undefined errors

* 132 errors, fix deleted property must be optional errors

* 129 errors, fix Type 'undefined' cannot be used as an index type

* use intermediate variables to clean up referrer decoding

* first refParts, then resultRef

* add missing METRICS_IN_RAM import

* fix Argument of type 'string | any[]'... errors

* fix type mismatch in fb auth function

* fix new expression which lacks context types error

* widen User type

* fix expected number of arguments errors

* fix Object is possibly null errors

* fix Cannot find name err errors

* fix does not exist on type string errors

* untangle User and Conversation, fix collision between types and non-stander PascalCase imports

* fix property does not exist on error

* add Demo type

* fix possibly undefined

* add Vote type

* add Assignment type

* 20 errors in server

* 9 errors in server.ts

* 0 errors in server.ts

* app.js -> app.ts

* install missing types for bluebird and express libraries

* add @ts-nocheck and comment about refactoring for app.ts

* convert all module.exports and requires to import, export syntax. back up to 186 typescript errors

* add types for fb

* ignore new expression whose target lacks a construct signature errors for now

* down to 111 typescript errors

* fix argument of type typescript errors

* label object is of type unknown errors

* 0 typescript errors

* update Procfile to include build step and dist dir

* update pg-connection-string from v2.0.0 to v2.5.0

* fix pgConnectionString arg undefined bug

* disambiguate pg postgress library and dbPgQuery custom wrapper

* add npm run start script for server

* update to intercom-client@2.11.2

* add build:watch script

* add additional check that process.env.INTERCOM_ACCESS_TOKEN is defined before trying to create a new Intercom client

* run build as part of start script, add new run:dev script

* add npm install to start command

* run:dev --> serve:dev

* fix makefile and dockerfile, remove xip.io, run build and use dist dir

* rename serve:dev serve

* call npm run serve in dockerfile

* fix typescript config

* fix usage of npm run serve in start command

* move build command to later in server dockerfile

* switch back to CommonJS bundle type

* use outDir instead of outFile since CommonJS doesn't support outFile

* adding types

* dockerfile additions to ensure install

* add nodemon

* adding moderation types

* first try connecting vscode debug to node inside docker config

* auto generated vscode

* move inspect into command

* 9229

* expose port, build command in docker

* 9229 again

* successful debug attach

* Added non-default export to pg-query.ts to allow function to be loaded in server.js.

* Bugfix: Don't type iterator in for loop, as it compiled to void(0) aka undefined.

* Bugfix: Loaded DEV_MODE envvar using prior get() func.

Co-authored-by: micahstubbs <micah.stubbs@gmail.com>
Co-authored-by: Colin Megill <colinmegill@gmail.com>
  • Loading branch information
3 people authored Dec 13, 2021
1 parent 4f28ef7 commit 9a29414
Show file tree
Hide file tree
Showing 42 changed files with 11,974 additions and 11,322 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"protocol": "inspector",
"remoteRoot": "/app",
"localRoot": "${workspaceFolder}/server",
"restart": true
},
{
"name": "Docker Node.js Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"platform": "node",
"node": {
"package": "${workspaceFolder}/server/package.json",
"localRoot": "${workspaceFolder}/server"
}
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "node",
"dockerBuild": {
"dockerfile": "${workspaceFolder}/server/Dockerfile",
"context": "${workspaceFolder}/server",
"pull": true
},
"node": {
"package": "${workspaceFolder}/server/package.json"
}
},
{
"type": "docker-run",
"label": "docker-run: release",
"dependsOn": ["docker-build"],
"platform": "node",
"node": {
"package": "${workspaceFolder}/server/package.json"
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"dockerRun": {
"env": {
"DEBUG": "*",
"NODE_ENV": "development"
}
},
"node": {
"package": "${workspaceFolder}/server/package.json",
"enableDebugging": true
}
}
]
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

BASEURL ?= https://127.0.0.1.sslip.io
E2E_RUN = cd e2e; CYPRESS_BASE_URL=$(BASEURL)

Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: sh -c 'cd server && node --max_old_space_size=400 --gc_interval=100 --harmony app.js'
web: sh -c 'cd server && npm i && npm run build && node --max_old_space_size=400 --gc_interval=100 --harmony dist/app.js'
12 changes: 12 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.4"

services:
polis:
image: polis
build:
context: server
dockerfile: ./Dockerfile
environment:
NODE_ENV: development

command: ["npm", "run", "dev"]
6 changes: 6 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ version: "3.1"
# * Definitely want to have different env var files for prod vs dev

services:
server:
command: npm run dev
volumes:
- "./server:/app"
ports:
- "9229:9229"
math:
command: clojure -X:dev-poller
volumes:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ services:
- "polis-net"
ports:
- "5000:5000"
- "9229:9229"

math:
container_name: polis-math
Expand Down
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.google_creds_temp
npm-debug.log
node_modules
dist/*
3 changes: 3 additions & 0 deletions server/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
10 changes: 7 additions & 3 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ FROM node:14.14.0-alpine

WORKDIR /app

RUN apk add postgresql-dev
RUN apk add postgresql-dev python-dev build-base

RUN apk add --no-cache --virtual .build \
g++ git make python

COPY package*.json ./

# TODO get `npm ci` to work
RUN npm install

RUN apk del .build

COPY . .

EXPOSE 5000
# For vscode debug
EXPOSE 9229

This comment has been minimized.

Copy link
@metasoarous

metasoarous Apr 13, 2022

Member

As mentioned below, this should really be in the docker-compose.dev.yml overlay. Resolving this on fc95762.

See #555 for issue tracking this.



CMD node --max_old_space_size=400 --gc_interval=100 --harmony app.js
# CMD npm run build && npm run serve
CMD npm run build:watch && npm run serve

This comment has been minimized.

Copy link
@metasoarous

metasoarous Apr 13, 2022

Member

Note; We actually do not want this here, as this would end up in production. This should have been moved to the docker-compose.dev.yml overlay. Working on fixing this now (see 6ab90cd).

See #555 for issue tracking this more generally.

Loading

0 comments on commit 9a29414

Please sign in to comment.