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

Commit 8a119de

Browse files
Update deps, drop support for 0.12 (#258)
This change updates google-cloud/common to a version which is no longer compatable with node v0.12. To upgrade this dependency, we must drop support for 0.12 as well. Additionally, we prune out some code paths that were only executed on node versions less than 1.6. PR-URL: #258
1 parent 022d1ba commit 8a119de

File tree

12 files changed

+137
-301
lines changed

12 files changed

+137
-301
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: node_js
22
dist: trusty
33
node_js:
4-
- '0.12'
54
- '4'
65
- '6'
76
- '7'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module provides Stackdriver Debugger support for Node.js applications. [Sta
1414
[![Cloud Debugger Intro](http://img.youtube.com/vi/tyHcK_kAOpw/0.jpg)](https://www.youtube.com/watch?v=tyHcK_kAOpw)
1515

1616
## Prerequisites
17-
* Stackdriver Debugger is comptible with Node.js version 0.12 or greater. Node.js v5+ is recommended.
17+
* Stackdriver Debugger is comptible with Node.js version 4 or greater. Node.js v5+ is recommended.
1818

1919
## Quick Start
2020
```shell

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"license": "Apache-2.0",
2020
"engines": {
21-
"node": ">=0.12"
21+
"node": ">=4"
2222
},
2323
"devDependencies": {
2424
"changelog-maker": "^2.2.2",
@@ -28,17 +28,18 @@
2828
"istanbul": "^0.4.1",
2929
"jshint": "^2.7.0",
3030
"mocha": "^3.0.0",
31-
"nock": "^9.0.0"
31+
"nock": "^9.0.0",
32+
"proxyquire": "^1.7.11",
33+
"request": "^2.81.0"
3234
},
3335
"dependencies": {
34-
"@google-cloud/common": "^0.12.0",
35-
"acorn": "^4.0.3",
36+
"@google-cloud/common": "^0.13.3",
37+
"acorn": "^5.0.3",
3638
"async": "^2.1.2",
3739
"coffee-script": "^1.9.3",
3840
"findit2": "^2.2.3",
39-
"gcp-metadata": "^0.1.0",
41+
"gcp-metadata": "^0.2.0",
4042
"lodash": "^4.12.0",
41-
"request": "^2.61.0",
4243
"semver": "^5.1.0",
4344
"source-map": "^0.5.1",
4445
"split": "^1.0.0"

src/agent/debuglet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Debuglet.prototype.start = function() {
215215
// This is ignorable.
216216
}
217217

218-
if (semver.satisfies(process.version, '5.2 || <0.12')) {
218+
if (semver.satisfies(process.version, '5.2 || <4')) {
219219
// Using an unsupported version. We report an error message about the
220220
// Node.js version, but we keep on running. The idea is that the user
221221
// may miss the error message on the console. This way we can report the
@@ -550,7 +550,7 @@ Debuglet.prototype.addBreakpoint_ = function(breakpoint, cb) {
550550
return;
551551
}
552552

553-
if (semver.satisfies(process.version, '5.2 || <0.12')) {
553+
if (semver.satisfies(process.version, '5.2 || <4')) {
554554
var message = NODE_VERSION_MESSAGE;
555555
that.logger_.error(message);
556556
breakpoint.status = new StatusMessage(StatusMessage.UNSPECIFIED,

src/agent/state.js

Lines changed: 5 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ module.exports = {
2323

2424
var ScopeType = require('vm').runInDebugContext('ScopeType');
2525
var assert = require('assert');
26-
var semver = require('semver');
2726
var util = require('util');
2827
var lodash = require('lodash');
29-
var find = lodash.find;
3028
var transform = lodash.transform;
31-
var remove = lodash.remove;
3229
var flatten = lodash.flatten;
3330
var isEmpty = lodash.isEmpty;
3431

@@ -302,23 +299,13 @@ StateResolver.prototype.resolveFrame_ = function(frame, underFrameCap) {
302299
varTableIndex: ARG_LOCAL_LIMIT_MESSAGE_INDEX
303300
});
304301
} else {
305-
args = this.extractArgumentsList_(frame);
302+
// We will use the values aggregated from the ScopeMirror traversal stored
303+
// in locals which will include any applicable arguments from the invocation.
304+
args = [];
306305
locals = this.resolveLocalsList_(frame, args);
307306
if (isEmpty(locals)) {
308307
locals = [];
309308
}
310-
if (semver.satisfies(process.version, '<1.6')) {
311-
// If the node version is over 1.6 we do not read the frame arguments since
312-
// the values produced by the frame for the arguments may contain inaccurate
313-
// values. If the version is lower than 1.6, though, the frame's argument
314-
// list can be relied upon to produce accurate values for arguments.
315-
args = !isEmpty(args) ? this.resolveArgumentList_(args) : [];
316-
} else {
317-
// Otherwise, if the version is 1.6 or higher than we will use the values
318-
// aggregated from the ScopeMirror traversal stored in locals which will
319-
// include any applicable arguments from the invocation.
320-
args = [];
321-
}
322309
}
323310
return {
324311
function: this.resolveFunctionName_(frame.func()),
@@ -355,13 +342,6 @@ StateResolver.prototype.extractArgumentsList_ = function (frame) {
355342
return args;
356343
};
357344

358-
StateResolver.prototype.resolveArgumentList_ = function(args) {
359-
var resolveVariable = this.resolveVariable_.bind(this);
360-
return args.map(function (arg){
361-
return resolveVariable(arg.name, arg.value);
362-
});
363-
};
364-
365345
/**
366346
* Iterates and returns variable information for all scopes (excluding global)
367347
* in a given frame. FrameMirrors should return their scope object list with
@@ -396,34 +376,7 @@ StateResolver.prototype.resolveLocalsList_ = function (frame, args) {
396376
scope.details().object(),
397377
function (locals, value, name) {
398378
var trg = makeMirror(value);
399-
var argMatch = find(args, {name: name});
400-
if (argMatch && (semver.satisfies(process.version, '<1.6'))) {
401-
// If the version is lower than 1.6 we will use the frame's argument
402-
// list to source argument values, yet the ScopeMirror traversal for
403-
// these Node versions will also return the arguments. Therefore, on
404-
// these versions, compare the value sourced as the argument from
405-
// the FrameMirror to the argument found in the ScopeMirror locals
406-
// list with the same name and attempt to determine whether or not
407-
// they have the same value. If each of these items has the same
408-
// name and value we may assume that the ScopeMirror variable
409-
// representation is merely a duplicate of the FrameMirror's
410-
// variable representation. Otherwise, the variable may have been
411-
// redeclared or reassigned in the function and is therefore a local
412-
// triggering removal from the arguments list and insertion into the
413-
// locals list.
414-
if (argMatch.value.value() === trg.value()) {
415-
// Argument ref is the same ref as the local ref - this is an
416-
// argument do not push this into the locals list
417-
return locals;
418-
}
419-
// There is another local/scope var with the same name and it is not
420-
// the argument so this will take precedence. Remove the same-named
421-
// entry from the arguments list and push the local value onto the
422-
// locals list.
423-
remove(args, {name: name});
424-
usedNames[name] = true;
425-
locals.push(self.resolveVariable_(name, trg));
426-
} else if (!usedNames[name]) {
379+
if (!usedNames[name]) {
427380
// It's a valid variable that belongs in the locals list and wasn't
428381
// discovered at a lower-scope
429382
usedNames[name] = true;
@@ -507,55 +460,9 @@ StateResolver.prototype.storeObjectToVariableTable_ = function(obj) {
507460

508461
/**
509462
* Responsible for recursively resolving the properties on a
510-
* provided object mirror. Due to a bug in early node versions,
511-
* we maintain two implementations using the fast approach
512-
* for supported node versions.
513-
*
514-
* See https://github.com/iojs/io.js/issues/1190.
463+
* provided object mirror.
515464
*/
516465
StateResolver.prototype.resolveMirror_ = function(mirror) {
517-
if (semver.satisfies(process.version, '<1.6')) {
518-
return this.resolveMirrorSlow_(mirror);
519-
} else {
520-
return this.resolveMirrorFast_(mirror);
521-
}
522-
};
523-
524-
// A slower implementation of resolveMirror_ which is safe for all node versions
525-
StateResolver.prototype.resolveMirrorSlow_ = function(mirror) {
526-
// Instead, let's use Object.keys. This will only get the enumerable
527-
// properties. The other alternative would be Object.getOwnPropertyNames, but
528-
// I'm going with the former as that's what util.inspect does.
529-
var that = this;
530-
531-
var keys = Object.keys(mirror.value());
532-
var maxProps = that.config_.capture.maxProperties;
533-
var truncate = maxProps && keys.length > maxProps;
534-
if (truncate) {
535-
keys = keys.slice(0, maxProps);
536-
}
537-
var members = keys.map(function(prop) {
538-
return that.resolveMirrorProperty_(mirror.property(prop));
539-
});
540-
if (truncate) {
541-
members.push({name: 'Only first `config.capture.maxProperties=' +
542-
this.config_.capture.maxProperties +
543-
'` properties were captured'});
544-
}
545-
546-
var mirrorVal = mirror.value();
547-
var len = mirrorVal && mirrorVal.length;
548-
return {
549-
value: mirror.toText() +
550-
((typeof len === 'undefined') ? '' : ' of length ' + len),
551-
members: members
552-
};
553-
};
554-
555-
// A faster implementation of resolveMirror_ which segfaults in node <1.6
556-
//
557-
// See https://github.com/iojs/io.js/issues/1190.
558-
StateResolver.prototype.resolveMirrorFast_ = function(mirror) {
559466
var properties = mirror.properties();
560467
var maxProps = this.config_.capture.maxProperties;
561468
var truncate = maxProps && properties.length > maxProps;

test/test-debuglet.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
'use strict';
1717

18+
var proxyquire = require('proxyquire');
19+
proxyquire('gcp-metadata', {
20+
'retry-request': require('request')
21+
});
22+
1823
var _ = require('lodash');
1924
var assert = require('assert');
2025
var DEFAULT_CONFIG = require('../src/agent/config.js');
@@ -78,15 +83,9 @@ describe('Debuglet', function() {
7883
var debug = require('../src/debug.js')();
7984
var debuglet = new Debuglet(debug, defaultConfig);
8085

81-
// The following mock is neccessary for the case when the test is running
82-
// on GCP. In that case we will get the projectId from the metadata
83-
// service.
84-
var scope = nocks.projectId(404);
85-
8686
debuglet.once('initError', function(err) {
8787
assert.ok(err);
8888
// no need to stop the debuggee.
89-
scope.done();
9089
done();
9190
});
9291
debuglet.once('started', function() { assert.fail(); });
@@ -98,14 +97,8 @@ describe('Debuglet', function() {
9897
var debug = require('../src/debug.js')();
9998
var debuglet = new Debuglet(debug, defaultConfig);
10099

101-
// The following mock is neccessary for the case when the test is running
102-
// on GCP. In that case we will get the projectId from the metadata
103-
// service.
104-
var scope = nocks.projectId(404);
105-
106100
debuglet.once('started', function() { assert.fail(); });
107101
debuglet.once('initError', function() {
108-
scope.done();
109102
done();
110103
});
111104
debuglet.start();

test/test-duplicate-nested-expressions.js

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var common = require('@google-cloud/common');
3131
var defaultConfig = require('../src/agent/config.js');
3232
var SourceMapper = require('../src/agent/sourcemapper.js');
3333
var scanner = require('../src/agent/scanner.js');
34-
var semver = require('semver');
3534

3635
function stateIsClean(api) {
3736
assert.equal(api.numBreakpoints_(), 0,
@@ -83,21 +82,12 @@ describe(__filename, function() {
8382
var frame = brk.stackFrames[0];
8483
var args = frame.arguments;
8584
var locals = frame.locals;
86-
if (semver.satisfies(process.version, '<1.6')) {
87-
assert.equal(args.length, 1, 'There should be one argument');
88-
assert.deepEqual(
89-
args[0],
90-
{name: 'a', value: '11'}
91-
);
92-
assert.equal(locals.length, 0);
93-
} else {
94-
assert.equal(args.length, 0, 'There should be zero arguments');
95-
assert.equal(locals.length, 1, 'There should be one locals');
96-
assert.deepEqual(
97-
locals[0],
98-
{name: 'a', value: 'test'}
99-
);
100-
}
85+
assert.equal(args.length, 0, 'There should be zero arguments');
86+
assert.equal(locals.length, 1, 'There should be one locals');
87+
assert.deepEqual(
88+
locals[0],
89+
{name: 'a', value: 'test'}
90+
);
10191
api.clear(brk);
10292
done();
10393
});
@@ -117,21 +107,12 @@ describe(__filename, function() {
117107
var frame = brk.stackFrames[0];
118108
var args = frame.arguments;
119109
var locals = frame.locals;
120-
if (semver.satisfies(process.version, '<1.6')) {
121-
assert.equal(args.length, 1, 'There should be one argument');
122-
assert.deepEqual(
123-
args[0],
124-
{name: 'a', value: '11'}
125-
);
126-
assert.equal(locals.length, 0);
127-
} else {
128-
assert.equal(args.length, 0, 'There should be zero arguments');
129-
assert.equal(locals.length, 1, 'There should be one local');
130-
assert.deepEqual(
131-
locals[0],
132-
{name: 'a', value: '10'}
133-
);
134-
}
110+
assert.equal(args.length, 0, 'There should be zero arguments');
111+
assert.equal(locals.length, 1, 'There should be one local');
112+
assert.deepEqual(
113+
locals[0],
114+
{name: 'a', value: '10'}
115+
);
135116
api.clear(brk);
136117
done();
137118
});
@@ -151,21 +132,12 @@ describe(__filename, function() {
151132
var frame = brk.stackFrames[0];
152133
var args = frame.arguments;
153134
var locals = frame.locals;
154-
if (semver.satisfies(process.version, '<1.6')) {
155-
assert.equal(args.length, 1, 'There should be one argument');
156-
assert.deepEqual(
157-
args[0],
158-
{name: 'a', value: '11'}
159-
);
160-
assert.equal(locals.length, 0);
161-
} else {
162-
assert.equal(args.length, 0, 'There should be zero arguments');
163-
assert.equal(locals.length, 1, 'There should be one local');
164-
assert.deepEqual(
165-
locals[0],
166-
{name: 'a', value: '11'}
167-
);
168-
}
135+
assert.equal(args.length, 0, 'There should be zero arguments');
136+
assert.equal(locals.length, 1, 'There should be one local');
137+
assert.deepEqual(
138+
locals[0],
139+
{name: 'a', value: '11'}
140+
);
169141
api.clear(brk);
170142
done();
171143
});
@@ -178,15 +150,6 @@ describe(__filename, function() {
178150
id: 'fake-id-1234',
179151
location: { path: 'test-duplicate-nested-expressions.js', line: 8 }
180152
};
181-
if (semver.satisfies(process.version, '<1.6')) {
182-
// this IIFE test does not work on 0.12. Specifically the IIFE never
183-
// executes and, therefore, the breakpoint is never hit. This will require
184-
// further investigation as to what is causing the IIFE not to execute.a
185-
// @TODO cristiancavalli - investigate why this IIFE does not execute
186-
console.log('Skipping IIFE test due to Node.JS version requirements');
187-
this.skip();
188-
return;
189-
}
190153
api.set(brk, function(err) {
191154
assert.ifError(err);
192155
api.wait(brk, function(err) {

test/test-fat-arrow.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var common = require('@google-cloud/common');
2222
var defaultConfig = require('../src/agent/config.js');
2323
var SourceMapper = require('../src/agent/sourcemapper.js');
2424
var scanner = require('../src/agent/scanner.js');
25-
var semver = require('semver');
2625

2726
process.env.GCLOUD_PROJECT = 0;
2827

@@ -43,13 +42,6 @@ describe(__filename, function() {
4342
var api = null;
4443
var foo;
4544
before(function () {
46-
if (semver.satisfies(process.version, '<4.0')) {
47-
// Fat arrow syntax is not recognized by these node versions - skip tests.
48-
console.log('Skipping fat-arrow syntax due to Node.JS version being ' +
49-
'lower than requirements');
50-
this.skip();
51-
return;
52-
}
5345
foo = require('./fixtures/fat-arrow.js');
5446
});
5547
beforeEach(function(done) {

0 commit comments

Comments
 (0)