Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix logic for resolving path to themes #578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/render-html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path');

const tryResolve = (...args) => {
try {
return require.resolve(...args);
Expand All @@ -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(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know why there was a throw here. It seems like it would always fail for a path that begins with a dot. I removed that to make it work.

`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');
}
Expand Down