How to use @pnpm/store-connection-manager - 10 common examples

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-installation / src / install.ts View on Github external
}
    }
    opts['preserveWorkspaceProtocol'] = !opts.linkWorkspacePackages
  }
  // `pnpm install ""` is going to be just `pnpm install`
  input = input.filter(Boolean)

  const dir = opts.dir || process.cwd()

  const workspacePackages = opts.workspaceDir
    ? arrayOfWorkspacePackagesToMap(
      await findWorkspacePackages(opts.workspaceDir, opts),
    )
    : undefined

  const store = await createOrConnectStoreController(opts)
  const installOpts = {
    ...opts,
    // In case installation is done in a multi-package repository
    // The dependencies should be built first,
    // so ignoring scripts for now
    ignoreScripts: !!workspacePackages || opts.ignoreScripts,
    storeController: store.ctrl,
    storeDir: store.dir,
    workspacePackages,

    forceHoistPattern: typeof opts.rawLocalConfig['hoist-pattern'] !== 'undefined' || typeof opts.rawLocalConfig['hoist'] !== 'undefined',
    forceIndependentLeaves: typeof opts.rawLocalConfig['independent-leaves'] !== 'undefined',
    forceShamefullyHoist: typeof opts.rawLocalConfig['shamefully-hoist'] !== 'undefined',
  }
  if (!opts.ignorePnpmfile) {
    installOpts['hooks'] = requireHooks(opts.lockfileDir || dir, opts)
github pnpm / pnpm / packages / plugin-commands-import / src / import.ts View on Github external
export async function handler (
  input: string[],
  opts: CreateStoreControllerOptions & Omit,
) {
  // Removing existing pnpm lockfile
  // it should not influence the new one
  await rimraf(path.join(opts.dir, WANTED_LOCKFILE))
  const npmPackageLock = await readNpmLockfile(opts.dir)
  const versionsByPackageNames = {}
  getAllVersionsByPackageNames(npmPackageLock, versionsByPackageNames)
  const preferredVersions = getPreferredVersions(versionsByPackageNames)
  const store = await createOrConnectStoreController(opts)
  const installOpts = {
    ...opts,
    lockfileOnly: true,
    preferredVersions,
    storeController: store.ctrl,
    storeDir: store.dir,
  }
  await install(await readImporterManifestOnly(opts.dir), installOpts)
}
github pnpm / pnpm / packages / plugin-commands-recursive / src / recursive.ts View on Github external
switch (cmdFullName) {
    case 'test':
      throwOnFail(await run(chunks, opts.selectedWsPkgsGraph, ['test', ...input], cmd, opts as any)) // tslint:disable-line:no-any
      return true
    case 'run':
      throwOnFail(await run(chunks, opts.selectedWsPkgsGraph, input, cmd, { ...opts, allPackagesAreSelected } as any)) // tslint:disable-line:no-any
      return true
    case 'update':
      opts = { ...opts, update: true, allowNew: false } as any // tslint:disable-line:no-any
      break
    case 'exec':
      throwOnFail(await exec(chunks, opts.selectedWsPkgsGraph, input, cmd, opts as any)) // tslint:disable-line:no-any
      return true
  }

  const store = await createOrConnectStoreController(opts)

  // It is enough to save the store.json file once,
  // once all installations are done.
  // That's why saveState that is passed to the install engine
  // does nothing.
  const saveState = store.ctrl.saveState
  const storeController = {
    ...store.ctrl,
    saveState: async () => undefined,
  }

  const workspacePackages = cmdFullName !== 'unlink'
    ? arrayOfWorkspacePackagesToMap(allWsPkgs)
    : {}
  const installOpts = Object.assign(opts, {
    ownLifecycleHooksStdio: 'pipe',
github pnpm / pnpm / packages / plugin-commands-installation / src / recursive.ts View on Github external
manifestsByPath[dir] = { manifest, writeImporterManifest }
  }

  scopeLogger.debug({
    selected: pkgs.length,
    total: allWsPkgs.length,
    workspacePrefix: opts.workspaceDir,
  })

  const throwOnFail = throwOnCommandFail.bind(null, `pnpm recursive ${cmdFullName}`)

  const chunks = opts.sort !== false
    ? sortPackages(opts.selectedWsPkgsGraph)
    : [Object.keys(opts.selectedWsPkgsGraph).sort()]

  const store = await createOrConnectStoreController(opts)

  // It is enough to save the store.json file once,
  // once all installations are done.
  // That's why saveState that is passed to the install engine
  // does nothing.
  const saveState = store.ctrl.saveState
  const storeController = {
    ...store.ctrl,
    saveState: async () => undefined,
  }

  const workspacePackages = cmdFullName !== 'unlink'
    ? arrayOfWorkspacePackagesToMap(allWsPkgs)
    : {}
  const installOpts = Object.assign(opts, {
    ownLifecycleHooksStdio: 'pipe',
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-installation / src / link.ts View on Github external
'workspaceDir'
  > & Partial>,
) {
  const cwd = opts?.dir ?? process.cwd()

  const storeControllerCache = new Map>()
  let workspacePackagesArr
  let workspacePackages!: WorkspacePackages
  if (opts.workspaceDir) {
    workspacePackagesArr = await findWorkspacePackages(opts.workspaceDir, opts)
    workspacePackages = arrayOfWorkspacePackagesToMap(workspacePackagesArr)
  } else {
    workspacePackages = {}
  }

  const store = await createOrConnectStoreControllerCached(storeControllerCache, opts)
  const linkOpts = Object.assign(opts, {
    storeController: store.ctrl,
    storeDir: store.dir,
    targetDependenciesField: getSaveType(opts),
    workspacePackages,
  })

  // pnpm link
  if (!input || !input.length) {
    const { manifest, writeImporterManifest } = await tryReadImporterManifest(opts.globalDir!, opts)
    const newManifest = await linkToGlobal(cwd, {
      ...linkOpts,
      // A temporary workaround. global bin/prefix are always defined when --global is set
      globalBin: linkOpts.globalBin!,
      globalDir: linkOpts.globalDir!,
      manifest: manifest || {},
github pnpm / pnpm / packages / plugin-commands-server / src / start.ts View on Github external
if (fd !== null) {
      try {
        fs.closeSync(fd)
      } catch (error) {
        storeServerLogger.error(error, `Got error while closing file descriptor of server.json, but the process is already exiting`)
      }
    }
    try {
      fs.unlinkSync(serverJsonPath)
    } catch (error) {
      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.
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-installation / src / link.ts View on Github external
pkgPaths.map((dir) => installLimit(async () => {
      const s = await createOrConnectStoreControllerCached(storeControllerCache, opts)
      await install(
        await readImporterManifestOnly(dir, opts), {
          ...await getConfig(
            { ...opts.cliOptions, 'dir': dir },
            {
              command: ['link'],
              excludeReporter: true,
              rcOptionsTypes: installCommand.rcOptionsTypes(),
              workspaceDir: await findWorkspaceDir(dir),
            },
          ),
          storeController: s.ctrl,
          storeDir: s.dir,
          workspacePackages,
        } as InstallOptions,
      )
github pnpm / pnpm / packages / plugin-commands-installation / src / remove.ts View on Github external
export async function handler (
  input: string[],
  opts: CreateStoreControllerOptions & Pick,
) {
  const store = await createOrConnectStoreController(opts)
  const removeOpts = Object.assign(opts, {
    storeController: store.ctrl,
    storeDir: store.dir,
  })
  if (!opts.ignorePnpmfile) {
    removeOpts['hooks'] = requireHooks(opts.lockfileDir || opts.dir, opts)
  }
  removeOpts['workspacePackages'] = opts.workspaceDir
    ? arrayOfWorkspacePackagesToMap(await findWorkspacePackages(opts.workspaceDir, opts))
    : undefined
  const currentManifest = await readImporterManifest(opts.dir, opts)
  const [mutationResult] = await mutateModules(
    [
      {
        binsDir: opts.bin,
        dependencyNames: input,

@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