Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update dependencies / general cleanup #1356

Merged
merged 15 commits into from Apr 17, 2020
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
bin/* text eol=lf
dist/* binary
36 changes: 31 additions & 5 deletions .github/workflows/test.yml
Expand Up @@ -5,9 +5,34 @@ on:
- master
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Lint sources"
run: npm run lint:sources -- --max-warnings 0
- name: "Lint types"
run: npm run lint:types
build:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Build distribution files"
run: npm run build
test:
name: "Test"
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
node_version: ["4", "4.3.2", "6", "8", "10", "12"]
Expand All @@ -18,12 +43,13 @@ jobs:
node-version: ${{ matrix.node_version }}
- name: "Install dependencies"
run: npm install
- name: "Run tests"
run: npm test
- name: "Test sources"
run: npm run test:sources
- name: "Test types"
run: npm run test:types
bench:
name: "Bench"
runs-on: ubuntu-latest
needs: test
needs: build
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,7 +1,10 @@
.nyc_output
.vscode
*.log
npm-debug.*
node_modules/
cli/node_modules/
cli/package-lock.json
docs/
coverage/
sandbox/
Expand Down
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

22 changes: 11 additions & 11 deletions bench/data/static_pbjs.js
Expand Up @@ -24,13 +24,13 @@ $root.Test = (function() {
Test.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.string != null && message.hasOwnProperty("string"))
if (message.string != null && Object.hasOwnProperty.call(message, "string"))
writer.uint32(10).string(message.string);
if (message.uint32 != null && message.hasOwnProperty("uint32"))
if (message.uint32 != null && Object.hasOwnProperty.call(message, "uint32"))
writer.uint32(16).uint32(message.uint32);
if (message.inner != null && message.hasOwnProperty("inner"))
if (message.inner != null && Object.hasOwnProperty.call(message, "inner"))
$root.Test.Inner.encode(message.inner, writer.uint32(26).fork()).ldelim();
if (message.float != null && message.hasOwnProperty("float"))
if (message.float != null && Object.hasOwnProperty.call(message, "float"))
writer.uint32(37).float(message.float);
return writer;
};
Expand Down Expand Up @@ -78,11 +78,11 @@ $root.Test = (function() {
Inner.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.int32 != null && message.hasOwnProperty("int32"))
if (message.int32 != null && Object.hasOwnProperty.call(message, "int32"))
writer.uint32(8).int32(message.int32);
if (message.innerInner != null && message.hasOwnProperty("innerInner"))
if (message.innerInner != null && Object.hasOwnProperty.call(message, "innerInner"))
$root.Test.Inner.InnerInner.encode(message.innerInner, writer.uint32(18).fork()).ldelim();
if (message.outer != null && message.hasOwnProperty("outer"))
if (message.outer != null && Object.hasOwnProperty.call(message, "outer"))
$root.Outer.encode(message.outer, writer.uint32(26).fork()).ldelim();
return writer;
};
Expand Down Expand Up @@ -127,11 +127,11 @@ $root.Test = (function() {
InnerInner.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.long != null && message.hasOwnProperty("long"))
if (message.long != null && Object.hasOwnProperty.call(message, "long"))
writer.uint32(8).int64(message.long);
if (message["enum"] != null && message.hasOwnProperty("enum"))
if (message["enum"] != null && Object.hasOwnProperty.call(message, "enum"))
writer.uint32(16).int32(message["enum"]);
if (message.sint32 != null && message.hasOwnProperty("sint32"))
if (message.sint32 != null && Object.hasOwnProperty.call(message, "sint32"))
writer.uint32(24).sint32(message.sint32);
return writer;
};
Expand Down Expand Up @@ -201,7 +201,7 @@ $root.Outer = (function() {
writer.bool(message.bool[i]);
writer.ldelim();
}
if (message.double != null && message.hasOwnProperty("double"))
if (message.double != null && Object.hasOwnProperty.call(message, "double"))
writer.uint32(17).double(message.double);
return writer;
};
Expand Down
130 changes: 71 additions & 59 deletions cli/lib/tsd-jsdoc/publish.js
Expand Up @@ -318,9 +318,11 @@ function begin(element, is_interface) {
seen[element.longname] = element;
} else
writeln();
if (element.scope !== "global" || options.module)
return;
write("export ");
// ????: something changed in JSDoc 3.6.0? so that @exports + @enum does
// no longer yield a 'global' scope, but is some sort of unscoped module
// element now. The additional condition added below works around this.
if ((element.scope === "global" || element.isEnum && element.scope === undefined) && !options.module)
write("export ");
}

// writes the function signature describing element
Expand Down Expand Up @@ -432,6 +434,11 @@ function handleElement(element, parent) {
handleClass(element, parent);
else switch (element.kind) {
case "module":
if (element.isEnum) {
handleEnum(element, parent);
break;
}
// eslint-disable-line no-fallthrough
case "namespace":
handleNamespace(element, parent);
break;
Expand Down Expand Up @@ -569,69 +576,74 @@ function handleClass(element, parent) {
}
}

// handles a namespace or class member
function handleMember(element, parent) {
// handles an enum
function handleEnum(element) {
begin(element);

if (element.isEnum) {
var stringEnum = false;
element.properties.forEach(function(property) {
if (isNaN(property.defaultvalue)) {
stringEnum = true;
}
});
if (stringEnum) {
writeln("type ", element.name, " =");
++indent;
element.properties.forEach(function(property, i) {
write(i === 0 ? "" : "| ", JSON.stringify(property.defaultvalue));
});
--indent;
writeln(";");
} else {
writeln("enum ", element.name, " {");
++indent;
element.properties.forEach(function(property, i) {
write(property.name);
if (property.defaultvalue !== undefined)
write(" = ", JSON.stringify(property.defaultvalue));
if (i < element.properties.length - 1)
writeln(",");
else
writeln();
});
--indent;
writeln("}");
var stringEnum = false;
element.properties.forEach(function(property) {
if (isNaN(property.defaultvalue)) {
stringEnum = true;
}

});
if (stringEnum) {
writeln("type ", element.name, " =");
++indent;
element.properties.forEach(function(property, i) {
write(i === 0 ? "" : "| ", JSON.stringify(property.defaultvalue));
});
--indent;
writeln(";");
} else {
writeln("enum ", element.name, " {");
++indent;
element.properties.forEach(function(property, i) {
write(property.name);
if (property.defaultvalue !== undefined)
write(" = ", JSON.stringify(property.defaultvalue));
if (i < element.properties.length - 1)
writeln(",");
else
writeln();
});
--indent;
writeln("}");
}
}

var inClass = isClassLike(parent);
if (inClass) {
write(element.access || "public", " ");
if (element.scope === "static")
write("static ");
if (element.readonly)
write("readonly ");
} else
write(element.kind === "constant" ? "const " : "let ");
// handles a namespace or class member
function handleMember(element, parent) {
if (element.isEnum) {
handleEnum(element);
return;
}
begin(element);

write(element.name);
if (element.optional)
write("?");
write(": ");
var inClass = isClassLike(parent);
if (inClass) {
write(element.access || "public", " ");
if (element.scope === "static")
write("static ");
if (element.readonly)
write("readonly ");
} else
write(element.kind === "constant" ? "const " : "let ");

if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
writeln("{");
++indent;
element.properties.forEach(function(property, i) {
writeln(JSON.stringify(property.name), ": ", getTypeOf(property), i < element.properties.length - 1 ? "," : "");
});
--indent;
writeln("};");
} else
writeln(getTypeOf(element), ";");
}
write(element.name);
if (element.optional)
write("?");
write(": ");

if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
writeln("{");
++indent;
element.properties.forEach(function(property, i) {
writeln(JSON.stringify(property.name), ": ", getTypeOf(property), i < element.properties.length - 1 ? "," : "");
});
--indent;
writeln("};");
} else
writeln(getTypeOf(element), ";");
}

// handles a function or method
Expand Down
20 changes: 0 additions & 20 deletions cli/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion cli/package.json
@@ -1 +1 @@
{"version": "6.7.0"}
{"version": "6.9.0"}
24 changes: 12 additions & 12 deletions cli/package.standalone.json
@@ -1,7 +1,7 @@
{
"name": "protobufjs-cli",
"description": "Translates between file formats and generates static code as well as TypeScript definitions.",
"version": "6.7.0",
"version": "6.9.0",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"repository": {
"type": "git",
Expand All @@ -15,18 +15,18 @@
"pbts": "bin/pbts"
},
"peerDependencies": {
"protobufjs": "~6.7.0"
"protobufjs": "~6.9.0"
},
"dependencies": {
"chalk": "^1.1.3",
"escodegen": "^1.8.1",
"espree": "^3.1.3",
"estraverse": "^4.2.0",
"glob": "^7.1.1",
"jsdoc": "^3.4.2",
"chalk": "^3.0.0",
"escodegen": "^1.13.0",
"espree": "^6.1.2",
"estraverse": "^4.3.0",
"glob": "^7.1.6",
"jsdoc": "^3.6.3",
"minimist": "^1.2.0",
"semver": "^5.3.0",
"tmp": "0.0.31",
"uglify-js": "^2.8.15"
"semver": "^7.1.2",
"tmp": "^0.1.0",
"uglify-js": "^3.7.7"
}
}
}
4 changes: 0 additions & 4 deletions cli/pbts.js
Expand Up @@ -151,10 +151,6 @@ exports.main = function(args, callback) {
"// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
""
);
output.push(
"import * as Long from \"long\";",
""
);
if (argv.global)
output.push(
"export as namespace " + argv.global + ";",
Expand Down
2 changes: 1 addition & 1 deletion cli/targets/static.js
Expand Up @@ -675,7 +675,7 @@ function buildEnum(ref, enm) {
var comment = [
enm.comment || enm.name + " enum.",
enm.parent instanceof protobuf.Root ? "@exports " + escapeName(enm.name) : "@name " + exportName(enm),
config.forceEnumString ? "@enum {number}" : "@enum {string}",
config.forceEnumString ? "@enum {string}" : "@enum {number}",
];
Object.keys(enm.values).forEach(function(key) {
var val = config.forceEnumString ? key : enm.values[key];
Expand Down
5 changes: 0 additions & 5 deletions config/istanbul.json

This file was deleted.