Skip to content

Commit b78535e

Browse files
committed
fix: Return undefined when no version is found
1 parent ddc2f97 commit b78535e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/get-last-release.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async ({publishConfig, name}, logger) => {
1919
const data = await promisify(client.get.bind(client))(uri, {auth});
2020
if (data && !data['dist-tags']) {
2121
logger.log('No version found of package %s found on %s', name, registry);
22-
return {};
22+
return;
2323
}
2424
const distTags = data['dist-tags'];
2525
let version;
@@ -34,7 +34,7 @@ module.exports = async ({publishConfig, name}, logger) => {
3434
} catch (err) {
3535
if (err.statusCode === 404 || /not found/i.test(err.message)) {
3636
logger.log('No version found of package %s found on %s', name, registry);
37-
return {};
37+
return;
3838
}
3939
throw err;
4040
}

test/get-last-release.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test.serial('Get nothing from completely unpublished package name', async t => {
9494
const registryMock = mock(name).reply(200, unpublishedModule);
9595
const release = await lastRelease({name, publishConfig: {registry}}, t.context.logger);
9696

97-
t.is(release.version, undefined);
97+
t.falsy(release);
9898
t.true(registryMock.isDone());
9999
});
100100

@@ -103,7 +103,7 @@ test.serial('Get nothing from not yet published package name (unavailable)', asy
103103
const registryMock = mock(name).reply(404, {});
104104
const release = await lastRelease({name, publishConfig: {registry}}, t.context.logger);
105105

106-
t.is(release.version, undefined);
106+
t.falsy(release);
107107
t.true(registryMock.isDone());
108108
});
109109

@@ -112,7 +112,7 @@ test.serial('Get nothing from not yet published package name (unavailable w/o re
112112
const registryMock = mock(name).reply(404);
113113
const release = await lastRelease({name, publishConfig: {registry}}, t.context.logger);
114114

115-
t.is(release.version, undefined);
115+
t.falsy(release);
116116
t.true(registryMock.isDone());
117117
});
118118

@@ -135,7 +135,7 @@ test.serial('Get nothing from not yet published package name (unavailable w/o st
135135
await appendFile('./.npmrc', 'fetch-retry-factor = 1\nfetch-retry-mintimeout = 1\nfetch-retry-maxtimeout = 1');
136136
const release = await lastRelease({name, publishConfig: {registry}}, t.context.logger);
137137

138-
t.is(release.version, undefined);
138+
t.falsy(release);
139139
t.true(registryMock.isDone());
140140
});
141141

test/integration.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ test.serial('Return nothing if no version if published', async t => {
9595
await writeJson('./package.json', pkg);
9696
const nextRelease = await t.context.m.getLastRelease({}, {logger: t.context.logger});
9797

98-
t.deepEqual(nextRelease, {});
98+
t.falsy(nextRelease);
9999
});
100100

101101
test.serial('Return last version published', async t => {
@@ -155,7 +155,7 @@ test.serial('Return nothing for an unpublished package', async t => {
155155
await execa('npm', ['unpublish', 'unpublished', '--force']);
156156

157157
const nextRelease = await t.context.m.getLastRelease({}, {logger: t.context.logger});
158-
t.deepEqual(nextRelease, {});
158+
t.falsy(nextRelease);
159159
});
160160

161161
test.serial('Publish a package', async t => {
@@ -176,7 +176,7 @@ test.serial('Verify token and set up auth only on the fist call', async t => {
176176
await t.notThrows(t.context.m.verifyConditions({}, {logger: t.context.logger}));
177177

178178
let nextRelease = await t.context.m.getLastRelease({}, {logger: t.context.logger});
179-
t.deepEqual(nextRelease, {});
179+
t.falsy(nextRelease);
180180

181181
await t.context.m.publish({}, {logger: t.context.logger, nextRelease: {version: '1.0.0'}});
182182

0 commit comments

Comments
 (0)