Skip to content

Commit

Permalink
Update dependency prettier to v2.3.0 (#420)
Browse files Browse the repository at this point in the history
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Adam <adam@haglund.dev>
  • Loading branch information
3 people authored Jun 3, 2021
1 parent d438a70 commit f4ad42a
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 229 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
node: true,
},
extends: [
'plugin:@beequeue/base',
'plugin:@beequeue/node',
'plugin:@beequeue/typescript',
'plugin:@beequeue/prettier',
"plugin:@beequeue/base",
"plugin:@beequeue/node",
"plugin:@beequeue/typescript",
"plugin:@beequeue/prettier",
],
rules: {
'import/no-named-as-default': 'off',
"import/no-named-as-default": "off",
},
}
26 changes: 13 additions & 13 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
extends: ['config:js-app', 'helpers:disableTypesNodeMajor'],
extends: ["config:js-app", "helpers:disableTypesNodeMajor"],
prConcurrentLimit: 5,
branchConcurrentLimit: 5,
schedule: ['before 11am'],
labels: ['dependencies'],
baseBranches: ['master'],
schedule: ["before 11am"],
labels: ["dependencies"],
baseBranches: ["master"],
automerge: false,
packageRules: [
{
packageNames: ['node'],
allowedVersions: '<13',
rangeStrategy: 'replace',
packageNames: ["node"],
allowedVersions: "<=14",
rangeStrategy: "replace",
},
{
groupName: 'linters',
matchPackageNames: ['eslint'],
groupName: "linters",
matchPackageNames: ["eslint"],
automerge: true,
},
{
groupName: 'testing packages',
matchPackageNames: ['jest', 'test'],
groupName: "testing packages",
matchPackageNames: ["jest", "test"],
automerge: true,
},
{
groupName: '`@types` package patches',
matchPackagePrefixes: ['@types/'],
groupName: "`@types` package patches",
matchPackagePrefixes: ["@types/"],
patch: true,
automerge: true,
},
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 90,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion bin/update.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { updateRelations } from '../src/update'
import { updateRelations } from "../src/update"

void updateRelations()
16 changes: 8 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { pathsToModuleNameMapper } = require('ts-jest/utils')
const { compilerOptions } = require('./tsconfig')
const { pathsToModuleNameMapper } = require("ts-jest/utils")
const { compilerOptions } = require("./tsconfig")

module.exports = {
roots: ['<rootDir>/src'],
preset: 'ts-jest',
moduleFileExtensions: ['js', 'ts'],
roots: ["<rootDir>/src"],
preset: "ts-jest",
moduleFileExtensions: ["js", "ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
prefix: "<rootDir>/",
}),
coveragePathIgnorePatterns: ['sentry.ts', 'utils.ts'],
coveragePathIgnorePatterns: ["sentry.ts", "utils.ts"],
collectCoverage: true,
coverageReporters: ['text', 'text-summary'],
coverageReporters: ["text", "text-summary"],
coverageThreshold: {
global: {
statements: 90,
Expand Down
10 changes: 5 additions & 5 deletions knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const config: import('knex').Knex.Config = {
client: 'sqlite3',
export const config: import("knex").Knex.Config = {
client: "sqlite3",
migrations: {
tableName: 'migrations',
directory: 'migrations',
tableName: "migrations",
directory: "migrations",
},
useNullAsDefault: true,
connection: {
filename: `./sqlite/${process.env.NODE_ENV ?? 'development'}.sqlite3`,
filename: `./sqlite/${process.env.NODE_ENV ?? "development"}.sqlite3`,
},
}

Expand Down
16 changes: 8 additions & 8 deletions migrations/20190611171759_create_tables.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Knex } from 'knex'
import { Knex } from "knex"

export async function up(knex: Knex): Promise<void> {
if (await knex.schema.hasTable('relations')) return
if (await knex.schema.hasTable("relations")) return

const promises: Promise<void>[] = []

promises.push(
knex.schema.createTable('relations', (table) => {
table.integer('anilist').unique()
table.integer('anidb').unique()
table.integer('myanimelist').unique()
table.integer('kitsu').unique()
knex.schema.createTable("relations", (table) => {
table.integer("anilist").unique()
table.integer("anidb").unique()
table.integer("myanimelist").unique()
table.integer("kitsu").unique()
}),
)

await Promise.all(promises)
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists('relations')
await knex.schema.dropTableIfExists("relations")
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"husky": "4.3.8",
"jest": "26.6.3",
"lint-staged": "11.0.0",
"prettier": "2.2.1",
"prettier": "2.3.0",
"supertest": "6.1.3",
"ts-jest": "26.5.6",
"ts-node-dev": "1.1.6",
Expand Down
26 changes: 11 additions & 15 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import Koa, { Context } from 'koa'
import BodyParser from 'koa-bodyparser'
import RequestLogger from 'koa-pino-logger'
import Router from 'koa-router'
import Koa, { Context } from "koa"
import BodyParser from "koa-bodyparser"
import RequestLogger from "koa-pino-logger"
import Router from "koa-router"

import { config } from '@/config'
import { Logger } from '@/lib/logger'
import {
requestHandler,
sendErrorToSentry,
tracingMiddleWare,
} from '@/lib/sentry'
import { config } from "@/config"
import { Logger } from "@/lib/logger"
import { requestHandler, sendErrorToSentry, tracingMiddleWare } from "@/lib/sentry"

import { routes } from './routes'
import { routes } from "./routes"

export const App = new Koa()
const router = new Router()

App.use(
RequestLogger({
prettyPrint: config.NODE_ENV === 'development',
prettyPrint: config.NODE_ENV === "development",
}),
)

App.use(requestHandler)
App.use(tracingMiddleWare)

App.on('error', (err, ctx) => {
App.on("error", (err, ctx) => {
Logger.error(err)

sendErrorToSentry(err, ctx)
})

App.use(BodyParser())

router.get('/', (ctx: Context) => {
router.get("/", (ctx: Context) => {
ctx.body = `
<pre>
<b>Get IDs:</b>
Expand Down
22 changes: 9 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { envsafe, port, str } from 'envsafe'
import { envsafe, port, str } from "envsafe"

export enum Environment {
Development = 'development',
Test = 'test',
Production = 'production',
Development = "development",
Test = "test",
Production = "production",
}

export const config = envsafe({
NODE_ENV: str({
choices: [
Environment.Development,
Environment.Test,
Environment.Production,
],
choices: [Environment.Development, Environment.Test, Environment.Production],
default: Environment.Development,
}),
PORT: port({
devDefault: 3000,
}),
LOG_LEVEL: str({
default: 'info',
devDefault: 'debug',
choices: ['fatal', 'error', 'warn', 'info', 'debug', 'trace'],
default: "info",
devDefault: "debug",
choices: ["fatal", "error", "warn", "info", "debug", "trace"],
}),
USER_AGENT: str({
default: 'arm-server',
default: "arm-server",
}),
})
4 changes: 2 additions & 2 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Knex from 'knex'
import Knex from "knex"

import { config } from '../knexfile'
import { config } from "../knexfile"

export const knex = Knex(config)

Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { captureException } from '@sentry/node'
import { captureException } from "@sentry/node"

import { Logger } from '@/lib/logger'
import { Logger } from "@/lib/logger"

import { App } from './app'
import { updateRelations } from './update'
import { App } from "./app"
import { updateRelations } from "./update"

const { NODE_ENV, PORT } = process.env
const port = PORT ?? 3000

const runUpdateScript = () => updateRelations().catch(captureException)

const listen = () => {
if (NODE_ENV === 'production') {
if (NODE_ENV === "production") {
void runUpdateScript()

// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand Down
6 changes: 3 additions & 3 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Pino from 'pino'
import Pino from "pino"

import { config } from '../config'
import { config } from "../config"

export const Logger = Pino({
level: config.LOG_LEVEL,
prettyPrint: config.NODE_ENV !== 'production',
prettyPrint: config.NODE_ENV !== "production",
})
31 changes: 13 additions & 18 deletions src/lib/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// eslint-disable-next-line node/no-deprecated-api
import domain from 'domain'
import domain from "domain"

import { Context, Next } from 'koa'
import { Context, Next } from "koa"

import * as Sentry from '@sentry/node'
import {
extractTraceparentData,
stripUrlQueryAndFragment,
} from '@sentry/tracing'
import * as Sentry from "@sentry/node"
import { extractTraceparentData, stripUrlQueryAndFragment } from "@sentry/tracing"

const { NODE_ENV, TRACES_SAMPLERATE, SENTRY_DSN } = process.env

Sentry.init({
dsn: SENTRY_DSN,
enabled: NODE_ENV === 'production',
enabled: NODE_ENV === "production",
tracesSampleRate: Number(TRACES_SAMPLERATE ?? 1),
})

Expand All @@ -23,10 +20,10 @@ export const requestHandler = (ctx: Context, next: Next) =>

local.add(ctx as any) // TODO

local.on('error', (err) => {
local.on("error", (err) => {
ctx.status = err.status || 500
ctx.body = err.message
ctx.app.emit('error', err, ctx)
ctx.app.emit("error", err, ctx)
})

void local.run(async () => {
Expand All @@ -45,19 +42,19 @@ export const requestHandler = (ctx: Context, next: Next) =>
})

export const tracingMiddleWare = async (ctx: Context, next: Next) => {
const reqMethod = (ctx.method || '').toUpperCase()
const reqMethod = (ctx.method || "").toUpperCase()
const reqUrl = ctx.url && stripUrlQueryAndFragment(ctx.url)

// connect to trace of upstream app
let traceparentData = null

if (ctx.request.get('sentry-trace')) {
traceparentData = extractTraceparentData(ctx.request.get('sentry-trace'))
if (ctx.request.get("sentry-trace")) {
traceparentData = extractTraceparentData(ctx.request.get("sentry-trace"))
}

const transaction = Sentry.startTransaction({
name: `${reqMethod} ${reqUrl}`,
op: 'http.server',
op: "http.server",
...traceparentData,
})

Expand All @@ -67,10 +64,8 @@ export const tracingMiddleWare = async (ctx: Context, next: Next) => {

// if using koa router, a nicer way to capture transaction using the matched route
if (ctx._matchedRoute) {
const mountPath = (ctx.mountPath as string) || ''
transaction.setName(
`${reqMethod} ${mountPath}${ctx._matchedRoute as string}`,
)
const mountPath = (ctx.mountPath as string) || ""
transaction.setName(`${reqMethod} ${mountPath}${ctx._matchedRoute as string}`)
}

transaction.setHttpStatus(ctx.status)
Expand Down
Loading

0 comments on commit f4ad42a

Please sign in to comment.