bimba-cli 0.7.14 → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/typecheck.js +23 -5
package/package.json
CHANGED
package/typecheck.js
CHANGED
|
@@ -26,6 +26,10 @@ function canResolve(request, from) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function hasPackage(root, name) {
|
|
30
|
+
return fs.existsSync(path.join(root, name, 'package.json'));
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
function findTypeScript(cwd) {
|
|
30
34
|
const tsserver = canResolve('typescript/lib/tsserver.js', cwd);
|
|
31
35
|
if (tsserver) return tsserver;
|
|
@@ -35,7 +39,7 @@ function findTypeScript(cwd) {
|
|
|
35
39
|
|
|
36
40
|
function findPluginProbe(cwd) {
|
|
37
41
|
const localProbe = path.join(cwd, 'node_modules');
|
|
38
|
-
if (
|
|
42
|
+
if (hasPackage(localProbe, 'typescript-imba-plugin')) return localProbe;
|
|
39
43
|
|
|
40
44
|
const extensionRoots = [
|
|
41
45
|
path.join(os.homedir(), '.vscode', 'extensions'),
|
|
@@ -49,7 +53,7 @@ function findPluginProbe(cwd) {
|
|
|
49
53
|
|
|
50
54
|
for (const entry of fs.readdirSync(root)) {
|
|
51
55
|
const probe = path.join(root, entry, 'node_modules');
|
|
52
|
-
if (
|
|
56
|
+
if (hasPackage(probe, 'typescript-imba-plugin')) return probe;
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -153,7 +157,7 @@ function send(server, seq, command, args) {
|
|
|
153
157
|
|
|
154
158
|
export async function checkImbaTypes(entrypoint, options = {}) {
|
|
155
159
|
const cwd = options.cwd || process.cwd();
|
|
156
|
-
const timeout = Number(options.timeout || process.env.BIMBA_TYPECHECK_TIMEOUT || process.env.IMBA_TS_CHECK_TIMEOUT ||
|
|
160
|
+
const timeout = Number(options.timeout || process.env.BIMBA_TYPECHECK_TIMEOUT || process.env.IMBA_TS_CHECK_TIMEOUT || 30000);
|
|
157
161
|
const scanRoot = getScanRoot(entrypoint, cwd);
|
|
158
162
|
const files = collectImbaFiles(scanRoot);
|
|
159
163
|
|
|
@@ -174,6 +178,7 @@ export async function checkImbaTypes(entrypoint, options = {}) {
|
|
|
174
178
|
let buffer = Buffer.alloc(0);
|
|
175
179
|
const seq = { value: 1 };
|
|
176
180
|
const diagnostics = [];
|
|
181
|
+
let geterrSeq = null;
|
|
177
182
|
|
|
178
183
|
const server = spawn(runner, [
|
|
179
184
|
tsserver,
|
|
@@ -191,7 +196,7 @@ export async function checkImbaTypes(entrypoint, options = {}) {
|
|
|
191
196
|
resolve(success);
|
|
192
197
|
}
|
|
193
198
|
|
|
194
|
-
|
|
199
|
+
function finishWithDiagnostics() {
|
|
195
200
|
const unique = uniqueDiagnostics(diagnostics);
|
|
196
201
|
|
|
197
202
|
if (!unique.length) {
|
|
@@ -203,6 +208,11 @@ export async function checkImbaTypes(entrypoint, options = {}) {
|
|
|
203
208
|
printDiagnostics(cwd, unique);
|
|
204
209
|
console.log(theme.failure(' Failure ') + ` TypeScript found ${theme.count(unique.length)} diagnostic${unique.length > 1 ? 's' : ''}`);
|
|
205
210
|
finish(false);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const timer = setTimeout(() => {
|
|
214
|
+
console.log(theme.failure(' Failure ') + ` Timed out waiting for TypeScript diagnostics after ${theme.time(timeout)} ms`);
|
|
215
|
+
finish(false);
|
|
206
216
|
}, timeout);
|
|
207
217
|
|
|
208
218
|
server.on('error', (error) => {
|
|
@@ -215,7 +225,14 @@ export async function checkImbaTypes(entrypoint, options = {}) {
|
|
|
215
225
|
server.stdout.on('data', chunk => {
|
|
216
226
|
buffer = Buffer.concat([buffer, chunk]);
|
|
217
227
|
buffer = parseMessages(buffer, msg => {
|
|
218
|
-
if (msg.type != 'event'
|
|
228
|
+
if (msg.type != 'event') return;
|
|
229
|
+
|
|
230
|
+
if (msg.event == 'requestCompleted' && msg.body?.request_seq == geterrSeq) {
|
|
231
|
+
finishWithDiagnostics();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (!/Diag$/.test(msg.event)) return;
|
|
219
236
|
if (!msg.body?.diagnostics?.length) return;
|
|
220
237
|
|
|
221
238
|
for (const diagnostic of msg.body.diagnostics) {
|
|
@@ -242,6 +259,7 @@ export async function checkImbaTypes(entrypoint, options = {}) {
|
|
|
242
259
|
if (settled) return;
|
|
243
260
|
send(server, seq, 'configure', { preferences: {}, hostInfo: 'bimba-typecheck' });
|
|
244
261
|
for (const file of files) send(server, seq, 'open', { file, projectRootPath: cwd });
|
|
262
|
+
geterrSeq = seq.value;
|
|
245
263
|
send(server, seq, 'geterr', { files, delay: 0 });
|
|
246
264
|
}, 100);
|
|
247
265
|
});
|