Skip to content

Commit

Permalink
Merge pull request #298 from murgatroid99/proto_loader_include_option…
Browse files Browse the repository at this point in the history
…_name_change

Change 'include' to 'includeDirs' in proto-loader package
  • Loading branch information
murgatroid99 committed Apr 30, 2018
2 parents c9aa5f7 + a63f534 commit 1b9b989
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-protobufjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The options parameter is an object that can have the following optional properti
| `arrays` | `true` or `false` | Set empty arrays for missing array values even if `defaults` is `false` Defaults to `false`.
| `objects` | `true` or `false` | Set empty objects for missing object values even if `defaults` is `false` Defaults to `false`.
| `oneofs` | `true` or `false` | Set virtual oneof properties to the present field's name. Defaults to `false`.
| `include` | An array of strings | A list of search paths for imported `.proto` files.
| `includeDirs` | An array of strings | A list of search paths for imported `.proto` files.

The following options object closely approximates the existing behavior of `grpc.load`:

Expand Down
18 changes: 9 additions & 9 deletions packages/grpc-protobufjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface PackageDefinition {
}

export type Options = Protobuf.IParseOptions & Protobuf.IConversionOptions & {
include?: string[];
includeDirs?: string[];
};

function joinName(baseName: string, name: string): string {
Expand Down Expand Up @@ -154,15 +154,15 @@ function addIncludePathResolver(root: Protobuf.Root, includePaths: string[]) {
* `defaults` is `false`. Defaults to `false`.
* @param options.oneofs Set virtual oneof properties to the present field's
* name
* @param options.include Paths to search for imported `.proto` files.
* @param options.includeDirs Paths to search for imported `.proto` files.
*/
export function load(filename: string, options: Options): Promise<PackageDefinition> {
const root: Protobuf.Root = new Protobuf.Root();
if (!!options.include) {
if (!(options.include instanceof Array)) {
return Promise.reject(new Error('The include option must be an array'));
if (!!options.includeDirs) {
if (!(options.includeDirs instanceof Array)) {
return Promise.reject(new Error('The includeDirs option must be an array'));
}
addIncludePathResolver(root, options.include as string[]);
addIncludePathResolver(root, options.includeDirs as string[]);
}
return root.load(filename, options).then((loadedRoot) => {
loadedRoot.resolveAll();
Expand All @@ -172,11 +172,11 @@ export function load(filename: string, options: Options): Promise<PackageDefinit

export function loadSync(filename: string, options: Options): PackageDefinition {
const root: Protobuf.Root = new Protobuf.Root();
if (!!options.include) {
if (!(options.include instanceof Array)) {
if (!!options.includeDirs) {
if (!(options.includeDirs instanceof Array)) {
throw new Error('The include option must be an array');
}
addIncludePathResolver(root, options.include as string[]);
addIncludePathResolver(root, options.includeDirs as string[]);
}
const loadedRoot = root.loadSync(filename, options);
loadedRoot.resolveAll();
Expand Down
2 changes: 1 addition & 1 deletion test/interop/interop_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var protoPackage = protoLoader.loadSync(
{keepCase: true,
defaults: true,
enums: String,
include: [__dirname + '/../../packages/grpc-native-core/deps/grpc']});
includeDirs: [__dirname + '/../../packages/grpc-native-core/deps/grpc']});
var testProto = grpc.loadPackageDefinition(protoPackage).grpc.testing;

var assert = require('assert');
Expand Down
2 changes: 1 addition & 1 deletion test/interop/interop_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var protoPackage = protoLoader.loadSync(
{keepCase: true,
defaults: true,
enums: String,
include: [__dirname + '/../../packages/grpc-native-core/deps/grpc']});
includeDirs: [__dirname + '/../../packages/grpc-native-core/deps/grpc']});
var testProto = grpc.loadPackageDefinition(protoPackage).grpc.testing;

var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial';
Expand Down

0 comments on commit 1b9b989

Please sign in to comment.