Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Fix Lerna issues? Migrate to Yarn workspaces #1241

Merged
merged 18 commits into from
Oct 28, 2019

Conversation

frangio
Copy link
Contributor

@frangio frangio commented Sep 20, 2019

Attempts to fix #665.

There is some context in #665, but I would like to have a clearer picture of what are the issues that people have been having with our current Lerna setup. It's clear to me that there's general unhappiness about it in the team but I haven't had enough experience with it to know the concrete issues.

The things I've run into are: 1) running npm ci in a package subdirectory doesn't work, and 2) npm installing any new dependency breaks the Lerna "links".

I've been experimenting with ways of fixing this but Lerna has basically zero documentation, specially around the lerna link functionality.

I've tried lerna link convert, which automatically converts all repository-local dependencies into file: dependencies, and at the same time hoists all dev dependencies to the root. However, the automatic conversion had some bugs, and I also didn't see the reason to do the hoisting at the same time.

I then tried manually converting to file: dependencies and I ran into some npm bugs where it simply fails to install (and I'm pretty sure this would have happened with Lerna's automatic conversion too). I have run into these bugs before in different projects. I just don't think npm handles file: dependencies well.

I then migrated to Yarn workspaces, and this seems to work more robustly. I've configured Lerna to work with Yarn workspaces. We can still use it for publishing, etc. This is what's included in this PR.

The downside is that this implies we have to migrate to Yarn rather than npm.

@frangio frangio requested a review from spalladino September 20, 2019 22:44
@frangio
Copy link
Contributor Author

frangio commented Sep 20, 2019

I have no idea if the CI is going to work.

@spalladino spalladino added the status:to-review Awaiting review label Oct 18, 2019
@frangio frangio force-pushed the lerna-refactor branch 4 times, most recently from dee36f2 to aec3476 Compare October 24, 2019 21:32
@frangio
Copy link
Contributor Author

frangio commented Oct 25, 2019

The only thing pending is fixing the starter kits integration test, but I don't want to step on @ylv-io here because I think he was working on that this week. Let's coordinate.

@ylv-io
Copy link
Contributor

ylv-io commented Oct 28, 2019

Hey @frangio. Thanks for all the efforts to move SDK to workspaces 🚀
Starter kit CI issue I fixed was on starter kit repo itself so have nothing to do with SDK.
Regarding kits integration test at SDK. It works just fine at master branch but It is not going to work on this PR because it depends on lerna bootstrap command to create symlinks for local oz command.

    run(`${findUp.sync('node_modules/.bin/lerna')} bootstrap --scope=tests-cli-kits --scope="@openzeppelin/*"`);

I am not familiar with yarn workspaces and how they manage local package dependencies. Do you have any idea what would the equivalent to the prior line in terms of yarn workspaces? Does lerna bootstrap still works under yarn workspaces?

@ylv-io
Copy link
Contributor

ylv-io commented Oct 28, 2019

Yet. There might be an issue with kits tests at SDK as well. They need some refactor as well anyway. I'll make a refactor/fix PR for kits.

@ylv-io
Copy link
Contributor

ylv-io commented Oct 28, 2019

#1269 updated kits tests but I am pretty certain we still have to deal with lerna bootstrap

@frangio
Copy link
Contributor Author

frangio commented Oct 28, 2019

lerna bootstrap now uses yarn under the hood, so it's okay to keep it.

Thanks! I'll review it in a bit.

Copy link
Contributor

@spalladino spalladino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @frangio! I particularly like how the CI script looks like now. And I see you used the opportunity to fix or clean up a bunch of other things as well.

Could you add a paragraph on the README to explain how to bootstrap the developer environment now? Assume a setup from scratch, no need to explain how to migrate from the old one.

- checkout
- restore_cache:
key: dependency-cache-v4-{{ checksum "yarn.lock" }}
- attach_workspace:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great usage of workspaces! The CI script is much cleaner now, and without any loss of performance 👏

@frangio
Copy link
Contributor Author

frangio commented Oct 28, 2019

@spalladino I updated the existing HACKING.md file with the information about development environment setup. Let me know if you think that information should go in the README.

@frangio frangio merged commit 6494075 into OpenZeppelin:master Oct 28, 2019
@frangio frangio deleted the lerna-refactor branch October 28, 2019 22:48
@abcoathup
Copy link
Contributor

abcoathup commented Oct 29, 2019

@spalladino @frangio should the environment setup go in CONTRIBUTING.md, otherwise change CONTRIBUTING to use setup in HACKING?

To run tests in packages/cli
I run yarn in the root
I still have to compile some contracts (I don't know if I am missing a step, or if there is still some config missing)

packages/cli$ npx truffle compile

Then I can run the tests

packages/cli$ yarn test

I get two tests failing, I don't know if this is as expected or if I am missing a step.
For the second failing test, I assume I am missing a step to run ganache-cli on a specific port:

  1) link command
       should call link script with a list of dependencies and no install:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/mnt/c/Users/andre/Documents/projects/forum/openzeppelin-sdk/packages/cli/test/commands/link.test.js)


  2) Contract: set-admin script
       on application contract
         "before each" hook: setup for "does not attempt to change admin of unowned proxy":
     Error:
Could not connect to your Ethereum client with the following parameters:
    - host       > localhost
    - port       > 9555
    - network_id > 4447
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)
packages/lib$ yarn test

I get three tests failing, I assume I am missing a step to run ganache-cli on a specific port:

     Error:
Could not connect to your Ethereum client with the following parameters:
    - host       > localhost
    - port       > 9555
    - network_id > 4447

Also may need to mention that this process replaces global installs (which feels obvious but I didn't know this until I deleted my local copy of the repo 😄)

$ npm list -g --depth=0
/home/abcoathup/.nvm/versions/node/v10.16.0/lib
├── @openzeppelin/cli@2.5.3 -> /mnt/c/Users/andre/Documents/projects/forum/openzeppelin-sdk/packages/cli
├── @openzeppelin/upgrades@2.5.3 -> /mnt/c/Users/andre/Documents/projects/forum/openzeppelin-sdk/packages/lib

@frangio
Copy link
Contributor Author

frangio commented Oct 29, 2019

I still have to compile some contracts (I don't know if I am missing a step, or if there is still some config missing)

It shouldn't be necessary to compile the contracts in packages/cli because they're only used for testing. They should be compiled automatically by Truffle when you run yarn test.

It should also not be necessary to run Ganache.

This is weird, because the tests are passing in CI, but some tests are also failing in my computer so there is something wrong here. There may also be some flakiness. Something crashed the first time I ran the CLI tests but didn't the second time. I'm gonna look into it.


Also may need to mention that this process replaces global installs (which feels obvious but I didn't know this until I deleted my local copy of the repo smile)

Wow, that should not be happening. Are you sure it was Yarn? @spalladino can you reproduce this?

@spalladino
Copy link
Contributor

Wow, that should not be happening. Are you sure it was Yarn? @spalladino can you reproduce this?

Could not reproduce. @abcoathup maybe you had run npm link earlier at some point...?

@abcoathup
Copy link
Contributor

@frangio

maybe you had run npm link earlier at some point...?

Sorry, I did run npm link during a previous attempt to run the tests using CONTRIBUTING

npm install
npx lerna bootstrap
openzeppelin-sdk/packages/cli$ npm link
openzeppelin-sdk/packages/lib$ npm link

Then

openzeppelin-sdk/packages/cli$ npm test
openzeppelin-sdk/packages/lib$ npm test

@abcoathup
Copy link
Contributor

Getting the following issues still:
#1268 (comment)

frangio added a commit that referenced this pull request Dec 23, 2019
* regenerate all lockfiles using npm install

* run yarn import

* migrate to yarn workspaces

* fix type errors

* modify circleci config to use yarn

* fix lib-complex example

* fix Dependency test

* set working_directory for integration tests

* fix first-project and creating-instances

* optimize circle ci setup job

* fix integration tests

* remove unused directory

* fix error when stderr is null

* configure create-react-app to skip dependency check

* Revert "remove unused directory"

This reverts commit 24781a4.

* trigger ci

* update HACKING.md for yarn

(cherry picked from commit 6494075)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:to-review Awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix lerna related issues
4 participants