@@ -6,7 +6,7 @@ import pathUtils from 'path';
66
77import type { SnapManifest } from './validation' ;
88import type { ValidatorResults } from './validator' ;
9- import { hasFixes , runValidators } from './validator' ;
9+ import { isReportFixable , hasFixes , runValidators } from './validator' ;
1010import type { ValidatorMeta , ValidatorReport } from './validator-types' ;
1111import * as defaultValidators from './validators' ;
1212import { deepClone } from '../deep-clone' ;
@@ -65,6 +65,12 @@ export type CheckManifestOptions = {
6565 * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.
6666 */
6767 handlerEndowments ?: Record < string , string | null > ;
68+
69+ /**
70+ * Whether the compiler is running in watch mode. This is used to determine
71+ * whether to fix warnings or errors only.
72+ */
73+ watchMode ?: boolean ;
6874} ;
6975
7076/**
@@ -99,6 +105,8 @@ export type WriteFileFunction = (path: string, data: string) => Promise<void>;
99105 * handlers and their respective permission name. This must be provided to avoid
100106 * circular dependencies between `@metamask/snaps-utils` and
101107 * `@metamask/snaps-rpc-methods`.
108+ * @param options.watchMode - Whether the compiler is running in watch mode.
109+ * This is used to determine whether to fix warnings or errors only.
102110 * @returns Whether the manifest was updated, and an array of warnings that
103111 * were encountered during processing of the manifest files.
104112 */
@@ -110,6 +118,7 @@ export async function checkManifest(
110118 writeFileFn = fs . writeFile ,
111119 exports,
112120 handlerEndowments,
121+ watchMode = false ,
113122 } : CheckManifestOptions = { } ,
114123) : Promise < CheckManifestResult > {
115124 const manifestPath = pathUtils . join ( basePath , NpmSnapFileNames . Manifest ) ;
@@ -169,8 +178,8 @@ export async function checkManifest(
169178 reports : validatorResults . reports ,
170179 } ;
171180
172- if ( updateAndWriteManifest && hasFixes ( manifestResults ) ) {
173- const fixedResults = await runFixes ( validatorResults ) ;
181+ if ( updateAndWriteManifest && hasFixes ( manifestResults , watchMode ) ) {
182+ const fixedResults = await runFixes ( validatorResults , undefined , watchMode ) ;
174183
175184 if ( fixedResults . updated ) {
176185 manifestResults = fixedResults ;
@@ -206,11 +215,13 @@ export async function checkManifest(
206215 *
207216 * @param results - Results of the initial run of validation.
208217 * @param rules - Optional list of rules to run the fixes with.
218+ * @param errorsOnly - Whether to only run fixes for errors, not warnings.
209219 * @returns The updated manifest and whether it was updated.
210220 */
211221export async function runFixes (
212222 results : ValidatorResults ,
213223 rules ?: ValidatorMeta [ ] ,
224+ errorsOnly = false ,
214225) : Promise < CheckManifestResult > {
215226 let shouldRunFixes = true ;
216227 const MAX_ATTEMPTS = 10 ;
@@ -230,7 +241,10 @@ export async function runFixes(
230241
231242 let manifest = fixResults . files . manifest . result ;
232243
233- const fixable = fixResults . reports . filter ( ( report ) => report . fix ) ;
244+ const fixable = fixResults . reports . filter ( ( report ) =>
245+ isReportFixable ( report , errorsOnly ) ,
246+ ) ;
247+
234248 for ( const report of fixable ) {
235249 assert ( report . fix ) ;
236250 ( { manifest } = await report . fix ( { manifest } ) ) ;
@@ -244,7 +258,7 @@ export async function runFixes(
244258 fixResults . files . manifest . result = manifest ;
245259
246260 fixResults = await runValidators ( fixResults . files , rules ) ;
247- shouldRunFixes = hasFixes ( fixResults ) ;
261+ shouldRunFixes = hasFixes ( fixResults , errorsOnly ) ;
248262 }
249263
250264 const initialReports : ( CheckManifestReport & ValidatorReport ) [ ] = deepClone (
0 commit comments