Skip to content

Commit

Permalink
All workspace default (#49)
Browse files Browse the repository at this point in the history
* Remove `--all` flag in favor of `--workspace` flag

* Update docs

* Update tests

* Rename test

* Fix current workspace test

* Fix snapshot

* Make each part of th environment a fixture
  • Loading branch information
mskelton authored Feb 26, 2022
1 parent 3830855 commit e06fa60
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 127 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ yarn outdated '@babel/*'

### Options

| Definition | Description |
| ------------------ | -------------------------------------------------------- |
| `-a`, `--all` | Include outdated dependencies from all workspaces. |
| `-c`, `--check` | Return exit code 1 if outdated dependencies are found. |
| `-s`, `--severity` | Filter results based on the severity of the update. |
| `-t`, `--type` | Filter results based on the dependency type. |
| `--url` | Include the homepage URL of each package in the output. |
| `--json` | Output in JSON format instead of in the formatted table. |
| Definition | Description |
| ------------------- | ------------------------------------------------------------ |
| `-w`, `--workspace` | Only include outdated dependencies in the current workspace. |
| `-c`, `--check` | Return exit code 1 if outdated dependencies are found. |
| `-s`, `--severity` | Filter results based on the severity of the update. |
| `-t`, `--type` | Filter results based on the dependency type. |
| `--url` | Include the homepage URL of each package in the output. |
| `--json` | Output in JSON format instead of in the formatted table. |
6 changes: 3 additions & 3 deletions bundles/@yarnpkg/plugin-outdated.js

Large diffs are not rendered by default.

37 changes: 29 additions & 8 deletions src/OutdatedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class OutdatedCommand extends BaseCommand {

patterns = Option.Rest()

all = Option.Boolean("-a,--all", false, {
description: "Include outdated dependencies from all workspaces",
workspace = Option.Boolean("-w,--workspace", false, {
description: "Only include outdated dependencies in the current workspace",
})

check = Option.Boolean("-c,--check", false, {
Expand Down Expand Up @@ -97,7 +97,12 @@ export class OutdatedCommand extends BaseCommand {
const dependencies = this.getDependencies(configuration, workspaces)

if (this.json) {
const outdated = await this.getOutdatedDependencies(fetcher, dependencies)
const outdated = await this.getOutdatedDependencies(
project,
fetcher,
dependencies
)

this.context.stdout.write(JSON.stringify(outdated) + "\n")
return
}
Expand All @@ -107,6 +112,7 @@ export class OutdatedCommand extends BaseCommand {
async (report) => {
await this.checkOutdatedDependencies(
configuration,
project,
dependencies,
fetcher,
report
Expand All @@ -119,6 +125,7 @@ export class OutdatedCommand extends BaseCommand {

async checkOutdatedDependencies(
configuration: Configuration,
project: Project,
dependencies: DependencyInfo[],
fetcher: DependencyFetcher,
report: StreamReport
Expand All @@ -133,6 +140,7 @@ export class OutdatedCommand extends BaseCommand {
report.reportProgress(progress)

outdated = await this.getOutdatedDependencies(
project,
fetcher,
dependencies,
progress
Expand All @@ -145,7 +153,7 @@ export class OutdatedCommand extends BaseCommand {
if (outdated.length) {
const table = new DependencyTable(report, configuration, outdated, {
url: this.url,
workspace: this.all,
workspace: this.includeWorkspace(project),
})

table.print()
Expand Down Expand Up @@ -187,13 +195,23 @@ export class OutdatedCommand extends BaseCommand {
}

/**
* If the user passed the `--all` CLI flag, then we will load dependencies
* from all workspaces instead of just the current workspace.
* If the user passed the `--workspace` CLI flag, then we only include
* outdated dependencies in the current workspace.
*/
getWorkspaces(project: Project, workspace: Workspace) {
return this.all ? project.workspaces : [workspace]
return this.workspace ? [workspace] : project.workspaces
}

/**
* Whether to include the workspace column in the output.
*/
includeWorkspace(project: Project) {
return !this.workspace && project.workspaces.length > 1
}

/**
* Get the dependency types that should be included in the output.
*/
get dependencyTypes() {
return this.type ? [this.type] : dependencyTypes
}
Expand Down Expand Up @@ -298,6 +316,7 @@ export class OutdatedCommand extends BaseCommand {
* sort them in ascending order.
*/
async getOutdatedDependencies(
project: Project,
fetcher: DependencyFetcher,
dependencies: DependencyInfo[],
progress?: ReturnType<typeof Report["progressViaCounter"]>
Expand Down Expand Up @@ -328,7 +347,9 @@ export class OutdatedCommand extends BaseCommand {
severity: this.getSeverity(pkg.version!, latest),
type: dependencyType,
url,
workspace: this.all ? this.getWorkspaceName(workspace) : undefined,
workspace: this.includeWorkspace(project)
? this.getWorkspaceName(workspace)
: undefined,
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions test/fixtures/env.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { test as base } from "@playwright/test"
import { makeTemporaryEnv } from "../utils/env"

type ThenArg<T> = T extends PromiseLike<infer U> ? U : T
type Environment = Omit<ThenArg<ReturnType<typeof makeTemporaryEnv>>, "destroy">
type Environment = Awaited<ReturnType<typeof makeTemporaryEnv>>

interface EnvironmentFixtures {
env: Environment
interface EnvironmentFixtures extends Omit<Environment, "destroy"> {
env: Omit<Environment, "destroy">
}

export const test = base.extend<EnvironmentFixtures>({
Expand All @@ -18,6 +17,11 @@ export const test = base.extend<EnvironmentFixtures>({
await use(env)
await destroy()
},
readFile: ({ env }, use) => use(env.readFile),
registry: ({ env }, use) => use(env.registry),
run: ({ env }, use) => use(env.run),
writeFile: ({ env }, use) => use(env.writeFile),
writeJSON: ({ env }, use) => use(env.writeJSON),
})

export const expect = test.expect
47 changes: 0 additions & 47 deletions test/specs/all.spec.ts

This file was deleted.

10 changes: 4 additions & 6 deletions test/specs/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { expect, test } from "../fixtures/env"

test.describe.parallel("yarn outdated --check", () => {
test("returns exit code 0 when dependencies are up to date", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", { dependencies: { patch: "1.0.1" } })
await run("install")

Expand All @@ -16,10 +15,9 @@ test.describe.parallel("yarn outdated --check", () => {
})

test("returns exit code 1 when outdated dependencies are found", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", { dependencies: { patch: "1.0.0" } })
await run("install")

Expand Down
8 changes: 2 additions & 6 deletions test/specs/filter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { expect, test } from "../fixtures/env"

test.describe.parallel("yarn outdated", () => {
test("filters based on dependency type", async ({ env }) => {
const { run, writeJSON } = env

test("filters based on dependency type", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { patch: "1.0.0" },
devDependencies: { minor: "1.0.0" },
Expand All @@ -15,9 +13,7 @@ test.describe.parallel("yarn outdated", () => {
expect(stderr).toBe("")
})

test("filters based on outdated severity", async ({ env }) => {
const { run, writeJSON } = env

test("filters based on outdated severity", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { major: "1.0.0", minor: "1.0.0" },
})
Expand Down
9 changes: 3 additions & 6 deletions test/specs/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { expect, test } from "../fixtures/env"
import { prettyJSON } from "../utils/format"

test.describe.parallel("yarn outdated --json", () => {
test("shows outdated dependencies", async ({ env }) => {
const { run, writeJSON } = env

test("shows outdated dependencies", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { patch: "1.0.0" },
devDependencies: { minor: "1.0.0" },
Expand All @@ -17,10 +15,9 @@ test.describe.parallel("yarn outdated --json", () => {
})

test("displays an empty state if no dependencies are outdated", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", { dependencies: { patch: "1.0.1" } })
await run("install")

Expand Down
40 changes: 17 additions & 23 deletions test/specs/outdated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { expect, test } from "../fixtures/env"
import { readSupplementalFile } from "../utils/files"

test.describe.parallel("yarn outdated", () => {
test("shows outdated dependencies", async ({ env }) => {
const { run, writeJSON } = env

test("shows outdated dependencies", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { patch: "1.0.0" },
devDependencies: { minor: "1.0.0" },
Expand All @@ -18,10 +16,9 @@ test.describe.parallel("yarn outdated", () => {
})

test("displays an empty state if no dependencies are outdated", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", { dependencies: { patch: "1.0.1" } })
await run("install")

Expand All @@ -30,9 +27,7 @@ test.describe.parallel("yarn outdated", () => {
expect(stderr).toBe("")
})

test("formats scoped dependencies", async ({ env }) => {
const { run, writeJSON } = env

test("formats scoped dependencies", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { "@scoped/patch": "1.0.0" },
})
Expand All @@ -43,8 +38,13 @@ test.describe.parallel("yarn outdated", () => {
expect(stderr).toBe("")
})

test("throws an error when a package is not found", async ({ env }) => {
const { readFile, registry, run, writeFile, writeJSON } = env
test("throws an error when a package is not found", async ({
readFile,
registry,
run,
writeFile,
writeJSON,
}) => {
await writeJSON("package.json", { dependencies: { patch: "1.0.0" } })
await run("install")

Expand All @@ -64,10 +64,9 @@ test.describe.parallel("yarn outdated", () => {
})

test("defers to lockfile over manifest to check if a package is outdated", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", { dependencies: { patch: "^1.0.0" } })
await run("install")

Expand All @@ -77,10 +76,9 @@ test.describe.parallel("yarn outdated", () => {
})

test("respects resolutions to determine if a package is outdated", async ({
env,
run,
writeJSON,
}) => {
const { run, writeJSON } = env

await writeJSON("package.json", {
dependencies: { minor: "1.0.0" },
resolutions: { minor: "1.0.1" },
Expand All @@ -92,9 +90,7 @@ test.describe.parallel("yarn outdated", () => {
expect(stderr).toBe("")
})

test("handles non-semver ranges", async ({ env }) => {
const { run, writeFile, writeJSON } = env

test("handles non-semver ranges", async ({ run, writeFile, writeJSON }) => {
await writeJSON("package.json", {
dependencies: {
"@scoped/patch": "patch:@scoped/patch@1.0.0#./alias.patch",
Expand All @@ -116,9 +112,7 @@ test.describe.parallel("yarn outdated", () => {
expect(stderr).toBe("")
})

test("ignores pre-release versions", async ({ env }) => {
const { run, writeJSON } = env

test("ignores pre-release versions", async ({ run, writeJSON }) => {
await writeJSON("package.json", {
dependencies: { patch: "1.0.1-alpha.1" },
})
Expand Down
Loading

0 comments on commit e06fa60

Please sign in to comment.