Skip to content

Commit

Permalink
chore: enabling building from root (trufflesuite#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch authored and sam committed Apr 15, 2021
1 parent 67c22f4 commit 360aa93
Show file tree
Hide file tree
Showing 35 changed files with 74 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name> 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
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
27 changes: 17 additions & 10 deletions scripts/create.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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, "../");
Expand Down Expand Up @@ -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'"
Expand All @@ -184,7 +187,7 @@ process.stdout.write(`${COLORS.Reset}`);
};

const tsConfig = {
extends: `${relativePathToRoot}tsconfig.json`,
extends: `${relativePathToSrc}tsconfig-base.json`,
compilerOptions: {
outDir: "lib"
},
Expand Down Expand Up @@ -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"),
Expand All @@ -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.
Expand All @@ -243,6 +248,7 @@ describe("${packageName}", () => {
);
}

//@ts-ignore
function initRootFiles() {
return Promise.all([
writeFile(
Expand All @@ -261,6 +267,7 @@ typedoc.json
]);
}

//@ts-ignore
function initTests() {
return writeFile(
join(tests, "index.test.ts"),
Expand Down
8 changes: 5 additions & 3 deletions scripts/link-ts-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
4 changes: 3 additions & 1 deletion scripts/postinstall.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
3 changes: 1 addition & 2 deletions src/chains/ethereum/ethereum/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../../tsconfig.json",
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../../tsconfig.json",
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/chains/tezos/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/chains/tezos/options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../../tsconfig.json",
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/chains/tezos/tezos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"directory": "src/chains/tezos/tezos"
},
"scripts": {
"tsc": "ttsc"
"tsc": "ttsc --build"
},
"bugs": {
"url": "https://github.com/trufflesuite/ganache-core/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/chains/tezos/tezos/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../../tsconfig.json",
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/colors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/packages/colors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
4 changes: 2 additions & 2 deletions src/packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/flavors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"directory": "src/packages/flavors"
},
"scripts": {
"tsc": "ttsc"
"tsc": "ttsc --build"
},
"bugs": {
"url": "https://github.com/trufflesuite/ganache-core/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/flavors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/ganache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/ganache/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib"
},
Expand Down
2 changes: 1 addition & 1 deletion src/packages/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"directory": "src/packages/options"
},
"scripts": {
"tsc": "ttsc"
"tsc": "ttsc --build"
},
"bugs": {
"url": "https://github.com/trufflesuite/ganache-core/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/promise-queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/packages/promise-queue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
2 changes: 1 addition & 1 deletion src/packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"directory": "src/packages/utils"
},
"scripts": {
"tsc": "ttsc"
"tsc": "ttsc --build"
},
"bugs": {
"url": "https://github.com/trufflesuite/ganache-core/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "lib",
"composite": true
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json → src/tsconfig-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"noImplicitAny": false,
"newLine": "lf",
"lib": ["ES2020"],
"typeRoots": ["./node_modules/@types", "src/@types"],
"experimentalDecorators": true,
"plugins": [
{
Expand Down
Loading

0 comments on commit 360aa93

Please sign in to comment.