Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb14d34d

Browse files
pvdlggr2m
authored andcommitted
feat: adddetails to error messages
1 parenteda41f0 commitb14d34d

File tree

6 files changed

+69
-14
lines changed

6 files changed

+69
-14
lines changed

‎lib/definitions/errors.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
consturl=require('url');
2+
constpkg=require('../../package.json');
3+
4+
consthomepage=url.format({...url.parse(pkg.homepage), ...{hash:null}});
5+
constlinkify=file=>`${homepage}/blob/master/${file}`;
6+
7+
module.exports={
8+
EINVALIDNPMPUBLISH:({npmPublish})=>({
9+
message:'Invalid `npmPublish` option.',
10+
details:`The [npmPublish option](${linkify('README.md#npmpublish')}) option, if defined, must be a \`Boolean\`.
11+
12+
Your configuration for the \`npmPublish\` option is \`${npmPublish}\`.`,
13+
}),
14+
EINVALIDTARBALLDIR:({tarballDir})=>({
15+
message:'Invalid `tarballDir` option.',
16+
details:`The [tarballDir option](${linkify('README.md#tarballdir')}) option, if defined, must be a \`String\`.
17+
18+
Your configuration for the \`tarballDir\` option is \`${tarballDir}\`.`,
19+
}),
20+
EINVALIDPKGROOT:({pkgRoot})=>({
21+
message:'Invalid `pkgRoot` option.',
22+
details:`The [pkgRoot option](${linkify('README.md#pkgroot')}) option, if defined, must be a \`String\`.
23+
24+
Your configuration for the \`pkgRoot\` option is \`${pkgRoot}\`.`,
25+
}),
26+
EINVALIDNPMTOKEN:({registry})=>({
27+
message:'Invalid npm token.',
28+
details:`The [npm token](${linkify(
29+
'README.md#npm-registry-authentication'
30+
)}) configured in the \`NPM_TOKEN\` environment variable must be a valid [token](https://docs.npmjs.com/getting-started/working_with_tokens) allowing to publish to the registry \`${registry}\`.
31+
32+
If you are using Two-Factor Authentication, make configure the \`auth-only\` [level](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported. **semantic-release** cannot publish with the default \`auth-and-writes\` level.
33+
34+
Please make sure to set the \`NPM_TOKEN\` environment variable in your CI with the exact value of the npm token.`,
35+
}),
36+
37+
ENOPKGNAME:()=>({
38+
message:'Missing `name` property in `package.json`.',
39+
details:`The \`package.json\`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish a package to the npm registry.
40+
41+
Please make sure to add a valid \`name\` for your package in your \`package.json\`.`,
42+
}),
43+
ENOPKG:()=>({
44+
message:'Missing `package.json` file.',
45+
details:`A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to release on npm.
46+
47+
Please follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid \`pacakge.json\` file.`,
48+
}),
49+
};

‎lib/get-error.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
constSemanticReleaseError=require('@semantic-release/error');
2+
constERROR_DEFINITIONS=require('./definitions/errors');
3+
4+
module.exports=(code,ctx={})=>{
5+
const{message, details}=ERROR_DEFINITIONS[code](ctx);
6+
returnnewSemanticReleaseError(message,code,details);
7+
};

‎lib/get-pkg.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
constreadPkg=require('read-pkg');
22
constAggregateError=require('aggregate-error');
3-
constSemanticReleaseError=require('@semantic-release/error');
3+
constgetError=require('./get-error');
44

55
module.exports=asyncpkgRoot=>{
66
consterrors=[];
@@ -10,17 +10,19 @@ module.exports = async pkgRoot => {
1010
pkg=awaitreadPkg(pkgRoot);
1111

1212
if(!pkg.name){
13-
errors.push(newSemanticReleaseError('No "name" found in package.json.','ENOPKGNAME'));
13+
errors.push(getError('ENOPKGNAME'));
1414
}
1515
}catch(err){
1616
if(err.code==='ENOENT'){
17-
errors.push(newSemanticReleaseError('A package.json file is required to release on npm.','ENOPKG'));
17+
errors.push(getError('ENOPKG'));
1818
}else{
1919
errors.push(err);
2020
}
2121
}
22+
2223
if(errors.length>0){
2324
thrownewAggregateError(errors);
2425
}
26+
2527
returnpkg;
2628
};

‎lib/verify-auth.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
constexeca=require('execa');
22
constnormalizeUrl=require('normalize-url');
33
constAggregateError=require('aggregate-error');
4-
constSemanticReleaseError=require('@semantic-release/error');
4+
constgetError=require('./get-error');
55
constgetRegistry=require('./get-registry');
66
constsetNpmrcAuth=require('./set-npmrc-auth');
77

@@ -20,7 +20,7 @@ module.exports = async (
2020
try{
2121
awaitexeca('npm',['whoami','--registry',registry]);
2222
}catch(err){
23-
thrownewAggregateError([newSemanticReleaseError('Invalid npm token.','EINVALIDNPMTOKEN')]);
23+
thrownewAggregateError([getError('EINVALIDNPMTOKEN',{registry})]);
2424
}
2525
}
2626
};

‎lib/verify-config.js‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
const{isString, isUndefined, isBoolean}=require('lodash');
2-
constSemanticReleaseError=require('@semantic-release/error');
2+
constgetError=require('./get-error');
33

44
module.exports=({npmPublish, tarballDir, pkgRoot})=>{
55
consterrors=[];
66
if(!isUndefined(npmPublish)&&!isBoolean(npmPublish)){
7-
errors.push(
8-
newSemanticReleaseError('The "npmPublish" options, if defined, must be a Boolean.','EINVALIDNPMPUBLISH')
9-
);
7+
errors.push(getError('EINVALIDNPMPUBLISH',{npmPublish}));
108
}
119

1210
if(!isUndefined(tarballDir)&&!isString(tarballDir)){
13-
errors.push(
14-
newSemanticReleaseError('The "tarballDir" options, if defined, must be a String.','EINVALIDTARBALLDIR')
15-
);
11+
errors.push(getError('EINVALIDTARBALLDIR',{tarballDir}));
1612
}
1713

1814
if(!isUndefined(pkgRoot)&&!isString(pkgRoot)){
19-
errors.push(newSemanticReleaseError('The "pkgRoot" options, if defined, must be a String.','EINVALIDPKGROOT'));
15+
errors.push(getError('EINVALIDPKGROOT',{pkgRoot}));
2016
}
17+
2118
returnerrors;
2219
};

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Gregor Martynus (https://twitter.com/gr2m)"
1717
],
1818
"dependencies": {
19-
"@semantic-release/error":"^2.1.0",
19+
"@semantic-release/error":"^2.2.0",
2020
"aggregate-error":"^1.0.0",
2121
"execa":"^0.9.0",
2222
"fs-extra":"^5.0.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp