How to use the @yarnpkg/core.execUtils.execvp function in @yarnpkg/core

To help you get started, we’ve selected a few @yarnpkg/core 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 yarnpkg / berry / packages / plugin-version / sources / commands / version / check.ts View on Github external
async function fetchChangedFiles(root: PortablePath, {base}: {base: string}) {
  const {stdout: diffStdout} = await execUtils.execvp(`git`, [`diff`, `--name-only`, base], {cwd: root, strict: true});
  const files = diffStdout.split(/\r\n|\r|\n/).filter(file => file.length > 0).map(file => ppath.resolve(root, toPortablePath(file)));

  const {stdout: untrackedStdout} = await execUtils.execvp(`git`, [`ls-files`, `--others`, `--exclude-standard`], {cwd: root, strict: true});
  const moreFiles = untrackedStdout.split(/\r\n|\r|\n/).filter(file => file.length > 0).map(file => ppath.resolve(root, toPortablePath(file)));

  return [...files, ...moreFiles];
}
github yarnpkg / berry / packages / plugin-git / sources / gitUtils.ts View on Github external
export async function lsRemote(repo: string, configuration: Configuration) {
  if (!configuration.get(`enableNetwork`))
    throw new Error(`Network access has been disabled by configuration (${repo})`);

  let res: {stdout: string};
  try {
    res = await execUtils.execvp(`git`, [`ls-remote`, `--refs`, normalizeRepoUrl(repo)], {
      cwd: configuration.startingCwd,
      env: makeGitEnvironment(),
      strict: true,
    });
  } catch (error) {
    error.message = `Listing the refs for ${repo} failed`;
    throw error;
  }

  const refs = new Map();

  const matcher = /^([a-f0-9]{40})\t(refs\/[^\n]+)/gm;
  let match;

  while ((match = matcher.exec(res.stdout)) !== null)
    refs.set(match[2], match[1]);
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.tsx View on Github external
async function fetchBase(root: PortablePath) {
  const candidateBases = [`master`, `origin/master`, `upstream/master`];
  const ancestorBases = [];

  for (const candidate of candidateBases) {
    const {code} = await execUtils.execvp(`git`, [`merge-base`, candidate, `HEAD`], {cwd: root});
    if (code === 0) {
      ancestorBases.push(candidate);
    }
  }

  if (ancestorBases.length === 0)
    throw new UsageError(`No ancestor could be found between any of HEAD and ${candidateBases.join(`, `)}`);

  const {stdout: mergeBaseStdout} = await execUtils.execvp(`git`, [`merge-base`, `HEAD`, ...ancestorBases], {cwd: root, strict: true});
  const hash = mergeBaseStdout.trim();

  const {stdout: showStdout} = await execUtils.execvp(`git`, [`show`, `--quiet`, `--pretty=format:%s`, hash], {cwd: root, strict: true});
  const message = showStdout.trim();

  return {hash, message};
}
github yarnpkg / berry / packages / plugin-git / sources / gitUtils.ts View on Github external
export async function clone(url: string, configuration: Configuration) {
  if (!configuration.get(`enableNetwork`))
    throw new Error(`Network access has been disabled by configuration (${url})`);

  const {repo, treeish: {protocol, request}} = splitRepoUrl(url);
  if (protocol !== `commit`)
    throw new Error(`Invalid treeish protocol when cloning`);

  const directory = await xfs.mktempPromise();
  const execOpts = {cwd: directory, env: makeGitEnvironment(), strict: true};

  try {
    await execUtils.execvp(`git`, [`clone`, `${normalizeRepoUrl(repo)}`, npath.fromPortablePath(directory)], execOpts);
    await execUtils.execvp(`git`, [`checkout`, `${request}`], execOpts);
  } catch (error) {
    error.message = `Repository clone failed`;
    throw error;
  }

  return directory;
}
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.tsx View on Github external
async function fetchPreviousNonce(workspace: Workspace, {root, base}: {root: PortablePath, base: string}) {
  const {code, stdout} = await execUtils.execvp(`git`, [`show`, `${base}:${npath.fromPortablePath(ppath.relative(root, ppath.join(workspace.cwd, `package.json` as Filename)))}`], {cwd: workspace.cwd});

  if (code === 0) {
    return getNonce(Manifest.fromText(stdout));
  } else {
    return null;
  }
}
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.tsx View on Github external
async function fetchBase(root: PortablePath) {
  const candidateBases = [`master`, `origin/master`, `upstream/master`];
  const ancestorBases = [];

  for (const candidate of candidateBases) {
    const {code} = await execUtils.execvp(`git`, [`merge-base`, candidate, `HEAD`], {cwd: root});
    if (code === 0) {
      ancestorBases.push(candidate);
    }
  }

  if (ancestorBases.length === 0)
    throw new UsageError(`No ancestor could be found between any of HEAD and ${candidateBases.join(`, `)}`);

  const {stdout: mergeBaseStdout} = await execUtils.execvp(`git`, [`merge-base`, `HEAD`, ...ancestorBases], {cwd: root, strict: true});
  const hash = mergeBaseStdout.trim();

  const {stdout: showStdout} = await execUtils.execvp(`git`, [`show`, `--quiet`, `--pretty=format:%s`, hash], {cwd: root, strict: true});
  const message = showStdout.trim();

  return {hash, message};
}
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.ts View on Github external
async function fetchBase(root: PortablePath) {
  const candidateBases = [`master`, `origin/master`, `upstream/master`];
  const ancestorBases = [];

  for (const candidate of candidateBases) {
    const {code} = await execUtils.execvp(`git`, [`merge-base`, candidate, `HEAD`], {cwd: root});
    if (code === 0) {
      ancestorBases.push(candidate);
    }
  }

  if (ancestorBases.length === 0)
    throw new UsageError(`No ancestor could be found between any of HEAD and ${candidateBases.join(`, `)}`);

  const {stdout: mergeBaseStdout} = await execUtils.execvp(`git`, [`merge-base`, `HEAD`, ...ancestorBases], {cwd: root, strict: true});
  const hash = mergeBaseStdout.trim();

  const {stdout: showStdout} = await execUtils.execvp(`git`, [`show`, `--quiet`, `--pretty=format:%s`, hash], {cwd: root, strict: true});
  const message = showStdout.trim();

  return {hash, message};
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / set / version / sources.ts View on Github external
if (usePipe)
            args.pop();

          if (usePipe) {
            await execUtils.pipevp(fileName, args, {
              cwd: target,
              stdin: this.context.stdin,
              stdout: this.context.stdout,
              stderr: this.context.stderr,
              strict: true,
            });
          } else {
            this.context.stdout.write(`${configuration.format(`  $ ${[fileName, ...args].join(` `)}`, `grey`)}\n`);

            try {
              await execUtils.execvp(fileName, args, {
                cwd: target,
                strict: true,
              });
            } catch (error) {
              this.context.stdout.write(error.stdout || error.stack);
              throw error;
            }
          }
        }
      };