This repository was archived by the owner on Nov 26, 2019. It is now read-only.
forked from sourcegraph/javascript-typescript-langserver
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependency-manager.ts
More file actions
90 lines (78 loc) · 2.61 KB
/
dependency-manager.ts
File metadata and controls
90 lines (78 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Logger } from './logging';
import { spawnSync } from 'child_process'
import * as fs from 'mz/fs';
import { resolve } from 'path';
// import * as rimraf from 'rimraf';
// import { promisify } from 'util';
export class DependencyManager {
// private rimrafAysnc = promisify(rimraf);
constructor(readonly rootPath: string, readonly logger: Logger, readonly gitHostWhitelist: string[]) { }
public installDependency(): void {
try {
this.runNpm()
} catch (e) {
console.debug(e)
}
// TO check if this is neccessary if we just download deps inside the workspace
// await Promise.all(iterare.default(this.packageManager.packageJsonUris()).map(
// async uri => {
// console.log(uri)
// }
// ))
}
public shutdown(): void {
// TODO check the best way to kill
// TODO is this sync or async
// console.debug('shutdowwn')
// this.npmProcess.kill('SIGKILL')
}
public runNpm(): void {
const env = Object.create(process.env);
env.TERM = 'dumb';
const cwd = this.rootPath;
// let cmd = 'yarn';
//
// if (existsSync(resolve(cwd, 'package-lock.json'))) {
// cmd = 'npm'
// }
if (!fs.existsSync(resolve(cwd, 'package.json'))) {
return
}
const yarnScript = require.resolve('yarn/bin/yarn.js');
// console.error('Yarn script location' + yarnScript);
// this.npmProcess =
spawnSync(
process.execPath,
[
yarnScript,
'install',
'--json',
'--ignore-scripts', // no user script will be run
'--no-progress', // don't show progress
'--non-interactive',
'--ignore-engines', // ignore "incompatible module" error
'--ignore-optional',
'--no-bin-links',
'--production==false', // Otherwise not all deps will be downloaded
],
{
env,
cwd,
stdio: 'inherit',
}
)
// TODO filter deps
// this.deletePackageRecursively(this.rootPath);
// this.npmProcess.stdout.on('data', data => {
// console.debug('stdout: ' + data)
// })
//
// this.npmProcess.stderr.on('data', data => {
// console.debug('stderr:' + data)
// })
//
// this.npmProcess.on('error', err => {
// console.debug('error:' + err)
// })
}
}