Skip to content

Commit

Permalink
Merge branch 'main' into chrisbarber/get-project-team-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Barber committed Jun 12, 2023
2 parents c41499c + c438bbb commit 5c75c83
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 163 deletions.
2 changes: 2 additions & 0 deletions .changeset/fluffy-eggs-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/yellow-eels-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
241 changes: 135 additions & 106 deletions examples/nextjs/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"lint": "next lint"
},
"dependencies": {
"eslint": "8.41.0",
"eslint-config-next": "13.4.4",
"next": "13.4.4",
"eslint": "8.42.0",
"eslint-config-next": "13.4.5",
"next": "13.4.5",
"react": "18.2.0",
"react-dom": "18.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"source-map-support": "0.5.12",
"ts-eager": "2.0.2",
"ts-jest": "29.1.0",
"turbo": "1.10.1",
"turbo": "1.10.3",
"typescript": "4.9.5"
},
"scripts": {
Expand Down
17 changes: 6 additions & 11 deletions packages/cli/src/util/link/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function findProjectsFromPath(
path: string
): RepoProjectConfig[] {
const normalizedPath = normalizePath(path);
return projects
const matches = projects
.slice()
.sort(sortByDirectory)
.filter(project => {
Expand All @@ -288,14 +288,9 @@ export function findProjectsFromPath(
normalizedPath.startsWith(`${project.directory}/`)
);
});
}

/**
* TODO: remove
*/
export function findProjectFromPath(
projects: RepoProjectConfig[],
path: string
): RepoProjectConfig | undefined {
return findProjectsFromPath(projects, path)[0];
// If there are multiple matches, we only want the most relevant
// selections (with the deepest directory depth), so pick the first
// one and filter on those matches.
const firstMatch = matches[0];
return matches.filter(match => match.directory === firstMatch.directory);
}
41 changes: 21 additions & 20 deletions packages/cli/test/unit/util/link/repo.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tmpdir } from 'node:os';
import { join, sep } from 'node:path';
import {
findProjectFromPath,
findProjectsFromPath,
findRepoRoot,
RepoProjectConfig,
traverseUpDirectories,
Expand Down Expand Up @@ -57,35 +57,36 @@ describe('traverseUpDirectories()', () => {
});
});

describe('findProjectFromPath()', () => {
describe('findProjectsFromPath()', () => {
const projects: RepoProjectConfig[] = [
{ id: 'root', name: 'r', directory: '.' },
{ id: 'site', name: 'a', directory: 'apps/site' },
{ id: 'site2', name: 'a', directory: 'apps/site2' },
{ id: 'other', name: 'b', directory: 'apps/other' },
{ id: 'duplicate', name: 'd', directory: 'apps/other' },
{ id: 'nested', name: 'n', directory: 'apps/other/nested' },
];

it.each([
{ id: 'root', path: '.' },
{ id: 'root', path: 'lib' },
{ id: 'root', path: 'lib' },
{ id: 'site', path: `apps${sep}site` },
{ id: 'site', path: `apps${sep}site` },
{ id: 'site', path: `apps${sep}site${sep}components` },
{ id: 'site2', path: `apps${sep}site2` },
{ id: 'site2', path: `apps${sep}site2${sep}inner` },
{ id: 'other', path: `apps${sep}other` },
{ id: 'other', path: `apps${sep}other${sep}lib` },
{ id: 'nested', path: `apps${sep}other${sep}nested` },
{ id: 'nested', path: `apps${sep}other${sep}nested${sep}foo` },
])('should find Project "$id" for path "$path"', ({ path, id }) => {
const actual = findProjectFromPath(projects, path);
expect(actual?.id).toEqual(id);
{ ids: ['root'], path: '.' },
{ ids: ['root'], path: 'lib' },
{ ids: ['root'], path: 'lib' },
{ ids: ['site'], path: `apps${sep}site` },
{ ids: ['site'], path: `apps${sep}site` },
{ ids: ['site'], path: `apps${sep}site${sep}components` },
{ ids: ['site2'], path: `apps${sep}site2` },
{ ids: ['site2'], path: `apps${sep}site2${sep}inner` },
{ ids: ['other', 'duplicate'], path: `apps${sep}other` },
{ ids: ['other', 'duplicate'], path: `apps${sep}other${sep}lib` },
{ ids: ['nested'], path: `apps${sep}other${sep}nested` },
{ ids: ['nested'], path: `apps${sep}other${sep}nested${sep}foo` },
])('should find Project "$id" for path "$path"', ({ path, ids }) => {
const actual = findProjectsFromPath(projects, path);
expect(actual.map(a => a.id)).toEqual(ids);
});

it('should return `undefined` when there are no matching Projects', () => {
const actual = findProjectFromPath([projects[1]], '.');
expect(actual).toBeUndefined();
it('should return empty array when there are no matching Projects', () => {
const actual = findProjectsFromPath([projects[1]], '.');
expect(actual).toHaveLength(0);
});
});
44 changes: 22 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c75c83

Please sign in to comment.