Skip to content

Commit

Permalink
fix: add .js suffix to proto cross-reference imports (#602)
Browse files Browse the repository at this point in the history
When importing a cross-referenced file, a line like this is generated:

  import { MyMessage } from '../myother/myother'

.. assuming there's a proto at ../myother/myother.proto

But if we add the suffix '.pb.ts' to the generated files:

  import { MyMessage } from '../myother/myother.pb'

Is not recognized as a TypeScript import by tsc because of the .pb suffix.

To fix this, we can just add .js, and the TypeScript compiler recognizes that we actually mean the .ts file:

  import { MyMessage } from '../myother/myother.pb.js'

Fixes #601

Fix the resolution in ts-jest with the jest-ts-webcompat-resolver:
See: kulshekhar/ts-jest#1057 (comment)

Signed-off-by: Christian Stewart <christian@paral.in>
  • Loading branch information
paralin authored Jul 2, 2022
1 parent 36f66b0 commit 8dc38af
Show file tree
Hide file tree
Showing 45 changed files with 1,011 additions and 1,898 deletions.
2 changes: 1 addition & 1 deletion integration/avoid-import-conflicts-types-only/simple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import type { SimpleEnum as SimpleEnum1, Simple as Simple2 } from './simple2';
import type { SimpleEnum as SimpleEnum1, Simple as Simple2 } from './simple2.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Simple as Simple2,
simpleEnumFromJSON as simpleEnumFromJSON3,
simpleEnumToJSON as simpleEnumToJSON4,
} from './simple2';
} from './simple2.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
2 changes: 1 addition & 1 deletion integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Bar } from './bar';
import { Bar } from './bar.js';
import * as _m0 from 'protobufjs/minimal';

export interface Foo {
Expand Down
2 changes: 1 addition & 1 deletion integration/bytes-node/point.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { BytesValue } from './google/protobuf/wrappers';
import { BytesValue } from './google/protobuf/wrappers.js';

export const protobufPackage = '';

Expand Down
2 changes: 1 addition & 1 deletion integration/fieldmask/fieldmask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { FieldMask } from './google/protobuf/field_mask';
import { FieldMask } from './google/protobuf/field_mask.js';

export const protobufPackage = '';

Expand Down
4 changes: 2 additions & 2 deletions integration/file-suffix/parent.pb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { ChildEnum, Child, childEnumFromJSON, childEnumToJSON } from './child.pb';
import { Timestamp } from './google/protobuf/timestamp.pb';
import { ChildEnum, Child, childEnumFromJSON, childEnumToJSON } from './child.pb.js';
import { Timestamp } from './google/protobuf/timestamp.pb.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'file_suffix';
Expand Down
8 changes: 4 additions & 4 deletions integration/grpc-js/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
ClientDuplexStream,
ServiceError,
} from '@grpc/grpc-js';
import { Timestamp } from './google/protobuf/timestamp';
import { Empty } from './google/protobuf/empty';
import { Timestamp } from './google/protobuf/timestamp.js';
import { Empty } from './google/protobuf/empty.js';
import {
StringValue,
Int64Value,
Expand All @@ -29,8 +29,8 @@ import {
FloatValue,
DoubleValue,
BoolValue,
} from './google/protobuf/wrappers';
import { Struct, ListValue, Value } from './google/protobuf/struct';
} from './google/protobuf/wrappers.js';
import { Struct, ListValue, Value } from './google/protobuf/struct.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
3 changes: 2 additions & 1 deletion integration/meta-typings/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable */
import { FileDescriptorProto } from 'ts-proto-descriptors';
import { protoMetadata as protoMetadata1, Timestamp } from '../google/protobuf/timestamp';
import { protoMetadata as protoMetadata1 } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
12 changes: 8 additions & 4 deletions integration/meta-typings/simple.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable */
import { FileDescriptorProto } from 'ts-proto-descriptors';
import { protoMetadata as protoMetadata1, DateMessage } from './google/type/date';
import { protoMetadata as protoMetadata2, StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers';
import { protoMetadata as protoMetadata3, Timestamp } from './google/protobuf/timestamp';
import { protoMetadata as protoMetadata4, ImportedThing } from './import_dir/thing';
import { protoMetadata as protoMetadata1 } from './google/type/date';
import { protoMetadata as protoMetadata2 } from './google/protobuf/wrappers';
import { protoMetadata as protoMetadata3 } from './google/protobuf/timestamp';
import { protoMetadata as protoMetadata4 } from './import_dir/thing';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import { ImportedThing } from './import_dir/thing.js';
import { DateMessage } from './google/type/date.js';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-simple-restparameters/hero.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from '@nestjs/microservices';
import { Observable } from 'rxjs';
import { Empty } from './google/protobuf/empty';
import { Empty } from './google/protobuf/empty.js';

export const protobufPackage = 'hero';

Expand Down
4 changes: 2 additions & 2 deletions integration/nestjs-simple/hero.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from '@nestjs/microservices';
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import { Observable } from 'rxjs';
import { Empty } from './google/protobuf/empty';
import { Empty } from './google/protobuf/empty.js';

export const protobufPackage = 'hero';

Expand Down
8 changes: 4 additions & 4 deletions integration/nice-grpc/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { CallContext, CallOptions } from 'nice-grpc-common';
import { Timestamp } from './google/protobuf/timestamp';
import { Empty } from './google/protobuf/empty';
import { Timestamp } from './google/protobuf/timestamp.js';
import { Empty } from './google/protobuf/empty.js';
import {
StringValue,
Int64Value,
Expand All @@ -12,8 +12,8 @@ import {
FloatValue,
DoubleValue,
BoolValue,
} from './google/protobuf/wrappers';
import { Struct, Value, ListValue } from './google/protobuf/struct';
} from './google/protobuf/wrappers.js';
import { Struct, Value, ListValue } from './google/protobuf/struct.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
2 changes: 1 addition & 1 deletion integration/oneof-unions-snake/simple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { Struct } from './google/protobuf/struct';
import { Struct } from './google/protobuf/struct.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/oneof-unions/oneof.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { Value } from './google/protobuf/struct';
import { Value } from './google/protobuf/struct.js';

export const protobufPackage = 'oneof';

Expand Down
2 changes: 1 addition & 1 deletion integration/only-types/reservation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import type { Any } from './google/protobuf/any';
import type { Any } from './google/protobuf/any.js';

export const protobufPackage = 'event';

Expand Down
3 changes: 2 additions & 1 deletion integration/options/options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable */
import { FileDescriptorProto as FileDescriptorProto1 } from 'ts-proto-descriptors';
import { protoMetadata as protoMetadata1 } from './google/protobuf/descriptor';
import { protoMetadata as protoMetadata2, Something } from './something/something';
import { protoMetadata as protoMetadata2 } from './something/something';
import * as _m0 from 'protobufjs/minimal';
import { Something } from './something/something.js';

export const protobufPackage = '';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-json-name/simple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
4 changes: 2 additions & 2 deletions integration/simple-long-string/simple.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';
import { UInt64Value } from './google/protobuf/wrappers';
import { UInt64Value } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-long/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue, Int64Value } from './google/protobuf/wrappers';
import { StringValue, Int32Value, BoolValue, Int64Value } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-optionals/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
6 changes: 3 additions & 3 deletions integration/simple-optionals/simple.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */
import { ImportedThing } from './import_dir/thing';
import { Timestamp } from './google/protobuf/timestamp';
import { ImportedThing } from './import_dir/thing.js';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-optionals/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-prototype-defaults/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
8 changes: 4 additions & 4 deletions integration/simple-prototype-defaults/simple.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import { ImportedThing } from './import_dir/thing';
import { DateMessage } from './google/type/date';
import { ImportedThing } from './import_dir/thing.js';
import { DateMessage } from './google/type/date.js';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue, BytesValue } from './google/protobuf/wrappers';
import { StringValue, Int32Value, BoolValue, BytesValue } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-snake/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
8 changes: 4 additions & 4 deletions integration/simple-snake/simple.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import { ImportedThing } from './import_dir/thing';
import { ImportedThing } from './import_dir/thing.js';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers';
import { Struct } from './google/protobuf/struct';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers.js';
import { Struct } from './google/protobuf/struct.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple-string-enums/simple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { NullValue, nullValueToNumber, nullValueFromJSON, nullValueToJSON } from './google/protobuf/struct';
import { NullValue, nullValueToNumber, nullValueFromJSON, nullValueToJSON } from './google/protobuf/struct.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-unrecognized-enum/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
6 changes: 3 additions & 3 deletions integration/simple-unrecognized-enum/simple.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import { ImportedThing } from './import_dir/thing';
import { ImportedThing } from './import_dir/thing.js';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers';
import { StringValue, Int32Value, BoolValue } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/simple/import_dir/thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from '../google/protobuf/timestamp';
import { Timestamp } from '../google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple';
Expand Down
8 changes: 4 additions & 4 deletions integration/simple/simple.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as Long from 'long';
import { ImportedThing } from './import_dir/thing';
import { DateMessage } from './google/type/date';
import { ImportedThing } from './import_dir/thing.js';
import { DateMessage } from './google/type/date.js';
import * as _m0 from 'protobufjs/minimal';
import { StringValue, Int32Value, BoolValue, BytesValue } from './google/protobuf/wrappers';
import { StringValue, Int32Value, BoolValue, BytesValue } from './google/protobuf/wrappers.js';

export const protobufPackage = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion integration/struct/struct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { Struct } from './google/protobuf/struct';
import { Struct } from './google/protobuf/struct.js';

export const protobufPackage = '';

Expand Down
2 changes: 1 addition & 1 deletion integration/type-registry/bar/bar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { messageTypeRegistry } from '../typeRegistry';
import { Foo } from '../foo';
import { Foo } from '../foo.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'foo.bar';
Expand Down
4 changes: 2 additions & 2 deletions integration/type-registry/foo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
import { messageTypeRegistry } from './typeRegistry';
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';
import { Struct } from './google/protobuf/struct';
import { Struct } from './google/protobuf/struct.js';

export const protobufPackage = 'foo';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from 'long';
import { FileDescriptorProto, GeneratedCodeInfo } from '../../../google/protobuf/descriptor';
import { FileDescriptorProto, GeneratedCodeInfo } from '../descriptor.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'google.protobuf.compiler';
Expand Down
2 changes: 1 addition & 1 deletion integration/use-date-false/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = '';
Expand Down
2 changes: 1 addition & 1 deletion integration/use-date-string/use-date-string.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Timestamp } from './google/protobuf/timestamp.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = '';
Expand Down
4 changes: 2 additions & 2 deletions integration/use-date-true/use-date-true.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { Timestamp } from './google/protobuf/timestamp';
import { Empty } from './google/protobuf/empty';
import { Timestamp } from './google/protobuf/timestamp.js';
import { Empty } from './google/protobuf/empty.js';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import * as mongodb from 'mongodb';
import * as _m0 from 'protobufjs/minimal';
import { ObjectId } from './objectid/objectid';
import { ObjectId } from './objectid/objectid.js';

export const protobufPackage = 'foo';

Expand Down
4 changes: 2 additions & 2 deletions integration/value/value.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import * as _m0 from 'protobufjs/minimal';
import { Value, ListValue, Struct } from './google/protobuf/struct';
import { StringValue } from './google/protobuf/wrappers';
import { Value, ListValue, Struct } from './google/protobuf/struct.js';
import { StringValue } from './google/protobuf/wrappers.js';

export const protobufPackage = '';

Expand Down
Loading

0 comments on commit 8dc38af

Please sign in to comment.