-
Notifications
You must be signed in to change notification settings - Fork 122
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
yarn-support #488
yarn-support #488
Changes from 3 commits
f0a56d1
f289a5c
ab7e7bb
66fa535
bdc3b1b
035dae2
085b4e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`requireTemplate not valid lodash 1`] = `"Error requiring oc-template: \\"lodash\\" is not a valid oc-template"`; | ||
|
||
exports[`requireTemplate not valid oc-invalid-template 1`] = `"Error requiring oc-template: \\"oc-invalid-template\\" not found"`; | ||
|
||
exports[`requireTemplate valid oc-template-handlebars 1`] = ` | ||
Object { | ||
"compile": [Function], | ||
"getCompiledTemplate": [Function], | ||
"getInfo": [Function], | ||
"render": [Function], | ||
} | ||
`; | ||
|
||
exports[`requireTemplate valid oc-template-jade 1`] = ` | ||
Object { | ||
"compile": [Function], | ||
"getCompiledTemplate": [Function], | ||
"getInfo": [Function], | ||
"render": [Function], | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const requireTemplate = require('../../../src/utils/require-template'); | ||
|
||
describe('requireTemplate', () => { | ||
test('expect type of `requireTemplate` to be function', () => { | ||
expect(typeof requireTemplate).toBe('function'); | ||
}); | ||
|
||
describe('valid', () => { | ||
const scenarios = [ | ||
{ name: 'oc-template-handlebars' }, | ||
{ name: 'oc-template-jade' } | ||
]; | ||
|
||
scenarios.forEach(({ name }) => { | ||
test(name, () => { | ||
const template = requireTemplate(name); | ||
|
||
['compile', 'getCompiledTemplate', 'getInfo', 'render'] | ||
.forEach((method) => { | ||
expect(template).toHaveProperty(method); | ||
}); | ||
expect(template).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('not valid', () => { | ||
const scenarios = [ | ||
{ name: 'lodash' }, | ||
{ name: 'oc-invalid-template' } | ||
]; | ||
|
||
scenarios.forEach(({ name }) => { | ||
test(name, () => { | ||
const sut = () => { | ||
requireTemplate(name); | ||
}; | ||
|
||
expect(sut).toThrow(); | ||
expect(sut).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,14 @@ function isValidTemplate(template) { | |
); | ||
} | ||
|
||
module.exports = function(template) { | ||
const getOcTemplate = (path) => { | ||
if (require.cache && !!require.cache[path]) { | ||
delete require.cache[path]; | ||
} | ||
return require(path); | ||
}; | ||
|
||
module.exports = function (template) { | ||
let ocTemplate; | ||
const localTemplate = path.join( | ||
__dirname, | ||
|
@@ -28,23 +35,21 @@ module.exports = function(template) { | |
const relativeTemplate = path.resolve('.', 'node_modules', template); | ||
|
||
try { | ||
if (require.cache && !!require.cache[localTemplate]) { | ||
delete require.cache[localTemplate]; | ||
} | ||
ocTemplate = require(localTemplate); | ||
ocTemplate = getOcTemplate(template); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only "new" code I've added that tries to fix the yarn issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about my ignorance, but how can that change affect over the yarn installation behavior? I only see you moved the logic to a function 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is another problem; you need to rm -rf node_modules first, it is a known issue w/ npmlog when switching between npm and yarn 😢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After manually installing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very good; we are getting there 😉 thanks for your help! // cc @matteofigus @nickbalestra |
||
} catch (err) { | ||
try { | ||
if (require.cache && !!require.cache[relativeTemplate]) { | ||
delete require.cache[relativeTemplate]; | ||
} | ||
ocTemplate = require(relativeTemplate); | ||
ocTemplate = getOcTemplate(localTemplate); | ||
} catch (err) { | ||
throw format(templateNotFound, template); | ||
try { | ||
ocTemplate = getOcTemplate(relativeTemplate); | ||
} catch (err) { | ||
throw new Error(format(templateNotFound, template)); | ||
} | ||
} | ||
} | ||
|
||
if (!isValidTemplate(ocTemplate)) { | ||
throw format(templateNotValid, template); | ||
throw new Error(format(templateNotValid, template)); | ||
} | ||
|
||
return ocTemplate; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to understand, in case of yarn install, why this doesn't work. The oc-template-jade module must be there if yarn installed everything correctly, if it is not we need to find out where it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the infinite-loop-loader. It should be in the node_modules.