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

pbjs overwrite package so seperate compile multiple file of one package is not allowed #1383

Open
yangjuncode opened this issue Mar 31, 2020 · 0 comments

Comments

@yangjuncode
Copy link

protobuf.js version: 6.8.8

we have two proto file a.proto and b.proto

syntax = "proto3";
package ttt;
message A{
    string RID = 1;
}
syntax = "proto3";
package ttt;
message B{
    string RID = 1;
}

when build with pbjs with two file together, the generated file is ok,$root.ttt.A and $root.ttt.B is set right.

pbjs -t static-module -w es6 a.proto b.proto > ttt.js

when build a.proto and b.proto seperately, each output has reset the $root.ttt

export const ttt = $root.ttt = (() => {

    /**
     * Namespace ttt.
     * @exports ttt
     * @namespace
     */
    const ttt = {};

so when import one generated js file will overwrite any previous setting with the same package name.

the solution is changing cli/targets/static.js line 132 to below

push((config.es6 ? "const" : "var") + " " + escapeName(ns.name) + " = {};");

to

push((config.es6 ? "const" : "var") + " " + escapeName(ns.name) + " = $root."+escapeName(ns.name)+" || {};");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant