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

Commitfb96126

Browse files
committed
feat: addaddChannel plugin step
1 parentb8deba7 commitfb96126

File tree

9 files changed

+304
-20
lines changed

9 files changed

+304
-20
lines changed

‎README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
[![npm latest version](https://img.shields.io/npm/v/@semantic-release/npm/latest.svg)](https://www.npmjs.com/package/@semantic-release/npm)
1010
[![npm next version](https://img.shields.io/npm/v/@semantic-release/npm/next.svg)](https://www.npmjs.com/package/@semantic-release/npm)
1111

12-
| Step| Description|
13-
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
14-
|`verifyConditions`| Verify the presence of the`NPM_TOKEN` environment variable, create or update the`.npmrc` file with the token and verify the token is valid.|
15-
|`prepare`| Update the`package.json` version and[create](https://docs.npmjs.com/cli/pack) the npm package tarball.|
16-
|`publish`|[Publish the npm package](https://docs.npmjs.com/cli/publish) to the registry.|
12+
| Step| Description||
13+
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
14+
|`verifyConditions`| Verify the presence of the`NPM_TOKEN` environment variable, create or update the`.npmrc` file with the token and verify the token is valid.||
15+
|`prepare`| Update the`package.json` version and[create](https://docs.npmjs.com/cli/pack) the npm package tarball.||
16+
|`addChannel`||[Add a release to a dist-tag](https://docs.npmjs.com/cli/dist-tag).|
17+
|`publish`|[Publish the npm package](https://docs.npmjs.com/cli/publish) to the registry.||
1718

1819
##Install
1920

‎index.js‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const setLegacyToken = require('./lib/set-legacy-token');
44
constgetPkg=require('./lib/get-pkg');
55
constverifyNpmConfig=require('./lib/verify-config');
66
constverifyNpmAuth=require('./lib/verify-auth');
7+
constaddChannelNpm=require('./lib/add-channel');
78
constprepareNpm=require('./lib/prepare');
89
constpublishNpm=require('./lib/publish');
910

@@ -87,4 +88,27 @@ async function publish(pluginConfig, context) {
8788
returnpublishNpm(pluginConfig,pkg,context);
8889
}
8990

90-
module.exports={verifyConditions, prepare, publish};
91+
asyncfunctionaddChannel(pluginConfig,context){
92+
letpkg;
93+
consterrors=verified ?[] :verifyNpmConfig(pluginConfig);
94+
95+
setLegacyToken(context);
96+
97+
try{
98+
// Reload package.json in case a previous external step updated it
99+
pkg=awaitgetPkg(pluginConfig,context);
100+
if(!verified&&pluginConfig.npmPublish!==false&&pkg.private!==true){
101+
awaitverifyNpmAuth(pluginConfig,pkg,context);
102+
}
103+
}catch(error){
104+
errors.push(...error);
105+
}
106+
107+
if(errors.length>0){
108+
thrownewAggregateError(errors);
109+
}
110+
111+
returnaddChannelNpm(pluginConfig,pkg,context);
112+
}
113+
114+
module.exports={verifyConditions, prepare, publish, addChannel};

‎lib/add-channel.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
constexeca=require('execa');
2+
constgetRegistry=require('./get-registry');
3+
constgetChannel=require('./get-channel');
4+
constgetReleaseInfo=require('./get-release-info');
5+
6+
module.exports=async({npmPublish},pkg,context)=>{
7+
const{
8+
cwd,
9+
env,
10+
stdout,
11+
stderr,
12+
nextRelease:{version, channel},
13+
logger,
14+
}=context;
15+
16+
if(npmPublish!==false&&pkg.private!==true){
17+
constregistry=getRegistry(pkg,context);
18+
constdistTag=getChannel(channel);
19+
20+
logger.log(`Adding version${version} to npm registry on dist-tag${distTag}`);
21+
constresult=execa('npm',['dist-tag','add',`${pkg.name}@${version}`,distTag,'--registry',registry],{
22+
cwd,
23+
env,
24+
});
25+
result.stdout.pipe(
26+
stdout,
27+
{end:false}
28+
);
29+
result.stderr.pipe(
30+
stderr,
31+
{end:false}
32+
);
33+
awaitresult;
34+
35+
logger.log(`Published${pkg.name}@${version} on${registry}`);
36+
37+
returngetReleaseInfo(pkg,context,distTag,registry);
38+
}
39+
40+
logger.log(
41+
`Skip adding to npm channel as${
42+
npmPublish===false ?'npmPublish' :"package.json's private property"
43+
} is${npmPublish!==false}`
44+
);
45+
};

‎lib/get-release-info.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
constnormalizeUrl=require('normalize-url');
22

3-
module.exports=async({name},{env:{DEFAULT_NPM_REGISTRY='https://registry.npmjs.org/'}},distTag,registry)=>({
3+
module.exports=({name},{env:{DEFAULT_NPM_REGISTRY='https://registry.npmjs.org/'}},distTag,registry)=>({
44
name:`npm package (@${distTag} dist-tag)`,
55
url:
66
normalizeUrl(registry)===normalizeUrl(DEFAULT_NPM_REGISTRY) ?`https://www.npmjs.com/package/${name}` :undefined,
7+
channel:distTag,
78
});

‎lib/prepare.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ module.exports = async ({tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRe
77

88
logger.log('Write version %s to package.json in %s',version,basePath);
99

10-
constversionResult=execa('npm',['version',version,'--no-git-tag-version'],{cwd:basePath, env});
10+
constversionResult=execa('npm',['version',version,'--no-git-tag-version','--allow-same-version'],{
11+
cwd:basePath,
12+
env,
13+
});
1114
versionResult.stdout.pipe(
1215
stdout,
1316
{end:false}

‎lib/publish.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async ({npmPublish, pkgRoot}, pkg, context) => {
1919
constregistry=getRegistry(pkg,context);
2020
constdistTag=getChannel(channel);
2121

22-
logger.log('Publishing version%s to npm registry',version);
22+
logger.log(`Publishing version${version} to npm registry`);
2323
constresult=execa('npm',['publish',basePath,'--tag',distTag,'--registry',registry],{
2424
cwd,
2525
env,
@@ -34,11 +34,14 @@ module.exports = async ({npmPublish, pkgRoot}, pkg, context) => {
3434
);
3535
awaitresult;
3636

37-
logger.log(`Published${pkg.name}@${pkg.version} on${registry}`);
37+
logger.log(`Published${pkg.name}@${version} to${registry}`);
38+
3839
returngetReleaseInfo(pkg,context,distTag,registry);
3940
}
41+
4042
logger.log(
41-
'Skip publishing to npm registry as %s is %s',
42-
...(npmPublish===false ?['npmPublish',false] :["package.json's private property",true])
43+
`Skip publishing to npm registry as${
44+
npmPublish===false ?'npmPublish' :"package.json's private property"
45+
} is${npmPublish!==false}`
4346
);
4447
};

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"all":true
8080
},
8181
"peerDependencies": {
82-
"semantic-release":">=15.9.0 <16.0.0"
82+
"semantic-release":">=15.9.0 <17.0.0"
8383
},
8484
"prettier": {
8585
"printWidth":120,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ test('Default registry and scoped module', async t => {
55
t.deepEqual(awaitgetReleaseInfo({name:'@scope/module'},{env:{}},'latest','https://registry.npmjs.org/'),{
66
name:'npm package (@latest dist-tag)',
77
url:'https://www.npmjs.com/package/@scope/module',
8+
channel:'latest',
89
});
910
});
1011

1112
test('Custom registry and scoped module',asynct=>{
1213
t.deepEqual(awaitgetReleaseInfo({name:'@scope/module'},{env:{}},'latest','https://custom.registry.org/'),{
1314
name:'npm package (@latest dist-tag)',
1415
url:undefined,
16+
channel:'latest',
1517
});
1618
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp