-
-
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
Feature [--migrate]: Migrate from webpack 1 to 2 through webpack-cli #6
Comments
Maybe we could create a schema diff map. (At least for future builds) v3, 4, etc. Then we could literally map values and pieces to v3 schema etc. Obvs a down the road feature but still relevant. |
Yes, I'm really not sure what webpack1 schema was and so I'm pretty sure I will miss many cases while doing this. |
I think we should add explicitly the task that we should validate the current webpack 1 config, and the generated webpack 2 config. This way we would avoid problems during the migration and ensure that the result is working fine |
Plan of actionwebpack --migrate <transformation(optional)> This would then work as follows. switch (arg1) {
// other cases
case 'migrate':
cliEngine.migrate(..restOfArgs);
break;
} Migration logic
const migrate = chosenTransforms => {
const currentConfig = readCurrentWebpackConfig();
var expectedConfig = makeCopyOf(currentConfig);
/* jscodeshift api is usually represented by variable j
will find and apply transformations */
const j = api.jscodeshift;
const transforms = getRelevantTransforms(chosenTransforms);
/* mutates the copied webpack config */
const ast = j(expectedConfig);
const output = applyTransforms(transforms, ast);
const isUserFineWithChanges = validateAndshowTheCodeDiffs()
if (isUserFineWithChanges) {
displayPrettyOutput(output, ast.toSource())
} else {
abortOrRetryProcedure()
}
}
const getRelevantTransforms = chosenTransforms => {
const allTransformFns = getAllTransforms();
/* May need some logic */
const filteredTransformFns = allTransformFns.filter(chosenTransforms);
return filteredTransformFns;
}
const applyTransforms = (transformFns, ast) {
let output = [];
/* ast is being mutated as global variable
But each transformation can send out its own output of errors/success/code-diff/logs etc */
transformFns.forEach(fn => output.push(fn(ast)));
return output;
} TransformationsEach transformation is an independent mutation of code. It should tackle a bare minimum of mutation and must work under all possible circumstances. The out of the box testing of jscodeshift should help with this. ---transformations
export default ast => {
return ast.findStuff()
.forEach(doStuff);
} Transform Utils[TODO]
@DanielaValero - This is basically what I plan to implement under this issue. I will first write the raw transformers so that I get passing tests for all possible input config scenarios. After that we can create common utils and refactor with the assurance of the test beds. |
Hello @pksjce thanks a lot for the detailed explanation! Now is clearer what you intend to do. I will dig soon deeper into this, so I can be more useful with the code reviews and picking up any task. At a point, would be good when we migrated some of the documentation you added in your comment into some relevant place in the code, so the explanations don't get lost, and others can consume them after this issue is closed and lost of our radar |
Yes, I will try to adequately transfer this knowledge to the code. You also be on the lookout during reviews. |
|
I've started some work in #40 Let's coordinate the effort. I'm just going the list of open items for now. |
Closing this issue. |
I don't think it should be closed. It is still only works with the hard coded example. |
Alright nice work everyone, I'm going to take this for a ride. I'll report back! |
Closing. See #40 |
TODOS
Migrations
enforce: 'pre/post'
-loaders
suffix.json-loader
sourceMap: true
toUglifyJsPlugin
ExtractTextPlugin
syntaxOccurendeOrderPlugin
LoaderOptionsPlugin
withminimize:true
,context
anddebug
NFR
Do you want to request a feature or report a bug?
This is a feature request
What is the current behavior?
There is no automated tool to help migrate from webpack 1 to webpack 2.
If the current behavior is a bug, please provide the steps to reproduce.
NA
What is the expected behavior?
The expected behavior is to have webpack-cli help make this migration automatically.
If this is a feature request, what is motivation or use case for changing the behavior?
It is not clear from first glance as to what it takes to migrate breaking features for webpack2. Providing an automated option would be the best case scenario
Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language.
Node.js version > 0.12.17
The text was updated successfully, but these errors were encountered: