Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert coordinator service to esm module #265

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
32 changes: 23 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,15 @@
"scripts": {
"hardhat": "hardhat node",
"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"start:prod": "node dist/main",
"run:node": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));'",
"start": "pnpm run run:node ./ts/main.ts",
"start:prod": "pnpm run run:node 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": "pnpm run run:node ./scripts/generateKeypair.ts",
"download-zkeys:test": "pnpm run run:node ./scripts/downloadZKeys.ts test ./zkeys",
"download-zkeys:prod": "pnpm run run:node ./scripts/downloadZKeys.ts prod ./zkeys"
},
"dependencies": {
"@graphprotocol/graph-cli": "^0.79.0",
Expand Down Expand Up @@ -58,7 +62,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 +84,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
7 changes: 7 additions & 0 deletions packages/coordinator/scripts/generateKeypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ 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));
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-enable no-underscore-dangle */
/* eslint-enable @typescript-eslint/no-shadow */

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,
};
12 changes: 11 additions & 1 deletion packages/coordinator/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ 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 */
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/* eslint-enable no-underscore-dangle */
/* eslint-disable @typescript-eslint/no-shadow */

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
Loading