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

Adds a failing test for focused workspaces #5967

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions __tests__/commands/install/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,30 @@ test.concurrent('focus works correctly when focusing on a scoped package', (): P
});
});

test.concurrent('focus work even when the workspace root also depends on other workspaces', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-root-dep', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
const existAndIsMaterialized = async moduleDir => {
expect(await fs.exists(path.join(moduleDir, 'package.json'))).toBeTruthy();
const stat = await fs.lstat(moduleDir);
expect(stat.isSymbolicLink()).toEqual(false);
};

// The one in the root must exist, and must be materialized (since we're focusing on example-yarn-workspace-1)
await existAndIsMaterialized(path.join(config.cwd, '..', '..', 'node_modules', 'example-yarn-workspace-2'));
Copy link
Contributor

Choose a reason for hiding this comment

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

this check will always fail because it's expecting it to not be a symlink even though it is one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why should it be a symlink? If you focus on a workspace I thought it meant that all other workspaces would be fetched from the network.

Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation is actually a little different from that. When you do a focused install, it installs everything like normal, and only adds in remote installs "shallowly". That means it doesn't put the remote copy of example-yarn-workspace-2 at root/node_modules. That is still a symlink to the local copy. Instead it installs it at packages/example-yarn-workspace-1/node_modules/examples-yarn-workspace-2. That helps deal with version conflict issues and also makes it quicker to switch back and forth between focused and not focused.

Copy link
Contributor

Choose a reason for hiding this comment

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

so basically the shallow install comes first in node module resolution so it masks the symlink and causes it not to be used.


// If there's one in example-yarn-workspace-1, it also has to be materialized
if (await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2'))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

there definitely should be one at this path, so I would recommend removing this check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally there shouldn't, because it should be hoisted to the root (since both the root and example-yarn-workspace-1 share the same dependency to example-yarn-workspace-2).

Copy link
Contributor

Choose a reason for hiding this comment

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

see my comment above. It would never hoist the remote copy of the workspace.

Copy link
Contributor

@bdwain bdwain Jun 12, 2018

Choose a reason for hiding this comment

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

oh i see what you're trying to do. You want to allow the stuff in the root workspace to depend on the pre-built copy of example-yarn-workspace-2.

Making something like that work would be a much bigger change I think. Because focus was only intended to affect the workspace you focus on. So the root workspace was never really intended to be affected (and neither were other workspaces). Also I didn't realize the root workspace was a regular workspace that could be used but that's a separate thing.

expect(
await existAndIsMaterialized(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2')),
Copy link
Contributor

@bdwain bdwain Jun 12, 2018

Choose a reason for hiding this comment

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

existsAndIsMaterialized has no return value, so this always fails. You can just get rid of the expect, since existsAndIsMaterialized makes the proper check inside of itself

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

).toBeTruthy();
}
},
);
});

describe('nohoist', () => {
test.concurrent('focus installs nohoist dependencies shallowly', (): Promise<void> => {
return runInstall(
Expand Down
11 changes: 11 additions & 0 deletions __tests__/fixtures/install/focus-root-dep/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "monorepo",
"private": true,
"workspaces": [
"packages/*"
],
"dependencies": {
"example-yarn-workspace-1": "*",
"example-yarn-workspace-2": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSPACES ROCK!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('p1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "example-yarn-workspace-1",
"version": "1.0.1",
"dependencies": {
"example-yarn-workspace-2": "^1.0.0"
},
"main": "index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSPACES ROCK2!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log('hey');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "example-yarn-workspace-2",
"version": "1.1.1",
"bin": "index.js",
"dependencies": {
"left-pad": "1.1.2"
},
"main": "index.js"
}
11 changes: 11 additions & 0 deletions __tests__/fixtures/install/focus-root-dep/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


left-pad@1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.2.tgz#b46d4b36116fafb6f2814c30ecf3247bdfd842f7"

left-pad@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"