Skip to content

Commit cb1d645

Browse files
author
Keen Yee Liau
committed
Add build script to package vsix
The current build process includes **everything** in the project, which leads to ~25mb of payload for the extension. By isolating the files that are actually needed, including node_modules, this could be reduced to about 460kb. Next step: use rollup to bundle the entire server, so that node_modules don't have to be included at all.
1 parent 1830d57 commit cb1d645

File tree

14 files changed

+88
-53
lines changed

14 files changed

+88
-53
lines changed

.vscode/settings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
2-
"editor.insertSpaces": false,
3-
"tslint.enable": true,
4-
"typescript.tsc.autoDetect": "off",
5-
"typescript.preferences.quoteStyle": "single"
6-
}
1+
{
2+
"editor.insertSpaces": true,
3+
"tslint.enable": true,
4+
"typescript.tsc.autoDetect": "off",
5+
"typescript.preferences.quoteStyle": "single"
6+
}

client/src/extension.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,34 @@ import { workspace, ExtensionContext } from 'vscode';
44
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RevealOutputChannelOn } from 'vscode-languageclient';
55

66
export function activate(context: ExtensionContext) {
7-
// The server is implemented in node
8-
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'src', 'server.js'));
9-
const options = {
10-
module: serverModule,
11-
transport: TransportKind.ipc,
12-
options: {
13-
env: {
14-
// Force TypeScript to use the non-polling version of the file watchers.
15-
TSC_NONPOLLING_WATCHER: true,
16-
},
17-
},
18-
};
197

208
// If the extension is launched in debug mode then the debug server options are used
219
// Otherwise the run options are used
2210
const serverOptions: ServerOptions = {
23-
run : options,
24-
debug: options,
11+
run : {
12+
module: context.asAbsolutePath(path.join('server', 'server.js')),
13+
transport: TransportKind.ipc,
14+
options: {
15+
env: {
16+
// Force TypeScript to use the non-polling version of the file watchers.
17+
TSC_NONPOLLING_WATCHER: true,
18+
},
19+
},
20+
},
21+
debug: {
22+
module: context.asAbsolutePath(path.join('server', 'out', 'server.js')),
23+
transport: TransportKind.ipc,
24+
options: {
25+
env: {
26+
// Force TypeScript to use the non-polling version of the file watchers.
27+
TSC_NONPOLLING_WATCHER: true,
28+
NG_DEBUG: true,
29+
},
30+
execArgv: [
31+
"--inspect=6009", // If this is changed, update .vscode/launch.json as well
32+
]
33+
},
34+
},
2535
}
2636

2737
// Options to control the language client

client/tsconfig.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
2+
"extends": "../tsconfig.json",
23
"compilerOptions": {
3-
"module": "commonjs",
4-
"target": "es2015",
5-
"outDir": "out",
6-
"rootDir": "src",
7-
"sourceMap": true,
8-
"strict": true
4+
"outDir": "out"
95
},
106
"include": ["src"],
11-
"exclude": ["node_modules", ".vscode-test"]
7+
"exclude": ["node_modules"]
128
}

integration/smoke_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ResponseEmitter extends EventEmitter {}
99
describe('Angular Language Service', () => {
1010
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; /* 10 seconds */
1111
const PROJECT_PATH = resolve(__dirname, '../project');
12-
const SERVER_PATH = resolve(__dirname, '../../server/out/src/server.js');
12+
const SERVER_PATH = resolve(__dirname, '../../server/out/server.js');
1313
const responseEmitter = new ResponseEmitter();
1414
let server: ChildProcess;
1515

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222
],
2323
"main": "./client/out/extension",
2424
"scripts": {
25-
"vscode:prepublish": "cd client && yarn update-vscode && cd .. && yarn compile",
2625
"compile": "tsc -b",
2726
"watch": "tsc -b -w",
2827
"postinstall": "cd client && yarn && cd ../server && yarn && cd ..",
2928
"package": "rm -rf dist && node scripts/package.js",
30-
"test": "tsc -b server/tests && jasmine server/out/tests/*_spec.js",
29+
"test": "tsc -b server/src/tests && jasmine server/out/tests/*_spec.js",
3130
"test:integration": "tsc -b integration && jasmine integration/out/*_spec.js"
3231
},
32+
"dependencies": {
33+
"typescript": "~3.5.3"
34+
},
3335
"devDependencies": {
3436
"@types/jasmine": "^3.4.0",
3537
"@types/node": "^10.9.4",
3638
"jasmine": "^3.4.0",
37-
"typescript": "~3.5.3",
3839
"vsce": "^1.66.0",
3940
"vscode-jsonrpc": "^4.0.0"
4041
},

scripts/build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,29 @@ rm -rf server/out
88

99
# Build the client and server
1010
yarn run compile
11+
12+
rm -rf dist
13+
mkdir dist
14+
cp package.json yarn.lock angular.png README.md dist
15+
mkdir dist/client
16+
cp client/package.json client/yarn.lock dist/client
17+
cp client/out/*.js dist/client
18+
mkdir dist/server
19+
cp server/package.json server/yarn.lock dist/server
20+
cp server/out/*.js dist/server
21+
22+
pushd dist
23+
yarn install --production --ignore-scripts
24+
25+
pushd client
26+
yarn install --production --ignore-scripts
27+
popd
28+
29+
pushd server
30+
yarn install --production --ignore-scripts
31+
popd
32+
33+
sed -i -e 's#./client/out/extension#./client/extension#' package.json
34+
../node_modules/.bin/vsce package --yarn --out ngls.vsix
35+
36+
popd

scripts/cleanup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex -o pipefail
4+
5+
# Clean up from last build
6+
rm -rf client/out
7+
rm -rf server/out

server/tests/editorServices_spec.ts renamed to server/src/tests/editorServices_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {LineIndexSnapshot, ProjectService, ScriptInfo} from '../src/editorServices';
1+
import {LineIndexSnapshot, ProjectService, ScriptInfo} from '../editorServices';
22

33
import * as u from './test_utils';
44
import {QUICKSTART} from './test_data';
File renamed without changes.

server/tests/test_utils.ts renamed to server/src/tests/test_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ts from 'typescript';
2-
import {Logger, ProjectServiceHost} from '../src/editorServices';
2+
import {Logger, ProjectServiceHost} from '../editorServices';
33

44
export type MockData = string | MockDirectory;
55

0 commit comments

Comments
 (0)