Skip to content

Commit 88f5a76

Browse files
authored
fix: Correct ES6 wrapper imports in static-module output (#2151)
1 parent 2fe8b09 commit 88f5a76

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

cli/targets/static-module.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ function static_module_target(root, options, callback) {
1818
return;
1919
}
2020
try {
21-
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/minimal" }, options));
21+
output = util.wrap(output, protobuf.util.merge({
22+
dependency: options.wrap === "es6"
23+
? "protobufjs/minimal.js"
24+
: "protobufjs/minimal"
25+
}, options));
2226
} catch (e) {
2327
callback(e);
2428
return;

cli/wrappers/es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as $protobuf from $DEPENDENCY;
1+
import $protobuf from $DEPENDENCY;
22

33
$OUTPUT;
44

tests/cli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ tape.test("pbjs generates static code", function(test) {
9393
});
9494
});
9595

96+
tape.test("pbjs generates correct ES6 static-module imports", function(test) {
97+
cliTest(test, function() {
98+
var root = protobuf.loadSync("tests/data/cli/test.proto");
99+
root.resolveAll();
100+
101+
var staticModuleTarget = require("../cli/targets/static-module");
102+
103+
staticModuleTarget(root, {
104+
wrap: "es6",
105+
}, function(err, jsCode) {
106+
test.error(err, "static-module code generation worked");
107+
test.ok(jsCode.includes("import $protobuf from \"protobufjs/minimal.js\";"), "es6 wrapper uses a default import and explicit .js extension");
108+
test.end();
109+
});
110+
});
111+
});
112+
96113
tape.test("without null-defaults, absent optional fields have zero values", function(test) {
97114
cliTest(test, function() {
98115
var root = protobuf.loadSync("tests/data/cli/null-defaults.proto");

0 commit comments

Comments
 (0)