Skip to content

Commit c79d693

Browse files
authored
Merge branch 'master' into deduplicate-lsif-npm-identifiers
2 parents 9d4112f + b0c81c4 commit c79d693

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2256
-777
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
samples
3+
node_modules

.eslintrc.base.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module"
6+
},
7+
"env": {
8+
"node": true
9+
},
10+
"rules": {
11+
"semi": "error",
12+
"no-extra-semi": "warn",
13+
"curly": "warn",
14+
"quotes": ["error", "single", { "allowTemplateLiterals": true } ],
15+
"eqeqeq": "error",
16+
"indent": ["warn", "tab", { "SwitchCase": 1 } ]
17+
}
18+
}

.vscode/launch.json

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@
7575
"${workspaceFolder}/npm/lib/**/*.js"
7676
]
7777
},
78+
{
79+
"type": "node",
80+
"request": "launch",
81+
"name": "Repository Tests",
82+
"cwd": "${workspaceFolder}",
83+
"program": "${workspaceFolder}/build/azure-pipelines/tasks/lib/runLsif.js",
84+
"args": [
85+
"${workspaceFolder}/build/azure-pipelines/test-repositories/vscode-chat.json"
86+
],
87+
"preLaunchTask": "npm: watch:build",
88+
"sourceMaps": true,
89+
"outputCapture": "std",
90+
"outFiles": [
91+
"${workspaceFolder}/build/azure-pipelines/tasks/**/*.js"
92+
]
93+
},
7894
{
7995
"type": "node",
8096
"request": "launch",
@@ -100,7 +116,8 @@
100116
"program": "${workspaceFolder}/tsc/lib/main.js",
101117
"args": [
102118
"-p", "tsconfig.json",
103-
"--outputFormat", "line"
119+
"--outputFormat", "line",
120+
"--stdout"
104121
],
105122
"preLaunchTask": "npm: watch",
106123
"sourceMaps": true,
@@ -117,6 +134,7 @@
117134
"program": "${workspaceFolder}/tsc/lib/main.js",
118135
"args": [
119136
"-p", "tsconfig.json",
137+
"--out", "${workspaceFolder}/tmp/protocol.lsif",
120138
"--outputFormat", "line"
121139
],
122140
"preLaunchTask": "npm: watch",
@@ -130,7 +148,7 @@
130148
"type": "node",
131149
"request": "launch",
132150
"name": "mobx",
133-
"cwd": "${workspaceFolder}/../../connect-demo/mobx",
151+
"cwd": "${workspaceFolder}/../Playgrounds/lsif/mobx",
134152
"program": "${workspaceFolder}/tsc/lib/main.js",
135153
"args": [
136154
"-p", "tsconfig.json",
@@ -143,6 +161,25 @@
143161
"${workspaceFolder}/tsc/lib/**/*.js"
144162
]
145163
},
164+
{
165+
"type": "node",
166+
"request": "launch",
167+
"name": "rxjs",
168+
"cwd": "${workspaceFolder}/../Playgrounds/lsif/rxjs",
169+
"program": "${workspaceFolder}/tsc/lib/main.js",
170+
"args": [
171+
"-p", "tsconfig.json",
172+
"--projectRoot", "./",
173+
"--outputFormat", "line",
174+
"--out", "rxjs.lsif"
175+
],
176+
"preLaunchTask": "npm: watch",
177+
"sourceMaps": true,
178+
"outputCapture": "std",
179+
"outFiles": [
180+
"${workspaceFolder}/tsc/lib/**/*.js"
181+
]
182+
},
146183
{
147184
"type": "node",
148185
"request": "launch",
@@ -202,13 +239,13 @@
202239
"request": "launch",
203240
"name": "Blob Storage",
204241
"program": "${workspaceFolder}/sqlite/lib/main.js",
205-
"cwd": "${workspaceFolder}/samples/typescript",
242+
"cwd": "${workspaceFolder}/../Playgrounds/lsif/mobx",
206243
"args": [
207244
"--format", "blob",
208245
"--projectVersion", "1.0",
209246
"--delete",
210-
"--in", "./test.lsif",
211-
"--out", "./test.db"
247+
"--in", "./mobx.1.lsif",
248+
"--out", "./mobx.db"
212249
],
213250
"preLaunchTask": "npm: watch",
214251
"sourceMaps": true,

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@
77
"spellright.documentTypes": [
88
"markdown",
99
"latex"
10+
],
11+
"eslint.enable": true,
12+
"eslint.validate": [
13+
{ "language": "typescript", "autoFix": true }
14+
],
15+
"eslint.workingDirectories": [
16+
{ "directory": "./protocol", "changeProcessCWD": true },
17+
{ "directory": "./tsc", "changeProcessCWD": true },
18+
{ "directory": "./npm", "changeProcessCWD": true },
19+
{ "directory": "./sqlite", "changeProcessCWD": true },
20+
{ "directory": "./util", "changeProcessCWD": true }
1021
]
1122
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"type": "npm",
2323
"script": "watch",
2424
"isBackground": true,
25+
"runOptions": {
26+
"runOn": "folderOpen"
27+
},
2528
"problemMatcher": [
2629
"$tsc-watch"
2730
],
@@ -91,6 +94,15 @@
9194
"showReuseMessage": true,
9295
"clear": true
9396
}
97+
},
98+
{
99+
"type": "npm",
100+
"script": "watch:build",
101+
"problemMatcher": [
102+
"$tsc-watch"
103+
],
104+
"group": "build",
105+
"isBackground": true
94106
}
95107
]
96108
}

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ steps:
1515
displayName: 'Install dependencies'
1616

1717
- script: |
18+
npm run lint
1819
npm run compile
1920
displayName: 'Compile client'
2021

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
trigger:
2+
- none
3+
4+
pool:
5+
vmImage: 'Ubuntu-16.04'
6+
7+
steps:
8+
- task: NodeTool@0
9+
inputs:
10+
versionSpec: '10.*'
11+
displayName: 'Use Node.js 10.15.1'
12+
13+
- script: |
14+
npm ci
15+
displayName: 'Install dependencies'
16+
17+
- script: |
18+
npm run compile
19+
displayName: 'Compile client'
20+
21+
- script: |
22+
npm run test
23+
displayName: 'Run unit tests'
24+
25+
- script: |
26+
npm run compile:build
27+
displayName: 'Compiling test scrips'
28+
29+
- script: |
30+
node ./build/azure-pipelines/tasks/lib/runLsif.js ./build/azure-pipelines/test-repositories
31+
displayName: 'Running repository tests'
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
6+
import * as fs from 'fs';
7+
import * as os from 'os';
8+
import * as path from 'path';
9+
import * as cp from 'child_process';
10+
import * as util from 'util';
11+
12+
import * as shelljs from 'shelljs';
13+
14+
const exists = util.promisify(fs.exists);
15+
const readFile = util.promisify(fs.readFile);
16+
const stat = util.promisify(fs.stat);
17+
const readdir = util.promisify(fs.readdir);
18+
19+
const ROOT = path.join(__dirname, '..', '..', '..', '..');
20+
21+
interface DataFormat {
22+
name: string;
23+
repository: string;
24+
branch?: string;
25+
init?: { command: string, args?: string[] }[];
26+
tests: { tsconfig: string, projectRoot?: string, cwd?: string, }[];
27+
}
28+
29+
interface TestStatistics {
30+
passed: string[];
31+
failed: string[];
32+
}
33+
34+
async function runCommand(command: string, args?: ReadonlyArray<string>, cwd?: string): Promise<number | undefined> {
35+
return new Promise((resolve, reject) => {
36+
const process = cp.spawn(command, args, {
37+
cwd,
38+
stdio: 'inherit',
39+
shell: true
40+
});
41+
let resolved: boolean = false;
42+
const handleEnd = (code: number | null, signal: string | null) => {
43+
if (resolved) {
44+
return;
45+
}
46+
resolved = true;
47+
if (signal) {
48+
reject(1);
49+
}
50+
if (code === null || code === 0) {
51+
resolve();
52+
} else {
53+
reject(code);
54+
}
55+
}
56+
process.on('close', handleEnd);
57+
process.on('exit', handleEnd);
58+
process.on('error', (error) => {
59+
console.error(error);
60+
reject(1);
61+
});
62+
})
63+
}
64+
65+
async function runTest(filename: string): Promise<number | undefined> {
66+
process.stdout.write(`Running tests for: ${filename}\n`);
67+
if (!filename) {
68+
process.stderr.write(`No repository description provided.\n`);
69+
return 1;
70+
}
71+
if (!await exists(filename)) {
72+
process.stderr.write(`Repository description ${filename} not found.`);
73+
return 1;
74+
}
75+
const data: DataFormat = JSON.parse(await readFile(filename, { encoding: 'utf8' }));
76+
const tmpdir = os.tmpdir();
77+
let directory = path.join(tmpdir, data.name);
78+
79+
if (await exists(directory)) {
80+
shelljs.rm('-rf', directory);
81+
}
82+
83+
await runCommand('git', ['clone', data.repository, directory]);
84+
if (data.branch) {
85+
await runCommand('git', ['checkout', data.branch], directory);
86+
}
87+
if (data.init) {
88+
for (let init of data.init) {
89+
await runCommand(init.command, init.args, directory);
90+
}
91+
}
92+
if (data.tests) {
93+
for (let test of data.tests) {
94+
let cwd = test.cwd ? path.join(directory, test.cwd) : directory;
95+
process.stdout.write(`Running LSIF exporter for ${path.join(cwd, test.tsconfig)}\n`);
96+
let args: string[] = [path.join(ROOT, 'tsc', 'lib', 'main.js'),
97+
'-p', test.tsconfig,
98+
'--outputFormat', 'line'
99+
];
100+
if (test.projectRoot) {
101+
args.push('--projectRoot', test.projectRoot);
102+
}
103+
args.push('--out', path.join(cwd, `${data.name}.lsif`));
104+
await runCommand('node', args, cwd);
105+
process.stdout.write(`\n`);
106+
}
107+
}
108+
if (await exists(directory)) {
109+
shelljs.rm('-rf', directory);
110+
}
111+
return undefined;
112+
}
113+
114+
115+
async function main(pathname: string | undefined): Promise<number | undefined> {
116+
if (pathname === undefined) {
117+
console.error(`No test file or test directory provided`);
118+
return 1;
119+
}
120+
121+
let testStats: TestStatistics = { passed: [], failed: [] };
122+
let stats = await stat(pathname);
123+
if (stats.isFile() && path.extname(pathname) === '.json') {
124+
try {
125+
await runTest(pathname);
126+
testStats.passed.push(pathname);
127+
} catch (error) {
128+
testStats.failed.push(pathname);
129+
console.log(error);
130+
}
131+
} else if (stats.isDirectory()) {
132+
let entries = await readdir(pathname);
133+
for (let entry of entries) {
134+
if (entry === '.' || entry === '..') {
135+
continue;
136+
}
137+
let candidate = path.join(pathname, entry);
138+
let stats = await stat(candidate);
139+
if (stats.isFile() && path.extname(candidate) === '.json') {
140+
try {
141+
await runTest(candidate);
142+
testStats.passed.push(candidate);
143+
} catch (error) {
144+
testStats.failed.push(candidate);
145+
console.log(error);
146+
}
147+
}
148+
}
149+
} else {
150+
console.error('No tests to run found');
151+
return 1;
152+
}
153+
process.stdout.write(`\n\nTest summary:\n`);
154+
process.stdout.write(`\tPassed tests: ${testStats.passed.length}\n`);
155+
process.stdout.write(`\tFailed tests: ${testStats.failed.length}\n`);
156+
if (testStats.failed.length > 0) {
157+
for (let failed of testStats.failed) {
158+
process.stdout.write(`\t\t${failed}\n`);
159+
}
160+
}
161+
return testStats.failed.length > 0 ? 1 : undefined;
162+
}
163+
164+
main(process.argv[2]).then((error) => {
165+
if (error !== undefined) {
166+
process.exitCode = error;
167+
}
168+
}, (error) => {
169+
process.exitCode = 1;
170+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"sourceMap": true,
5+
"declaration": true,
6+
"composite": true,
7+
"sourceRoot": "../src",
8+
"rootDir": "./src",
9+
"outDir": "./lib",
10+
"tsBuildInfoFile":"./lib/tsconfig.tsbuildInfo"
11+
},
12+
"include": [
13+
"src/**/*.ts"
14+
]
15+
}

0 commit comments

Comments
 (0)