@@ -29,6 +29,7 @@ const path = require('path');
29
29
const runCommand = require ( './run-command' ) ;
30
30
31
31
const packagesDirPath = path . resolve ( __dirname , '../packages' ) ;
32
+ const npmrcPath = path . resolve ( process . env . HOME , '.npmrc' ) ;
32
33
33
34
async function isPackageVersionPublished ( packageName , version ) {
34
35
return fetch ( `https://registry.npmjs.org/${ encodeURI ( packageName ) } /${ version } ` )
@@ -38,8 +39,9 @@ async function isPackageVersionPublished(packageName, version) {
38
39
async function isValidPackagePath ( packageDir ) {
39
40
const packageJsonPath = `${ packageDir } /package.json` ;
40
41
try {
42
+ // check to see if the file already exists - if so do nothing
41
43
await fs . stat ( packageJsonPath ) ;
42
- return true
44
+ return true ;
43
45
} catch {
44
46
return false ;
45
47
}
@@ -52,6 +54,20 @@ async function getPackageInfo(packageDir) {
52
54
} ;
53
55
}
54
56
57
+ async function setupNpm ( ) {
58
+ // For npm publication to work, the NPM token must be stored in the .npmrc file
59
+ if ( process . env . GITHUB_ACTIONS && process . env . NPM_TOKEN ) {
60
+ await fs . writeFile (
61
+ npmrcPath ,
62
+ `//registry.npmjs.org/:_authToken=${ process . env . NPM_TOKEN } \nregistry=https://registry.npmjs.org/` ,
63
+ 'utf8' ) ;
64
+ }
65
+ }
66
+
67
+ async function cleanupNpmrc ( ) {
68
+ await fs . unlink ( npmrcPath ) ;
69
+ }
70
+
55
71
async function publishPackagesIfNeeded ( packageInfo ) {
56
72
const pkgJson = packageInfo . pkg ;
57
73
const isAlreadyPublished = await isPackageVersionPublished ( pkgJson . name , pkgJson . version ) ;
@@ -60,16 +76,15 @@ async function publishPackagesIfNeeded(packageInfo) {
60
76
return ;
61
77
}
62
78
console . log ( 'Publishing' , pkgJson . name , pkgJson . version ) ;
63
- const publishArgs = [ ] ;
79
+ const publishArgs = [ 'workspace' , pkgJson . name , 'publish' , `--new-version= ${ pkgJson . version } ` ] ;
64
80
if ( process . env . COMPILER_NIGHTLY ) {
65
- publishArgs . push ( '--npm- tag' , 'nightly' ) ;
81
+ publishArgs . push ( '--tag' , 'nightly' ) ;
66
82
}
67
- await runCommand ( 'npm' , [ 'publish' ] . concat ( publishArgs ) , {
68
- cwd : packageInfo . path
69
- } ) ;
83
+ await runCommand ( 'yarn' , publishArgs ) ;
70
84
}
71
85
72
86
( async ( ) => {
87
+ await setupNpm ( ) ;
73
88
const packagesDirEntries = await fs . readdir ( packagesDirPath ) ;
74
89
// build a graph of the interdependencies of projects and only publish
75
90
const graph = new graphlib . Graph ( { directed : true , compound : false } ) ;
@@ -112,4 +127,6 @@ async function publishPackagesIfNeeded(packageInfo) {
112
127
throw new Error ( 'Unable to publish packages: cyclical dependencies encountered.' ) ;
113
128
}
114
129
}
115
- } ) ( ) . catch ( ( e ) => { throw e } ) ;
130
+ } ) ( ) . catch ( ( e ) => {
131
+ throw e ;
132
+ } ) . finally ( cleanupNpmrc ) ;
0 commit comments