Skip to content

Commit 668c318

Browse files
committed
Better handling of deleted packages
Fixes #88
1 parent a2ed1b5 commit 668c318

File tree

7 files changed

+49
-43
lines changed

7 files changed

+49
-43
lines changed

bundles/@yarnpkg/plugin-outdated.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"glob-promise": "^4.2.2",
5050
"prettier": "^2.5.1",
5151
"tar-fs": "^2.1.1",
52-
"typescript": "^4.6.4",
52+
"typescript": "^5.7.2",
5353
"zlib": "^1.0.5"
5454
}
5555
}

src/DependencyFetcher.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Manifest,
66
Package,
77
Project,
8-
structUtils,
98
ThrowReport,
109
Workspace,
1110
} from "@yarnpkg/core"
@@ -28,21 +27,20 @@ export class DependencyFetcher {
2827
) {}
2928

3029
async fetch({ descriptor, includeRange, includeURL, pkg }: FetchOptions) {
31-
const [latest, range, homepageURL] = await Promise.all([
32-
this.suggest(pkg, "latest"),
33-
includeRange ? this.suggest(pkg, descriptor.range) : Promise.resolve(),
34-
includeURL ? this.fetchURL(pkg) : Promise.resolve(),
35-
])
36-
37-
if (!latest) {
38-
const name = structUtils.prettyIdent(this.configuration, pkg)
39-
throw new Error(`Could not fetch candidate for ${name}.`)
40-
}
30+
try {
31+
const [latest, range, homepageURL] = await Promise.all([
32+
this.suggest(pkg, "latest"),
33+
includeRange ? this.suggest(pkg, descriptor.range) : Promise.resolve(),
34+
includeURL ? this.fetchURL(pkg) : Promise.resolve(),
35+
])
4136

42-
return {
43-
latest: latest.range,
44-
range: range?.range,
45-
url: homepageURL ?? undefined,
37+
return {
38+
latest: latest?.range,
39+
range: range?.range,
40+
url: homepageURL ?? undefined,
41+
}
42+
} catch (error) {
43+
return { error }
4644
}
4745
}
4846

src/OutdatedCommand.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export class OutdatedCommand extends BaseCommand {
200200
project,
201201
fetcher,
202202
dependencies,
203-
progress
203+
progress,
204+
report
204205
)
205206
}
206207
)
@@ -422,11 +423,12 @@ export class OutdatedCommand extends BaseCommand {
422423
project: Project,
423424
fetcher: DependencyFetcher,
424425
dependencies: DependencyInfo[],
425-
progress?: ReturnType<typeof Report["progressViaCounter"]>
426+
progress?: ReturnType<typeof Report["progressViaCounter"]>,
427+
report?: StreamReport
426428
): Promise<OutdatedDependency[]> {
427429
const outdated = dependencies.map(
428430
async ({ dependencyType, descriptor, name, pkg, workspace }) => {
429-
const { latest, range, url } = await fetcher.fetch({
431+
const { error, latest, range, url } = await fetcher.fetch({
430432
descriptor,
431433
includeRange: this.includeRange,
432434
includeURL: this.includeURL(configuration),
@@ -436,7 +438,16 @@ export class OutdatedCommand extends BaseCommand {
436438
// JSON reports don't use progress, so this only applies for non-JSON cases.
437439
progress?.tick()
438440

439-
if (isVersionOutdated(pkg.version!, latest)) {
441+
if (error instanceof Error) {
442+
report?.reportError(
443+
MessageName.UNNAMED,
444+
`Failed to fetch ${name}: ${error.message}`
445+
)
446+
447+
return
448+
}
449+
450+
if (latest && isVersionOutdated(pkg.version!, latest)) {
440451
return {
441452
current: pkg.version!,
442453
latest,

test/specs/outdated.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ test.describe("yarn outdated", () => {
3939
expect(stderr).toBe("")
4040
})
4141

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

6059
const { code, stderr, stdout } = await run("outdated")
61-
const output = stdout.replace(registry.port.toString(), "<registry port>")
62-
expect(output).toMatchSnapshot("not-found.txt")
60+
expect(stdout).toMatchSnapshot("not-found.txt")
6361
expect(stderr).toBe("")
6462
expect(code).toBe(1)
6563
})
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
➤ YN0000: ┌ Checking for outdated dependencies
2-
➤ YN0035: │ Package not found
3-
➤ YN0035: │ Response Code: 404 (Not Found)
4-
➤ YN0035: │ Request Method: GET
5-
➤ YN0035: │ Request URL: http://localhost:<registry port>/not-found
2+
➤ YN0000: │ Failed to fetch not-found: Package not found
63
➤ YN0000: └ Completed
4+
5+
➤ YN0000: ✨ All your dependencies are up to date!
76
➤ YN0000: Failed with errors

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,23 +3667,23 @@ __metadata:
36673667
languageName: node
36683668
linkType: hard
36693669

3670-
"typescript@npm:^4.6.4":
3671-
version: 4.6.4
3672-
resolution: "typescript@npm:4.6.4"
3670+
"typescript@npm:^5.7.2":
3671+
version: 5.7.2
3672+
resolution: "typescript@npm:5.7.2"
36733673
bin:
36743674
tsc: bin/tsc
36753675
tsserver: bin/tsserver
3676-
checksum: 92e2c0328485a4f7bd7435f5b105f03addff32f867e241dc3be8c372ed801a138c732d9a55697696d2f82a80dd6ad4bddff1ad6b0d1884bf4a24b92e71094c44
3676+
checksum: a873118b5201b2ef332127ef5c63fb9d9c155e6fdbe211cbd9d8e65877283797cca76546bad742eea36ed7efbe3424a30376818f79c7318512064e8625d61622
36773677
languageName: node
36783678
linkType: hard
36793679

3680-
"typescript@patch:typescript@npm%3A^4.6.4#optional!builtin<compat/typescript>":
3681-
version: 4.6.4
3682-
resolution: "typescript@patch:typescript@npm%3A4.6.4#optional!builtin<compat/typescript>::version=4.6.4&hash=5d3a66"
3680+
"typescript@patch:typescript@npm%3A^5.7.2#optional!builtin<compat/typescript>":
3681+
version: 5.7.2
3682+
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=e012d7"
36833683
bin:
36843684
tsc: bin/tsc
36853685
tsserver: bin/tsserver
3686-
checksum: 0e3fa814d454942a689daf4c00f82328d323e7ecd4077e3265d45375e64642611631f4c882a71be87774468ba03793e9b8ff4bccfac3018194a9e36d8f72c251
3686+
checksum: c891ccf04008bc1305ba34053db951f8a4584b4a1bf2f68fd972c4a354df3dc5e62c8bfed4f6ac2d12e5b3b1c49af312c83a651048f818cd5b4949d17baacd79
36873687
languageName: node
36883688
linkType: hard
36893689

@@ -3817,7 +3817,7 @@ __metadata:
38173817
semver: "npm:^7.5.4"
38183818
tar-fs: "npm:^2.1.1"
38193819
typanion: "npm:^3.14.0"
3820-
typescript: "npm:^4.6.4"
3820+
typescript: "npm:^5.7.2"
38213821
zlib: "npm:^1.0.5"
38223822
languageName: unknown
38233823
linkType: soft

0 commit comments

Comments
 (0)