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: fixing theme resolution for node greater than version 10 #469

Merged
Merged
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
44 changes: 25 additions & 19 deletions lib/render-html.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import path from 'path';
const tryResolve = (...args) => {
try {
return require.resolve(...args);
} catch (err) {
return false;
}
};

export default async ({ resume, themePath }) => {
const cwd = process.cwd();
let resolvedThemePath = themePath;
try {
if (themePath[0] === '.') {
resolvedThemePath = path.join(process.cwd(), themePath, 'index.js');
} else {
try {
resolvedThemePath = require.resolve(themePath, {
paths: process.cwd(),
});
} catch (err) {
resolvedThemePath = require.resolve(`jsonresume-theme-${themePath}`, {
paths: process.cwd(),
});
}
}
} catch (err) {
throw new Error(`Theme ${themePath} could not be resolved from ${cwd}`);
let path;
if (themePath[0] === '.') {
path = tryResolve(path.join(cwd, themePath), { paths: [cwd] });
Copy link

Choose a reason for hiding this comment

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

how can this work ? path is never initialized before this instruction

let path;
// #=> undefined
path.join(cwd, themePath)
// #=> Uncaught TypeError: Cannot read property 'join' of undefined
resume export --theme . --format html /tmp/output.html

(node:11456) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'join' of undefined
at _default (/usr/local/lib/node_modules/resume-cli/build/render-html.js:24:28)

throw new Error(
`Theme ${themePath} could not be resolved relative to ${cwd}`,
);
}
if (!path) {
path = tryResolve(themePath, { paths: [cwd] });
}
if (!path && /^[a-z0-9]/i.test(path)) {
path = tryResolve(`jsonresume-theme-${themePath}`, { paths: [cwd] });
}
if (!path) {
throw new Error(
`theme path ${themePath} could not be resolved from current working directory`,
);
}
const theme = require(resolvedThemePath);
const theme = require(path);
if (typeof theme?.render !== 'function') {
throw new Error('theme.render is not a function');
}
Expand Down