Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit cdee56f

Browse files
chore: Upgrade to Typescript ~2.6.1 (#355)
1 parent 1553565 commit cdee56f

File tree

8 files changed

+1096
-1942
lines changed

8 files changed

+1096
-1942
lines changed

package-lock.json

Lines changed: 1015 additions & 1869 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"request": "^2.81.0",
5050
"source-map-support": "^0.4.15",
5151
"tslint": "^5.4.3",
52-
"typescript": "2.4.1"
52+
"typescript": "~2.6.1"
5353
},
5454
"dependencies": {
5555
"@google-cloud/common": "^0.13.3",

src/agent/debuglet.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as dns from 'dns';
2424
import * as fs from 'fs';
2525

2626
import * as metadata from 'gcp-metadata';
27+
import * as request from 'request';
2728

2829
import * as _ from 'lodash';
2930
import * as path from 'path';
@@ -420,20 +421,20 @@ export class Debuglet extends EventEmitter {
420421
}
421422
}
422423

423-
static getProjectIdFromMetadata(): Promise<string> {
424+
static getProjectIdFromMetadata() {
424425
return new Promise<string>((resolve, reject) => {
425426
metadata.project(
426-
'project-id', (err: Error, res: any, projectId: string) => {
427+
'project-id', (err, res, projectId) => {
427428
err ? reject(err) : resolve(projectId);
428429
});
429430
});
430431
}
431432

432-
static getClusterNameFromMetadata(): Promise<string> {
433+
static getClusterNameFromMetadata() {
433434
return new Promise<string>((resolve, reject) => {
434435
metadata.instance(
435436
'attributes/cluster-name',
436-
(err: Error, res: any, clusterName: string) => {
437+
(err, res, clusterName) => {
437438
err ? reject(err) : resolve(clusterName);
438439
});
439440
});
@@ -535,7 +536,7 @@ export class Debuglet extends EventEmitter {
535536
that.logger.info('Fetching breakpoints');
536537
// TODO: Address the case when `that.debuggee` is `null`.
537538
that.controller.listBreakpoints(
538-
(that.debuggee as Debuggee), function(err: Error, response, body) {
539+
(that.debuggee as Debuggee), function(err, response, body) {
539540
if (err) {
540541
that.logger.error(
541542
'Unable to fetch breakpoints – stopping fetcher', err);

src/agent/io/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function computeStats(
151151
fileList.forEach(function(filename) {
152152
statsForFile(
153153
filename, shouldHash,
154-
function(err: Error, fileStats: FileStats|undefined) {
154+
function(err: Error|null, fileStats?: FileStats) {
155155
if (err) {
156156
callback(err);
157157
return;

src/agent/state/legacy-state.ts

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class StateResolver {
372372
* @returns {Array<Object>} - returns an array containing data about selected
373373
* variables
374374
*/
375-
resolveLocalsList_(frame: v8.FrameMirror): v8.ScopeMirror[] {
375+
resolveLocalsList_(frame: v8.FrameMirror): stackdriver.Variable[] {
376376
const self = this;
377377
const usedNames: {[name: string]: boolean} = {};
378378
const makeMirror = this.ctx.MakeMirror;
@@ -397,40 +397,43 @@ class StateResolver {
397397
scopes = allScopes.slice(0, -2);
398398
}
399399

400-
return flatten(scopes.map(function(scope: v8.ScopeMirror) {
401-
return transform(
402-
// TODO: Update this so that `locals` is not of type `any[]`.
403-
scope.details().object(),
404-
function(locals: any[], value, name: string) {
405-
const trg = makeMirror(value);
406-
if (!usedNames[name]) {
407-
// It's a valid variable that belongs in the locals list
408-
// and wasn't discovered at a lower-scope
409-
usedNames[name] = true;
410-
// TODO: Determine how to not have an explicit down cast to
411-
// ValueMirror
412-
locals.push(self.resolveVariable_(
413-
name, trg as v8.ValueMirror, false));
414-
} // otherwise another same-named variable occured at a
415-
// lower scope
416-
return locals;
417-
},
418-
[]);
419-
}))
420-
.concat((function() {
421-
// The frame receiver is the 'this' context that is present during
422-
// invocation. Check to see whether a receiver context is substantive,
423-
// (invocations may be bound to null) if so: store in the locals list
424-
// under the name 'context' which is used by the Chrome DevTools.
425-
const ctx = frame.details().receiver();
426-
if (ctx) {
427-
// TODO: Determine how to not have an explicit down cast to
428-
// ValueMirror
429-
return [self.resolveVariable_(
430-
'context', makeMirror(ctx) as v8.ValueMirror, false)];
431-
}
432-
return [];
433-
}()));
400+
const fromScopes: stackdriver.Variable[][] = scopes.map(function(scope: v8.ScopeMirror) {
401+
return transform(
402+
// TODO: Update this so that `locals` is not of type `any[]`.
403+
scope.details().object(),
404+
function(locals: stackdriver.Variable[], value, name: string) {
405+
const trg = makeMirror(value);
406+
if (!usedNames[name]) {
407+
// It's a valid variable that belongs in the locals list
408+
// and wasn't discovered at a lower-scope
409+
usedNames[name] = true;
410+
// TODO: Determine how to not have an explicit down cast to
411+
// ValueMirror
412+
locals.push(self.resolveVariable_(
413+
name, trg as v8.ValueMirror, false));
414+
} // otherwise another same-named variable occured at a
415+
// lower scope
416+
return locals;
417+
},
418+
[]);
419+
});
420+
421+
function resolveFromReceiver(): stackdriver.Variable[] {
422+
// The frame receiver is the 'this' context that is present during
423+
// invocation. Check to see whether a receiver context is substantive,
424+
// (invocations may be bound to null) if so: store in the locals list
425+
// under the name 'context' which is used by the Chrome DevTools.
426+
const ctx = frame.details().receiver();
427+
if (ctx) {
428+
// TODO: Determine how to not have an explicit down cast to
429+
// ValueMirror
430+
return [self.resolveVariable_(
431+
'context', makeMirror(ctx) as v8.ValueMirror, false)];
432+
}
433+
return [];
434+
}
435+
436+
return flatten(fromScopes).concat(resolveFromReceiver());
434437
}
435438

436439
/**

test/test-controller.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ describe('Controller API', function() {
5757
const controller = new Controller(fakeDebug);
5858
// TODO: Determine if this type signature is correct.
5959
controller.register(
60-
debuggee, function(err: Error|null, result: {debuggee: Debuggee}) {
60+
debuggee, function(err, result) {
6161
assert(!err, 'not expecting an error');
62-
assert.equal(result.debuggee.id, 'fake-debuggee');
62+
assert.ok(result);
63+
assert.equal(result!.debuggee.id, 'fake-debuggee');
6364
scope.done();
6465
done();
6566
});
@@ -79,11 +80,12 @@ describe('Controller API', function() {
7980
});
8081
const controller = new Controller(fakeDebug);
8182
controller.register(
82-
debuggee, function(err: Error, result: {debuggee: Debuggee}) {
83+
debuggee, function(err, result) {
8384
// TODO: Fix this incorrect method signature.
8485
(assert as any).ifError(err, 'not expecting an error');
85-
assert.equal(result.debuggee.id, 'fake-debuggee');
86-
assert.ok(result.debuggee.isDisabled);
86+
assert.ok(result);
87+
assert.equal(result!.debuggee.id, 'fake-debuggee');
88+
assert.ok(result!.debuggee.isDisabled);
8789
scope.done();
8890
done();
8991
});
@@ -231,12 +233,11 @@ describe('Controller API', function() {
231233
// TODO: Determine if the response parameter should be used.
232234
controller.listBreakpoints(
233235
debuggee,
234-
function(
235-
err: Error|null, response: http.ServerResponse,
236-
result: stackdriver.ListBreakpointsResponse) {
236+
function(err, response, result) {
237237
assert(!err, 'not expecting an error');
238-
assert(result.breakpoints, 'should have a breakpoints property');
239-
const bps = result.breakpoints;
238+
assert.ok(result);
239+
assert(result!.breakpoints, 'should have a breakpoints property');
240+
const bps = result!.breakpoints;
240241
assert.deepEqual(bps, breakpoints, 'breakpoints mismatch');
241242
scope.done();
242243
done();

test/test-max-data-size.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ describe('maxDataSize', function() {
7575
location: breakpointInFoo.location
7676
} as stackdriver.Breakpoint;
7777
// TODO: Determine how to remove this cast to any.
78-
api.set(bp, function(err1: Error) {
78+
api.set(bp, function(err1) {
7979
assert.ifError(err1);
8080
// TODO: Determine how to remove this cast to any.
81-
api.wait(bp, function(err2: Error) {
81+
api.wait(bp, function(err2?: Error) {
8282
assert.ifError(err2);
8383
// TODO: Determine how to remove this cast to any.
8484
assert(bp.variableTable.some(function(v) {
@@ -109,9 +109,9 @@ describe('maxDataSize', function() {
109109
id: breakpointInFoo.id,
110110
location: breakpointInFoo.location
111111
} as stackdriver.Breakpoint;
112-
api.set(bp, function(err1: Error) {
112+
api.set(bp, function(err1) {
113113
assert.ifError(err1);
114-
api.wait(bp, function(err2: Error) {
114+
api.wait(bp, function(err2?: Error) {
115115
assert.ifError(err2);
116116
// TODO: Determine how to remove this cast to any.
117117
// TODO: The function supplied to reduce is of the wrong type.

test/test-v8debugapi.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,26 @@ function stateIsClean(api: DebugApi): boolean {
4949
return true;
5050
}
5151

52-
function validateVariable(variable: stackdriver.Variable): void {
53-
if (variable.name) {
54-
assert.equal(typeof variable.name, 'string');
55-
}
56-
if (variable.value) {
57-
assert.equal(typeof variable.value, 'string');
58-
}
59-
if (variable.type) {
60-
assert.equal(typeof variable.type, 'string');
61-
}
62-
if (variable.members) {
63-
variable.members.forEach(validateVariable);
64-
}
65-
if (variable.varTableIndex) {
66-
assert.ok(
67-
Number.isInteger(variable.varTableIndex) &&
68-
variable.varTableIndex >= 0 && variable.varTableIndex <= MAX_INT);
52+
function validateVariable(variable: stackdriver.Variable|null): void {
53+
assert.ok(variable);
54+
if (variable) {
55+
if (variable.name) {
56+
assert.equal(typeof variable.name, 'string');
57+
}
58+
if (variable.value) {
59+
assert.equal(typeof variable.value, 'string');
60+
}
61+
if (variable.type) {
62+
assert.equal(typeof variable.type, 'string');
63+
}
64+
if (variable.members) {
65+
variable.members.forEach(validateVariable);
66+
}
67+
if (variable.varTableIndex) {
68+
assert.ok(
69+
Number.isInteger(variable.varTableIndex) &&
70+
variable.varTableIndex >= 0 && variable.varTableIndex <= MAX_INT);
71+
}
6972
}
7073
}
7174

0 commit comments

Comments
 (0)