@@ -108,6 +108,35 @@ export async function updateRecentResponse(
108108 getLogger ( ) . warn ( `sam: unable to save response at key "${ key } ": %s` , err )
109109 }
110110}
111+
112+ const buildProcessMementoRootKey = 'samcli.build.processes'
113+
114+ /**
115+ * Returns true if there's an ongoing build process for the provided template, false otherwise
116+ * @Param templatePath The path to the template.yaml file
117+ */
118+ function isBuildInProgress ( templatePath : string ) : boolean {
119+ return getRecentResponse ( buildProcessMementoRootKey , 'global' , templatePath ) !== undefined
120+ }
121+
122+ /**
123+ * Throws an error if there's a build in progress for the provided template
124+ * @Param templatePath The path to the template.yaml file
125+ */
126+ export function throwIfTemplateIsBeingBuilt ( templatePath : string ) {
127+ if ( isBuildInProgress ( templatePath ) ) {
128+ throw new ToolkitError ( 'Build in progress' , { code : 'BuildInProgress' } )
129+ }
130+ }
131+
132+ export async function registerTemplateBuild ( templatePath : string ) {
133+ await updateRecentResponse ( buildProcessMementoRootKey , 'global' , templatePath , 'true' )
134+ }
135+
136+ export async function unregisterTemplateBuild ( templatePath : string ) {
137+ await updateRecentResponse ( buildProcessMementoRootKey , 'global' , templatePath , undefined )
138+ }
139+
111140export function getSamCliErrorMessage ( stderr : string ) : string {
112141 // Split the stderr string by newline, filter out empty lines, and get the last line
113142 const lines = stderr
0 commit comments