-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
Add NoEmitOnErrorsPlugin transformation #399
Merged
evenstensberg
merged 3 commits into
webpack:master
from
bitpshr:feature/v3-v4-noEmitOnErrorsPlugin
Apr 15, 2018
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/migrate/noEmitOnErrorsPlugin/__snapshots__/noEmitOnErrorsPlugin.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-0" data 1`] = ` | ||
"module.export = { | ||
optimizations: { | ||
noEmitOnErrors: true | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-1" data 1`] = ` | ||
"module.export = { | ||
optimizations: { | ||
splitChunks: false, | ||
noEmitOnErrors: true | ||
}, | ||
plugins: [new Foo()] | ||
} | ||
" | ||
`; | ||
|
||
exports[`noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-2" data 1`] = ` | ||
"module.export = { | ||
optimizations: { | ||
noEmitOnErrors: true | ||
}, | ||
plugins: [new Foo()] | ||
} | ||
" | ||
`; |
3 changes: 3 additions & 0 deletions
3
lib/migrate/noEmitOnErrorsPlugin/__testfixtures__/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*] | ||
indent_style = space | ||
indent_size = 4 |
5 changes: 5 additions & 0 deletions
5
lib/migrate/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-0.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.export = { | ||
plugins: [ | ||
new webpack.NoEmitOnErrorsPlugin() | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/migrate/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-1.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.export = { | ||
optimizations: { | ||
splitChunks: false | ||
}, | ||
plugins: [ | ||
new Foo(), | ||
new webpack.NoEmitOnErrorsPlugin() | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/migrate/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-2.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.export = { | ||
optimizations: { | ||
noEmitOnErrors: false | ||
}, | ||
plugins: [ | ||
new Foo(), | ||
new webpack.NoEmitOnErrorsPlugin() | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { | ||
findPluginsByName, | ||
safeTraverse | ||
} = require("../../utils/ast-utils"); | ||
|
||
/** | ||
* | ||
* Transform for NoEmitOnErrorsPlugin. If found, removes the | ||
* plugin and sets optimizations.noEmitOnErrors to true | ||
* | ||
* @param {Object} j - jscodeshift top-level import | ||
* @param {Node} ast - jscodeshift ast to transform | ||
* @returns {Node} ast - jscodeshift ast | ||
*/ | ||
module.exports = function(j, ast) { | ||
let rootPath; | ||
|
||
// Remove old plugin | ||
findPluginsByName(j, ast, ["webpack.NoEmitOnErrorsPlugin"]) | ||
.filter(path => safeTraverse(path, ["parent", "value"])) | ||
.forEach(path => { | ||
rootPath = safeTraverse(path, ["parent", "parent", "parent", "value"]); | ||
const arrayPath = path.parent.value; | ||
if (arrayPath.elements && arrayPath.elements.length === 1) { | ||
j(path.parent.parent).remove(); | ||
} else { | ||
j(path).remove(); | ||
} | ||
}); | ||
|
||
// Set new optimizations option | ||
if (rootPath) { | ||
const optimizationsExist = ast.find(j.Property).filter(path => path.node.key.name === "optimizations").size() > 0; | ||
|
||
if (optimizationsExist) { | ||
rootPath.properties.filter(path => path.key.name === "optimizations") | ||
.forEach(path => { | ||
const newProperties = path.value.properties.filter(path => path.key.name !== "noEmitOnErrors"); | ||
newProperties.push(j.objectProperty(j.identifier("noEmitOnErrors"), j.booleanLiteral(true))); | ||
path.value.properties = newProperties; | ||
}); | ||
} else { | ||
rootPath.properties.push( | ||
j.objectProperty( | ||
j.identifier("optimizations"), | ||
j.objectExpression([ | ||
j.objectProperty(j.identifier("noEmitOnErrors"), j.booleanLiteral(true)) | ||
]) | ||
) | ||
); | ||
} | ||
} | ||
|
||
return ast; | ||
}; |
7 changes: 7 additions & 0 deletions
7
lib/migrate/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
const defineTest = require("../../utils/defineTest"); | ||
|
||
defineTest(__dirname, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-0"); | ||
defineTest(__dirname, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-1"); | ||
defineTest(__dirname, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-2"); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 noticed that this function is basically used also in the other PRs. I think it's worth creating on single function that does this. Regarding the
rootPath
, we could change the logic:Ideally you could create on single PR to tackle all the transformers in one go so they can use the same utility all together. Or we could change one PR, merge it to master and you will rebase the others accordingly. What do you think? What's best for you
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'll combine them all into this PR if that works for you. Seems like the easiest approach. On it now, thanks for the review.