This document contains some tips on how to collaborate in this project.
This repository is a monorepo handled with Lerna.
There's a folder for each subproject in packages/. All of them are plugins, except for /packages/buidler-core which
is the main project (i.e. the one that's published as @nomiclabs/buidler).
To install this project you have to run:
npm install
Plugins require buidler-core to be built or tested. Our recommendation is to run npm run watch from the root folder.
This will keep everything compiled, and these problems will be avoided.
All tests are written using mocha and chai.
You can run a package's tests by executing npm test inside its folder.
Note: for package buidler-vyper case, a running instance of Docker Desktop is required, with ethereum/vyper image pulled. To install it, run:
docker pull ethereum/vyper:0.1.0b10
You can run all the tests at once by running npm test from the root folder.
For the case of package buidler-vyper, an ethereum/vyper docker instance installed is required (see previous section for details). Exception of this requirement is if running on a Windows local machine, in this case we skip it by default since Win 10 Pro version would be also required.
We use Prettier to format all the code without any special configuration. Whatever Prettier does is considered The Right Thing. It's completely fine to commit non-prettied code and then reformat it in a later commit.
We also have tslint installed in all the projects. It checks that you have run Prettier and forbids some dangerous patterns.
The linter is always run in the CI, so make sure it passes before pushing code. You can use npm run lint and
npm run lint:fix inside the packages' folders.
We work on the branch development
and keep master in sync with the latest release.
Please, branch from development when implementing a new feature or fixing a
bug, and use it as the base branch in pull requests.
If you are modifying the default config, adding a feature, or doing any kind of technical work that should be reflected in the documentation, the documentation change should be contained in the same branch and PR than the change.
If you are working purely on the website or documentation, not as a result of
a technical change, you should branch from website
and use it as the base branch in your pull request. Anything merged into
website this way should also be merged into development.
Note that the website branch is automatically deployed, so take care when
merging into it.
We keep our dependencies versions in sync between the different projects.
Running node scripts/check-dependencies.js from the root folder checks that every project specifies the same versions
of each dependency. It will print an error if the versions get out of sync.
Buidler and its plugins are optimized for keeping startup time low.
This is done by selectively requiring dependencies when needed using import or require following this criteria:
- If something is only imported for its type, and NOT its value, use a top-level
import ... from "mod" - If a module is in the "Essential modules" list below, use a top-level
import ... from "mod"". - Otherwise, use
await importorrequirelocally in the functions that use it.- If the function is sync, use node's
require - If the function is an async, use
await import
- If the function is sync, use node's
Note that these rules don't apply to tests. You can always use top-level imports there.
This is a list of the modules that always get loaded during startup:
fspathutilfind-upfs-extrachalksemverdeepmergesource-map-support/register
All these tips assume you are running npm run watch from the root directory.
You can link any package to test it locally. For example, if you are working on
buidler-core, you can follow these steps:
- Go to
packages/buidler-coreand runnpm link - Go to some buidler project and run
npm link @nomiclabs/buidler
Alternatively, you can go to your buidler project and run npm link /path/to/buidler/packages/buidler-core.
Now any change you make in the code will be reflected in that project.
If for any reason linking doesn't work for you, you can use yalc.
- Go to
packages/buidler-coreand runyalc publish - Go to some buidler project and run
yalc add @nomiclabs/buidler
Unlike linking, if you make a change in the code, you'll need to repeat the process.
An even more realistic way of using your local changes in a project is to use npm pack:
- Go to
packages/buidler-coreand runnpm pack. This will create anomiclabs-buidler-x.y.z.tgzfile in that directory. - Go to some buidler project and run
npm install /path/to/buidler/packages/buidler-core/nomiclabs-buidler-x.y.z.tgz.
Unlike linking, if you make a change in the code, you'll need to repeat the process.
If you want to debug something, you can use ndb. First add a debugger
statement wherever you want. Then link your project. Finally, run buidler as normally but prepend the command with
ndb. For example, you can do ndb npx buidler compile to debug some part of the compile task.
You should avoid monkey-patching whenever possible. But if it's necessary to do so, you should pay extra care when doing it in Buidler or your tests may fail in very hard to debug ways.
When tests are run, Buidler gets initialized multiple times. That may lead to monkey-patching the same multiple times. To avoid this, keep references to the original implementations. In order to do this, you need to get it just once:
let originalImpl; // May be a global
// ...
if (originalImpl === undefined) {
originalImpl = lib.func;
}
lib.func = function(...args) {
// Do something;
return originalImpl.apply(this, args);
};This isn't normally a problem if you are monkey-patching an object's methods. But it is when monkey-patching a class or its prototype.