@@ -31,135 +31,62 @@ type RequirementsEvaluationContext = {
3131 isConfigSatisfied : ( pathStr : string ) => boolean ;
3232} ;
3333
34- type RequirementsEvaluationRemoteContext = {
35- hasRemoteBin ?: ( bin : string ) => boolean ;
36- hasRemoteAnyBin ?: ( bins : string [ ] ) => boolean ;
37- remotePlatforms ?: string [ ] ;
38- } ;
39-
40- /** Returns required binaries absent from both the local host and optional remote target. */
41- function resolveMissingBins ( params : {
42- required : string [ ] ;
43- hasLocalBin : ( bin : string ) => boolean ;
44- hasRemoteBin ?: ( bin : string ) => boolean ;
45- } ) : string [ ] {
46- const remote = params . hasRemoteBin ;
47- return params . required . filter ( ( bin ) => {
48- if ( params . hasLocalBin ( bin ) ) {
49- return false ;
50- }
51- if ( remote ?.( bin ) ) {
52- return false ;
53- }
54- return true ;
55- } ) ;
56- }
57-
58- /** Treats an any-bin requirement as satisfied when any listed binary exists locally or remotely. */
59- function resolveMissingAnyBins ( params : {
60- required : string [ ] ;
61- hasLocalBin : ( bin : string ) => boolean ;
62- hasRemoteAnyBin ?: ( bins : string [ ] ) => boolean ;
63- } ) : string [ ] {
64- if ( params . required . length === 0 ) {
65- return [ ] ;
66- }
67- if ( params . required . some ( ( bin ) => params . hasLocalBin ( bin ) ) ) {
68- return [ ] ;
69- }
70- if ( params . hasRemoteAnyBin ?.( params . required ) ) {
71- return [ ] ;
72- }
73- return params . required ;
74- }
75-
76- /** Resolves OS requirements against local and remote platforms, accepting macos as darwin. */
77- function resolveMissingOs ( params : {
78- required : string [ ] ;
79- localPlatform : string ;
80- remotePlatforms ?: string [ ] ;
81- } ) : string [ ] {
82- if ( params . required . length === 0 ) {
83- return [ ] ;
84- }
85- const localPlatform = normalizeOsRequirementPlatform ( params . localPlatform ) ;
86- const requiredPlatforms = new Set (
87- params . required . map ( ( platform ) => normalizeOsRequirementPlatform ( platform ) ) ,
88- ) ;
89- if ( requiredPlatforms . has ( localPlatform ) ) {
90- return [ ] ;
91- }
92- if (
93- params . remotePlatforms ?. some ( ( platform ) =>
94- requiredPlatforms . has ( normalizeOsRequirementPlatform ( platform ) ) ,
95- )
96- ) {
97- return [ ] ;
98- }
99- return params . required ;
100- }
101-
10234function normalizeOsRequirementPlatform ( platform : string ) : string {
10335 const normalized = platform . trim ( ) . toLowerCase ( ) ;
10436 return normalized === "macos" ? "darwin" : normalized ;
10537}
10638
107- /** Returns environment variable names whose caller-provided satisfaction check fails. */
108- function resolveMissingEnv ( params : {
109- required : string [ ] ;
110- isSatisfied : ( envName : string ) => boolean ;
111- } ) : string [ ] {
112- const missing : string [ ] = [ ] ;
113- for ( const envName of params . required ) {
114- if ( params . isSatisfied ( envName ) ) {
115- continue ;
39+ /** Evaluates entry requirements against the current host and optional remote capabilities. */
40+ export function evaluateRequirementsFromMetadataWithRemote (
41+ params : RequirementsEvaluationContext & {
42+ metadata ?: RequirementsMetadata ;
43+ remote ?: RequirementRemote ;
44+ } ,
45+ ) : {
46+ required : Requirements ;
47+ missing : Requirements ;
48+ eligible : boolean ;
49+ configChecks : RequirementConfigCheck [ ] ;
50+ } {
51+ const required : Requirements = {
52+ bins : params . metadata ?. requires ?. bins ?? [ ] ,
53+ anyBins : params . metadata ?. requires ?. anyBins ?? [ ] ,
54+ env : params . metadata ?. requires ?. env ?? [ ] ,
55+ config : params . metadata ?. requires ?. config ?? [ ] ,
56+ os : params . metadata ?. os ?? [ ] ,
57+ } ;
58+
59+ const hasRemoteBin = params . remote ?. hasBin ;
60+ const hasRemoteAnyBin = params . remote ?. hasAnyBin ;
61+ const missingBins = required . bins . filter (
62+ ( bin ) => ! params . hasLocalBin ( bin ) && ! hasRemoteBin ?.( bin ) ,
63+ ) ;
64+ const missingAnyBins =
65+ required . anyBins . length === 0 ||
66+ required . anyBins . some ( ( bin ) => params . hasLocalBin ( bin ) ) ||
67+ hasRemoteAnyBin ?.( required . anyBins )
68+ ? [ ]
69+ : required . anyBins ;
70+
71+ let missingOs : string [ ] = [ ] ;
72+ if ( required . os . length > 0 ) {
73+ const localPlatform = normalizeOsRequirementPlatform ( params . localPlatform ) ;
74+ const requiredPlatforms = new Set ( required . os . map ( normalizeOsRequirementPlatform ) ) ;
75+ if (
76+ ! requiredPlatforms . has ( localPlatform ) &&
77+ ! params . remote ?. platforms ?. some ( ( platform ) =>
78+ requiredPlatforms . has ( normalizeOsRequirementPlatform ( platform ) ) ,
79+ )
80+ ) {
81+ missingOs = required . os ;
11682 }
117- missing . push ( envName ) ;
11883 }
119- return missing ;
120- }
12184
122- /** Builds per-config-path status while preserving every declared path for UI diagnostics. */
123- function buildConfigChecks ( params : {
124- required : string [ ] ;
125- isSatisfied : ( pathStr : string ) => boolean ;
126- } ) : RequirementConfigCheck [ ] {
127- return params . required . map ( ( pathStr ) => {
128- const satisfied = params . isSatisfied ( pathStr ) ;
129- return { path : pathStr , satisfied } ;
130- } ) ;
131- }
132-
133- /** Evaluates normalized requirements and returns missing categories plus config diagnostics. */
134- function evaluateRequirements (
135- params : RequirementsEvaluationContext &
136- RequirementsEvaluationRemoteContext & {
137- required : Requirements ;
138- } ,
139- ) : { missing : Requirements ; eligible : boolean ; configChecks : RequirementConfigCheck [ ] } {
140- const missingBins = resolveMissingBins ( {
141- required : params . required . bins ,
142- hasLocalBin : params . hasLocalBin ,
143- hasRemoteBin : params . hasRemoteBin ,
144- } ) ;
145- const missingAnyBins = resolveMissingAnyBins ( {
146- required : params . required . anyBins ,
147- hasLocalBin : params . hasLocalBin ,
148- hasRemoteAnyBin : params . hasRemoteAnyBin ,
149- } ) ;
150- const missingOs = resolveMissingOs ( {
151- required : params . required . os ,
152- localPlatform : params . localPlatform ,
153- remotePlatforms : params . remotePlatforms ,
154- } ) ;
155- const missingEnv = resolveMissingEnv ( {
156- required : params . required . env ,
157- isSatisfied : params . isEnvSatisfied ,
158- } ) ;
159- const configChecks = buildConfigChecks ( {
160- required : params . required . config ,
161- isSatisfied : params . isConfigSatisfied ,
162- } ) ;
85+ const missingEnv = required . env . filter ( ( envName ) => ! params . isEnvSatisfied ( envName ) ) ;
86+ const configChecks = required . config . map ( ( path ) => ( {
87+ path,
88+ satisfied : params . isConfigSatisfied ( path ) ,
89+ } ) ) ;
16390 const missingConfig = configChecks . filter ( ( check ) => ! check . satisfied ) . map ( ( check ) => check . path ) ;
16491
16592 // `always` bypasses runtime requirements, but OS remains a hard compatibility boundary.
@@ -179,64 +106,5 @@ function evaluateRequirements(
179106 missing . env . length === 0 &&
180107 missing . config . length === 0 ) ) ;
181108
182- return { missing, eligible, configChecks } ;
183- }
184-
185- /** Converts entry metadata into the canonical requirement shape before evaluation. */
186- function evaluateRequirementsFromMetadata (
187- params : RequirementsEvaluationContext &
188- RequirementsEvaluationRemoteContext & {
189- metadata ?: RequirementsMetadata ;
190- } ,
191- ) : {
192- required : Requirements ;
193- missing : Requirements ;
194- eligible : boolean ;
195- configChecks : RequirementConfigCheck [ ] ;
196- } {
197- const required : Requirements = {
198- bins : params . metadata ?. requires ?. bins ?? [ ] ,
199- anyBins : params . metadata ?. requires ?. anyBins ?? [ ] ,
200- env : params . metadata ?. requires ?. env ?? [ ] ,
201- config : params . metadata ?. requires ?. config ?? [ ] ,
202- os : params . metadata ?. os ?? [ ] ,
203- } ;
204-
205- const result = evaluateRequirements ( {
206- always : params . always ,
207- required,
208- hasLocalBin : params . hasLocalBin ,
209- hasRemoteBin : params . hasRemoteBin ,
210- hasRemoteAnyBin : params . hasRemoteAnyBin ,
211- localPlatform : params . localPlatform ,
212- remotePlatforms : params . remotePlatforms ,
213- isEnvSatisfied : params . isEnvSatisfied ,
214- isConfigSatisfied : params . isConfigSatisfied ,
215- } ) ;
216- return { required, ...result } ;
217- }
218-
219- /** Convenience wrapper for callers that receive remote capability checks as one object. */
220- export function evaluateRequirementsFromMetadataWithRemote (
221- params : RequirementsEvaluationContext & {
222- metadata ?: RequirementsMetadata ;
223- remote ?: RequirementRemote ;
224- } ,
225- ) : {
226- required : Requirements ;
227- missing : Requirements ;
228- eligible : boolean ;
229- configChecks : RequirementConfigCheck [ ] ;
230- } {
231- return evaluateRequirementsFromMetadata ( {
232- always : params . always ,
233- metadata : params . metadata ,
234- hasLocalBin : params . hasLocalBin ,
235- hasRemoteBin : params . remote ?. hasBin ,
236- hasRemoteAnyBin : params . remote ?. hasAnyBin ,
237- localPlatform : params . localPlatform ,
238- remotePlatforms : params . remote ?. platforms ,
239- isEnvSatisfied : params . isEnvSatisfied ,
240- isConfigSatisfied : params . isConfigSatisfied ,
241- } ) ;
109+ return { required, missing, eligible, configChecks } ;
242110}
0 commit comments