Skip to content

Commit

Permalink
using resolver to fix deps bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jul 4, 2023
1 parent 11976a7 commit 37cd2c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ exports[`osmosis excluded gamm 1`] = `
"cosmos.bank.v1beta1",
"cosmos.base.query.v1beta1",
"cosmos.base.v1beta1",
"cosmos.msg.v1",
"cosmos.staking.v1beta1",
"cosmos_proto",
"gogoproto",
Expand All @@ -204,13 +205,18 @@ exports[`osmosis excluded gamm 1`] = `
"osmosis.tokenfactory.v1beta1",
"osmosis.twap.v1beta1",
"osmosis.txfees.v1beta1",
"tendermint.crypto",
"tendermint.types",
"tendermint.version",
]
`;

exports[`osmosis/gamm/v1beta1/tx.proto 1`] = `
[
"cosmos.base.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
"osmosis.gamm.v1beta1",
]
`;
2 changes: 1 addition & 1 deletion packages/parser/__tests__/traverse/bad.traversal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ message MyMessage {
store.traverseAll();
} catch (e) {
failed = true;
expect(e.message).toEqual('missing proto import gogoproto/gogo.proto')
expect(e.message).toEqual('Dependency Not Found gogoproto/gogo.proto')
}
expect(failed).toBe(true);
});
Expand Down
24 changes: 15 additions & 9 deletions packages/parser/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import google_empty from './native/empty';
import google_field_mask from './native/field_mask';
import google_struct from './native/struct';
import google_wrappers from './native/wrappers';
import { ProtoResolver } from './resolver';

const GOOGLE_PROTOS = [
['google/protobuf/any.proto', google_any],
Expand Down Expand Up @@ -208,18 +209,23 @@ export class ProtoStore {
}

traverseAll(): void {
if (this._traversed) return;

let actualFiles = new Set();
let resolver = new ProtoResolver(this.getDeps());

if (this._traversed) return;
this.protos = this.getProtos().map((ref: ProtoRef) => {
// get included imported files
const isIncluded = isRefIncluded(ref, this.options.prototypes.includes)
const isExcluded = isRefExcluded(ref, this.options.prototypes.excluded)

if(isIncluded && !isExcluded){
actualFiles.add(ref.filename);
if(ref.proto.imports && ref.proto.imports.length){
actualFiles = new Set([...actualFiles, ...ref.proto.imports])
if( !actualFiles.has(ref.filename) ){
// get included imported files
const isIncluded = isRefIncluded(ref, this.options.prototypes.includes)
const isExcluded = isRefExcluded(ref, this.options.prototypes.excluded)

if(isIncluded && !isExcluded){
const deps = resolver.resolve(ref.filename);

for (const dep of deps) {
actualFiles.add(dep);
}
}
}

Expand Down

0 comments on commit 37cd2c7

Please sign in to comment.