@@ -3,6 +3,10 @@ import { spawnSync } from "node:child_process";
33import * as fs from "node:fs" ;
44import * as util from "node:util" ;
55
6+ const ADO_PUBLISH_PIPELINE = ".ado/templates/npm-publish.yml" ;
7+ const NPM_TAG_NEXT = "next" ;
8+ const NX_CONFIG_FILE = "nx.json" ;
9+
610/**
711 * @typedef {typeof import("../../nx.json") } NxConfig
812 * @typedef {{ tag?: string; update?: boolean; } } Options
@@ -39,9 +43,10 @@ function isStableBranch(branch) {
3943
4044/**
4145 * Loads Nx configuration.
46+ * @param {string } configFile
4247 * @returns {NxConfig }
4348 */
44- function loadNxConfig ( configFile = "nx.json" ) {
49+ function loadNxConfig ( configFile ) {
4550 const nx = fs . readFileSync ( configFile , { encoding : "utf-8" } ) ;
4651 return JSON . parse ( nx ) ;
4752}
@@ -119,7 +124,7 @@ function getTagForStableBranch(branch, { tag }) {
119124 }
120125
121126 // Publishing a release candidate
122- return { npmTag : "next" , prerelease : "rc" } ;
127+ return { npmTag : NPM_TAG_NEXT , prerelease : "rc" } ;
123128}
124129
125130/**
@@ -172,6 +177,22 @@ function enablePublishing(config, currentBranch, tag, prerelease) {
172177 enablePublishingOnAzurePipelines ( ) ;
173178}
174179
180+ /**
181+ * @param {string } file
182+ * @param {string } tag
183+ */
184+ function verifyPublishPipeline ( file , tag ) {
185+ const data = fs . readFileSync ( file , { encoding : "utf-8" } ) ;
186+ const m = data . match ( / p u b l i s h T a g : ' ( \w * ?) ' / ) ;
187+ if ( ! m ) {
188+ throw new Error ( `Could not find npm publish tag in '${ file } '` ) ;
189+ }
190+
191+ if ( m [ 1 ] !== tag ) {
192+ throw new Error ( `${ file } : 'publishTag' needs to be set to '${ tag } '` ) ;
193+ }
194+ }
195+
175196/**
176197 * @param {Options } options
177198 */
@@ -181,9 +202,9 @@ function main(options) {
181202 throw new Error ( "Could not get current branch" ) ;
182203 }
183204
184- const nxConfigPath = "nx.json" ;
205+ verifyPublishPipeline ( ADO_PUBLISH_PIPELINE , options . tag || NPM_TAG_NEXT ) ;
185206
186- const config = loadNxConfig ( nxConfigPath ) ;
207+ const config = loadNxConfig ( NX_CONFIG_FILE ) ;
187208 try {
188209 if ( isMainBranch ( branch ) ) {
189210 enablePublishing ( config , branch , "nightly" , "nightly" ) ;
@@ -194,7 +215,7 @@ function main(options) {
194215 } catch ( e ) {
195216 process . exitCode = 1 ;
196217 if ( options . update ) {
197- const fd = fs . openSync ( nxConfigPath , "w" ) ;
218+ const fd = fs . openSync ( NX_CONFIG_FILE , "w" ) ;
198219 fs . writeSync ( fd , JSON . stringify ( config , undefined , 2 ) ) ;
199220 fs . writeSync ( fd , "\n" ) ;
200221 fs . closeSync ( fd )
@@ -209,7 +230,7 @@ const { values } = util.parseArgs({
209230 options : {
210231 tag : {
211232 type : "string" ,
212- default : "next" ,
233+ default : NPM_TAG_NEXT ,
213234 } ,
214235 update : {
215236 type : "boolean" ,
0 commit comments