UNPKG

genezio

Version:

Command line utility to interact with Genezio infrastructure.

70 lines (69 loc) 2.84 kB
import { $ } from "execa"; export default class PnpmPackageManager { constructor() { this.command = "pnpm"; } async install(packages = [], cwd, args = []) { // Pnpm has two different commands for installing packages: // - `pnpm install` will install all packages from the lockfile // - `pnpm add` will install the specified packages and update the lockfile if (packages.length === 0) { await $({ cwd }) `pnpm install ${args}`; return; } await $({ cwd }) `pnpm add ${args} ${packages}`; } async cleanInstall(cwd, args = []) { await $({ cwd }) `pnpm install --frozen-lockfile ${args}`; } installSync(packages = [], cwd) { // Pnpm has two different commands for installing packages: // - `pnpm install` will install all packages from the lockfile // - `pnpm add` will install the specified packages and update the lockfile if (packages.length === 0) { $({ cwd }).sync `pnpm install`; return; } $({ cwd }).sync `pnpm add ${packages}`; } async link(packages = [], cwd) { await $({ cwd }) `pnpm link ${packages}`; } async publish(cwd) { await $({ cwd }) `pnpm publish --no-git-checks`; } async addScopedRegistry(scope, url, authToken) { // Set the registry url for the specified scope await $ `pnpm config set @${scope}:registry=${url}`; if (authToken === undefined) { return; } // Add the authentication token for the registry hostname const registryUrl = new URL(url); const path = registryUrl.pathname.split("/").slice(0, -1).join("/"); await $ `pnpm config set //${registryUrl.hostname}${path}/:_authToken=${authToken}`; } async removeScopedRegistry(scope) { // Get the registry url for the specified scope const { stdout } = await $ `pnpm config get @${scope}:registry`; const registryUrl = new URL(stdout.trim()); const path = registryUrl.pathname.split("/").slice(0, -1).join("/"); // Remove the package scoped registry await $ `pnpm config delete @${scope}:registry`; // Remove the authentication token for the registry hostname await $ `pnpm config delete //${registryUrl.hostname}${path}/:_authToken`; } async getVersion() { // Check if the version is already cached if (this.version !== undefined) { return this.version; } const { stdout } = await $ `pnpm --version`; this.version = stdout.trim(); return this.version; } async pack(cwd, destination) { const { stdout } = await $({ cwd }) `pnpm pack --pack-destination ${destination}`; return stdout.trim(); } }