How to use @pnpm/server - 7 common examples

To help you get started, we’ve selected a few @pnpm/server 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 / store-connection-manager / src / index.ts View on Github external
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,
github pnpm / pnpm / packages / store-connection-manager / src / index.ts View on Github external
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,
  }))
}
github pnpm / pnpm / packages / plugin-commands-server / src / start.ts View on Github external
if (error.code !== 'ENOENT') {
        storeServerLogger.error(error, `Got error unlinking server.json, but the process is already exiting`)
      }
    }
  })
  const store = await createNewStoreController(Object.assign(opts, {
    storeDir,
  }))
  const protocol = opts.protocol ?? (opts.port ? 'tcp' : 'auto')
  const serverOptions = await getServerOptions(connectionInfoDir, { protocol, port: opts.port })
  const connectionOptions = {
    remotePrefix: serverOptions.path
      ? `http://unix:${serverOptions.path}:`
      : `http://${serverOptions.hostname}:${serverOptions.port}`,
  }
  server = createServer(store.ctrl, {
    ...serverOptions,
    ignoreStopRequests: opts.ignoreStopRequests,
    ignoreUploadRequests: opts.ignoreUploadRequests,
  })
  // Make sure to populate server.json after the server has started, so clients know that the server is
  // listening if a server.json with valid JSON content exists.
  const serverJson = {
    connectionOptions,
    pid: process.pid,
    pnpmVersion: packageManager.version,
  }
  const serverJsonStr = JSON.stringify(serverJson, undefined, 2) // undefined and 2 are for formatting.
  const serverJsonBuffer = Buffer.from(serverJsonStr, 'utf8')
  // fs.write on NodeJS 4 requires the parameters offset and length to be set:
  // https://nodejs.org/docs/latest-v4.x/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback
  await fs.write(fd, serverJsonBuffer, 0, serverJsonBuffer.byteLength)
github pnpm / pnpm / packages / pnpm / src / cmd / server / start.ts View on Github external
if (error.code !== 'ENOENT') {
        storeLogger.error(error, `Got error unlinking server.json, but the process is already exiting`)
      }
    }
  })
  const store = await createStore(Object.assign(opts, {
    store: pathOfStore,
  }))
  const protocol = opts.protocol || opts.port && 'tcp' || 'auto'
  const serverOptions = await getServerOptions(connectionInfoDir, { protocol, port: opts.port })
  const connectionOptions = {
    remotePrefix: serverOptions.path
      ? `http://unix:${serverOptions.path}:`
      : `http://${serverOptions.hostname}:${serverOptions.port}`,
  }
  server = createServer(store.ctrl, {
    ...serverOptions,
    ignoreStopRequests: opts.ignoreStopRequests,
    ignoreUploadRequests: opts.ignoreUploadRequests,
  })
  // Make sure to populate server.json after the server has started, so clients know that the server is
  // listening if a server.json with valid JSON content exists.
  const serverJson = {
    connectionOptions,
    pid: process.pid,
    pnpmVersion: packageManager.version,
  }
  const serverJsonStr = JSON.stringify(serverJson, undefined, 2) // undefined and 2 are for formatting.
  const serverJsonBuffer = Buffer.from(serverJsonStr, 'utf8')
  // fs.write on NodeJS 4 requires the parameters offset and length to be set:
  // https://nodejs.org/docs/latest-v4.x/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback
  await fs.write(fd, serverJsonBuffer, 0, serverJsonBuffer.byteLength)
github pnpm / pnpm / packages / server / example / client.js View on Github external
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: []})
github pnpm / pnpm / packages / plugin-commands-server / src / stop.ts View on Github external
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')
}
github pnpm / pnpm / packages / server / example / server.js View on Github external
metaCache: new Map(),
  })
  const fetchers = createFetcher({
    alwaysAuth: true,
    registry,
    strictSsl: true,
    rawConfig,
  })
  const storeCtrl = await createStore(resolve, fetchers, {
    networkConcurrency: 1,
    store,
  })

  const port = 5813
  const hostname = '127.0.0.1';
  const server = createServer(storeCtrl, {
    port,
    hostname,
  })

  process.on('exit', () => server.close())
}

@pnpm/server

A pnpm installer server

MIT
Latest version published 6 days ago

Package Health Score

61 / 100
Full package analysis