@@ -283,11 +283,14 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
283
283
var moduleData = new ModuleData ( ) ;
284
284
285
285
IEnumerable < CommandInfo > coreCommands = _pwsh . AddCommand ( GcmInfo )
286
- . AddParameter ( "Module" , CORE_MODULE_NAME )
287
- . InvokeAndClear < CommandInfo > ( ) ;
286
+ . AddParameter ( "Type" , CommandTypes . Alias | CommandTypes . Cmdlet | CommandTypes . Function )
287
+ . InvokeAndClear < CommandInfo > ( )
288
+ . Where ( commandInfo => string . IsNullOrEmpty ( commandInfo . ModuleName ) || CORE_MODULE_NAME . Equals ( commandInfo . ModuleName , StringComparison . OrdinalIgnoreCase ) ) ;
288
289
289
290
var cmdletData = new JsonCaseInsensitiveStringDictionary < CmdletData > ( ) ;
290
291
var functionData = new JsonCaseInsensitiveStringDictionary < FunctionData > ( ) ;
292
+ var aliases = new JsonCaseInsensitiveStringDictionary < string > ( ) ;
293
+ var aliasesToRequest = new List < string > ( ) ;
291
294
foreach ( CommandInfo command in coreCommands )
292
295
{
293
296
switch ( command )
@@ -315,6 +318,24 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
315
318
}
316
319
continue ;
317
320
321
+ case AliasInfo alias :
322
+ try
323
+ {
324
+ // Some aliases won't resolve unless specified specifically
325
+ if ( alias . Definition == null )
326
+ {
327
+ aliasesToRequest . Add ( alias . Name ) ;
328
+ continue ;
329
+ }
330
+
331
+ aliases . Add ( alias . Name , alias . Definition ) ;
332
+ }
333
+ catch ( RuntimeException )
334
+ {
335
+ // Ignore aliases that have trouble loading
336
+ }
337
+ continue ;
338
+
318
339
default :
319
340
throw new CompatibilityAnalysisException ( $ "Command { command . Name } in core module is of unsupported type { command . CommandType } ") ;
320
341
}
@@ -323,15 +344,31 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
323
344
moduleData . Cmdlets = cmdletData ;
324
345
moduleData . Functions = functionData ;
325
346
347
+ if ( aliasesToRequest != null && aliasesToRequest . Count > 0 )
348
+ {
349
+ IEnumerable < AliasInfo > resolvedAliases = _pwsh . AddCommand ( GcmInfo )
350
+ . AddParameter ( "Name" , aliasesToRequest )
351
+ . InvokeAndClear < AliasInfo > ( ) ;
352
+
353
+ foreach ( AliasInfo resolvedAlias in resolvedAliases )
354
+ {
355
+ if ( resolvedAlias ? . Definition == null )
356
+ {
357
+ continue ;
358
+ }
359
+
360
+ aliases [ resolvedAlias . Name ] = resolvedAlias . Definition ;
361
+ }
362
+ }
363
+
326
364
// Get default variables and core aliases out of a fresh runspace
327
365
using ( SMA . PowerShell freshPwsh = SMA . PowerShell . Create ( RunspaceMode . NewRunspace ) )
328
366
{
329
367
Collection < PSObject > varsAndAliases = freshPwsh . AddCommand ( "Get-ChildItem" )
330
- . AddParameter ( "Path" , "variable:,alias: " )
368
+ . AddParameter ( "Path" , "variable:" )
331
369
. InvokeAndClear ( ) ;
332
370
333
371
var variables = new List < string > ( ) ;
334
- var aliases = new JsonCaseInsensitiveStringDictionary < string > ( ) ;
335
372
336
373
foreach ( PSObject returnedObject in varsAndAliases )
337
374
{
@@ -341,10 +378,6 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
341
378
variables . Add ( variable . Name ) ;
342
379
continue ;
343
380
344
- case AliasInfo alias :
345
- aliases . Add ( alias . Name , GetSingleAliasData ( alias ) ) ;
346
- continue ;
347
-
348
381
// Skip over other objects we get back, since there's no reason to throw
349
382
}
350
383
}
0 commit comments