How to use the @pnpm/store-connection-manager.serverConnectionInfoDir function in @pnpm/store-connection-manager

To help you get started, we’ve selected a few @pnpm/store-connection-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pnpm / pnpm / packages / plugin-commands-server / src / start.ts View on Github external
opts: CreateStoreControllerOptions & {
    background?: boolean,
    protocol?: 'auto' | 'tcp' | 'ipc',
    port?: number,
    ignoreStopRequests?: boolean,
    ignoreUploadRequests?: boolean,
  },
) => {
  if (opts.protocol === 'ipc' && opts.port) {
    throw new Error('Port cannot be selected when server communicates via IPC')
  }
  if (opts.background && !Diable.isDaemon()) {
    Diable()
  }
  const storeDir = await storePath(opts.dir, opts.storeDir)
  const connectionInfoDir = serverConnectionInfoDir(storeDir)
  const serverJsonPath = path.join(connectionInfoDir, 'server.json')
  await makeDir(connectionInfoDir)

  // Open server.json with exclusive write access to ensure only one process can successfully
  // start the server. Note: NFS does not support exclusive writing, but do we really care?
  // Source: https://github.com/moxystudio/node-proper-lockfile#user-content-comparison
  let fd: number|null
  try {
    fd = await fs.open(serverJsonPath, 'wx')
  } catch (error) {
    if (error.code !== 'EEXIST') {
      throw error
    }
    throw new PnpmError('SERVER_MANIFEST_LOCKED', `Canceling startup of server (pid ${process.pid}) because another process got exclusive access to server.json`)
  }
  let server: null|{close (): Promise} = null
github pnpm / pnpm / packages / plugin-commands-server / src / status.ts View on Github external
export default async (
  opts: Pick,
) => {
  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(`No server is running for the store at ${storeDir}`)
    return
  }
  console.log(stripIndents`
    store: ${storeDir}
    process id: ${serverJson.pid}
    remote prefix: ${serverJson.connectionOptions.remotePrefix}
  `)
}
github pnpm / pnpm / packages / plugin-commands-server / src / stop.ts View on Github external
export default async (
  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')

@pnpm/store-connection-manager

Create a direct pnpm store controller or connect to a running store server

MIT
Latest version published 7 days ago

Package Health Score

55 / 100
Full package analysis