TwirpScript: Using twirpscript with Buf.build is not working due to prettier
Hi !
I am trying to build with the buf client but I am unable to achieve a generation 😕
I created a example repository that you can play with : https://github.com/alexisvisco/protocol-example
Just clone it and run make run (it will take some time because I assume that you are not using buf so I created an image and make run build it)
Output:
/usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:12990
throw error;
^
SyntaxError: Unexpected token (239:53)
237 | const put = json.put ?? json.put;if (put) {msg.put = put;}
238 | const post = json.post ?? json.post;if (post) {msg.post = post;}
> 239 | const delete = json.delete ?? json.delete;if (delete) {msg.delete = delete;}
| ^
240 | const patch = json.patch ?? json.patch;if (patch) {msg.patch = patch;}
241 | const custom = json.custom ?? json.custom;if (custom) {const m = CustomHttpPattern.initialize();CustomHttpPattern._readMessageJSON(m, custom);msg.custom = m;}
242 | const body = json.body ?? json.body;if (body) {msg.body = body;}
at ku (/usr/lib/node_modules/twirpscript/node_modules/prettier/parser-babel.js:1:54892)
at Ou (/usr/lib/node_modules/twirpscript/node_modules/prettier/parser-babel.js:1:55033)
at Object.parse (/usr/lib/node_modules/twirpscript/node_modules/prettier/parser-babel.js:1:381521)
at Object.parse$d [as parse] (/usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:12975:19)
at coreFormat (/usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:14525:16)
at formatWithCursor$1 (/usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:14765:14)
at /usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:60959:12
at format (/usr/lib/node_modules/twirpscript/node_modules/prettier/index.js:60979:12)
at writeFile (/usr/lib/node_modules/twirpscript/dist/compile.js:19:47)
at /usr/lib/node_modules/twirpscript/dist/compile.js:28:9 {
loc: { start: { line: 239, column: 53 } },
codeFrame: ' 237 | const put = json.put ?? json.put;if (put) {msg.put = put;}\n' +
' 238 | const post = json.post ?? json.post;if (post) {msg.post = post;}\n' +
'> 239 | const delete = json.delete ?? json.delete;if (delete) {msg.delete = delete;}\n' +
' | ^\n' +
' 240 | const patch = json.patch ?? json.patch;if (patch) {msg.patch = patch;}\n' +
' 241 | const custom = json.custom ?? json.custom;if (custom) {const m = CustomHttpPattern.initialize();CustomHttpPattern._readMessageJSON(m, custom);msg.custom = m;}\n' +
' 242 | const body = json.body ?? json.body;if (body) {msg.body = body;}'
}
Failure: failed to generate plugins concurrently: failed to execute plugins concurrently: failed to generate: exit status 1.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (6 by maintainers)
@alexisvisco I tracked down the generation issue and fixed it. I’ve published v0.0.48 with the fix. Try it out and LMK if you run into any issues
Hey @alexisvisco thanks for opening this and linking the reproduction. I haven’t looked into running
twirpscriptfrombuf. Right now, TwirpScript assumes that it is compiling all of a project’sprotofiles in a single pass, so there may be a few changes necessary to integrate well withbuf.@tatethurston thanks you so much for your investigation ! It works well I am very happy.
I haven’t tested it yet, I will do it tomorrow (00:01 France ) thank you man for your answer, I will give you feedback asap.
Cool, looks like the
allstrategy resolves the warnings (those are generated because duplicate files are being generated for google’s well known types, which TwirpScript outputs in a separate file rather than inlining).The next issue to tackle is figuring out why
protoc-gen-openapiv2is being generated – looking at thegooutput that is not desirable.Then we’ll need to specify the language output (typescript auto-detection is in the twirpscript cli runner and not the compiler)
@tatethurston yep, using
strategy: allresolve warnings, maybe I should add a tsconfig.json and a package.jsoin at the root of the generation 🤔