Skip to content

Commit 1be200b

Browse files
Introduce Debug and Release configurations (#3775)
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, only builds PSES if not already copied, 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 b8c4e5d commit 1be200b

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
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 }}

extension-dev.code-workspace

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"options": {
8989
"cwd": "${workspaceFolder:Client}"
9090
},
91-
"command": "Invoke-Build LinkEditorServices,Build",
91+
"command": "Invoke-Build Build",
9292
"problemMatcher": [
9393
"$msCompile",
9494
"$tsc"
@@ -104,7 +104,7 @@
104104
"options": {
105105
"cwd": "${workspaceFolder:Client}"
106106
},
107-
"command": "Invoke-Build LinkEditorServices,Test",
107+
"command": "Invoke-Build Test",
108108
"problemMatcher": [
109109
"$msCompile",
110110
"$tsc"
@@ -156,7 +156,6 @@
156156
"options": [
157157
"Restore",
158158
"Clean",
159-
"LinkEditorServices",
160159
"Build",
161160
"Test",
162161
"Package"

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

+53-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,50 @@ 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+
# We only build if it hasn't been built at all.
65+
if (!(Test-Path "$(Split-Path (Get-EditorServicesPath))/module/PowerShellEditorServices/bin")) {
66+
Write-Host "`n### Building PSES`n" -ForegroundColor Green
67+
Invoke-Build Build (Get-EditorServicesPath)
68+
}
69+
70+
Write-Host "`n### Copying PSES`n" -ForegroundColor Green
71+
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
72+
}
73+
}
74+
}
75+
}
76+
77+
task Restore RestoreEditorServices, RestoreNodeModules
3778

79+
#endregion
3880
#region Clean tasks
3981

4082
task Clean {
4183
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
84+
remove ./modules, ./out, ./node_modules, *.vsix
4585
}
4686

4787
task CleanEditorServices -If (Get-EditorServicesPath) {
@@ -52,24 +92,10 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
5292
#endregion
5393
#region Build tasks
5494

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-
}
95+
task Build Restore, {
96+
Write-Host "`n### Building vscode-powershell`n" -ForegroundColor Green
97+
assert (Test-Path ./modules/PowerShellEditorServices/bin) "Extension requires PSES"
6598

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
7399
# TODO: TSLint is deprecated and we need to switch to ESLint.
74100
# https://github.com/PowerShell/vscode-powershell/pull/3331
75101
exec { & npm run lint }
@@ -80,7 +106,10 @@ task Build CopyEditorServices, Restore, {
80106
# Code test runner expects individual files (and globs them at runtime).
81107
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
82108
# https://github.com/evanw/esbuild/issues/944
83-
exec { & npm run build }
109+
switch ($Configuration) {
110+
"Debug" { exec { & npm run build -- --sourcemap } }
111+
"Release" { exec { & npm run build -- --minify } }
112+
}
84113
}
85114

86115
#endregion
@@ -97,7 +126,6 @@ task TestEditorServices -If (Get-EditorServicesPath) {
97126
}
98127

99128
#endregion
100-
101129
#region Package tasks
102130

103131
task UpdateReadme -If { $script:IsPreviewExtension } {
@@ -117,10 +145,8 @@ task UpdateReadme -If { $script:IsPreviewExtension } {
117145
}
118146

119147
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-
123148
Write-Host "`n### Packaging $($script:PackageJson.name)-$($script:PackageJson.version).vsix`n" -ForegroundColor Green
149+
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
124150
exec { & npm run package }
125151
}
126152

0 commit comments

Comments
 (0)