Skip to content

Change 'include' to 'includeDirs' in proto-loader package #298

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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