From 2c13a21b0b6e917d1da15d99e23ef0111c5b2e60 Mon Sep 17 00:00:00 2001 From: Daniel Hauser <36034483+daniel-hauser@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:54:29 +0300 Subject: [PATCH] fix: runtime import error import error (#346) * Fix Error ***ERR_MODULE_NOT_FOUND***: Cannot find module '/app/dst/utils/currency' imported from /app/dst/messages.js * Let jest use the ts files when importing js files See: https://github.com/kulshekhar/ts-jest/issues/1057 * Fix more extension-less imports --- jest.config.js | 3 +++ src/config.ts | 2 +- src/data/index.ts | 2 +- src/messages.test.ts | 10 +++++----- src/messages.ts | 4 ++-- src/notifier.ts | 5 ----- src/saveStats.ts | 6 +++--- src/storage/azure-data-explorer.ts | 2 +- src/storage/utils.test.ts | 4 ++-- src/storage/utils.ts | 2 +- src/types.ts | 4 ++-- src/utils/currency.test.ts | 2 +- 12 files changed, 22 insertions(+), 24 deletions(-) diff --git a/jest.config.js b/jest.config.js index 6fd5d237..3aab9045 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,4 +3,7 @@ export default { preset: "ts-jest", testEnvironment: "node", rootDir: "./src", + moduleNameMapper: { + "^(\\.\\.?\\/.+)\\.jsx?$": "$1", + }, }; diff --git a/src/config.ts b/src/config.ts index 8033cacc..437f9d8e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,6 @@ import "dotenv/config"; import { subDays, format } from "date-fns"; -import { AccountConfig } from "./types"; +import { AccountConfig } from "./types.js"; import { createLogger, logToPublicLog } from "./utils/logger.js"; const logger = createLogger("config"); diff --git a/src/data/index.ts b/src/data/index.ts index f1770a9c..131770a5 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -1,6 +1,6 @@ import { performance } from "perf_hooks"; import { getAccountTransactions } from "./scrape.js"; -import { AccountConfig, AccountScrapeResult } from "../types"; +import { AccountConfig, AccountScrapeResult } from "../types.js"; import { createLogger } from "../utils/logger.js"; const logger = createLogger("data"); diff --git a/src/messages.test.ts b/src/messages.test.ts index 37ae2929..225425c8 100644 --- a/src/messages.test.ts +++ b/src/messages.test.ts @@ -1,12 +1,12 @@ import { CompanyTypes } from "israeli-bank-scrapers"; -import { getSummaryMessages } from "./messages"; -import { AccountScrapeResult, Transaction, TransactionRow } from "./types"; +import { getSummaryMessages } from "./messages.js"; +import { AccountScrapeResult, Transaction, TransactionRow } from "./types.js"; import { TransactionStatuses, TransactionTypes, -} from "israeli-bank-scrapers/lib/transactions"; -import { ScraperErrorTypes } from "israeli-bank-scrapers/lib/scrapers/errors"; -import { createSaveStats, SaveStats, statsString } from "./saveStats"; +} from "israeli-bank-scrapers/lib/transactions.js"; +import { ScraperErrorTypes } from "israeli-bank-scrapers/lib/scrapers/errors.js"; +import { createSaveStats, SaveStats, statsString } from "./saveStats.js"; describe("messages", () => { describe("getSummaryMessages", () => { diff --git a/src/messages.ts b/src/messages.ts index 5e0f325a..1f450ab3 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -2,8 +2,8 @@ import { TransactionStatuses, TransactionTypes, } from "israeli-bank-scrapers/lib/transactions.js"; -import { AccountScrapeResult, Transaction } from "./types"; -import { normalizeCurrency } from "./utils/currency"; +import { AccountScrapeResult, Transaction } from "./types.js"; +import { normalizeCurrency } from "./utils/currency.js"; export function getSummaryMessages(results: Array) { const accountsSummary = results.flatMap(({ result, companyId }) => { diff --git a/src/notifier.ts b/src/notifier.ts index 91ec7e98..e4d86024 100644 --- a/src/notifier.ts +++ b/src/notifier.ts @@ -1,5 +1,4 @@ import { Telegraf, TelegramError } from "telegraf"; -import { Message } from "telegraf/typings/core/types/typegram"; import { TELEGRAM_API_KEY, TELEGRAM_CHAT_ID } from "./config.js"; import { createLogger, logToPublicLog } from "./utils/logger.js"; @@ -32,10 +31,6 @@ export async function sendPhoto(photoPath: string, caption: string) { ); } -export async function deleteMessage(message: Message.TextMessage) { - await bot?.telegram.deleteMessage(TELEGRAM_CHAT_ID, message.message_id); -} - export async function editMessage( message: number | undefined, newText: string, diff --git a/src/saveStats.ts b/src/saveStats.ts index 3706846a..a6313b54 100644 --- a/src/saveStats.ts +++ b/src/saveStats.ts @@ -1,6 +1,6 @@ -import { TransactionStatuses } from "israeli-bank-scrapers/lib/transactions"; -import { TransactionRow } from "./types"; -import { transactionList } from "./messages"; +import { TransactionStatuses } from "israeli-bank-scrapers/lib/transactions.js"; +import { TransactionRow } from "./types.js"; +import { transactionList } from "./messages.js"; export interface SaveStats { /** diff --git a/src/storage/azure-data-explorer.ts b/src/storage/azure-data-explorer.ts index 707259f2..ef528ac7 100644 --- a/src/storage/azure-data-explorer.ts +++ b/src/storage/azure-data-explorer.ts @@ -8,7 +8,7 @@ import { import { sendError } from "../notifier.js"; import { systemName } from "./../config.js"; import { createLogger } from "./../utils/logger.js"; -import type KustoIngestClient from "azure-kusto-ingest/types/src/ingestClient.js"; +import type { KustoIngestClient } from "azure-kusto-ingest/types/src/ingestClient.js"; import type { TransactionRow, TransactionStorage } from "../types.js"; import { createSaveStats } from "../saveStats.js"; diff --git a/src/storage/utils.test.ts b/src/storage/utils.test.ts index 2e3611dc..8e03fc58 100644 --- a/src/storage/utils.test.ts +++ b/src/storage/utils.test.ts @@ -2,8 +2,8 @@ import { Transaction, TransactionStatuses, TransactionTypes, -} from "israeli-bank-scrapers/lib/transactions"; -import { transactionUniqueId, transactionHash } from "./utils"; +} from "israeli-bank-scrapers/lib/transactions.js"; +import { transactionUniqueId, transactionHash } from "./utils.js"; import { CompanyTypes } from "israeli-bank-scrapers"; const transaction1: Transaction = { diff --git a/src/storage/utils.ts b/src/storage/utils.ts index 9feeddc8..5c20151c 100644 --- a/src/storage/utils.ts +++ b/src/storage/utils.ts @@ -1,6 +1,6 @@ import { formatISO, parseISO, roundToNearestMinutes } from "date-fns"; import type { CompanyTypes } from "israeli-bank-scrapers"; -import type { Transaction } from "israeli-bank-scrapers/lib/transactions"; +import type { Transaction } from "israeli-bank-scrapers/lib/transactions.js"; /** * Generates a hash for a transaction that can be used to ~uniquely identify it. diff --git a/src/types.ts b/src/types.ts index 7f0726d9..95a48293 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,10 @@ import type { CompanyTypes } from "israeli-bank-scrapers"; -import type { Transaction } from "israeli-bank-scrapers/lib/transactions"; +import type { Transaction } from "israeli-bank-scrapers/lib/transactions.js"; import type { ScraperScrapingResult, ScraperCredentials, } from "israeli-bank-scrapers"; -import { SaveStats } from "./saveStats"; +import { SaveStats } from "./saveStats.js"; export type { Transaction }; export type AccountConfig = ScraperCredentials & { diff --git a/src/utils/currency.test.ts b/src/utils/currency.test.ts index 4c6df835..5db8c8b7 100644 --- a/src/utils/currency.test.ts +++ b/src/utils/currency.test.ts @@ -1,4 +1,4 @@ -import { normalizeCurrency } from "./currency"; +import { normalizeCurrency } from "./currency.js"; describe("normalizeCurrency", () => { it("should return undefined if currency is undefined", () => {