Skip to content

Commit

Permalink
feat(dist-tag): Wrap options in figgy-pudding
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 19, 2018
1 parent b1c2a10 commit 2713ab8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions utils/npm-dist-tag/__tests__/npm-dist-tag.test.js
Expand Up @@ -8,6 +8,8 @@ const fetch = require("libnpm/fetch");
// file under test
const npmDistTag = require("..");

expect.extend(require("@lerna-test/figgy-pudding-matchers"));

const stubLog = {
verbose: jest.fn(),
info: jest.fn(),
Expand All @@ -28,7 +30,7 @@ describe("npmDistTag.add()", () => {
});
expect(fetch).toHaveBeenLastCalledWith(
"-/package/@scope%2fsome-pkg/dist-tags/added-tag",
expect.objectContaining({
expect.figgyPudding({
method: "PUT",
body: JSON.stringify("1.0.1"),
headers: {
Expand Down Expand Up @@ -91,7 +93,7 @@ describe("npmDistTag.remove()", () => {
expect(tags).not.toHaveProperty("removed-tag");
expect(fetch).toHaveBeenLastCalledWith(
"-/package/@scope%2fsome-pkg/dist-tags/removed-tag",
expect.objectContaining({
expect.figgyPudding({
method: "DELETE",
})
);
Expand Down Expand Up @@ -128,7 +130,7 @@ describe("npmDistTag.list()", () => {
});
expect(fetch.json).toHaveBeenLastCalledWith(
"-/package/@scope%2fsome-pkg/dist-tags",
expect.objectContaining({
expect.figgyPudding({
spec: expect.objectContaining({
name: "@scope/some-pkg",
}),
Expand Down
33 changes: 23 additions & 10 deletions utils/npm-dist-tag/npm-dist-tag.js
Expand Up @@ -2,19 +2,32 @@

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

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

function add(spec, tag, _opts) {
// tag is not in the pudding spec, handle separately
const cleanTag = (tag || _opts.get("tag")).trim();
const DistTagConfig = figgyPudding(
{
log: {},
spec: {},
tag: {},
},
{
other() {
// open it up for the sake of tests
return true;
},
}
);

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

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

Expand All @@ -38,7 +51,7 @@ function add(spec, tag, _opts) {
});

// success returns HTTP 204, thus no JSON to parse
return fetch(uri, payload.toJSON()).then(() => {
return fetch(uri, payload).then(() => {
opts.log.verbose("dist-tag", `added "${cleanTag}" to ${name}@${version}`);

// eslint-disable-next-line no-param-reassign
Expand All @@ -50,7 +63,7 @@ function add(spec, tag, _opts) {
}

function remove(spec, tag, _opts) {
const opts = RegistryConfig(_opts, {
const opts = DistTagConfig(_opts, {
spec: npa(spec),
});

Expand All @@ -70,7 +83,7 @@ function remove(spec, tag, _opts) {
});

// the delete properly returns a 204, so no json to parse
return fetch(uri, payload.toJSON()).then(() => {
return fetch(uri, payload).then(() => {
opts.log.verbose("dist-tag", `removed "${tag}" from ${opts.spec.name}@${version}`);

// eslint-disable-next-line no-param-reassign
Expand All @@ -82,7 +95,7 @@ function remove(spec, tag, _opts) {
}

function list(spec, _opts) {
const opts = RegistryConfig(_opts, {
const opts = DistTagConfig(_opts, {
spec: npa(spec),
});

Expand All @@ -92,5 +105,5 @@ function list(spec, _opts) {
function fetchTags(opts) {
const uri = `-/package/${opts.spec.escapedName}/dist-tags`;

return fetch.json(uri, opts.toJSON());
return fetch.json(uri, opts);
}
4 changes: 2 additions & 2 deletions utils/npm-dist-tag/package.json
Expand Up @@ -31,7 +31,7 @@
"test": "echo \"Run tests from root\" && exit 1"
},
"dependencies": {
"libnpm": "^2.0.1",
"npm-registry-fetch": "^3.8.0"
"figgy-pudding": "^3.5.1",
"libnpm": "^2.0.1"
}
}

0 comments on commit 2713ab8

Please sign in to comment.