Skip to content

Commit

Permalink
Patch protocol (#43)
Browse files Browse the repository at this point in the history
* Add patch protocol test

* Support patch protocol
  • Loading branch information
mskelton authored Dec 1, 2021
1 parent ec4062f commit ceb81bb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bundles/@yarnpkg/plugin-outdated.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/OutdatedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ export class OutdatedCommand extends BaseCommand {
for (const descriptor of workspace.manifest[dependencyType].values()) {
const { range } = descriptor

// Only include dependencies that are semver-compatible or are
// package aliases (npm protocol).
if (range.includes(":") && !range.startsWith("npm:")) {
// Only include dependencies that are semver-compatible, package
// aliases (npm protocol), or patches.
if (range.includes(":") && !/(npm|patch):/.test(range)) {
continue
}

Expand Down
11 changes: 11 additions & 0 deletions test/files/alias.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/package.json b/package.json
index ce0f2d99044712d15a94d48287077f5486e63281..d517dd0f3e183d0aea82112ebca97ea468196ebb 100644
--- a/package.json
+++ b/package.json
@@ -1,4 +1,5 @@
{
"name": "@scoped/patch",
- "version": "1.0.0"
+ "version": "1.0.0",
+ "author": "Me"
}
15 changes: 15 additions & 0 deletions test/lockfiles/non-semver.lock → test/files/non-semver.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ __metadata:
version: 4
cacheKey: 0

"@scoped/patch@1.0.0":
version: 1.0.0
resolution: "@scoped/patch@npm:1.0.0"
checksum: a66cf4ff65e1170614fddfcab8fed08b15d7fedb785a94e4e1845076841bd18a80e0b2bd1461e3a184e44a329b4513fc12f7bbd69114943370aa6edd9ae59524
languageName: node
linkType: hard

"@scoped/patch@patch:@scoped/patch@1.0.0#./alias.patch::locator=foo%40workspace%3A.":
version: 1.0.0
resolution: "@scoped/patch@patch:@scoped/patch@npm%3A1.0.0#./alias.patch::version=1.0.0&hash=958e67&locator=foo%40workspace%3A."
checksum: cd04881d496e3e1583ee6ae50994b2535d287acfb3267a287b07fa5564d9da2f70cb57030920a631a2f302eddf31db390c37618982e00e6d0ba7a2112759a5eb
languageName: node
linkType: hard

"alias@npm:patch@1.0.0, patch@npm:latest":
version: 1.0.0
resolution: "patch@npm:1.0.0"
Expand Down Expand Up @@ -37,6 +51,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "foo@workspace:."
dependencies:
"@scoped/patch": "patch:@scoped/patch@1.0.0#./alias.patch"
alias: "npm:patch@1.0.0"
major: "*"
minor: ">1.0.0 <2.0.0"
Expand Down
6 changes: 4 additions & 2 deletions test/specs/outdated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "../fixtures/env"
import { readLockfile } from "../utils/lockfile"
import { readSupplementalFile } from "../utils/files"

test.describe("yarn outdated", () => {
test("shows outdated dependencies", async ({ env }) => {
Expand Down Expand Up @@ -97,6 +97,7 @@ test.describe("yarn outdated", () => {

await writeJSON("package.json", {
dependencies: {
"@scoped/patch": "patch:@scoped/patch@1.0.0#./alias.patch",
alias: "npm:patch@1.0.0",
file: "file:./file-dep",
major: "*",
Expand All @@ -106,7 +107,8 @@ test.describe("yarn outdated", () => {
name: "foo",
})
await writeJSON("file-dep/package.json", { version: "1.1.0" })
await writeFile("yarn.lock", readLockfile("non-semver.lock"))
await writeFile("alias.patch", readSupplementalFile("alias.patch"))
await writeFile("yarn.lock", readSupplementalFile("non-semver.lock"))
await run("install --immutable")

const { stderr, stdout } = await run("outdated")
Expand Down
13 changes: 7 additions & 6 deletions test/specs/outdated.spec.ts-snapshots/non-semver.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
➤ YN0000: ┌ Checking for outdated dependencies
➤ YN0000: └ Completed

➤ YN0000: Package Current Latest Package Type
➤ YN0000: alias 1.0.0 1.0.1 dependencies
➤ YN0000: major 1.0.0 2.0.0 dependencies
➤ YN0000: minor 1.0.0 1.1.0 dependencies
➤ YN0000: patch 1.0.0 1.0.1 dependencies
➤ YN0000: Package Current Latest Package Type
➤ YN0000: @scoped/patch 1.0.0 1.0.1 dependencies
➤ YN0000: alias 1.0.0 1.0.1 dependencies
➤ YN0000: major 1.0.0 2.0.0 dependencies
➤ YN0000: minor 1.0.0 1.1.0 dependencies
➤ YN0000: patch 1.0.0 1.0.1 dependencies

➤ YN0000: 4 dependencies are out of date
➤ YN0000: 5 dependencies are out of date
➤ YN0000: Done with warnings
6 changes: 6 additions & 0 deletions test/utils/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fs from "fs"
import path from "path"

export function readSupplementalFile(filename: string) {
return fs.readFileSync(path.join(__dirname, "..", "files", filename), "utf8")
}
9 changes: 0 additions & 9 deletions test/utils/lockfile.ts

This file was deleted.

0 comments on commit ceb81bb

Please sign in to comment.