How to use @lerna/child-process - 10 common examples

To help you get started, we’ve selected a few @lerna/child-process 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 lerna / lerna / utils / describe-ref / lib / describe-ref.js View on Github external
function parse(stdout, options = {}) {
  const minimalShaRegex = /^([0-9a-f]{7,40})(-dirty)?$/;
  // when git describe fails to locate tags, it returns only the minimal sha
  if (minimalShaRegex.test(stdout)) {
    // repo might still be dirty
    const [, sha, isDirty] = minimalShaRegex.exec(stdout);

    // count number of commits since beginning of time
    const refCount = childProcess.execSync("git", ["rev-list", "--count", sha], options);

    return { refCount, sha, isDirty: Boolean(isDirty) };
  }

  const [, lastTagName, lastVersion, refCount, sha, isDirty] =
    /^((?:.*@)?(.*))-(\d+)-g([0-9a-f]+)(-dirty)?$/.exec(stdout) || [];

  return { lastTagName, lastVersion, refCount, sha, isDirty: Boolean(isDirty) };
}
github lerna / lerna / commands / publish / lib / verify-npm-registry.js View on Github external
}

  const args = [
    "ping",
    // immediate feedback from request errors, not excruciatingly slow retries
    // @see https://docs.npmjs.com/misc/config#fetch-retries
    "--fetch-retries=0",
    // including http requests makes raw logging easier to debug for end users
    "--loglevel=http",
  ];
  const opts = getExecOpts({ location }, registry);

  // we do not need special log handling
  delete opts.pkg;

  return childProcess.exec("npm", args, opts).catch(({ stderr }) => {
    // Log the error cleanly to stderr, it already has npmlog decorations
    log.pause();
    console.error(stderr); // eslint-disable-line no-console
    log.resume();

    throw new ValidationError("EREGISTRY", "Connection to npm registry failed");
  });
}
github lerna / lerna / commands / publish / lib / get-tagged-packages.js View on Github external
function getTaggedPackages(packageGraph, rootPath, opts) {
  log.silly("getTaggedPackages");

  // @see https://stackoverflow.com/a/424142/5707
  // FIXME: --root is only necessary for tests :P
  return childProcess
    .exec("git", ["diff-tree", "--name-only", "--no-commit-id", "--root", "-r", "-c", "HEAD"], opts)
    .then(({ stdout }) => {
      const manifests = stdout.split("\n").filter(fp => path.basename(fp) === "package.json");
      const locations = new Set(manifests.map(fp => path.join(rootPath, path.dirname(fp))));

      return Array.from(packageGraph.values()).filter(node => locations.has(node.location));
    });
}
github lerna / lerna / commands / import / index.js View on Github external
tracker.info(sha);

      const patch = this.createPatchForCommit(sha);
      const procArgs = ["am", "-3", "--keep-non-patch"];

      if (this.options.preserveCommit) {
        this.configureGitUser(this.getGitUserFromSha(sha));
        procArgs.push("--committer-date-is-author-date");
      }

      // Apply the modified patch to the current lerna repository, preserving
      // original commit date, author and message.
      //
      // Fall back to three-way merge, which can help with duplicate commits
      // due to merge history.
      const proc = ChildProcessUtilities.exec("git", procArgs, this.execOpts);

      proc.stdin.end(patch);

      return pulseTillDone(proc)
        .then(() => {
          tracker.completeWork(1);
        })
        .catch(err => {
          if (err.stdout.indexOf("Patch is empty.") === 0) {
            tracker.completeWork(1);

            // Automatically skip empty commits
            return ChildProcessUtilities.exec("git", ["am", "--skip"], this.execOpts);
          }

          err.sha = sha;
github lerna / lerna / commands / publish / lib / get-current-tags.js View on Github external
function getCurrentTags(execOpts, matchingPattern) {
  log.silly("getCurrentTags", "matching %j", matchingPattern);

  const opts = Object.assign({}, execOpts, {
    // don't reject due to non-zero exit code when there are no results
    reject: false,
  });

  return childProcess
    .exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD", "--list", matchingPattern], opts)
    .then(result => {
      const lines = result.stdout.split("\n").filter(Boolean);

      if (matchingPattern === "*@*") {
        // independent mode does not respect tagVersionPrefix,
        // but embeds the package name in the tag "prefix"
        return lines.map(tag => npa(tag).name);
      }

      // "fixed" mode can have a custom tagVersionPrefix,
      // but it doesn't really matter as it is not used to extract package names
      return lines;
    });
}
github lerna / lerna / utils / describe-ref / lib / describe-ref.js View on Github external
function sync(options = {}, includeMergedTags) {
  const stdout = childProcess.execSync("git", getArgs(options, includeMergedTags), options);
  const result = parse(stdout, options);

  // only called by collect-updates with no matcher
  log.silly("git-describe.sync", "%j => %j", stdout, result);

  return result;
}
github lerna / lerna / commands / version / lib / is-behind-upstream.js View on Github external
function updateRemote(opts) {
  // git fetch, but for everything
  childProcess.execSync("git", ["remote", "update"], opts);
}
github lerna / lerna / utils / npm-install / npm-install.js View on Github external
args.push("--non-interactive");
  }

  if (npmClientArgs && npmClientArgs.length) {
    args.push(...npmClientArgs);
  }

  // potential override, e.g. "inherit" in root-only bootstrap
  opts.stdio = stdio;

  // provide env sentinels to avoid recursive execution from scripts
  opts.env.LERNA_EXEC_PATH = pkg.location;
  opts.env.LERNA_ROOT_PATH = pkg.rootPath;

  log.silly("npmInstall", [cmd, args]);
  return ChildProcessUtilities.exec(cmd, args, opts);
}
github lerna / lerna / utils / rimraf-dir / rimraf-dir.js View on Github external
return pathExists(dirPath).then(exists => {
    if (!exists) {
      return;
    }

    // globs only return directories with a trailing slash
    const slashed = path.normalize(`${dirPath}/`);
    const args = [RIMRAF_CLI, "--no-glob", slashed];

    // We call this resolved CLI path in the "path/to/node path/to/cli <..args>"
    // pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it)
    return ChildProcessUtilities.spawn(process.execPath, args).then(() => {
      log.verbose("rimrafDir", "removed", dirPath);

      return dirPath;
    });
  });
}
github lerna / lerna / utils / rimraf-dir / rimraf-dir.js View on Github external
return pathExists(dirPath).then(exists => {
    if (!exists) {
      return;
    }

    // globs only return directories with a trailing slash
    const slashed = path.normalize(`${dirPath}/`);
    const args = [RIMRAF_CLI, "--no-glob", slashed];

    // We call this resolved CLI path in the "path/to/node path/to/cli <..args>"
    // pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it)
    return ChildProcessUtilities.spawn(process.execPath, args).then(() => {
      log.verbose("rimrafDir", "removed", dirPath);

      return dirPath;
    });
  });
}

@lerna/child-process

Lerna's internal child_process wrapper

MIT
Latest version published 7 months ago

Package Health Score

96 / 100
Full package analysis