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

Commitf2e30c7

Browse files
committed
feat: usecwd andenv options passed by core
BREAKING CHANGE: require `semantic-release` >= `15.8.0`
1 parent14f9d11 commitf2e30c7

17 files changed

+453
-420
lines changed

‎index.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ async function verifyConditions(pluginConfig, context) {
2424
consterrors=verifyNpmConfig(pluginConfig);
2525

2626
try{
27-
constpkg=awaitgetPkg(pluginConfig.pkgRoot);
27+
constpkg=awaitgetPkg(pluginConfig,context);
2828

2929
// Verify the npm authentication only if `npmPublish` is not false and `pkg.private` is not `true`
3030
if(pluginConfig.npmPublish!==false&&pkg.private!==true){
31-
setLegacyToken();
31+
setLegacyToken(context);
3232
awaitverifyNpmAuth(pluginConfig,pkg,context);
3333
}
3434
}catch(err){
@@ -46,9 +46,9 @@ async function prepare(pluginConfig, context) {
4646

4747
try{
4848
// Reload package.json in case a previous external step updated it
49-
pkg=awaitgetPkg(pluginConfig.pkgRoot);
49+
pkg=awaitgetPkg(pluginConfig,context);
5050
if(!verified&&pluginConfig.npmPublish!==false&&pkg.private!==true){
51-
setLegacyToken();
51+
setLegacyToken(context);
5252
awaitverifyNpmAuth(pluginConfig,pkg,context);
5353
}
5454
}catch(err){
@@ -65,11 +65,11 @@ async function publish(pluginConfig, context) {
6565
letpkg;
6666
consterrors=verified ?[] :verifyNpmConfig(pluginConfig);
6767

68-
setLegacyToken();
68+
setLegacyToken(context);
6969

7070
try{
7171
// Reload package.json in case a previous external step updated it
72-
pkg=awaitgetPkg(pluginConfig.pkgRoot);
72+
pkg=awaitgetPkg(pluginConfig,context);
7373
if(!verified&&pluginConfig.npmPublish!==false&&pkg.private!==true){
7474
awaitverifyNpmAuth(pluginConfig,pkg,context);
7575
}

‎lib/get-pkg.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
constpath=require('path');
12
constreadPkg=require('read-pkg');
23
constAggregateError=require('aggregate-error');
34
constgetError=require('./get-error');
45

5-
module.exports=asyncpkgRoot=>{
6+
module.exports=async({pkgRoot},{cwd})=>{
67
consterrors=[];
78
letpkg;
89

910
try{
10-
pkg=awaitreadPkg({cwd:pkgRoot ?String(pkgRoot) :process.cwd()});
11+
pkg=awaitreadPkg({cwd:pkgRoot ?path.resolve(cwd,String(pkgRoot)) :cwd});
1112

1213
if(!pkg.name){
1314
errors.push(getError('ENOPKGNAME'));

‎lib/get-registry.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
constpath=require('path');
2+
constrc=require('rc');
13
constgetRegistryUrl=require('registry-auth-token/registry-url');
24

3-
module.exports=async({registry}={},name)=>(registry ?registry :getRegistryUrl(name.split('/')[0]));
5+
module.exports=({publishConfig:{registry}={}, name},{cwd})=>
6+
registry
7+
?registry
8+
:getRegistryUrl(
9+
name.split('/')[0],
10+
rc('npm',{registry:'https://registry.npmjs.org/'},{config:path.resolve(cwd,'.npmrc')})
11+
);

‎lib/get-release-info.js‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
constexeca=require('execa');
22
constnormalizeUrl=require('normalize-url');
33

4-
constDEFAULT_NPM_REGISTRY='https://registry.npmjs.org/';
5-
64
module.exports=async(
7-
name,
8-
publishConfig,
9-
registry,
10-
defaultRegistry=process.env.DEFAULT_NPM_REGISTRY||DEFAULT_NPM_REGISTRY
5+
{name,publishConfig:{tag}={}},
6+
{cwd,env:{DEFAULT_NPM_REGISTRY='https://registry.npmjs.org/', ...env}},
7+
registry
118
)=>{
12-
constdistTag=
13-
(publishConfig&&publishConfig.tag)||(awaitexeca.stdout('npm',['config','get','tag']))||'latest';
9+
constdistTag=tag||(awaitexeca.stdout('npm',['config','get','tag'],{cwd, env}))||'latest';
1410

1511
return{
1612
name:`npm package (@${distTag} dist-tag)`,
17-
url:normalizeUrl(registry)===normalizeUrl(defaultRegistry) ?`https://www.npmjs.com/package/${name}` :undefined,
13+
url:
14+
normalizeUrl(registry)===normalizeUrl(DEFAULT_NPM_REGISTRY)
15+
?`https://www.npmjs.com/package/${name}`
16+
:undefined,
1817
};
1918
};

‎lib/prepare.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const {move} = require('fs-extra');
33
constexeca=require('execa');
44
constupdatePackageVersion=require('./update-package-version');
55

6-
module.exports=async({tarballDir, pkgRoot},{nextRelease:{version}, logger})=>{
7-
constbasePath=pkgRoot||'.';
6+
module.exports=async({tarballDir, pkgRoot},{cwd,nextRelease:{version}, logger})=>{
7+
constbasePath=pkgRoot?path.resolve(cwd,pkgRoot) :cwd;
88
awaitupdatePackageVersion(version,basePath,logger);
99

1010
if(tarballDir){
1111
logger.log('Creating npm package version %s',version);
12-
consttarball=(awaitexeca.stdout('npm',['pack',`./${basePath}`])).split('\n').pop();
13-
awaitmove(tarball,path.join(tarballDir.trim(),tarball));
12+
consttarball=(awaitexeca.stdout('npm',['pack',basePath],{cwd})).split('\n').pop();
13+
awaitmove(path.resolve(cwd,tarball),path.resolve(cwd,tarballDir.trim(),tarball));
1414
}
1515
};

‎lib/publish.js‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
constpath=require('path');
12
constexeca=require('execa');
23
constgetRegistry=require('./get-registry');
34
constgetReleaseInfo=require('./get-release-info');
45

5-
module.exports=async(
6-
{npmPublish, pkgRoot},
7-
{publishConfig, name,private:priv},
8-
{nextRelease:{version}, logger}
9-
)=>{
10-
if(npmPublish!==false&&priv!==true){
11-
constbasePath=pkgRoot||'.';
12-
constregistry=awaitgetRegistry(publishConfig,name);
6+
module.exports=async({npmPublish, pkgRoot},pkg,context)=>{
7+
const{
8+
cwd,
9+
env,
10+
nextRelease:{version},
11+
logger,
12+
}=context;
13+
14+
if(npmPublish!==false&&pkg.private!==true){
15+
constbasePath=pkgRoot ?path.resolve(cwd,pkgRoot) :cwd;
16+
constregistry=getRegistry(pkg,context);
1317

1418
logger.log('Publishing version %s to npm registry',version);
15-
constshell=awaitexeca('npm',['publish',`./${basePath}`,'--registry',registry]);
19+
constshell=awaitexeca('npm',['publish',basePath,'--registry',registry],{cwd, env});
1620

17-
process.stdout.write(shell.stdout);
18-
returngetReleaseInfo(name,publishConfig,registry);
21+
logger.stdout(shell.stdout);
22+
returngetReleaseInfo(pkg,context,registry);
1923
}
2024
logger.log(
2125
'Skip publishing to npm registry as %s is %s',

‎lib/set-legacy-token.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
module.exports=()=>{
1+
module.exports=({env})=>{
22
// Set the environment variable `LEGACY_TOKEN` when user use the legacy auth, so it can be resolved by npm CLI
3-
if(process.env.NPM_USERNAME&&process.env.NPM_PASSWORD&&process.env.NPM_EMAIL){
4-
process.env.LEGACY_TOKEN=Buffer.from(`${process.env.NPM_USERNAME}:${process.env.NPM_PASSWORD}`,'utf8').toString(
5-
'base64'
6-
);
3+
if(env.NPM_USERNAME&&env.NPM_PASSWORD&&env.NPM_EMAIL){
4+
env.LEGACY_TOKEN=Buffer.from(`${env.NPM_USERNAME}:${env.NPM_PASSWORD}`,'utf8').toString('base64');
75
}
86
};

‎lib/set-npmrc-auth.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
constpath=require('path');
2+
constrc=require('rc');
13
const{appendFile}=require('fs-extra');
24
constgetAuthToken=require('registry-auth-token');
35
constnerfDart=require('nerf-dart');
46
constAggregateError=require('aggregate-error');
57
constgetError=require('./get-error');
68

7-
module.exports=async(registry,logger)=>{
9+
module.exports=async(registry,{cwd,env:{NPM_TOKEN,NPM_USERNAME,NPM_PASSWORD,NPM_EMAIL},logger})=>{
810
logger.log('Verify authentication for registry %s',registry);
9-
const{NPM_TOKEN,NPM_USERNAME,NPM_PASSWORD,NPM_EMAIL}=process.env;
10-
11-
if(getAuthToken(registry)){
11+
constconfig=path.resolve(cwd,'.npmrc');
12+
if(getAuthToken(registry,{npmrc:rc('npm',{registry:'https://registry.npmjs.org/'},{config})})){
1213
return;
1314
}
1415
if(NPM_USERNAME&&NPM_PASSWORD&&NPM_EMAIL){
15-
awaitappendFile('./.npmrc',`\n_auth =${Buffer.from(`\${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`)}`);
16-
logger.log('Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to.npmrc.');
16+
awaitappendFile(config,`\n_auth =${Buffer.from(`\${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`)}`);
17+
logger.log(`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to${config}`);
1718
}elseif(NPM_TOKEN){
18-
awaitappendFile('./.npmrc',`\n${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`);
19-
logger.log('Wrote NPM_TOKEN to.npmrc.');
19+
awaitappendFile(config,`\n${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`);
20+
logger.log(`Wrote NPM_TOKEN to${config}`);
2021
}else{
2122
thrownewAggregateError([getError('ENONPMTOKEN',{registry})]);
2223
}

‎lib/update-package-version.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const DEFAULT_INDENT = 2;
88
constDEFAULT_NEWLINE='\n';
99

1010
module.exports=async(version,basePath,logger)=>{
11-
constpackagePath=path.join(basePath,'package.json');
12-
constshrinkwrapPath=path.join(basePath,'npm-shrinkwrap.json');
13-
constpackageLockPath=path.join(basePath,'package-lock.json');
11+
constpackagePath=path.resolve(basePath,'package.json');
12+
constshrinkwrapPath=path.resolve(basePath,'npm-shrinkwrap.json');
13+
constpackageLockPath=path.resolve(basePath,'package-lock.json');
1414
constpkg=awaitreadFile(packagePath,'utf8');
1515

1616
awaitwriteJson(packagePath,{...parseJson(pkg), ...{version}},getWriteOptions(pkg));

‎lib/verify-auth.js‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ const getError = require('./get-error');
55
constgetRegistry=require('./get-registry');
66
constsetNpmrcAuth=require('./set-npmrc-auth');
77

8-
constDEFAULT_NPM_REGISTRY='https://registry.npmjs.org/';
8+
module.exports=async(pluginConfig,pkg,context)=>{
9+
const{
10+
cwd,
11+
env:{DEFAULT_NPM_REGISTRY='https://registry.npmjs.org/', ...env},
12+
}=context;
13+
constregistry=getRegistry(pkg,context);
914

10-
module.exports=async(
11-
pluginConfig,
12-
{publishConfig, name},
13-
{logger},
14-
defaultRegistry=process.env.DEFAULT_NPM_REGISTRY||DEFAULT_NPM_REGISTRY
15-
)=>{
16-
constregistry=awaitgetRegistry(publishConfig,name);
17-
awaitsetNpmrcAuth(registry,logger);
15+
awaitsetNpmrcAuth(registry,context);
1816

19-
if(normalizeUrl(registry)===normalizeUrl(defaultRegistry)){
17+
if(normalizeUrl(registry)===normalizeUrl(DEFAULT_NPM_REGISTRY)){
2018
try{
21-
awaitexeca('npm',['whoami','--registry',registry]);
19+
awaitexeca('npm',['whoami','--registry',registry],{cwd, env});
2220
}catch(err){
2321
thrownewAggregateError([getError('EINVALIDNPMTOKEN',{registry})]);
2422
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp