-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Throw friendly error when workspaces are not configured correctly #1212
Throw friendly error when workspaces are not configured correctly #1212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a good idea! A few formatting nits, and we're good to go.
test/Repository.js
Outdated
|
||
beforeAll(async () => { | ||
testDir = await initFixture("Repository/basic"); | ||
testDirWithWorkspaces = await initFixture("Repository/yarn-workspaces"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can move this into the one test case that actually needs it, instead of copying over the directory fixture every single test.
- it("returns workspace packageConfigs", () => {
+ it("returns workspace packageConfigs", async () => {
+ const testDirWithWorkspaces = await initFixture("Repository/yarn-workspaces");
const repo = new Repository(testDirWithWorkspaces);
test/Repository.js
Outdated
it("throws with friendly error if workspaces are not configured", () => { | ||
const repo = new Repository(testDir); | ||
repo.lernaJson.useWorkspaces = true; | ||
expect(() => repo.packageConfigs).toThrowErrorMatchingSnapshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid a solitary snapshot with a concise .toThrow(/workspaces need to be defined/)
assertion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if you use the "EWORKSPACES"
prefix, the regex can be even simpler: .toThrow(/EWORKSPACES/)
src/Repository.js
Outdated
@@ -61,6 +61,14 @@ class Repository { | |||
|
|||
get packageConfigs() { | |||
if (this.lernaJson.useWorkspaces) { | |||
if (!this.packageJson.workspaces) { | |||
throw new ValidationError( | |||
"Invalid workspaces", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "EWORKSPACES"
, to be consistent with other ValidationError
s
src/Repository.js
Outdated
if (!this.packageJson.workspaces) { | ||
throw new ValidationError( | ||
"Invalid workspaces", | ||
"workspaces need to be defined in the root package.json." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a multiline tagged template string (using dedent
, several examples of usage in src/Command.js).
Should probably call them "yarn workspaces", too, to clarify their origin.
@evocateur I've tidied it up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I’m not sure what’s up with the test:watch script, I just use |
@evocateur fyi - looks like it's to do with the way the tests borrow each others files so the tests can't run in parallel. Running in band works. Would be a larger rewrite of the tests. |
Ah, yes, that is a problem right now. Thanks for looking into it.
… On Jan 18, 2018, at 08:27, Craig Bilner ***@***.***> wrote:
@evocateur fyi - looks like it's to do with the way the tests borrow each others files so the tests can't run in parallel. Running in band works. Would be a larger rewrite of the tests.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
If you add
useWorkspaces
to your lerna config but don't make the necessary changes in yourpackage.json
,lerna bootstrap
will fail here.Motivation and Context
This PR adds a validation error to make it clearer where the problem is, rather than pointing at the call to
some
on anundefined
value for example.Potentially it should throw if not an
Array<string>
too?How Has This Been Tested?
There didn't appear to be any repo workspace tests so added an example for future use using the naming convention that seemed to exist. Added one test to confirm workspaces were correctly returned as a default and another for when
useWorkspaces
is configured only.As an aside all tests run and pass for me if I use
yarn test
butyarn test:watch
fails on several of them. I can look at this separately if needed?Types of changes
Checklist: