Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) };
}
}
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");
});
}
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));
});
}
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;
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;
});
}
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;
}
function updateRemote(opts) {
// git fetch, but for everything
childProcess.execSync("git", ["remote", "update"], opts);
}
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);
}
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;
});
});
}
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;
});
});
}