UNPKG

semantic-release-yarn

Version:

semantic-release plugin to publish a npm package with yarn

38 lines (37 loc) 1.64 kB
import { resolve } from "node:path"; import { getImplementation } from "./container.js"; import { isDefaultRegistry } from "./definitions/constants.js"; import { getError } from "./get-error.js"; import { getRegistry } from "./get-registry.js"; import { getToken } from "./get-token.js"; import { getYarnConfig } from "./get-yarn-config.js"; export async function verifyAuth({ pkgRoot }, pkg, context) { const { cwd, env, stdout, stderr, logger } = context; const basePath = pkgRoot ? resolve(cwd, String(pkgRoot)) : cwd; const execa = await getImplementation("execa"); const AggregateError = await getImplementation("AggregateError"); const yarnrc = await getYarnConfig(context); const registry = getRegistry(pkg, yarnrc, context); const token = getToken(registry, yarnrc, context); if (!token) { throw new AggregateError([getError("ENONPMTOKEN", { registry })]); } if (!isDefaultRegistry(registry)) { logger.log(`Skipping authentication verification for non-default registry "${registry}"`); return; } try { logger.log(`Running "yarn npm whoami --publish" to verify authentication on registry "${registry}"`); // @todo deal with npm npm whoami --scope if pkg is scoped const whoamiResult = execa("yarn", ["npm", "whoami", "--publish"], { cwd: basePath, env, }); whoamiResult.stdout.pipe(stdout, { end: false }); whoamiResult.stderr.pipe(stderr, { end: false }); await whoamiResult; } catch { throw new AggregateError([getError("EINVALIDNPMTOKEN", { registry })]); } }