Skip to content

Commit

Permalink
refactor(backend): use node16 for moduleResolution (#10938)
Browse files Browse the repository at this point in the history
* refactor(backend): use node16 for moduleResolution

* update deps

* Update tsconfig.json

* ✌️

* revive KEYWORD

* restore strict-event-emitter-types dependency

* restore ms dependency

* cancel redundant import reorder

* fix

* Delete ms.ts

* remove rndstr

---------

Co-authored-by: Kagami Sascha Rosylight <saschanaz@outlook.com>
  • Loading branch information
syuilo and saschanaz authored Jun 25, 2023
1 parent ef354e9 commit 8099bc2
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 86 deletions.
2 changes: 1 addition & 1 deletion packages/backend/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"paths": {
"@/*": ["*"]
},
"target": "es2021"
"target": "es2022"
},
"minify": false
}
6 changes: 3 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"bcryptjs": "2.4.3",
"blurhash": "2.0.5",
"bullmq": "4.1.0",
"cacheable-lookup": "6.1.0",
"cacheable-lookup": "7.0.0",
"cbor": "9.0.0",
"chalk": "5.2.0",
"chalk-template": "0.4.0",
Expand All @@ -95,7 +95,7 @@
"file-type": "18.5.0",
"fluent-ffmpeg": "2.1.2",
"form-data": "4.0.0",
"got": "12.6.0",
"got": "13.0.0",
"happy-dom": "9.20.3",
"hpagent": "1.2.0",
"ioredis": "5.3.2",
Expand Down Expand Up @@ -137,7 +137,6 @@
"rxjs": "7.8.1",
"s-age": "1.1.2",
"sanitize-html": "2.11.0",
"seedrandom": "3.0.5",
"semver": "7.5.3",
"sharp": "0.32.1",
"sharp-read-bmp": "github:misskey-dev/sharp-read-bmp",
Expand Down Expand Up @@ -178,6 +177,7 @@
"@types/jsonld": "1.5.9",
"@types/jsrsasign": "10.5.8",
"@types/mime-types": "2.1.1",
"@types/ms": "^0.7.31",
"@types/node": "20.3.1",
"@types/node-fetch": "3.0.3",
"@types/nodemailer": "6.4.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/GlobalEventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { Packed } from '@/misc/json-schema.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { bindThis } from '@/decorators.js';
import { Role } from '@/models';
import { Role } from '@/models/index.js';

@Injectable()
export class GlobalEventService {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/LoggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import type { KEYWORD } from 'color-convert/conversions';
import type { KEYWORD } from 'color-convert/conversions.js';

@Injectable()
export class LoggerService {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/PushNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import push from 'web-push';
import * as Redis from 'ioredis';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { Packed } from '@/misc/json-schema';
import type { Packed } from '@/misc/json-schema.js';
import { getNoteSummary } from '@/misc/get-note-summary.js';
import type { SwSubscription, SwSubscriptionsRepository } from '@/models/index.js';
import { MetaService } from '@/core/MetaService.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/RoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { StreamMessages } from '@/server/api/stream/types.js';
import { IdService } from '@/core/IdService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import type { Packed } from '@/misc/json-schema';
import type { Packed } from '@/misc/json-schema.js';
import type { OnApplicationShutdown } from '@nestjs/common';

export type RolePolicies = {
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { In, Not } from 'typeorm';
import * as Redis from 'ioredis';
import Ajv from 'ajv';
import _Ajv from 'ajv';
import { ModuleRef } from '@nestjs/core';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
Expand Down Expand Up @@ -31,6 +31,7 @@ type IsMeAndIsUserDetailed<ExpectsMe extends boolean | null, Detailed extends bo
Packed<'UserDetailed'> :
Packed<'UserLite'>;

const Ajv = _Ajv.default;
const ajv = new Ajv();

function isLocalUser(user: User): user is LocalUser;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { default as convertColor } from 'color-convert';
import { format as dateFormat } from 'date-fns';
import { bindThis } from '@/decorators.js';
import { envOption } from './env.js';
import type { KEYWORD } from 'color-convert/conversions';
import type { KEYWORD } from 'color-convert/conversions.js';

type Context = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, Inject } from '@nestjs/common';
import Ajv from 'ajv';
import _Ajv from 'ajv';
import { IdService } from '@/core/IdService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import Logger from '@/logger.js';
Expand All @@ -10,6 +10,8 @@ import { QueueLoggerService } from '../QueueLoggerService.js';
import { DBAntennaImportJobData } from '../types.js';
import type * as Bull from 'bullmq';

const Ajv = _Ajv.default;

const validate = new Ajv().compile({
type: 'object',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
import { NotificationService } from '@/core/NotificationService.js';
import { bindThis } from '@/decorators.js';
import { CacheService } from '@/core/CacheService.js';
import { LocalUser } from '@/models/entities/User';
import { LocalUser } from '@/models/entities/User.js';
import { AuthenticateService, AuthenticationError } from './AuthenticateService.js';
import MainStreamConnection from './stream/index.js';
import { ChannelsService } from './stream/ChannelsService.js';
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/server/api/endpoint-base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as fs from 'node:fs';
import Ajv from 'ajv';
import _Ajv from 'ajv';
import type { Schema, SchemaType } from '@/misc/json-schema.js';
import type { LocalUser } from '@/models/entities/User.js';
import type { AccessToken } from '@/models/entities/AccessToken.js';
import { ApiError } from './error.js';
import type { IEndpointMeta } from './endpoints.js';

const Ajv = _Ajv.default;

const ajv = new Ajv({
useDefaults: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor (
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,

@Inject(DI.antennasRepository)
private antennasRepository: AntennasRepository,

Expand All @@ -79,6 +79,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
this.queueService.createImportAntennasJob(me, antennas);
});
}
}
}

export type Antenna = (_Antenna & { userListAccts: string[] | null })[];
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const checkMoving = await this.accountMoveService.validateAlsoKnownAs(
me,
(old, src) => !!src.movedAt && src.movedAt.getTime() + 1000 * 60 * 60 * 2 > (new Date()).getTime(),
true
true,
);
if (checkMoving ? file.size > 32 * 1024 * 1024 : file.size > 64 * 1024) throw new ApiError(meta.errors.tooBigFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const checkMoving = await this.accountMoveService.validateAlsoKnownAs(
me,
(old, src) => !!src.movedAt && src.movedAt.getTime() + 1000 * 60 * 60 * 2 > (new Date()).getTime(),
true
true,
);
if (checkMoving ? file.size > 32 * 1024 * 1024 : file.size > 64 * 1024) throw new ApiError(meta.errors.tooBigFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const checkMoving = await this.accountMoveService.validateAlsoKnownAs(
me,
(old, src) => !!src.movedAt && src.movedAt.getTime() + 1000 * 60 * 60 * 2 > (new Date()).getTime(),
true
true,
);
if (checkMoving ? file.size > 32 * 1024 * 1024 : file.size > 64 * 1024) throw new ApiError(meta.errors.tooBigFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const checkMoving = await this.accountMoveService.validateAlsoKnownAs(
me,
(old, src) => !!src.movedAt && src.movedAt.getTime() + 1000 * 60 * 60 * 2 > (new Date()).getTime(),
true
true,
);
if (checkMoving ? file.size > 32 * 1024 * 1024 : file.size > 64 * 1024) throw new ApiError(meta.errors.tooBigFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { UsersRepository, NotesRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteDeleteService } from '@/core/NoteDeleteService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';

export const meta = {
tags: ['notes'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {

@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,

private userEntityService: UserEntityService,
private queryService: QueryService,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as sanitizeHtml from 'sanitize-html';
import sanitizeHtml from 'sanitize-html';
import { Inject, Injectable } from '@nestjs/common';
import type { UsersRepository, AbuseUserReportsRepository } from '@/models/index.js';
import { IdService } from '@/core/IdService.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/stream/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bindThis } from '@/decorators.js';
import type Connection from '.';
import type Connection from './index.js';

/**
* Stream channel
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/server/api/stream/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Page } from '@/models/entities/Page.js';
import type { Packed } from '@/misc/json-schema.js';
import type { Webhook } from '@/models/entities/Webhook.js';
import type { Meta } from '@/models/entities/Meta.js';
import { Role, RoleAssignment } from '@/models';
import { Role, RoleAssignment } from '@/models/index.js';
import type Emitter from 'strict-event-emitter-types';
import type { EventEmitter } from 'events';

Expand Down Expand Up @@ -233,7 +233,7 @@ export type StreamMessages = {

// API event definitions
// ストリームごとのEmitterの辞書を用意
type EventEmitterDictionary = { [x in keyof StreamMessages]: Emitter<EventEmitter, { [y in StreamMessages[x]['name']]: (e: StreamMessages[x]['payload']) => void }> };
type EventEmitterDictionary = { [x in keyof StreamMessages]: Emitter.default<EventEmitter, { [y in StreamMessages[x]['name']]: (e: StreamMessages[x]['payload']) => void }> };
// 共用体型を交差型にする型 https://stackoverflow.com/questions/54938141/typescript-convert-union-to-intersection
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
// Emitter辞書から共用体型を作り、UnionToIntersectionで交差型にする
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": true,
"target": "es2021",
"target": "ES2022",
"module": "es2020",
"moduleResolution": "node",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"noLib": false,
Expand Down Expand Up @@ -39,6 +39,6 @@
"include": [
"./**/*.ts",
"../src/**/*.test.ts",
"../src/@types/**/*.ts",
"../src/@types/**/*.ts"
]
}
6 changes: 3 additions & 3 deletions packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": false,
"target": "es2021",
"module": "esnext",
"moduleResolution": "node",
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"noLib": false,
Expand Down
3 changes: 0 additions & 3 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@
"prismjs": "1.29.0",
"punycode": "2.3.0",
"querystring": "0.2.1",
"rndstr": "1.0.0",
"rollup": "3.25.1",
"s-age": "1.1.2",
"sanitize-html": "2.11.0",
"sass": "1.63.6",
"seedrandom": "3.0.5",
"strict-event-emitter-types": "2.0.0",
"syuilo-password-strength": "0.0.1",
"textarea-caret": "3.1.0",
Expand Down Expand Up @@ -107,7 +105,6 @@
"@types/node": "20.3.1",
"@types/punycode": "2.1.0",
"@types/sanitize-html": "2.9.0",
"@types/seedrandom": "3.0.5",
"@types/testing-library__jest-dom": "^5.14.6",
"@types/throttle-debounce": "5.0.0",
"@types/tinycolor2": "1.4.3",
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": true,
"target": "es2021",
"target": "ES2022",
"module": "es2020",
"moduleResolution": "node",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"noLib": false,
Expand All @@ -27,7 +27,7 @@
"@/*": ["../src/*"]
},
"typeRoots": [
"../node_modules/@types",
"../node_modules/@types"
],
"lib": [
"esnext",
Expand All @@ -38,6 +38,6 @@
"compileOnSave": false,
"include": [
"./**/*.ts",
"../src/**/*.vue",
"../src/**/*.vue"
]
}
4 changes: 2 additions & 2 deletions packages/frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": false,
"target": "es2021",
"target": "ES2022",
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "node16",
"removeComments": false,
"noLib": false,
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/misskey-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "es2022",
"target": "ES2022",
"module": "ES2020",
"moduleResolution": "node",
"moduleResolution": "node16",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand Down
8 changes: 4 additions & 4 deletions packages/sw/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": false,
"target": "es2021",
"target": "ES2022",
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "node16",
"removeComments": false,
"noLib": false,
"strict": true,
Expand All @@ -21,11 +21,11 @@
"isolatedModules": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/*": ["./src/*"]
},
"typeRoots": [
"node_modules/@types",
"@types",
"@types"
],
"lib": [
"esnext",
Expand Down
Loading

0 comments on commit 8099bc2

Please sign in to comment.