Skip to content

Conversation

@arcanis
Copy link
Member

@arcanis arcanis commented Feb 21, 2018

Summary

Running yarn workspaces info will now yield information to reconstruct the workspace dependency tree. This information can then be feed to other build systems.

Test plan

Updated the tests to include the new fields

@arcanis arcanis force-pushed the yarn-workspaces-info-deps branch from ee41f79 to e7e00b9 Compare February 21, 2018 14:52
@arcanis arcanis requested a review from BYK February 21, 2018 14:52
Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Logic looks good. Have comments about code quality and you also need to fix linting.

Approving to unblock but please address the comments before merging :)

const workspaceDependencies = new Set();
const mismatchedWorkspaceDependencies = new Set();

for (const dependencyType of DEPENDENCY_TYPES) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it better to just omit this before the loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? Duplicate the DEPENDENCY_TYPES array, but without peerDependencies?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. It seems wasteful and less readable this way to check for this specific value in every iteration.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe we could have a DIRECT_DEPENDENCY_TYPES array.

for (const dependencyType of DEPENDENCY_TYPES) {
if (dependencyType !== 'peerDependencies') {
for (const dependencyName of Object.keys(manifest[dependencyType] || {})) {
if (Object.prototype.hasOwnProperty.call(workspaces, dependencyName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't we have a shortcut for Object.prototype.hasOwnProperty.call here? Do we really need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we have, there's multiple matches for this function in the codebase.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, we should make that happen. That said I'm not sure if we need to be so defensive about this. We should be able to use Object.hasOwnProperty() I guess? Or some variant of Object.keys() that only returns own properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

Object.keys only returns own properties, but we're calling it on a different object from the one we're dereferencing. So for example, a malicious (or a bit weird) user could add a dependency called __proto__ to one of its workspaces, and without this check we would then access workspaces.__proto__.

if (dependencyType !== 'peerDependencies') {
for (const dependencyName of Object.keys(manifest[dependencyType] || {})) {
if (Object.prototype.hasOwnProperty.call(workspaces, dependencyName)) {
const request = manifest[dependencyType][dependencyName];
Copy link
Member

Choose a reason for hiding this comment

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

expectedRange, requestedRange? Something that wouldn't confuse me with an actual HTTP request or the request module?

@buildsize
Copy link

buildsize bot commented Feb 23, 2018

This change will increase the build size from 10.46 MB to 10.46 MB, an increase of 807 bytes (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 906.83 KB 906.85 KB 24 bytes (0%)
yarn-[version].js 3.94 MB 3.94 MB 146 bytes (0%)
yarn-legacy-[version].js 4.09 MB 4.09 MB 508 bytes (0%)
yarn-v[version].tar.gz 912.07 KB 912.01 KB -59 bytes (0%)
yarn_[version]all.deb 673.53 KB 673.71 KB 188 bytes (0%)

@arcanis arcanis merged commit 7bf5c16 into yarnpkg:master Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants