Skip to content

Commit

Permalink
Merge pull request #218 from UN-OCHA/HPC-9238
Browse files Browse the repository at this point in the history
HPC-9238: Upgrade to Node.js v20
  • Loading branch information
Pl217 authored Nov 6, 2023
2 parents 12f76d4 + 676fb02 commit 3a67933
Show file tree
Hide file tree
Showing 37 changed files with 838 additions and 539 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.json
# build artifacts
schema.graphql
.eslintrc.js
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const baseConfig = require('@unocha/hpc-repo-tools/eslintrc.base');

module.exports = {
...baseConfig,
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
overrides: [
...baseConfig.overrides,
{
files: ['*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'unicorn/prefer-module': 'off',
},
},
],
};
6 changes: 0 additions & 6 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
82d3b42643c6d2ebfb2b130e070618aaaf32ba3f
f1f7def10f8fc5c9c4e2dc7626e6bae811d4eab9
a99457116c7bf7553283f5bc49e64385aae9492a
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
timeout-minutes: 25
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/setup-node@v3
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'
- name: Install packages
run: yarn install --frozen-lockfile
- name: TypeScript compiler checks
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -23,7 +23,7 @@ jobs:

- name: Login to Public ECR
if: ${{ github.actor != 'dependabot[bot]' }}
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.HPC_ECR_AWS_ACCESS_KEY_ID }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open-source.

## Prerequisites

- node v18
- node v20
- yarn

## Running Locally
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/unocha/nodejs:18-alpine
FROM public.ecr.aws/unocha/nodejs:20-alpine

ARG COMMIT_SHA
ARG TREE_SHA
Expand Down
12 changes: 6 additions & 6 deletions config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ export const CONFIG = {
},
},
local: {
uploadDirectory: process.env.UPLOAD_DIRECTORY || 'media',
uploadDirectory: process.env.UPLOAD_DIRECTORY ?? 'media',
},
},
mediaURI: process.env.MEDIA_PATH || 'media',
mediaURI: process.env.MEDIA_PATH ?? 'media',
uploadTo: 'aws',
name: process.env.NODE_ENV,
authBaseUrl: process.env.AUTHBASE_URL,
db: {
connection: process.env.POSTGRES_SERVER,
logging: !!parseInt(process.env.POSTGRES_LOGGING || ''),
logging: !!parseInt(process.env.POSTGRES_LOGGING ?? ''),
poolMin: 2,
poolMax: 10,
poolIdle: 10000,
poolIdle: 10_000,
},
logging: {
mode: process.env.LOG_MODE || 'live',
path: process.env.LOG_PATH || '/var/log/api/api.log',
mode: process.env.LOG_MODE ?? 'live',
path: process.env.LOG_PATH ?? '/var/log/api/api.log',
color:
process.env.LOG_COLOR === undefined
? undefined
Expand Down
2 changes: 1 addition & 1 deletion env/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/unocha/nodejs:18-alpine
FROM public.ecr.aws/unocha/nodejs:20-alpine

RUN apk add -U build-base python3 py-pip

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
"lint": "yarn lint-prettier && yarn lint-eslint"
},
"dependencies": {
"@unocha/hpc-api-core": "^6.0.0",
"@unocha/hpc-api-core": "^7.0.0",
"apollo-server-hapi": "^3.12.0",
"bunyan": "^1.8.15",
"class-validator": "^0.14.0",
"graphql": "^15.7.2",
"knex": "0.21.1",
"pg": "^8.10.0",
"pg": "^8.11.3",
"pm2": "^5.3.0",
"reflect-metadata": "^0.1.13",
"ts-node": "^10.9.1",
"type-graphql": "^1.1.1",
"typedi": "^0.10.0",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"devDependencies": {
"@hapi/hapi": "^20.2.1",
"@types/bunyan": "^1.8.8",
"@types/hapi__hapi": "^20.0.9",
"@types/node": "^18.16.19",
"@unocha/hpc-repo-tools": "^3.0.1",
"eslint": "^8.44.0",
"@types/node": "^20.8.10",
"@unocha/hpc-repo-tools": "^4.0.0",
"eslint": "^8.52.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "2.8.8",
"lint-staged": "^15.0.2",
"prettier": "3.0.3",
"ts-node-dev": "^2.0.0"
},
"engines": {
"node": ">=18.16.1",
"node": ">=18.18.2 || >=20.9.0",
"yarn": ">=1.22.10"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions src/common-libs/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request } from '@hapi/hapi';
import { type Request } from '@hapi/hapi';
import { BASIC_AUTH_USER } from '@unocha/hpc-api-core/src/auth';
import { BadRequestError } from '@unocha/hpc-api-core/src/util/error';

Expand All @@ -8,7 +8,7 @@ interface BasicAuth {
}

const parseBasic = (credentialsPart: string): BasicAuth => {
let pieces: (string | null)[];
let pieces: Array<string | null>;

const decoded = Buffer.from(credentialsPart, 'base64').toString('utf8');

Expand Down
6 changes: 3 additions & 3 deletions src/common-libs/auth/permission-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { actionIsPermitted } from '@unocha/hpc-api-core/src/auth';
import { RequiredPermissionsCondition } from '@unocha/hpc-api-core/src/auth/permissions';
import { Context } from '@unocha/hpc-api-core/src/lib/context';
import { type RequiredPermissionsCondition } from '@unocha/hpc-api-core/src/auth/permissions';
import { type Context } from '@unocha/hpc-api-core/src/lib/context';
import { ForbiddenError } from '@unocha/hpc-api-core/src/util/error';
import { createMethodDecorator, ResolverData } from 'type-graphql';
import { createMethodDecorator, type ResolverData } from 'type-graphql';

type RequiredPermissions = (
resolverData: ResolverData<Context>
Expand Down
Empty file.
14 changes: 7 additions & 7 deletions src/common-libs/logging/context.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bunyan from 'bunyan';
import { format } from 'util';
import { LogData, LogDataAfterContextProcessing } from './data';
import type bunyan from 'bunyan';
import { format } from 'node:util';
import type { LogData, LogDataAfterContextProcessing } from './data';
import merge = require('lodash/merge');

import {
LogMethod,
import type {
LogContext as LogContextInterface,
LogMethod,
} from '@unocha/hpc-api-core/src/lib/logging';

export type LogContextHandler = (
Expand Down Expand Up @@ -35,10 +35,10 @@ export class LogContext implements LogContextInterface<LogData> {
const data: LogDataAfterContextProcessing = merge(
{},
this.context,
opts?.data || {},
opts?.data ?? {},
opts?.error
? {
stackTrace: opts.error.stack || format(opts.error),
stackTrace: opts.error.stack ?? format(opts.error),
}
: {}
);
Expand Down
2 changes: 1 addition & 1 deletion src/common-libs/logging/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SharedLogData } from '@unocha/hpc-api-core/src/lib/logging';
import { type SharedLogData } from '@unocha/hpc-api-core/src/lib/logging';

/**
* Structured json data that can be included along with log messages
Expand Down
32 changes: 16 additions & 16 deletions src/common-libs/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bunyan from 'bunyan';
import { format } from 'util';
import { promises as fs } from 'fs';
import * as path from 'path';
import { promises as fs } from 'node:fs';
import * as path from 'node:path';
import { format } from 'node:util';

import { CONFIG } from '../../../config';
import { LogContext } from './context';
import { LogDataAfterBunyanProcessing } from './data';
import { type LogDataAfterBunyanProcessing } from './data';
import { printLog } from './printing';

interface LoggingConfig {
Expand All @@ -23,7 +23,7 @@ const LOGGING_MODES = ['live', 'liveDetailed', 'devServer', 'test'] as const;
type LoggingMode = (typeof LOGGING_MODES)[number];

const isLoggingMode = (mode: string): mode is LoggingMode =>
LOGGING_MODES.indexOf(mode as LoggingMode) > -1;
LOGGING_MODES.includes(mode as LoggingMode);

/**
* Standard logging configurations
Expand Down Expand Up @@ -86,8 +86,8 @@ const isLogDirectoryReady = async () => {
} else {
return true;
}
} catch (e) {
if (isNodeError(e) && e.code === 'ENOENT') {
} catch (error) {
if (isNodeError(error) && error.code === 'ENOENT') {
console.error(
`Unable to write log file at ${CONFIG.logging.path}, directory doesn't exist`
);
Expand All @@ -112,20 +112,20 @@ export const initializeLogging = async (): Promise<LogContext> => {
level: 0,
stream: {
write: (obj: LogDataAfterBunyanProcessing) => {
listeners.forEach((l) => l(obj));
for (const l of listeners) {
l(obj);
}
},
} as any,
};

const streams: bunyan.Stream[] = [loggingListenerStream];

if (logConfig.writeToFile) {
if (await isLogDirectoryReady()) {
streams.push({
level: logConfig.writeToFile,
path: CONFIG.logging.path,
});
}
if (logConfig.writeToFile && (await isLogDirectoryReady())) {
streams.push({
level: logConfig.writeToFile,
path: CONFIG.logging.path,
});
}

if (logConfig.writeToStdout) {
Expand All @@ -141,7 +141,7 @@ export const initializeLogging = async (): Promise<LogContext> => {
}

const logger = bunyan.createLogger({
name: CONFIG.name || 'hpc-api',
name: CONFIG.name ?? 'hpc-api',
streams,
});

Expand Down
33 changes: 13 additions & 20 deletions src/common-libs/logging/printing.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import bunyan from 'bunyan';
import { LogDataAfterBunyanProcessing } from './data';
import { type LogDataAfterBunyanProcessing } from './data';

const printLevel = (obj: LogDataAfterBunyanProcessing, useColor: boolean) => {
if (obj.level >= bunyan.FATAL) {
return (useColor ? '\x1b[0;31;1m' : '') + '[FATAL]';
return `${useColor ? '\u001B[0;31;1m' : ''}[FATAL]`;
}
if (obj.level >= bunyan.ERROR) {
return (useColor ? '\x1b[0;31;1m' : '') + '[ERROR]';
return `${useColor ? '\u001B[0;31;1m' : ''}[ERROR]`;
}
if (obj.level >= bunyan.WARN) {
return (useColor ? '\x1b[0;33;1m' : '') + '[WARN]';
return `${useColor ? '\u001B[0;33;1m' : ''}[WARN]`;
}
if (obj.level >= bunyan.INFO) {
return (useColor ? '\x1b[0;36;1m' : '') + '[INFO]';
return `${useColor ? '\u001B[0;36;1m' : ''}[INFO]`;
}
if (obj.level >= bunyan.DEBUG) {
return '[DEBUG]';
Expand All @@ -28,23 +28,16 @@ export const printLog = (
) => {
process.stdout.write(
// Make Dim
(useColor ? '\x1b[2m' : '') +
`${
useColor ? '\u001B[2m' : ''
// Time
'[' +
obj.time.getHours() +
':' +
obj.time.getMinutes() +
':' +
obj.time.getSeconds() +
':' +
obj.time.getMilliseconds() +
'] ' +
printLevel(obj, useColor) +
' ' +
}[${obj.time.getHours()}:${obj.time.getMinutes()}:${obj.time.getSeconds()}:${obj.time.getMilliseconds()}] ${printLevel(
obj,
useColor
)} ${
// Reset colors
(useColor ? '\x1b[0m' : '') +
obj.msg +
'\n'
useColor ? '\u001B[0m' : ''
}${obj.msg}\n`
);
if (obj.stackTrace) {
process.stdout.write(
Expand Down
8 changes: 4 additions & 4 deletions src/common-libs/plan/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Database } from '@unocha/hpc-api-core/src/db';
import { PlanReportingPeriodId } from '@unocha/hpc-api-core/src/db/models/planReportingPeriod';
import { InstanceDataOfModel } from '@unocha/hpc-api-core/src/db/util/raw-model';
import { type Database } from '@unocha/hpc-api-core/src/db';
import { type PlanReportingPeriodId } from '@unocha/hpc-api-core/src/db/models/planReportingPeriod';
import { type InstanceDataOfModel } from '@unocha/hpc-api-core/src/db/util/raw-model';
import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types';
import { AddPlanTagInput } from '../../domain-services/plan-tag/graphql/types';
import { type AddPlanTagInput } from '../../domain-services/plan-tag/graphql/types';

export const getNextTag = async (
models: Database,
Expand Down
Loading

0 comments on commit 3a67933

Please sign in to comment.