Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const connectionInfoDir = serverConnectionInfoDir(storeDir)
const serverJsonPath = path.join(connectionInfoDir, 'server.json')
let serverJson = await tryLoadServerJson({ serverJsonPath, shouldRetryOnNoent: false })
if (serverJson !== null) {
if (serverJson.pnpmVersion !== packageManager.version) {
logger.warn({
message: `The store server runs on pnpm v${serverJson.pnpmVersion}. It is recommended to connect with the same version (current is v${packageManager.version})`,
prefix: opts.dir,
})
}
logger.info({
message: 'A store server is running. All store manipulations are delegated to it.',
prefix: opts.dir,
})
return {
ctrl: await connectStoreController(serverJson.connectionOptions), // tslint:disable-line
dir: storeDir,
}
}
if (opts.useRunningStoreServer) {
throw new PnpmError('NO_STORE_SERVER', 'No store server is running.')
}
if (opts.useStoreServer) {
runServerInBackground(storeDir)
serverJson = await tryLoadServerJson({ serverJsonPath, shouldRetryOnNoent: true })
logger.info({
message: 'A store server has been started. To stop it, use \`pnpm server stop\`',
prefix: opts.dir,
})
return {
ctrl: await connectStoreController(serverJson!.connectionOptions), // tslint:disable-line
dir: storeDir,
ctrl: await connectStoreController(serverJson.connectionOptions), // tslint:disable-line
dir: storeDir,
}
}
if (opts.useRunningStoreServer) {
throw new PnpmError('NO_STORE_SERVER', 'No store server is running.')
}
if (opts.useStoreServer) {
runServerInBackground(storeDir)
serverJson = await tryLoadServerJson({ serverJsonPath, shouldRetryOnNoent: true })
logger.info({
message: 'A store server has been started. To stop it, use \`pnpm server stop\`',
prefix: opts.dir,
})
return {
ctrl: await connectStoreController(serverJson!.connectionOptions), // tslint:disable-line
dir: storeDir,
}
}
return createNewStoreController(Object.assign(opts, {
storeDir,
}))
}
async function main () {
const registry = 'https://registry.npmjs.org/'
const prefix = process.cwd()
const storeCtrl = await connectStoreController({remotePrefix: 'http://localhost:5813'})
const response = await storeCtrl.requestPackage(
{alias: 'is-positive', pref: '1.0.0'},
{
downloadPriority: 0,
offline: false,
prefix,
registry,
verifyStoreIntegrity: false,
}
)
console.log(response)
console.log(await response.fetchingManifest)
console.log(await response['fetchingFiles'])
await storeCtrl.updateConnections(prefix, {addDependencies: [response.id], removeDependencies: []})
opts: {
storeDir?: string,
dir: string,
},
) => {
const storeDir = await storePath(opts.dir, opts.storeDir)
const connectionInfoDir = serverConnectionInfoDir(storeDir)
const serverJson = await tryLoadServerJson({
serverJsonPath: path.join(connectionInfoDir, 'server.json'),
shouldRetryOnNoent: false,
})
if (serverJson === null) {
globalInfo(`Nothing to stop. No server is running for the store at ${storeDir}`)
return
}
const storeController = await connectStoreController(serverJson.connectionOptions)
await storeController.stop()
if (await serverGracefullyStops(serverJson.pid)) {
globalInfo('Server gracefully stopped')
return
}
globalWarn('Graceful shutdown failed')
await kill(serverJson.pid, 'SIGINT')
globalInfo('Server process terminated')
}