aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts-gen/.npmignore6
-rw-r--r--packages/contracts-gen/CHANGELOG.json1
-rw-r--r--packages/contracts-gen/README.md76
-rwxr-xr-xpackages/contracts-gen/bin/contracts-gen.js2
-rw-r--r--packages/contracts-gen/package.json49
-rw-r--r--packages/contracts-gen/src/contracts-gen.ts175
-rw-r--r--packages/contracts-gen/src/index.ts6
-rw-r--r--packages/contracts-gen/tsconfig.json8
-rw-r--r--packages/contracts-gen/tslint.json3
-rw-r--r--packages/metacoin/package.json3
-rw-r--r--packages/monorepo-scripts/package.json1
-rw-r--r--packages/monorepo-scripts/src/deps_versions.ts16
-rw-r--r--packages/monorepo-scripts/src/publish.ts8
-rw-r--r--packages/monorepo-scripts/src/test_installation.ts4
-rw-r--r--packages/monorepo-scripts/src/types.ts17
-rw-r--r--packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts3
-rw-r--r--packages/monorepo-scripts/src/utils/utils.ts14
-rw-r--r--packages/pipeline/package.json2
-rw-r--r--packages/sol-compiler/CHANGELOG.json9
-rw-r--r--packages/sol-compiler/src/compiler.ts16
-rw-r--r--packages/sol-compiler/src/utils/compiler.ts5
-rw-r--r--packages/types/src/index.ts24
-rw-r--r--packages/website/package.json2
23 files changed, 402 insertions, 48 deletions
diff --git a/packages/contracts-gen/.npmignore b/packages/contracts-gen/.npmignore
new file mode 100644
index 000000000..d645458f6
--- /dev/null
+++ b/packages/contracts-gen/.npmignore
@@ -0,0 +1,6 @@
+.*
+yarn-error.log
+/src/
+/scripts/
+tsconfig.json
+/lib/monorepo_scripts/
diff --git a/packages/contracts-gen/CHANGELOG.json b/packages/contracts-gen/CHANGELOG.json
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/packages/contracts-gen/CHANGELOG.json
@@ -0,0 +1 @@
+[]
diff --git a/packages/contracts-gen/README.md b/packages/contracts-gen/README.md
new file mode 100644
index 000000000..feaf9e65f
--- /dev/null
+++ b/packages/contracts-gen/README.md
@@ -0,0 +1,76 @@
+# Contracts Gen
+
+This package allows you to generate boilerplate TypeScript code and configs for smart contracts packages.
+
+## Installation
+
+`yarn add -g @0x/contracts-gen`
+
+## Usage
+
+Run it from within your smart contracts packages.
+
+```bash
+contracts-gen
+```
+
+You should run this tool after each time you move your contracts around to regenerate boilerplate code and configs.
+
+## What can it generate
+
+This tool does the following:
+
+- Reads your `compiler.json`. Specifically the list of smart contracts.
+- Creates `wrapper.ts` file which exports all contract wrappers.
+- Creates `artifacts.ts` file which exports all contract artifacts.
+- Generates list of JSON artifact files in `tsconfig.json`
+- Generates a glob for abi-gen in `package.json`
+
+On top of that - if your `compiler.json` has contracts referenced just by name - it will resolve the name to relative path and put it there.
+It also sorts all the lists in it's output leading to smaller and cleaner diffs.
+
+## Contributing
+
+We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
+
+Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
+
+### Install dependencies
+
+If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
+
+```bash
+yarn config set workspaces-experimental true
+```
+
+Then install dependencies
+
+```bash
+yarn install
+```
+
+### Build
+
+To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
+
+```bash
+PKG=@0x/contracts-gen yarn build
+```
+
+Or continuously rebuild on change:
+
+```bash
+PKG=@0x/contracts-gen yarn watch
+```
+
+### Clean
+
+```bash
+yarn clean
+```
+
+### Lint
+
+```bash
+yarn lint
+```
diff --git a/packages/contracts-gen/bin/contracts-gen.js b/packages/contracts-gen/bin/contracts-gen.js
new file mode 100755
index 000000000..ec6ab4db6
--- /dev/null
+++ b/packages/contracts-gen/bin/contracts-gen.js
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('../lib/src/contracts-gen.js');
diff --git a/packages/contracts-gen/package.json b/packages/contracts-gen/package.json
new file mode 100644
index 000000000..1265cac69
--- /dev/null
+++ b/packages/contracts-gen/package.json
@@ -0,0 +1,49 @@
+{
+ "name": "@0x/contracts-gen",
+ "version": "1.0.0",
+ "engines": {
+ "node": ">=6.12"
+ },
+ "description": "Generates boilerplate code for smart contracts packages",
+ "main": "lib/src/index.js",
+ "types": "lib/src/index.d.ts",
+ "scripts": {
+ "lint": "tslint --format stylish --project .",
+ "clean": "shx rm -rf lib",
+ "build": "tsc -b",
+ "build:ci": "yarn build"
+ },
+ "bin": {
+ "contracts-gen": "bin/contracts-gen.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/0xProject/0x-monorepo.git"
+ },
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/0xProject/0x-monorepo/issues"
+ },
+ "homepage": "https://github.com/0xProject/0x-monorepo/packages/contracts-gen/README.md",
+ "dependencies": {
+ "@0x/types": "^2.0.1",
+ "@0x/utils": "^4.0.2",
+ "@0x/typescript-typings": "^4.0.0",
+ "ethereum-types": "^2.0.0",
+ "@0x/sol-resolver": "^2.0.1",
+ "lodash": "^4.17.11",
+ "prettier": "^1.16.3",
+ "to-snake-case": "^1.0.0"
+ },
+ "devDependencies": {
+ "@0x/tslint-config": "^3.0.0",
+ "@types/node": "*",
+ "@types/prettier": "^1.15.2",
+ "shx": "^0.2.2",
+ "tslint": "5.11.0",
+ "typescript": "3.0.1"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/contracts-gen/src/contracts-gen.ts b/packages/contracts-gen/src/contracts-gen.ts
new file mode 100644
index 000000000..0160a8204
--- /dev/null
+++ b/packages/contracts-gen/src/contracts-gen.ts
@@ -0,0 +1,175 @@
+#!/usr/bin/env node
+
+import { NameResolver } from '@0x/sol-resolver';
+import { PackageJSON } from '@0x/types';
+import { logUtils } from '@0x/utils';
+import { CompilerOptions } from 'ethereum-types';
+import * as fs from 'fs';
+import * as _ from 'lodash';
+import * as path from 'path';
+import * as prettier from 'prettier';
+import toSnakeCase = require('to-snake-case');
+
+const SOLIDITY_EXTENSION = '.sol';
+const DEFAULT_ARTIFACTS_DIR = 'artifacts';
+const DEFAULT_CONTRACTS_DIR = 'contracts';
+const DEFAULT_WRAPPERS_DIR = 'generated-wrappers';
+const AUTO_GENERATED_BANNER = `/*
+* -----------------------------------------------------------------------------
+* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
+* -----------------------------------------------------------------------------
+*/`;
+const AUTO_GENERATED_BANNER_FOR_LISTS = `This list is auto-generated by contracts-gen. Don't edit manually.`;
+
+(async () => {
+ const packageDir = process.cwd();
+ const compilerJSON = readJSONFile<CompilerOptions>('compiler.json');
+ const contracts = compilerJSON.contracts;
+ const contractsDir = compilerJSON.contractsDir || DEFAULT_CONTRACTS_DIR;
+ const artifactsDir = compilerJSON.artifactsDir || DEFAULT_ARTIFACTS_DIR;
+ const wrappersDir = DEFAULT_WRAPPERS_DIR;
+ if (!_.isArray(contracts)) {
+ throw new Error('Unable to run the generator bacause contracts key in compiler.json is not of type array');
+ }
+ const prettierConfig = await prettier.resolveConfig(packageDir);
+ generateCompilerJSONContractsList(contracts, contractsDir, prettierConfig);
+ generateArtifactsTs(contracts, artifactsDir, prettierConfig);
+ generateWrappersTs(contracts, wrappersDir, prettierConfig);
+ generateTsConfigJSONFilesList(contracts, artifactsDir, prettierConfig);
+ generatePackageJSONABIConfig(contracts, artifactsDir, prettierConfig);
+ process.exit(0);
+})().catch(err => {
+ logUtils.log(err);
+ process.exit(1);
+});
+
+function generateCompilerJSONContractsList(
+ contracts: string[],
+ contractsDir: string,
+ prettierConfig: prettier.Options | null,
+): void {
+ const COMPILER_JSON_FILE_PATH = 'compiler.json';
+ const compilerJSON = readJSONFile<CompilerOptions>(COMPILER_JSON_FILE_PATH);
+ compilerJSON.contracts = _.map(contracts, contract => {
+ if (contract.endsWith(SOLIDITY_EXTENSION)) {
+ // If it's already a relative path - NO-OP.
+ return contract;
+ } else {
+ // If it's just a contract name - resolve it and rewrite.
+ return new NameResolver(contractsDir).resolve(contract).path;
+ }
+ });
+ compilerJSON.contracts = _.sortBy(compilerJSON.contracts);
+ const compilerJSONString = JSON.stringify(compilerJSON);
+ const formattedCompilerJSON = prettier.format(compilerJSONString, {
+ ...prettierConfig,
+ filepath: COMPILER_JSON_FILE_PATH,
+ });
+ fs.writeFileSync(COMPILER_JSON_FILE_PATH, formattedCompilerJSON);
+}
+
+function generateArtifactsTs(contracts: string[], artifactsDir: string, prettierConfig: prettier.Options | null): void {
+ const imports = _.map(contracts, contract => {
+ const contractName = path.basename(contract, SOLIDITY_EXTENSION);
+ const importPath = path.join('..', artifactsDir, `${contractName}.json`);
+ return `import * as ${contractName} from '${importPath}';`;
+ });
+ const sortedImports = _.sortBy(imports);
+ const artifacts = _.map(contracts, contract => {
+ const contractName = path.basename(contract, SOLIDITY_EXTENSION);
+ if (contractName === 'ZRXToken') {
+ // HACK(albrow): "as any" hack still required here because ZRXToken does not
+ // conform to the v2 artifact type.
+ return `${contractName}: (${contractName} as any) as ContractArtifact,`;
+ } else {
+ return `${contractName}: ${contractName} as ContractArtifact,`;
+ }
+ });
+ const artifactsTs = `
+ ${AUTO_GENERATED_BANNER}
+ import { ContractArtifact } from 'ethereum-types';
+
+ ${sortedImports.join('\n')}
+ export const artifacts = {${artifacts.join('\n')}};
+ `;
+ const ARTIFACTS_TS_FILE_PATH = 'src/artifacts.ts';
+ const formattedArtifactsTs = prettier.format(artifactsTs, { ...prettierConfig, filepath: ARTIFACTS_TS_FILE_PATH });
+ fs.writeFileSync(ARTIFACTS_TS_FILE_PATH, formattedArtifactsTs);
+}
+
+function generateWrappersTs(contracts: string[], wrappersDir: string, prettierConfig: prettier.Options | null): void {
+ const imports = _.map(contracts, contract => {
+ const contractName = path.basename(contract, SOLIDITY_EXTENSION);
+ const outputFileName = makeOutputFileName(contractName);
+ const exportPath = path.join('..', wrappersDir, outputFileName);
+ return `export * from '${exportPath}';`;
+ });
+ const sortedImports = _.sortBy(imports);
+ const wrappersTs = `
+ ${AUTO_GENERATED_BANNER}
+ ${sortedImports.join('\n')}
+ `;
+ const WRAPPERS_TS_FILE_PATH = 'src/wrappers.ts';
+ const formattedArtifactsTs = prettier.format(wrappersTs, { ...prettierConfig, filepath: WRAPPERS_TS_FILE_PATH });
+ fs.writeFileSync(WRAPPERS_TS_FILE_PATH, formattedArtifactsTs);
+}
+
+function generateTsConfigJSONFilesList(
+ contracts: string[],
+ artifactsDir: string,
+ prettierConfig: prettier.Options | null,
+): void {
+ const TS_CONFIG_FILE_PATH = 'tsconfig.json';
+ const tsConfig = readJSONFile<any>(TS_CONFIG_FILE_PATH);
+ tsConfig.files = _.map(contracts, contract => {
+ const contractName = path.basename(contract, SOLIDITY_EXTENSION);
+ const artifactPath = path.join(artifactsDir, `${contractName}.json`);
+ return artifactPath;
+ });
+ tsConfig.files = _.sortBy(tsConfig.files);
+ const tsConfigString = JSON.stringify(tsConfig);
+ const formattedTsConfig = prettier.format(tsConfigString, { ...prettierConfig, filepath: TS_CONFIG_FILE_PATH });
+ fs.writeFileSync(TS_CONFIG_FILE_PATH, formattedTsConfig);
+}
+
+function generatePackageJSONABIConfig(
+ contracts: string[],
+ artifactsDir: string,
+ prettierConfig: prettier.Options | null,
+): void {
+ let packageJSON = readJSONFile<PackageJSON>('package.json');
+ const contractNames = _.map(contracts, contract => {
+ const contractName = path.basename(contract, SOLIDITY_EXTENSION);
+ return contractName;
+ });
+ const sortedContractNames = _.sortBy(contractNames);
+ packageJSON = {
+ ...packageJSON,
+ config: {
+ ...packageJSON.config,
+ 'abis:comment': AUTO_GENERATED_BANNER_FOR_LISTS,
+ abis: `${artifactsDir}/@(${sortedContractNames.join('|')}).json`,
+ },
+ };
+ const PACKAGE_JSON_FILE_PATH = 'package.json';
+ const packageJSONString = JSON.stringify(packageJSON);
+ const formattedPackageJSON = prettier.format(packageJSONString, {
+ ...prettierConfig,
+ filepath: PACKAGE_JSON_FILE_PATH,
+ });
+ fs.writeFileSync(PACKAGE_JSON_FILE_PATH, formattedPackageJSON);
+}
+
+function makeOutputFileName(name: string): string {
+ let fileName = toSnakeCase(name);
+ // HACK: Snake case doesn't make a lot of sense for abbreviated names but we can't reliably detect abbreviations
+ // so we special-case the abbreviations we use.
+ fileName = fileName.replace('z_r_x', 'zrx').replace('e_r_c', 'erc');
+ return fileName;
+}
+
+function readJSONFile<T>(filePath: string): T {
+ const JSONString = fs.readFileSync(filePath, 'utf8');
+ const parsed: T = JSON.parse(JSONString);
+ return parsed;
+}
diff --git a/packages/contracts-gen/src/index.ts b/packages/contracts-gen/src/index.ts
new file mode 100644
index 000000000..c5f4b01f1
--- /dev/null
+++ b/packages/contracts-gen/src/index.ts
@@ -0,0 +1,6 @@
+/**
+ * This module is a CLI tool. As soon as you run it - it starts doing stuff.
+ * At the same time - our installation tests assume that you can import package without causing side effects.
+ * That's why our main entry point it empty. No side effects. But our secondary entry point - contracts-gen.ts is a CLI tool and starts running as soon as you import/run it.
+ */
+export {};
diff --git a/packages/contracts-gen/tsconfig.json b/packages/contracts-gen/tsconfig.json
new file mode 100644
index 000000000..233008d61
--- /dev/null
+++ b/packages/contracts-gen/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "lib",
+ "rootDir": "."
+ },
+ "include": ["./src/**/*"]
+}
diff --git a/packages/contracts-gen/tslint.json b/packages/contracts-gen/tslint.json
new file mode 100644
index 000000000..dd9053357
--- /dev/null
+++ b/packages/contracts-gen/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["@0x/tslint-config"]
+}
diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json
index 24b387355..fbff1c62a 100644
--- a/packages/metacoin/package.json
+++ b/packages/metacoin/package.json
@@ -24,7 +24,8 @@
"profiler:report:html": "istanbul report html && open coverage/index.html",
"coverage:report:lcov": "istanbul report lcov",
"test:circleci": "yarn test:coverage",
- "compile": "sol-compiler compile"
+ "compile": "sol-compiler",
+ "watch": "sol-compiler -w"
},
"author": "",
"license": "Apache-2.0",
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json
index fddcc13f8..24dca0004 100644
--- a/packages/monorepo-scripts/package.json
+++ b/packages/monorepo-scripts/package.json
@@ -47,6 +47,7 @@
"typescript": "3.0.1"
},
"dependencies": {
+ "@0x/types": "^2.0.1",
"@0x/utils": "^4.0.2",
"@lerna/batch-packages": "^3.0.0-beta.18",
"@types/depcheck": "^0.6.0",
diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts
index 0d01a2e3c..bb7e50f51 100644
--- a/packages/monorepo-scripts/src/deps_versions.ts
+++ b/packages/monorepo-scripts/src/deps_versions.ts
@@ -1,7 +1,7 @@
#!/usr/bin/env node
+import { PackageJSON, PackageJSONConfig } from '@0x/types';
import chalk from 'chalk';
-import * as fs from 'fs';
import { sync as globSync } from 'glob';
import * as path from 'path';
@@ -24,9 +24,10 @@ interface ParsedDependencies {
const PACKAGE_JSON_GLOB = '../../*/package.json';
-const config = JSON.parse(fs.readFileSync(path.join(__dirname, '../../../package.json')).toString()).config;
-const dependenciesWithIgnoredVersions: string[] = config.ignoreDependencyVersions.split(' ');
-const packagesWithIgnoredVersions: string[] = config.ignoreDependencyVersionsForPackage.split(' ');
+const config = utils.readJSONFile<PackageJSON>(path.join(__dirname, '../../../package.json'))
+ .config as PackageJSONConfig; // tslint:disable-line no-unnecessary-type-assertion
+const dependenciesWithIgnoredVersions: string[] = (config.ignoreDependencyVersions as string).split(' ');
+const packagesWithIgnoredVersions: string[] = (config.ignoreDependencyVersionsForPackage as string).split(' ');
if (require.main === module) {
const dependencies = parseDependencies();
@@ -44,11 +45,10 @@ if (require.main === module) {
}
function getDependencies(_path: string): Dependencies {
- const file = fs.readFileSync(_path).toString();
- const parsed = JSON.parse(file);
+ const packageJSON = utils.readJSONFile<PackageJSON>(_path);
const dependencies = {
- ...parsed.dependencies,
- ...parsed.devDependencies,
+ ...packageJSON.dependencies,
+ ...packageJSON.devDependencies,
};
return dependencies;
}
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts
index 196b4c2ff..ddb2811f2 100644
--- a/packages/monorepo-scripts/src/publish.ts
+++ b/packages/monorepo-scripts/src/publish.ts
@@ -1,8 +1,8 @@
#!/usr/bin/env node
+import { PackageJSON } from '@0x/types';
import { logUtils } from '@0x/utils';
import * as promisify from 'es6-promisify';
-import * as fs from 'fs';
import * as _ from 'lodash';
import * as moment from 'moment';
import opn = require('opn');
@@ -47,7 +47,7 @@ async function confirmAsync(message: string): Promise<void> {
await confirmAsync(
'THIS IS NOT A TEST PUBLISH! You are about to publish one or more packages to npm. Are you sure you want to continue? (y/n)',
);
- // await confirmDocPagesRenderAsync(packagesWithDocs);
+ await confirmDocPagesRenderAsync(packagesWithDocs);
}
// Update CHANGELOGs
@@ -141,8 +141,8 @@ async function publishImagesToDockerHubAsync(allUpdatedPackages: Package[]): Pro
function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] {
const rootPackageJsonPath = `${constants.monorepoRootPath}/package.json`;
- const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath).toString());
- const packagesWithDocPagesStringIfExist = _.get(rootPackageJson, 'config.packagesWithDocPages', undefined);
+ const rootPackageJSON = utils.readJSONFile<PackageJSON>(rootPackageJsonPath);
+ const packagesWithDocPagesStringIfExist = _.get(rootPackageJSON, 'config.packagesWithDocPages', undefined);
if (_.isUndefined(packagesWithDocPagesStringIfExist)) {
return []; // None to generate & publish
}
diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts
index 822f48967..ec145cd32 100644
--- a/packages/monorepo-scripts/src/test_installation.ts
+++ b/packages/monorepo-scripts/src/test_installation.ts
@@ -8,7 +8,7 @@ import { exec as execAsync } from 'promisify-child-process';
import * as rimraf from 'rimraf';
import { promisify } from 'util';
-import { Package } from './types';
+import { Changelog, Package } from './types';
import { utils } from './utils/utils';
// Packages might not be runnable if they are command-line tools or only run in browsers.
@@ -100,7 +100,7 @@ async function testInstallPackageAsync(
installablePackage: Package,
): Promise<void> {
const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json');
- const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version;
+ const lastChangelogVersion = utils.readJSONFile<Changelog>(changelogPath)[0].version;
const packageName = installablePackage.packageJson.name;
utils.log(`Testing ${packageName}@${lastChangelogVersion}`);
const packageDirName = path.join(...`${packageName}-test`.split('/'));
diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts
index 4af4fd257..e285d9082 100644
--- a/packages/monorepo-scripts/src/types.ts
+++ b/packages/monorepo-scripts/src/types.ts
@@ -1,3 +1,5 @@
+import { PackageJSON } from '@0x/types';
+
export interface UpdatedPackage {
name: string;
version: string;
@@ -34,21 +36,6 @@ export interface GitTagsByPackageName {
[packageName: string]: string[];
}
-export interface PackageJSON {
- private?: boolean;
- version: string;
- name: string;
- main?: string;
- scripts?: { [command: string]: string };
- config?: {
- postpublish?: {
- assets?: string[];
- docOmitExports?: string[];
- dockerHubRepo?: string;
- };
- };
-}
-
export interface Package {
location: string;
packageJson: PackageJSON;
diff --git a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
index 1a4294e9c..c0e86ad44 100644
--- a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
+++ b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
@@ -1,3 +1,4 @@
+import { PackageJSON } from '@0x/types';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
@@ -6,7 +7,7 @@ import * as ts from 'typescript';
import { constants } from '../constants';
import { docGenConfigs } from '../doc_gen_configs';
-import { ExportInfo, ExportNameToTypedocNames, ExportPathToExportedItems, PackageJSON } from '../types';
+import { ExportInfo, ExportNameToTypedocNames, ExportPathToExportedItems } from '../types';
import { utils } from './utils';
diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts
index 28c5658f3..20a6932c3 100644
--- a/packages/monorepo-scripts/src/utils/utils.ts
+++ b/packages/monorepo-scripts/src/utils/utils.ts
@@ -1,3 +1,4 @@
+import { PackageJSON } from '@0x/types';
import batchPackages = require('@lerna/batch-packages');
import * as fs from 'fs';
import * as _ from 'lodash';
@@ -5,7 +6,7 @@ import { exec as execAsync } from 'promisify-child-process';
import semver = require('semver');
import { constants } from '../constants';
-import { GitTagsByPackageName, Package, PackageJSON, UpdatedPackage } from '../types';
+import { GitTagsByPackageName, Package, UpdatedPackage } from '../types';
import { changelogUtils } from './changelog_utils';
@@ -13,6 +14,11 @@ export const utils = {
log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console
},
+ readJSONFile<T>(path: string): T {
+ const JSONString = fs.readFileSync(path, 'utf8');
+ const parsed: T = JSON.parse(JSONString);
+ return parsed;
+ },
getTopologicallySortedPackages(rootDir: string): Package[] {
const packages = utils.getPackages(rootDir);
const batchedPackages: PackageJSON[] = _.flatten(batchPackages(_.map(packages, pkg => pkg.packageJson), false));
@@ -23,8 +29,7 @@ export const utils = {
return topsortedPackages;
},
getPackages(rootDir: string): Package[] {
- const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8');
- const rootPackageJson = JSON.parse(rootPackageJsonString);
+ const rootPackageJson = utils.readJSONFile<PackageJSON>(`${rootDir}/package.json`);
if (_.isUndefined(rootPackageJson.workspaces)) {
throw new Error(`Did not find 'workspaces' key in root package.json`);
}
@@ -40,8 +45,7 @@ export const utils = {
}
const pathToPackageJson = `${rootDir}/${workspacePath}${subpackageName}`;
try {
- const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8');
- const packageJson = JSON.parse(packageJsonString);
+ const packageJson = utils.readJSONFile<PackageJSON>(`${pathToPackageJson}/package.json`);
const pkg = {
location: pathToPackageJson,
packageJson,
diff --git a/packages/pipeline/package.json b/packages/pipeline/package.json
index a1500cc74..3e45aa992 100644
--- a/packages/pipeline/package.json
+++ b/packages/pipeline/package.json
@@ -57,7 +57,7 @@
"dockerode": "^2.5.7",
"ethereum-types": "^2.0.0",
"pg": "^7.5.0",
- "prettier": "^1.15.3",
+ "prettier": "^1.16.3",
"ramda": "^0.25.0",
"reflect-metadata": "^0.1.12",
"sqlite3": "^4.0.2",
diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json
index 5f103342e..dd65f3aed 100644
--- a/packages/sol-compiler/CHANGELOG.json
+++ b/packages/sol-compiler/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "3.0.2",
+ "changes": [
+ {
+ "note": "Fix a bug when smart recompilation wasn't working because of remappings",
+ "pr": 1575
+ }
+ ]
+ },
+ {
"timestamp": 1549452781,
"version": "3.0.1",
"changes": [
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index efee3eb8a..c5dea1155 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -195,9 +195,7 @@ export class Compiler {
path.basename(contractSource.path, constants.SOLIDITY_FILE_EXTENSION),
);
} else {
- contractNamesToCompile = this._specifiedContracts.map(specifiedContract =>
- path.basename(specifiedContract, constants.SOLIDITY_FILE_EXTENSION),
- );
+ return this._specifiedContracts;
}
return contractNamesToCompile;
}
@@ -217,12 +215,9 @@ export class Compiler {
for (const contractName of contractNames) {
const spyResolver = new SpyResolver(this._resolver);
const contractSource = spyResolver.resolve(contractName);
- const sourceTreeHashHex = getSourceTreeHash(
- spyResolver,
- path.join(this._contractsDir, contractSource.path),
- ).toString('hex');
+ const sourceTreeHashHex = getSourceTreeHash(spyResolver, contractSource.path).toString('hex');
const contractData = {
- contractName,
+ contractName: path.basename(contractName, constants.SOLIDITY_FILE_EXTENSION),
currentArtifactIfExists: await getContractArtifactIfExistsAsync(this._artifactsDir, contractName),
sourceTreeHashHex: `0x${sourceTreeHashHex}`,
};
@@ -329,7 +324,10 @@ export class Compiler {
} else {
const currentArtifact = contractData.currentArtifactIfExists as ContractArtifact;
const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION;
- const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings);
+ const didCompilerSettingsChange = !_.isEqual(
+ _.omit(currentArtifact.compiler.settings, 'remappings'),
+ this._compilerSettings,
+ );
const didSourceChange = currentArtifact.sourceTreeHashHex !== contractData.sourceTreeHashHex;
return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
}
diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts
index c75f76dac..dffd07b1d 100644
--- a/packages/sol-compiler/src/utils/compiler.ts
+++ b/packages/sol-compiler/src/utils/compiler.ts
@@ -26,7 +26,10 @@ export async function getContractArtifactIfExistsAsync(
contractName: string,
): Promise<ContractArtifact | void> {
let contractArtifact;
- const currentArtifactPath = `${artifactsDir}/${contractName}.json`;
+ const currentArtifactPath = `${artifactsDir}/${path.basename(
+ contractName,
+ constants.SOLIDITY_FILE_EXTENSION,
+ )}.json`;
try {
const opts = {
encoding: 'utf8',
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index a30a0494f..b3a083999 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -691,6 +691,30 @@ export interface DutchAuctionDetails {
currentTimeSeconds: BigNumber;
}
+export interface PackageJSONConfig {
+ postpublish?: {
+ assets?: string[];
+ docOmitExports?: string[];
+ dockerHubRepo?: string;
+ };
+ 'abis:comment'?: string;
+ abis?: string;
+ ignoreDependencyVersions?: string;
+ ignoreDependencyVersionsForPackage?: string;
+}
+
+export interface PackageJSON {
+ private?: boolean;
+ version: string;
+ name: string;
+ main?: string;
+ scripts?: { [command: string]: string };
+ config?: PackageJSONConfig;
+ dependencies?: { [dependencyName: string]: string };
+ devDependencies?: { [dependencyName: string]: string };
+ workspaces?: string[];
+}
+
export interface EIP712DomainWithDefaultSchema {
name?: string;
version?: string;
diff --git a/packages/website/package.json b/packages/website/package.json
index 77295d4de..62b83b3ec 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -47,7 +47,7 @@
"find-versions": "^2.0.0",
"jsonschema": "^1.2.0",
"less": "^2.7.2",
- "lodash": "^4.17.5",
+ "lodash": "^4.17.11",
"material-ui": "^0.20.0",
"moment": "2.21.0",
"numeral": "^2.0.6",