From 9e28913c3761ee2bae7c2cf8f27ba93990b555a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4fer?= Date: Fri, 31 Jan 2020 13:23:52 +0100 Subject: [PATCH] [BUILD][VSC] Use webpack as building method In order to keep the size of the extension rather small the building method has been changed to webpack. This also brings the benefit of excluding files that aren't really needed. --- .gitignore | 1 + vscode/build.gradle | 4 +-- vscode/package.json | 23 +++++++++++------ vscode/src/core/saros-extension.ts | 8 ++++-- vscode/src/core/saros-server.ts | 12 +++------ vscode/src/extension.ts | 2 +- vscode/webpack.config.js | 41 ++++++++++++++++++++++++++++++ 7 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 vscode/webpack.config.js diff --git a/.gitignore b/.gitignore index 214c9a634f..3d1f281cc7 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ vscode*/.vscode *.vscode *.code-workspace *.vscodeignore +dist/ diff --git a/vscode/build.gradle b/vscode/build.gradle index be36f0d8ae..51d5cca412 100644 --- a/vscode/build.gradle +++ b/vscode/build.gradle @@ -36,13 +36,13 @@ npmInstall { task copyLsp(type: Copy) { from("$rootProject.projectDir/build/distribution/lsp") - into('out') + into('dist') } task buildExtension(dependsOn: [ 'copyLsp', 'npmInstall', - 'npm_run_compile' + 'npm_run_webpack' ]) { group 'VS Code' description 'Builds the extension' diff --git a/vscode/package.json b/vscode/package.json index 9a463ff99c..5e874d0292 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -2,7 +2,11 @@ "name": "saros", "displayName": "saros", "description": "Saros implementation for VS Code.", - "version": "0.0.2", + "version": "0.0.1", + "publisher": "mschaefer", + "repository": { + "url": "https://github.com/saros-project/saros" + }, "engines": { "vscode": "^1.38.0" }, @@ -12,7 +16,7 @@ "activationEvents": [ "*" ], - "main": "./out/extension.js", + "main": "./dist/extension", "contributes": { "commands": [ { @@ -40,9 +44,10 @@ } }, "scripts": { - "vscode:prepublish": "npm run compile", - "compile": "tsc -p ./", - "watch": "tsc -watch -p ./", + "vscode:prepublish": "webpack --mode production", + "webpack": "webpack --mode development", + "webpack-dev": "webpack --mode development --watch", + "test-compile": "tsc -p ./", "pretest": "npm run compile", "test": "node ./out/test/runTest.js" }, @@ -53,13 +58,15 @@ "@types/vscode": "^1.38.0", "glob": "^7.1.4", "mocha": "^6.1.4", - "typescript": "^3.3.1", + "ts-loader": "^6.2.1", "tslint": "^5.12.1", + "typescript": "^3.3.1", + "vsce": "^1.71.0", "vscode-test": "^1.2.0", - "vsce": "^1.71.0" + "webpack": "^4.41.5", + "webpack-cli": "^3.3.10" }, "dependencies": { - "node-jre": "^0.2.3", "vscode-languageclient": "^5.2.1" } } diff --git a/vscode/src/core/saros-extension.ts b/vscode/src/core/saros-extension.ts index e13395940e..d757db6577 100644 --- a/vscode/src/core/saros-extension.ts +++ b/vscode/src/core/saros-extension.ts @@ -42,16 +42,18 @@ export class SarosExtension { * @memberof SarosExtension */ async init() { + if(!this.context) { return Promise.reject('Context not set'); } - try { + try { let self = this; return new Promise((resolve, reject) => { + const server = new SarosServer(self.context); - self.client = new SarosClient('sarosServer', 'Saros Server', server.getStartFunc(), this.createClientOptions()); + self.client = new SarosClient('sarosServer', 'Saros Server', server.getStartFunc(), this.createClientOptions()); self.context.subscriptions.push(self.client.start()); resolve(); @@ -70,9 +72,11 @@ export class SarosExtension { */ async onReady() { if(!this.client) { + console.log("onReady.reject"); return Promise.reject('SarosExtension is not initialized'); } + console.log("onReady"); return this.client.onReady(); } diff --git a/vscode/src/core/saros-server.ts b/vscode/src/core/saros-server.ts index 09386febc8..9614b93845 100644 --- a/vscode/src/core/saros-server.ts +++ b/vscode/src/core/saros-server.ts @@ -96,16 +96,10 @@ export class SarosServer { */ private startProcess(...args: any[]): SarosServer { - var pathToJar = path.resolve(this.context.extensionPath, 'out', 'saros.lsp.jar'); - var jre = require('node-jre'); + var pathToJar = path.resolve(this.context.extensionPath, 'dist', 'saros.lsp.jar'); console.log('spawning jar process'); - this.process = jre.spawn( - [pathToJar], - 'saros.lsp.SarosLauncher', - args, - { encoding: 'utf8' } - ) as process.ChildProcess; + this.process = process.spawn('java', ['-jar', pathToJar].concat(args)); return this; } @@ -120,7 +114,7 @@ export class SarosServer { * @memberof SarosServer */ private withDebug(isEnabled: boolean): SarosServer { - + if(this.process === undefined) { throw new Error('Server process is undefined'); } diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index 83066c448b..46d39b318d 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -19,6 +19,7 @@ export function activate(context: vscode.ExtensionContext) { console.log('Extension "Saros" is now active!'); }) .catch(reason => { + console.log(reason); vscode.window.showErrorMessage('Saros extension did not start propertly.' + 'Reason: ' + reason); //TODO: restart feature }); @@ -35,7 +36,6 @@ function createStatusBar(): Disposable { let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MAX_VALUE); statusBarItem.text = "Saros"; - statusBarItem.command = "saros.start"; statusBarItem.show(); return statusBarItem; diff --git a/vscode/webpack.config.js b/vscode/webpack.config.js new file mode 100644 index 0000000000..a76643bba5 --- /dev/null +++ b/vscode/webpack.config.js @@ -0,0 +1,41 @@ +//@ts-check + +'use strict'; + +const path = require('path'); + +/**@type {import('webpack').Configuration}*/ +const config = { + target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ + + entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ + output: { + // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ + path: path.resolve(__dirname, 'dist'), + filename: 'extension.js', + libraryTarget: 'commonjs2', + devtoolModuleFilenameTemplate: '../[resource-path]' + }, + devtool: 'source-map', + externals: { + vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ + }, + resolve: { + // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: 'ts-loader' + } + ] + } + ] + } +}; +module.exports = config; \ No newline at end of file