Skip to content

Commit

Permalink
Merge pull request #677 from open-rpc/fix/custom-component-relative-urls
Browse files Browse the repository at this point in the history
Fix/custom component relative urls
  • Loading branch information
shanejonas authored Aug 27, 2021
2 parents 5efd58c + 8389a87 commit 912ddce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe(`Examples to generate Js clients`, () => {
{ type: "client", language: "typescript", name: "testclient-ts" },
{ type: "server", language: "typescript", name: "testserver-ts" },
{ type: "docs", language: "gatsby", name: "testserver-gatsby" },
{ type: "custom", language: "typescript", name: "custom-stuff", "customComponent":"./custom-test-component.js", customType:"client"},
{ type: "custom", language: "typescript", name: "custom-stuff2", "customComponent":"./custom-test-component.js", customType:"client", openRPCPath: null},
{ type: "custom", language: "typescript", name: "custom-stuff3", "customComponent":"./custom-test-component.js", customType:"client", openRPCPath: "tmpz"}
{ type: "custom", language: "typescript", name: "custom-stuff", "customComponent":"./src/custom-test-component.js", customType:"client"},
{ type: "custom", language: "typescript", name: "custom-stuff2", "customComponent":"./src/custom-test-component.js", customType:"client", openRPCPath: null},
{ type: "custom", language: "typescript", name: "custom-stuff3", "customComponent":"./src/custom-test-component.js", customType:"client", openRPCPath: "tmpz"}
],
});

Expand All @@ -93,9 +93,9 @@ describe(`Examples to generate Js clients`, () => {
{ type: "client", language: "typescript", name: "testclient-ts" },
{ type: "server", language: "typescript", name: "testserver-ts" },
{ type: "docs", language: "gatsby", name: "testserver-gatsby" },
{ type: "custom", language: "typescript", name: "custom-stuff", "customComponent":"./custom-test-component.js", customType:"client"},
{ type: "custom", language: "typescript", name: "custom-stuff2", "customComponent":"./custom-test-component.js", customType:"client", openRPCPath: null},
{ type: "custom", language: "typescript", name: "custom-stuff3", "customComponent":"./custom-test-component.js", customType:"client", openRPCPath: "tmpz"}
{ type: "custom", language: "typescript", name: "custom-stuff", "customComponent":"./src/custom-test-component.js", customType:"client"},
{ type: "custom", language: "typescript", name: "custom-stuff2", "customComponent":"./src/custom-test-component.js", customType:"client", openRPCPath: null},
{ type: "custom", language: "typescript", name: "custom-stuff3", "customComponent":"./src/custom-test-component.js", customType:"client", openRPCPath: "tmpz"}
],
});

Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ interface IComponent {
const getComponentFromConfig = async (componentConfig: TComponentConfig): Promise<IComponent> => {
const { language, name, type} = componentConfig;
let openRPCPath: string | undefined = "src";
if(componentConfig.type === "custom"){
const compModule: IComponentModule = (await import(componentConfig.customComponent)).default;
if(compModule.hooks === undefined) throw new Error("Hooks interface not exported or defined")
openRPCPath = componentConfig.openRPCPath === null ? undefined : componentConfig.openRPCPath || "src" ;
return { hooks: compModule.hooks, staticPath: compModule.staticPath(language, componentConfig.customType), language, name, type, openRPCPath }
if (componentConfig.type === "custom"){
const componentPath = componentConfig.customComponent.startsWith("./") ? path.resolve(process.cwd(), componentConfig.customComponent) : componentConfig.customComponent
const compModule: IComponentModule = (await import(componentPath)).default;
if(compModule.hooks === undefined) throw new Error("Hooks interface not exported or defined")
openRPCPath = componentConfig.openRPCPath === null ? undefined : componentConfig.openRPCPath || "src" ;
return { hooks: compModule.hooks, staticPath: compModule.staticPath(language, componentConfig.customType), language, name, type, openRPCPath }
}
const componentModule = componentModules[type]
return { hooks: componentModule.hooks, staticPath: componentModule.staticPath(language, type), language, name, type, openRPCPath }
Expand Down

0 comments on commit 912ddce

Please sign in to comment.