diff --git a/jest.config.integration.js b/jest.config.integration.js index 7e8ee17..7e2e84d 100644 --- a/jest.config.integration.js +++ b/jest.config.integration.js @@ -4,6 +4,7 @@ module.exports = { testEnvironment: "node", testMatch: ["**/test/integration/**/*.test.ts"], testPathIgnorePatterns: ["binaryen"], + modulePathIgnorePatterns: ["/dist/"], // Set the timeout value for all tests to 2 minutes (default is 5 seconds) testTimeout: 120000, diff --git a/src/2bytes/decodeRestrictedBase64ToBytes.ts b/src/2bytes/decodeRestrictedBase64ToBytes.ts index bb22222..200e96c 100644 --- a/src/2bytes/decodeRestrictedBase64ToBytes.ts +++ b/src/2bytes/decodeRestrictedBase64ToBytes.ts @@ -86,12 +86,9 @@ const base64DecodeMapOffset = 0x2b; const base64EOF = 0x3d; export function decodeRestrictedBase64ToBytes(encoded: string) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let ch: any; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let code: any; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let code2: any; + let ch: number; + let code: number; + let code2: number; const len = encoded.length; const padding = diff --git a/src/c2wasm/index.ts b/src/c2wasm/index.ts index 6e8a87f..89a8404 100644 --- a/src/c2wasm/index.ts +++ b/src/c2wasm/index.ts @@ -18,14 +18,14 @@ interface BuildResult { tasks: Task[]; } -const getCustomHeader = (headersPath: string | undefined): any[] => { - let headerObjects: any[] = []; +const getCustomHeader = (headersPath: string | undefined): FileObject[] => { + let headerObjects: FileObject[] = []; if (headersPath) { try { headerObjects = readFiles(headersPath).filter( (file) => file.type === "h" ); - } catch (error: any) { + } catch (error: unknown) { console.error(`Error reading header files: ${error}`); process.exit(1); } @@ -51,10 +51,10 @@ export async function buildCDir( isXRPL: boolean ): Promise { // Reading all files in the directory tree - let fileObjects: any[]; + let fileObjects: FileObject[]; try { fileObjects = readFiles(dirPath).filter((file) => file.type === "c"); - } catch (error: any) { + } catch (error: unknown) { console.error(`Error reading files: ${error}`); process.exit(1); } @@ -88,14 +88,13 @@ export async function buildFile( throw Error("Invalid file type. must be .c file"); } const filename = filePath.split("/").pop(); - const fileObject = { + if (!filename) throw Error("Invalid file name. must be a file name"); + const fileObject: FileObject = { type: "c", name: filename, src: fileContent, }; - const headerObjects = getCustomHeader(headerPath); - try { await buildWasm(fileObject, headerObjects, outDir, isXRPL); } catch (error) { @@ -105,8 +104,8 @@ export async function buildFile( } // Function to read all files in a directory tree -export function readFiles(dirPath: string): any[] { - const files: any[] = []; +export function readFiles(dirPath: string): FileObject[] { + const files: FileObject[] = []; const fileNames = fs.readdirSync(dirPath); for (const fileName of fileNames) { const filePath = path.join(dirPath, fileName); @@ -168,14 +167,14 @@ async function saveFileOrError( const binary = await decodeBinary(result.output); fs.writeFileSync( path.join(outDir + "/" + filename + ".wasm"), - Buffer.from(binary) + Uint8Array.from(Buffer.from(binary)) ); } } export async function buildWasm( - fileObject: any, - headerObjects: any[], + fileObject: FileObject, + headerObjects: FileObject[], outDir: string, isXRPL: boolean ) { @@ -221,7 +220,7 @@ export async function buildWasm( } as BuildResult; fs.mkdirSync(outDir, { recursive: true }); await saveFileOrError(outDir, filename, result); - } catch (error: any) { + } catch (error: unknown) { throw Error(`Error sending API call: ${error}`); } } diff --git a/src/commands.ts b/src/commands.ts index 68a2192..59022f7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -180,7 +180,7 @@ export const compileJSCommand = async (inPath: string, outDir: string) => { console.error("Output path must be a directory."); process.exit(1); } - } catch (error: any) { + } catch (error: unknown) { mkdir(outDir, { recursive: true }, (err) => { if (err) { console.error(`Failed to create directory: ${outDir}`); @@ -245,7 +245,7 @@ export const compileCCommand = async ( console.error("Output path must be a directory."); process.exit(1); } - } catch (error: any) { + } catch (error: unknown) { mkdir(outDir, { recursive: true }, (err) => { if (err) { console.error(`Failed to create directory: ${outDir}`); diff --git a/src/debug/index.ts b/src/debug/index.ts index 8542245..3b12de3 100644 --- a/src/debug/index.ts +++ b/src/debug/index.ts @@ -1,5 +1,5 @@ import ReconnectingWebSocket from "reconnecting-websocket"; -import WebSocket from "ws"; // Import the WebSocket implementation for Node.js +import WebSocket, { CloseEvent } from "ws"; // Import the WebSocket implementation for Node.js export interface ISelect { label: string; @@ -19,15 +19,14 @@ const onError = () => { console.error("Something went wrong! Check your connection and try again."); }; -const onClose = (e: any) => { +const onClose = (e: CloseEvent) => { // 999 = closed websocket connection by switching account if (e.code !== 4999) { console.error(`Connection was closed. [code: ${e.code}]`); } }; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const onMessage = (event: any) => { +const onMessage = (event: globalThis.MessageEvent) => { // Ping returns just account address, if we get that // response we don't need to log anything if (event.data !== selectedAccount?.value) { diff --git a/src/js2qjsc/index.ts b/src/js2qjsc/index.ts index ca79b68..c0716ab 100644 --- a/src/js2qjsc/index.ts +++ b/src/js2qjsc/index.ts @@ -30,19 +30,17 @@ interface BuildResult { tasks: Task[]; } -function generateHash(dataBytes: Buffer) { +function generateHash(dataBytes: Uint8Array) { const hash = createHash("sha512").update(dataBytes).digest(); - return hash.slice(0, 32).toString("hex").toUpperCase(); + return hash.subarray(0, 32).toString("hex").toUpperCase(); } export async function buildDir(dirPath: string, outDir: string): Promise { // Reading all files in the directory tree - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let fileObjects: any[]; + let fileObjects: FileObject[]; try { fileObjects = readFiles(dirPath); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { + } catch (error: unknown) { console.error(`Error reading files: ${error}`); process.exit(1); } @@ -73,8 +71,10 @@ export async function buildFile( } const filename = dirPath.split("/").pop(); const filetype = filename?.split(".").pop(); - const fileObject = { - type: filetype, + if (!filetype) throw Error("Invalid file type. must be .js or .ts file"); + if (!filename) throw Error("Invalid file name. must be a file name"); + const fileObject: FileObject = { + type: filetype as "js" | "ts", name: filename, options: "-O3", src: fileContent, @@ -88,10 +88,8 @@ export async function buildFile( } // Function to read all files in a directory tree -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function readFiles(dirPath: string): any[] { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const files: any[] = []; +export function readFiles(dirPath: string): FileObject[] { + const files: FileObject[] = []; const fileNames = fs.readdirSync(dirPath); for (const fileName of fileNames) { const filePath = path.join(dirPath, fileName); @@ -154,7 +152,7 @@ async function saveFileOrError( } console.log( `Hook Hash: ${ConsoleColor.Green}%s${ConsoleColor.Reset}`, - `${generateHash(Buffer.from(binary))}` + `${generateHash(Uint8Array.from(Buffer.from(binary)))}` ); console.log( `Output: ${outDir}${filename}.bc ${ConsoleColor.Blue}%s${ConsoleColor.Reset}`, @@ -162,13 +160,12 @@ async function saveFileOrError( ); fs.writeFileSync( path.join(outDir + "/" + filename + ".bc"), - Buffer.from(binary) + Uint8Array.from(Buffer.from(binary)) ); } } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export async function buildWasm(fileObject: any, outDir: string) { +export async function buildWasm(fileObject: FileObject, outDir: string) { const filename = fileObject.name.split(".")[0]; // Sending API call to endpoint const body = JSON.stringify({ @@ -209,8 +206,7 @@ export async function buildWasm(fileObject: any, outDir: string) { } as BuildResult; fs.mkdirSync(outDir, { recursive: true }); await saveFileOrError(outDir, filename, result); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { + } catch (error: unknown) { throw Error(`Error sending API call: ${error}`); } } diff --git a/src/type.d.ts b/src/type.d.ts new file mode 100644 index 0000000..de1abb9 --- /dev/null +++ b/src/type.d.ts @@ -0,0 +1,6 @@ +interface FileObject { + type: "c" | "h" | "js" | "ts"; + name: string; + options?: string; + src: string; +}