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

Commit3c975df

Browse files
committed
feat: verifypackage.json has aversion property
1 parent6123e84 commit3c975df

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

‎lib/get-pkg.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ const SemanticReleaseError = require('@semantic-release/error');
44
module.exports=asyncpkgRoot=>{
55
try{
66
constpkg=awaitreadPkg(pkgRoot);
7+
78
if(!pkg.name){
89
thrownewSemanticReleaseError('No "name" found in package.json.','ENOPKGNAME');
910
}
1011

12+
if(!pkg.version){
13+
thrownewSemanticReleaseError('No "version" found in package.json.','ENOPKGVERSION');
14+
}
15+
1116
returnpkg;
1217
}catch(err){
1318
if(err.code==='ENOENT'){

‎test/get-pkg.test.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test.afterEach.always(() => {
1616
process.chdir(cwd);
1717
});
1818

19-
test.serial('Verify name and return parsed package.json',asynct=>{
19+
test.serial('Verify name andversion thenreturn parsed package.json',asynct=>{
2020
constpkg={name:'package',version:'0.0.0'};
2121
awaitoutputJson('./package.json',pkg);
2222

@@ -25,7 +25,7 @@ test.serial('Verify name and return parsed package.json', async t => {
2525
t.is(pkg.version,result.version);
2626
});
2727

28-
test.serial('Verify name and return parsed package.json from a sub-directory',asynct=>{
28+
test.serial('Verify name andversion thenreturn parsed package.json from a sub-directory',asynct=>{
2929
constpkg={name:'package',version:'0.0.0'};
3030
awaitoutputJson('./dist/package.json',pkg);
3131

@@ -50,6 +50,15 @@ test.serial('Throw error if missing package name', async t => {
5050
t.is(error.code,'ENOPKGNAME');
5151
});
5252

53+
test.serial('Throw error if missing package version',asynct=>{
54+
awaitoutputJson('./package.json',{name:'package'});
55+
56+
consterror=awaitt.throws(getPkg());
57+
58+
t.is(error.name,'SemanticReleaseError');
59+
t.is(error.code,'ENOPKGVERSION');
60+
});
61+
5362
test.serial('Throw error if package.json is malformed',asynct=>{
5463
awaitwriteFile('./package.json',"{name: 'package',}");
5564

‎test/integration.test.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test.serial(
116116

117117
test.serial('Verify npm auth and package',asynct=>{
118118
Object.assign(process.env,npmRegistry.authEnv);
119-
constpkg={name:'valid-token',publishConfig:{registry:npmRegistry.url}};
119+
constpkg={name:'valid-token',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
120120
awaitoutputJson('./package.json',pkg);
121121
awaitt.notThrows(t.context.m.verifyConditions({},{options:{},logger:t.context.logger}));
122122

@@ -127,7 +127,7 @@ test.serial('Verify npm auth and package', async t => {
127127

128128
test.serial('Verify npm auth and package from a sub-directory',asynct=>{
129129
Object.assign(process.env,npmRegistry.authEnv);
130-
constpkg={name:'valid-token',publishConfig:{registry:npmRegistry.url}};
130+
constpkg={name:'valid-token',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
131131
awaitoutputJson('./dist/package.json',pkg);
132132
awaitt.notThrows(t.context.m.verifyConditions({pkgRoot:'dist'},{options:{},logger:t.context.logger}));
133133

@@ -139,7 +139,7 @@ test.serial('Verify npm auth and package from a sub-directory', async t => {
139139
test.serial('Verify npm auth and package with "npm_config_registry" env var set by yarn',asynct=>{
140140
Object.assign(process.env,npmRegistry.authEnv);
141141
process.env.npm_config_registry='https://registry.yarnpkg.com';// eslint-disable-line camelcase
142-
constpkg={name:'valid-token',publishConfig:{registry:npmRegistry.url}};
142+
constpkg={name:'valid-token',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
143143
awaitoutputJson('./package.json',pkg);
144144
awaitt.notThrows(t.context.m.verifyConditions({},{options:{},logger:t.context.logger}));
145145

@@ -150,7 +150,7 @@ test.serial('Verify npm auth and package with "npm_config_registry" env var set
150150

151151
test.serial('Return nothing if no version if published',asynct=>{
152152
Object.assign(process.env,npmRegistry.authEnv);
153-
constpkg={name:'not-published',publishConfig:{registry:npmRegistry.url}};
153+
constpkg={name:'not-published',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
154154
awaitoutputJson('./package.json',pkg);
155155
constnextRelease=awaitt.context.m.getLastRelease({},{options:{},logger:t.context.logger});
156156

@@ -243,7 +243,7 @@ test('Throw SemanticReleaseError if publish "pkgRoot" option in getLastRelease i
243243
});
244244

245245
test('Throw SemanticReleaseError if publish "npmPublish" option in verifyConditions is not a Boolean',asynct=>{
246-
constpkg={name:'invalid-npmPublish',publishConfig:{registry:npmRegistry.url}};
246+
constpkg={name:'invalid-npmPublish',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
247247
awaitoutputJson('./package.json',pkg);
248248
constnpmPublish=42;
249249
consterror=awaitt.throws(
@@ -261,7 +261,7 @@ test('Throw SemanticReleaseError if publish "npmPublish" option in verifyConditi
261261
});
262262

263263
test('Throw SemanticReleaseError if publish "tarballDir" option in verifyConditions is not a String',asynct=>{
264-
constpkg={name:'invalid-tarballDir',publishConfig:{registry:npmRegistry.url}};
264+
constpkg={name:'invalid-tarballDir',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
265265
awaitoutputJson('./package.json',pkg);
266266
consttarballDir=42;
267267
consterror=awaitt.throws(
@@ -279,7 +279,7 @@ test('Throw SemanticReleaseError if publish "tarballDir" option in verifyConditi
279279
});
280280

281281
test('Throw SemanticReleaseError if publish "pkgRoot" option in verifyConditions is not a String',asynct=>{
282-
constpkg={name:'invalid-pkgRoot',publishConfig:{registry:npmRegistry.url}};
282+
constpkg={name:'invalid-pkgRoot',version:'0.0.0-dev',publishConfig:{registry:npmRegistry.url}};
283283
awaitoutputJson('./dist/package.json',pkg);
284284
constpkgRoot=42;
285285
consterror=awaitt.throws(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp