Skip to content

Commit

Permalink
CLI: Added --strict-long option to pbjs to always emit 'Long' instead…
Browse files Browse the repository at this point in the history
… of 'number|Long' (only relevant with long.js), see #718
  • Loading branch information
dcodeIO committed Mar 23, 2017
1 parent e1dd1bc commit c3f0a21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
27 changes: 15 additions & 12 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ exports.main = function main(args, callback) {
lint : "l"
},
string: [ "target", "out", "path", "wrap", "root", "lint" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "strict-long" ],
default: {
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true,
es6 : null,
lint : lintDefault
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true,
es6 : null,
lint : lintDefault,
"keep-case" : false,
"strict-long": false
}
});

Expand Down Expand Up @@ -107,6 +109,7 @@ exports.main = function main(args, callback) {
" --no-delimited Does not generate delimited encode/decode functions.",
" --no-beautify Does not beautify generated code.",
" --no-comments Does not output any JSDoc comments.",
" --strict-long Forces s-/u-/int64 and s-/fixed64 types to 'Long' only (no numbers).",
"",
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or) ") + "other | " + chalk.bold.green("pbjs") + " [options] -",
""
Expand Down
4 changes: 2 additions & 2 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function buildFunction(type, functionName, gen, scope) {
push("};");
}

function toJsType(field, isReturn) {
function toJsType(field) {
switch (field.type) {
case "double":
case "float":
Expand All @@ -265,7 +265,7 @@ function toJsType(field, isReturn) {
case "sint64":
case "fixed64":
case "sfixed64":
return isReturn ? "Long" : "number|Long";
return config["strict-long"] ? "Long" : "number|Long";
case "bool":
return "boolean";
case "string":
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"postinstall": "node scripts/postinstall",
"prof": "node bench/prof",
"test": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js | tap-spec",
"types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && tsc tests/comp_typescript.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/test.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
"test-types": "tsc tests/comp_typescript.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/test.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
"types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && npm run test-types",
"zuul": "zuul --ui tape --no-coverage --concurrency 4 -- tests/*.js",
"zuul-local": "zuul --ui tape --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
"make": "npm run test && npm run types && npm run build && npm run lint",
Expand Down

0 comments on commit c3f0a21

Please sign in to comment.