Skip to content

Commit 16eae28

Browse files
authored
fix(theme): fix serving and exporting local themes (#537)
1 parent a13e63b commit 16eae28

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

lib/builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const themeServer =
33
const fs = require('fs');
44
const request = require('superagent');
55
const chalk = require('chalk');
6-
const renderHtml = require('./render-html');
6+
const renderHtml = require('./render-html').default;
77

88
const denormalizeTheme = (value) => {
99
return value.match(/jsonresume-theme-(.*)/)[1];

lib/render-html.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export default async ({ resume, themePath }) => {
1010
const cwd = process.cwd();
1111
let path;
1212
if (themePath[0] === '.') {
13-
path = tryResolve(path.join(cwd, themePath), { paths: [cwd] });
14-
throw new Error(
15-
`Theme ${themePath} could not be resolved relative to ${cwd}`,
16-
);
13+
path = tryResolve(require('path').join(cwd, themePath), { paths: [cwd] });
14+
if (!path) {
15+
throw new Error(
16+
`Theme ${themePath} could not be resolved relative to ${cwd}`,
17+
);
18+
}
1719
}
1820
if (!path) {
1921
path = tryResolve(themePath, { paths: [cwd] });

lib/render-html.test.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ describe('renderHTML', () => {
55
const originalRequireResolve = require.resolve;
66
const mockThemePath = 'mock/path/to/jsonresume-theme-even';
77
require.resolve = (...args) => {
8-
if (args[0] === 'jsonresume-theme-even') {
9-
return mockThemePath;
10-
}
118
if (args[0] === 'jsonresume-theme-even') {
129
return mockThemePath;
1310
}
@@ -25,13 +22,13 @@ describe('renderHTML', () => {
2522
},
2623
};
2724

28-
it('should reject when theme is not availlable', async () => {
25+
it('should reject when theme is not available', async () => {
2926
await expect(
3027
renderHTML({ resume, themePath: 'unknown' }),
3128
).rejects.toBeTruthy();
3229
});
3330

34-
describe('should render html when theme is availlable', () => {
31+
describe('should render html when theme is available', () => {
3532
it('with long theme name', async () => {
3633
expect(
3734
await renderHTML({ resume, themePath: 'jsonresume-theme-even' }),
@@ -43,5 +40,20 @@ describe('renderHTML', () => {
4340
'<!doctype html>',
4441
);
4542
});
43+
44+
it('should reject theme with invalid path', async () => {
45+
await expect(
46+
renderHTML({ resume, themePath: './unknown' }),
47+
).rejects.toBeTruthy();
48+
});
49+
50+
it('with local theme path', async () => {
51+
expect(
52+
await renderHTML({
53+
resume,
54+
themePath: './node_modules/jsonresume-theme-even',
55+
}),
56+
).toStartWith('<!doctype html>');
57+
});
4658
});
4759
});

0 commit comments

Comments
 (0)