You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ Support for PSResourceGet, RequiredModules, and PSDepend manifest files
The `-Path` parameter can now be directed to a manifest .psd1 or .json file of these alternate specification formats and ModuleFast will resolve and install the packages.
ModuleFast has some limited autodetection for the format used, but in case it guesses wrong, there is also a new `-SpecFileType` parameter to explicitly define which format the file is in. Check the debug messages to see which format it detected and why.
#Provide a required module specification path to install from. This can be a local psd1/json file, or a remote URL with a psd1/json file in supported manifest formats, or a .ps1/.psm1 file with a #Requires statement.
#Explicitly specify the type of SpecFile to use. ModuleFast has some limited autodetection capability for ModuleBuilder and PSDepend formats, you should use this parameter if they explicitly fail. This is ignored if the file is not a .psd1 file.
#Where to install the modules. This defaults to the builtin module path on non-windows and a custom LOCALAPPDATA location on Windows. You can also specify 'CurrentUser' to install to the Documents folder on Windows Only (this is not recommended)
207
209
[string]$Destination,
208
210
#The repository to scan for modules. TODO: Multi-repo support
Write-Debug"PSDepend Parse: Skipping $key because its extended type is not PSGalleryModule"
1079
+
continue
1080
+
} else {
1081
+
Write-Debug"PSDepend Parse: Adding $key$value)"
1082
+
$initialSpec[$matches[1]] =$value
1083
+
continue
1084
+
}
1085
+
} elseif ($value-is [string]) {
1086
+
#If the key doesn't have any special formats and the value is a string, we can assume it is a direct "shorthand" specification
1087
+
$initialSpec[$key] =$value
1088
+
continue
1089
+
}
1090
+
1091
+
#At this point there should only be PSDepend "Extended" Syntax objects
1092
+
if ($value-isnot [hashtable]) {
1093
+
throw [NotSupportedException]'PSDepend Parse: Value target must be a string or hashtable'
1094
+
}
1095
+
1096
+
if ($value.DependencyType-ne'PSGalleryModule') {
1097
+
Write-Debug"PSDepend Parse: Skipping $key because its extended DependencyType is not PSGalleryModule"
1098
+
continue
1099
+
}
1100
+
1101
+
if ($value.Parameters.Repository) {
1102
+
Write-Warning"PSDepend Parse: Repository specification detected for $key. This is not currently supported and will use the default Source for now."
1103
+
}
1104
+
1105
+
$version=$value.Version??'latest'
1106
+
1107
+
#TODO: Repository support
1108
+
if (-not$value.Name) {
1109
+
Write-Debug'PSDepend Parse: Skipping $key because no Name property was specified'
1110
+
}
1111
+
1112
+
if ($value.Parameters.AllowPrerelease) {
1113
+
Write-Debug"PSDepend Parse: Prerelease detected for $key"
1114
+
$value.Name="!$($value.Name)"
1115
+
}
1116
+
1117
+
Write-Debug"PSDepend Parse: Adding $key extended module name $($value.Name)$version"
1118
+
$initialSpec[$value.Name] =$version
1119
+
}
1120
+
1121
+
foreach ($entryin$initialspec.GetEnumerator()) {
1122
+
if ($entry.Value-eq'latest') {
1123
+
[ModuleFastSpec]::new($entry.Key)
1124
+
} else {
1125
+
[ModuleFastSpec]::new($entry.Key,$entry.Value)
1126
+
}
1127
+
}
1128
+
}
1129
+
1130
+
functionConvertFrom-PSResourceGet {
1131
+
[OutputType([ModuleFastSpec[]])]
1132
+
param(
1133
+
[hashtable]$PSDependManifest
1134
+
)
1135
+
1136
+
$initialSpec= [ordered]@{}
1137
+
foreach ($keyin$PSDependManifest.Keys) {
1138
+
$value=$PSDependManifest[$key]
1139
+
1140
+
if ($key-isnot [string]) {
1141
+
throw [InvalidDataException]"PSResourceGet Parse: Manifest is invalid. Keys must be strings. Found $key$($key.GetType().FullName)"
1142
+
}
1143
+
1144
+
if ($value-is [string]) {
1145
+
$initialSpec[$key] =$value
1146
+
continue
1147
+
}
1148
+
1149
+
#At this point there should only be PSDepend "Extended" Syntax objects
1150
+
if ($value-isnot [hashtable]) {throw [NotSupportedException]'PSResourceGet Parse: Value target must be a string or hashtable'}
1151
+
1152
+
$version=$value.Version??'latest'
1153
+
1154
+
if ($value.prerelease) {
1155
+
Write-Debug"PSResourceGet Parse: Prerelease detected for $key"
1156
+
$key="!$key"
1157
+
}
1158
+
1159
+
if ($value.Repository) {
1160
+
Write-Warning"PSResourceGet Parse: Repository specification detected for $key. This is not currently supported and will use the default Source for now."
1161
+
}
1162
+
1163
+
Write-Debug"PSResourceGet Parse: Adding $key extended module name $key$version"
1164
+
$initialSpec[$key] =$version
1165
+
}
1166
+
1167
+
foreach ($entryin$initialspec.GetEnumerator()) {
1168
+
if ($entry.Value-eq'latest') {
1169
+
[ModuleFastSpec]::new($entry.Key)
1170
+
} else {
1171
+
$version=$entry.Value
1172
+
1173
+
#HACK: This handles a PSResourceGet/RequiresModule quirk where '1.0.5' is meant to be a specific version, not a minimum version which is what the NuGet version spec defines it as.
if ($version.StartsWith('[') -or$version.StartsWith('(') -or$version.Contains('*')) {
1176
+
$version= [VersionRange]::Parse($entry.Value)
1177
+
}
1178
+
1179
+
[ModuleFastSpec]::new($entry.Key,$version)
1180
+
}
1181
+
}
1182
+
}
1183
+
1055
1184
#endregion Private
1056
1185
1057
1186
#region Classes
1058
1187
1188
+
enum SpecFileType {
1189
+
AutoDetect
1190
+
ModuleFast
1191
+
PSResourceGet #Note: RequiredModules seems to be semantically close enough to PSResourceGet to use the same parser
1192
+
PSDepend
1193
+
}
1194
+
1059
1195
#This is a module construction helper to create "getters" in classes. The getters must be defined as a static hidden class prefixed with Get_ (case sensitive) and take a single parameter of the PSObject type that will be an instance of the class object for you to act on. Place this in your class constructor to automatically add the getters to the class.
throw [NotImplementedException]'TODO: PSResourceGet/PSDepend full syntax'
1925
+
throw [NotSupportedException]'ModuleFast SpecFile detected but the value is a hashtable. This is not supported. Try using the -SpecFileType parameter if you expected another format'
1781
1926
}
1782
1927
if ($kv.Value-isnot [string]) {
1783
1928
throw [NotSupportedException]'Only strings and hashtables are supported on the right hand side of the = operator.'
0 commit comments