diff --git a/packages/coordinator/.eslintrc.js b/packages/coordinator/.eslintrc.cjs similarity index 100% rename from packages/coordinator/.eslintrc.js rename to packages/coordinator/.eslintrc.cjs diff --git a/packages/coordinator/hardhat.config.ts b/packages/coordinator/hardhat.config.cjs similarity index 74% rename from packages/coordinator/hardhat.config.ts rename to packages/coordinator/hardhat.config.cjs index 330bf493..fb532b4a 100644 --- a/packages/coordinator/hardhat.config.ts +++ b/packages/coordinator/hardhat.config.cjs @@ -1,17 +1,16 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -import "@nomicfoundation/hardhat-toolbox"; -import * as dotenv from "dotenv"; -import { HardhatUserConfig } from "hardhat/types"; +require("@nomicfoundation/hardhat-toolbox"); +const dotenv = require("dotenv"); -import * as path from "path"; +const path = require("path"); dotenv.config(); const parentDir = __dirname.includes("build") ? ".." : ""; const TEST_MNEMONIC = "test test test test test test test test test test test junk"; -const config: HardhatUserConfig = { - defaultNetwork: "localhost", +module.exports = { + defaultNetwork: "hardhat", networks: { localhost: { url: process.env.COORDINATOR_RPC_URL || "", @@ -32,5 +31,3 @@ const config: HardhatUserConfig = { artifacts: path.resolve(__dirname, parentDir, "./node_modules/maci-contracts/build/artifacts"), }, }; - -export default config; diff --git a/packages/coordinator/package.json b/packages/coordinator/package.json index 4ac43ce7..0b175e57 100644 --- a/packages/coordinator/package.json +++ b/packages/coordinator/package.json @@ -4,6 +4,10 @@ "private": true, "description": "Coordinator service for MACI", "main": "build/ts/main.js", + "type": "module", + "exports": { + ".": "./build/ts/main.js" + }, "files": [ "build", "CHANGELOG.md", @@ -12,15 +16,14 @@ "scripts": { "hardhat": "hardhat node", "build": "nest build", - "start": "nest start", - "start:dev": "nest start --watch", - "start:prod": "node dist/main", + "start": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./ts/main.ts", + "start:prod": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' build/ts/main.js", "test": "jest --forceExit", "test:coverage": "jest --coverage --forceExit", "types": "tsc -p tsconfig.json --noEmit", - "generate-keypair": "ts-node ./scripts/generateKeypair.ts", - "download-zkeys:test": "ts-node ./scripts/downloadZKeys.ts test ./zkeys", - "download-zkeys:prod": "ts-node ./scripts/downloadZKeys.ts prod ./zkeys" + "generate-keypair": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./scripts/generateKeypair.ts", + "download-zkeys:test": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./scripts/downloadZKeys.ts test ./zkeys", + "download-zkeys:prod": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./scripts/downloadZKeys.ts prod ./zkeys" }, "dependencies": { "@graphprotocol/graph-cli": "^0.79.0", @@ -58,7 +61,7 @@ "@types/express": "^4.17.17", "@types/jest": "^29.5.2", "@types/node": "^20.14.11", - "@types/supertest": "^6.0.0", + "@types/supertest": "^6.0.2", "fast-check": "^3.20.0", "jest": "^29.5.0", "socket.io-client": "^4.7.5", @@ -80,8 +83,18 @@ ], "testRegex": ".*\\.test\\.ts$", "transform": { - "^.+\\.js$": "/ts/jest/transform.js", - "^.+\\.(t|j)s$": "ts-jest" + "^.+\\.js$": [ + "/ts/jest/transform.js", + { + "useESM": true + } + ], + "^.+\\.(t|j)s$": [ + "ts-jest", + { + "useESM": true + } + ] }, "collectCoverageFrom": [ "**/*.(t|j)s", diff --git a/packages/coordinator/scripts/generateKeypair.ts b/packages/coordinator/scripts/generateKeypair.ts index 85a38dad..f974e695 100644 --- a/packages/coordinator/scripts/generateKeypair.ts +++ b/packages/coordinator/scripts/generateKeypair.ts @@ -3,6 +3,11 @@ import dotenv from "dotenv"; import { generateKeyPairSync } from "crypto"; import fs from "fs"; import path from "path"; +import url from "url"; + +/* eslint-disable no-underscore-dangle */ +/* eslint-disable @typescript-eslint/no-shadow */ +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); dotenv.config({ path: [path.resolve(__dirname, "../.env"), path.resolve(__dirname, "../.env.example")] }); diff --git a/packages/coordinator/tests/app.test.ts b/packages/coordinator/tests/app.test.ts index fd2c9ac7..32d66ee3 100644 --- a/packages/coordinator/tests/app.test.ts +++ b/packages/coordinator/tests/app.test.ts @@ -16,7 +16,7 @@ import { mergeMessages, mergeSignups, } from "maci-cli"; -import { Proof, TallyData, Poll__factory as PollFactory } from "maci-contracts"; +import { type Proof, type TallyData, Poll__factory as PollFactory } from "maci-contracts"; import { Keypair } from "maci-domainobjs"; import { io, Socket } from "socket.io-client"; import request from "supertest"; @@ -30,8 +30,8 @@ import { AppModule } from "../ts/app.module"; import { ErrorCodes, ESupportedNetworks } from "../ts/common"; import { CryptoService } from "../ts/crypto/crypto.service"; import { FileModule } from "../ts/file/file.module"; -import { EProofGenerationEvents, IGenerateArgs } from "../ts/proof/types"; -import { ESubgraphEvents, IDeploySubgraphArgs } from "../ts/subgraph/types"; +import { EProofGenerationEvents, type IGenerateArgs } from "../ts/proof/types"; +import { ESubgraphEvents, type IDeploySubgraphArgs } from "../ts/subgraph/types"; const STATE_TREE_DEPTH = 10; const INT_STATE_TREE_DEPTH = 1; diff --git a/packages/coordinator/ts/auth/AccountSignatureGuard.service.ts b/packages/coordinator/ts/auth/AccountSignatureGuard.service.ts index 759458ac..68d77a32 100644 --- a/packages/coordinator/ts/auth/AccountSignatureGuard.service.ts +++ b/packages/coordinator/ts/auth/AccountSignatureGuard.service.ts @@ -1,6 +1,6 @@ import { Logger, - CanActivate, + type CanActivate, Injectable, SetMetadata, type ExecutionContext, diff --git a/packages/coordinator/ts/jest/transform.js b/packages/coordinator/ts/jest/transform.js index d07dcc1e..dd33c841 100644 --- a/packages/coordinator/ts/jest/transform.js +++ b/packages/coordinator/ts/jest/transform.js @@ -1,9 +1,11 @@ /* eslint-disable */ -module.exports = { - process(sourceText) { - return { - code: sourceText.replace("#!/usr/bin/env node", ""), - }; - }, +export function process(sourceText) { + return { + code: sourceText.replace("#!/usr/bin/env node", ""), + }; +} + +export default { + process, }; diff --git a/packages/coordinator/ts/main.ts b/packages/coordinator/ts/main.ts index b6aabfc5..62ac1f31 100644 --- a/packages/coordinator/ts/main.ts +++ b/packages/coordinator/ts/main.ts @@ -5,8 +5,16 @@ import dotenv from "dotenv"; import helmet from "helmet"; import path from "path"; +import url from "url"; -dotenv.config({ path: [path.resolve(__dirname, "../.env"), path.resolve(__dirname, "../.env.example")] }); +/* eslint-disable no-underscore-dangle */ +/* eslint-disable @typescript-eslint/no-shadow */ +const __filename = url.fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +dotenv.config({ + path: [path.resolve(__dirname, "../.env"), path.resolve(__dirname, "../.env.example")], +}); async function bootstrap() { const { AppModule } = await import("./app.module.js"); diff --git a/packages/coordinator/ts/proof/__tests__/proof.gateway.test.ts b/packages/coordinator/ts/proof/__tests__/proof.gateway.test.ts index ca2e26f3..b23ed09c 100644 --- a/packages/coordinator/ts/proof/__tests__/proof.gateway.test.ts +++ b/packages/coordinator/ts/proof/__tests__/proof.gateway.test.ts @@ -1,9 +1,9 @@ import { Test } from "@nestjs/testing"; -import { IGenerateProofsOptions } from "maci-contracts"; import { Server } from "socket.io"; import type { IGenerateArgs, IGenerateData } from "../types"; import type { TallyData } from "maci-cli"; +import type { IGenerateProofsOptions } from "maci-contracts"; import { ProofGateway } from "../proof.gateway"; import { ProofGeneratorService } from "../proof.service"; diff --git a/packages/coordinator/ts/proof/proof.gateway.ts b/packages/coordinator/ts/proof/proof.gateway.ts index eca88387..d9400018 100644 --- a/packages/coordinator/ts/proof/proof.gateway.ts +++ b/packages/coordinator/ts/proof/proof.gateway.ts @@ -1,7 +1,7 @@ import { Logger, UseGuards, UsePipes, ValidationPipe } from "@nestjs/common"; import { MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer, WsException } from "@nestjs/websockets"; -import { IGenerateProofsBatchData, type Proof, type TallyData } from "maci-contracts"; +import type { IGenerateProofsBatchData, Proof, TallyData } from "maci-contracts"; import type { Server } from "socket.io"; import { AccountSignatureGuard } from "../auth/AccountSignatureGuard.service"; diff --git a/packages/coordinator/ts/subgraph/subgraph.gateway.ts b/packages/coordinator/ts/subgraph/subgraph.gateway.ts index ab1cbaec..fbacc619 100644 --- a/packages/coordinator/ts/subgraph/subgraph.gateway.ts +++ b/packages/coordinator/ts/subgraph/subgraph.gateway.ts @@ -7,7 +7,7 @@ import { AccountSignatureGuard } from "../auth/AccountSignatureGuard.service"; import { DeploySubgraphDto } from "./dto"; import { SubgraphService } from "./subgraph.service"; -import { ESubgraphEvents, IProgressArgs } from "./types"; +import { ESubgraphEvents, type IProgressArgs } from "./types"; /** * SubgraphGateway is responsible for websockets integration between client and SubgraphService. diff --git a/packages/coordinator/tsconfig.build.json b/packages/coordinator/tsconfig.build.json index efe68365..f0be7d9d 100644 --- a/packages/coordinator/tsconfig.build.json +++ b/packages/coordinator/tsconfig.build.json @@ -4,8 +4,16 @@ "outDir": "./build", "emitDecoratorMetadata": true, "experimentalDecorators": true, - "allowJs": true + "lib": ["ES2023"], + "module": "ESNext", + "moduleResolution": "Bundler", + "target": "ES2022", + "forceConsistentCasingInFileNames": true + }, + "ts-node": { + "esm": true, + "experimentalSpecifierResolution": "node" }, "include": ["./ts", "./scripts", "./tests"], - "files": ["./hardhat.config.ts"] + "files": ["./hardhat.config.cjs"] } diff --git a/packages/coordinator/tsconfig.json b/packages/coordinator/tsconfig.json index 474eb52a..f0be7d9d 100644 --- a/packages/coordinator/tsconfig.json +++ b/packages/coordinator/tsconfig.json @@ -3,8 +3,17 @@ "compilerOptions": { "outDir": "./build", "emitDecoratorMetadata": true, - "experimentalDecorators": true + "experimentalDecorators": true, + "lib": ["ES2023"], + "module": "ESNext", + "moduleResolution": "Bundler", + "target": "ES2022", + "forceConsistentCasingInFileNames": true + }, + "ts-node": { + "esm": true, + "experimentalSpecifierResolution": "node" }, "include": ["./ts", "./scripts", "./tests"], - "files": ["hardhat.config.ts"] + "files": ["./hardhat.config.cjs"] } diff --git a/packages/interface/tsconfig.build.json b/packages/interface/tsconfig.build.json index 63259043..3f459815 100644 --- a/packages/interface/tsconfig.build.json +++ b/packages/interface/tsconfig.build.json @@ -5,7 +5,6 @@ "esModuleInterop": true, "skipLibCheck": true, "target": "es2022", - "allowJs": true, "resolveJsonModule": true, "moduleDetection": "force", "isolatedModules": true, diff --git a/packages/interface/tsconfig.json b/packages/interface/tsconfig.json index 5de61f80..1fae778e 100644 --- a/packages/interface/tsconfig.json +++ b/packages/interface/tsconfig.json @@ -5,7 +5,6 @@ "esModuleInterop": true, "skipLibCheck": true, "target": "es2022", - "allowJs": true, "resolveJsonModule": true, "moduleDetection": "force", "isolatedModules": true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index df0b6159..d57b289e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -254,7 +254,7 @@ importers: specifier: ^20.14.11 version: 20.14.14 '@types/supertest': - specifier: ^6.0.0 + specifier: ^6.0.2 version: 6.0.2 fast-check: specifier: ^3.20.0 @@ -20827,6 +20827,10 @@ snapshots: dependencies: ms: 2.0.0 + debug@3.2.7: + dependencies: + ms: 2.1.3 + debug@3.2.7(supports-color@8.1.1): dependencies: ms: 2.1.3 @@ -21064,7 +21068,7 @@ snapshots: docker-modem@1.0.9: dependencies: JSONStream: 1.3.2 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7 readable-stream: 1.0.34 split-ca: 1.0.1 transitivePeerDependencies: diff --git a/tsconfig.json b/tsconfig.json index a2716455..fd4fe2a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "allowJs": true }, "exclude": ["node_modules"], "include": ["packages/coordinator/ts", "packages/coordinator/scripts", "./packages/interface/src"]