Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

chore: move chain packages to a subfolder #701

Closed
wants to merge 9 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
if: startsWith(matrix.os, 'windows-')
run: npm config set msvs_version 2015
- run: npm ci
- run: npm run tsc
- run: npm test
env:
FORCE_COLOR: 1
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ Runs all tests:

## To create a new package

- `npm run create <name> --location <location>`
- `npm run create -- <name> --location <location> [--folder <folder>]`

**NOTE:** You must pass the `--` that follows `create`.

This will create a new package with Ganache defaults at `src/<location>/<name>`.

If you provide the optional `--folder` option, the package will be created at `src/<location>/<folder>`.

## To add a module to a package:

- `npx lerna add <module>[@version] -E [--dev] [--peer] --scope=<package>`
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packages": ["src/packages/*", "src/chains/*"],
"packages": ["src/packages/*", "src/chains/*/*"],
"version": "independent"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ts-transformer-inline-file": "0.1.1",
"ttypescript": "1.5.12",
"typescript": "4.1.1-rc",
"validate-npm-package-name": "3.0.0",
"yargs": "16.1.0"
},
"license": "MIT",
Expand Down
61 changes: 43 additions & 18 deletions scripts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import yargs from "yargs";
import prettier from "prettier";
import camelCase from "camelcase";
import npa from "npm-package-arg";
import npmValiddate from "validate-npm-package-name";
import userName from "git-user-name";
import { join, resolve } from "path";
import { highlight } from "cli-highlight";
Expand All @@ -24,41 +25,47 @@ const COLORS = {
FgRed: "\x1b[31m"
};

const scopes = getDirectories(join(__dirname, "../src"));
let locations = getDirectories(join(__dirname, "../src")).filter(
d => d !== "chains"
);
const chainLocations = getDirectories(join(__dirname, "../src/chains")).map(
d => `chains/${d}`
);
locations = locations.concat(chainLocations);
const argv = yargs
.command(
`$0 <name> --location`,
`$0 <name> [options]`,
`Create a new package in the given location with the provided name.`,
yargs => {
return yargs
.usage(
chalk`{hex("#e4a663").bold Create a new package in the given location with the provided name.}\n\n` +
chalk`{bold Usage}\n {bold $} {dim <}name{dim >} {dim --}location {dim <}${scopes.join(
chalk.dim(" | ")
)}{dim >}`
chalk`{bold Usage}\n {bold $} {dim <}name{dim >} {dim [}options{dim ]}`
)
.positional("<name>", {
describe: ` The name of the new package`,
.positional("name", {
describe: `The name of the new package`,
type: "string",
demandOption: true
})
.alias("name", "<name>")
.option("location", {
alias: "l",
default: "packages",
describe: `The location for the new package.`,
choices: scopes,
choices: locations,
type: "string",
demandOption: true
})
.option("folder", {
alias: "f",
default: null,
describe: `Optional override for the folder name of the package instead of using <name>`,
type: "string"
});
}
)
.demandCommand()
.version(false)
.help(false)
.updateStrings({
"Positionals:": chalk.bold("Options"),
"Options:": ` `,
"Not enough non-option arguments: got %s, need at least %s": {
one: chalk`{red {bold ERROR! Not enough non-option arguments:}\n got %s, need at least %s}`,
other: chalk`{red {bold ERROR! Not enough non-option arguments:}\n got %s, need at least %s}`
Expand All @@ -78,14 +85,28 @@ process.stdout.write(`${COLORS.Reset}`);

(async function () {
let name = argv.name;
let location = argv.location;
const location = argv.location;
const folderName = argv.folder as null | string;
console.log(argv);

const nameValidation = npmValiddate(name);
if (!nameValidation.validForNewPackages) {
throw new Error(
`Name "${name}" is not a valid NPM name:\n${nameValidation.errors}`
);
}

// determines how many `../` are needed for package contents
const numDirectoriesAwayFromRoot = 3 + (/\//g.exec(location) || []).length;
const relativePathToRoot = "../".repeat(numDirectoriesAwayFromRoot);

try {
const workspaceDir = join(__dirname, "../");
const LICENSE = readFile(join(workspaceDir, "LICENSE"), "utf-8");

const prettierConfig = await prettier.resolveConfig(process.cwd());

console.log(npa(name));
name = npa(name).name;

const packageName = `@ganache/${name}`;
Expand All @@ -97,7 +118,9 @@ process.stdout.write(`${COLORS.Reset}`);
version,
description: "",
author: packageAuthor || require("../package.json").author,
homepage: `https://github.com/trufflesuite/ganache-core/tree/develop/src/${location}/${name}#readme`,
homepage: `https://github.com/trufflesuite/ganache-core/tree/develop/src/${location}/${
folderName || name
}#readme`,
license: "MIT",
main: "lib/index.js",
types: "src/index.ts",
Expand All @@ -110,7 +133,7 @@ process.stdout.write(`${COLORS.Reset}`);
repository: {
type: "git",
url: "https://github.com/trufflesuite/ganache-core.git",
directory: `src/${location}/${name}`
directory: `src/${location}/${folderName || name}`
},
scripts: {
tsc: "ttsc",
Expand Down Expand Up @@ -139,7 +162,7 @@ process.stdout.write(`${COLORS.Reset}`);
};

const tsConfig = {
extends: "../../../tsconfig.json",
extends: `${relativePathToRoot}tsconfig.json`,
compilerOptions: {
outDir: "lib"
},
Expand All @@ -164,7 +187,7 @@ describe("${packageName}", () => {
}
`;

const dir = join(workspaceDir, "src", location, name);
const dir = join(workspaceDir, "src", location, folderName || name);
const tests = join(dir, "tests");
const src = join(dir, "src");

Expand Down Expand Up @@ -263,7 +286,9 @@ typedoc.json
);

console.log(
chalk`{green success} {magenta create} New package {bgBlack ${name} } created at ./src/packages/${name}.`
chalk`{green success} {magenta create} New package {bgBlack ${name} } created at ./src/${location}/${
folderName || name
}.`
);
console.log("");
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"scripts": {
"docs.build": "rm -rf ./lib/docs ./lib/api.json && npm run docs.typedoc",
"docs.typedoc": "typedoc --options ./typedoc.json --readme ./README.md --out ../../../docs/typedoc --json ../../../docs/typedoc/api.json src/api.ts",
"docs.preview": "ws --open --port 3010 --directory ../../../",
"docs.typedoc": "typedoc --options ./typedoc.json --readme ./README.md --out ../../../../docs/typedoc --json ../../../../docs/typedoc/api.json src/api.ts",
"docs.preview": "ws --open --port 3010 --directory ../../../../",
"tsc": "ttsc",
"test": "nyc --reporter lcov npm run mocha",
"mocha": "cross-env TS_NODE_COMPILER=ttypescript TS_NODE_FILES=true mocha --exit --check-leaks --throw-deprecation --trace-warnings --require ts-node/register 'tests/**/*.test.ts'"
Expand All @@ -49,6 +49,8 @@
"tooling"
],
"dependencies": {
"@ganache/ethereum-options": "^0.1.0",
"@ganache/ethereum-utils": "0.1.0",
"@ganache/options": "^0.1.0",
"@ganache/promise-queue": "^0.1.0",
"@ganache/utils": "^0.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
//#region Imports
import { RuntimeBlock, Block } from "./things/runtime-block";
import {
RuntimeBlock,
Block,
Tag,
Address,
Transaction,
BlockLogs,
Account,
VM_EXCEPTION,
VM_EXCEPTIONS,
CodedError,
ErrorCodes,
WhisperPostObject,
BaseFilterArgs,
Filter,
FilterArgs,
FilterTypes,
RangeFilterArgs,
SubscriptionId,
SubscriptionName
} from "@ganache/ethereum-utils";
import {
toRpcSig,
KECCAK256_NULL,
ecsign,
hashPersonalMessage
} from "ethereumjs-util";
import { TypedData as NotTypedData, signTypedData_v4 } from "eth-sig-util";
import { EthereumInternalOptions } from "./options";
import { types, Data, Quantity } from "@ganache/utils";
import { EthereumInternalOptions } from "@ganache/ethereum-options";
import { types, Data, Quantity, PromiEvent, utils } from "@ganache/utils";
import Blockchain, { TransactionTraceOptions } from "./blockchain";
import Tag from "./things/tags";
import { VM_EXCEPTION, VM_EXCEPTIONS } from "./errors/errors";
import Address from "./things/address";
import Transaction from "./things/transaction";
import Wallet from "./wallet";
import { decode as rlpDecode } from "rlp";
import { $INLINE_JSON } from "ts-transformer-inline-file";

import { PromiEvent, utils } from "@ganache/utils";
import Emittery from "emittery";
import Common from "ethereumjs-common";
import BlockLogs from "./things/blocklogs";
import EthereumAccount from "ethereumjs-account";
import estimateGas from "./helpers/gas-estimator";
import CodedError, { ErrorCodes } from "./errors/coded-error";
import { WhisperPostObject } from "./types/shh";
import {
BaseFilterArgs,
Filter,
FilterArgs,
FilterTypes,
RangeFilterArgs
} from "./types/filters";
import { assertArgLength } from "./helpers/assert-arg-length";
import Account from "./things/account";
import { SubscriptionId, SubscriptionName } from "./types/subscriptions";
import {
parseFilter,
parseFilterDetails,
parseFilterRange
} from "./helpers/filter-parsing";
import { Hardfork } from "./options/chain-options";
import { Hardfork } from "@ganache/ethereum-options";

// Read in the current ganache version from core's package.json
const { version } = $INLINE_JSON("../../../packages/ganache/package.json");
const { version } = $INLINE_JSON("../../../../packages/ganache/package.json");
const { keccak } = utils;
//#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import { EOL } from "os";
import RuntimeError, { RETURN_TYPES } from "./errors/runtime-error";
import Miner from "./miner/miner";
import Database from "./database";
import Emittery from "emittery";
import BlockManager from "./data-managers/block-manager";
import BlockLogs from "./things/blocklogs";
import {
BlockLogs,
Account,
Transaction,
TransactionReceipt,
Address,
RuntimeBlock,
Block,
ITraceData,
TraceDataFactory,
TraceStorageMap,
RuntimeError,
RETURN_TYPES,
Snapshots
} from "@ganache/ethereum-utils";
import TransactionManager from "./data-managers/transaction-manager";
import SecureTrie from "merkle-patricia-tree/secure";
import { BN, KECCAK256_RLP } from "ethereumjs-util";
import Account from "./things/account";
import { promisify } from "util";
import { Quantity, Data } from "@ganache/utils";
import { Quantity, Data, utils } from "@ganache/utils";
import AccountManager from "./data-managers/account-manager";
import { utils } from "@ganache/utils";
import Transaction from "./things/transaction";
import Manager from "./data-managers/manager";
import TransactionReceipt from "./things/transaction-receipt";
import { encode as rlpEncode } from "rlp";
import Common from "ethereumjs-common";
import VM from "ethereumjs-vm";
import Address from "./things/address";
import BlockLogManager from "./data-managers/blocklog-manager";
import { EVMResult } from "ethereumjs-vm/dist/evm/evm";
import { VmError, ERROR } from "ethereumjs-vm/dist/exceptions";
import { EthereumInternalOptions } from "./options";
import { Snapshots } from "./types/snapshots";
import { RuntimeBlock, Block } from "./things/runtime-block";
import { ITraceData, TraceDataFactory } from "./things/trace-data";
import TraceStorageMap from "./things/trace-storage-map";
import { EthereumInternalOptions } from "@ganache/ethereum-options";

const {
BUFFER_EMPTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import EthereumApi from "./api";
import { JsonRpcTypes, types, utils } from "@ganache/utils";
import EthereumProvider from "./provider";
import { RecognizedString, WebSocket, HttpRequest } from "uWebSockets.js";
import CodedError, { ErrorCodes } from "./errors/coded-error";
import { EthereumProviderOptions, EthereumLegacyOptions } from "./options";
import { CodedError, ErrorCodes } from "@ganache/ethereum-utils";
import {
EthereumProviderOptions,
EthereumLegacyOptions
} from "@ganache/ethereum-options";

export type ProviderOptions = EthereumProviderOptions | EthereumLegacyOptions;
export type Provider = EthereumProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Account from "../things/account";
import Address from "../things/address";
import { Account, Address, Tag } from "@ganache/ethereum-utils";
import Trie from "merkle-patricia-tree/baseTrie";
import Blockchain from "../blockchain";
import Tag from "../things/tags";
import { LevelUp } from "levelup";
import { rlp } from "ethereumjs-util";
import { utils, Quantity } from "@ganache/utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Manager from "./manager";
import Tag from "../things/tags";
import { Tag, Block } from "@ganache/ethereum-utils";
import { LevelUp } from "levelup";
import { Quantity, Data } from "@ganache/utils";
import Common from "ethereumjs-common";
import { Block } from "../things/runtime-block";

const NOTFOUND = 404;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import BlockLog from "../things/blocklogs";
import { BlockLogs } from "@ganache/ethereum-utils";
import { LevelUp } from "levelup";
import Manager from "./manager";
import { Quantity } from "@ganache/utils";

export default class BlockLogManager extends Manager<BlockLog> {
export default class BlockLogManager extends Manager<BlockLogs> {
constructor(base: LevelUp) {
super(base, BlockLog);
super(base, BlockLogs);
}

async get(key: string | Buffer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LevelUp } from "levelup";
import { Data } from "@ganache/utils";
import Tag from "../things/tags";
import { Tag } from "@ganache/ethereum-utils";
const NOTFOUND = 404;

export type Instantiable<T> = { new (...args: any[]): T };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Transaction from "../things/transaction";
import { Transaction } from "@ganache/ethereum-utils";
import Manager from "./manager";
import TransactionPool from "../transaction-pool";
import { EthereumInternalOptions } from "../options";
import { EthereumInternalOptions } from "@ganache/ethereum-options";
import { LevelUp } from "levelup";
import Blockchain from "../blockchain";
import PromiseQueue from "@ganache/promise-queue";
Expand Down
Loading