Skip to content

Commit

Permalink
fix: Fix integration test codegen script (#291)
Browse files Browse the repository at this point in the history
The codegen script was importing plugin.ts which expects to read from stdin (which is empty), then calls process.exit. This caused codegen to fail silently.

Co-authored-by: Eric Butler <eric@level.com>
  • Loading branch information
codebutler and Eric Butler authored May 9, 2021
1 parent a32f748 commit a51eee5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions integration/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { CodeGeneratorRequest } from 'ts-proto-descriptors';
import { CodeGeneratorRequest, FileDescriptorProto } from 'ts-proto-descriptors';
import { mkdir, readFile, writeFile } from 'fs';
import { parse } from 'path';
import { promisify } from 'util';
import { generateFile, makeUtils } from '../src/main';
import { createTypeMap } from '../src/types';
import { prefixDisableLinter } from '../src/utils';
import { prefixDisableLinter, protoFilesToGenerate } from '../src/utils';
import { getTsPoetOpts, optionsFromParameter } from '../src/options';
import { Context } from '../src/context';
import { generateTypeRegistry } from '../src/generate-type-registry';
import { protoFilesToGenerate } from '../src/plugin';

/**
* Generates output for our integration tests from their example proto files.
Expand Down
6 changes: 1 addition & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import {
FileDescriptorProto,
} from 'ts-proto-descriptors';
import { promisify } from 'util';
import { prefixDisableLinter, readToBuffer } from './utils';
import { prefixDisableLinter, protoFilesToGenerate, readToBuffer } from './utils';
import { generateFile, makeUtils } from './main';
import { createTypeMap } from './types';
import { Context } from './context';
import { getTsPoetOpts, optionsFromParameter } from './options';
import { generateTypeRegistry } from './generate-type-registry';

export function protoFilesToGenerate(request: CodeGeneratorRequest): FileDescriptorProto[] {
return request.protoFile.filter((f) => request.fileToGenerate.includes(f.name));
}

// this would be the plugin called by the protoc compiler
async function main() {
const stdin = await readToBuffer(process.stdin);
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { code, Code } from 'ts-poet';
import { FileDescriptorProto } from 'ts-proto-descriptors';
import { CodeGeneratorRequest, FileDescriptorProto } from 'ts-proto-descriptors';
import ReadStream = NodeJS.ReadStream;
import { SourceDescription } from './sourceInfo';

export function protoFilesToGenerate(request: CodeGeneratorRequest): FileDescriptorProto[] {
return request.protoFile.filter((f) => request.fileToGenerate.includes(f.name));
}

export function readToBuffer(stream: ReadStream): Promise<Buffer> {
return new Promise((resolve) => {
const ret: Array<Buffer | string> = [];
Expand Down

0 comments on commit a51eee5

Please sign in to comment.