From 3c19b64998a1f0c44b26e09b2e44acb91d93b381 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 8 Sep 2021 11:02:22 -0700 Subject: [PATCH 1/5] Add `esbuild` dev dependency for bundling --- package-lock.json | 17 +++++++++++++++++ package.json | 1 + 2 files changed, 18 insertions(+) diff --git a/package-lock.json b/package-lock.json index 631db92bef..866a607edf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "@types/uuid": "~8.3.1", "@types/vscode": "~1.56.0", "@vscode/test-electron": "~1.6.2", + "esbuild": "^0.12.25", "mocha": "~9.1.1", "mocha-junit-reporter": "~2.0.0", "mocha-multi-reporters": "~1.5.1", @@ -1034,6 +1035,16 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/esbuild": { + "version": "0.12.25", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.25.tgz", + "integrity": "sha512-woie0PosbRSoN8gQytrdCzUbS2ByKgO8nD1xCZkEup3D9q92miCze4PqEI9TZDYAuwn6CruEnQpJxgTRWdooAg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -4706,6 +4717,12 @@ "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==", "dev": true }, + "esbuild": { + "version": "0.12.25", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.25.tgz", + "integrity": "sha512-woie0PosbRSoN8gQytrdCzUbS2ByKgO8nD1xCZkEup3D9q92miCze4PqEI9TZDYAuwn6CruEnQpJxgTRWdooAg==", + "dev": true + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", diff --git a/package.json b/package.json index ca0b77938a..26f585fd56 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "@types/uuid": "~8.3.1", "@types/vscode": "~1.56.0", "@vscode/test-electron": "~1.6.2", + "esbuild": "^0.12.25", "mocha": "~9.1.1", "mocha-junit-reporter": "~2.0.0", "mocha-multi-reporters": "~1.5.1", From d6446de1f2a2542975760e403296868acec85506 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 10 Sep 2021 16:04:47 -0700 Subject: [PATCH 2/5] Setup bundling and fix tasks While we need to bundle the extension code with `eslint` we still have to use `tsc` for the tests, which is annoying. This also fixes are (already broken) VS Code launch tasks! --- .vscode/launch.json | 22 +++++++++---------- .vscodeignore | 43 ++++++++++++++++++++----------------- package.json | 6 +++--- tsconfig.json | 30 ++++++++++++++------------ vscode-powershell.build.ps1 | 12 ++++++++++- 5 files changed, 63 insertions(+), 50 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 34b28e7083..467945da05 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,13 +7,11 @@ "request": "launch", "runtimeExecutable": "${execPath}", "args": [ - "--extensionDevelopmentPath=${workspaceRoot}" + "--disable-extensions", + "--extensionDevelopmentPath=${workspaceFolder}" ], - "stopOnEntry": false, "sourceMaps": true, - "outFiles": [ - "${workspaceFolder}/out/src/**/*.js" - ], + "outFiles": [ "${workspaceFolder}/out/main.js" ], "preLaunchTask": "Build" }, { @@ -22,15 +20,15 @@ "request": "launch", "runtimeExecutable": "${execPath}", "args": [ - "--disable-extensions", - "ms-vscode.powershell-preview", + // The tests require Code be opened with a workspace, which exists in + // `test`, but this has to be passed as a CLI argument, not just `cwd`. + "${workspaceFolder}/test", + "--disableExtensions", "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/out/test/testRunner.js", - "${workspaceFolder}/test" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js" + "--extensionTestsPath=${workspaceFolder}/out/test/index.js", ], + "sourceMaps": true, + "outFiles": [ "${workspaceFolder}/out/test/**/*.js" ], "preLaunchTask": "Build" }, { diff --git a/.vscodeignore b/.vscodeignore index e38118a072..d04733defc 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,24 +1,27 @@ -.vscode/** -.vscode-test/** -vscode-powershell.build.ps1 -typings/** -**/*.ts +.github/ +.poshchan/ +.vscode/ +.vscode-test/ +.vsts-ci/ +logs/ +node_modules/ +out/ +scripts/ +sessions/ +src/ +test/ +tools/ + +!out/main.js + +.editorconfig +.gitattributes .gitignore -tsconfig.json -build/** -bin/EditorServices.log -bin/DebugAdapter.log -bin/*.vshost.* -bin/PowerShell/** -logs/** -out/test/** -test/** -sessions/** -scripts/Install-VSCode.ps1 -tools/** -.poshchan/** -.github/** -.vsts-ci/** +.markdownlint.json +.vscodeignore build.ps1 +extension-dev.code-workspace +*.vsix tsconfig.json tslint.json +vscode-powershell.build.ps1 diff --git a/package.json b/package.json index 26f585fd56..64086c08c2 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "type": "git", "url": "https://github.com/PowerShell/vscode-powershell.git" }, - "main": "./out/src/main", "activationEvents": [ "onDebugInitialConfigurations", "onDebugResolve:PowerShell", @@ -79,9 +78,10 @@ "extensionDependencies": [ "vscode.powershell" ], + "main": "./out/main.js", "scripts": { - "compile": "tsc -v && tsc -p ./ && tslint -p ./", - "compile-watch": "tsc -watch -p ./", + "lint": "tslint --project tsconfig.json", + "build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --sourcemap --bundle --minify --external:vscode --platform=node", "test": "node ./out/test/runTests.js", "package": "vsce package --no-gitHubIssueLinking", "publish": "vsce publish" diff --git a/tsconfig.json b/tsconfig.json index c2fa369ef5..1bfaad4864 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,18 @@ { - "compilerOptions": { - "rootDir": ".", - "module": "commonjs", - "target": "es6", - "outDir": "out", - "lib": [ - "es2017", - "DOM" - ], - "sourceMap": true - }, - "exclude": [ - "node_modules" - ] + "compilerOptions": { + // NOTE: The TypeScript compiler is only used for building the tests (and + // the sources which the tests need). The extension is built with `esbuild`. + "module": "commonjs", + "outDir": "out", + "target": "ES6", + "lib": [ "ES6", "DOM" ], + "sourceMap": true, + "rootDir": ".", + // TODO: We need to enable stricter checking... + // "strict": true, + // "noImplicitReturns": true, + // "noFallthroughCasesInSwitch": true, + // "noUnusedParameters": true + }, + "include": [ "src", "test" ], } diff --git a/vscode-powershell.build.ps1 b/vscode-powershell.build.ps1 index 8ae05d3222..33231e3ec0 100644 --- a/vscode-powershell.build.ps1 +++ b/vscode-powershell.build.ps1 @@ -64,7 +64,17 @@ task CopyEditorServices -If { !(Test-Path ./modules/PowerShellEditorServices) -a task Build CopyEditorServices, Restore, { Write-Host "`n### Building vscode-powershell" -ForegroundColor Green - exec { & npm run compile } + # TODO: TSLint is deprecated and we need to switch to ESLint. + # https://github.com/PowerShell/vscode-powershell/pull/3331 + exec { & npm run lint } + + # TODO: When supported we should use `esbuild` for the tests too. Although + # we now use `esbuild` to transpile, bundle, and minify the extension, we + # still use `tsc` to transpile everything in `src` and `test` because the VS + # 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 } } #endregion From 4a9d605e98518d8e05f35ed6ba46ae082a337718 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 10 Sep 2021 16:08:15 -0700 Subject: [PATCH 3/5] Fix relative paths in source now that extension is bundled Since bundling produces a single (bundled) file at `out/main.js` all the relative paths that expected `out/src/...` needed to drop one set of `../` to be correct. We cannot emit the bundled extension to `out/src/main.js` because, as mentioned previously, we still must transpile everything for the unit tests, so `out/src/` is already full. --- src/features/Examples.ts | 2 +- src/features/PesterTests.ts | 2 +- src/logging.ts | 2 +- src/main.ts | 4 ++-- src/settings.ts | 4 ++-- test/features/CustomViews.test.ts | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/features/Examples.ts b/src/features/Examples.ts index 13ac41fa92..94007b5d05 100644 --- a/src/features/Examples.ts +++ b/src/features/Examples.ts @@ -9,7 +9,7 @@ export class ExamplesFeature implements vscode.Disposable { private examplesPath: string; constructor() { - this.examplesPath = path.resolve(__dirname, "../../../examples"); + this.examplesPath = path.resolve(__dirname, "../../examples"); this.command = vscode.commands.registerCommand("PowerShell.OpenExamplesFolder", () => { vscode.commands.executeCommand( "vscode.openFolder", diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 759f6189a4..35d753f3b1 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -18,7 +18,7 @@ export class PesterTestsFeature implements vscode.Disposable { private invokePesterStubScriptPath: string; constructor(private sessionManager: SessionManager) { - this.invokePesterStubScriptPath = path.resolve(__dirname, "../../../modules/PowerShellEditorServices/InvokePesterStub.ps1"); + this.invokePesterStubScriptPath = path.resolve(__dirname, "../../modules/PowerShellEditorServices/InvokePesterStub.ps1"); // File context-menu command - Run Pester Tests this.command = vscode.commands.registerCommand( diff --git a/src/logging.ts b/src/logging.ts index 83f67f08c0..5faf23a3d2 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -40,7 +40,7 @@ export class Logger implements ILogger { constructor() { this.logChannel = vscode.window.createOutputChannel("PowerShell Extension Logs"); - this.logBasePath = path.resolve(__dirname, "../../logs"); + this.logBasePath = path.resolve(__dirname, "../logs"); utils.ensurePathExists(this.logBasePath); this.commands = [ diff --git a/src/main.ts b/src/main.ts index 6acecb0bc0..109dcf3afd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,7 +36,7 @@ import { LanguageClientConsumer } from "./languageClientConsumer"; // The most reliable way to get the name and version of the current extension. // tslint:disable-next-line: no-var-requires -const PackageJSON: any = require("../../package.json"); +const PackageJSON: any = require("../package.json"); // the application insights key (also known as instrumentation key) used for telemetry. const AI_KEY: string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217"; @@ -197,7 +197,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext, version: strin if (choice === showReleaseNotes) { vscode.commands.executeCommand( "markdown.showPreview", - vscode.Uri.file(path.resolve(__dirname, "../../CHANGELOG.md"))); + vscode.Uri.file(path.resolve(__dirname, "../CHANGELOG.md"))); } }); } diff --git a/src/settings.ts b/src/settings.ts index 57c57f8c26..1403512e95 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -157,7 +157,7 @@ export function load(): ISettings { const defaultDeveloperSettings: IDeveloperSettings = { featureFlags: [], - bundledModulesPath: "../../../PowerShellEditorServices/module", + bundledModulesPath: "../../PowerShellEditorServices/module", editorServicesLogLevel: "Normal", editorServicesWaitForDebugger: false, waitForSessionFileTimeoutSeconds: 240, @@ -234,7 +234,7 @@ export function load(): ISettings { promptToUpdatePackageManagement: configuration.get("promptToUpdatePackageManagement", true), bundledModulesPath: - "../../modules", + "../modules", useX86Host: configuration.get("useX86Host", false), enableProfileLoading: diff --git a/test/features/CustomViews.test.ts b/test/features/CustomViews.test.ts index 48816c9aaa..57b44075a1 100644 --- a/test/features/CustomViews.test.ts +++ b/test/features/CustomViews.test.ts @@ -70,7 +70,7 @@ hello content: "console.log('asdf');", }, { - fileName: "../testCustomViews.js", + fileName: "../../testCustomViews.js", content: "console.log('asdf');", }, ], @@ -78,7 +78,7 @@ hello expectedHtmlString: ` hello - + `, }, From 82c120de602632f7945cade4dfc8e2d914944a62 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 10 Sep 2021 16:11:11 -0700 Subject: [PATCH 4/5] Fix `isProcess64Bit` logic to support `arm64` (e.g. Apple M1) It's still 64-bit just not `x64`. --- src/platform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform.ts b/src/platform.ts index d72a97f108..9aee1e5d1a 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -49,7 +49,7 @@ export function getPlatformDetails(): IPlatformDetails { operatingSystem = OperatingSystem.Linux; } - const isProcess64Bit = process.arch === "x64"; + const isProcess64Bit = (process.arch === "x64" || process.arch === "arm64"); return { operatingSystem, From c629012a01181ed3f0354781706cfc8ea05aa72b Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 13 Sep 2021 10:30:13 -0700 Subject: [PATCH 5/5] Fix formatting of `extension-dev.code-workspace` --- extension-dev.code-workspace | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/extension-dev.code-workspace b/extension-dev.code-workspace index b7504e7b6d..fc9c8b1cfd 100644 --- a/extension-dev.code-workspace +++ b/extension-dev.code-workspace @@ -7,18 +7,18 @@ "path": "../PowerShellEditorServices" } ], - "settings": { - "files.associations": { - "**/snippets/*.json": "jsonc", - "**/.vsts-ci/**/*.yml": "azure-pipelines", - }, - "typescript.tsdk": "./node_modules/typescript/lib", - "powershell.codeFormatting.autoCorrectAliases": true, - "powershell.codeFormatting.newLineAfterCloseBrace": false, - "powershell.codeFormatting.trimWhitespaceAroundPipe": true, - "powershell.codeFormatting.useCorrectCasing": true, - "powershell.codeFormatting.whitespaceBeforeOpenBrace": false, - "powershell.codeFormatting.whitespaceBetweenParameters": true, - "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline" - } + "settings": { + "files.associations": { + "**/snippets/*.json": "jsonc", + "**/.vsts-ci/**/*.yml": "azure-pipelines", + }, + "typescript.tsdk": "./node_modules/typescript/lib", + "powershell.codeFormatting.autoCorrectAliases": true, + "powershell.codeFormatting.newLineAfterCloseBrace": false, + "powershell.codeFormatting.trimWhitespaceAroundPipe": true, + "powershell.codeFormatting.useCorrectCasing": true, + "powershell.codeFormatting.whitespaceBeforeOpenBrace": false, + "powershell.codeFormatting.whitespaceBetweenParameters": true, + "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline" + } }