Skip to content

Commit 62023bd

Browse files
committed
Emit .d.ts types for NPM package
1 parent 72bd8ba commit 62023bd

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

lib/crashlogger.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const CRASH_EMAIL_THROTTLE = 5 * 60 * 1000; // 5 minutes
1616
const logPath = path.resolve(
1717
// not sure why this is necessary, but in Windows testing it was
1818
__dirname, '../', __dirname.includes(`${path.sep}dist${path.sep}`) ? '..' : '',
19-
path.join(global.Config?.logsdir || 'logs', 'errors.txt')
19+
path.join((global as any).Config?.logsdir || 'logs', 'errors.txt')
2020
);
2121
let lastCrashLog = 0;
2222
let transport: any;
@@ -50,7 +50,7 @@ export function crashlogger(
5050
console.error(`\nSUBCRASH: ${err.stack}\n`);
5151
});
5252

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

lib/process-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class QueryProcessWrapper<T, U> implements ProcessWrapper {
163163
// it's also futureproofing in case other external modfules require this
164164
// we also specifically do not throw here because this json might be sensitive,
165165
// so we only want it to go to emails
166-
global.Monitor?.crashlog?.(e, `a ${path.basename(this.file)} process`, { result: obj });
166+
(global as any).Monitor?.crashlog?.(e, `a ${path.basename(this.file)} process`, { result: obj });
167167
return undefined;
168168
}
169169
}

lib/sql.ts

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type ErrorHandler = (error: Error, data: DatabaseQuery, isParentProcess: boolean
6262

6363
function getModule() {
6464
try {
65+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66+
// @ts-ignore does not exist while building NPM package???
6567
return require('better-sqlite3') as typeof sqlite.default;
6668
} catch {
6769
return null;

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "The server for the Pokémon Showdown battle simulator",
44
"version": "0.11.9",
55
"main": "dist/sim/index.js",
6+
"types": "dist/sim/index.d.ts",
67
"dependencies": {
78
"esbuild": "^0.16.10",
89
"mysql2": "^3.9.7",
@@ -34,6 +35,8 @@
3435
"scripts": {
3536
"start": "node pokemon-showdown start",
3637
"build": "node build",
38+
"build-npm": "npx tsc sim/global-types.ts sim/index.ts --declaration --emitDeclarationOnly --declarationDir dist/ --target es2020 --strict --moduleResolution node --types node --lib es2020",
39+
"test-npm": "npx tsc sim/global-types.ts sim/index.ts --noEmit --target es2020 --strict --moduleResolution node --types node --lib es2020",
3740
"tsc": "tsc",
3841
"lint": "eslint --cache",
3942
"fix": "eslint --cache --fix",
@@ -42,7 +45,7 @@
4245
"test": "mocha",
4346
"posttest": "npm run tsc",
4447
"full-test": "npm run lint && npm run tsc && mocha --timeout 8000 --forbid-only -g \".*\"",
45-
"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 \".*\")",
48+
"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",
4649
"postinstall": "npm run build postinstall"
4750
},
4851
"bin": "./pokemon-showdown",

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"types": ["node"],
2323
"exclude": [
2424
"/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.dom.d.ts",
25-
"./.*-dist/**/*",
25+
"./dist/**/*",
2626
"./server/chat-plugins/private/*/*.d.ts"
2727
],
2828
"include": [

0 commit comments

Comments
 (0)