Skip to content

Commit d246024

Browse files
committed
Other: Minor optimizations to dependencies, build process and tsd
1 parent 33d14c9 commit d246024

25 files changed

+65
-64
lines changed

Diff for: .eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"browser": true
55
},
66
"globals": {
7+
"ArrayBuffer": true,
78
"Uint8Array": true,
89
"Float32Array": true,
910
"Float64Array": true,

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ branches:
1616
matrix:
1717
include:
1818
- node_js: 6
19-
script: set -e; if [ -n "$SAUCE_USERNAME" ]; then travis_wait npm run zuul; sleep 3; fi
19+
script: set -e; if [ -n "$SAUCE_USERNAME" ]; then npm install [email protected] [email protected]; travis_wait npm run zuul; sleep 3; fi
2020
- node_js: 6
2121
script: npm run coverage-ci

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ The `pbjs` utility is also capable of generating static code (hint: works with j
418418
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
419419
```
420420

421-
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`, which then can be used with just the [minimal library](#distributions).
421+
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`.
422422

423423
**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.
424424

@@ -465,9 +465,9 @@ $> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
465465

466466
### On reflection vs. static code
467467

468-
While using .proto files directly requires the [full library](#distributions) respectively pure reflection/JSON the [light library](#distributions), pretty much all code but the relatively short descriptors is shared.
468+
While using .proto files directly requires the full library respectively pure reflection/JSON the light library, pretty much all code but the relatively short descriptors is shared.
469469

470-
Static code, on the other hand, requires just the [minimal library](#distributions), but generates additional, albeit editable, source code without any reflection features.
470+
Static code, on the other hand, requires just the minimal library, but generates additional, albeit editable, source code without any reflection features.
471471

472472
There is no significant difference performance-wise as the code generated statically is pretty much the same as generated at runtime and both are largely interchangeable as seen in the previous section.
473473

Diff for: cli/targets/static.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = static_target;
44
var protobuf = require("../.."),
55
cliUtil = require("../util"),
66
UglifyJS = require("uglify-js"),
7-
esprima = require("esprima"),
7+
espree = require("espree"),
88
escodegen = require("escodegen"),
99
estraverse = require("estraverse");
1010

@@ -161,7 +161,7 @@ function beautifyCode(code) {
161161
}
162162
}).code;
163163
// Properly beautify
164-
var ast = esprima.parse(code);
164+
var ast = espree.parse(code);
165165
estraverse.replace(ast, {
166166
enter: function(node, parent) {
167167
// rename short vars

Diff for: dist/light/protobuf.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/light/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/light/protobuf.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/light/protobuf.min.js.gz

14 Bytes
Binary file not shown.

Diff for: dist/light/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/minimal/protobuf.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/minimal/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/minimal/protobuf.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/minimal/protobuf.min.js.gz

2 Bytes
Binary file not shown.

Diff for: dist/minimal/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.min.js.gz

5 Bytes
Binary file not shown.

Diff for: dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function defineTask(name, entry, target) {
88
entry : entry,
99
target : target
1010
}));
11-
gulp.task(name + "-minify" , bundle.bind(this, {
11+
gulp.task(name + "-minify" , [ name + "-bundle" ], bundle.bind(this, {
1212
entry : entry,
1313
target : target,
1414
compress : true

Diff for: index.d.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,6 @@ export class Type extends NamespaceBase {
18131813
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
18141814
* @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
18151815
*/
1816-
18171816
interface ConversionOptions {
18181817
longs?: any;
18191818
enums?: any;
@@ -1997,7 +1996,6 @@ export namespace types {
19971996
* @property {number} high High bits
19981997
* @property {boolean} unsigned Whether unsigned or not
19991998
*/
2000-
20011999
interface Long {
20022000
low: number;
20032001
high: number;
@@ -2760,7 +2758,6 @@ type FetchCallback = (error: Error, contents?: string) => void;
27602758
* @property {boolean} [binary=false] Whether expecting a binary response
27612759
* @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
27622760
*/
2763-
27642761
interface FetchOptions {
27652762
binary?: boolean;
27662763
xhr?: boolean;

Diff for: lib/tsd-jsdoc/publish.js

+26-23
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ exports.publish = function publish(taffy, opts) {
3232

3333
// query overrides options
3434
if (options.query)
35-
for (var i in options.query)
36-
if (options.query.hasOwnProperty(i))
37-
switch (options[i] = options.query[i]) {
35+
Object.keys(options.query).forEach(function(key) {
36+
if (key !== "query")
37+
switch (options[key] = options.query[key]) {
3838
case "true":
39-
options[i] = true;
39+
options[key] = true;
4040
break;
4141
case "false":
42-
options[i] = false;
42+
options[key] = false;
4343
break;
4444
case "null":
45-
options[i] = null;
45+
options[key] = null;
4646
break;
4747
}
48+
});
4849

4950
// remove undocumented
5051
taffy({ undocumented: true }).remove();
@@ -105,7 +106,7 @@ exports.publish = function publish(taffy, opts) {
105106
seen = options = {};
106107
queuedInterfaces = [];
107108
}
108-
}
109+
};
109110

110111
//
111112
// Utility
@@ -123,7 +124,7 @@ function write() {
123124
firstLine = false;
124125
}
125126

126-
// writes one or multiple strings, followed by a new line
127+
// writes zero or multiple strings, followed by a new line
127128
function writeln() {
128129
var s = Array.prototype.slice.call(arguments).join("");
129130
if (s.length)
@@ -156,12 +157,15 @@ function writeComment(comment, otherwiseNewline) {
156157
// recursively replaces all occurencies of re's match
157158
function replaceRecursive(name, re, fn) {
158159
var found;
160+
161+
function replacer() {
162+
found = true;
163+
return fn.apply(null, arguments);
164+
}
165+
159166
do {
160167
found = false;
161-
name = name.replace(re, function() {
162-
found = true;
163-
return fn.apply(null, arguments);
164-
});
168+
name = name.replace(re, replacer);
165169
} while (found);
166170
return name;
167171
}
@@ -173,7 +177,7 @@ function isClassLike(element) {
173177

174178
// tests if an element is considered to be an interface
175179
function isInterface(element) {
176-
return element && (element.kind === "interface" || (getTypeOf(element) === 'Object' && element.properties && element.properties.length));
180+
return element && (element.kind === "interface" || getTypeOf(element) === "Object" && element.properties && element.properties.length);
177181
}
178182

179183
// tests if an element is considered to be a namespace
@@ -219,11 +223,11 @@ function getTypeOf(element) {
219223

220224
// Replace Object.<string,number> with { [k: string]: number }
221225
name = replaceRecursive(name, /\bObject\.?<([^,]*), *([^>]*)>/gi, function($0, $1, $2) {
222-
return '{ [k: ' + $1 + ']: ' + $2 + ' }';
226+
return "{ [k: " + $1 + "]: " + $2 + " }";
223227
});
224228

225229
// Replace functions (there are no signatures) with () => any
226-
name = name.replace(/\bfunction(?:\(\))?([^\w]|$)/gi, '() => any');
230+
name = name.replace(/\bfunction(?:\(\))?([^\w]|$)/gi, "() => any");
227231

228232
return name;
229233
}
@@ -238,7 +242,7 @@ function begin(element, is_interface) {
238242

239243
// writes the function signature describing element
240244
function writeFunctionSignature(element, isConstructor, isTypeDef) {
241-
write('(');
245+
write("(");
242246

243247
var params = {};
244248

@@ -258,7 +262,7 @@ function writeFunctionSignature(element, isConstructor, isTypeDef) {
258262
type: getTypeOf(param),
259263
variable: param.variable === true,
260264
optional: param.optional === true,
261-
defaultValue: param.defaultvalue // TODO
265+
defaultValue: param.defaultvalue // Not used yet (TODO)
262266
};
263267
else // Property syntax (TODO)
264268
params[path[0]].type = "{ [k: string]: any }";
@@ -292,7 +296,6 @@ function writeFunctionSignature(element, isConstructor, isTypeDef) {
292296

293297
// writes (a typedef as) an interface
294298
function writeInterface(element) {
295-
writeln();
296299
writeln("interface ", element.name, " {");
297300
++indent;
298301
element.properties.forEach(function(property) {
@@ -401,23 +404,23 @@ function handleClass(element, parent) {
401404
handleFunction(element, parent, true);
402405

403406
// class-compatible members
404-
var inner = [];
407+
var incompatible = [];
405408
getChildrenOf(element).forEach(function(child) {
406409
if (!handleElement(child, element, true))
407-
inner.push(child);
410+
incompatible.push(child);
408411
});
409412

410413
--indent;
411414
writeln("}");
412415

413416
// class-incompatible members
414-
if (inner.length) {
417+
if (incompatible.length) {
415418
writeln();
416419
if (element.scope === "global" && !options.module)
417420
write("export ");
418421
writeln("namespace ", element.name, " {");
419422
++indent;
420-
inner.forEach(function(child) {
423+
incompatible.forEach(function(child) {
421424
handleElement(child, element);
422425
});
423426
--indent;
@@ -512,4 +515,4 @@ function handleTypeDef(element, parent) {
512515
write(getTypeOf(element));
513516
writeln(";");
514517
}
515-
}
518+
}

Diff for: package.json

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protobufjs",
3-
"version": "6.6.3",
3+
"version": "6.6.4",
44
"versionScheme": "~",
55
"description": "Protocol Buffers for JavaScript (& TypeScript).",
66
"author": "Daniel Wirtz <[email protected]>",
@@ -13,11 +13,9 @@
1313
"homepage": "http://dcode.io/protobuf.js",
1414
"keywords": [
1515
"protobuf",
16-
"protocol",
17-
"buffers",
18-
"protocol buffers",
16+
"protocol-buffers",
1917
"serialization",
20-
"encoding"
18+
"typescript"
2119
],
2220
"main": "index.js",
2321
"types": "index.d.ts",
@@ -69,7 +67,7 @@
6967
"coveralls": "^2.11.15",
7068
"escodegen": "^1.8.1",
7169
"eslint": "^3.14.1",
72-
"esprima": "^3.1.3",
70+
"espree": "^3.1.3",
7371
"estraverse": "^4.2.0",
7472
"gh-pages": "^0.12.0",
7573
"git-raw-commits": "^1.1.2",
@@ -89,13 +87,11 @@
8987
"tap-spec": "^4.1.1",
9088
"tape": "^4.6.3",
9189
"tmp": "0.0.31",
92-
"typescript": "^2.1.5",
90+
"typescript": "^2.2.0",
9391
"uglify-js": "^2.7.5",
9492
"vinyl-buffer": "^1.0.0",
9593
"vinyl-fs": "^2.4.4",
96-
"vinyl-source-stream": "^1.1.0",
97-
"zuul": "^3.11.1",
98-
"zuul-ngrok": "^4.0.0"
94+
"vinyl-source-stream": "^1.1.0"
9995
},
10096
"cliDependencies": [
10197
"semver",
@@ -105,7 +101,7 @@
105101
"minimist",
106102
"tmp",
107103
"uglify-js",
108-
"esprima",
104+
"espree",
109105
"escodegen",
110106
"estraverse"
111107
]

Diff for: src/util/minimal.js

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ util.toJSONOptions = {
253253

254254
util._configure = function() {
255255
var Buffer = util.Buffer;
256+
/* istanbul ignore if */
256257
if (!Buffer) {
257258
util._Buffer_from = util._Buffer_allocUnsafe = null;
258259
return;

Diff for: tests/api_reader-writer-reuse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tape.test("reusing", function(test) {
2424
}, writer);
2525

2626
B.encodeDelimited({
27-
b: 'a'
27+
b: "a"
2828
}, writer);
2929

3030
var buffer = writer.finish();
@@ -45,7 +45,7 @@ tape.test("reusing", function(test) {
4545
test.deepEqual(a, { a: 1 }, "read back the first message");
4646

4747
var b = B.decodeDelimited(reader);
48-
test.deepEqual(b, { b: 'a' }, "read back the second message");
48+
test.deepEqual(b, { b: "a" }, "read back the second message");
4949

5050
test.equal(reader.pos, reader.len, "consume the reader");
5151

0 commit comments

Comments
 (0)