diff --git a/.gitattributes b/.gitattributes index 4f0ae64f85..44bef32452 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ docs/assets/launch.json linguist-language=JSON5 +tsconfig-base.json linguist-language=JSON5 .nycrc linguist-language=JSON .prettierrc linguist-language=JSON diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b72c80cee0..5a2edefe5e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,10 +47,16 @@ directories, then reinstalls all modules. ## To compile -Compiles all packages: +Compiles the `ganache` package and its internal dependencies and subdependencies: - `npm run tsc` +To compile a package directly: + +- `npx lerna run --scope @ganache/ tsc` + +This can be useful if the package isn't yet in ganache's dependency tree. + ## To build the ganache package Creates the bundle that can be published to npm diff --git a/package.json b/package.json index ada470a26f..b93f521362 100644 --- a/package.json +++ b/package.json @@ -7,16 +7,16 @@ "npm": ">=6.4.1" }, "scripts": { - "build": "lerna run build && shx cp -r ./src/packages/ganache/dist/web ./docs/assets/js/ganache", + "build": "lerna run build && shx cp -r src/packages/ganache/dist/web docs/assets/js/ganache", "clean": "npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules", - "create": "ts-node ./scripts/create", - "docs.build": "lerna run docs.build && ts-node ./scripts/build-docs/", + "create": "ts-node scripts/create", + "docs.build": "lerna run docs.build && ts-node scripts/build-docs/", "docs.preview": "lerna run docs.preview", - "postinstall": "lerna bootstrap && npx patch-package && ts-node ./scripts/link-ts-references.ts && ts-node ./scripts/postinstall", + "postinstall": "lerna bootstrap && npx patch-package && ts-node scripts/link-ts-references.ts && npm run tsc && ts-node scripts/postinstall", "reinstall": "npm run clean && npm install", "start": "lerna exec --loglevel=silent --scope ganache -- npm run start --silent -- ", "test": "lerna exec -- npm run test", - "tsc": "lerna exec -- npm run tsc", + "tsc": "ttsc --build src", "tsc.clean": "npx lerna exec -- npx shx rm -rf lib dist" }, "devDependencies": { diff --git a/scripts/create.ts b/scripts/create.ts index 6294570b9d..e74f177900 100644 --- a/scripts/create.ts +++ b/scripts/create.ts @@ -1,10 +1,4 @@ import { TruffleColors } from "../src/packages/colors"; -import chalk from "chalk"; -import yargs from "yargs"; -import prettier from "prettier"; -import camelCase from "camelcase"; -import npmValiddate from "validate-npm-package-name"; -import userName from "git-user-name"; import { sep, join, resolve } from "path"; import { highlight } from "cli-highlight"; import { mkdir, mkdirSync, writeFile } from "fs-extra"; @@ -14,6 +8,15 @@ import { readFileSync as readFile } from "fs"; +// using `require` because everything in scripts uses typescript's default +// compiler settings, and these modules require enabling `esModuleInterop` +const npmValiddate = require("validate-npm-package-name"); +const userName = require("git-user-name"); +const camelCase = require("camelcase"); +const prettier = require("prettier"); +const chalk = require("chalk"); +const yargs = require("yargs"); + const COMMAND_NAME = "create"; const getArgv = () => { @@ -108,8 +111,8 @@ process.stdout.write(`${COLORS.Reset}`); } // determines how many `../` are needed for package contents - const numDirectoriesAwayFromRoot = 2 + location.split(sep).length; - const relativePathToRoot = "../".repeat(numDirectoriesAwayFromRoot); + const numDirectoriesAwayFromSrc = 1 + location.split(sep).length; + const relativePathToSrc = "../".repeat(numDirectoriesAwayFromSrc); const isNewChain = location === "chains"; const workspaceDir = join(__dirname, "../"); @@ -158,7 +161,7 @@ process.stdout.write(`${COLORS.Reset}`); directory: `src/${location}/${folderName}` }, scripts: { - tsc: "ttsc", + tsc: "ttsc --build", test: "nyc 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'" @@ -184,7 +187,7 @@ process.stdout.write(`${COLORS.Reset}`); }; const tsConfig = { - extends: `${relativePathToRoot}tsconfig.json`, + extends: `${relativePathToSrc}tsconfig-base.json`, compilerOptions: { outDir: "lib" }, @@ -212,6 +215,7 @@ describe("${packageName}", () => { const tests = join(dir, "tests"); const src = join(dir, "src"); + //@ts-ignore function initSrc() { return writeFile( join(src, "index.ts"), @@ -222,6 +226,7 @@ describe("${packageName}", () => { ); } + //@ts-ignore function initIndex() { // When a bundler compiles our libs this headerdoc comment will cause that // tool to retain our LICENSE information in their bundled output. @@ -243,6 +248,7 @@ describe("${packageName}", () => { ); } + //@ts-ignore function initRootFiles() { return Promise.all([ writeFile( @@ -261,6 +267,7 @@ typedoc.json ]); } + //@ts-ignore function initTests() { return writeFile( join(tests, "index.test.ts"), diff --git a/scripts/link-ts-references.ts b/scripts/link-ts-references.ts index 4f0b387134..26a206b8c5 100644 --- a/scripts/link-ts-references.ts +++ b/scripts/link-ts-references.ts @@ -3,11 +3,13 @@ * monorepo dependencies in each package's package.json. */ +import { readFileSync, existsSync, writeFileSync } from "fs-extra"; import { resolve, join, relative, sep } from "path"; -import glob from "glob"; -import { readFileSync, existsSync, writeFileSync } from "fs-extra"; -import JSON5 from "comment-json"; +// using `require` because everything in scripts uses typescript's default +// compiler settings, and these two modules require enabling `esModuleInterop` +const JSON5 = require("comment-json"); +const glob = require("glob"); type Mapping = { [key: string]: string }; diff --git a/scripts/postinstall.ts b/scripts/postinstall.ts index bf6bb8e904..05c908edbb 100644 --- a/scripts/postinstall.ts +++ b/scripts/postinstall.ts @@ -1,4 +1,6 @@ -import chalk from "chalk"; +// using `require` because everything in scripts uses typescript's default +// compiler settings, and this module requires enabling `esModuleInterop` +const chalk = require("chalk"); console.log(""); console.log( diff --git a/src/chains/ethereum/ethereum/package.json b/src/chains/ethereum/ethereum/package.json index dc01818287..5162c9146d 100644 --- a/src/chains/ethereum/ethereum/package.json +++ b/src/chains/ethereum/ethereum/package.json @@ -27,7 +27,7 @@ "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", - "tsc": "ttsc", + "tsc": "ttsc --build", "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'" }, diff --git a/src/chains/ethereum/ethereum/tsconfig.json b/src/chains/ethereum/ethereum/tsconfig.json index b308031091..41d562afc7 100644 --- a/src/chains/ethereum/ethereum/tsconfig.json +++ b/src/chains/ethereum/ethereum/tsconfig.json @@ -1,11 +1,10 @@ { - "extends": "../../../../tsconfig.json", + "extends": "../../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true }, "include": ["index.ts", "src/**/*"], - "typeRoots": ["./node_modules/@types", "./src/@types"], "references": [ { "name": "@ganache/ethereum-utils", diff --git a/src/chains/ethereum/options/package.json b/src/chains/ethereum/options/package.json index 353162d7b4..85f28b5f42 100644 --- a/src/chains/ethereum/options/package.json +++ b/src/chains/ethereum/options/package.json @@ -21,7 +21,7 @@ "directory": "src/chains/ethereum/options" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'" }, diff --git a/src/chains/ethereum/options/tsconfig.json b/src/chains/ethereum/options/tsconfig.json index e125e8ee55..5e42347456 100644 --- a/src/chains/ethereum/options/tsconfig.json +++ b/src/chains/ethereum/options/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../../tsconfig.json", + "extends": "../../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/chains/ethereum/utils/package.json b/src/chains/ethereum/utils/package.json index 6fcfe1695b..aa6b582b45 100644 --- a/src/chains/ethereum/utils/package.json +++ b/src/chains/ethereum/utils/package.json @@ -21,7 +21,7 @@ "directory": "src/chains/ethereum/utils" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'" }, diff --git a/src/chains/ethereum/utils/tsconfig.json b/src/chains/ethereum/utils/tsconfig.json index 216b9b7905..ab6c5fc9a8 100644 --- a/src/chains/ethereum/utils/tsconfig.json +++ b/src/chains/ethereum/utils/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../../tsconfig.json", + "extends": "../../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/chains/tezos/options/package.json b/src/chains/tezos/options/package.json index c5922a73fd..8f06c555b3 100644 --- a/src/chains/tezos/options/package.json +++ b/src/chains/tezos/options/package.json @@ -21,7 +21,7 @@ "directory": "src/chains/tezos/options" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'" }, diff --git a/src/chains/tezos/options/tsconfig.json b/src/chains/tezos/options/tsconfig.json index 7dc3b68a6c..f2b4acc379 100644 --- a/src/chains/tezos/options/tsconfig.json +++ b/src/chains/tezos/options/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../../tsconfig.json", + "extends": "../../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/chains/tezos/tezos/package.json b/src/chains/tezos/tezos/package.json index f9530449cc..989f71963d 100644 --- a/src/chains/tezos/tezos/package.json +++ b/src/chains/tezos/tezos/package.json @@ -24,7 +24,7 @@ "directory": "src/chains/tezos/tezos" }, "scripts": { - "tsc": "ttsc" + "tsc": "ttsc --build" }, "bugs": { "url": "https://github.com/trufflesuite/ganache-core/issues" diff --git a/src/chains/tezos/tezos/tsconfig.json b/src/chains/tezos/tezos/tsconfig.json index 4521ec320f..2d2d122dd4 100644 --- a/src/chains/tezos/tezos/tsconfig.json +++ b/src/chains/tezos/tezos/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../../tsconfig.json", + "extends": "../../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/cli/package.json b/src/packages/cli/package.json index 8d9db27a09..2945a38efb 100644 --- a/src/packages/cli/package.json +++ b/src/packages/cli/package.json @@ -25,7 +25,7 @@ "directory": "src/packages/cli" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'", "start": "cross-env TS_NODE_COMPILER=ttypescript node --require ts-node/register --inspect src/cli.ts" diff --git a/src/packages/cli/tsconfig.json b/src/packages/cli/tsconfig.json index 8985268a8b..9faebd6a95 100644 --- a/src/packages/cli/tsconfig.json +++ b/src/packages/cli/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/colors/package.json b/src/packages/colors/package.json index e2b455b399..f1273f6167 100644 --- a/src/packages/colors/package.json +++ b/src/packages/colors/package.json @@ -21,7 +21,7 @@ "directory": "src/packages/colors" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'" }, diff --git a/src/packages/colors/tsconfig.json b/src/packages/colors/tsconfig.json index 782054e6d5..d45dbc05ba 100644 --- a/src/packages/colors/tsconfig.json +++ b/src/packages/colors/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/core/package.json b/src/packages/core/package.json index 8fdc8eb0c6..26b4f8526f 100644 --- a/src/packages/core/package.json +++ b/src/packages/core/package.json @@ -24,9 +24,9 @@ "directory": "src/packages/core" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc npm run mocha", - "mocha": "cross-env TS_NODE_COMPILER=ttypescript TS_NODE_FILES=true mocha --exit --throw-deprecation --trace-warnings --check-leaks --require ts-node/register 'tests/**/*.test.ts'" + "mocha": "cross-env TS_NODE_PROJECT=tsconfig.json TS_NODE_COMPILER=ttypescript TS_NODE_FILES=true mocha --exit --throw-deprecation --trace-warnings --check-leaks --require ts-node/register 'tests/**/*.test.ts'" }, "bugs": { "url": "https://github.com/trufflesuite/ganache-core/issues" diff --git a/src/packages/core/src/server.ts b/src/packages/core/src/server.ts index 4f3183e851..bc877353a0 100644 --- a/src/packages/core/src/server.ts +++ b/src/packages/core/src/server.ts @@ -115,7 +115,7 @@ export default class Server { // https://github.com/uNetworking/uSockets/commit/04295b9730a4d413895fa3b151a7337797dcb91f#diff-79a34a07b0945668e00f805838601c11R51 const LIBUS_LISTEN_EXCLUSIVE_PORT = 1; hostname - ? (this.#app as any).listen( + ? this.#app.listen( hostname, port, LIBUS_LISTEN_EXCLUSIVE_PORT, diff --git a/src/packages/core/tsconfig.json b/src/packages/core/tsconfig.json index 846dcbe58d..3d5ee197d0 100644 --- a/src/packages/core/tsconfig.json +++ b/src/packages/core/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/flavors/package.json b/src/packages/flavors/package.json index 8889a8238a..62351c8e6c 100644 --- a/src/packages/flavors/package.json +++ b/src/packages/flavors/package.json @@ -21,7 +21,7 @@ "directory": "src/packages/flavors" }, "scripts": { - "tsc": "ttsc" + "tsc": "ttsc --build" }, "bugs": { "url": "https://github.com/trufflesuite/ganache-core/issues" diff --git a/src/packages/flavors/tsconfig.json b/src/packages/flavors/tsconfig.json index 80cb06ea37..bef9b17cdd 100644 --- a/src/packages/flavors/tsconfig.json +++ b/src/packages/flavors/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/ganache/package.json b/src/packages/ganache/package.json index cd80c7e24a..c886d84821 100644 --- a/src/packages/ganache/package.json +++ b/src/packages/ganache/package.json @@ -28,7 +28,7 @@ }, "scripts": { "build": "webpack", - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc 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'", "start": "cross-env TS_NODE_COMPILER=ttypescript node --require ts-node/register --inspect src/cli.ts" diff --git a/src/packages/ganache/tsconfig.json b/src/packages/ganache/tsconfig.json index 615de82fb7..6978f32ea3 100644 --- a/src/packages/ganache/tsconfig.json +++ b/src/packages/ganache/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib" }, diff --git a/src/packages/options/package.json b/src/packages/options/package.json index 0f9c7f017c..b7a508f5ab 100644 --- a/src/packages/options/package.json +++ b/src/packages/options/package.json @@ -20,7 +20,7 @@ "directory": "src/packages/options" }, "scripts": { - "tsc": "ttsc" + "tsc": "ttsc --build" }, "bugs": { "url": "https://github.com/trufflesuite/ganache-core/issues" diff --git a/src/packages/options/tsconfig.json b/src/packages/options/tsconfig.json index fe3cf528c0..594288dc75 100644 --- a/src/packages/options/tsconfig.json +++ b/src/packages/options/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/promise-queue/package.json b/src/packages/promise-queue/package.json index 4fdf5beb6c..7159af684f 100644 --- a/src/packages/promise-queue/package.json +++ b/src/packages/promise-queue/package.json @@ -21,7 +21,7 @@ "directory": "src/packages/promise-queue" }, "scripts": { - "tsc": "ttsc", + "tsc": "ttsc --build", "test": "nyc npm run mocha", "mocha": "cross-env TS_NODE_COMPILER=ttypescript TS_NODE_FILES=true mocha --exit --require ts-node/register --recursive --check-leaks 'tests/**.ts'" }, diff --git a/src/packages/promise-queue/tsconfig.json b/src/packages/promise-queue/tsconfig.json index d6032d24d6..6fd42631a1 100644 --- a/src/packages/promise-queue/tsconfig.json +++ b/src/packages/promise-queue/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/src/packages/utils/package.json b/src/packages/utils/package.json index ca6cb2bf41..3f328fd766 100644 --- a/src/packages/utils/package.json +++ b/src/packages/utils/package.json @@ -24,7 +24,7 @@ "directory": "src/packages/utils" }, "scripts": { - "tsc": "ttsc" + "tsc": "ttsc --build" }, "bugs": { "url": "https://github.com/trufflesuite/ganache-core/issues" diff --git a/src/packages/utils/tsconfig.json b/src/packages/utils/tsconfig.json index d6032d24d6..6fd42631a1 100644 --- a/src/packages/utils/tsconfig.json +++ b/src/packages/utils/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../../tsconfig-base.json", "compilerOptions": { "outDir": "lib", "composite": true diff --git a/tsconfig.json b/src/tsconfig-base.json similarity index 92% rename from tsconfig.json rename to src/tsconfig-base.json index d4e572f589..2821d56f8b 100644 --- a/tsconfig.json +++ b/src/tsconfig-base.json @@ -16,7 +16,6 @@ "noImplicitAny": false, "newLine": "lf", "lib": ["ES2020"], - "typeRoots": ["./node_modules/@types", "src/@types"], "experimentalDecorators": true, "plugins": [ { diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 0000000000..a4e5723ac4 --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,8 @@ +{ + "files": [], + "references": [ + { + "path": "packages/ganache" + } + ] +}