Skip to content

Commit c301a87

Browse files
committed
Introduce Debug and Release configurations
The debug build creates a symlink to PSES, rebuilds PSES, does not minify the extension and generates a TypeScript sourcemap. The release build deletes the symlink if it exists and copies PSES, does not rebuild PSES, minifies the extension and does not generate a TypeScript sourcemap. This removes the manual `LinkEditorServices` step and ensures that the developer debugging experience works well.
1 parent 709376e commit c301a87

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

.vsts-ci/templates/ci-general.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ steps:
4848
script: |
4949
Get-Module -ListAvailable Pester
5050
Install-Module InvokeBuild -Scope CurrentUser -Force
51-
Invoke-Build
51+
Invoke-Build -Configuration Release
5252
Write-Host "##vso[task.setvariable variable=vsixPath]$(Resolve-Path powershell-*.vsix)"
5353
workingDirectory: $(Build.SourcesDirectory)/vscode-powershell
5454
pwsh: ${{ parameters.pwsh }}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"main": "./out/main.js",
7979
"scripts": {
8080
"lint": "tslint --project tsconfig.json",
81-
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --sourcemap --bundle --minify --external:vscode --platform=node",
81+
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --bundle --external:vscode --platform=node",
8282
"test": "node ./out/test/runTests.js",
8383
"package": "vsce package --no-gitHubIssueLinking",
8484
"publish": "vsce publish"

vscode-powershell.build.ps1

+47-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the MIT License.
33

44
param(
5+
[ValidateSet("Debug", "Release")]
6+
[string]$Configuration = "Debug",
57
[string]$EditorServicesRepoPath = $null
68
)
79

@@ -10,7 +12,7 @@ param(
1012
# Grab package.json data which is used throughout the build.
1113
$script:PackageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
1214
$script:IsPreviewExtension = $script:PackageJson.name -like "*preview*" -or $script:PackageJson.displayName -like "*preview*"
13-
Write-Host "`n### Extension Version: $($script:PackageJson.version) Extension Name: $($script:PackageJson.name)`n" -ForegroundColor Green
15+
Write-Host "`n### Extension: $($script:PackageJson.name)-$($script:PackageJson.version)`n" -ForegroundColor Green
1416

1517
function Get-EditorServicesPath {
1618
$psesRepoPath = if ($EditorServicesRepoPath) {
@@ -23,7 +25,9 @@ function Get-EditorServicesPath {
2325
return Resolve-Path "$psesRepoPath/PowerShellEditorServices.build.ps1" -ErrorAction Continue
2426
}
2527

26-
task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
28+
#region Setup tasks
29+
30+
task RestoreNodeModules -If { !(Test-Path ./node_modules) } {
2731
Write-Host "`n### Restoring vscode-powershell dependencies`n" -ForegroundColor Green
2832
# When in a CI build use the --loglevel=error parameter so that
2933
# package install warnings don't cause PowerShell to throw up
@@ -34,14 +38,44 @@ task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
3438
}
3539
}
3640

41+
task RestoreEditorServices -If (Get-EditorServicesPath) {
42+
switch ($Configuration) {
43+
"Debug" {
44+
# When debugging, we always rebuild PSES and ensure its symlinked so
45+
# that developers always have the latest local bits.
46+
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -ne "SymbolicLink") {
47+
Write-Host "`n### Creating symbolic link to PSES" -ForegroundColor Green
48+
remove ./modules
49+
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
50+
}
51+
52+
Write-Host "`n### Building PSES`n" -ForegroundColor Green
53+
Invoke-Build Build (Get-EditorServicesPath)
54+
}
55+
"Release" {
56+
# When releasing, we ensure the bits are not symlinked but copied,
57+
# and only if they don't already exist.
58+
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -eq "SymbolicLink") {
59+
Write-Host "`n### Deleting PSES symbolic link" -ForegroundColor Green
60+
remove ./modules
61+
}
62+
63+
if (!(Test-Path ./modules)) {
64+
Write-Host "`n### Copying PSES`n" -ForegroundColor Green
65+
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
66+
}
67+
}
68+
}
69+
}
70+
71+
task Restore RestoreEditorServices, RestoreNodeModules
3772

73+
#endregion
3874
#region Clean tasks
3975

4076
task Clean {
4177
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
42-
Remove-Item ./modules -Recurse -Force -ErrorAction Ignore
43-
Remove-Item ./out -Recurse -Force -ErrorAction Ignore
44-
Remove-Item ./node_modules -Recurse -Force -ErrorAction Ignore
78+
remove ./modules, ./out, ./node_modules, *.vsix
4579
}
4680

4781
task CleanEditorServices -If (Get-EditorServicesPath) {
@@ -52,24 +86,10 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
5286
#endregion
5387
#region Build tasks
5488

55-
task BuildEditorServices -If (Get-EditorServicesPath) {
56-
Write-Host "`n### Building PowerShellEditorServices`n" -ForegroundColor Green
57-
Invoke-Build Build (Get-EditorServicesPath)
58-
}
59-
60-
task LinkEditorServices -If (Get-EditorServicesPath) BuildEditorServices, {
61-
Write-Host "`n### For developer use only! Creating symbolic link to PSES" -ForegroundColor Green
62-
Remove-Item ./modules -Recurse -Force -ErrorAction Ignore
63-
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
64-
}
89+
task Build Restore, {
90+
Write-Host "`n### Building vscode-powershell`n" -ForegroundColor Green
91+
assert (Test-Path ./modules/PowerShellEditorServices) "Extension requires PSES"
6592

66-
task CopyEditorServices -If { !(Test-Path ./modules) -and (Get-EditorServicesPath) } BuildEditorServices, {
67-
Write-Host "`n### Copying PSES" -ForegroundColor Green
68-
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
69-
}
70-
71-
task Build CopyEditorServices, Restore, {
72-
Write-Host "`n### Building vscode-powershell" -ForegroundColor Green
7393
# TODO: TSLint is deprecated and we need to switch to ESLint.
7494
# https://github.com/PowerShell/vscode-powershell/pull/3331
7595
exec { & npm run lint }
@@ -80,7 +100,10 @@ task Build CopyEditorServices, Restore, {
80100
# Code test runner expects individual files (and globs them at runtime).
81101
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
82102
# https://github.com/evanw/esbuild/issues/944
83-
exec { & npm run build }
103+
switch ($Configuration) {
104+
"Debug" { exec { & npm run build -- --sourcemap } }
105+
"Release" { exec { & npm run build -- --minify } }
106+
}
84107
}
85108

86109
#endregion
@@ -97,7 +120,6 @@ task TestEditorServices -If (Get-EditorServicesPath) {
97120
}
98121

99122
#endregion
100-
101123
#region Package tasks
102124

103125
task UpdateReadme -If { $script:IsPreviewExtension } {
@@ -117,10 +139,8 @@ task UpdateReadme -If { $script:IsPreviewExtension } {
117139
}
118140

119141
task Package UpdateReadme, Build, {
120-
assert (Test-Path ./modules/PowerShellEditorServices)
121-
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
122-
123142
Write-Host "`n### Packaging $($script:PackageJson.name)-$($script:PackageJson.version).vsix`n" -ForegroundColor Green
143+
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
124144
exec { & npm run package }
125145
}
126146

0 commit comments

Comments
 (0)