Skip to content

Commit

Permalink
chore: convert coordinator service to esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Aug 16, 2024
1 parent 6cf7392 commit 261113e
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 40 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 || "",
Expand All @@ -32,5 +31,3 @@ const config: HardhatUserConfig = {
artifacts: path.resolve(__dirname, parentDir, "./node_modules/maci-contracts/build/artifacts"),
},
};

export default config;
31 changes: 22 additions & 9 deletions packages/coordinator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -80,8 +83,18 @@
],
"testRegex": ".*\\.test\\.ts$",
"transform": {
"^.+\\.js$": "<rootDir>/ts/jest/transform.js",
"^.+\\.(t|j)s$": "ts-jest"
"^.+\\.js$": [
"<rootDir>/ts/jest/transform.js",
{
"useESM": true
}
],
"^.+\\.(t|j)s$": [
"ts-jest",
{
"useESM": true
}
]
},
"collectCoverageFrom": [
"**/*.(t|j)s",
Expand Down
5 changes: 5 additions & 0 deletions packages/coordinator/scripts/generateKeypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")] });

Expand Down
6 changes: 3 additions & 3 deletions packages/coordinator/tests/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Logger,
CanActivate,
type CanActivate,
Injectable,
SetMetadata,
type ExecutionContext,
Expand Down
14 changes: 8 additions & 6 deletions packages/coordinator/ts/jest/transform.js
Original file line number Diff line number Diff line change
@@ -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,
};
10 changes: 9 additions & 1 deletion packages/coordinator/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/ts/proof/proof.gateway.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/ts/subgraph/subgraph.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions packages/coordinator/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
13 changes: 11 additions & 2 deletions packages/coordinator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
1 change: 0 additions & 1 deletion packages/interface/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
Expand Down
1 change: 0 additions & 1 deletion packages/interface/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
Expand Down
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 261113e

Please sign in to comment.