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: Use a module star import for protobuf types. #540

Merged
merged 1 commit into from
Mar 25, 2022
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
run: yarn test
env:
CI: true
- name: test esmodule interop
working-directory: ./integration/simple-esmodule-interop
run: |
yarn install
yarn tsc
yarn jest
env:
CI: true

release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules/
/build/
node_modules/
build/
/.idea
/.vscode
/integration/*/pbjs.js
Expand Down
14 changes: 7 additions & 7 deletions integration/angular/simple-message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'angular';

Expand All @@ -13,15 +13,15 @@ function createBaseSimpleMessage(): SimpleMessage {
}

export const SimpleMessage = {
encode(message: SimpleMessage, writer: Writer = Writer.create()): Writer {
encode(message: SimpleMessage, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.numberField !== 0) {
writer.uint32(8).int32(message.numberField);
}
return writer;
},

decode(input: Reader | Uint8Array, length?: number): SimpleMessage {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): SimpleMessage {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSimpleMessage();
while (reader.pos < end) {
Expand Down Expand Up @@ -76,9 +76,9 @@ export type Exact<P, I extends P> = P extends Builtin

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (util.Long !== Long) {
util.Long = Long as any;
configure();
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
Expand Down
20 changes: 10 additions & 10 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';
import {
SimpleEnum as SimpleEnum1,
Simple as Simple2,
Expand Down Expand Up @@ -63,7 +63,7 @@ function createBaseSimple(): Simple {
}

export const Simple = {
encode(message: Simple, writer: Writer = Writer.create()): Writer {
encode(message: Simple, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== '') {
writer.uint32(10).string(message.name);
}
Expand All @@ -73,8 +73,8 @@ export const Simple = {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): Simple {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): Simple {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSimple();
while (reader.pos < end) {
Expand Down Expand Up @@ -125,7 +125,7 @@ function createBaseSimpleEnums(): SimpleEnums {
}

export const SimpleEnums = {
encode(message: SimpleEnums, writer: Writer = Writer.create()): Writer {
encode(message: SimpleEnums, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.localEnum !== 0) {
writer.uint32(8).int32(message.localEnum);
}
Expand All @@ -135,8 +135,8 @@ export const SimpleEnums = {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): SimpleEnums {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): SimpleEnums {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSimpleEnums();
while (reader.pos < end) {
Expand Down Expand Up @@ -197,9 +197,9 @@ export type Exact<P, I extends P> = P extends Builtin

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (util.Long !== Long) {
util.Long = Long as any;
configure();
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
Expand Down
14 changes: 7 additions & 7 deletions integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';

export const protobufPackage = 'simple2';

Expand Down Expand Up @@ -52,7 +52,7 @@ function createBaseSimple(): Simple {
}

export const Simple = {
encode(message: Simple, writer: Writer = Writer.create()): Writer {
encode(message: Simple, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== '') {
writer.uint32(10).string(message.name);
}
Expand All @@ -62,8 +62,8 @@ export const Simple = {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): Simple {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): Simple {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSimple();
while (reader.pos < end) {
Expand Down Expand Up @@ -124,9 +124,9 @@ export type Exact<P, I extends P> = P extends Builtin

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (util.Long !== Long) {
util.Long = Long as any;
configure();
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
Expand Down
14 changes: 7 additions & 7 deletions integration/barrel-imports/bar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';

export interface Bar {
name: string;
Expand All @@ -12,7 +12,7 @@ function createBaseBar(): Bar {
}

export const Bar = {
encode(message: Bar, writer: Writer = Writer.create()): Writer {
encode(message: Bar, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== '') {
writer.uint32(10).string(message.name);
}
Expand All @@ -22,8 +22,8 @@ export const Bar = {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): Bar {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): Bar {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseBar();
while (reader.pos < end) {
Expand Down Expand Up @@ -84,9 +84,9 @@ type Exact<P, I extends P> = P extends Builtin

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (util.Long !== Long) {
util.Long = Long as any;
configure();
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
Expand Down
14 changes: 7 additions & 7 deletions integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import * as _m0 from 'protobufjs/minimal';
import { Bar } from './bar';

export interface Foo {
Expand All @@ -13,7 +13,7 @@ function createBaseFoo(): Foo {
}

export const Foo = {
encode(message: Foo, writer: Writer = Writer.create()): Writer {
encode(message: Foo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== '') {
writer.uint32(10).string(message.name);
}
Expand All @@ -23,8 +23,8 @@ export const Foo = {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): Foo {
const reader = input instanceof Reader ? input : new Reader(input);
decode(input: _m0.Reader | Uint8Array, length?: number): Foo {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseFoo();
while (reader.pos < end) {
Expand Down Expand Up @@ -85,9 +85,9 @@ type Exact<P, I extends P> = P extends Builtin

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (util.Long !== Long) {
util.Long = Long as any;
configure();
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
Expand Down
Loading