UNPKG

genezio

Version:

Command line utility to interact with Genezio infrastructure.

56 lines (55 loc) 2.11 kB
import { $ } from "execa"; export default class NpmPackageManager { constructor() { this.command = "npm"; } async install(packages = [], cwd, args = []) { await $({ cwd }) `npm install ${args} ${packages}`; } async cleanInstall(cwd, args = []) { await $({ cwd }) `npm ci ${args}`; } installSync(packages = [], cwd) { $({ cwd }).sync `npm install ${packages}`; } async link(packages = [], cwd) { await $({ cwd }) `npm link ${packages}`; } async publish(cwd) { await $({ cwd }) `npm publish`; } async addScopedRegistry(scope, url, authToken) { // Set the registry url for the specified scope await $ `npm 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 $ `npm config set //${registryUrl.hostname}${path}/:_authToken=${authToken}`; } async removeScopedRegistry(scope) { // Get the registry url for the specified scope const { stdout } = await $ `npm 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 $ `npm config delete @${scope}:registry`; // Remove the authentication token for the registry hostname await $ `npm 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 $ `npm --version`; this.version = stdout.trim(); return this.version; } async pack(cwd, destination) { const { stdout } = await $({ cwd }) `npm pack --pack-destination ${destination}`; return stdout.trim(); } }