From b28b2059935f0232fc31744f31278714194996f9 Mon Sep 17 00:00:00 2001 From: shanejonas Date: Fri, 27 Aug 2021 09:19:48 -0700 Subject: [PATCH 1/2] fix: custom component relative urls --- src/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3217d6b0..aa466d93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,11 +50,12 @@ interface IComponent { const getComponentFromConfig = async (componentConfig: TComponentConfig): Promise => { 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 } From 8389a87a741957c1565394a0222526c9fcb26a8c Mon Sep 17 00:00:00 2001 From: shanejonas Date: Fri, 27 Aug 2021 09:35:49 -0700 Subject: [PATCH 2/2] fix: customComponent test paths --- src/index.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 19617fd1..4d31dd0d 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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"} ], }); @@ -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"} ], });