Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#577 support yarn workspaces #598

Merged
merged 18 commits into from
Jan 14, 2018

Conversation

amitgilad3
Copy link
Contributor

@AppVeyorBot
Copy link

Build bit 1.0.2893 failed (commit 455804ec78 by @amitgilad3)

@@ -603,6 +630,10 @@ export default class Consumer {
}
});
}

// add workspaces if flag is true
if (this.bitJson.manageWorkspaces) await this.addWorkspacesToPackageJson();
Copy link
Member

Choose a reason for hiding this comment

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

you should check that useWorkspaces is true and that packageManager is yarn. otherwise there is no reason to add workspaces

Copy link
Member

Choose a reason for hiding this comment

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

we should pass the path in case the import is done using -p with a custom path, in this case, we will need to specifically add this path to the workspaces because it won't be under the default directories.

scope: YARN_WORKSPACES_REGEX,
namespace: YARN_WORKSPACES_REGEX
});
const formatedRegexPath = formatedComponentsPath
Copy link
Member

Choose a reason for hiding this comment

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

add comment with example why we did that

.join(DEFAULT_SEPARATOR);
workSpaces.push(formatedRegexPath);
pkg.workspaces = R.uniq(workSpaces);
await pkg.write({ override: true });
Copy link
Member

Choose a reason for hiding this comment

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

you override the existing package.json, what will happen to fields that the user defined but are not supported by our packageJson class in bit-javascript? we should make sure we won't delete anything for the user..

Copy link
Member

Choose a reason for hiding this comment

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

Amit, regarding Gilad's comment, I had this exact concern when I implemented another task, so in order to keep the root package.json of the user with all the attributes, I didn't use the load() and write() methods of PackageJson.
Instead, I wrote a static method addComponentsIntoExistingPackageJson in the same PackageJson class in bit-javascript, which loads the package.json content raw, add an attribute and save it without creating an instance of PackageJson class.
Feel free to re-use it or write a new similar one.

const packageJson = { name, version };
fs.writeJSONSync(packageJsonPath, packageJson);
}
changePackageManagerToYarn(
Copy link
Member

Choose a reason for hiding this comment

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

this is confusing, it's change to yarn and also set the manage workspaces.
should be a seperate function.
Also we should add one for the useWorkspaces key.

fs.writeJSONSync(packageJsonPath, packageJson);
}
changePackageManagerToYarn(
withWorkspaces: boolean = true,
Copy link
Member

Choose a reason for hiding this comment

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

change the name to manageWorkspaces

@@ -1810,7 +1810,64 @@ describe('bit import', function () {
});
});
});

describe('import component with dependencies with yarn workspaces', () => {
Copy link
Member

@GiladShoham GiladShoham Jan 11, 2018

Choose a reason for hiding this comment

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

add the following cases:

  • running it again and make sure the is no duplication in the workspaces
  • add some custom field to the package.json and make sure we didn't delete it on the rewrite
  • import using -p and make sure the directory has been added to the workspaces
  • if manage workspaces is true but packageManager is npm / use workspaces is false, nothing happen
  • if the user put some workspaces himself, they shouldn't be overriden

@AppVeyorBot
Copy link

Build bit 1.0.2898 failed (commit 437aa940e3 by @amitgilad3)

@AppVeyorBot
Copy link

Build bit 1.0.2903 failed (commit b474f91fd9 by @amitgilad3)

@AppVeyorBot
Copy link

Build bit 1.0.2921 failed (commit 01bdcf9cee by @amitgilad3)

@AppVeyorBot
Copy link

Build bit 1.0.2923 failed (commit 763b88dc17 by @amitgilad3)

@AppVeyorBot
Copy link

Build bit 1.0.2934 failed (commit 18de389d84 by @amitgilad3)

@AppVeyorBot
Copy link

Build bit 1.0.2938 failed (commit 20b8d78eee by @amitgilad3)

@GiladShoham
Copy link
Member

closes #577

@GiladShoham GiladShoham merged commit 7d220d3 into master Jan 14, 2018
@GiladShoham GiladShoham deleted the feature/#577-support-yarn-workspaces branch January 14, 2018 19:10
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.

4 participants