Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c348af2f
Commit
c348af2f
authored
Feb 18, 2016
by
Josh Haberman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addressed more code review comments.
parent
7726cd20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
22 deletions
+28
-22
README.md
js/README.md
+6
-7
rewrite_tests_for_commonjs.js
js/commonjs/rewrite_tests_for_commonjs.js
+22
-15
No files found.
js/README.md
View file @
c348af2f
...
...
@@ -30,17 +30,16 @@ To use Protocol Buffers with JavaScript, you need two main components:
Setup
=====
First, compile the Protocol Compiler.
You can compile
`protoc`
from GitHub or a source tarball. From the
top level directory type:
$ ./autogen.sh (only necessary for GitHub)
$ ./configure
$ make
First, obtain the Protocol Compiler. The easiest way is to download
a pre-built binary from
[
https://github.com/google/protobuf/releases
](
https://github.com/google/protobuf/releases
)
.
If you want, you can compile
`protoc`
from source instead. To do this
follow the instructions in
[
the top-level
README](https://github.com/google/protobuf/blob/master/src/README.md).
Once you have
`protoc`
compiled, you can run the tests by typing:
$ cd js
$ npm install
$ npm test
...
...
js/commonjs/rewrite_tests_for_commonjs.js
View file @
c348af2f
...
...
@@ -19,7 +19,16 @@
*
* This script parses that special comment and uses it to generate proper
* CommonJS require() statements so that the tests can run and pass using
* CommonJS imports.
* CommonJS imports. The script will change the above statements into:
*
* var test_pb = require('test_pb');
* googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global);
* googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global);
* googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global);
*
* (The "exportSymbol" function will define the given names in the global
* namespace, taking care not to overwrite any previous value for
* "proto.jspb.test").
*/
var
lineReader
=
require
(
'readline'
).
createInterface
({
...
...
@@ -37,18 +46,16 @@ function tryStripPrefix(str, prefix) {
var
module
=
null
;
var
pkg
=
null
;
lineReader
.
on
(
'line'
,
function
(
line
)
{
var
is_require
=
line
.
match
(
/goog
\.
require
\(
'
([^
'
]
*
)
'
\)
/
);
var
is_loadfromfile
=
line
.
match
(
/CommonJS-LoadFromFile:
([^
]
*
)
(
.*
)
/
);
var
is_settestonly
=
line
.
match
(
/goog.setTestOnly
()
/
);
if
(
is_settestonly
)
{
// Remove this line.
}
else
if
(
is_require
)
{
var
isRequire
=
line
.
match
(
/goog
\.
require
\(
'
([^
'
]
*
)
'
\)
/
);
var
isLoadFromFile
=
line
.
match
(
/CommonJS-LoadFromFile:
(\S
*
)
(
.*
)
/
);
var
isSetTestOnly
=
line
.
match
(
/goog.setTestOnly
()
/
);
if
(
isRequire
)
{
if
(
module
)
{
// Skip goog.require() lines before the first directive.
var
full
_sym
=
is_r
equire
[
1
];
var
sym
=
tryStripPrefix
(
full
_s
ym
,
pkg
);
console
.
log
(
"googleProtobuf.exportSymbol('"
+
full
_s
ym
+
"', "
+
module
+
sym
+
', global);'
);
var
full
Sym
=
isR
equire
[
1
];
var
sym
=
tryStripPrefix
(
full
S
ym
,
pkg
);
console
.
log
(
"googleProtobuf.exportSymbol('"
+
full
S
ym
+
"', "
+
module
+
sym
+
', global);'
);
}
}
else
if
(
is
_loadfromf
ile
)
{
}
else
if
(
is
LoadFromF
ile
)
{
if
(
!
module
)
{
console
.
log
(
"var googleProtobuf = require('google-protobuf');"
);
console
.
log
(
"var asserts = require('closure_asserts_commonjs');"
);
...
...
@@ -57,13 +64,13 @@ lineReader.on('line', function(line) {
console
.
log
(
"// Bring asserts into the global namespace."
);
console
.
log
(
"googleProtobuf.object.extend(global, asserts);"
);
}
module
=
is
_loadfromf
ile
[
1
].
replace
(
"-"
,
"_"
);
pkg
=
is
_loadfromf
ile
[
2
];
module
=
is
LoadFromF
ile
[
1
].
replace
(
"-"
,
"_"
);
pkg
=
is
LoadFromF
ile
[
2
];
if
(
module
!=
"googleProtobuf"
)
{
// We unconditionally require this in the header.
console
.
log
(
"var "
+
module
+
" = require('"
+
is
_loadfromf
ile
[
1
]
+
"');"
);
console
.
log
(
"var "
+
module
+
" = require('"
+
is
LoadFromF
ile
[
1
]
+
"');"
);
}
}
else
{
}
else
if
(
!
isSetTestOnly
)
{
// Remove goog.setTestOnly() lines.
console
.
log
(
line
);
}
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment