<commit_before>"use strict";

const npa = require("libnpm/parse-arg");
const fetch = require("libnpm/fetch");
const figgyPudding = require("figgy-pudding");

exports.add = add;
exports.remove = remove;
exports.list = list;

const DistTagConfig = figgyPudding(
  {
    log: {},
    spec: {},
    tag: {},
  },
  {
    other() {
      // open it up for the sake of tests
      return true;
    },
  }
);

function add(spec, tag, _opts) {
  const opts = DistTagConfig(_opts, {
    spec: npa(spec),
    tag,
  });
  const cleanTag = opts.tag.trim();

  const { name, rawSpec: version } = opts.spec;

  opts.log.verbose("dist-tag", `adding "${cleanTag}" to ${name}@${version}`);

  return fetchTags(opts).then(tags => {
    if (tags[cleanTag] === version) {
      opts.log.warn("dist-tag", `${name}@${cleanTag} already set to ${version}`);
      return tags;
    }
<commit_msg>fix(npm-dist-tag): Accept opts.log, defaulting to libnpm/log<commit_after>"use strict";

const log = require("libnpm/log");
const npa = require("libnpm/parse-arg");
const fetch = require("libnpm/fetch");
const figgyPudding = require("figgy-pudding");

exports.add = add;
exports.remove = remove;
exports.list = list;

const DistTagConfig = figgyPudding(
  {
    log: { default: log },
    spec: {},
    tag: {},
  },
  {
    other() {
      // open it up for the sake of tests
      return true;
    },
  }
);

function add(spec, tag, _opts) {
  const opts = DistTagConfig(_opts, {
    spec: npa(spec),
    tag,
  });
  const cleanTag = opts.tag.trim();

  const { name, rawSpec: version } = opts.spec;

  opts.log.verbose("dist-tag", `adding "${cleanTag}" to ${name}@${version}`);

  return fetchTags(opts).then(tags => {
    if (tags[cleanTag] === version) {
      opts.log.warn("dist-tag", `${name}@${cleanTag} already set to ${version}`);
      return tags;
    }

{'fraction_non_alphanumeric': 0.1793478260869565, 'fraction_numerical': 0.0, 'mean_word_length': 3.261574074074074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2868823', 'n_tokens_mistral': 648, 'n_tokens_neox': 640, 'n_words': 150}