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

Add NoEmitOnErrorsPlugin transformation #399

Merged
merged 3 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const uglifyJsPluginTransform = require("./uglifyJsPlugin/uglifyJsPlugin");
const loaderOptionsPluginTransform = require("./loaderOptionsPlugin/loaderOptionsPlugin");
const bannerPluginTransform = require("./bannerPlugin/bannerPlugin");
const extractTextPluginTransform = require("./extractTextPlugin/extractTextPlugin");
const noEmitOnErrorsPluginTransform = require("./noEmitOnErrorsPlugin/noEmitOnErrorsPlugin");
const removeDeprecatedPluginsTransform = require("./removeDeprecatedPlugins/removeDeprecatedPlugins");

const transformsObject = {
Expand All @@ -19,6 +20,7 @@ const transformsObject = {
loaderOptionsPluginTransform,
bannerPluginTransform,
extractTextPluginTransform,
noEmitOnErrorsPluginTransform,
removeDeprecatedPluginsTransform
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-0" data 1`] = `
"module.export = {
optimizations: {
concatenateModules: true
}
}
"
`;

exports[`moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-1" data 1`] = `
"module.export = {
optimizations: {
splitChunks: false,
concatenateModules: true
},
plugins: [new Foo()]
}
"
`;

exports[`moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-2" data 1`] = `
"module.export = {
optimizations: {
concatenateModules: true
},
plugins: [new Foo()]
}
"
`;
Copy link
Member

Choose a reason for hiding this comment

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

Great!

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.export = {
plugins: [
new webpack.optimize.ModuleConcatenationPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.export = {
optimizations: {
splitChunks: false
},
plugins: [
new Foo(),
new webpack.optimize.ModuleConcatenationPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.export = {
optimizations: {
concatenateModules: false
},
plugins: [
new Foo(),
new webpack.optimize.ModuleConcatenationPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const {
addOrUpdateConfigObject,
findAndRemovePluginByName
} = require("../../utils/ast-utils");

/**
*
* Transform for NamedModulesPlugin. If found, removes the
* plugin and sets optimizations.namedModules 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) {
// Remove old plugin
const root = findAndRemovePluginByName(
j,
ast,
"webpack.optimize.ModuleConcatenationPlugin"
);

// Add new optimizations option
root &&
addOrUpdateConfigObject(
j,
root,
"optimizations",
"concatenateModules",
j.booleanLiteral(true)
);

return ast;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";

const defineTest = require("../../utils/defineTest");

defineTest(
__dirname,
"moduleConcatenationPlugin",
"moduleConcatenationPlugin-0"
);
defineTest(
__dirname,
"moduleConcatenationPlugin",
"moduleConcatenationPlugin-1"
);
defineTest(
__dirname,
"moduleConcatenationPlugin",
"moduleConcatenationPlugin-2"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`namedModulesPlugin transforms correctly using "namedModulesPlugin-0" data 1`] = `
"module.export = {
optimizations: {
namedModules: true
}
}
"
`;

exports[`namedModulesPlugin transforms correctly using "namedModulesPlugin-1" data 1`] = `
"module.export = {
optimizations: {
splitChunks: false,
namedModules: true
},
plugins: [new Foo()]
}
"
`;

exports[`namedModulesPlugin transforms correctly using "namedModulesPlugin-2" data 1`] = `
"module.export = {
optimizations: {
namedModules: true
},
plugins: [new Foo()]
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.export = {
plugins: [
new webpack.NamedModulesPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.export = {
optimizations: {
splitChunks: false
},
plugins: [
new Foo(),
new webpack.NamedModulesPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.export = {
optimizations: {
namedModules: false
},
plugins: [
new Foo(),
new webpack.NamedModulesPlugin()
]
}
30 changes: 30 additions & 0 deletions lib/migrate/namedModulesPlugin/namedModulesPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const {
addOrUpdateConfigObject,
findAndRemovePluginByName
} = require("../../utils/ast-utils");

/**
*
* Transform for NamedModulesPlugin. If found, removes the
* plugin and sets optimizations.namedModules 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) {
// Remove old plugin
const root = findAndRemovePluginByName(j, ast, "webpack.NamedModulesPlugin");

// Add new optimizations option
root &&
addOrUpdateConfigObject(
j,
root,
"optimizations",
"namedModules",
j.booleanLiteral(true)
);

return ast;
};
7 changes: 7 additions & 0 deletions lib/migrate/namedModulesPlugin/namedModulesPlugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

const defineTest = require("../../utils/defineTest");

defineTest(__dirname, "namedModulesPlugin", "namedModulesPlugin-0");
defineTest(__dirname, "namedModulesPlugin", "namedModulesPlugin-1");
defineTest(__dirname, "namedModulesPlugin", "namedModulesPlugin-2");
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()]
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.export = {
plugins: [
new webpack.NoEmitOnErrorsPlugin()
]
}
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()
]
}
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()
]
}
34 changes: 34 additions & 0 deletions lib/migrate/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const {
addOrUpdateConfigObject,
findAndRemovePluginByName
} = 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) {
// Remove old plugin
const root = findAndRemovePluginByName(
j,
ast,
"webpack.NoEmitOnErrorsPlugin"
);

// Add new optimizations option
root &&
addOrUpdateConfigObject(
j,
root,
"optimizations",
"noEmitOnErrors",
j.booleanLiteral(true)
);

return ast;
};
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");
Loading