Skip to content

Commit

Permalink
Better handling of deleted packages
Browse files Browse the repository at this point in the history
Fixes #88
  • Loading branch information
mskelton committed Dec 26, 2024
1 parent a2ed1b5 commit 668c318
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
12 changes: 6 additions & 6 deletions bundles/@yarnpkg/plugin-outdated.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"glob-promise": "^4.2.2",
"prettier": "^2.5.1",
"tar-fs": "^2.1.1",
"typescript": "^4.6.4",
"typescript": "^5.7.2",
"zlib": "^1.0.5"
}
}
28 changes: 13 additions & 15 deletions src/DependencyFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Manifest,
Package,
Project,
structUtils,
ThrowReport,
Workspace,
} from "@yarnpkg/core"
Expand All @@ -28,21 +27,20 @@ export class DependencyFetcher {
) {}

async fetch({ descriptor, includeRange, includeURL, pkg }: FetchOptions) {
const [latest, range, homepageURL] = await Promise.all([
this.suggest(pkg, "latest"),
includeRange ? this.suggest(pkg, descriptor.range) : Promise.resolve(),
includeURL ? this.fetchURL(pkg) : Promise.resolve(),
])

if (!latest) {
const name = structUtils.prettyIdent(this.configuration, pkg)
throw new Error(`Could not fetch candidate for ${name}.`)
}
try {
const [latest, range, homepageURL] = await Promise.all([
this.suggest(pkg, "latest"),
includeRange ? this.suggest(pkg, descriptor.range) : Promise.resolve(),
includeURL ? this.fetchURL(pkg) : Promise.resolve(),
])

return {
latest: latest.range,
range: range?.range,
url: homepageURL ?? undefined,
return {
latest: latest?.range,
range: range?.range,
url: homepageURL ?? undefined,
}
} catch (error) {
return { error }
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/OutdatedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ export class OutdatedCommand extends BaseCommand {
project,
fetcher,
dependencies,
progress
progress,
report
)
}
)
Expand Down Expand Up @@ -422,11 +423,12 @@ export class OutdatedCommand extends BaseCommand {
project: Project,
fetcher: DependencyFetcher,
dependencies: DependencyInfo[],
progress?: ReturnType<typeof Report["progressViaCounter"]>
progress?: ReturnType<typeof Report["progressViaCounter"]>,
report?: StreamReport
): Promise<OutdatedDependency[]> {
const outdated = dependencies.map(
async ({ dependencyType, descriptor, name, pkg, workspace }) => {
const { latest, range, url } = await fetcher.fetch({
const { error, latest, range, url } = await fetcher.fetch({
descriptor,
includeRange: this.includeRange,
includeURL: this.includeURL(configuration),
Expand All @@ -436,7 +438,16 @@ export class OutdatedCommand extends BaseCommand {
// JSON reports don't use progress, so this only applies for non-JSON cases.
progress?.tick()

if (isVersionOutdated(pkg.version!, latest)) {
if (error instanceof Error) {
report?.reportError(
MessageName.UNNAMED,
`Failed to fetch ${name}: ${error.message}`
)

return
}

if (latest && isVersionOutdated(pkg.version!, latest)) {
return {
current: pkg.version!,
latest,
Expand Down
6 changes: 2 additions & 4 deletions test/specs/outdated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ test.describe("yarn outdated", () => {
expect(stderr).toBe("")
})

test("throws an error when a package is not found", async ({
test("displays a report error when a package is not found", async ({
readFile,
registry,
run,
writeFile,
writeJSON,
Expand All @@ -58,8 +57,7 @@ test.describe("yarn outdated", () => {
await writeFile("yarn.lock", lockfile.replace(/patch/g, "not-found"))

const { code, stderr, stdout } = await run("outdated")
const output = stdout.replace(registry.port.toString(), "<registry port>")
expect(output).toMatchSnapshot("not-found.txt")
expect(stdout).toMatchSnapshot("not-found.txt")
expect(stderr).toBe("")
expect(code).toBe(1)
})
Expand Down
7 changes: 3 additions & 4 deletions test/specs/outdated.test.ts-snapshots/not-found.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
➤ YN0000: ┌ Checking for outdated dependencies
➤ YN0035: │ Package not found
➤ YN0035: │ Response Code: 404 (Not Found)
➤ YN0035: │ Request Method: GET
➤ YN0035: │ Request URL: http://localhost:<registry port>/not-found
➤ YN0000: │ Failed to fetch not-found: Package not found
➤ YN0000: └ Completed

➤ YN0000: ✨ All your dependencies are up to date!
➤ YN0000: Failed with errors
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3667,23 +3667,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^4.6.4":
version: 4.6.4
resolution: "typescript@npm:4.6.4"
"typescript@npm:^5.7.2":
version: 5.7.2
resolution: "typescript@npm:5.7.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 92e2c0328485a4f7bd7435f5b105f03addff32f867e241dc3be8c372ed801a138c732d9a55697696d2f82a80dd6ad4bddff1ad6b0d1884bf4a24b92e71094c44
checksum: a873118b5201b2ef332127ef5c63fb9d9c155e6fdbe211cbd9d8e65877283797cca76546bad742eea36ed7efbe3424a30376818f79c7318512064e8625d61622
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^4.6.4#optional!builtin<compat/typescript>":
version: 4.6.4
resolution: "typescript@patch:typescript@npm%3A4.6.4#optional!builtin<compat/typescript>::version=4.6.4&hash=5d3a66"
"typescript@patch:typescript@npm%3A^5.7.2#optional!builtin<compat/typescript>":
version: 5.7.2
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=e012d7"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 0e3fa814d454942a689daf4c00f82328d323e7ecd4077e3265d45375e64642611631f4c882a71be87774468ba03793e9b8ff4bccfac3018194a9e36d8f72c251
checksum: c891ccf04008bc1305ba34053db951f8a4584b4a1bf2f68fd972c4a354df3dc5e62c8bfed4f6ac2d12e5b3b1c49af312c83a651048f818cd5b4949d17baacd79
languageName: node
linkType: hard

Expand Down Expand Up @@ -3817,7 +3817,7 @@ __metadata:
semver: "npm:^7.5.4"
tar-fs: "npm:^2.1.1"
typanion: "npm:^3.14.0"
typescript: "npm:^4.6.4"
typescript: "npm:^5.7.2"
zlib: "npm:^1.0.5"
languageName: unknown
linkType: soft
Expand Down

0 comments on commit 668c318

Please sign in to comment.