1
1
const { readPreState } = require ( '@changesets/pre' ) ;
2
2
const { default : readChangesets } = require ( '@changesets/read' ) ;
3
3
const { join } = require ( 'path' ) ;
4
- const { version } = require ( join ( __dirname , '../../../package.json' ) ) ;
4
+ const { fetch } = require ( 'undici' ) ;
5
+ const { version, name : packageName } = require ( join ( __dirname , '../../../contracts/package.json' ) ) ;
5
6
6
7
module . exports = async ( { github, context, core } ) => {
7
8
const state = await getState ( { github, context, core } ) ;
@@ -34,8 +35,8 @@ function shouldRunChangesets({ isReleaseBranch, isPush, isWorkflowDispatch, botR
34
35
return ( isReleaseBranch && isPush ) || ( isReleaseBranch && isWorkflowDispatch && botRun ) ;
35
36
}
36
37
37
- function shouldRunPublish ( { isReleaseBranch, isPush, hasPendingChangesets } ) {
38
- return isReleaseBranch && isPush && ! hasPendingChangesets ;
38
+ function shouldRunPublish ( { isReleaseBranch, isPush, hasPendingChangesets, isPublishedOnNpm } ) {
39
+ return isReleaseBranch && isPush && ! hasPendingChangesets && ! isPublishedOnNpm ;
39
40
}
40
41
41
42
function shouldRunMerge ( {
@@ -80,6 +81,8 @@ async function getState({ github, context, core }) {
80
81
81
82
state . prBackExists = prs . length === 0 ;
82
83
84
+ state . isPublishedOnNpm = await isPublishedOnNpm ( packageName , version ) ;
85
+
83
86
// Log every state value in debug mode
84
87
if ( core . isDebug ( ) ) for ( const [ key , value ] of Object . entries ( state ) ) core . debug ( `${ key } : ${ value } ` ) ;
85
88
@@ -102,3 +105,8 @@ async function readChangesetState(cwd = process.cwd()) {
102
105
changesets,
103
106
} ;
104
107
}
108
+
109
+ async function isPublishedOnNpm ( package , version ) {
110
+ const res = await fetch ( `https://registry.npmjs.com/${ package } /${ version } ` ) ;
111
+ return res . ok ;
112
+ }
0 commit comments