From c628876bf695570694e6f0fb9f4bf7c2fd9fddae Mon Sep 17 00:00:00 2001 From: Sean Lang Date: Wed, 12 May 2021 13:32:05 -0500 Subject: [PATCH] fix: fix logic for resolving path to themes --- lib/render-html.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/render-html.js b/lib/render-html.js index c5065f80..2820c367 100644 --- a/lib/render-html.js +++ b/lib/render-html.js @@ -1,3 +1,5 @@ +const path = require('path'); + const tryResolve = (...args) => { try { return require.resolve(...args); @@ -8,25 +10,24 @@ const tryResolve = (...args) => { export default async ({ resume, themePath }) => { const cwd = process.cwd(); - let path; + let resolvedPath; if (themePath[0] === '.') { - path = tryResolve(path.join(cwd, themePath), { paths: [cwd] }); - throw new Error( - `Theme ${themePath} could not be resolved relative to ${cwd}`, - ); + resolvedPath = tryResolve(path.join(cwd, themePath), { paths: [cwd] }); } - if (!path) { - path = tryResolve(themePath, { paths: [cwd] }); + if (!resolvedPath) { + resolvedPath = tryResolve(themePath, { paths: [cwd] }); } - if (!path && /^[a-z0-9]/i.test(path)) { - path = tryResolve(`jsonresume-theme-${themePath}`, { paths: [cwd] }); + if (!resolvedPath && /^[a-z0-9]/i.test(resolvedPath)) { + resolvedPath = tryResolve(`jsonresume-theme-${themePath}`, { + paths: [cwd] + }); } - if (!path) { + if (!resolvedPath) { throw new Error( `theme path ${themePath} could not be resolved from current working directory`, ); } - const theme = require(path); + const theme = require(resolvedPath); if (typeof theme?.render !== 'function') { throw new Error('theme.render is not a function'); }