Skip to content

Commit

Permalink
Emit .d.ts types for NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Feb 26, 2025
1 parent 72bd8ba commit 62023bd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/crashlogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CRASH_EMAIL_THROTTLE = 5 * 60 * 1000; // 5 minutes
const logPath = path.resolve(
// not sure why this is necessary, but in Windows testing it was
__dirname, '../', __dirname.includes(`${path.sep}dist${path.sep}`) ? '..' : '',
path.join(global.Config?.logsdir || 'logs', 'errors.txt')
path.join((global as any).Config?.logsdir || 'logs', 'errors.txt')
);
let lastCrashLog = 0;
let transport: any;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function crashlogger(
console.error(`\nSUBCRASH: ${err.stack}\n`);
});

const emailOpts = emailConfig || global.Config?.crashguardemail;
const emailOpts = emailConfig || (global as any).Config?.crashguardemail;
if (emailOpts && ((datenow - lastCrashLog) > CRASH_EMAIL_THROTTLE)) {
lastCrashLog = datenow;

Expand Down
2 changes: 1 addition & 1 deletion lib/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class QueryProcessWrapper<T, U> implements ProcessWrapper {
// it's also futureproofing in case other external modfules require this
// we also specifically do not throw here because this json might be sensitive,
// so we only want it to go to emails
global.Monitor?.crashlog?.(e, `a ${path.basename(this.file)} process`, { result: obj });
(global as any).Monitor?.crashlog?.(e, `a ${path.basename(this.file)} process`, { result: obj });
return undefined;
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type ErrorHandler = (error: Error, data: DatabaseQuery, isParentProcess: boolean

function getModule() {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore does not exist while building NPM package???
return require('better-sqlite3') as typeof sqlite.default;
} catch {
return null;
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The server for the Pokémon Showdown battle simulator",
"version": "0.11.9",
"main": "dist/sim/index.js",
"types": "dist/sim/index.d.ts",
"dependencies": {
"esbuild": "^0.16.10",
"mysql2": "^3.9.7",
Expand Down Expand Up @@ -34,6 +35,8 @@
"scripts": {
"start": "node pokemon-showdown start",
"build": "node build",
"build-npm": "npx tsc sim/global-types.ts sim/index.ts --declaration --emitDeclarationOnly --declarationDir dist/ --target es2020 --strict --moduleResolution node --types node --lib es2020",
"test-npm": "npx tsc sim/global-types.ts sim/index.ts --noEmit --target es2020 --strict --moduleResolution node --types node --lib es2020",
"tsc": "tsc",
"lint": "eslint --cache",
"fix": "eslint --cache --fix",
Expand All @@ -42,7 +45,7 @@
"test": "mocha",
"posttest": "npm run tsc",
"full-test": "npm run lint && npm run tsc && mocha --timeout 8000 --forbid-only -g \".*\"",
"full-test-ci": "eslint --max-warnings 0 && tsc && (([ \"$SKIPSIMTESTS\" = true ] && mocha --timeout 8000 --forbid-only -g \".*\" --exclude \"test/{sim,random-battles}/**\") || mocha --timeout 8000 --forbid-only -g \".*\")",
"full-test-ci": "eslint --max-warnings 0 && tsc && (([ \"$SKIPSIMTESTS\" = true ] && mocha --timeout 8000 --forbid-only -g \".*\" --exclude \"test/{sim,random-battles}/**\") || mocha --timeout 8000 --forbid-only -g \".*\") && npm run test-npm",
"postinstall": "npm run build postinstall"
},
"bin": "./pokemon-showdown",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"types": ["node"],
"exclude": [
"/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.dom.d.ts",
"./.*-dist/**/*",
"./dist/**/*",
"./server/chat-plugins/private/*/*.d.ts"
],
"include": [
Expand Down

0 comments on commit 62023bd

Please sign in to comment.