-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
…-release
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
const getPkg = require('./lib/get-pkg'); | ||
const verifyNpm = require('./lib/verify'); | ||
const publishNpm = require('./lib/publish'); | ||
const getLastReleaseNpm = require('./lib/get-last-release'); | ||
|
||
let verified; | ||
|
||
async function verifyConditions(pluginConfig, {pkg, logger}) { | ||
async function verifyConditions(pluginConfig, {logger}) { | ||
const pkg = await getPkg(); | ||
await verifyNpm(pkg, logger); | ||
verified = true; | ||
} | ||
|
||
async function getLastRelease(pluginConfig, {pkg, logger}) { | ||
async function getLastRelease(pluginConfig, {logger}) { | ||
// Reload package.json in case a previous external step updated it | ||
const pkg = await getPkg(); | ||
if (!verified) { | ||
await verifyNpm(pkg, logger); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
felixfbecker
|
||
verified = true; | ||
} | ||
return getLastReleaseNpm(pkg, logger); | ||
} | ||
|
||
async function publish(pluginConfig, {pkg, nextRelease: {version}, logger}) { | ||
async function publish(pluginConfig, {nextRelease: {version}, logger}) { | ||
// Reload package.json in case a previous external step updated it | ||
const pkg = await getPkg(); | ||
if (!verified) { | ||
await verifyNpm(pkg, logger); | ||
verified = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const readPkgUp = require('read-pkg-up'); | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
|
||
module.exports = async () => { | ||
const {pkg} = await readPkgUp(); | ||
|
||
if (!pkg) { | ||
throw new SemanticReleaseError('A package.json file is required to release on npm.', 'ENOPKG'); | ||
} | ||
|
||
if (!pkg.name) { | ||
throw new SemanticReleaseError('No "name" found in package.json.', 'ENOPKGNAME'); | ||
} | ||
|
||
return pkg; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import test from 'ava'; | ||
import {writeJson, writeFile} from 'fs-extra'; | ||
import tempy from 'tempy'; | ||
import getPkg from '../lib/get-pkg'; | ||
|
||
test.beforeEach(t => { | ||
// Save the current working diretory | ||
t.context.cwd = process.cwd(); | ||
// Change current working directory to a temp directory | ||
process.chdir(tempy.directory()); | ||
}); | ||
|
||
test.afterEach.always(t => { | ||
// Restore the current working directory | ||
process.chdir(t.context.cwd); | ||
}); | ||
|
||
test.serial('Verify name and return parsed package.json', async t => { | ||
const pkg = {name: 'package', version: '0.0.0'}; | ||
await writeJson('./package.json', pkg); | ||
|
||
const result = await getPkg(); | ||
t.is(pkg.name, result.name); | ||
t.is(pkg.version, result.version); | ||
}); | ||
|
||
test.serial('Throw error if missing package.json', async t => { | ||
const error = await t.throws(getPkg()); | ||
|
||
t.is(error.name, 'SemanticReleaseError'); | ||
t.is(error.code, 'ENOPKG'); | ||
}); | ||
|
||
test.serial('Throw error if missing package name', async t => { | ||
await writeJson('./package.json', {version: '0.0.0'}); | ||
|
||
const error = await t.throws(getPkg()); | ||
|
||
t.is(error.name, 'SemanticReleaseError'); | ||
t.is(error.code, 'ENOPKGNAME'); | ||
}); | ||
|
||
test.serial('Throw error if package.json is malformed', async t => { | ||
await writeFile('./package.json', "{name: 'package',}"); | ||
|
||
const error = await t.throws(getPkg()); | ||
|
||
t.is(error.name, 'JSONError'); | ||
}); |
This file was deleted.
Shouldn't this be
pkg.pkg
?