Skip to content

Introduce Debug and Release configurations #3775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vsts-ci/templates/ci-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ steps:
script: |
Get-Module -ListAvailable Pester
Install-Module InvokeBuild -Scope CurrentUser -Force
Invoke-Build
Invoke-Build -Configuration Release
Write-Host "##vso[task.setvariable variable=vsixPath]$(Resolve-Path powershell-*.vsix)"
workingDirectory: $(Build.SourcesDirectory)/vscode-powershell
pwsh: ${{ parameters.pwsh }}
Expand Down
5 changes: 2 additions & 3 deletions extension-dev.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "Invoke-Build LinkEditorServices,Build",
"command": "Invoke-Build Build",
"problemMatcher": [
"$msCompile",
"$tsc"
Expand All @@ -104,7 +104,7 @@
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "Invoke-Build LinkEditorServices,Test",
"command": "Invoke-Build Test",
"problemMatcher": [
"$msCompile",
"$tsc"
Expand Down Expand Up @@ -156,7 +156,6 @@
"options": [
"Restore",
"Clean",
"LinkEditorServices",
"Build",
"Test",
"Package"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"main": "./out/main.js",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --sourcemap --bundle --minify --external:vscode --platform=node",
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --bundle --external:vscode --platform=node",
"test": "node ./out/test/runTests.js",
"package": "vsce package --no-gitHubIssueLinking",
"publish": "vsce publish"
Expand Down
80 changes: 53 additions & 27 deletions vscode-powershell.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Licensed under the MIT License.

param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[string]$EditorServicesRepoPath = $null
)

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

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

task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
#region Setup tasks

task RestoreNodeModules -If { !(Test-Path ./node_modules) } {
Write-Host "`n### Restoring vscode-powershell dependencies`n" -ForegroundColor Green
# When in a CI build use the --loglevel=error parameter so that
# package install warnings don't cause PowerShell to throw up
Expand All @@ -34,14 +38,50 @@ task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
}
}

task RestoreEditorServices -If (Get-EditorServicesPath) {
switch ($Configuration) {
"Debug" {
# When debugging, we always rebuild PSES and ensure its symlinked so
# that developers always have the latest local bits.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -ne "SymbolicLink") {
Write-Host "`n### Creating symbolic link to PSES" -ForegroundColor Green
remove ./modules
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
}

Write-Host "`n### Building PSES`n" -ForegroundColor Green
Invoke-Build Build (Get-EditorServicesPath)
}
"Release" {
# When releasing, we ensure the bits are not symlinked but copied,
# and only if they don't already exist.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -eq "SymbolicLink") {
Write-Host "`n### Deleting PSES symbolic link" -ForegroundColor Green
remove ./modules
}

if (!(Test-Path ./modules)) {
# We only build if it hasn't been built at all.
if (!(Test-Path "$(Split-Path (Get-EditorServicesPath))/module/PowerShellEditorServices/bin")) {
Write-Host "`n### Building PSES`n" -ForegroundColor Green
Invoke-Build Build (Get-EditorServicesPath)
}

Write-Host "`n### Copying PSES`n" -ForegroundColor Green
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
}
}
}
}

task Restore RestoreEditorServices, RestoreNodeModules

#endregion
#region Clean tasks

task Clean {
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
Remove-Item ./modules -Recurse -Force -ErrorAction Ignore
Remove-Item ./out -Recurse -Force -ErrorAction Ignore
Remove-Item ./node_modules -Recurse -Force -ErrorAction Ignore
remove ./modules, ./out, ./node_modules, *.vsix
}

task CleanEditorServices -If (Get-EditorServicesPath) {
Expand All @@ -52,24 +92,10 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
#endregion
#region Build tasks

task BuildEditorServices -If (Get-EditorServicesPath) {
Write-Host "`n### Building PowerShellEditorServices`n" -ForegroundColor Green
Invoke-Build Build (Get-EditorServicesPath)
}

task LinkEditorServices -If (Get-EditorServicesPath) BuildEditorServices, {
Write-Host "`n### For developer use only! Creating symbolic link to PSES" -ForegroundColor Green
Remove-Item ./modules -Recurse -Force -ErrorAction Ignore
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
}
task Build Restore, {
Write-Host "`n### Building vscode-powershell`n" -ForegroundColor Green
assert (Test-Path ./modules/PowerShellEditorServices/bin) "Extension requires PSES"

task CopyEditorServices -If { !(Test-Path ./modules) -and (Get-EditorServicesPath) } BuildEditorServices, {
Write-Host "`n### Copying PSES" -ForegroundColor Green
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
}

task Build CopyEditorServices, Restore, {
Write-Host "`n### Building vscode-powershell" -ForegroundColor Green
# TODO: TSLint is deprecated and we need to switch to ESLint.
# https://github.com/PowerShell/vscode-powershell/pull/3331
exec { & npm run lint }
Expand All @@ -80,7 +106,10 @@ task Build CopyEditorServices, Restore, {
# Code test runner expects individual files (and globs them at runtime).
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
# https://github.com/evanw/esbuild/issues/944
exec { & npm run build }
switch ($Configuration) {
"Debug" { exec { & npm run build -- --sourcemap } }
"Release" { exec { & npm run build -- --minify } }
}
}

#endregion
Expand All @@ -97,7 +126,6 @@ task TestEditorServices -If (Get-EditorServicesPath) {
}

#endregion

#region Package tasks

task UpdateReadme -If { $script:IsPreviewExtension } {
Expand All @@ -117,10 +145,8 @@ task UpdateReadme -If { $script:IsPreviewExtension } {
}

task Package UpdateReadme, Build, {
assert (Test-Path ./modules/PowerShellEditorServices)
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"

Write-Host "`n### Packaging $($script:PackageJson.name)-$($script:PackageJson.version).vsix`n" -ForegroundColor Green
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
exec { & npm run package }
}

Expand Down