From 8031caacffc19367c865a2f15b79c12fd66687d1 Mon Sep 17 00:00:00 2001 From: Dallas Hoffman Date: Wed, 7 Aug 2024 20:59:22 -0400 Subject: [PATCH] Enable noImplicitOverride and moduleDetection; fix test type checking --- package.json | 2 +- src/client.ts | 4 ++-- src/lib/exec-on-db.ts | 2 +- test/batch.test.ts | 2 +- test/create-callback-function.test.ts | 2 +- test/create-scalar-function.test.ts | 2 +- test/destroy.test.ts | 2 +- test/drizzle/driver.test.ts | 4 ++-- test/get-database-file.test.ts | 2 +- test/get-database-info.test.ts | 2 +- test/init.test.ts | 2 +- test/kysely/dialect.test.ts | 7 ++++--- test/kysely/migrations.test.ts | 4 ++-- test/kysely/migrations/2023-08-01.ts | 3 ++- test/kysely/migrations/2023-08-02.ts | 3 ++- test/kysely/migrations/index.ts | 6 +++--- test/overwrite-database-file.test.ts | 2 +- test/sql.test.ts | 2 +- test/transaction.test.ts | 4 ++-- tsconfig.build.json | 4 ++++ tsconfig.json | 4 +++- 21 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 tsconfig.build.json diff --git a/package.json b/package.json index b66eca7..168abf8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "src" ], "scripts": { - "build": "tsc", + "build": "tsc --project tsconfig.build.json", "test": "vitest", "test:ui": "vitest --ui", "format": "prettier . --write", diff --git a/src/client.ts b/src/client.ts index 0e484ae..333785a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -162,8 +162,8 @@ export class SQLocal { }; if (message.type === 'data') { - data.rows = message.data[0].rows; - data.columns = message.data[0].columns; + data.rows = message.data[0]?.rows ?? []; + data.columns = message.data[0]?.columns ?? []; } return data; diff --git a/src/lib/exec-on-db.ts b/src/lib/exec-on-db.ts index fbf9134..aa97afd 100644 --- a/src/lib/exec-on-db.ts +++ b/src/lib/exec-on-db.ts @@ -21,7 +21,7 @@ export function execOnDb( case 'run': break; case 'get': - statementData.rows = rows[0]; + statementData.rows = rows[0] ?? []; break; case 'all': default: diff --git a/test/batch.test.ts b/test/batch.test.ts index 2f0ff2e..025f2e3 100644 --- a/test/batch.test.ts +++ b/test/batch.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('batch', () => { const { sql, batch } = new SQLocal('batch-test.sqlite3'); diff --git a/test/create-callback-function.test.ts b/test/create-callback-function.test.ts index a48ec07..667ef80 100644 --- a/test/create-callback-function.test.ts +++ b/test/create-callback-function.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('createCallbackFunction', () => { const { sql, createCallbackFunction } = new SQLocal( diff --git a/test/create-scalar-function.test.ts b/test/create-scalar-function.test.ts index 54289ba..35c1a6a 100644 --- a/test/create-scalar-function.test.ts +++ b/test/create-scalar-function.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('createScalarFunction', () => { const { sql, createScalarFunction } = new SQLocal( diff --git a/test/destroy.test.ts b/test/destroy.test.ts index 103764d..73210af 100644 --- a/test/destroy.test.ts +++ b/test/destroy.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('destroy', () => { const { sql, destroy } = new SQLocal('destroy-test.sqlite3'); diff --git a/test/drizzle/driver.test.ts b/test/drizzle/driver.test.ts index 97d291c..d248e93 100644 --- a/test/drizzle/driver.test.ts +++ b/test/drizzle/driver.test.ts @@ -1,9 +1,9 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocalDrizzle } from '../../src/drizzle'; +import { SQLocalDrizzle } from '../../src/drizzle/index.js'; import { drizzle } from 'drizzle-orm/sqlite-proxy'; import { int, real, sqliteTable, text } from 'drizzle-orm/sqlite-core'; import { desc, eq, relations, sql as dsql } from 'drizzle-orm'; -import { sleep } from '../test-utils/sleep'; +import { sleep } from '../test-utils/sleep.js'; describe('drizzle driver', () => { const { sql, driver, batchDriver, transaction } = new SQLocalDrizzle( diff --git a/test/get-database-file.test.ts b/test/get-database-file.test.ts index d05088c..2acf1a4 100644 --- a/test/get-database-file.test.ts +++ b/test/get-database-file.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('getDatabaseFile', () => { const fileName = 'get-database-file-test.sqlite3'; diff --git a/test/get-database-info.test.ts b/test/get-database-info.test.ts index 585a14b..a9422d9 100644 --- a/test/get-database-info.test.ts +++ b/test/get-database-info.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('getDatabaseInfo', () => { const { sql, getDatabaseInfo } = new SQLocal( diff --git a/test/init.test.ts b/test/init.test.ts index 00a61e0..1e69b08 100644 --- a/test/init.test.ts +++ b/test/init.test.ts @@ -1,5 +1,5 @@ import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('init', () => { const databasePath = 'init-test.sqlite3'; diff --git a/test/kysely/dialect.test.ts b/test/kysely/dialect.test.ts index 3532a07..a3393d2 100644 --- a/test/kysely/dialect.test.ts +++ b/test/kysely/dialect.test.ts @@ -1,8 +1,9 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { Generated, Kysely, ParseJSONResultsPlugin } from 'kysely'; +import { Kysely, ParseJSONResultsPlugin } from 'kysely'; +import type { Generated } from 'kysely'; import { jsonArrayFrom } from 'kysely/helpers/sqlite'; -import { SQLocalKysely } from '../../src/kysely'; -import { sleep } from '../test-utils/sleep'; +import { SQLocalKysely } from '../../src/kysely/index.js'; +import { sleep } from '../test-utils/sleep.js'; describe('kysely dialect', () => { const { dialect, transaction } = new SQLocalKysely( diff --git a/test/kysely/migrations.test.ts b/test/kysely/migrations.test.ts index f2c8ad1..8a7b81f 100644 --- a/test/kysely/migrations.test.ts +++ b/test/kysely/migrations.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, it } from 'vitest'; -import { SQLocalKysely } from '../../src/kysely'; +import { SQLocalKysely } from '../../src/kysely/index.js'; import { Kysely, Migrator } from 'kysely'; describe('kysely migrations', () => { @@ -11,7 +11,7 @@ describe('kysely migrations', () => { db, provider: { async getMigrations() { - const { migrations } = await import('./migrations/'); + const { migrations } = await import('./migrations/index.js'); return migrations; }, }, diff --git a/test/kysely/migrations/2023-08-01.ts b/test/kysely/migrations/2023-08-01.ts index 2970b71..9c735a8 100644 --- a/test/kysely/migrations/2023-08-01.ts +++ b/test/kysely/migrations/2023-08-01.ts @@ -1,4 +1,5 @@ -import { Kysely, Migration } from 'kysely'; +import { Kysely } from 'kysely'; +import type { Migration } from 'kysely'; export const Migration20230801: Migration = { async up(db: Kysely) { diff --git a/test/kysely/migrations/2023-08-02.ts b/test/kysely/migrations/2023-08-02.ts index 2111f0d..57002d3 100644 --- a/test/kysely/migrations/2023-08-02.ts +++ b/test/kysely/migrations/2023-08-02.ts @@ -1,4 +1,5 @@ -import { Kysely, Migration } from 'kysely'; +import { Kysely } from 'kysely'; +import type { Migration } from 'kysely'; export const Migration20230802: Migration = { async up(db: Kysely) { diff --git a/test/kysely/migrations/index.ts b/test/kysely/migrations/index.ts index 02ad47e..6cdc7cc 100644 --- a/test/kysely/migrations/index.ts +++ b/test/kysely/migrations/index.ts @@ -1,6 +1,6 @@ -import { Migration } from 'kysely'; -import { Migration20230801 } from './2023-08-01'; -import { Migration20230802 } from './2023-08-02'; +import type { Migration } from 'kysely'; +import { Migration20230801 } from './2023-08-01.js'; +import { Migration20230802 } from './2023-08-02.js'; export const migrations: Record = { '2023-08-02': Migration20230802, diff --git a/test/overwrite-database-file.test.ts b/test/overwrite-database-file.test.ts index 1c7d25a..7410756 100644 --- a/test/overwrite-database-file.test.ts +++ b/test/overwrite-database-file.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, afterAll } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('overwriteDatabaseFile', async () => { const db1 = new SQLocal('overwrite-test-db1.sqlite3'); diff --git a/test/sql.test.ts b/test/sql.test.ts index 6a4f105..f7e42ef 100644 --- a/test/sql.test.ts +++ b/test/sql.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; +import { SQLocal } from '../src/index.js'; describe('sql', () => { const { sql } = new SQLocal('sql-test.sqlite3'); diff --git a/test/transaction.test.ts b/test/transaction.test.ts index d4514e1..5ac41f7 100644 --- a/test/transaction.test.ts +++ b/test/transaction.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SQLocal } from '../src/index'; -import { sleep } from './test-utils/sleep'; +import { SQLocal } from '../src/index.js'; +import { sleep } from './test-utils/sleep.js'; describe('transaction', () => { const { sql, transaction } = new SQLocal('transaction-test.sqlite3'); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..2acb0bc --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["test"] +} diff --git a/tsconfig.json b/tsconfig.json index 2815ef8..137703c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ /* Building */ "moduleResolution": "NodeNext", + "moduleDetection": "force", "esModuleInterop": true, "useDefineForClassFields": true, "allowSyntheticDefaultImports": true, @@ -21,8 +22,9 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, "verbatimModuleSyntax": true }, - "include": ["src"], + "include": ["src", "test"], "exclude": ["**/node_modules/**", "dist"] }