Skip to content

Commit

Permalink
Merge pull request #324 from Zetazzz/bundle-gen-bug
Browse files Browse the repository at this point in the history
Bundle gen bug
  • Loading branch information
pyramation authored Mar 3, 2023
2 parents 72d6f35 + ca319e5 commit 548683f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 26 deletions.
1 change: 0 additions & 1 deletion __fixtures__/v-next/outputv2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export * from "./ibc/client";
export * from "./osmosis/bundle";
export * from "./osmosis/client";
export * from "./tendermint/bundle";
export * from "./hooks";
export * from "./extern";
export * from "./react-query";
export * from "./grpc-web";
2 changes: 0 additions & 2 deletions __fixtures__/v-next/outputv3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export * from "./ibc/client";
export * from "./osmosis/bundle";
export * from "./osmosis/client";
export * from "./tendermint/bundle";
export * from "./hooks";
export * from "./stores";
export * from "./extern";
export * from "./react-query";
export * from "./mobx";
Expand Down
11 changes: 11 additions & 0 deletions packages/telescope/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class TelescopeBuilder {
readonly rpcQueryClients: BundlerFile[] = [];
readonly rpcMsgClients: BundlerFile[] = [];
readonly registries: BundlerFile[] = [];
readonly stateManagers: Record<string, BundlerFile[]> = {};

constructor({
protoDirs,
Expand All @@ -77,6 +78,16 @@ export class TelescopeBuilder {
return ctx;
}

addStateManagers(type: string, files: BundlerFile[]) {
const state = this.stateManagers[type];

if(!state){
this.stateManagers[type] = [];
}

[].push.apply(this.stateManagers[type], files);
}

addRPCQueryClients(files: BundlerFile[]) {
[].push.apply(this.rpcQueryClients, files);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/telescope/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Bundler {
readonly rpcQueryClients: BundlerFile[] = [];
readonly rpcMsgClients: BundlerFile[] = [];
readonly registries: BundlerFile[] = [];
readonly stateManagers: Record<string, BundlerFile[]> = {};

constructor(
builder: TelescopeBuilder,
Expand All @@ -31,6 +32,18 @@ export class Bundler {
]
}

addStateManagers(type: string, files: BundlerFile[]) {
const state = this.stateManagers[type];

if(!state){
this.stateManagers[type] = [];
}

[].push.apply(this.stateManagers[type], files);

this.builder.addStateManagers(type, files);
}

addLCDClients(files: BundlerFile[]) {
[].push.apply(this.lcdClients, files);
this.builder.addLCDClients(files);
Expand Down
8 changes: 7 additions & 1 deletion packages/telescope/src/generators/create-mobx-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export const plugin = (builder: TelescopeBuilder) => {

// get mapping of packages and rpc query filenames.
const obj = {};
builder.rpcQueryClients.map((queryClient) => {
const bundlerFiles = builder.stateManagers["mobx"];

if(!bundlerFiles || !bundlerFiles.length){
return;
}

bundlerFiles.map((queryClient) => {
const path = `./${queryClient.localname.replace(/\.ts$/, '')}`;
dotty.put(obj, queryClient.package, path);
});
Expand Down
12 changes: 9 additions & 3 deletions packages/telescope/src/generators/create-react-query-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ export const plugin = (

// get mapping of packages and rpc query filenames.
const obj = {};
builder.rpcQueryClients.map(queryClient => {
const path = `./${queryClient.localname.replace(/\.ts$/, '')}`;
dotty.put(obj, queryClient.package, path);
const bundlerFiles = builder.stateManagers["reactQuery"];

if(!bundlerFiles || !bundlerFiles.length){
return;
}

bundlerFiles.map(bundlerFile => {
const path = `./${bundlerFile.localname.replace(/\.ts$/, '')}`;
dotty.put(obj, bundlerFile.package, path);
});

// create proto ref for context
Expand Down
40 changes: 21 additions & 19 deletions packages/telescope/src/generators/create-rpc-query-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const plugin = (
builder: TelescopeBuilder,
bundler: Bundler
) => {
const reactQueryBundlerFiles = [];
const mobxBundlerFiles = [];

const clients = bundler.contexts.map(c => {

Expand Down Expand Up @@ -73,6 +75,12 @@ export const plugin = (
const localname = bundler.getLocalFilename(c.ref, `rpc.${name}`);
const filename = bundler.getFilename(localname);

const bundlerFile = {
package: c.ref.proto.package,
localname,
filename
};

const asts = [];

switch (c.proto.pluginValue('rpcClients.type')) {
Expand Down Expand Up @@ -132,23 +140,19 @@ export const plugin = (
[].push.apply(asts, createRpcQueryHookInterfaces(ctx.generic, svc));
[].push.apply(asts, createRpcQueryHookClientMap(ctx.generic, svc));
asts.push(createRpcQueryHooks(ctx.generic, proto[svcKey]));
}

// see if current file has been pinia enabled and included
const includePinia = c.proto.pluginValue('pinia.enabled') && isRefIncluded(
c.ref,
c.proto.pluginValue('pinia.include')
)
reactQueryBundlerFiles.push(bundlerFile);
}

if (includePinia) {
const mobxQueryStoreAst = createMobxQueryStores(
ctx.generic,
proto[svcKey]
);
// whether mobx plugin is enabled has been dealt with inside createMobxQueryStores
const mobxQueryStoreAst = createMobxQueryStores(
ctx.generic,
proto[svcKey]
);

if (mobxQueryStoreAst) {
asts.push(mobxQueryStoreAst);
}
if (mobxQueryStoreAst) {
asts.push(mobxQueryStoreAst);
mobxBundlerFiles.push(bundlerFile);
}
}
});
Expand All @@ -173,13 +177,11 @@ export const plugin = (
bundler.writeAst(prog, filename);
bundler.addToBundle(c, localname);

return {
package: c.ref.proto.package,
localname,
filename
};
return bundlerFile;

}).filter(Boolean);

bundler.addRPCQueryClients(clients);
bundler.addStateManagers("reactQuery", reactQueryBundlerFiles);
bundler.addStateManagers("mobx", mobxBundlerFiles);
};

0 comments on commit 548683f

Please sign in to comment.