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

fix: Only generate files in fileToGenerate #283

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

emil-e
Copy link
Contributor

@emil-e emil-e commented Apr 23, 2021

According to doc comments in plugin.proto from Google:

// The .proto files that were explicitly listed on the command-line.  The
// code generator should generate code only for these files.  Each file's
// descriptor will be included in proto_file, below.
repeated string file_to_generate = 1;

@emil-e emil-e changed the title Only generate files in fileToGenerate fix: Only generate files in fileToGenerate Apr 23, 2021
@@ -31,7 +31,7 @@ async function generate(binFile: string, baseDir: string, parameter: string) {
const options = optionsFromParameter(parameter || '');
const typeMap = createTypeMap(request, options);

for (let file of request.protoFile) {
for (let file of request.fileToGenerate) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes compile errors due to the generateFile call on line 38 still wanting the FileDescriptorProto but fileToGenerate is just a string[].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look!

@emil-e
Copy link
Contributor Author

emil-e commented Apr 27, 2021

@stephenh How about that?

src/plugin.ts Outdated
if (descriptor === undefined) {
throw new Error(`Cannot find descriptor for file-to-generate: ${fileName}`);
}
const [path, code] = generateFile(ctx, descriptor);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this looks good. Just to make sure src/plugin.ts and integration/codegen.ts stay in sync (I've had bugs come up from them drifting before), how about:

  • Add a new function protoFilesToGenerate(request): FileDescriptorProto[] in src/plugin.ts that returns request.protoFile.filter(f => request.filesToGenerate.includes(f.name));
  • Make line 23 in src/plugin.ts be protoFilesToGenerate(request).map(async file =>
  • Make line 34 in codegen.ts be for (let file of protoFilesToGenerate(request)) {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable, will make the change.

@stephenh stephenh merged commit a32f748 into stephenh:main Apr 29, 2021
@stephenh
Copy link
Owner

stephenh commented May 9, 2021

🎉 This PR is included in version 1.79.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

doochik added a commit to doochik/ts-proto that referenced this pull request May 22, 2021
Fixes stephenh#294.
This commit puts changes from stephenh#283 behind the flag.
doochik added a commit to doochik/ts-proto that referenced this pull request May 23, 2021
stephenh pushed a commit that referenced this pull request May 23, 2021
* feat: implemented emitImportedFiles flag

Fixes #294.
This commit puts changes from #283 behind the flag.

* fix: revert changes from #283
stephenh pushed a commit that referenced this pull request May 23, 2021
# [1.81.0](v1.80.1...v1.81.0) (2021-05-23)

### Features

* implemented emitImportedFiles flag ([#302](#302)) ([16b4aca](16b4aca)), closes [#294](#294) [#283](#283) [#283](#283)
zfy0701 added a commit to sentioxyz/ts-proto that referenced this pull request Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants