Skip to content

Commit 62e257a

Browse files
committed
fix(ci): Deploy should now work with TS
1 parent 50525b3 commit 62e257a

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

scripts/dbRefresh.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readdirSync, readFileSync } from 'fs';
2-
import { MongoClient, Collection, Db } from 'mongodb'; // Import MongoClient and types
2+
import { MongoClient, Collection, Db, MongoServerError } from 'mongodb'; // Import MongoClient and types
33
// Import utilities and constants
44
import {
55
checkMongoUri,
@@ -77,7 +77,7 @@ async function _processFileForRefresh(
7777
await collection.drop();
7878
console.log(` Dropped existing collection '${collectionName}'.`);
7979
} catch (err) {
80-
if (err.codeName !== 'NamespaceNotFound') {
80+
if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) {
8181
console.error(` Error dropping collection '${collectionName}':`, err);
8282
// Decide if we should stop the whole process - maybe throw here?
8383
return null; // Indicate failure
@@ -117,7 +117,7 @@ async function _refreshIndexCollection(
117117
await collectionsCollection.drop();
118118
console.log(` Dropped existing collection '${collectionsCollectionName}'.`);
119119
} catch (err) {
120-
if (err.codeName !== 'NamespaceNotFound') {
120+
if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) {
121121
console.error(` Error dropping collection '${collectionsCollectionName}':`, err);
122122
throw err; // Throw if dropping index fails unexpectedly
123123
}

scripts/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"noImplicitAny": true,
88
"module": "CommonJS",
99
"moduleResolution": "node",
10+
"ignoreDeprecations": "5.0",
1011
"strictNullChecks": true,
11-
"skipLibCheck": true
12+
"skipLibCheck": true,
13+
"types": ["node"]
1214
},
1315
"include": ["./**/*"]
1416
}

scripts/update/gitUtils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { execSync, spawn } from 'child_process';
22

3+
function hasStderr(err: unknown): err is { stderr: string } {
4+
return typeof err === 'object' && err !== null && 'stderr' in err && typeof (err as { stderr: unknown }).stderr === 'string';
5+
}
6+
37
// Define a type for the file status and path
48
export type ChangedFile = {
59
status: 'A' | 'M' | 'D' | 'R' | 'C' | 'T' | 'U' | 'X' | 'B'; // Git status codes
@@ -61,7 +65,7 @@ export function getChangedJsonFilesWithStatus(): ChangedFile[] {
6165
});
6266
} catch (error) {
6367
// Check if the error is due to missing history (e.g., first commit)
64-
if (error.stderr?.includes('unknown revision or path not in the working tree')) {
68+
if (hasStderr(error) && error.stderr.includes('unknown revision or path not in the working tree')) {
6569
console.warn(
6670
'Could not find previous commit (HEAD~1). Checking working tree status against index...'
6771
);
@@ -122,21 +126,21 @@ export async function getOldFileContent(gitPath: string): Promise<string> {
122126
let oldFileContent = '';
123127
let errorOutput = '';
124128

125-
gitShow.stdout.on('data', (data) => {
129+
gitShow.stdout.on('data', (data: Buffer) => {
126130
oldFileContent += data.toString();
127131
});
128132

129-
gitShow.stderr.on('data', (data) => {
133+
gitShow.stderr.on('data', (data: Buffer) => {
130134
errorOutput += data.toString();
131135
});
132136

133-
gitShow.on('error', (err) => {
137+
gitShow.on('error', (err: Error) => {
134138
// Handle errors spawning the process itself
135139
console.error(`Error spawning git show for HEAD~1:${gitPath}:`, err);
136140
resolve(''); // Resolve with empty string on spawn error
137141
});
138142

139-
gitShow.on('close', (code) => {
143+
gitShow.on('close', (code: number | null) => {
140144
if (code === 0) {
141145
resolve(oldFileContent);
142146
} else {

scripts/update/processor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFileSync } from 'fs';
2-
import { MongoClient, AnyBulkWriteOperation, Document, Db } from 'mongodb';
2+
import { MongoClient, AnyBulkWriteOperation, Document, Db, MongoServerError } from 'mongodb';
33
import { diff } from 'deep-diff';
44
import {
55
getCollectionNameFromJsonFile,
@@ -291,7 +291,7 @@ async function _handleFileRenamed(db: Db, filepath: string, oldFilepath: string)
291291
await db.collection(oldCollectionName).drop();
292292
console.log(`Dropped old collection '${oldCollectionName}'.`);
293293
} catch (err) {
294-
if (err.codeName !== 'NamespaceNotFound') {
294+
if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) {
295295
console.error(`Error dropping old collection '${oldCollectionName}' during rename:`, err);
296296
}
297297
}
@@ -318,7 +318,7 @@ async function _handleFileDeleted(db: Db, filepath: string): Promise<void> {
318318
await db.collection(collectionName).drop();
319319
console.log(`Dropped collection '${collectionName}' due to file deletion.`);
320320
} catch (err) {
321-
if (err.codeName !== 'NamespaceNotFound') {
321+
if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) {
322322
console.error(`Error dropping collection '${collectionName}' for deleted file:`, err);
323323
} else {
324324
console.log(`Collection '${collectionName}' not found, likely already dropped.`);

0 commit comments

Comments
 (0)