mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 10:38:13 -05:00
refactor!: stricter Resolution type (#9582)
* refactor!: stricter `Resolution` type * docs(changeset): don't leave it out * fix: test * fix: test * refactor: replace `as` with `!`
This commit is contained in:
6
.changeset/eleven-chefs-change.md
Normal file
6
.changeset/eleven-chefs-change.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/resolver-base": major
|
||||
"@pnpm/pick-fetcher": patch
|
||||
---
|
||||
|
||||
Remove the blanket variant from the `Resolution` type, making it stricter and more useful.
|
||||
@@ -2,7 +2,7 @@ import type { Resolution } from '@pnpm/resolver-base'
|
||||
import type { Fetchers, FetchFunction, DirectoryFetcher, GitFetcher } from '@pnpm/fetcher-base'
|
||||
|
||||
export function pickFetcher (fetcherByHostingType: Partial<Fetchers>, resolution: Resolution): FetchFunction | DirectoryFetcher | GitFetcher {
|
||||
let fetcherType = resolution.type
|
||||
let fetcherType: keyof Fetchers | undefined = resolution.type
|
||||
|
||||
if (resolution.type == null) {
|
||||
if (resolution.tarball.startsWith('file:')) {
|
||||
@@ -14,7 +14,7 @@ export function pickFetcher (fetcherByHostingType: Partial<Fetchers>, resolution
|
||||
}
|
||||
}
|
||||
|
||||
const fetch = fetcherByHostingType[fetcherType! as keyof Fetchers]
|
||||
const fetch = fetcherByHostingType[fetcherType!]
|
||||
|
||||
if (!fetch) {
|
||||
throw new Error(`Fetching for dependency type "${resolution.type ?? 'undefined'}" is not supported`)
|
||||
|
||||
@@ -24,6 +24,6 @@ test.each([
|
||||
|
||||
test('should fail to pick fetcher if the type is not defined', () => {
|
||||
expect(() => {
|
||||
pickFetcher({}, { type: 'directory' })
|
||||
pickFetcher({}, { type: 'directory', directory: expect.anything() })
|
||||
}).toThrow('Fetching for dependency type "directory" is not supported')
|
||||
})
|
||||
|
||||
@@ -33,10 +33,9 @@ export interface GitResolution {
|
||||
}
|
||||
|
||||
export type Resolution =
|
||||
TarballResolution |
|
||||
DirectoryResolution |
|
||||
GitResolution |
|
||||
({ type: string } & object)
|
||||
| TarballResolution
|
||||
| DirectoryResolution
|
||||
| GitResolution
|
||||
|
||||
export interface ResolveResult {
|
||||
id: PkgResolutionId
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type ResolveFunction } from '@pnpm/client'
|
||||
import { type PkgResolutionId } from '@pnpm/resolver-base'
|
||||
import { type PkgResolutionId, type TarballResolution } from '@pnpm/resolver-base'
|
||||
import { getManifest } from '../lib/createManifestGetter'
|
||||
|
||||
test('getManifest()', async () => {
|
||||
@@ -17,9 +17,7 @@ test('getManifest()', async () => {
|
||||
name: 'foo',
|
||||
version: '1.0.0',
|
||||
},
|
||||
resolution: {
|
||||
type: 'tarball',
|
||||
},
|
||||
resolution: {} as TarballResolution,
|
||||
resolvedVia: 'npm-registry',
|
||||
}
|
||||
}
|
||||
@@ -37,9 +35,7 @@ test('getManifest()', async () => {
|
||||
name: 'foo',
|
||||
version: '2.0.0',
|
||||
},
|
||||
resolution: {
|
||||
type: 'tarball',
|
||||
},
|
||||
resolution: {} as TarballResolution,
|
||||
resolvedVia: 'npm-registry',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user