Skip to content

Commit

Permalink
[BUILD][VSC] Use webpack as building method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mschaefer88 authored and Michael Schäfer committed Sep 14, 2020
1 parent 5a4dcc7 commit 9e28913
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ vscode*/.vscode
*.vscode
*.code-workspace
*.vscodeignore
dist/
4 changes: 2 additions & 2 deletions vscode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 15 additions & 8 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -12,7 +16,7 @@
"activationEvents": [
"*"
],
"main": "./out/extension.js",
"main": "./dist/extension",
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -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"
},
Expand All @@ -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"
}
}
8 changes: 6 additions & 2 deletions vscode/src/core/saros-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

Expand Down
12 changes: 3 additions & 9 deletions vscode/src/core/saros-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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;
Expand Down
41 changes: 41 additions & 0 deletions vscode/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9e28913

Please sign in to comment.