stephenh / ts-poet

A code generator DSL for typescript
Apache License 2.0
103 stars 13 forks source link

Get relative path error #48

Closed fengpeng closed 1 year ago

fengpeng commented 1 year ago

Maybe there's a problem with the code: https://github.com/stephenh/ts-poet/blob/2b7173b4f9379bb8865f6f57cbffdd58cf6afe5b/src/Import.ts#L377-L390

My proto files directory structure:

./proto_files/zeus
├── attributes
│   ├── commons.proto
│   └── extended_method.proto
├── attributes.proto
└── token.proto

The extended_method.proto content:

...
import "zeus/commons.proto";
**import "zeus/attributes.proto";**
...

outputPathDir value is ./zues/attributes; importPath value also is ./zues/attributes https://github.com/stephenh/ts-poet/blob/2b7173b4f9379bb8865f6f57cbffdd58cf6afe5b/src/Import.ts#L384

The result is

import { AttrSource, Subject } from "./";
// It should be 
import { AttrSource, Subject } from "../attributes";
fengpeng commented 1 year ago

I try fix it, but there should be a better way

let relativePath = path.relative(outputPathDir, `${importPath}.proto`).split(path.sep).join(path.posix.sep);
relativePath = relativePath.replace('.proto', '');
stephenh commented 1 year ago

Hi @fengpeng , sorry for the late reply. I'm not 100% following what the bug is, although in general I'm not surprised there is some nuance/tricky-ness here.

Even if the bug is in ts-poet, do you mind creating a reproduction in ts-proto? Even if the bug ends up being in ts-poet, I think that would help me best understanding your use case/what is going wrong.

Thanks!

fengpeng commented 1 year ago

OK~