File tree Expand file tree Collapse file tree 3 files changed +26
-20
lines changed Expand file tree Collapse file tree 3 files changed +26
-20
lines changed Original file line number Diff line number Diff line change 33 * Licensed under the MIT License.
44 */
55
6- const execSync = require ( "child_process" ) . execSync ;
7-
8- function checkVersion ( packageName , version ) {
9- // It is expected npm view will fail for packages that are about to be published. 2> dev/null/ is used to suppress the error.
10- return execSync ( `npm view ${ packageName } @${ version } 2> /dev/null` ) . toString ( ) . trim ( ) ;
11- }
12-
6+ const checkPackageAndVersion = require ( "./checkPackageAndVersion.js" ) ;
137const path = require ( "path" ) ;
148const libPath = path . join ( __dirname , '..' , process . argv [ 2 ] ) ;
159
1610const { name, version } = require ( `${ libPath } /package.json` ) ;
1711
18- const versionIsPublished = checkVersion ( name , version ) ;
12+ const versionIsPublished = checkPackageAndVersion ( name , version ) ;
1913
2014if ( versionIsPublished ) {
2115 process . exit ( 0 ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License.
4+ */
5+
6+ const { execSync } = require ( "child_process" ) ;
7+
8+ const checkPackageAndVersion = ( packageName , version ) => {
9+ // It is expected npm view will fail for packages that are about to be published. 2> dev/null/ is used to suppress the error.
10+ try {
11+ execSync ( `npm view --silent ${ packageName } @${ version } ` ) . toString ( ) . trim ( ) ;
12+ return true ;
13+ } catch ( error ) {
14+ return false ;
15+ }
16+ }
17+
18+ module . exports = checkPackageAndVersion ;
Original file line number Diff line number Diff line change 33 * Licensed under the MIT License.
44 */
55
6- const execSync = require ( "child_process" ) . execSync ;
7-
8- function getPublishedVersion ( packageName ) {
9- return execSync ( `npm view ${ packageName } @${ version } ` ) . toString ( ) . trim ( ) ;
10- }
11-
6+ const checkPackageAndVersion = require ( "./checkPackageAndVersion.js" ) ;
127const path = require ( "path" ) ;
138const libPath = path . join ( __dirname , '..' , process . argv [ 2 ] ) ;
149
15- const packageName = require ( `${ libPath } /package.json` ) . name ;
16- const currentVersion = require ( `${ libPath } /package.json` ) . version ;
10+ const { name, version } = require ( `${ libPath } /package.json` ) ;
1711
1812let iteration = 0 ;
1913const intervalId = setInterval ( ( ) => {
2014 if ( iteration > 12 ) {
2115 clearInterval ( intervalId ) ;
22- throw new Error ( `Timed out waiting for ${ packageName } version ${ currentVersion } ` ) ;
16+ throw new Error ( `Timed out waiting for ${ name } version ${ version } ` ) ;
2317 }
24- const publishedVersion = getPublishedVersion ( packageName ) ;
25- if ( currentVersion === publishedVersion ) {
26- console . log ( `${ packageName } successfully published version ${ currentVersion } ` ) ;
18+ const versionIsPublished = checkPackageAndVersion ( name , version ) ;
19+ if ( versionIsPublished ) {
20+ console . log ( `${ name } successfully published version ${ version } ` ) ;
2721 clearInterval ( intervalId ) ;
2822 process . exit ( 0 ) ;
2923 }
You can’t perform that action at this time.
0 commit comments