-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Refactor lib/creator and integrate validation in migrate #99
Conversation
Lays the groundwork for a first release. Integrated Validation to migrate, refactored creator for the init feature to not be circular and made a cleaner structure to the project inside lib/creator.
@okonet Better to open this in PR in a text editor to see the changes. Could you review once you find the time? |
module.exports = function (promptOptions) { | ||
const promptParams = Object.keys(promptOptions); | ||
if (promptParams && promptParams.length) { | ||
let ast = j('{}'); |
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.
That's not the Object
as you might expect. This is a block statement. See https://astexplorer.net/#/gist/8ae05b2650bc27d2c4923ef8e6f36241/0a32afa94ee7cd5ecd742958c815706d34201345
.forEach( | ||
p => p.value.properties.push( | ||
j.property('init', j.literal('output'), | ||
j.objectExpression([j.property('init', j.literal('filename'), j.literal(value))]))) |
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.
You should check out the utils we've written for migrate feature: https://github.com/webpack/webpack-cli/blob/master/lib/transformations/utils.js#L82
fs.writeFileSync(outputConfigPath, result, 'utf8'); | ||
console.log(chalk.green(`✔︎ New webpack v2 config file is at ${outputConfigPath}`)); | ||
fs.writeFile(outputConfigPath, result, 'utf8', (err) => { | ||
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, require(outputConfigPath)); |
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.
👍
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.
Should this go to a separate PR?
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.
Probably not needed. Fixing the transform issues and let's merge and take it from there.
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'm working on a fix PR and desperately need this! :)
9581031
to
77dc227
Compare
@pksjce I've started the transformations, but let's move it to another seperate branch after this gets merged. I'll open a wip for you to follow along. |
lib/creator/index.js
Outdated
const env = yeoman.createEnv(null, null, new WebpackAdapter()); | ||
|
||
if(options) { | ||
env.register(require.resolve(options), 'npm:app'); |
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'd probably rename npm:app
to avoid any potential collisions by other packages that may have registered a Yeoman environment. Maybe webpack:cli
?
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.
It's gonna be assigned to the generator name :) See previous comment.
lib/creator/index.js
Outdated
env.register(require.resolve(options), 'npm:app'); | ||
|
||
env.run('npm:app') | ||
.on('end', () => { |
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.
This is an arrow function, so you could either just one-line it and leave out the return, or since it's an event, you probably don't need the return at all.
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.
This is actually just the first integration, would need to change the generatorName
through env.getGeneratorMetaData()
later, could integrate it now though.
fbf8392
to
9a84b36
Compare
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.
LGTM in general. See a couple of comments
*/ | ||
|
||
function replaceGeneratorName(name) { | ||
return name.replace( |
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.
Mind adding tests for this one?
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.
Sure, giveme 1h :) At school
lib/creator/index.js
Outdated
env.register(require.resolve(options), generatorName); | ||
|
||
env.run(generatorName) | ||
.on('end', () => { |
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.
Can the duplication be removed from these 2 code branches?
Also indentation is odd but this can be fixed as #102 is merged,
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.
Yeah, I was thinking about it actually, will do that.
Cool. I will work on a separate PR for transformations. My previous PR was meant for feedback. I was really not sure what approach would work with yeoman. |
Also commented out unused modules for now.
3833e75
to
3dee6de
Compare
Codecov Report
@@ Coverage Diff @@
## master #99 +/- ##
=========================================
Coverage ? 94.49%
=========================================
Files ? 13
Lines ? 363
Branches ? 75
=========================================
Hits ? 343
Misses ? 20
Partials ? 0 Continue to review full report at Codecov.
|
lib/creator/index.test.js
Outdated
@@ -0,0 +1,15 @@ | |||
'use strict'; | |||
|
|||
function replaceGeneratorName(name) { |
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.
Should this be the real implementation? Export it and import here to remove code duplication, please.
|
||
it('should replace a pattern of an addon', () => { | ||
const generatorName = replaceGeneratorName('webpack-addons-thefox'); | ||
expect(generatorName).toEqual('generator-thefox'); |
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.
The regex looks more complex as just this test and covers more edge cases. Should we test against them?
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.
Just an initial commit, can add more tests later and label an issue with good first contribution
Did you add tests for your changes?
N/A
If relevant, did you update the documentation?
N/A
Summary
Lays the groundwork for a first release. Integrated Validation to
migrate, refactored creator for the init feature to not be circular and
made a cleaner structure to the project inside lib/creator.
Does this PR introduce a breaking change?
No
Other information