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

Support for multiple dependencies #17

Merged
merged 14 commits into from
Aug 23, 2018
Merged

Support for multiple dependencies #17

merged 14 commits into from
Aug 23, 2018

Conversation

spalladino
Copy link
Contributor

@spalladino spalladino commented Aug 12, 2018

Tasks

  • Update lib contracts
  • Update lib models
  • Update lib examples
  • Update CLI main commands
  • Update documentation
  • Add CLI command to remove a dependency
  • Update stdlib model tests
  • Update TestApp model to work with new Projects
  • Update CLI status checkers
  • Validate CLI json version
  • Auto upgrade from CLI previous json format

Lib

App contract now has multiple providers, instead of having a single
one which could have a fallback (stdlib). Now the app explicitly manages
its dependencies. App is still offered in two flavours: unversioned
(which accepts directories) and versioned (which accepts packages with a
pinned version).

All contract wrapper models were also updated. In particular, App no
longer acts as a facade, but is instead an actual wrapper of the App
contract. A new abstraction, Project, is introduced to be used as a
facade by the CLI (or lib users). Project is subclassed by LibProject
and AppProject.

Part of #41

@spalladino spalladino added the status:in-progress Under development, do not merge this PR label Aug 12, 2018
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

The contracts look very good.

return info.package.getVersion(info.version);
}

function getPackage(string packageName) public view returns (Package, string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that the mapping is internal, we have no other way to access a package info


function unsetPackage(string packageName) public onlyOwner {
require(address(providers[packageName].package) != address(0), "Package to unset not found");
delete providers[packageName];
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing PackageChanged event here (and a test for it?).

@jbcarpanelli jbcarpanelli self-requested a review August 22, 2018 19:03
jbcarpanelli
jbcarpanelli previously approved these changes Aug 22, 2018
Copy link
Contributor

@jbcarpanelli jbcarpanelli left a comment

Choose a reason for hiding this comment

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

lgtm. I only added some minor comments regarding some changes we should make before releasing, but nothing really important.

}

async install() {
await npm.install([this.nameAndVersion], { save: true, cwd: process.cwd() })
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need of using async await here, as npm.install(...) is returning a promise that is being awaited in the function call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, but I have actually started using async/await in these cases to make it more explicit that the function should be awaited. If a user of this class sees an install() function, they may be inclined to call it directly; if they see async install(), they will certainly await it.

That said, when we migrate to typescript, as we annotate the function to return a promise, we can remove this :-P

}
}

static satisfiesVersion(version, requirement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move all static methods to the top of the class

const app = this.project.getApp()
this.networkFile.app = { address: app.address };

const thepackage = await this.project.getProjectPackage()
Copy link
Contributor

Choose a reason for hiding this comment

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

use lowerCamelCase and maybe rename this variable to projectPackage or something more descriptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. thepackage is the only case where I use all-lower, because strict mode prohibits using package as a variable name.

const proxies = await controller.upgradeProxies(contractAlias, proxyAddress, initMethod, initArgs);
_(proxies).values().forEach(proxies => proxies.forEach(proxy => stdout(proxy.address)));
const proxies = await controller.upgradeProxies(packageName, contractAlias, proxyAddress, initMethod, initArgs);
_.forEach(proxies, proxy => stdout(proxy.address));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: You could use proxies.forEach(proxy => stdout(proxy.address)) instead, and avoid lodash lib import (as this is the only lodash function call that is being used in this file). In addition to this, we could start importing only necessary lodash functions and not the whole lib (i.e., import { forEach } from 'lodash' or import { forEach as _forEach } from 'lodash' )

_.map(promisesWithObjects, handlingFailure)
)

if(!_.isEmpty(failures)) {
Copy link
Contributor

@jbcarpanelli jbcarpanelli Aug 22, 2018

Choose a reason for hiding this comment

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

You can move this conditional above the result variable assignment and avoid unnecessary promise management

App contract now has multiple providers, instead of having a single
one which could have a fallback (stdlib). Now the app explicitly manages
its dependencies. App is still offered in two flavours: unversioned
(which accepts directories) and versioned (which accepts packages with a
pinned version).

All contract wrapper models were also updated. In particular, App no
longer acts as a facade, but is instead an actual wrapper of the App
contract. A new abstraction, Project, is introduced to be used as a
facade by the CLI (or lib users). Project is subclassed by LibProject
and AppProject.
@spalladino spalladino merged commit 0d40e0e into next Aug 23, 2018
@facuspagnuolo facuspagnuolo deleted the feature/multiple-deps branch August 30, 2018 10:47
@spalladino spalladino removed the status:in-progress Under development, do not merge this PR label Aug 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants