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

Commit2d8ff15

Browse files
travigr2m
authored andcommitted
refactor(esm): converted the package to esm
BREAKING CHANGE: `@semantic-release/npm` is now a native ES Module. Ithas named exports for each plugin hook (`verifyConditions`, `prepare`,`publish`, `addChannel`)
1 parent7157d76 commit2d8ff15

25 files changed

+2363
-4443
lines changed

‎index.js‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
const{defaultTo, castArray}=require('lodash');
2-
constAggregateError=require('aggregate-error');
3-
consttempy=require('tempy');
4-
constsetLegacyToken=require('./lib/set-legacy-token');
5-
constgetPkg=require('./lib/get-pkg');
6-
constverifyNpmConfig=require('./lib/verify-config');
7-
constverifyNpmAuth=require('./lib/verify-auth');
8-
constaddChannelNpm=require('./lib/add-channel');
9-
constprepareNpm=require('./lib/prepare');
10-
constpublishNpm=require('./lib/publish');
1+
import{castArray,defaultTo}from'lodash-es';
2+
importAggregateErrorfrom'aggregate-error';
3+
importtempyfrom'tempy';
4+
importsetLegacyTokenfrom'./lib/set-legacy-token.js';
5+
importgetPkgfrom'./lib/get-pkg.js';
6+
importverifyNpmConfigfrom'./lib/verify-config.js';
7+
importverifyNpmAuthfrom'./lib/verify-auth.js';
8+
importaddChannelNpmfrom'./lib/add-channel.js';
9+
importprepareNpmfrom'./lib/prepare.js';
10+
importpublishNpmfrom'./lib/publish.js';
1111

1212
letverified;
1313
letprepared;
1414
constnpmrc=tempy.file({name:'.npmrc'});
1515

16-
asyncfunctionverifyConditions(pluginConfig,context){
16+
exportasyncfunctionverifyConditions(pluginConfig,context){
1717
// If the npm publish plugin is used and has `npmPublish`, `tarballDir` or `pkgRoot` configured, validate them now in order to prevent any release if the configuration is wrong
1818
if(context.options.publish){
1919
constpublishPlugin=
@@ -46,7 +46,7 @@ async function verifyConditions(pluginConfig, context) {
4646
verified=true;
4747
}
4848

49-
asyncfunctionprepare(pluginConfig,context){
49+
exportasyncfunctionprepare(pluginConfig,context){
5050
consterrors=verified ?[] :verifyNpmConfig(pluginConfig);
5151

5252
setLegacyToken(context);
@@ -69,7 +69,7 @@ async function prepare(pluginConfig, context) {
6969
prepared=true;
7070
}
7171

72-
asyncfunctionpublish(pluginConfig,context){
72+
exportasyncfunctionpublish(pluginConfig,context){
7373
letpkg;
7474
consterrors=verified ?[] :verifyNpmConfig(pluginConfig);
7575

@@ -96,7 +96,7 @@ async function publish(pluginConfig, context) {
9696
returnpublishNpm(npmrc,pluginConfig,pkg,context);
9797
}
9898

99-
asyncfunctionaddChannel(pluginConfig,context){
99+
exportasyncfunctionaddChannel(pluginConfig,context){
100100
letpkg;
101101
consterrors=verified ?[] :verifyNpmConfig(pluginConfig);
102102

@@ -118,5 +118,3 @@ async function addChannel(pluginConfig, context) {
118118

119119
returnaddChannelNpm(npmrc,pluginConfig,pkg,context);
120120
}
121-
122-
module.exports={verifyConditions, prepare, publish, addChannel};

‎lib/add-channel.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
constexeca=require('execa');
2-
constgetRegistry=require('./get-registry');
3-
constgetChannel=require('./get-channel');
4-
constgetReleaseInfo=require('./get-release-info');
1+
importexecafrom'execa';
2+
importgetRegistryfrom'./get-registry.js';
3+
importgetChannelfrom'./get-channel.js';
4+
importgetReleaseInfofrom'./get-release-info.js';
55

6-
module.exports=async(npmrc,{npmPublish},pkg,context)=>{
6+
exportdefaultasyncfunction(npmrc,{npmPublish},pkg,context){
77
const{
88
cwd,
99
env,
@@ -43,4 +43,4 @@ module.exports = async (npmrc, {npmPublish}, pkg, context) => {
4343
);
4444

4545
returnfalse;
46-
};
46+
}

‎lib/definitions/errors.js‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
1-
constpkg=require('../../package.json');
1+
import{dirname,resolve}from'node:path';
2+
import{fileURLToPath}from'node:url';
3+
import{readPackageSync}from'read-pkg';
24

5+
const__dirname=dirname(fileURLToPath(import.meta.url));
6+
constpkg=readPackageSync({cwd:resolve(__dirname,'../../')});
37
const[homepage]=pkg.homepage.split('#');
48
constlinkify=(file)=>`${homepage}/blob/master/${file}`;
59

6-
module.exports={
7-
EINVALIDNPMPUBLISH:({npmPublish})=>({
10+
exportfunctionEINVALIDNPMPUBLISH({ npmPublish}){
11+
return{
812
message:'Invalid `npmPublish` option.',
913
details:`The [npmPublish option](${linkify('README.md#npmpublish')}) option, if defined, must be a \`Boolean\`.
1014
1115
Your configuration for the \`npmPublish\` option is \`${npmPublish}\`.`,
12-
}),
13-
EINVALIDTARBALLDIR:({tarballDir})=>({
16+
};
17+
}
18+
19+
exportfunctionEINVALIDTARBALLDIR({ tarballDir}){
20+
return{
1421
message:'Invalid `tarballDir` option.',
1522
details:`The [tarballDir option](${linkify('README.md#tarballdir')}) option, if defined, must be a \`String\`.
1623
1724
Your configuration for the \`tarballDir\` option is \`${tarballDir}\`.`,
18-
}),
19-
EINVALIDPKGROOT:({pkgRoot})=>({
25+
};
26+
}
27+
28+
exportfunctionEINVALIDPKGROOT({ pkgRoot}){
29+
return{
2030
message:'Invalid `pkgRoot` option.',
2131
details:`The [pkgRoot option](${linkify('README.md#pkgroot')}) option, if defined, must be a \`String\`.
2232
2333
Your configuration for the \`pkgRoot\` option is \`${pkgRoot}\`.`,
24-
}),
25-
ENONPMTOKEN:({registry})=>({
34+
};
35+
}
36+
37+
exportfunctionENONPMTOKEN({ registry}){
38+
return{
2639
message:'No npm token specified.',
2740
details:`An [npm token](${linkify(
2841
'README.md#npm-registry-authentication'
2942
)}) must be created and set in the \`NPM_TOKEN\` environment variable on your CI environment.
3043
3144
Please make sure to create an [npm token](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) and to set it in the \`NPM_TOKEN\` environment variable on your CI environment. The token must allow to publish to the registry \`${registry}\`.`,
32-
}),
33-
EINVALIDNPMTOKEN:({registry})=>({
45+
};
46+
}
47+
48+
exportfunctionEINVALIDNPMTOKEN({ registry}){
49+
return{
3450
message:'Invalid npm token.',
3551
details:`The [npm token](${linkify(
3652
'README.md#npm-registry-authentication'
@@ -40,17 +56,23 @@ If you are using Two Factor Authentication for your account, set its level to ["
4056
Authorization and writes" level.
4157
4258
Please make sure to set the \`NPM_TOKEN\` environment variable in your CI with the exact value of the npm token.`,
43-
}),
44-
ENOPKGNAME:()=>({
59+
};
60+
}
61+
62+
exportfunctionENOPKGNAME(){
63+
return{
4564
message:'Missing `name` property in `package.json`.',
4665
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.
4766
4867
Please make sure to add a valid \`name\` for your package in your \`package.json\`.`,
49-
}),
50-
ENOPKG:()=>({
68+
};
69+
}
70+
71+
exportfunctionENOPKG(){
72+
return{
5173
message:'Missing `package.json` file.',
5274
details:`A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to release on npm.
5375
5476
Please follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid \`package.json\` file.`,
55-
}),
56-
};
77+
};
78+
}

‎lib/get-channel.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
constsemver=require('semver');
1+
importsemverfrom'semver';
22

3-
module.exports=(channel)=>(channel ?(semver.validRange(channel) ?`release-${channel}` :channel) :'latest');
3+
exportdefaultfunction(channel){
4+
returnchannel ?(semver.validRange(channel) ?`release-${channel}` :channel) :'latest';
5+
}

‎lib/get-error.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
constSemanticReleaseError=require('@semantic-release/error');
2-
constERROR_DEFINITIONS=require('./definitions/errors');
1+
importSemanticReleaseErrorfrom'@semantic-release/error';
2+
import*asERROR_DEFINITIONSfrom'./definitions/errors.js';
33

4-
module.exports=(code,ctx={})=>{
4+
exportdefaultfunction(code,ctx={}){
55
const{message, details}=ERROR_DEFINITIONS[code](ctx);
6+
67
returnnewSemanticReleaseError(message,code,details);
7-
};
8+
}

‎lib/get-pkg.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
constpath=require('path');
2-
constreadPkg=require('read-pkg');
3-
constAggregateError=require('aggregate-error');
4-
constgetError=require('./get-error');
1+
importpathfrom'path';
2+
import{readPackage}from'read-pkg';
3+
importAggregateErrorfrom'aggregate-error';
4+
importgetErrorfrom'./get-error.js';
55

6-
module.exports=async({pkgRoot},{cwd})=>{
6+
exportdefaultasyncfunction({pkgRoot},{cwd}){
77
try{
8-
constpkg=awaitreadPkg({cwd:pkgRoot ?path.resolve(cwd,String(pkgRoot)) :cwd});
8+
constpkg=awaitreadPackage({cwd:pkgRoot ?path.resolve(cwd,String(pkgRoot)) :cwd});
99

1010
if(!pkg.name){
1111
throwgetError('ENOPKGNAME');
@@ -19,4 +19,4 @@ module.exports = async ({pkgRoot}, {cwd}) => {
1919

2020
thrownewAggregateError([error]);
2121
}
22-
};
22+
}

‎lib/get-registry.js‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
constpath=require('path');
2-
constrc=require('rc');
3-
constgetRegistryUrl=require('registry-auth-token/registry-url');
1+
importpathfrom'path';
2+
importrcfrom'rc';
3+
importgetRegistryUrlfrom'registry-auth-token/registry-url.js';
44

5-
module.exports=({publishConfig:{registry}={}, name},{cwd, env})=>
6-
registry||
7-
env.NPM_CONFIG_REGISTRY||
8-
getRegistryUrl(
9-
name.split('/')[0],
10-
rc(
11-
'npm',
12-
{registry:'https://registry.npmjs.org/'},
13-
{config:env.NPM_CONFIG_USERCONFIG||path.resolve(cwd,'.npmrc')}
14-
)
15-
);
5+
exportdefaultfunction({publishConfig:{ registry}={}, name},{ cwd, env}){
6+
returnregistry||
7+
env.NPM_CONFIG_REGISTRY||
8+
getRegistryUrl(
9+
name.split('/')[0],
10+
rc(
11+
'npm',
12+
{registry:'https://registry.npmjs.org/'},
13+
{config:env.NPM_CONFIG_USERCONFIG||path.resolve(cwd,'.npmrc')}
14+
)
15+
);
16+
}

‎lib/get-release-info.js‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
constnormalizeUrl=require('normalize-url');
1+
importnormalizeUrlfrom'normalize-url';
22

3-
module.exports=(
3+
exportdefaultfunction(
44
{name},
55
{env:{DEFAULT_NPM_REGISTRY='https://registry.npmjs.org/'},nextRelease:{version}},
66
distTag,
77
registry
8-
)=>({
9-
name:`npm package (@${distTag} dist-tag)`,
10-
url:
8+
){
9+
return{
10+
name:`npm package (@${distTag} dist-tag)`,
11+
url:
1112
normalizeUrl(registry)===normalizeUrl(DEFAULT_NPM_REGISTRY)
1213
?`https://www.npmjs.com/package/${name}/v/${version}`
1314
:undefined,
14-
channel:distTag,
15-
});
15+
channel:distTag,
16+
};
17+
}

‎lib/prepare.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
constpath=require('path');
2-
const{move}=require('fs-extra');
3-
constexeca=require('execa');
1+
importpathfrom'path';
2+
import{move}from'fs-extra';
3+
importexecafrom'execa';
44

5-
module.exports=async(npmrc,{tarballDir, pkgRoot},{cwd, env, stdout, stderr,nextRelease:{version}, logger})=>{
5+
exportdefaultasyncfunction(npmrc,{tarballDir, pkgRoot},{cwd, env, stdout, stderr,nextRelease:{version}, logger}){
66
constbasePath=pkgRoot ?path.resolve(cwd,pkgRoot) :cwd;
77

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

‎lib/publish.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
constpath=require('path');
2-
constexeca=require('execa');
3-
constgetRegistry=require('./get-registry');
4-
constgetChannel=require('./get-channel');
5-
constgetReleaseInfo=require('./get-release-info');
1+
importpathfrom'path';
2+
importexecafrom'execa';
3+
importgetRegistryfrom'./get-registry.js';
4+
importgetChannelfrom'./get-channel.js';
5+
importgetReleaseInfofrom'./get-release-info.js';
66

7-
module.exports=async(npmrc,{npmPublish, pkgRoot},pkg,context)=>{
7+
exportdefaultasyncfunction(npmrc,{npmPublish, pkgRoot},pkg,context){
88
const{
99
cwd,
1010
env,
@@ -41,4 +41,4 @@ module.exports = async (npmrc, {npmPublish, pkgRoot}, pkg, context) => {
4141
);
4242

4343
returnfalse;
44-
};
44+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp