diff --git a/.eslintrc-no-types.json b/.eslintrc-no-types.json index c4fc91a37a66..ea10e103ee36 100644 --- a/.eslintrc-no-types.json +++ b/.eslintrc-no-types.json @@ -14,8 +14,7 @@ "tools/set-import/importer.js", "tools/set-import/sets", "tools/modlog/converter.js", - "server/global-variables.d.ts", - "sim/global-variables.d.ts" + "server/global-variables.d.ts" ], "env": { "es6": true, diff --git a/config/formats.ts b/config/formats.ts index f928750b113a..d8ce473e037c 100644 --- a/config/formats.ts +++ b/config/formats.ts @@ -1307,7 +1307,10 @@ export const Formats: FormatList = [ } const customRules = this.format.customRules || []; if (!customRules.includes('!obtainableabilities')) customRules.push('!obtainableabilities'); - // const TeamValidator: new (format: string | Format) => TeamValidator = this.constructor as TeamValidator; + + const TeamValidator: typeof import('../sim/team-validator').TeamValidator = + require('../sim/team-validator').TeamValidator; + const validator = new TeamValidator(dex.getFormat(`${this.format.id}@@@${customRules.join(',')}`)); const moves = set.moves; set.moves = [ability.id]; diff --git a/server/chat-plugins/datasearch.ts b/server/chat-plugins/datasearch.ts index 3508476cd62c..d095d1ba47fa 100644 --- a/server/chat-plugins/datasearch.ts +++ b/server/chat-plugins/datasearch.ts @@ -10,6 +10,7 @@ import {QueryProcessManager} from '../../lib/process-manager'; import {Utils} from '../../lib/utils'; +import {TeamValidator} from '../../sim/team-validator'; interface DexOrGroup { abilities: {[k: string]: boolean}; @@ -2423,7 +2424,6 @@ if (!PM.isParentProcess) { global.Chat = require('../chat').Chat; global.toID = Dex.toID; Dex.includeData(); - global.TeamValidator = require('../../sim/team-validator').TeamValidator; // @ts-ignore require('../../lib/repl').Repl.start('dexsearch', cmd => eval(cmd)); // eslint-disable-line no-eval diff --git a/server/global-variables.d.ts b/server/global-variables.d.ts index 4824734d80fc..b84906fceb42 100644 --- a/server/global-variables.d.ts +++ b/server/global-variables.d.ts @@ -1,6 +1,5 @@ import * as ChatType from './chat'; import * as RoomsType from './rooms'; -import * as RoomlogsType from './roomlogs'; import * as SocketsType from './sockets'; import * as TeamValidatorAsyncType from './team-validator-async'; import * as UsersType from './users'; @@ -9,13 +8,14 @@ import * as VerifierType from './verifier'; import {ConfigType} from "../server/config-loader"; import {IPTools as IPToolsType} from './ip-tools'; -import {LadderStore as LadderStoreType} from './ladders-remote'; import {Ladders as LaddersType} from './ladders'; import {LoginServer as LoginServerType} from './loginserver'; import {Monitor as MonitorType} from './monitor'; import {Punishments as PunishmentsType} from './punishments'; import {Tournaments as TournamentsType} from './tournaments'; +import {Dex as DexType} from '../sim/dex'; + declare global { namespace NodeJS { interface Global { @@ -30,7 +30,6 @@ declare global { Punishments: any; Rooms: any; Sockets: any - TeamValidator: any; TeamValidatorAsync: any; Tournaments: any; Users: any; @@ -41,18 +40,17 @@ declare global { } const Config: ConfigType; const Chat: typeof ChatType.Chat; + const Dex: typeof DexType; const IPTools: typeof IPToolsType; const Ladders: typeof LaddersType; - const LadderStoreT: typeof LadderStoreType; const LoginServer: typeof LoginServerType; const Monitor: typeof MonitorType; const Punishments: typeof PunishmentsType; + const Rooms: typeof RoomsType.Rooms; const Sockets: typeof SocketsType.Sockets; const TeamValidatorAsync: typeof TeamValidatorAsyncType; - const Rooms: typeof RoomsType.Rooms; const Tournaments: typeof TournamentsType; - const Roomlogs: typeof RoomlogsType.Roomlogs; const Users: typeof UsersType.Users; const Verifier: typeof VerifierType; - const toID: typeof Dex.toID; + const toID: typeof DexType.toID; } diff --git a/server/ladders.ts b/server/ladders.ts index 6486bc15d02e..47859ddbfc52 100644 --- a/server/ladders.ts +++ b/server/ladders.ts @@ -8,9 +8,9 @@ * @license MIT */ -const LadderStore: typeof LadderStoreT = (typeof Config === 'object' && Config.remoteladder ? - require('./ladders-remote') : - require('./ladders-local')).LadderStore; +const LadderStore: typeof import('./ladders-remote').LadderStore = ( + typeof Config === 'object' && Config.remoteladder ? require('./ladders-remote') : require('./ladders-local') +).LadderStore; const SECONDS = 1000; const PERIODIC_MATCH_INTERVAL = 60 * SECONDS; diff --git a/server/team-validator-async.ts b/server/team-validator-async.ts index 69d8c868ea5f..e74647810f8f 100644 --- a/server/team-validator-async.ts +++ b/server/team-validator-async.ts @@ -8,6 +8,7 @@ */ import {crashlogger} from '../lib/crashlogger'; +import {TeamValidator} from '../sim/team-validator'; export class TeamValidatorAsync { format: Format; @@ -68,15 +69,9 @@ export const PM = new QueryProcessManager<{ return '1' + packedTeam; }); -import {Repl} from '../lib/repl'; -import {TeamValidator} from '../sim/team-validator'; -import {Config} from './config-loader'; - if (!PM.isParentProcess) { // This is a child process! - global.Config = Config; - - global.TeamValidator = TeamValidator; + global.Config = require('./config-loader'); global.Monitor = { crashlog(error: Error, source = 'A team validator process', details: AnyObject | null = null) { @@ -97,7 +92,7 @@ if (!PM.isParentProcess) { global.Dex = require('../sim/dex').Dex.includeData(); // eslint-disable-next-line no-eval - Repl.start(`team-validator-${process.pid}`, cmd => eval(cmd)); + require('../lib/repl').Repl.start(`team-validator-${process.pid}`, (cmd: string) => eval(cmd)); } else { PM.spawn(global.Config ? Config.validatorprocesses : 1); } diff --git a/sim/global-variables.d.ts b/sim/global-variables.d.ts deleted file mode 100644 index d3ae0a24e2a4..000000000000 --- a/sim/global-variables.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -import {Battle as BattleType} from './battle'; -import * as BattleStreamType from './battle-stream'; -import * as DataType from './dex-data'; -import {Dex as DexType} from './dex'; -import * as SimType from './index'; -import {Field as FieldType} from './field'; -import {Pokemon as PokemonType} from './pokemon'; -import {PRNG as PRNGType} from './prng'; -import {Side as SideType} from './side'; -import {TeamValidator as TeamValidatorType} from './team-validator'; - -declare global { - namespace NodeJS { - interface Global { - __version: {head: string, origin?: string, tree?: string} - } - } - const Battle: BattleType; - const BattleStream: BattleStreamType.BattleStream; - const Dex: typeof DexType; - const Field: FieldType; - const ModdedDex: typeof DexType; - const PRNG: PRNGType; - const Pokemon: PokemonType; - const Side: SideType; - const Sim: typeof SimType; - const TeamValidator: typeof TeamValidatorType; - - const Ability: DataType.Ability; - const BasicEffect: DataType.BasicEffect; - const Format: DataType.Format; - const Item: DataType.Item; - const Move: DataType.Move; - const Condition: DataType.Condition; - const RuleTable: DataType.RuleTable; - const Species: DataType.Species; - const TypeInfo: DataType.TypeInfo; -}