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

Commit755356b

Browse files
pvdlggr2m
authored andcommitted
feat: return release informations frompublish hook
1 parentc2c59ab commit755356b

File tree

5 files changed

+122
-6
lines changed

5 files changed

+122
-6
lines changed

‎index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function publish(pluginConfig, {nextRelease: {version}, logger}) {
4444
}
4545
verified=true;
4646
}
47-
awaitpublishNpm(pluginConfig,pkg,version,logger);
47+
returnpublishNpm(pluginConfig,pkg,version,logger);
4848
}
4949

5050
module.exports={verifyConditions, publish};

‎lib/get-release-info.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
constexeca=require('execa');
2+
constnormalizeUrl=require('normalize-url');
3+
4+
constDEFAULT_NPM_REGISTRY='https://registry.npmjs.org/';
5+
6+
module.exports=async(
7+
name,
8+
publishConfig,
9+
registry,
10+
defaultRegistry=process.env.DEFAULT_NPM_REGISTRY||DEFAULT_NPM_REGISTRY
11+
)=>{
12+
constdistTag=
13+
(publishConfig&&publishConfig.tag)||(awaitexeca.stdout('npm',['config','get','tag']))||'latest';
14+
15+
return{
16+
name:`npm package (@${distTag} dist-tag)`,
17+
url:normalizeUrl(registry)===normalizeUrl(defaultRegistry) ?`https://www.npmjs.com/package/${name}` :undefined,
18+
};
19+
};

‎lib/publish.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const {move} = require('fs-extra');
33
constexeca=require('execa');
44
constgetRegistry=require('./get-registry');
55
constupdatePackageVersion=require('./update-package-version');
6+
constgetReleaseInfo=require('./get-release-info.js');
67

78
module.exports=async({npmPublish, tarballDir, pkgRoot},{publishConfig, name},version,logger)=>{
89
constbasePath=pkgRoot||'.';
@@ -20,4 +21,6 @@ module.exports = async ({npmPublish, tarballDir, pkgRoot}, {publishConfig, name}
2021
constshell=awaitexeca('npm',['publish',`./${basePath}`,'--registry',registry]);
2122
process.stdout.write(shell.stdout);
2223
}
24+
25+
returngetReleaseInfo(name,publishConfig,registry);
2326
};

‎test/get-release-info.test.js‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import{writeFile}from'fs-extra';
2+
importtestfrom'ava';
3+
importtempyfrom'tempy';
4+
importgetReleaseInfofrom'../lib/get-release-info';
5+
6+
// Save the current process.env
7+
constenvBackup=Object.assign({},process.env);
8+
// Save the current working diretory
9+
constcwd=process.cwd();
10+
11+
test.beforeEach(()=>{
12+
// Change current working directory to a temp directory
13+
process.chdir(tempy.directory());
14+
// Delete all `npm_config` environment variable set by CI as they take precedence over the `.npmrc` because the process that runs the tests is started before the `.npmrc` is created
15+
for(leti=0,keys=Object.keys(process.env);i<keys.length;i++){
16+
if(keys[i].startsWith('npm_')){
17+
deleteprocess.env[keys[i]];
18+
}
19+
}
20+
});
21+
22+
test.afterEach.always(()=>{
23+
// Restore process.env
24+
process.env=envBackup;
25+
// Restore the current working directory
26+
process.chdir(cwd);
27+
});
28+
29+
test.serial('Default registry and tag',asynct=>{
30+
t.deepEqual(awaitgetReleaseInfo('module',null,'https://registry.npmjs.org/'),{
31+
name:'npm package (@latest dist-tag)',
32+
url:'https://www.npmjs.com/package/module',
33+
});
34+
});
35+
36+
test.serial('Default registry, tag and scoped module',asynct=>{
37+
t.deepEqual(awaitgetReleaseInfo('@scope/module',null,'https://registry.npmjs.org/'),{
38+
name:'npm package (@latest dist-tag)',
39+
url:'https://www.npmjs.com/package/@scope/module',
40+
});
41+
});
42+
43+
test.serial('Custom registry, tag and scoped module',asynct=>{
44+
t.deepEqual(awaitgetReleaseInfo('@scope/module',null,'https://custom.registry.org/'),{
45+
name:'npm package (@latest dist-tag)',
46+
url:undefined,
47+
});
48+
});
49+
50+
test.serial('Default registry and tag from .npmrc',asynct=>{
51+
awaitwriteFile('./.npmrc','tag=npmrc');
52+
t.deepEqual(awaitgetReleaseInfo('module',{},'https://registry.npmjs.org/'),{
53+
name:'npm package (@npmrc dist-tag)',
54+
url:'https://www.npmjs.com/package/module',
55+
});
56+
});
57+
58+
test.serial('Default registry and tag from package.json',asynct=>{
59+
awaitwriteFile('./.npmrc','tag=npmrc');
60+
t.deepEqual(awaitgetReleaseInfo('module',{tag:'pkg'},'https://registry.npmjs.org/'),{
61+
name:'npm package (@pkg dist-tag)',
62+
url:'https://www.npmjs.com/package/module',
63+
});
64+
});
65+
66+
test.serial('Default tag',asynct=>{
67+
awaitwriteFile('./.npmrc','tag=');
68+
t.deepEqual(awaitgetReleaseInfo('module',{},'https://registry.npmjs.org/'),{
69+
name:'npm package (@latest dist-tag)',
70+
url:'https://www.npmjs.com/package/module',
71+
});
72+
});

‎test/integration.test.js‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,23 @@ test.serial('Publish the package', async t => {
181181
constpkg={name:'publish',version:'0.0.0',publishConfig:{registry:npmRegistry.url}};
182182
awaitoutputJson('./package.json',pkg);
183183

184-
awaitt.context.m.publish({},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
184+
constresult=awaitt.context.m.publish({},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
185185

186+
t.deepEqual(result,{name:'npm package (@latest dist-tag)',url:undefined});
187+
t.is((awaitreadJson('./package.json')).version,'1.0.0');
188+
t.false(awaitpathExists(`./${pkg.name}-1.0.0.tgz`));
189+
t.is((awaitexeca('npm',['view',pkg.name,'version'])).stdout,'1.0.0');
190+
});
191+
192+
test.serial('Publish the package on a dist-tag',asynct=>{
193+
Object.assign(process.env,npmRegistry.authEnv);
194+
process.env.DEFAULT_NPM_REGISTRY=npmRegistry.url;
195+
constpkg={name:'publish-tag',version:'0.0.0',publishConfig:{registry:npmRegistry.url,tag:'next'}};
196+
awaitoutputJson('./package.json',pkg);
197+
198+
constresult=awaitt.context.m.publish({},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
199+
200+
t.deepEqual(result,{name:'npm package (@next dist-tag)',url:'https://www.npmjs.com/package/publish-tag'});
186201
t.is((awaitreadJson('./package.json')).version,'1.0.0');
187202
t.false(awaitpathExists(`./${pkg.name}-1.0.0.tgz`));
188203
t.is((awaitexeca('npm',['view',pkg.name,'version'])).stdout,'1.0.0');
@@ -193,8 +208,12 @@ test.serial('Publish the package from a sub-directory', async t => {
193208
constpkg={name:'publish-sub-dir',version:'0.0.0',publishConfig:{registry:npmRegistry.url}};
194209
awaitoutputJson('./dist/package.json',pkg);
195210

196-
awaitt.context.m.publish({pkgRoot:'dist'},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
211+
constresult=awaitt.context.m.publish(
212+
{pkgRoot:'dist'},
213+
{logger:t.context.logger,nextRelease:{version:'1.0.0'}}
214+
);
197215

216+
t.deepEqual(result,{name:'npm package (@latest dist-tag)',url:undefined});
198217
t.is((awaitreadJson('./dist/package.json')).version,'1.0.0');
199218
t.false(awaitpathExists(`./${pkg.name}-1.0.0.tgz`));
200219
t.is((awaitexeca('npm',['view',pkg.name,'version'])).stdout,'1.0.0');
@@ -211,11 +230,12 @@ test.serial('Create the package and skip publish', async t => {
211230
constpkg={name:'skip-publish',version:'0.0.0',publishConfig:{registry:npmRegistry.url}};
212231
awaitoutputJson('./package.json',pkg);
213232

214-
awaitt.context.m.publish(
233+
constresult=awaitt.context.m.publish(
215234
{npmPublish:false,tarballDir:'tarball'},
216235
{logger:t.context.logger,nextRelease:{version:'1.0.0'}}
217236
);
218237

238+
t.deepEqual(result,{name:'npm package (@latest dist-tag)',url:undefined});
219239
t.is((awaitreadJson('./package.json')).version,'1.0.0');
220240
t.true(awaitpathExists(`./tarball/${pkg.name}-1.0.0.tgz`));
221241
awaitt.throws(execa('npm',['view',pkg.name,'version']));
@@ -226,11 +246,12 @@ test.serial('Create the package and skip publish from a sub-directory', async t
226246
constpkg={name:'skip-publish-sub-dir',version:'0.0.0',publishConfig:{registry:npmRegistry.url}};
227247
awaitoutputJson('./dist/package.json',pkg);
228248

229-
awaitt.context.m.publish(
249+
constresult=awaitt.context.m.publish(
230250
{npmPublish:false,tarballDir:'./tarball',pkgRoot:'./dist'},
231251
{logger:t.context.logger,nextRelease:{version:'1.0.0'}}
232252
);
233253

254+
t.deepEqual(result,{name:'npm package (@latest dist-tag)',url:undefined});
234255
t.is((awaitreadJson('./dist/package.json')).version,'1.0.0');
235256
t.true(awaitpathExists(`./tarball/${pkg.name}-1.0.0.tgz`));
236257
awaitt.throws(execa('npm',['view',pkg.name,'version']));
@@ -243,5 +264,6 @@ test.serial('Verify token and set up auth only on the fist call', async t => {
243264

244265
awaitt.notThrows(t.context.m.verifyConditions({},{options:{},logger:t.context.logger}));
245266

246-
awaitt.context.m.publish({},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
267+
constresult=awaitt.context.m.publish({},{logger:t.context.logger,nextRelease:{version:'1.0.0'}});
268+
t.deepEqual(result,{name:'npm package (@latest dist-tag)',url:undefined});
247269
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp