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

feat(workspaces): nested workspaces #6151

Closed
wants to merge 1 commit into from
Closed
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
46 changes: 46 additions & 0 deletions __tests__/commands/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ async function runWorkspaces(
test('workspaces info should list the workspaces', (): Promise<void> => {
return runWorkspaces({}, ['info'], 'run-basic', (config, reporter) => {
expect(reporter.getBufferJson()).toEqual({
'nested-workspace-1': {
location: 'packages/nested-workspace/packages/nested-workspace-child-1',
workspaceDependencies: ['workspace-1'],
mismatchedWorkspaceDependencies: [],
},
'workspace-1': {
location: 'packages/workspace-child-1',
workspaceDependencies: [],
mismatchedWorkspaceDependencies: [],
},
'workspace-2': {
location: 'packages/workspace-child-2',
workspaceDependencies: ['workspace-1'],
mismatchedWorkspaceDependencies: [],
},
});
});
});

test('workspaces info for nested workspace should list the global workspaces', (): Promise<void> => {
const name = path.join('run-basic', 'packages', 'nested-workspace', 'packages', 'nested-workspace-child-1');
return runWorkspaces({}, ['info'], name, (config, reporter) => {
expect(reporter.getBufferJson()).toEqual({
'nested-workspace-1': {
location: 'packages/nested-workspace/packages/nested-workspace-child-1',
workspaceDependencies: ['workspace-1'],
mismatchedWorkspaceDependencies: [],
},
'workspace-1': {
location: 'packages/workspace-child-1',
workspaceDependencies: [],
Expand All @@ -42,3 +70,21 @@ test('workspaces info should list the workspaces', (): Promise<void> => {
});
});
});

test('workspaces info should list the local workspaces if nested is unspecified in the global', (): Promise<void> => {
const name = path.join('run-basic', 'packages', 'nested-workspace', 'packages', 'nested-workspace-child-2');
return runWorkspaces({}, ['info'], name, (config, reporter) => {
expect(reporter.getBufferJson()).toEqual({
'nested-workspace-1': {
location: 'packages/nested-workspace-child-1',
workspaceDependencies: [],
mismatchedWorkspaceDependencies: [],
},
'nested-workspace-2': {
location: 'packages/nested-workspace-child-2',
workspaceDependencies: [],
mismatchedWorkspaceDependencies: [],
},
});
});
});
3 changes: 2 additions & 1 deletion __tests__/fixtures/workspace/run-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "my-project",
"private": true,
"workspaces": [
"packages/*"
"packages/workspace-child-*",
"packages/nested-workspace/packages/nested-workspace-child-1"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "another-project-with-worspaces",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "nested-workspace-1",
"version": "1.0.0",
"license": "BSD-2-Clause",
"scripts": {
"prescript": "echo nested-workspace-1 prescript",
"script": "echo nested-workspace-1 script",
"postscript": "echo nested-workspace-1 postscript"
},
"dependencies": {
"workspace-1": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "nested-workspace-2",
"version": "1.0.0",
"license": "BSD-2-Clause",
"scripts": {
"prescript": "echo nested-workspace-2 prescript",
"script": "echo nested-workspace-2 script",
"postscript": "echo nested-workspace-2 postscript"
}
}
7 changes: 3 additions & 4 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export default class Config {
}

async findWorkspaceRoot(initial: string): Promise<?string> {
let lastFound = null;
let previous = null;
let current = path.normalize(initial);
if (!await fs.exists(current)) {
Expand All @@ -669,17 +670,15 @@ export default class Config {
if (ws && ws.packages) {
const relativePath = path.relative(current, initial);
if (relativePath === '' || micromatch([relativePath], ws.packages).length > 0) {
return current;
} else {
return null;
lastFound = current;
}
}

previous = current;
current = path.dirname(current);
} while (current !== previous);

return null;
return lastFound;
}

async resolveWorkspaces(root: string, rootManifest: Manifest): Promise<WorkspacesManifestMap> {
Expand Down