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: import fails when folder name overlaps with file name #1000

Merged
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
Binary file not shown.
14 changes: 14 additions & 0 deletions integration/avoid-import-conflicts-folder-name/ui.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package simple2;

enum SimpleEnum {
IMPORT_DEFAULT = 0;
IMPORT_FOO = 10;
IMPORT_BAR = 11;
}

message Simple {
string simple2Name = 1;
int32 simple2Age = 2;
}

138 changes: 138 additions & 0 deletions integration/avoid-import-conflicts-folder-name/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* eslint-disable */
import * as _m0 from "protobufjs/minimal";

export const protobufPackage = "simple2";

export enum SimpleEnum {
IMPORT_DEFAULT = 0,
IMPORT_FOO = 10,
IMPORT_BAR = 11,
UNRECOGNIZED = -1,
}

export function simpleEnumFromJSON(object: any): SimpleEnum {
switch (object) {
case 0:
case "IMPORT_DEFAULT":
return SimpleEnum.IMPORT_DEFAULT;
case 10:
case "IMPORT_FOO":
return SimpleEnum.IMPORT_FOO;
case 11:
case "IMPORT_BAR":
return SimpleEnum.IMPORT_BAR;
case -1:
case "UNRECOGNIZED":
default:
return SimpleEnum.UNRECOGNIZED;
}
}

export function simpleEnumToJSON(object: SimpleEnum): string {
switch (object) {
case SimpleEnum.IMPORT_DEFAULT:
return "IMPORT_DEFAULT";
case SimpleEnum.IMPORT_FOO:
return "IMPORT_FOO";
case SimpleEnum.IMPORT_BAR:
return "IMPORT_BAR";
case SimpleEnum.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
}
}

export interface Simple {
simple2Name: string;
simple2Age: number;
}

function createBaseSimple(): Simple {
return { simple2Name: "", simple2Age: 0 };
}

export const Simple = {
encode(message: Simple, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.simple2Name !== "") {
writer.uint32(10).string(message.simple2Name);
}
if (message.simple2Age !== 0) {
writer.uint32(16).int32(message.simple2Age);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): Simple {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSimple();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}

message.simple2Name = reader.string();
continue;
case 2:
if (tag !== 16) {
break;
}

message.simple2Age = reader.int32();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): Simple {
return {
simple2Name: isSet(object.simple2Name) ? globalThis.String(object.simple2Name) : "",
simple2Age: isSet(object.simple2Age) ? globalThis.Number(object.simple2Age) : 0,
};
},

toJSON(message: Simple): unknown {
const obj: any = {};
if (message.simple2Name !== "") {
obj.simple2Name = message.simple2Name;
}
if (message.simple2Age !== 0) {
obj.simple2Age = Math.round(message.simple2Age);
}
return obj;
},

create<I extends Exact<DeepPartial<Simple>, I>>(base?: I): Simple {
return Simple.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<Simple>, I>>(object: I): Simple {
const message = createBaseSimple();
message.simple2Name = object.simple2Name ?? "";
message.simple2Age = object.simple2Age ?? 0;
return message;
},
};

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function isSet(value: any): boolean {
return value !== null && value !== undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SimpleEnums } from "./simple";

describe("avoid-import-conflicts-folder-name", () => {
it("compiles", () => {
expect(SimpleEnums).not.toBeUndefined();
});
});
Binary file not shown.
22 changes: 22 additions & 0 deletions integration/avoid-import-conflicts-folder-name/ui/simple.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package simple;

import "ui.proto";

enum SimpleEnum {
LOCAL_DEFAULT = 0;
LOCAL_FOO = 1;
LOCAL_BAR = 2;
}

message Simple {
string name = 1;
simple2.Simple otherSimple = 2;
}

message SimpleEnums {
SimpleEnum local_enum = 1;
simple2.SimpleEnum import_enum = 2;
}


Loading
Loading