Skip to content

Commit 2058e9e

Browse files
committed
feat: Return async functions
BREAKING CHANGE: Return async functions instead of functions calling a callback
1 parent a3601b5 commit 2058e9e

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const {callbackify} = require('util');
21
const verifyNpm = require('./lib/verify');
32
const publishNpm = require('./lib/publish');
43
const getLastReleaseNpm = require('./lib/get-last-release');
@@ -26,8 +25,4 @@ async function publish(pluginConfig, {pkg, nextRelease: {version}, logger}) {
2625
await publishNpm(version, logger);
2726
}
2827

29-
module.exports = {
30-
verifyConditions: callbackify(verifyConditions),
31-
getLastRelease: callbackify(getLastRelease),
32-
publish: callbackify(publish),
33-
};
28+
module.exports = {verifyConditions, getLastRelease, publish};

test/integration.test.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {promisify} from 'util';
21
import {writeJson, readFile, appendFile} from 'fs-extra';
32
import test from 'ava';
43
import execa from 'execa';
@@ -68,7 +67,7 @@ test.after.always(async () => {
6867
test.serial('Throws error if NPM token is invalid', async t => {
6968
process.env.NPM_TOKEN = 'wrong_token';
7069
const error = await t.throws(
71-
promisify(t.context.m.verifyConditions)({}, {pkg: {name: 'invalid-token'}, logger: t.context.logger})
70+
t.context.m.verifyConditions({}, {pkg: {name: 'invalid-token'}, logger: t.context.logger})
7271
);
7372

7473
t.true(error instanceof SemanticReleaseError);
@@ -82,7 +81,7 @@ test.serial('Throws error if NPM token is invalid', async t => {
8281
test.serial('Verify npm auth and package', async t => {
8382
Object.assign(process.env, npmRegistry.authEnv);
8483
const pkg = {name: 'valid-token', publishConfig: {registry: npmRegistry.url}};
85-
await t.notThrows(promisify(t.context.m.verifyConditions)({}, {pkg, logger: t.context.logger}));
84+
await t.notThrows(t.context.m.verifyConditions({}, {pkg, logger: t.context.logger}));
8685

8786
const npmrc = (await readFile('.npmrc')).toString();
8887
t.regex(npmrc, /_auth =/);
@@ -92,7 +91,7 @@ test.serial('Verify npm auth and package', async t => {
9291
test.serial('Return nothing if no version if published', async t => {
9392
Object.assign(process.env, npmRegistry.authEnv);
9493
const pkg = {name: 'not-published', publishConfig: {registry: npmRegistry.url}};
95-
const nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
94+
const nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
9695

9796
t.deepEqual(nextRelease, {});
9897
});
@@ -111,7 +110,7 @@ test.serial('Return last version published', async t => {
111110

112111
await execa('npm', ['publish']);
113112

114-
const nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
113+
const nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
115114
t.is(nextRelease.version, '1.0.0');
116115
});
117116

@@ -134,7 +133,7 @@ test.serial('Return last version published on a dist-tag', async t => {
134133
// Publish version 1.1.0 on next
135134
await execa('npm', ['publish', '--tag=next']);
136135

137-
const nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
136+
const nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
138137
t.is(nextRelease.version, '1.1.0');
139138
});
140139

@@ -153,7 +152,7 @@ test.serial('Return nothing for an unpublished package', async t => {
153152
await execa('npm', ['publish']);
154153
await execa('npm', ['unpublish', 'unpublished', '--force']);
155154

156-
const nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
155+
const nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
157156
t.deepEqual(nextRelease, {});
158157
});
159158

@@ -162,7 +161,7 @@ test.serial('Publish a package', async t => {
162161
const pkg = {name: 'publish', version: '1.0.0', publishConfig: {registry: npmRegistry.url}};
163162
await writeJson('./package.json', pkg);
164163

165-
await promisify(t.context.m.publish)({}, {pkg, logger: t.context.logger, nextRelease: {version: '1.0.0'}});
164+
await t.context.m.publish({}, {pkg, logger: t.context.logger, nextRelease: {version: '1.0.0'}});
166165

167166
t.is((await execa('npm', ['view', 'publish', 'version'])).stdout, '1.0.0');
168167
});
@@ -172,13 +171,13 @@ test.serial('Verify token and set up auth only on the fist call', async t => {
172171
const pkg = {name: 'test-module', version: '0.0.0-dev', publishConfig: {registry: npmRegistry.url}};
173172
await writeJson('./package.json', pkg);
174173

175-
await t.notThrows(promisify(t.context.m.verifyConditions)({}, {pkg, logger: t.context.logger}));
174+
await t.notThrows(t.context.m.verifyConditions({}, {pkg, logger: t.context.logger}));
176175

177-
let nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
176+
let nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
178177
t.deepEqual(nextRelease, {});
179178

180-
await promisify(t.context.m.publish)({}, {pkg, logger: t.context.logger, nextRelease: {version: '1.0.0'}});
179+
await t.context.m.publish({}, {pkg, logger: t.context.logger, nextRelease: {version: '1.0.0'}});
181180

182-
nextRelease = await promisify(t.context.m.getLastRelease)({}, {pkg, logger: t.context.logger});
181+
nextRelease = await t.context.m.getLastRelease({}, {pkg, logger: t.context.logger});
183182
t.is(nextRelease.version, '1.0.0');
184183
});

0 commit comments

Comments
 (0)