Skip to content

Commit 6fff81c

Browse files
committed
Add module restore build rule, move start script, fix script analyzer
code for tests. Change test module path so it works Generalise module path resolution Add module parse error, remove test debug code Use simpler module loading API Import ScriptAnalyzer based on path precedence, not version Remove PSES installing itself, remove zip file Remove -EditorServicesVersion reference in ServerTestBase.cs Move Start-PSES script to new location Update testing Start-PSES script path Change URL of Start-PSES script in comment
1 parent 9d5a2da commit 6fff81c

File tree

6 files changed

+167
-116
lines changed

6 files changed

+167
-116
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ docs/_site/
3333
docs/_repo/
3434
docs/metadata/
3535
tools/
36+
*.zip
3637

3738
# quickbuild.exe
3839
/VersionGeneratingLogs/
@@ -67,4 +68,4 @@ module/PowerShellEditorServices/Commands/en-US/*-help.xml
6768
module/PowerShellEditorServices/Third\ Party\ Notices.txt
6869

6970
# Visual Studio for Mac generated file
70-
*.userprefs
71+
*.userprefs

PowerShellEditorServices.build.ps1

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55

66
param(
77
[ValidateSet("Debug", "Release")]
8-
[string]$Configuration = "Debug"
8+
[string]$Configuration = "Debug",
9+
10+
[string]$PsesSubmodulePath = "$PSScriptRoot/module",
11+
12+
[string]$ModulesJsonPath = "$PSScriptRoot/modules.json",
13+
14+
[string]$DefaultModuleRepository = "PSGallery"
915
)
1016

1117
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
1218

1319
$script:IsCIBuild = $env:APPVEYOR -ne $null
1420
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
1521
$script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`""
22+
$script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease")
1623

1724
if ($PSVersionTable.PSEdition -ne "Core") {
1825
Add-Type -Assembly System.IO.Compression.FileSystem
@@ -179,7 +186,7 @@ task TestProtocol -If { !$script:IsUnix} {
179186
task TestHost -If { !$script:IsUnix} {
180187
Set-Location .\test\PowerShellEditorServices.Test.Host\
181188
exec { & $script:dotnetExe build -c $Configuration -f net452 }
182-
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild -x86 }
189+
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
183190
}
184191

185192
task CITest ?Test, {
@@ -220,6 +227,67 @@ task LayoutModule -After Build {
220227
}
221228
}
222229

230+
task RestorePsesModules -After Build {
231+
$submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar
232+
Write-Host "`nRestoring EditorServices modules..."
233+
234+
# Read in the modules.json file as a hashtable so it can be splatted
235+
$moduleInfos = @{}
236+
237+
(Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
238+
$name = $_.Name
239+
$body = @{
240+
Name = $name
241+
MinimumVersion = $_.Value.MinimumVersion
242+
MaximumVersion = $_.Value.MaximumVersion
243+
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
244+
Path = $submodulePath
245+
}
246+
247+
if (-not $name)
248+
{
249+
throw "EditorServices module listed without name in '$ModulesJsonPath'"
250+
}
251+
252+
if ($script:SaveModuleSupportsAllowPrerelease)
253+
{
254+
$body += @{ AllowPrerelease = $_.Value.AllowPrerelease }
255+
}
256+
257+
$moduleInfos.Add($name, $body)
258+
}
259+
260+
# Save each module in the modules.json file
261+
foreach ($moduleName in $moduleInfos.Keys)
262+
{
263+
if (Test-Path -Path (Join-Path -Path $submodulePath -ChildPath $moduleName))
264+
{
265+
Write-Host "`tModule '${moduleName}' already detected. Skipping"
266+
continue
267+
}
268+
269+
$moduleInstallDetails = $moduleInfos[$moduleName]
270+
271+
$splatParameters = @{
272+
Name = $moduleName
273+
MinimumVersion = $moduleInstallDetails.MinimumVersion
274+
MaximumVersion = $moduleInstallDetails.MaximumVersion
275+
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
276+
Path = $submodulePath
277+
}
278+
279+
if ($script:SaveModuleSupportsAllowPrerelease)
280+
{
281+
$splatParameters += @{ AllowPrerelease = $moduleInstallDetails.AllowPrerelease }
282+
}
283+
284+
Write-Host "`tInstalling module: ${moduleName}"
285+
286+
Save-Module @splatParameters
287+
}
288+
Write-Host "`n"
289+
}
290+
223291
task BuildCmdletHelp {
224292
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
225293
}

module/Start-EditorServices.ps1 renamed to module/PowerShellEditorServices/Start-EditorServices.ps1

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
# canonical version of this script at the PowerShell Editor
1515
# Services GitHub repository:
1616
#
17-
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/Start-EditorServices.ps1
17+
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/PowerShellEditorServices/Start-EditorServices.ps1
1818

1919
param(
20-
[Parameter(Mandatory=$true)]
21-
[ValidateNotNullOrEmpty()]
22-
[string]
23-
$EditorServicesVersion,
24-
2520
[Parameter(Mandatory=$true)]
2621
[ValidateNotNullOrEmpty()]
2722
[string]
@@ -97,6 +92,13 @@ function ExitWithError($errorString) {
9792
exit 1;
9893
}
9994

95+
function WriteSessionFile($sessionInfo) {
96+
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
97+
Log "Writing session file with contents:"
98+
Log $sessionInfoJson
99+
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
100+
}
101+
100102
# Are we running in PowerShell 2 or earlier?
101103
if ($PSVersionTable.PSVersion.Major -le 2) {
102104
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
@@ -106,12 +108,6 @@ if ($PSVersionTable.PSVersion.Major -le 2) {
106108
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
107109
}
108110

109-
function WriteSessionFile($sessionInfo) {
110-
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
111-
Log "Writing session file with contents:"
112-
Log $sessionInfoJson
113-
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
114-
}
115111

116112
if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') {
117113
WriteSessionFile @{
@@ -244,32 +240,11 @@ if ((Test-ModuleAvailable "PowerShellGet") -eq $false) {
244240
# TODO: WRITE ERROR
245241
}
246242

247-
# Check if the expected version of the PowerShell Editor Services
248-
# module is installed
249-
$parsedVersion = New-Object System.Version @($EditorServicesVersion)
250-
if ((Test-ModuleAvailable "PowerShellEditorServices" $parsedVersion) -eq $false) {
251-
if ($ConfirmInstall -and $isPS5orLater) {
252-
# TODO: Check for error and return failure if necessary
253-
LogSection "Install PowerShellEditorServices"
254-
Install-Module "PowerShellEditorServices" -RequiredVersion $parsedVersion -Confirm
255-
}
256-
else {
257-
# Indicate to the client that the PowerShellEditorServices module
258-
# needs to be installed
259-
Write-Output "needs_install"
260-
}
261-
}
262-
263243
try {
264244
LogSection "Start up PowerShellEditorServices"
265245
Log "Importing PowerShellEditorServices"
266246

267-
if ($isPS5orLater) {
268-
Import-Module PowerShellEditorServices -RequiredVersion $parsedVersion -ErrorAction Stop
269-
}
270-
else {
271-
Import-Module PowerShellEditorServices -Version $parsedVersion -ErrorAction Stop
272-
}
247+
Import-Module PowerShellEditorServices -ErrorAction Stop
273248

274249
# Locate available port numbers for services
275250
Log "Searching for available socket port for the language service"

modules.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"PSScriptAnalyzer":{
3+
"MinimumVersion":"1.6",
4+
"MaximumVersion":"1.99",
5+
"AllowPrerelease":false
6+
},
7+
"Plaster":{
8+
"MinimumVersion":"1.0",
9+
"MaximumVersion":"1.99",
10+
"AllowPrerelease":false
11+
}
12+
}

0 commit comments

Comments
 (0)