Skip to content

Commit f25d1b4

Browse files
Keen Yee Liauayazhafiz
authored andcommitted
build: Add rollup to build pipeline (#403)
PR closes #393
1 parent 87b119a commit f25d1b4

File tree

12 files changed

+179
-18
lines changed

12 files changed

+179
-18
lines changed

client/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
2323
// Otherwise the run options are used
2424
const serverOptions: lsp.ServerOptions = {
2525
run: {
26-
module: context.asAbsolutePath(path.join('server', 'server.js')),
26+
module: context.asAbsolutePath(path.join('server')),
2727
transport: lsp.TransportKind.ipc,
2828
args: [
2929
'--logFile',
@@ -40,7 +40,7 @@ export function activate(context: vscode.ExtensionContext) {
4040
},
4141
},
4242
debug: {
43-
module: context.asAbsolutePath(path.join('server', 'out', 'server.js')),
43+
module: context.asAbsolutePath(path.join('dist', 'server')),
4444
transport: lsp.TransportKind.ipc,
4545
args: [
4646
'--logFile',

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
],
3232
"main": "./client/out/extension",
3333
"scripts": {
34-
"compile": "tsc -b",
34+
"compile": "tsc -b && rollup -c",
3535
"compile:test": "tsc -b server/src/tests",
3636
"compile:integration": "tsc -b integration",
3737
"format": "scripts/format.sh",
38-
"watch": "tsc -b -w",
38+
"watch": "tsc -b -w & rollup -c -w",
3939
"postinstall": "vscode-install && cd client && yarn && cd ../server && yarn && cd ..",
4040
"package": "rm -rf dist && node scripts/package.js",
4141
"test": "yarn compile:test && jasmine server/out/tests/*_spec.js",
@@ -50,6 +50,9 @@
5050
"@types/node": "^10.9.4",
5151
"clang-format": "^1.2.4",
5252
"jasmine": "^3.4.0",
53+
"rollup": "^1.23.1",
54+
"rollup-plugin-commonjs": "^10.1.0",
55+
"rollup-plugin-node-resolve": "^5.2.0",
5356
"tslint": "^5.19.0",
5457
"tslint-eslint-rules": "^5.4.0",
5558
"vsce": "^1.66.0",

rollup.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as fs from 'fs';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import nodeResolve from 'rollup-plugin-node-resolve';
4+
5+
module.exports = [
6+
{
7+
input: 'client/out/extension.js',
8+
output: {
9+
file: 'dist/client/index.js',
10+
format: 'cjs',
11+
exports: 'named',
12+
},
13+
external: [
14+
'path',
15+
'vscode',
16+
'vscode-languageclient',
17+
],
18+
plugins: [
19+
nodeResolve(),
20+
commonjs(),
21+
],
22+
},
23+
{
24+
input: 'server/out/server.js',
25+
output: {
26+
file: 'dist/server/index.js',
27+
format: 'amd',
28+
banner: fs.readFileSync('server/src/banner.js', 'utf8'),
29+
},
30+
external: [
31+
'fs',
32+
'path',
33+
'typescript/lib/tsserverlibrary',
34+
'vscode-languageserver',
35+
'vscode-uri',
36+
],
37+
plugins: [
38+
nodeResolve(),
39+
commonjs(),
40+
],
41+
},
42+
];

scripts/build.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ set -ex -o pipefail
55
# Clean up from last build
66
rm -rf client/out
77
rm -rf server/out
8+
rm -rf dist
89

910
# Build the client and server
1011
yarn run compile
1112

12-
rm -rf dist
13-
mkdir dist
13+
# Copy files to package root
1414
cp package.json yarn.lock angular.png README.md dist
15-
mkdir dist/client
15+
# Copy files to client directory
1616
cp client/package.json client/yarn.lock dist/client
17-
cp client/out/*.js dist/client
18-
mkdir dist/server
17+
# Copy files to server directory
1918
cp server/package.json server/yarn.lock dist/server
20-
cp server/out/*.js dist/server
2119

2220
pushd dist
2321
yarn install --production --ignore-scripts
@@ -30,7 +28,7 @@ pushd server
3028
yarn install --production --ignore-scripts
3129
popd
3230

33-
sed -i -e 's#./client/out/extension#./client/extension#' package.json
31+
sed -i -e 's#./client/out/extension#./client#' package.json
3432
../node_modules/.bin/vsce package --yarn --out ngls.vsix
3533

3634
popd

server/src/banner.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function define(modules, cb) {
2+
function parseStringArray(argName) {
3+
const index = process.argv.indexOf(argName);
4+
if (index < 0 || index === process.argv.length - 1) {
5+
return [];
6+
}
7+
const arg = process.argv[index + 1];
8+
return arg.split(',');
9+
}
10+
const TSSERVER = 'typescript/lib/tsserverlibrary';
11+
let tsserverPath;
12+
try {
13+
tsserverPath = require.resolve(TSSERVER, {
14+
paths: parseStringArray('--typeScriptProbeLocations'),
15+
});
16+
}
17+
catch {}
18+
const resolvedModules = modules.map(m => {
19+
if (m === 'typescript') {
20+
throw new Error(`'typescript' should never be used. Use '${TSSERVER}' instead.`)
21+
}
22+
if (tsserverPath && m === TSSERVER) {
23+
return require(tsserverPath);
24+
}
25+
return require(m);
26+
});
27+
cb(...resolvedModules);
28+
}

server/src/diagnostic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as ts from 'typescript/lib/tsserverlibrary'; // used as value
9+
import * as ts from 'typescript/lib/tsserverlibrary';
1010
import * as lsp from 'vscode-languageserver';
1111
import {tsTextSpanToLspRange} from './utils';
1212

server/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as fs from 'fs';
1010
import * as path from 'path';
11-
import * as ts from 'typescript/lib/tsserverlibrary'; // used as value
11+
import * as ts from 'typescript/lib/tsserverlibrary';
1212

1313
// NOTES:
1414
// Be very careful about logging. There are two types of logging:

server/src/project_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as ts from 'typescript/lib/tsserverlibrary'; // used as value
9+
import * as ts from 'typescript/lib/tsserverlibrary';
1010
import * as lsp from 'vscode-languageserver';
1111

1212
import {tsDiagnosticToLspDiagnostic} from './diagnostic';

server/src/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as ts from 'typescript/lib/tsserverlibrary'; // used as value
9+
import * as ts from 'typescript/lib/tsserverlibrary';
1010
import * as lsp from 'vscode-languageserver';
1111

1212
import {tsCompletionEntryToLspCompletionItem} from './completion';
@@ -48,6 +48,7 @@ const {tsProjSvc} = projSvc;
4848
const EMPTY_RANGE = lsp.Range.create(0, 0, 0, 0);
4949

5050
// Log initialization info
51+
connection.console.info(`TypeScript version: ${ts.version}`);
5152
connection.console.info(`Log file: ${logger.getLogFileName()}`);
5253
if (process.env.NG_DEBUG) {
5354
logger.info('Angular Language Service is under DEBUG mode');

server/src/server_host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as ts from 'typescript/lib/tsserverlibrary'; // used as value
9+
import * as ts from 'typescript/lib/tsserverlibrary';
1010

1111
/**
1212
* `ServerHost` is a wrapper around `ts.sys` for the Node system. In Node, all

0 commit comments

Comments
 (0)