- Notifications
You must be signed in to change notification settings - Fork 2.7k
Focused Workspaces RFC Implementation #5663
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,261 @@ | ||
| /* @flow */ | ||
| | ||
| import * as reporters from '../../../src/reporters/index.js'; | ||
| import * as fs from '../../../src/util/fs.js'; | ||
| import {runInstall} from '../_helpers.js'; | ||
| import {Install} from '../../../src/cli/commands/install.js'; | ||
| import Lockfile from '../../../src/lockfile'; | ||
| | ||
| jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000; | ||
| | ||
| const path = require('path'); | ||
| | ||
| test.concurrent('focus does not work from a non-workspaces project', async (): Promise<void> => { | ||
| let error = ''; | ||
| const reporter = new reporters.ConsoleReporter({}); | ||
| try { | ||
| await runInstall({focus: true}, 'install-production'); | ||
| } catch (e) { | ||
| error = e.message; | ||
| } | ||
| expect(error).toContain(reporter.lang('workspacesFocusRootCheck')); | ||
| }); | ||
| | ||
| test.concurrent('focus does not work from the root of a workspaces project', async (): Promise<void> => { | ||
| let error = ''; | ||
| const reporter = new reporters.ConsoleReporter({}); | ||
| try { | ||
| await runInstall({focus: true}, 'published-monorepo'); | ||
| } catch (e) { | ||
| error = e.message; | ||
| } | ||
| expect(error).toContain(reporter.lang('workspacesFocusRootCheck')); | ||
| }); | ||
| | ||
| test.concurrent('focus does a normal workspace installation', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config): Promise<void> => { | ||
| const packageFile = await fs.readFile( | ||
| path.join(config.cwd, '..', '..', 'node_modules', 'example-yarn-workspace-2', 'package.json'), | ||
| ); | ||
| expect(JSON.parse(packageFile).version).toEqual('1.1.1'); | ||
| const readme = await fs.readFile( | ||
| path.join(config.cwd, '..', '..', 'node_modules', 'example-yarn-workspace-2', 'README.md'), | ||
| ); | ||
| expect(readme.split('\n')[0]).toEqual('WORKSPACES ROCK2!'); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent('focus shallowly installs sibling workspaces under target', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config): Promise<void> => { | ||
| const packageFile = await fs.readFile( | ||
| path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'), | ||
| ); | ||
| expect(JSON.parse(packageFile).version).toEqual('1.1.1'); | ||
| const readme = await fs.readFile(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'README.md')); | ||
| expect(readme.split('\n')[0]).toEqual('WORKSPACES ROCK2!'); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent('focus should not bail out early after an un-focused install', (): Promise<void> => { | ||
| return runInstall({}, 'published-monorepo', async (config, reporter) => { | ||
| const oldCwd = config.cwd; | ||
| | ||
| await fs.writeFile(path.join(oldCwd, 'node_modules', 'yarn.test'), 'YARN TEST'); | ||
| | ||
| config.cwd += '/packages/example-yarn-workspace-1'; | ||
| | ||
| const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(oldCwd)); | ||
| await reinstall.init(); | ||
| | ||
| expect(await fs.exists(path.join(oldCwd, 'node_modules', 'yarn.test'))).toBeFalsy(); | ||
| }); | ||
| }); | ||
| | ||
| test.concurrent('repeated focused installs should bail out early', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config, reporter) => { | ||
| await fs.writeFile(path.join(config.cwd, 'node_modules', 'yarn.test'), 'YARN TEST'); | ||
| | ||
| const lockfileDir = path.join(config.cwd, '..', '..'); | ||
| | ||
| const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(lockfileDir)); | ||
| await reinstall.init(); | ||
| | ||
| expect(await fs.exists(path.join(config.cwd, 'node_modules', 'yarn.test'))).toBeTruthy(); | ||
| | ||
| await fs.unlink(path.join(config.cwd, 'node_modules', 'yarn.test')); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent('switching directories for focused installs should fail integrity checks and reinstall', (): Promise< | ||
| void, | ||
| > => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config, reporter) => { | ||
| const rootDir = path.join(config.cwd, '..', '..'); | ||
| | ||
| await fs.writeFile(path.join(rootDir, 'node_modules', 'yarn.test'), 'YARN TEST'); | ||
| | ||
| config.cwd = path.join(rootDir, 'packages', 'example-yarn-workspace-2'); | ||
| | ||
| const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(rootDir)); | ||
| await reinstall.init(); | ||
| | ||
| expect(await fs.exists(path.join(rootDir, 'node_modules', 'yarn.test'))).toBeFalsy(); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent( | ||
| 'focus shallowly installs anything that a sibling needed to shallowly install underneath that sibling', | ||
| (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'focus-conflicts', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config, reporter) => { | ||
| const packageFile = await fs.readFile( | ||
| path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'node_modules', 'left-pad', 'package.json'), | ||
| ); | ||
| expect(JSON.parse(packageFile).version).toEqual('1.1.2'); | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| | ||
| test.concurrent("focus does not shallowly install a sibling's dev dependencies", (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'}, | ||
| async (config, reporter) => { | ||
| expect( | ||
| await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-3', 'node_modules', 'left-pad')), | ||
| ).toBeFalsy(); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent("focus runs shallow dependencies' postinstall scripts", (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'}, | ||
| async (config, reporter) => { | ||
| expect( | ||
| await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-3', 'temp.out')), | ||
| ).toBeTruthy(); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent('focus installs transitive dependencies shallowly', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'}, | ||
| async (config, reporter) => { | ||
| expect( | ||
| await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-1', 'package.json')), | ||
| ).toBeTruthy(); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent( | ||
| 'focus does not install transitive devdependencies shallowly (but does install non-transitive devdeps)', | ||
| (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-6'}, | ||
| async (config, reporter) => { | ||
| expect(await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-5'))).toBeTruthy(); | ||
| expect( | ||
| await fs.exists( | ||
| path.join( | ||
| config.cwd, | ||
| 'node_modules', | ||
| 'example-yarn-workspace-5', | ||
| 'node_modules', | ||
| 'example-yarn-workspace-2', | ||
| ), | ||
| ), | ||
| ).toBeFalsy(); | ||
| expect(await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2'))).toBeFalsy(); | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| | ||
| test.concurrent( | ||
| 'focus does not shallowly install current version of sibling if another version is specified in package.json', | ||
| (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'focus-different-versions', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config, reporter) => { | ||
| const packageFile = await fs.readFile( | ||
| path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'), | ||
| ); | ||
| expect(JSON.parse(packageFile).version).toEqual('1.0.1'); | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| | ||
| describe('nohoist', () => { | ||
| test.concurrent('focus installs nohoist dependencies shallowly', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'focus-nohoist', cwd: '/packages/example-yarn-workspace-1'}, | ||
| async (config, reporter) => { | ||
| const moduleDir = path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2'); | ||
| expect(await fs.exists(path.join(moduleDir, 'package.json'))).toBeTruthy(); | ||
| const stat = await fs.lstat(moduleDir); | ||
| expect(stat.isSymbolicLink()).toEqual(false); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent('focus does not do nested shallow installs of transitive nohoist packages', (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'focus-nohoist', cwd: '/packages/example-yarn-workspace-3'}, | ||
| async (config, reporter) => { | ||
| const moduleDir = path.join( | ||
| config.cwd, | ||
| 'node_modules', | ||
| 'example-yarn-workspace-1', | ||
| 'node_modules', | ||
| 'example-yarn-workspace-2', | ||
| ); | ||
| expect(await fs.exists(path.join(moduleDir, 'package.json'))).toBeFalsy(); | ||
| }, | ||
| ); | ||
| }); | ||
| | ||
| test.concurrent( | ||
| 'focus installs the correct version when a package is nohoist but differs from the workspace version', | ||
| (): Promise<void> => { | ||
| return runInstall( | ||
| {focus: true}, | ||
| {source: 'focus-nohoist-different-versions', cwd: '/packages/example-yarn-workspace-6'}, | ||
| async (config, reporter) => { | ||
| const packageFile = await fs.readFile( | ||
| path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'), | ||
| ); | ||
| expect(JSON.parse(packageFile).version).toEqual('1.0.0'); | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions 7 __tests__/fixtures/check/verify-tree-workspace-cwd/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "my-project", | ||
| "private": true, | ||
| "workspaces": [ | ||
| "packages/*" | ||
| ] | ||
| } |
30 changes: 30 additions & 0 deletions 30 __tests__/fixtures/check/verify-tree-workspace-cwd/packages/left-pad/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "name": "left-pad", | ||
| "version": "1.1.2", | ||
| "description": "String left pad", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "node test", | ||
| "bench": "node perf/perf.js" | ||
| }, | ||
| "keywords": [ | ||
| "leftpad", | ||
| "left", | ||
| "pad", | ||
| "padding", | ||
| "string", | ||
| "repeat" | ||
| ], | ||
| "repository": { | ||
| "url": "git@github.com:stevemao/left-pad.git", | ||
| "type": "git" | ||
| }, | ||
| "author": "azer", | ||
| "maintainers": [ | ||
| { | ||
| "name": "Cameron Westland", | ||
| "email": "camwest@gmail.com" | ||
| } | ||
| ], | ||
| "license": "WTFPL" | ||
| } |
7 changes: 7 additions & 0 deletions 7 __tests__/fixtures/check/verify-tree-workspace-cwd/packages/workspace-1/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "workspace-1", | ||
| "version": "1.0.0", | ||
| "dependencies": { | ||
| "left-pad": "1.1.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "monorepo", | ||
| "private": true, | ||
| "workspaces": [ | ||
| "packages/*" | ||
| ] | ||
| } |
1 change: 1 addition & 0 deletions 1 ...__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-1/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| WORKSPACES ROCK! |
1 change: 1 addition & 0 deletions 1 __tests__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-1/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('p1'); |
9 changes: 9 additions & 0 deletions 9 __tests__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-1/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "example-yarn-workspace-1", | ||
| "version": "1.0.1", | ||
| "dependencies": { | ||
| "example-yarn-workspace-2": "^1.0.0", | ||
| "left-pad": "1.1.3" | ||
| }, | ||
| "main": "index.js" | ||
| } |
1 change: 1 addition & 0 deletions 1 ...__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-2/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| WORKSPACES ROCK2! |
3 changes: 3 additions & 0 deletions 3 __tests__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-2/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/usr/bin/env node | ||
| | ||
| console.log('hey'); |
9 changes: 9 additions & 0 deletions 9 __tests__/fixtures/install/focus-conflicts/packages/example-yarn-workspace-2/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 made the change in check.js so that this test would pass. I needed it to work correctly for the new focus tests to work (or I could have avoided the check at the end of the install and be different from other install tests, but that felt wrong)