mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-03 23:11:49 -04:00
refactor: add createResolver() to @pnpm/client
This commit is contained in:
5
.changeset/modern-gifts-draw.md
Normal file
5
.changeset/modern-gifts-draw.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/client": minor
|
||||
---
|
||||
|
||||
A new function created for just creating a resolver: `createResolver(opts: ClientOptions)`.
|
||||
@@ -1,4 +1,7 @@
|
||||
import createResolve, { ResolverFactoryOptions } from '@pnpm/default-resolver'
|
||||
import createResolve, {
|
||||
ResolveFunction,
|
||||
ResolverFactoryOptions,
|
||||
} from '@pnpm/default-resolver'
|
||||
import { AgentOptions, createFetchFromRegistry } from '@pnpm/fetch'
|
||||
import { FetchFromRegistry, GetCredentials, RetryTimeoutOptions } from '@pnpm/fetching-types'
|
||||
import fetchFromGit from '@pnpm/git-fetcher'
|
||||
@@ -6,11 +9,15 @@ import createTarballFetcher from '@pnpm/tarball-fetcher'
|
||||
import getCredentialsByURI = require('credentials-by-uri')
|
||||
import mem = require('mem')
|
||||
|
||||
export default function (opts: {
|
||||
export { ResolveFunction }
|
||||
|
||||
export type ClientOptions = {
|
||||
authConfig: Record<string, string>,
|
||||
retry?: RetryTimeoutOptions,
|
||||
userAgent?: string,
|
||||
} & ResolverFactoryOptions & AgentOptions) {
|
||||
} & ResolverFactoryOptions & AgentOptions
|
||||
|
||||
export default function (opts: ClientOptions) {
|
||||
const fetchFromRegistry = createFetchFromRegistry(opts)
|
||||
const getCredentials = mem((registry: string) => getCredentialsByURI(opts.authConfig, registry))
|
||||
return {
|
||||
@@ -19,6 +26,12 @@ export default function (opts: {
|
||||
}
|
||||
}
|
||||
|
||||
export function createResolver (opts: ClientOptions) {
|
||||
const fetchFromRegistry = createFetchFromRegistry(opts)
|
||||
const getCredentials = mem((registry: string) => getCredentialsByURI(opts.authConfig, registry))
|
||||
return createResolve(fetchFromRegistry, getCredentials, opts)
|
||||
}
|
||||
|
||||
function createFetchers (
|
||||
fetchFromRegistry: FetchFromRegistry,
|
||||
getCredentials: GetCredentials,
|
||||
|
||||
@@ -35,10 +35,9 @@
|
||||
"@pnpm/logger": ">=3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pnpm/client": "workspace:^1.0.7",
|
||||
"@pnpm/constants": "workspace:4.0.0",
|
||||
"@pnpm/default-resolver": "workspace:10.0.7",
|
||||
"@pnpm/error": "workspace:1.3.0",
|
||||
"@pnpm/fetch": "workspace:^2.1.3",
|
||||
"@pnpm/lockfile-file": "workspace:3.0.12",
|
||||
"@pnpm/lockfile-utils": "workspace:2.0.16",
|
||||
"@pnpm/manifest-utils": "workspace:1.0.3",
|
||||
@@ -47,9 +46,7 @@
|
||||
"@pnpm/pick-registry-for-package": "workspace:1.0.3",
|
||||
"@pnpm/store-path": "^4.0.2",
|
||||
"@pnpm/types": "workspace:6.2.0",
|
||||
"credentials-by-uri": "^2.0.0",
|
||||
"dependency-path": "workspace:5.0.3",
|
||||
"mem": "^6.1.0",
|
||||
"ramda": "^0.27.1",
|
||||
"semver": "^7.3.2"
|
||||
},
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import createResolver, { ResolveFunction, ResolverFactoryOptions } from '@pnpm/default-resolver'
|
||||
import { createFetchFromRegistry } from '@pnpm/fetch'
|
||||
import {
|
||||
ClientOptions,
|
||||
createResolver,
|
||||
ResolveFunction,
|
||||
} from '@pnpm/client'
|
||||
import pickRegistryForPackage from '@pnpm/pick-registry-for-package'
|
||||
import { DependencyManifest, Registries } from '@pnpm/types'
|
||||
import getCredentialsByURI = require('credentials-by-uri')
|
||||
import mem = require('mem')
|
||||
|
||||
type GetManifestOpts = {
|
||||
dir: string,
|
||||
@@ -12,14 +13,14 @@ type GetManifestOpts = {
|
||||
registries: Registries,
|
||||
}
|
||||
|
||||
export type ManifestGetterOptions = ResolverFactoryOptions & GetManifestOpts
|
||||
export type ManifestGetterOptions = Omit<ClientOptions, 'authConfig'>
|
||||
& GetManifestOpts
|
||||
& { rawConfig: Record<string, string> }
|
||||
|
||||
export function createManifestGetter (
|
||||
opts: ManifestGetterOptions
|
||||
): (packageName: string, pref: string) => Promise<DependencyManifest | null> {
|
||||
const fetch = createFetchFromRegistry(opts)
|
||||
const getCredentials = mem((registry: string) => getCredentialsByURI(opts.rawConfig, registry))
|
||||
const resolve = createResolver(fetch, getCredentials, opts)
|
||||
const resolve = createResolver({ ...opts, authConfig: opts.rawConfig })
|
||||
return getManifest.bind(null, resolve, opts)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ResolveFunction } from '@pnpm/default-resolver'
|
||||
import { ResolveFunction } from '@pnpm/client'
|
||||
import test = require('tape')
|
||||
import { getManifest } from '../lib/createManifestGetter'
|
||||
|
||||
|
||||
@@ -9,18 +9,15 @@
|
||||
"../../typings/**/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../client"
|
||||
},
|
||||
{
|
||||
"path": "../constants"
|
||||
},
|
||||
{
|
||||
"path": "../default-resolver"
|
||||
},
|
||||
{
|
||||
"path": "../error"
|
||||
},
|
||||
{
|
||||
"path": "../fetch"
|
||||
},
|
||||
{
|
||||
"path": "../lockfile-file"
|
||||
},
|
||||
|
||||
@@ -52,12 +52,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@pnpm/cli-utils": "workspace:0.4.22",
|
||||
"@pnpm/client": "workspace:^1.0.7",
|
||||
"@pnpm/config": "workspace:11.2.4",
|
||||
"@pnpm/error": "workspace:1.3.0",
|
||||
"@pnpm/exportable-manifest": "workspace:^1.0.1",
|
||||
"@pnpm/fetch": "workspace:^2.1.3",
|
||||
"@pnpm/lifecycle": "workspace:9.2.2",
|
||||
"@pnpm/npm-resolver": "workspace:9.1.0",
|
||||
"@pnpm/pick-registry-for-package": "workspace:1.0.3",
|
||||
"@pnpm/resolver-base": "workspace:7.0.3",
|
||||
"@pnpm/run-npm": "workspace:2.0.3",
|
||||
@@ -66,10 +65,8 @@
|
||||
"@pnpm/types": "workspace:6.2.0",
|
||||
"@zkochan/rimraf": "^1.0.0",
|
||||
"cp-file": "^9.0.0",
|
||||
"credentials-by-uri": "^2.0.0",
|
||||
"enquirer": "^2.3.6",
|
||||
"fast-glob": "^3.2.4",
|
||||
"mem": "^6.1.0",
|
||||
"mz": "^2.7.0",
|
||||
"p-filter": "^2.1.0",
|
||||
"ramda": "^0.27.1",
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { createResolver } from '@pnpm/client'
|
||||
import { Config } from '@pnpm/config'
|
||||
import { createFetchFromRegistry } from '@pnpm/fetch'
|
||||
import createResolver from '@pnpm/npm-resolver'
|
||||
import pickRegistryForPackage from '@pnpm/pick-registry-for-package'
|
||||
import { ResolveFunction } from '@pnpm/resolver-base'
|
||||
import runNpm from '@pnpm/run-npm'
|
||||
import sortPackages from '@pnpm/sort-packages'
|
||||
import storePath from '@pnpm/store-path'
|
||||
import { Registries } from '@pnpm/types'
|
||||
import getCredentialsByURI = require('credentials-by-uri')
|
||||
import mem = require('mem')
|
||||
import pFilter = require('p-filter')
|
||||
import { handler as publish } from './publish'
|
||||
|
||||
@@ -54,9 +50,8 @@ export default async function (
|
||||
) {
|
||||
const pkgs = Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package)
|
||||
const storeDir = await storePath(opts.workspaceDir, opts.storeDir)
|
||||
const fetch = createFetchFromRegistry(opts)
|
||||
const getCredentials = mem((registry: string) => getCredentialsByURI(opts.rawConfig, registry))
|
||||
const resolve = createResolver(fetch, getCredentials, Object.assign(opts, {
|
||||
const resolve = createResolver(Object.assign(opts, {
|
||||
authConfig: opts.rawConfig,
|
||||
storeDir,
|
||||
})) as unknown as ResolveFunction
|
||||
const pkgsToPublish = await pFilter(pkgs, async (pkg) => {
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
{
|
||||
"path": "../cli-utils"
|
||||
},
|
||||
{
|
||||
"path": "../client"
|
||||
},
|
||||
{
|
||||
"path": "../config"
|
||||
},
|
||||
@@ -21,15 +24,9 @@
|
||||
{
|
||||
"path": "../exportable-manifest"
|
||||
},
|
||||
{
|
||||
"path": "../fetch"
|
||||
},
|
||||
{
|
||||
"path": "../lifecycle"
|
||||
},
|
||||
{
|
||||
"path": "../npm-resolver"
|
||||
},
|
||||
{
|
||||
"path": "../pick-registry-for-package"
|
||||
},
|
||||
|
||||
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@@ -1223,10 +1223,9 @@ importers:
|
||||
version-selector-type: ^3.0.0
|
||||
packages/outdated:
|
||||
dependencies:
|
||||
'@pnpm/client': 'link:../client'
|
||||
'@pnpm/constants': 'link:../constants'
|
||||
'@pnpm/default-resolver': 'link:../default-resolver'
|
||||
'@pnpm/error': 'link:../error'
|
||||
'@pnpm/fetch': 'link:../fetch'
|
||||
'@pnpm/lockfile-file': 'link:../lockfile-file'
|
||||
'@pnpm/lockfile-utils': 'link:../lockfile-utils'
|
||||
'@pnpm/manifest-utils': 'link:../manifest-utils'
|
||||
@@ -1235,9 +1234,7 @@ importers:
|
||||
'@pnpm/pick-registry-for-package': 'link:../pick-registry-for-package'
|
||||
'@pnpm/store-path': 4.0.2
|
||||
'@pnpm/types': 'link:../types'
|
||||
credentials-by-uri: 2.0.0
|
||||
dependency-path: 'link:../dependency-path'
|
||||
mem: 6.1.0
|
||||
ramda: 0.27.1
|
||||
semver: 7.3.2
|
||||
devDependencies:
|
||||
@@ -1247,10 +1244,9 @@ importers:
|
||||
'@types/semver': 7.3.1
|
||||
npm-run-all: 4.1.5
|
||||
specifiers:
|
||||
'@pnpm/client': 'workspace:^1.0.7'
|
||||
'@pnpm/constants': 'workspace:4.0.0'
|
||||
'@pnpm/default-resolver': 'workspace:10.0.7'
|
||||
'@pnpm/error': 'workspace:1.3.0'
|
||||
'@pnpm/fetch': 'workspace:^2.1.3'
|
||||
'@pnpm/lockfile-file': 'workspace:3.0.12'
|
||||
'@pnpm/lockfile-utils': 'workspace:2.0.16'
|
||||
'@pnpm/logger': ^3.2.2
|
||||
@@ -1263,9 +1259,7 @@ importers:
|
||||
'@pnpm/types': 'workspace:6.2.0'
|
||||
'@types/ramda': ^0.27.14
|
||||
'@types/semver': ^7.3.1
|
||||
credentials-by-uri: ^2.0.0
|
||||
dependency-path: 'workspace:5.0.3'
|
||||
mem: ^6.1.0
|
||||
npm-run-all: ^4.1.5
|
||||
ramda: ^0.27.1
|
||||
semver: ^7.3.2
|
||||
@@ -1790,12 +1784,11 @@ importers:
|
||||
packages/plugin-commands-publishing:
|
||||
dependencies:
|
||||
'@pnpm/cli-utils': 'link:../cli-utils'
|
||||
'@pnpm/client': 'link:../client'
|
||||
'@pnpm/config': 'link:../config'
|
||||
'@pnpm/error': 'link:../error'
|
||||
'@pnpm/exportable-manifest': 'link:../exportable-manifest'
|
||||
'@pnpm/fetch': 'link:../fetch'
|
||||
'@pnpm/lifecycle': 'link:../lifecycle'
|
||||
'@pnpm/npm-resolver': 'link:../npm-resolver'
|
||||
'@pnpm/pick-registry-for-package': 'link:../pick-registry-for-package'
|
||||
'@pnpm/resolver-base': 'link:../resolver-base'
|
||||
'@pnpm/run-npm': 'link:../run-npm'
|
||||
@@ -1804,10 +1797,8 @@ importers:
|
||||
'@pnpm/types': 'link:../types'
|
||||
'@zkochan/rimraf': 1.0.0
|
||||
cp-file: 9.0.0
|
||||
credentials-by-uri: 2.0.0
|
||||
enquirer: 2.3.6
|
||||
fast-glob: 3.2.4
|
||||
mem: 6.1.0
|
||||
mz: 2.7.0
|
||||
p-filter: 2.1.0
|
||||
ramda: 0.27.1
|
||||
@@ -1832,13 +1823,12 @@ importers:
|
||||
write-yaml-file: 4.1.0
|
||||
specifiers:
|
||||
'@pnpm/cli-utils': 'workspace:0.4.22'
|
||||
'@pnpm/client': 'workspace:^1.0.7'
|
||||
'@pnpm/config': 'workspace:11.2.4'
|
||||
'@pnpm/error': 'workspace:1.3.0'
|
||||
'@pnpm/exportable-manifest': 'workspace:^1.0.1'
|
||||
'@pnpm/fetch': 'workspace:^2.1.3'
|
||||
'@pnpm/filter-workspace-packages': 'workspace:2.1.15'
|
||||
'@pnpm/lifecycle': 'workspace:9.2.2'
|
||||
'@pnpm/npm-resolver': 'workspace:9.1.0'
|
||||
'@pnpm/pick-registry-for-package': 'workspace:1.0.3'
|
||||
'@pnpm/plugin-commands-publishing': 'link:'
|
||||
'@pnpm/prepare': 'workspace:0.0.9'
|
||||
@@ -1854,12 +1844,10 @@ importers:
|
||||
'@types/sinon': ^9.0.4
|
||||
'@zkochan/rimraf': ^1.0.0
|
||||
cp-file: ^9.0.0
|
||||
credentials-by-uri: ^2.0.0
|
||||
cross-spawn: ^7.0.3
|
||||
enquirer: ^2.3.6
|
||||
execa: ^4.0.3
|
||||
fast-glob: ^3.2.4
|
||||
mem: ^6.1.0
|
||||
mz: ^2.7.0
|
||||
p-filter: ^2.1.0
|
||||
path-exists: ^4.0.0
|
||||
|
||||
Reference in New Issue
Block a user