diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..9dce9a072 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +lib +docs +*README.md +CHANGELOG.md +CONTRIBUTING.md +ISSUE_TEMPLATE.md +pull_request_template.md +ethereum/blockwatch/testdata +packages/**/generated/** +*.d.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a43010ff3..127ab0052 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,6 +44,20 @@ the dropdown menu in the GitHub UI to select `development`. make deps ``` +## Building TypeScript packages + +Mesh contains some TypeScript packages, all of which are contained in a small monorepo in the __packages/__ directory. Some +packages are published, and some are only used internally for development and testing. + +To build all the TypeScript packages: + +``` +yarn build +``` + +You can also run `yarn build` inside of individual packages in order to just build that package and its dependencies. However, +changing any Go code will require running `yarn build` at the root of the project again. + ## Running Tests Some of the tests depend on having a test Ethereum node running. Before running @@ -99,6 +113,20 @@ available linters, run: make lint ``` +## Running prettier + +0x Mesh uses a tool called [prettier](https://prettier.io/), which is a tool that +enforces a consistent style across the Typescript codebase. The continuous integration +pipeline will fail if Typescript code is not "prettified," so `prettier` must be run +to ensure that the code is properly formatted. + +The prettier tool can be run using the following command from the top-level of the +0x-Mesh repository (outside of a directory inside `packages/`): + +```bash +yarn prettier +``` + ## Managing Dependencies Mesh uses [Go Modules](https://github.com/golang/go/wiki/Modules) for managing @@ -144,3 +172,13 @@ following to your editor config: // ... } ``` + +### Prettier + +Prettier configurations for most popular text editors can be found +[here](https://prettier.io/docs/en/editors.html). + +### TSLint + +TSLint configurations for most popular text editors can be found +[here](https://palantir.github.io/tslint/usage/third-party-tools/). diff --git a/Makefile b/Makefile index 23cdecfc7..cfd251a0d 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ test-ts: .PHONY: lint -lint: lint-go lint-ts +lint: lint-go lint-ts lint-prettier .PHONY: lint-go @@ -80,6 +80,9 @@ lint-go: lint-ts: yarn lint +.PHONY: lint-prettier +lint-prettier: + yarn prettier:ci .PHONY: mesh mesh: diff --git a/cmd/cut-release/main.go b/cmd/cut-release/main.go index d667d02de..88c4c377e 100644 --- a/cmd/cut-release/main.go +++ b/cmd/cut-release/main.go @@ -107,30 +107,50 @@ func generateTypescriptDocs() { // Update the version string in all files that must be updated for a new release func updateHardCodedVersions(version string) { + newVersionString := fmt.Sprintf(`"version": "%s"`, version) + newBrowserLiteDependencyString := fmt.Sprintf(`"@0x/mesh-browser-lite": "^%s"`, version) + newBrowserDependencyString := fmt.Sprintf(`"@0x/mesh-browser": "^%s"`, version) + // Update `packages/rpc-client/package.json` tsClientPackageJSONPath := "packages/rpc-client/package.json" - newVersionString := fmt.Sprintf(`"version": "%s"`, version) regex := `"version": "(.*)"` updateFileWithRegex(tsClientPackageJSONPath, regex, newVersionString) // Update `packages/browser-lite/package.json` browserLitePackageJSONPath := "packages/browser-lite/package.json" - newVersionString = fmt.Sprintf(`"version": "%s"`, version) regex = `"version": "(.*)"` updateFileWithRegex(browserLitePackageJSONPath, regex, newVersionString) // Update `packages/browser/package.json` browserPackageJSONPath := "packages/browser/package.json" - newVersionString = fmt.Sprintf(`"version": "%s"`, version) regex = `"version": "(.*)"` updateFileWithRegex(browserPackageJSONPath, regex, newVersionString) - newBrowserLiteDependencyString := fmt.Sprintf(`"@0x/mesh-browser-lite": "^%s"`, version) // NOTE(jalextowle): `@0x/mesh-browser` uses the local version of `@0x/mesh-browser-lite` // on the `development` branch. Once the `@0x/mesh-browser-lite` package has been published, // we need to update dependency in `@0x/mesh-browser` to published version. regex = `"@0x/mesh-browser-lite": "(.*)"` updateFileWithRegex(browserPackageJSONPath, regex, newBrowserLiteDependencyString) + // Update `packages/webpack-example-lite/package.json` + webpackExampleLitePackageJSONPath := "packages/webpack-example-lite/package.json" + regex = `"@0x/mesh-browser-lite": "(.*)"` + updateFileWithRegex(webpackExampleLitePackageJSONPath, regex, newBrowserLiteDependencyString) + + // Update `packages/webpack-example/package.json` + webpackExamplePackageJSONPath := "packages/webpack-example/package.json" + regex = `"@0x/mesh-browser": "(.*)"` + updateFileWithRegex(webpackExamplePackageJSONPath, regex, newBrowserDependencyString) + + // Update `packages/integration-tests/package.json` + integrationTestsPackageJSONPath := "packages/integration-tests/package.json" + regex = `"@0x/mesh-browser": "(.*)"` + updateFileWithRegex(integrationTestsPackageJSONPath, regex, newBrowserDependencyString) + + // Update `packages/test-wasm/package.json` + testWasmPackageJSONPath := "packages/test-wasm/package.json" + regex = `"@0x/mesh-browser-lite": "(.*)"` + updateFileWithRegex(testWasmPackageJSONPath, regex, newBrowserLiteDependencyString) + // Update `core.go` corePath := "core/core.go" newVersionString = fmt.Sprintf(`version$1= "%s"`, version) diff --git a/cmd/peer-id-to-pub-key/REAMDE.md b/cmd/peer-id-to-pub-key/README.md similarity index 100% rename from cmd/peer-id-to-pub-key/REAMDE.md rename to cmd/peer-id-to-pub-key/README.md diff --git a/integration-tests/utils.go b/integration-tests/utils.go index 12c8d2ba0..e38ee1f35 100644 --- a/integration-tests/utils.go +++ b/integration-tests/utils.go @@ -116,29 +116,20 @@ func buildForTests(t *testing.T, ctx context.Context) { buildStandaloneForTests(t, ctx) buildBootstrapForTests(t, ctx) - fmt.Println("Clear yarn cache...") - cmd := exec.CommandContext(ctx, "yarn", "cache", "clean") - cmd.Dir = "../" + // Note(albrow): We have to rebuild the browser package manually in case + // any Go code was changed. The TypeScript compiler can automatically rebuild + // for TypeScript code changes only. + fmt.Println("Building mesh-browser package...") + cmd := exec.CommandContext(ctx, "yarn", "build") + cmd.Dir = "../packages/browser" output, err := cmd.CombinedOutput() - require.NoError(t, err, "could not clean yarn cache: %s", string(output)) + require.NoError(t, err, "could not build mesh-browser package: %s", string(output)) - fmt.Println("Installing dependencies for TypeScript bindings...") - cmd = exec.CommandContext(ctx, "yarn", "install", "--force") - cmd.Dir = "../" - output, err = cmd.CombinedOutput() - require.NoError(t, err, "could not install depedencies for TypeScript bindings: %s", string(output)) - - fmt.Println("Running postinstall for browser node...") - cmd = exec.CommandContext(ctx, "yarn", "postinstall") - cmd.Dir = "../packages/integration-tests" - output, err = cmd.CombinedOutput() - require.NoError(t, err, "could not run yarn postinstall: %s", string(output)) - - fmt.Println("Building TypeScript bindings...") + fmt.Println("Building integration-tests package...") cmd = exec.CommandContext(ctx, "yarn", "build") - cmd.Dir = "../" + cmd.Dir = "../packages/integration-tests" output, err = cmd.CombinedOutput() - require.NoError(t, err, "could not build TypeScript bindings: %s", string(output)) + require.NoError(t, err, "could not build integration-tests package: %s", string(output)) fmt.Println("Done building everything") } diff --git a/package.json b/package.json index e047df49c..0464b700f 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,20 @@ "engines": { "node": ">=11" }, - "workspaces": [ - "packages/*" - ], + "workspaces": [ + "packages/*" + ], "scripts": { "wsrun": "wsrun", - "build": "wsrun --stages --fast-exit --exclude-missing build $PKG", + "build": "wsrun --stages --fast-exit --exclude-missing build", "build:ts": "tsc -b", "watch:ts": "tsc -b -w", - "clean": "wsrun --fast-exit --exclude-missing clean $PKG", - "docs:md": "wsrun --fast-exit --exclude-missing docs:md $PKG", - "lint": "wsrun lint $PKG", - "test": "wsrun --fast-exit --exclude-missing test $PKG " + "clean": "wsrun --fast-exit --exclude-missing clean", + "docs:md": "wsrun --fast-exit --exclude-missing docs:md", + "lint": "wsrun lint", + "prettier": "prettier --write '**/*.{ts,tsx,json,md}' --config .prettierrc", + "prettier:ci": "prettier --list-different '**/*.{ts,tsx,json}' --config .prettierrc", + "test": "wsrun --fast-exit --exclude-missing test " }, "description": "A peer-to-peer network for sharing orders", "main": "index.js", diff --git a/packages/browser-lite/tsconfig.json b/packages/browser-lite/tsconfig.json index 9b2e7a73a..4e5310a9a 100644 --- a/packages/browser-lite/tsconfig.json +++ b/packages/browser-lite/tsconfig.json @@ -1,7 +1,7 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", + "extends": "../../tsconfig-base", + "compilerOptions": { + "outDir": "lib", "rootDir": "src" }, "include": ["./src/**/*"] diff --git a/packages/browser/package.json b/packages/browser/package.json index c2a27033a..0b9c08343 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -21,7 +21,7 @@ "docsPath": "../../docs/browser-bindings/browser" }, "dependencies": { - "@0x/mesh-browser-lite": "file:../browser-lite", + "@0x/mesh-browser-lite": "1.0.0", "base64-arraybuffer": "^0.2.0", "browserfs": "^1.4.3", "ethereum-types": "^3.0.0" diff --git a/packages/browser/tsconfig.json b/packages/browser/tsconfig.json index a60328de1..c64e47d2c 100644 --- a/packages/browser/tsconfig.json +++ b/packages/browser/tsconfig.json @@ -1,9 +1,14 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "src" + "extends": "../../tsconfig-base", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" }, "include": ["./src/**/*"], - "exclude": ["./conversion-tests/**/*"] + "exclude": ["./conversion-tests/**/*"], + "references": [ + { + "path": "../browser-lite" + } + ] } diff --git a/packages/browser/webpack.tsconfig.json b/packages/browser/webpack.tsconfig.json index 4a5c9e167..ce9e854da 100644 --- a/packages/browser/webpack.tsconfig.json +++ b/packages/browser/webpack.tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig", + "extends": "../../tsconfig-base", "compilerOptions": { "outDir": "lib", "rootDir": "." }, "include": ["./src/**/*", "./conversion-tests/**/*"], "exclude": ["./src/index.ts"] diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 379b7bad5..57ad834a7 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -5,8 +5,9 @@ "license": "Apache-2.0", "private": true, "scripts": { - "build": "node --max_old_space_size=3072 ./node_modules/.bin/webpack --mode=development", + "build": "yarn build:ts && node --max_old_space_size=3072 ./node_modules/.bin/webpack --mode=development", "build:ts": "tsc -b", + "clean": "shx rm ./dist/bundle.js || exit 0", "postinstall:comment": "Remove the go and scripts directories of the mesh browser package to reduce the webpack bundle size", "postinstall": "yarn rimraf ./node_modules/@0x/mesh-browser/go ./node_modules/@0x/mesh-browser/scripts", "lint": "tslint --format stylish --project ." @@ -19,7 +20,7 @@ "webpack-cli": "^3.3.7" }, "dependencies": { - "@0x/mesh-browser": "file:../browser", + "@0x/mesh-browser": "1.0.0", "@0x/order-utils": "^10.0.1", "@0x/subproviders": "^6.0.2", "@0x/utils": "^5.1.1" diff --git a/packages/integration-tests/tsconfig.json b/packages/integration-tests/tsconfig.json index e03ea0292..4bbac901f 100644 --- a/packages/integration-tests/tsconfig.json +++ b/packages/integration-tests/tsconfig.json @@ -1,9 +1,14 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "./dist", - "rootDir": "./src" , + "extends": "../../tsconfig-base", + "compilerOptions": { + "outDir": "./lib", + "rootDir": "./src", "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"] }, - "include": ["./src/**/*", "./test/**/*"] + "include": ["./src/**/*", "./test/**/*"], + "references": [ + { + "path": "../browser" + } + ] } diff --git a/packages/rpc-client/tsconfig.json b/packages/rpc-client/tsconfig.json index ab2cebace..bacfadd97 100644 --- a/packages/rpc-client/tsconfig.json +++ b/packages/rpc-client/tsconfig.json @@ -1,8 +1,8 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "." + "extends": "../../tsconfig-base", + "compilerOptions": { + "outDir": "lib", + "rootDir": "." }, "include": ["./src/**/*", "./test/**/*"] } diff --git a/packages/test-wasm/package.json b/packages/test-wasm/package.json index e8be05f39..f4e238acf 100644 --- a/packages/test-wasm/package.json +++ b/packages/test-wasm/package.json @@ -6,12 +6,12 @@ "main": "./lib/index.js", "license": "Apache-2.0", "scripts": { - "build": "./node_modules/.bin/webpack --mode=development", + "build": "tsc -b && ./node_modules/.bin/webpack --mode=development", "clean": "shx rm -r ./dist && shx rm -r ./lib || exit 0", "lint": "tslint --format stylish --project ." }, "dependencies": { - "@0x/mesh-browser-lite": "file:../browser-lite", + "@0x/mesh-browser-lite": "1.0.0", "shx": "^0.3.2", "typescript": "^3.9.3", "ts-loader": "^6.2.1", diff --git a/packages/test-wasm/tsconfig.json b/packages/test-wasm/tsconfig.json index c8f04c595..c9d6044a7 100644 --- a/packages/test-wasm/tsconfig.json +++ b/packages/test-wasm/tsconfig.json @@ -1,8 +1,13 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "src" + "extends": "../../tsconfig-base", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" }, - "include": ["./src/**/*"] + "include": ["./src/**/*"], + "references": [ + { + "path": "../browser-lite" + } + ] } diff --git a/packages/webpack-example-lite/package.json b/packages/webpack-example-lite/package.json index 27c173e32..396dd354f 100644 --- a/packages/webpack-example-lite/package.json +++ b/packages/webpack-example-lite/package.json @@ -5,10 +5,10 @@ "license": "Apache-2.0", "private": true, "scripts": { - "build": "yarn build:webpack && yarn build:wasm", + "build": "tsc -b && yarn build:webpack && yarn build:wasm", "build:wasm": "GOOS=js GOARCH=wasm go build -o ./dist/main.wasm ../browser/go/mesh-browser/main.go", "build:webpack": "node --max_old_space_size=3072 ./node_modules/.bin/webpack --mode=development", - "clean": "shx rm ./dist/bundle.js", + "clean": "shx rm ./dist/bundle.js || exit 0", "postinstall:comment": "Remove the go and scripts directories of the mesh browser package to reduce the webpack bundle size", "postinstall": "yarn rimraf ./node_modules/@0x/mesh-browser/go ./node_modules/@0x/mesh-browser/scripts", "lint": "tslint --format stylish --project ." @@ -22,6 +22,6 @@ "webpack-cli": "^3.3.7" }, "dependencies": { - "@0x/mesh-browser-lite": "file:../browser-lite" + "@0x/mesh-browser-lite": "1.0.0" } } diff --git a/packages/webpack-example-lite/tsconfig.json b/packages/webpack-example-lite/tsconfig.json index 051574ca2..47fde54f4 100644 --- a/packages/webpack-example-lite/tsconfig.json +++ b/packages/webpack-example-lite/tsconfig.json @@ -1,17 +1,13 @@ { + "extends": "../../tsconfig-base", "compilerOptions": { - "outDir": "./dist", - "rootDir": "./src", - "module": "commonjs", - "target": "es5", - "lib": ["es2017", "dom"], - "experimentalDecorators": true, - "downlevelIteration": true, - "noImplicitReturns": true, - "pretty": true, - "skipLibCheck": true, - "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], - "strict": true + "outDir": "lib", + "rootDir": "src" }, - "include": ["./src/**/*", "./test/**/*"] + "include": ["./src/**/*", "./test/**/*"], + "references": [ + { + "path": "../browser-lite" + } + ] } diff --git a/packages/webpack-example/package.json b/packages/webpack-example/package.json index 7a123bb02..bc02d1ba0 100644 --- a/packages/webpack-example/package.json +++ b/packages/webpack-example/package.json @@ -5,8 +5,8 @@ "license": "Apache-2.0", "private": true, "scripts": { - "build": "node --max_old_space_size=3072 ./node_modules/.bin/webpack --mode=development", - "clean": "shx rm ./dist/bundle.js", + "build": "tsc -b && node --max_old_space_size=3072 ./node_modules/.bin/webpack --mode=development", + "clean": "shx rm ./dist/bundle.js || exit 0", "postinstall:comment": "Remove the go and scripts directories of the mesh browser package to reduce the webpack bundle size", "postinstall": "yarn rimraf ./node_modules/@0x/mesh-browser/go ./node_modules/@0x/mesh-browser/scripts", "lint": "tslint --format stylish --project ." @@ -20,6 +20,6 @@ "webpack-cli": "^3.3.7" }, "dependencies": { - "@0x/mesh-browser": "file:../browser" + "@0x/mesh-browser": "1.0.0" } } diff --git a/packages/webpack-example/tsconfig.json b/packages/webpack-example/tsconfig.json index 051574ca2..6f064db05 100644 --- a/packages/webpack-example/tsconfig.json +++ b/packages/webpack-example/tsconfig.json @@ -1,17 +1,13 @@ { + "extends": "../../tsconfig-base", "compilerOptions": { - "outDir": "./dist", - "rootDir": "./src", - "module": "commonjs", - "target": "es5", - "lib": ["es2017", "dom"], - "experimentalDecorators": true, - "downlevelIteration": true, - "noImplicitReturns": true, - "pretty": true, - "skipLibCheck": true, - "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], - "strict": true + "outDir": "lib", + "rootDir": "src" }, - "include": ["./src/**/*", "./test/**/*"] + "include": ["./src/**/*", "./test/**/*"], + "references": [ + { + "path": "../browser" + } + ] } diff --git a/tsconfig-base.json b/tsconfig-base.json new file mode 100644 index 000000000..baaaed8a2 --- /dev/null +++ b/tsconfig-base.json @@ -0,0 +1,21 @@ +// This file is used as a base for all other tsconfig.json files. +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "lib": ["es2017", "dom"], + "experimentalDecorators": true, + "downlevelIteration": true, + "noImplicitReturns": true, + "pretty": true, + "skipLibCheck": true, + "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], + "strict": true, + "allowJs": true, + // These settings are required for TypeScript project references + "composite": true, + "declaration": true, + "declarationMap": true, + "sourceMap": true + } +} diff --git a/tsconfig.json b/tsconfig.json index e885735e1..1159fc8b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,7 @@ +// The root of the project is just a list of references and does not contain +// any top-level TypeScript code. { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "lib": ["es2017", "dom"], - "experimentalDecorators": true, - "downlevelIteration": true, - "noImplicitReturns": true, - "pretty": true, - "skipLibCheck": true, - "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], - "strict": true, - // These settings are required for TypeScript project references - "composite": true, - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "allowJs": true - }, - // The root of the project is just a list of references and does not contain - // any top-level TypeScript code. + "extends": "./tsconfig-base", "include": [], "references": [ { "path": "./packages/browser" }, diff --git a/yarn.lock b/yarn.lock index 79bbf28a0..df5dbf364 100644 --- a/yarn.lock +++ b/yarn.lock @@ -163,24 +163,6 @@ jsonschema "^1.2.0" lodash.values "^4.3.0" -"@0x/mesh-browser-lite@file:packages/browser-lite": - version "1.0.0" - dependencies: - "@0x/order-utils" "^10.2.0" - "@0x/utils" "^5.4.0" - ajv "^6.12.2" - base64-arraybuffer "^0.2.0" - browserfs "^1.4.3" - ethereum-types "^3.0.0" - -"@0x/mesh-browser@file:packages/browser": - version "1.0.0" - dependencies: - "@0x/mesh-browser-lite" "file:../Library/Caches/Yarn/v6/npm-@0x-mesh-browser-1.0.0-4471228d-3d01-4169-a560-65f26f9b73eb-1591298415054/node_modules/@0x/browser-lite" - base64-arraybuffer "^0.2.0" - browserfs "^1.4.3" - ethereum-types "^3.0.0" - "@0x/order-utils@^10.0.1", "@0x/order-utils@^10.2.0", "@0x/order-utils@^10.2.4": version "10.2.4" resolved "https://registry.yarnpkg.com/@0x/order-utils/-/order-utils-10.2.4.tgz#23afe4656c9c71f2cf80f510154f7e2900515d68"