Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
localAddress?: string,
lockfileDir?: string,
offline?: boolean,
dir: string,
proxy?: string,
rawConfig: object,
registries: Registries,
storeDir?: string,
strictSsl?: boolean,
userAgent?: string,
verifyStoreIntegrity?: boolean,
workspaceDir: string,
},
) {
const storeDir = await storePath(opts.workspaceDir, opts.storeDir)
const resolve = createResolver(Object.assign(opts, {
fullMetadata: true,
metaCache: new LRU({
max: 10000,
maxAge: 120 * 1000, // 2 minutes
}) as any, // tslint:disable-line:no-any
storeDir,
})) as unknown as ResolveFunction
const pkgsToPublish = await pFilter(pkgs, async (pkg) => {
if (!pkg.manifest.name || !pkg.manifest.version || pkg.manifest.private) return false
return !(await isAlreadyPublished({
dir: pkg.dir,
lockfileDir: opts.lockfileDir || pkg.dir,
registries: opts.registries,
resolve,
}, pkg.manifest.name, pkg.manifest.version))
})
'use strict'
const createResolveFromNpm = require('@pnpm/npm-resolver').default
const resolveFromNpm = createResolveFromNpm({
metaCache: new Map(),
store: '.store',
offline: false,
rawConfig: {
registry: 'https://registry.npmjs.org/',
},
})
resolveFromNpm({alias: 'is-positive', pref: '1.0.0'}, {
registry: 'https://registry.npmjs.org/',
})
.then(resolveResult => console.log(JSON.stringify(resolveResult, null, 2)))
export default function createResolver (
pnpmOpts: ResolverFactoryOptions,
): ResolveFunction {
const resolveFromNpm = createResolveFromNpm(pnpmOpts)
const resolveFromGit = createResolveFromGit(pnpmOpts)
return async (wantedDependency, opts) => {
const resolution = await resolveFromNpm(wantedDependency, opts as ResolveFromNpmOptions)
|| wantedDependency.pref && (
await resolveFromTarball(wantedDependency as {pref: string})
|| await resolveFromGit(wantedDependency as {pref: string})
|| await resolveFromLocal(wantedDependency as {pref: string}, opts)
)
if (!resolution) {
throw new Error(`Cannot resolve ${wantedDependency.alias ? wantedDependency.alias + '@' : ''}${wantedDependency.pref} packages not supported`)
}
return resolution
}
}
async function main() {
const registry = 'https://registry.npmjs.org/'
const rawConfig = { registry }
const store = '.store'
const resolve = createResolver({
rawConfig,
store,
metaCache: new Map(),
})
const fetchers = createFetcher({
alwaysAuth: true,
registry,
strictSsl: true,
rawConfig,
})
const storeCtrl = await createStore(resolve, fetchers, {
networkConcurrency: 1,
store,
})
const port = 5813
export default function wantedDepIsLocallyAvailable (
workspacePackages: WorkspacePackages,
wantedDependency: WantedDependency,
opts: {
defaultTag: string,
registry: string,
},
) {
const spec = parsePref(wantedDependency.pref, wantedDependency.alias, opts.defaultTag || 'latest', opts.registry)
if (!spec || !workspacePackages[spec.name]) return false
return pickMatchingLocalVersionOrNull(workspacePackages[spec.name], spec) !== null
}