Skip to content

Commit

Permalink
Fixed: Properly set up reflection when using light build
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 24, 2017
1 parent 1a376ba commit 039ac77
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 177 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [6.6.0](https://github.com/dcodeIO/protobuf.js/releases/tag/6.6.0)
# [6.6.0](https://github.com/dcodeIO/protobuf.js/releases/tag/6.6.0) ([release](https://github.com/dcodeIO/protobuf.js/releases/tag/6.6.0))

## Breaking
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/cdfe6bfba27fa1a1d0e61887597ad4bb16d7e5ed) Inlined / refactored away .testJSON, see [#653](https://github.com/dcodeIO/protobuf.js/issues/653)<br />
Expand Down
10 changes: 8 additions & 2 deletions dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/light/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/minimal/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/minimal/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/minimal/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/minimal/protobuf.min.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2143,15 +2143,6 @@ export namespace util {
emit(evt: string, ...args: any[]): util.EventEmitter;
}

/**
* Lets the specified constructor extend `this` class.
* @memberof util
* @param {*} ctor Extending constructor
* @returns {Object.<string,*>} Constructor prototype
* @this Function
*/
function extend(this: Function, ctor: any): { [k: string]: any };

/**
* Fetches the contents of a file.
* @memberof util
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protobufjs",
"version": "6.6.0",
"version": "6.6.1",
"versionScheme": "~",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
Expand Down Expand Up @@ -31,7 +31,7 @@
"changelog": "node scripts/changelog -w",
"coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js tests/node/*.js",
"coverage-ci": "npm run coverage && cat coverage/lcov.info | coveralls",
"docs": "jsdoc -c jsdoc.docs.json -R README.md -P package.json --verbose --pedantic",
"docs": "jsdoc -c jsdoc.docs.json -R README.md --verbose --pedantic",
"lint": "eslint src",
"pages": "node scripts/pages",
"prepublish": "node scripts/prepublish",
Expand Down
5 changes: 5 additions & 0 deletions src/index-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ protobuf.Message = require("./message");
// Utility
protobuf.types = require("./types");
protobuf.util = require("./util");

// Configure reflection
protobuf.ReflectionObject._configure(protobuf.Root);
protobuf.Namespace._configure(protobuf.Type, protobuf.Service);
protobuf.Root._configure(protobuf.Type);
1 change: 1 addition & 0 deletions src/index-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ if (typeof define === "function" && define.amd)
return protobuf;
});

// Configure serialization
protobuf.Writer._configure(protobuf.BufferWriter);
configure();
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ protobuf.tokenize = require("./tokenize");
protobuf.parse = require("./parse");
protobuf.common = require("./common");

protobuf.ReflectionObject._configure(protobuf.Root);
protobuf.Namespace._configure(protobuf.Type, protobuf.Service);
// Configure parser
protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);
26 changes: 0 additions & 26 deletions src/util/extend/LICENSE

This file was deleted.

28 changes: 0 additions & 28 deletions src/util/extend/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions src/util/extend/index.d.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/util/extend/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/util/extend/package.json

This file was deleted.

107 changes: 64 additions & 43 deletions tests/node/comp_loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,82 @@ var fs = require("fs"),
long = require("long"),
tape = require("tape");

var distPath = path.join(__dirname, "..", "..", "dist", "protobuf.min.js");
var dist = fs.readFileSync(distPath).toString("utf8");
var distPath = path.join(__dirname, "..", "..", "dist");

tape.test("script tags", function(test) {
var sandbox;
[
{
name: "full",
data: fs.readFileSync(path.join(distPath, "protobuf.min.js")).toString("utf8")
},
{
name: "light",
data: fs.readFileSync(path.join(distPath, "light/protobuf.min.js")).toString("utf8")
},
{
name: "minimal",
data: fs.readFileSync(path.join(distPath, "minimal/protobuf.min.js")).toString("utf8")
}
]
.forEach(function(dist) {

var dcodeIO = { Long: long };
tape.test(dist.name + " build", function(test) {

vm.runInNewContext(dist, sandbox = {
window: {
dcodeIO: dcodeIO
},
dcodeIO: dcodeIO
});
test.test(test.name + " - script tags", function(test) {
var sandbox;

test.ok(sandbox.window.protobuf, "should load the library as a global");
test.ok(sandbox.window.protobuf.util.Long, "should load long.js to util");
test.end();
});
var dcodeIO = { Long: long };

tape.test("webworkers", function(test) {
var sandbox;
vm.runInNewContext(dist.data, sandbox = {
window: {
dcodeIO: dcodeIO
},
dcodeIO: dcodeIO
});

var dcodeIO = { Long: long };
test.ok(sandbox.window.protobuf, "should load the library as a global");
test.ok(sandbox.window.protobuf.util.Long, "should load long.js to util");
test.end();
});

vm.runInNewContext(dist, sandbox = {
self: {
dcodeIO: dcodeIO
},
dcodeIO: dcodeIO
});
test.test(test.name + " - webworkers", function(test) {
var sandbox;

test.ok(sandbox.self.protobuf, "should load the library as a global");
test.ok(sandbox.self.protobuf.util.Long, "should load long.js to util");
test.end();
});
var dcodeIO = { Long: long };

tape.test("amd loaders", function(test) {
var sandbox;
vm.runInNewContext(dist.data, sandbox = {
self: {
dcodeIO: dcodeIO
},
dcodeIO: dcodeIO
});

function fakeDefine(deps, init) {
test.same(deps, [ "long" ], "should request long.js as a dependency");
test.notOk(sandbox.window.protobuf.util.Long, "should not have loaded long.js before calling the factory function");
init([ long ]);
}
fakeDefine.amd = true;
test.ok(sandbox.self.protobuf, "should load the library as a global");
test.ok(sandbox.self.protobuf.util.Long, "should load long.js to util");
test.end();
});

vm.runInNewContext(dist, sandbox = {
define: fakeDefine,
window: {}
});
test.test(test.name + " - amd loaders", function(test) {
var sandbox;

function fakeDefine(deps, init) {
test.same(deps, [ "long" ], "should request long.js as a dependency");
test.notOk(sandbox.window.protobuf.util.Long, "should not have loaded long.js before calling the factory function");
init([ long ]);
}
fakeDefine.amd = true;

vm.runInNewContext(dist.data, sandbox = {
define: fakeDefine,
window: {}
});

test.ok(sandbox.window.protobuf, "should load the library as a global");
test.ok(sandbox.window.protobuf.util.Long, "should have loaded long.js after calling the factory function");
test.end();
test.ok(sandbox.window.protobuf, "should load the library as a global");
test.ok(sandbox.window.protobuf.util.Long, "should have loaded long.js after calling the factory function");
test.end();

});

});

});

Expand Down

0 comments on commit 039ac77

Please sign in to comment.