Skip to content

Commit

Permalink
fix(outdated): should work when the tarballs are hosted on a differen…
Browse files Browse the repository at this point in the history
…t domain (#5501)

close #5492
  • Loading branch information
zkochan committed Oct 16, 2022
1 parent 3c11799 commit 6ad990a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-mayflies-rush.md
@@ -0,0 +1,6 @@
---
"@pnpm/outdated": patch
"pnpm": patch
---

`pnpm outdated` should work when the package tarballs are hosted on a domain that differs from the registry's domain [#5492](https://github.com/pnpm/pnpm/issues/5492).
5 changes: 5 additions & 0 deletions .changeset/shiny-icons-hunt.md
@@ -0,0 +1,5 @@
---
"@pnpm/outdated": major
---

`registries` is a required option for the outdated function.
1 change: 1 addition & 0 deletions packages/outdated/package.json
Expand Up @@ -44,6 +44,7 @@
"@pnpm/manifest-utils": "workspace:*",
"@pnpm/matcher": "workspace:*",
"@pnpm/modules-yaml": "workspace:*",
"@pnpm/npm-resolver": "workspace:*",
"@pnpm/pick-registry-for-package": "workspace:*",
"@pnpm/types": "workspace:*",
"dependency-path": "workspace:*",
Expand Down
16 changes: 12 additions & 4 deletions packages/outdated/src/outdated.ts
Expand Up @@ -6,12 +6,15 @@ import {
} from '@pnpm/lockfile-file'
import { nameVerFromPkgSnapshot } from '@pnpm/lockfile-utils'
import { getAllDependenciesFromManifest } from '@pnpm/manifest-utils'
import { parsePref } from '@pnpm/npm-resolver'
import { pickRegistryForPackage } from '@pnpm/pick-registry-for-package'
import {
DependenciesField,
DEPENDENCIES_FIELDS,
IncludedDependencies,
PackageManifest,
ProjectManifest,
Registries,
} from '@pnpm/types'
import * as dp from 'dependency-path'
import semver from 'semver'
Expand Down Expand Up @@ -40,6 +43,7 @@ export async function outdated (
manifest: ProjectManifest
match?: (dependencyName: string) => boolean
prefix: string
registries: Registries
wantedLockfile: Lockfile | null
}
): Promise<OutdatedPackage[]> {
Expand Down Expand Up @@ -68,6 +72,7 @@ export async function outdated (

await Promise.all(
pkgs.map(async (alias) => {
if (!allDeps[alias]) return
const ref = opts.wantedLockfile!.importers[importerId][depType]![alias]

if (
Expand All @@ -93,10 +98,14 @@ export async function outdated (
const current = (currentRelative && dp.parse(currentRelative).version) ?? currentRef
const wanted = dp.parse(relativeDepPath).version ?? ref
const { name: packageName } = nameVerFromPkgSnapshot(relativeDepPath, pkgSnapshot)
const name = dp.parse(relativeDepPath).name ?? packageName

// It might be not the best solution to check for pkgSnapshot.name
// TODO: add some other field to distinct packages not from the registry
if (pkgSnapshot.resolution && (pkgSnapshot.resolution['type'] || pkgSnapshot.name)) {
// If the npm resolve parser cannot parse the spec of the dependency,
// it means that the package is not from a npm-compatible registry.
// In that case, we can't check whether the package is up-to-date
if (
parsePref(allDeps[alias], alias, 'latest', pickRegistryForPackage(opts.registries, name)) == null
) {
if (current !== wanted) {
outdated.push({
alias,
Expand All @@ -110,7 +119,6 @@ export async function outdated (
return
}

const name = dp.parse(relativeDepPath).name ?? packageName
const latestManifest = await opts.getLatestManifest(
name,
opts.compatible ? (allDeps[name] ?? 'latest') : 'latest'
Expand Down
1 change: 1 addition & 0 deletions packages/outdated/src/outdatedDepsOfProjects.ts
Expand Up @@ -51,6 +51,7 @@ export async function outdatedDepsOfProjects (
manifest,
match,
prefix: dir,
registries: opts.registries,
wantedLockfile,
})
}))
Expand Down
26 changes: 25 additions & 1 deletion packages/outdated/test/outdated.spec.ts
Expand Up @@ -39,6 +39,7 @@ test('outdated()', async () => {
'linked-2': 'file:../linked-2',
},
specifiers: {
'from-github': 'github:blabla/from-github#d5f8d5500f7faf593d32e134c1b0043ff69151b4',
'is-negative': '^2.1.0',
'is-positive': '^1.0.0',
},
Expand Down Expand Up @@ -74,7 +75,10 @@ test('outdated()', async () => {
manifest: {
name: 'wanted-shrinkwrap',
version: '1.0.0',

dependencies: {
'from-github': 'github:blabla/from-github#d5f8d5500f7faf593d32e134c1b0043ff69151b4',
'from-github-2': 'github:blabla/from-github-2#d5f8d5500f7faf593d32e134c1b0043ff69151b4',
},
devDependencies: {
'is-negative': '^2.1.0',
'is-positive': '^3.1.0',
Expand All @@ -97,6 +101,8 @@ test('outdated()', async () => {
'linked-2': 'file:../linked-2',
},
specifiers: {
'from-github': 'github:blabla/from-github#d5f8d5500f7faf593d32e134c1b0043ff69151b4',
'from-github-2': 'github:blabla/from-github-2#d5f8d5500f7faf593d32e134c1b0043ff69151b4',
'is-negative': '^2.1.0',
'is-positive': '^3.1.0',
},
Expand Down Expand Up @@ -132,6 +138,9 @@ test('outdated()', async () => {
},
},
},
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([
{
Expand Down Expand Up @@ -211,6 +220,9 @@ test('outdated() should return deprecated package even if its current version is
},
prefix: 'project',
wantedLockfile: lockfile,
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([
{
Expand Down Expand Up @@ -328,6 +340,9 @@ test('using a matcher', async () => {
},
},
},
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([
{
Expand Down Expand Up @@ -397,6 +412,9 @@ test('outdated() aliased dependency', async () => {
},
},
},
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([
{
Expand Down Expand Up @@ -486,6 +504,9 @@ test('a dependency is not outdated if it is newer than the latest version', asyn
},
prefix: 'project',
wantedLockfile: lockfile,
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([])
})
Expand All @@ -503,6 +524,9 @@ test('outdated() should [] when there is no dependency', async () => {
},
prefix: 'project',
wantedLockfile: null,
registries: {
default: 'https://registry.npmjs.org/',
},
})
expect(outdatedPkgs).toStrictEqual([])
})
3 changes: 3 additions & 0 deletions packages/outdated/tsconfig.json
Expand Up @@ -36,6 +36,9 @@
{
"path": "../modules-yaml"
},
{
"path": "../npm-resolver"
},
{
"path": "../pick-registry-for-package"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ad990a

Please sign in to comment.