Skip to content

Commit

Permalink
fix: handle yarn wokspaces.packages directive
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 24, 2023
1 parent 2e97387 commit 979cc99
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type IPackageDeps = Record<string, string>

export interface IPackageJson {
name: string
workspaces?: string[]
workspaces?: string[] | { packages?: string[] }
bolt?: {
workspaces?: string[]
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/ts/topo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const topo = async (
pkgFilter,
workspacesExtra,
workspaces: [
...(workspaces || (await getWorkspaces(root))),
...(workspaces || (await extractWorkspaces(root))),
...workspacesExtra
]
}
Expand All @@ -128,8 +128,10 @@ export const topo = async (
}
}

export const getWorkspaces = async (root: IPackageEntry) =>
root.manifest.workspaces ||
export const extractWorkspaces = async (root: IPackageEntry) =>
(Array.isArray(root.manifest.workspaces)
? root.manifest.workspaces
: root.manifest.workspaces?.packages) ||
root.manifest.bolt?.workspaces ||
(await (async () => {
try {
Expand Down
8 changes: 8 additions & 0 deletions src/test/fixtures/yarn-monorepo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "root",
"workspaces": {
"packages": [
"packages/*"
]
}
}
4 changes: 4 additions & 0 deletions src/test/fixtures/yarn-monorepo/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "a",
"private": true
}
1 change: 1 addition & 0 deletions src/test/fixtures/yarn-monorepo/packages/b/no-package.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no package.json
6 changes: 6 additions & 0 deletions src/test/fixtures/yarn-monorepo/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "c",
"dependencies": {
"e": "*"
}
}
3 changes: 3 additions & 0 deletions src/test/fixtures/yarn-monorepo/packages/d/d/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "d"
}
3 changes: 3 additions & 0 deletions src/test/fixtures/yarn-monorepo/packages/e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "e"
}
6 changes: 6 additions & 0 deletions src/test/ts/topo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ test('`topo` processes bolt monorepos', async () => {
assert.equal(result.nodes, ['a', 'c', 'e'])
})

test('`topo` processes yarn monorepos with `workspaces.packages` directive', async () => {
const cwd = resolve(fixtures, 'yarn-monorepo')
const result = await topo({ cwd })
assert.equal(result.nodes, ['a', 'c', 'e'])
})

test('`topo` injects packages to workspaces via workspacesExtra', async () => {
const cwd = resolve(fixtures, 'regular-monorepo')
const workspaces = ['packages/*']
Expand Down

0 comments on commit 979cc99

Please sign in to comment.