From 73fdf7d880cc2cef400769a7b6600a33deb9b902 Mon Sep 17 00:00:00 2001 From: Dylan Nelson Date: Thu, 8 Feb 2018 16:02:28 -0500 Subject: [PATCH] Add jsdoc comments for migrate (#255) * docs: jsdoc comments for migrate/loaders * docs: jsdoc comments for migrate transforms * docs: fix typos & omissions * docs: run jsdoc command * remove jsdoc exclude in config and rerun jsdocs * docs(migrate): incorporate pr feedback * docs: run jsdoc commmand * docs(migrate): incorporate pr feedback * docs(migrate): replace em dashes with hyphens * docs: run jsdoc command * docs(migrate): add descriptions to @returns tags * docs(migrate): run jsdoc command --- docs/AddGenerator.html | 4 +- docs/InitGenerator.html | 4 +- docs/LoaderGenerator.html | 8 +- docs/PluginGenerator.html | 8 +- docs/commands_add.js.html | 4 +- docs/commands_init.js.html | 4 +- docs/commands_make.js.html | 4 +- docs/commands_migrate.js.html | 4 +- docs/commands_remove.js.html | 4 +- docs/commands_serve.js.html | 4 +- docs/commands_update.js.html | 4 +- docs/generate-loader_index.js.html | 4 +- docs/generate-plugin_index.js.html | 4 +- docs/generators_add-generator.js.html | 4 +- docs/generators_init-generator.js.html | 4 +- docs/generators_loader-generator.js.html | 4 +- docs/generators_plugin-generator.js.html | 4 +- docs/generators_utils_entry.js.html | 4 +- docs/generators_utils_module.js.html | 4 +- docs/generators_utils_plugins.js.html | 4 +- docs/generators_utils_tooltip.js.html | 4 +- docs/generators_utils_validate.js.html | 4 +- docs/generators_webpack-generator.js.html | 4 +- docs/global.html | 549 +++++++++++++++++- docs/index.html | 4 +- docs/index.js.html | 4 +- docs/init_index.js.html | 4 +- ...it_transformations_context_context.js.html | 4 +- ...ransformations_devServer_devServer.js.html | 4 +- ...it_transformations_devtool_devtool.js.html | 4 +- docs/init_transformations_entry_entry.js.html | 4 +- ...ransformations_externals_externals.js.html | 4 +- docs/init_transformations_index.js.html | 4 +- docs/init_transformations_mode_mode.js.html | 4 +- ...init_transformations_module_module.js.html | 4 +- docs/init_transformations_node_node.js.html | 4 +- docs/init_transformations_other_amd.js.html | 4 +- docs/init_transformations_other_bail.js.html | 4 +- docs/init_transformations_other_cache.js.html | 4 +- docs/init_transformations_other_merge.js.html | 4 +- ..._transformations_other_parallelism.js.html | 4 +- ...init_transformations_other_profile.js.html | 4 +- ...sformations_other_recordsInputPath.js.html | 4 +- ...formations_other_recordsOutputPath.js.html | 4 +- ..._transformations_other_recordsPath.js.html | 4 +- ...init_transformations_output_output.js.html | 4 +- ...formations_performance_performance.js.html | 4 +- ...it_transformations_plugins_plugins.js.html | 4 +- ...ations_resolveLoader_resolveLoader.js.html | 4 +- ...it_transformations_resolve_resolve.js.html | 4 +- docs/init_transformations_stats_stats.js.html | 4 +- ...init_transformations_target_target.js.html | 4 +- ...ransformations_top-scope_top-scope.js.html | 4 +- docs/init_transformations_watch_watch.js.html | 4 +- ...transformations_watch_watchOptions.js.html | 4 +- .../migrate_bannerPlugin_bannerPlugin.js.html | 84 +++ ...xtractTextPlugin_extractTextPlugin.js.html | 109 ++++ docs/migrate_index.js.html | 130 +++++ ...rOptionsPlugin_loaderOptionsPlugin.js.html | 98 ++++ docs/migrate_loaders_loaders.js.html | 384 ++++++++++++ docs/migrate_outputPath_outputPath.js.html | 125 ++++ ...tedPlugins_removeDeprecatedPlugins.js.html | 95 +++ ..._removeJsonLoader_removeJsonLoader.js.html | 120 ++++ docs/migrate_resolve_resolve.js.html | 123 ++++ ...rate_uglifyJsPlugin_uglifyJsPlugin.js.html | 84 +++ docs/utils_ast-utils.js.html | 4 +- docs/utils_copy-utils.js.html | 4 +- docs/utils_defineTest.js.html | 4 +- docs/utils_hashtable.js.html | 4 +- docs/utils_modify-config-helper.js.html | 4 +- docs/utils_npm-exists.js.html | 4 +- docs/utils_npm-packages-exists.js.html | 4 +- docs/utils_package-manager.js.html | 4 +- docs/utils_prop-types.js.html | 4 +- docs/utils_resolve-packages.js.html | 4 +- docs/utils_run-prettier.js.html | 4 +- jsdoc.json | 3 +- lib/migrate/bannerPlugin/bannerPlugin.js | 10 + .../extractTextPlugin/extractTextPlugin.js | 19 + lib/migrate/index.js | 20 +- .../loaderOptionsPlugin.js | 10 + lib/migrate/loaders/loaders.js | 80 ++- lib/migrate/outputPath/outputPath.js | 9 + .../removeDeprecatedPlugins.js | 12 +- .../removeJsonLoader/removeJsonLoader.js | 18 + lib/migrate/resolve/resolve.js | 18 + lib/migrate/uglifyJsPlugin/uglifyJsPlugin.js | 9 + yarn.lock | 8 +- 88 files changed, 2178 insertions(+), 207 deletions(-) create mode 100644 docs/migrate_bannerPlugin_bannerPlugin.js.html create mode 100644 docs/migrate_extractTextPlugin_extractTextPlugin.js.html create mode 100644 docs/migrate_index.js.html create mode 100644 docs/migrate_loaderOptionsPlugin_loaderOptionsPlugin.js.html create mode 100644 docs/migrate_loaders_loaders.js.html create mode 100644 docs/migrate_outputPath_outputPath.js.html create mode 100644 docs/migrate_removeDeprecatedPlugins_removeDeprecatedPlugins.js.html create mode 100644 docs/migrate_removeJsonLoader_removeJsonLoader.js.html create mode 100644 docs/migrate_resolve_resolve.js.html create mode 100644 docs/migrate_uglifyJsPlugin_uglifyJsPlugin.js.html diff --git a/docs/AddGenerator.html b/docs/AddGenerator.html index a75aae8ea4d..2aff13a178b 100644 --- a/docs/AddGenerator.html +++ b/docs/AddGenerator.html @@ -186,13 +186,13 @@

Extends


diff --git a/docs/InitGenerator.html b/docs/InitGenerator.html index 4c920994768..9e63b598481 100644 --- a/docs/InitGenerator.html +++ b/docs/InitGenerator.html @@ -186,13 +186,13 @@

Extends


diff --git a/docs/LoaderGenerator.html b/docs/LoaderGenerator.html index a64d9f37749..df947b85ecf 100644 --- a/docs/LoaderGenerator.html +++ b/docs/LoaderGenerator.html @@ -49,7 +49,9 @@

new Lo
- A yeoman generator class for creating a webpack loader project. It adds some starter loader code and runs `webpack-defaults`. + A yeoman generator class for creating a webpack +loader project. It adds some starter loader code +and runs `webpack-defaults`.
@@ -164,13 +166,13 @@

Extends


diff --git a/docs/PluginGenerator.html b/docs/PluginGenerator.html index 85366f5815d..e130ed22b61 100644 --- a/docs/PluginGenerator.html +++ b/docs/PluginGenerator.html @@ -49,7 +49,9 @@

new Pl
- A yeoman generator class for creating a webpack plugin project. It adds some starter plugin code and runs `webpack-defaults`. + A yeoman generator class for creating a webpack +plugin project. It adds some starter plugin code +and runs `webpack-defaults`.
@@ -164,13 +166,13 @@

Extends


diff --git a/docs/commands_add.js.html b/docs/commands_add.js.html index 190339d0726..a86700c96db 100644 --- a/docs/commands_add.js.html +++ b/docs/commands_add.js.html @@ -52,13 +52,13 @@

Source: commands/add.js


diff --git a/docs/commands_init.js.html b/docs/commands_init.js.html index 76a660518ac..0d83217b91e 100644 --- a/docs/commands_init.js.html +++ b/docs/commands_init.js.html @@ -57,13 +57,13 @@

Source: commands/init.js


diff --git a/docs/commands_make.js.html b/docs/commands_make.js.html index fe85714b57f..f994274fffe 100644 --- a/docs/commands_make.js.html +++ b/docs/commands_make.js.html @@ -48,13 +48,13 @@

Source: commands/make.js


diff --git a/docs/commands_migrate.js.html b/docs/commands_migrate.js.html index df1c330a0c8..273451c995f 100644 --- a/docs/commands_migrate.js.html +++ b/docs/commands_migrate.js.html @@ -189,13 +189,13 @@

Source: commands/migrate.js


diff --git a/docs/commands_remove.js.html b/docs/commands_remove.js.html index 5caf35a8584..4e427b908eb 100644 --- a/docs/commands_remove.js.html +++ b/docs/commands_remove.js.html @@ -52,13 +52,13 @@

Source: commands/remove.js


diff --git a/docs/commands_serve.js.html b/docs/commands_serve.js.html index 6607f57cb2e..5a1b54b3e4b 100644 --- a/docs/commands_serve.js.html +++ b/docs/commands_serve.js.html @@ -207,13 +207,13 @@

Source: commands/serve.js


diff --git a/docs/commands_update.js.html b/docs/commands_update.js.html index 5cb477fc3fa..265f095514f 100644 --- a/docs/commands_update.js.html +++ b/docs/commands_update.js.html @@ -52,13 +52,13 @@

Source: commands/update.js


diff --git a/docs/generate-loader_index.js.html b/docs/generate-loader_index.js.html index a85847f1fa7..6d032bf1fbb 100644 --- a/docs/generate-loader_index.js.html +++ b/docs/generate-loader_index.js.html @@ -53,13 +53,13 @@

Source: generate-loader/index.js


diff --git a/docs/generate-plugin_index.js.html b/docs/generate-plugin_index.js.html index fc9eb9f8707..a8405b35906 100644 --- a/docs/generate-plugin_index.js.html +++ b/docs/generate-plugin_index.js.html @@ -53,13 +53,13 @@

Source: generate-plugin/index.js


diff --git a/docs/generators_add-generator.js.html b/docs/generators_add-generator.js.html index 5049d8ece1c..42d2383a9e2 100644 --- a/docs/generators_add-generator.js.html +++ b/docs/generators_add-generator.js.html @@ -486,13 +486,13 @@

Source: generators/add-generator.js


diff --git a/docs/generators_init-generator.js.html b/docs/generators_init-generator.js.html index dc0b18d70b1..aba50d7dd18 100644 --- a/docs/generators_init-generator.js.html +++ b/docs/generators_init-generator.js.html @@ -449,13 +449,13 @@

Source: generators/init-generator.js


diff --git a/docs/generators_loader-generator.js.html b/docs/generators_loader-generator.js.html index 77ba15f6426..95781607980 100644 --- a/docs/generators_loader-generator.js.html +++ b/docs/generators_loader-generator.js.html @@ -94,13 +94,13 @@

Source: generators/loader-generator.js


diff --git a/docs/generators_plugin-generator.js.html b/docs/generators_plugin-generator.js.html index a27ee01b0ab..ee859aedc57 100644 --- a/docs/generators_plugin-generator.js.html +++ b/docs/generators_plugin-generator.js.html @@ -75,13 +75,13 @@

Source: generators/plugin-generator.js


diff --git a/docs/generators_utils_entry.js.html b/docs/generators_utils_entry.js.html index 380572aec48..2ff9f74301c 100644 --- a/docs/generators_utils_entry.js.html +++ b/docs/generators_utils_entry.js.html @@ -126,13 +126,13 @@

Source: generators/utils/entry.js


diff --git a/docs/generators_utils_module.js.html b/docs/generators_utils_module.js.html index 52cde97781b..64eddf5e5a7 100644 --- a/docs/generators_utils_module.js.html +++ b/docs/generators_utils_module.js.html @@ -55,13 +55,13 @@

Source: generators/utils/module.js


diff --git a/docs/generators_utils_plugins.js.html b/docs/generators_utils_plugins.js.html index 9e854492366..98d17312204 100644 --- a/docs/generators_utils_plugins.js.html +++ b/docs/generators_utils_plugins.js.html @@ -50,13 +50,13 @@

Source: generators/utils/plugins.js


diff --git a/docs/generators_utils_tooltip.js.html b/docs/generators_utils_tooltip.js.html index 164632a3bb3..8d4a0a70f68 100644 --- a/docs/generators_utils_tooltip.js.html +++ b/docs/generators_utils_tooltip.js.html @@ -92,13 +92,13 @@

Source: generators/utils/tooltip.js


diff --git a/docs/generators_utils_validate.js.html b/docs/generators_utils_validate.js.html index e52edaf1688..16691643467 100644 --- a/docs/generators_utils_validate.js.html +++ b/docs/generators_utils_validate.js.html @@ -53,13 +53,13 @@

Source: generators/utils/validate.js


diff --git a/docs/generators_webpack-generator.js.html b/docs/generators_webpack-generator.js.html index 8017a0a5211..86b0d629ca0 100644 --- a/docs/generators_webpack-generator.js.html +++ b/docs/generators_webpack-generator.js.html @@ -113,13 +113,13 @@

Source: generators/webpack-generator.js


diff --git a/docs/global.html b/docs/global.html index 4a513579b12..0e56ef060cf 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1152,7 +1152,8 @@
Returns:
- - Returns the node for the created function + - Returns the node for the created +function
@@ -1756,7 +1757,8 @@

- Findes or creates a node for a given plugin name string with options object If plugin decalaration already exist, options are merged. + Findes or creates a node for a given plugin name string with options object +If plugin decalaration already exist, options are merged. @@ -2186,7 +2188,8 @@

creator - Runs yeoman and runs the transformations based on the object built up from an author/user + Runs yeoman and runs the transformations based on the object +built up from an author/user @@ -2306,7 +2309,8 @@
Returns:
- runTransform - Run transformations based on the finished yeoman instance + runTransform - Run transformations based on the finished +yeoman instance
@@ -2343,7 +2347,8 @@

defineTest<
- Handles some boilerplate around defining a simple jest/Jasmine test for a jscodeshift transform. + Handles some boilerplate around defining a simple jest/Jasmine test for a +jscodeshift transform.
@@ -2405,7 +2410,8 @@

Parameters:
- contains the name of the directory the test is located in. This should normally be passed via __dirname. + contains the name of the directory the test is located in. This + should normally be passed via __dirname. @@ -2436,7 +2442,8 @@
Parameters:
- contains the filename of the transform being tested, excluding the .js extension. + contains the filename of the transform being tested, + excluding the .js extension. @@ -2469,7 +2476,12 @@
Parameters:
- Optionally contains the name of the file with the test data. If not specified, it defaults to the same value as `transformName`. This will be suffixed with ".input.js" for the input file and ".output.js" for the expected output. For example, if set to "foo", we will read the "foo.input.js" file, pass this to the transform, and expect its output to be equal to the contents of "foo.output.js". + Optionally contains the name of the file with the test + data. If not specified, it defaults to the same value as `transformName`. + This will be suffixed with ".input.js" for the input file and ".output.js" + for the expected output. For example, if set to "foo", we will read the + "foo.input.js" file, pass this to the transform, and expect its output to + be equal to the contents of "foo.output.js". @@ -2628,6 +2640,209 @@
Returns:
+

findInvocation(j, node, pluginName) → {Boolean}

+ + + + + + +
+ Check whether `node` is the invocation of the plugin denoted by `pluginName` +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +Object + + + + jscodeshift top-level import
node + + +Node + + + + ast node to check
pluginName + + +String + + + + name of the plugin
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ isPluginInvocation - whether `node` is the invocation of the plugin denoted by `pluginName` +
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + + + +

findPluginsByName(j, node, pluginNamesArray) → {Node}

@@ -2636,7 +2851,8 @@

find
- Find paths that match `new name.space.PluginName()` for a given array of plugin names + Find paths that match `new name.space.PluginName()` for a +given array of plugin names
@@ -3245,7 +3461,8 @@

generato
- Takes in a file path in the `./templates` directory. Copies that file to the destination, with the `.tpl` extension stripped. + Takes in a file path in the `./templates` directory. Copies that +file to the destination, with the `.tpl` extension stripped.
@@ -3425,7 +3642,9 @@

gener
- Takes in a file path in the `./templates` directory. Copies that file to the destination, with the `.tpl` extension and `_` prefix stripped. Passes `this.props` to the template. + Takes in a file path in the `./templates` directory. Copies that +file to the destination, with the `.tpl` extension and `_` prefix +stripped. Passes `this.props` to the template.
@@ -3523,7 +3742,8 @@

Parameters:
- An object containing the data passed to the template files. + An object containing the data passed to +the template files. @@ -3628,7 +3848,8 @@

getP
- Returns the name of package manager to use, preferring yarn over npm if available + Returns the name of package manager to use, +preferring yarn over npm if available
@@ -4096,7 +4317,9 @@

isAssignm
- Checks if we are at the correct node and later invokes a callback for the transforms to either use their own transform function or use pushCreateProperty if the transform doesn't expect any properties + Checks if we are at the correct node and later invokes a callback +for the transforms to either use their own transform function or +use pushCreateProperty if the transform doesn't expect any properties
@@ -4240,7 +4463,8 @@

Parameters:
- WebpackOptions that later will be converted via pushCreateProperty via WebpackOptions[identifier] + WebpackOptions that later will be converted via +pushCreateProperty via WebpackOptions[identifier] @@ -4791,7 +5015,8 @@
Returns:
- - Either pushes the node, or reruns until nothing is left + - Either pushes the node, or reruns until +nothing is left
@@ -4831,7 +5056,8 @@

makeLoa
- Formats a string into webpack loader format (eg: 'style-loader', 'raw-loader') + Formats a string into webpack loader format +(eg: 'style-loader', 'raw-loader')
@@ -5660,7 +5886,8 @@

Returns:
- Returns a function that will push a node if subProperty is an array, else it will invoke a function that will push a single node + Returns a function that will push a node if +subProperty is an array, else it will invoke a function that will push a single node
@@ -5700,7 +5927,8 @@

replaceAt - Replaces the string with a substring at the given index https://gist.github.com/efenacigiray/9367920 + Replaces the string with a substring at the given index +https://gist.github.com/efenacigiray/9367920 @@ -6023,7 +6251,8 @@
Returns:
- creator - Builds a webpack configuration through yeoman or throws an error + creator - Builds +a webpack configuration through yeoman or throws an error
@@ -6063,7 +6292,15 @@

runS
- Utility function to run a jscodeshift script within a unit test. This makes several assumptions about the environment. Notes: - The test should be located in a subdirectory next to the transform itself. Commonly tests are located in a directory called __tests__. - Test data should be located in a directory called __testfixtures__ alongside the transform and __tests__ directory. + Utility function to run a jscodeshift script within a unit test. +This makes several assumptions about the environment. + +Notes: +- The test should be located in a subdirectory next to the transform itself. + Commonly tests are located in a directory called __tests__. + +- Test data should be located in a directory called __testfixtures__ + alongside the transform and __tests__ directory.
@@ -6125,7 +6362,8 @@

Parameters:
- contains the name of the directory the test is located in. This should normally be passed via __dirname. + contains the name of the directory the test is located in. This + should normally be passed via __dirname. @@ -6156,7 +6394,8 @@
Parameters:
- contains the filename of the transform being tested, excluding the .js extension. + contains the filename of the transform being tested, + excluding the .js extension. @@ -6189,7 +6428,12 @@
Parameters:
- Optionally contains the name of the file with the test data. If not specified, it defaults to the same value as `transformName`. This will be suffixed with ".input.js" for the input file and ".output.js" for the expected output. For example, if set to "foo", we will read the "foo.input.js" file, pass this to the transform, and expect its output to be equal to the contents of "foo.output.js". + Optionally contains the name of the file with the test + data. If not specified, it defaults to the same value as `transformName`. + This will be suffixed with ".input.js" for the input file and ".output.js" + for the expected output. For example, if set to "foo", we will read the + "foo.input.js" file, pass this to the transform, and expect its output to + be equal to the contents of "foo.output.js". @@ -7334,6 +7578,242 @@
Returns:
+

transform(source, transformsopt, optionsopt) → {String}

+ + + + + + +
+ Transforms a given piece of source code by applying selected transformations to the AST. +By default, transforms a webpack version 1 configuration file into a webpack version 2 +configuration file. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
source + + +String + + + + + + + + + + source file contents
transforms + + +Array.<function()> + + + + + + <optional>
+ + + + + +
List of transformation functions, defined in the +order to apply them in. By default, all defined transfomations.
options + + +Object + + + + + + <optional>
+ + + + + +
recast formatting options
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ source — transformed source code +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + +

traverseAndGetProperties(arr, prop) → {Boolean}

@@ -7485,7 +7965,8 @@
Returns:
- hasProp - Boolean indicating if the property is present + hasProp - Boolean indicating if the property +is present
@@ -7522,7 +8003,8 @@

webpa
- Creates a Yeoman Generator that generates a project conforming to webpack-defaults. + Creates a Yeoman Generator that generates a project conforming +to webpack-defaults.
@@ -7620,7 +8102,9 @@

Parameters:
- An array of file paths (relative to `./templates`) of files to be copied to the generated project. File paths should be of the form `path/to/file.js.tpl`. + An array of file paths (relative to `./templates`) +of files to be copied to the generated project. File paths should be of the +form `path/to/file.js.tpl`. @@ -7643,7 +8127,9 @@
Parameters:
- An array of file paths (relative to `./templates`) of files to be copied to the generated project. Template file paths should be of the form `path/to/_file.js.tpl`. + An array of file paths (relative to +`./templates`) of files to be copied to the generated project. Template +file paths should be of the form `path/to/_file.js.tpl`. @@ -7666,7 +8152,8 @@
Parameters:
- A function that is passed a generator instance and returns an object containing data to be supplied to the template files. + A function that is passed a generator instance and +returns an object containing data to be supplied to the template files. @@ -7773,13 +8260,13 @@
Returns:

- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/index.html b/docs/index.html index 332309d5b6d..a0147732e29 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,13 +50,13 @@


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/index.js.html b/docs/index.js.html index 09d29ff7c6c..ee5a94e8a88 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -96,13 +96,13 @@

Source: index.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_index.js.html b/docs/init_index.js.html index 7c7f9029668..5cf4748706c 100644 --- a/docs/init_index.js.html +++ b/docs/init_index.js.html @@ -101,13 +101,13 @@

Source: init/index.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_context_context.js.html b/docs/init_transformations_context_context.js.html index 9ecfbfd212d..3170416b72d 100644 --- a/docs/init_transformations_context_context.js.html +++ b/docs/init_transformations_context_context.js.html @@ -91,13 +91,13 @@

Source: init/transformations/context/context.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_devServer_devServer.js.html b/docs/init_transformations_devServer_devServer.js.html index 162c7311ca1..296e9ebd792 100644 --- a/docs/init_transformations_devServer_devServer.js.html +++ b/docs/init_transformations_devServer_devServer.js.html @@ -125,13 +125,13 @@

Source: init/transformations/devServer/devServer.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_devtool_devtool.js.html b/docs/init_transformations_devtool_devtool.js.html index 32b055687bc..bf7ab31b162 100644 --- a/docs/init_transformations_devtool_devtool.js.html +++ b/docs/init_transformations_devtool_devtool.js.html @@ -90,13 +90,13 @@

Source: init/transformations/devtool/devtool.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_entry_entry.js.html b/docs/init_transformations_entry_entry.js.html index 59e8824a4bb..cd1cff9a062 100644 --- a/docs/init_transformations_entry_entry.js.html +++ b/docs/init_transformations_entry_entry.js.html @@ -121,13 +121,13 @@

Source: init/transformations/entry/entry.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_externals_externals.js.html b/docs/init_transformations_externals_externals.js.html index 5b57744a59f..98bc5573b00 100644 --- a/docs/init_transformations_externals_externals.js.html +++ b/docs/init_transformations_externals_externals.js.html @@ -145,13 +145,13 @@

Source: init/transformations/externals/externals.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_index.js.html b/docs/init_transformations_index.js.html index e494e3c3935..d6b0a629797 100644 --- a/docs/init_transformations_index.js.html +++ b/docs/init_transformations_index.js.html @@ -186,13 +186,13 @@

Source: init/transformations/index.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_mode_mode.js.html b/docs/init_transformations_mode_mode.js.html index fc7f6a7da6e..4052c5ebd55 100644 --- a/docs/init_transformations_mode_mode.js.html +++ b/docs/init_transformations_mode_mode.js.html @@ -91,13 +91,13 @@

Source: init/transformations/mode/mode.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_module_module.js.html b/docs/init_transformations_module_module.js.html index 4b84117b041..befe655ba3e 100644 --- a/docs/init_transformations_module_module.js.html +++ b/docs/init_transformations_module_module.js.html @@ -109,13 +109,13 @@

Source: init/transformations/module/module.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_node_node.js.html b/docs/init_transformations_node_node.js.html index 5b6992ec1b0..835dd4f5c38 100644 --- a/docs/init_transformations_node_node.js.html +++ b/docs/init_transformations_node_node.js.html @@ -80,13 +80,13 @@

Source: init/transformations/node/node.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_amd.js.html b/docs/init_transformations_other_amd.js.html index 6a636d065e7..bc8caea2c7f 100644 --- a/docs/init_transformations_other_amd.js.html +++ b/docs/init_transformations_other_amd.js.html @@ -120,13 +120,13 @@

Source: init/transformations/other/amd.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_bail.js.html b/docs/init_transformations_other_bail.js.html index 3d4892993e5..908889f8eaa 100644 --- a/docs/init_transformations_other_bail.js.html +++ b/docs/init_transformations_other_bail.js.html @@ -91,13 +91,13 @@

Source: init/transformations/other/bail.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_cache.js.html b/docs/init_transformations_other_cache.js.html index 024d922fb97..9683aa298f7 100644 --- a/docs/init_transformations_other_cache.js.html +++ b/docs/init_transformations_other_cache.js.html @@ -124,13 +124,13 @@

Source: init/transformations/other/cache.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_merge.js.html b/docs/init_transformations_other_merge.js.html index 9c77c6ceea3..8885a364f77 100644 --- a/docs/init_transformations_other_merge.js.html +++ b/docs/init_transformations_other_merge.js.html @@ -83,13 +83,13 @@

Source: init/transformations/other/merge.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_parallelism.js.html b/docs/init_transformations_other_parallelism.js.html index fb09af56c22..04ea3ab54da 100644 --- a/docs/init_transformations_other_parallelism.js.html +++ b/docs/init_transformations_other_parallelism.js.html @@ -96,13 +96,13 @@

Source: init/transformations/other/parallelism.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_profile.js.html b/docs/init_transformations_other_profile.js.html index 54acd7c55d7..37d630f7b45 100644 --- a/docs/init_transformations_other_profile.js.html +++ b/docs/init_transformations_other_profile.js.html @@ -124,13 +124,13 @@

Source: init/transformations/other/profile.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_recordsInputPath.js.html b/docs/init_transformations_other_recordsInputPath.js.html index 745b0daad64..387738a1f27 100644 --- a/docs/init_transformations_other_recordsInputPath.js.html +++ b/docs/init_transformations_other_recordsInputPath.js.html @@ -136,13 +136,13 @@

Source: init/transformations/other/recordsInputPath.js
- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_recordsOutputPath.js.html b/docs/init_transformations_other_recordsOutputPath.js.html index b9dc3db94a8..ccffc4f9f19 100644 --- a/docs/init_transformations_other_recordsOutputPath.js.html +++ b/docs/init_transformations_other_recordsOutputPath.js.html @@ -136,13 +136,13 @@

Source: init/transformations/other/recordsOutputPath.js
- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_other_recordsPath.js.html b/docs/init_transformations_other_recordsPath.js.html index ab5a8f4026b..7d921ad2925 100644 --- a/docs/init_transformations_other_recordsPath.js.html +++ b/docs/init_transformations_other_recordsPath.js.html @@ -125,13 +125,13 @@

Source: init/transformations/other/recordsPath.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_output_output.js.html b/docs/init_transformations_output_output.js.html index e1d203372d2..e667d31b54d 100644 --- a/docs/init_transformations_output_output.js.html +++ b/docs/init_transformations_output_output.js.html @@ -120,13 +120,13 @@

Source: init/transformations/output/output.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_performance_performance.js.html b/docs/init_transformations_performance_performance.js.html index bfabe1a6d2c..a2351a7364f 100644 --- a/docs/init_transformations_performance_performance.js.html +++ b/docs/init_transformations_performance_performance.js.html @@ -128,13 +128,13 @@

Source: init/transformations/performance/performance.js
- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_plugins_plugins.js.html b/docs/init_transformations_plugins_plugins.js.html index 9925599e436..d5b3218995c 100644 --- a/docs/init_transformations_plugins_plugins.js.html +++ b/docs/init_transformations_plugins_plugins.js.html @@ -92,13 +92,13 @@

Source: init/transformations/plugins/plugins.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_resolveLoader_resolveLoader.js.html b/docs/init_transformations_resolveLoader_resolveLoader.js.html index 72ec0d44466..784e05252a3 100644 --- a/docs/init_transformations_resolveLoader_resolveLoader.js.html +++ b/docs/init_transformations_resolveLoader_resolveLoader.js.html @@ -121,13 +121,13 @@

Source: init/transformations/resolveLoader/resolveLoader.
- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_resolve_resolve.js.html b/docs/init_transformations_resolve_resolve.js.html index 9643da67153..668d90c9e0a 100644 --- a/docs/init_transformations_resolve_resolve.js.html +++ b/docs/init_transformations_resolve_resolve.js.html @@ -109,13 +109,13 @@

Source: init/transformations/resolve/resolve.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_stats_stats.js.html b/docs/init_transformations_stats_stats.js.html index 9fa2b1b12c4..156936307c9 100644 --- a/docs/init_transformations_stats_stats.js.html +++ b/docs/init_transformations_stats_stats.js.html @@ -120,13 +120,13 @@

Source: init/transformations/stats/stats.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_target_target.js.html b/docs/init_transformations_target_target.js.html index d7066ecb94d..e4840793f9b 100644 --- a/docs/init_transformations_target_target.js.html +++ b/docs/init_transformations_target_target.js.html @@ -91,13 +91,13 @@

Source: init/transformations/target/target.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_top-scope_top-scope.js.html b/docs/init_transformations_top-scope_top-scope.js.html index 60b2dd6b726..96787bc6692 100644 --- a/docs/init_transformations_top-scope_top-scope.js.html +++ b/docs/init_transformations_top-scope_top-scope.js.html @@ -65,13 +65,13 @@

Source: init/transformations/top-scope/top-scope.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_watch_watch.js.html b/docs/init_transformations_watch_watch.js.html index cc69352c39d..25ec14901d5 100644 --- a/docs/init_transformations_watch_watch.js.html +++ b/docs/init_transformations_watch_watch.js.html @@ -121,13 +121,13 @@

Source: init/transformations/watch/watch.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/init_transformations_watch_watchOptions.js.html b/docs/init_transformations_watch_watchOptions.js.html index 4ae6d659a73..9f684f06962 100644 --- a/docs/init_transformations_watch_watchOptions.js.html +++ b/docs/init_transformations_watch_watchOptions.js.html @@ -136,13 +136,13 @@

Source: init/transformations/watch/watchOptions.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/migrate_bannerPlugin_bannerPlugin.js.html b/docs/migrate_bannerPlugin_bannerPlugin.js.html new file mode 100644 index 00000000000..ab9d643892f --- /dev/null +++ b/docs/migrate_bannerPlugin_bannerPlugin.js.html @@ -0,0 +1,84 @@ + + + + + JSDoc: Source: migrate/bannerPlugin/bannerPlugin.js + + + + + + + + + + +
+ +

Source: migrate/bannerPlugin/bannerPlugin.js

+ + + + + + +
+
+
const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Transform for BannerPlugin arguments. Consolidates first and second argument (if
+ * both are present) into single options object.
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast) {
+	return utils
+		.findPluginsByName(j, ast, ["webpack.BannerPlugin"])
+		.forEach(path => {
+			const args = path.value.arguments; // any node
+			// If the first argument is a literal replace it with object notation
+			// See https://webpack.js.org/guides/migrating/#bannerplugin-breaking-change
+			if (args && args.length > 1 && args[0].type === j.Literal.name) {
+				// and remove the first argument
+				path.value.arguments = [path.value.arguments[1]];
+				utils.createOrUpdatePluginByName(
+					j,
+					path.parent,
+					"webpack.BannerPlugin",
+					{
+						banner: args[0].value
+					}
+				);
+			}
+		});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_extractTextPlugin_extractTextPlugin.js.html b/docs/migrate_extractTextPlugin_extractTextPlugin.js.html new file mode 100644 index 00000000000..c24afc22b88 --- /dev/null +++ b/docs/migrate_extractTextPlugin_extractTextPlugin.js.html @@ -0,0 +1,109 @@ + + + + + JSDoc: Source: migrate/extractTextPlugin/extractTextPlugin.js + + + + + + + + + + +
+ +

Source: migrate/extractTextPlugin/extractTextPlugin.js

+ + + + + + +
+
+
const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Check whether `node` is the invocation of the plugin denoted by `pluginName`
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} node - ast node to check
+ * @param {String} pluginName - name of the plugin
+ * @returns {Boolean} isPluginInvocation - whether `node` is the invocation of the plugin denoted by `pluginName`
+ */
+
+function findInvocation(j, node, pluginName) {
+	let found = false;
+	found =
+		j(node)
+			.find(j.MemberExpression)
+			.filter(p => p.get("object").value.name === pluginName)
+			.size() > 0;
+	return found;
+}
+
+/**
+ *
+ * Transform for ExtractTextPlugin arguments. Consolidates arguments into single options object.
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast) {
+	const changeArguments = function(p) {
+		const args = p.value.arguments;
+
+		const literalArgs = args.filter(p => utils.isType(p, "Literal"));
+		if (literalArgs && literalArgs.length > 1) {
+			const newArgs = j.objectExpression(
+				literalArgs.map((p, index) =>
+					utils.createProperty(j, index === 0 ? "fallback" : "use", p.value)
+				)
+			);
+			p.value.arguments = [newArgs];
+		}
+		return p;
+	};
+	const name = utils.findVariableToPlugin(
+		j,
+		ast,
+		"extract-text-webpack-plugin"
+	);
+	if (!name) return ast;
+
+	return ast
+		.find(j.CallExpression)
+		.filter(p => findInvocation(j, p, name))
+		.forEach(changeArguments);
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_index.js.html b/docs/migrate_index.js.html new file mode 100644 index 00000000000..2e805277425 --- /dev/null +++ b/docs/migrate_index.js.html @@ -0,0 +1,130 @@ + + + + + JSDoc: Source: migrate/index.js + + + + + + + + + + +
+ +

Source: migrate/index.js

+ + + + + + +
+
+
const jscodeshift = require("jscodeshift");
+const pEachSeries = require("p-each-series");
+const PLazy = require("p-lazy");
+
+const loadersTransform = require("./loaders/loaders");
+const resolveTransform = require("./resolve/resolve");
+const removeJsonLoaderTransform = require("./removeJsonLoader/removeJsonLoader");
+const uglifyJsPluginTransform = require("./uglifyJsPlugin/uglifyJsPlugin");
+const loaderOptionsPluginTransform = require("./loaderOptionsPlugin/loaderOptionsPlugin");
+const bannerPluginTransform = require("./bannerPlugin/bannerPlugin");
+const extractTextPluginTransform = require("./extractTextPlugin/extractTextPlugin");
+const removeDeprecatedPluginsTransform = require("./removeDeprecatedPlugins/removeDeprecatedPlugins");
+
+const transformsObject = {
+	loadersTransform,
+	resolveTransform,
+	removeJsonLoaderTransform,
+	uglifyJsPluginTransform,
+	loaderOptionsPluginTransform,
+	bannerPluginTransform,
+	extractTextPluginTransform,
+	removeDeprecatedPluginsTransform
+};
+
+const transformations = Object.keys(transformsObject).reduce((res, key) => {
+	res[key] = (ast, source) =>
+		transformSingleAST(ast, source, transformsObject[key]);
+	return res;
+}, {});
+
+function transformSingleAST(ast, source, transformFunction) {
+	return new PLazy((resolve, reject) => {
+		setTimeout(_ => {
+			try {
+				resolve(transformFunction(jscodeshift, ast, source));
+			} catch (err) {
+				reject(err);
+			}
+		}, 0);
+	});
+}
+
+/**
+ *
+ * Transforms a given piece of source code by applying selected transformations to the AST.
+ * By default, transforms a webpack version 1 configuration file into a webpack version 2
+ * configuration file.
+ *
+ * @param {String} source - source file contents
+ * @param {Function[]} [transforms] - List of transformation functions, defined in the
+ * order to apply them in. By default, all defined transfomations.
+ * @param {Object} [options] - recast formatting options
+ * @returns {String} source — transformed source code
+ */
+
+function transform(source, transforms, options) {
+	const ast = jscodeshift(source);
+	const recastOptions = Object.assign(
+		{
+			quote: "single"
+		},
+		options
+	);
+	transforms =
+		transforms || Object.keys(transformations).map(k => transformations[k]);
+	return pEachSeries(transforms, f => f(ast, source))
+		.then(_ => {
+			return ast.toSource(recastOptions);
+		})
+		.catch(err => {
+			console.error(err);
+		});
+}
+
+module.exports = {
+	transform,
+	transformSingleAST,
+	transformations
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_loaderOptionsPlugin_loaderOptionsPlugin.js.html b/docs/migrate_loaderOptionsPlugin_loaderOptionsPlugin.js.html new file mode 100644 index 00000000000..ed1e4518209 --- /dev/null +++ b/docs/migrate_loaderOptionsPlugin_loaderOptionsPlugin.js.html @@ -0,0 +1,98 @@ + + + + + JSDoc: Source: migrate/loaderOptionsPlugin/loaderOptionsPlugin.js + + + + + + + + + + +
+ +

Source: migrate/loaderOptionsPlugin/loaderOptionsPlugin.js

+ + + + + + +
+
+
const isEmpty = require("lodash/isEmpty");
+const findPluginsByName = require("../../utils/ast-utils").findPluginsByName;
+const createOrUpdatePluginByName = require("../../utils/ast-utils")
+	.createOrUpdatePluginByName;
+const safeTraverse = require("../../utils/ast-utils").safeTraverse;
+
+/**
+ *
+ * Transform which adds context information for old loaders by injecting a `LoaderOptionsPlugin`
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ *
+ */
+
+module.exports = function(j, ast) {
+	const loaderOptions = {};
+
+	// If there is debug: true, set debug: true in the plugin
+	// TODO: remove global debug setting
+	// TODO: I can't figure out how to find the topmost `debug: true`. help!
+	if (ast.find(j.Identifier, { name: "debug" }).size()) {
+		loaderOptions.debug = true;
+	}
+
+	// If there is UglifyJsPlugin, set minimize: true
+	if (findPluginsByName(j, ast, ["webpack.optimize.UglifyJsPlugin"]).size()) {
+		loaderOptions.minimize = true;
+	}
+
+	return ast
+		.find(j.ArrayExpression)
+		.filter(
+			path =>
+				safeTraverse(path, ["parent", "value", "key", "name"]) === "plugins"
+		)
+		.forEach(path => {
+			!isEmpty(loaderOptions) &&
+				createOrUpdatePluginByName(
+					j,
+					path,
+					"webpack.LoaderOptionsPlugin",
+					loaderOptions
+				);
+		});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_loaders_loaders.js.html b/docs/migrate_loaders_loaders.js.html new file mode 100644 index 00000000000..dbcffaee3f8 --- /dev/null +++ b/docs/migrate_loaders_loaders.js.html @@ -0,0 +1,384 @@ + + + + + JSDoc: Source: migrate/loaders/loaders.js + + + + + + + + + + +
+ +

Source: migrate/loaders/loaders.js

+ + + + + + +
+
+
const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Transform for loaders. Transforms pre- and postLoaders into enforce options,
+ * moves loader configuration into rules array, transforms query strings and
+ * props into loader options, and adds -loader suffix to loader names.
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast) {
+	/**
+	 * Creates an Array expression out of loaders string
+	 *
+	 *
+	 * For syntaxes like
+	 *
+	 * {
+	 *   loader: 'style!css`
+	 * }
+	 *
+	 * or
+	 *
+	 * {
+	 *   loaders: ['style', 'css']
+	 * }
+	 *
+	 * or
+	 *
+	 * loaders: [{
+	 *   loader: 'style'
+	 * },
+	 * {
+	 *   loader: 'css',
+	 * }]
+	 *
+	 * it should generate
+	 *
+	 * {
+	 *   use: [{
+	 *     loader: 'style'
+	 *   },
+	 *   {
+	 *     loader: 'css'
+	 *   }]
+	 * }
+	 *
+	 * @param  {Node} path - object expression ast
+	 * @returns {Node} path - object expression ast with array expression instead of loaders string
+	 */
+
+	const createArrayExpressionFromArray = function(path) {
+		const value = path.value;
+		// Find paths with `loaders` keys in the given Object
+		const paths = value.properties.filter(prop =>
+			prop.key.name.startsWith("loader")
+		);
+		// For each pair of key and value
+		paths.forEach(pair => {
+			// Replace 'loaders' Identifier with 'use'
+			pair.key.name = "use";
+			// If the value is an Array
+			if (pair.value.type === j.ArrayExpression.name) {
+				// replace its elements
+				const pairValue = pair.value;
+				pair.value = j.arrayExpression(
+					pairValue.elements.map(arrElement => {
+						// If items of the array are Strings
+						if (arrElement.type === j.Literal.name) {
+							// Replace with `{ loader: LOADER }` Object
+							return j.objectExpression([
+								utils.createProperty(j, "loader", arrElement.value)
+							]);
+						}
+						// otherwise keep the existing element
+						return arrElement;
+					})
+				);
+				//	If the value is String of loaders like 'style!css'
+			} else if (pair.value.type === j.Literal.name) {
+				// Replace it with Array expression of loaders
+				const literalValue = pair.value;
+				pair.value = j.arrayExpression(
+					literalValue.value.split("!").map(loader => {
+						return j.objectExpression([
+							utils.createProperty(j, "loader", loader)
+						]);
+					})
+				);
+			}
+		});
+		return path;
+	};
+
+	/**
+	 *
+	 * Puts query parameters from loader value into options object
+	 *
+	 * @param {Node} p - object expression ast for loader object
+	 * @returns {Node} objectExpression - an new object expression ast containing the query parameters
+	 */
+
+	const createLoaderWithQuery = p => {
+		let properties = p.value.properties;
+		let loaderValue = properties.reduce(
+			(val, prop) => (prop.key.name === "loader" ? prop.value.value : val),
+			""
+		);
+		let loader = loaderValue.split("?")[0];
+		let query = loaderValue.split("?")[1];
+		let options = query.split("&").map(option => {
+			const param = option.split("=");
+			const key = param[0];
+			const val = param[1] || true; // No value in query string means it is truthy value
+			return j.objectProperty(j.identifier(key), utils.createLiteral(j, val));
+		});
+		let loaderProp = utils.createProperty(j, "loader", loader);
+		let queryProp = j.property(
+			"init",
+			j.identifier("options"),
+			j.objectExpression(options)
+		);
+		return j.objectExpression([loaderProp, queryProp]);
+	};
+
+	/**
+	 *
+	 * Determine whether a loader has a query string
+	 *
+	 * @param {Node} p - object expression ast for loader object
+	 * @returns {Boolean} hasLoaderQueryString - whether the loader object contains a query string
+	 */
+
+	const findLoaderWithQueryString = p => {
+		return p.value.properties.reduce((predicate, prop) => {
+			return (
+				(utils.safeTraverse(prop, ["value", "value", "indexOf"]) &&
+					prop.value.value.indexOf("?") > -1) ||
+				predicate
+			);
+		}, false);
+	};
+
+	/**
+	 * Check if the identifier is the `loaders` prop in the `module` object.
+	 * If the path value is `loaders` and it’s located in `module` object
+	 * we assume it’s the loader's section.
+	 *
+	 * @param {Node} path - identifier ast
+	 * @returns {Boolean} isLoadersProp - whether the identifier is the `loaders` prop in the `module` object
+	 */
+
+	const checkForLoader = path =>
+		path.value.name === "loaders" &&
+		utils.safeTraverse(path, [
+			"parent",
+			"parent",
+			"parent",
+			"node",
+			"key",
+			"name"
+		]) === "module";
+
+	/**
+	 * Puts pre- or postLoader into `loaders` object and adds the appropriate `enforce` property
+	 *
+	 * @param {Node} p - object expression ast that has a key for either 'preLoaders' or 'postLoaders'
+	 * @returns {Node} p - object expression with a `loaders` object and appropriate `enforce` properties
+	 */
+
+	const fitIntoLoaders = p => {
+		let loaders;
+		p.value.properties.map(prop => {
+			const keyName = prop.key.name;
+			if (keyName === "loaders") {
+				loaders = prop.value;
+			}
+		});
+		p.value.properties.map(prop => {
+			const keyName = prop.key.name;
+			if (keyName !== "loaders") {
+				const enforceVal = keyName === "preLoaders" ? "pre" : "post";
+				prop.value.elements.map(elem => {
+					elem.properties.push(utils.createProperty(j, "enforce", enforceVal));
+					if (loaders && loaders.type === "ArrayExpression") {
+						loaders.elements.push(elem);
+					} else {
+						prop.key.name = "loaders";
+					}
+				});
+			}
+		});
+		if (loaders) {
+			p.value.properties = p.value.properties.filter(
+				prop => prop.key.name === "loaders"
+			);
+		}
+		return p;
+	};
+
+	/**
+	 * Find pre and postLoaders in the ast and put them into the `loaders` array
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const prepostLoaders = () =>
+		ast
+			.find(j.ObjectExpression)
+			.filter(p => utils.findObjWithOneOfKeys(p, ["preLoaders", "postLoaders"]))
+			.forEach(fitIntoLoaders);
+
+	/**
+	 * Convert top level `loaders` to `rules`
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const loadersToRules = () =>
+		ast
+			.find(j.Identifier)
+			.filter(checkForLoader)
+			.forEach(p => (p.value.name = "rules"));
+
+	/**
+	 * Convert `loader` and `loaders` to Array of {Rule.Use}
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const loadersToArrayExpression = () =>
+		ast
+			.find(j.ObjectExpression)
+			.filter(path => utils.findObjWithOneOfKeys(path, ["loader", "loaders"]))
+			.filter(
+				path =>
+					utils.safeTraverse(path, [
+						"parent",
+						"parent",
+						"node",
+						"key",
+						"name"
+					]) === "rules"
+			)
+			.forEach(createArrayExpressionFromArray);
+
+	/**
+	 * Find loaders with options encoded as a query string and replace the string with an options object
+	 *
+	 * i.e. for loader like
+	 *
+	 * {
+	 *   loader: 'css?modules&importLoaders=1&string=test123'
+	 * }
+	 *
+	 * it should generate
+	 * {
+	 *   loader: 'css-loader',
+	 *   options: {
+	 *     modules: true,
+	 *     importLoaders: 1,
+	 *     string: 'test123'
+	 *   }
+	 * }
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const loaderWithQueryParam = () =>
+		ast
+			.find(j.ObjectExpression)
+			.filter(p => utils.findObjWithOneOfKeys(p, ["loader"]))
+			.filter(findLoaderWithQueryString)
+			.replaceWith(createLoaderWithQuery);
+
+	/**
+	 * Find nodes with a `query` key and replace it with `options`
+	 *
+	 * i.e. for
+	 * {
+	 *   query: { ... }
+	 * }
+	 *
+	 * it should generate
+	 *
+	 * {
+	 *   options: { ... }
+	 * }
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const loaderWithQueryProp = () =>
+		ast
+			.find(j.Identifier)
+			.filter(p => p.value.name === "query")
+			.replaceWith(j.identifier("options"));
+
+	/**
+	 * Add required `-loader` suffix to a loader with missing suffix
+	 * e.g. for `babel` it should generate `babel-loader`
+	 *
+	 * @returns {Node} ast - jscodeshift ast
+	 */
+
+	const addLoaderSuffix = () =>
+		ast.find(j.ObjectExpression).forEach(path => {
+			path.value.properties.forEach(prop => {
+				if (
+					prop.key.name === "loader" &&
+					utils.safeTraverse(prop, ["value", "value"]) &&
+					!prop.value.value.endsWith("-loader")
+				) {
+					prop.value = j.literal(prop.value.value + "-loader");
+				}
+			});
+		});
+
+	const transforms = [
+		prepostLoaders,
+		loadersToRules,
+		loadersToArrayExpression,
+		loaderWithQueryParam,
+		loaderWithQueryProp,
+		addLoaderSuffix
+	];
+	transforms.forEach(t => t());
+
+	return ast;
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_outputPath_outputPath.js.html b/docs/migrate_outputPath_outputPath.js.html new file mode 100644 index 00000000000..bd1d503c3f1 --- /dev/null +++ b/docs/migrate_outputPath_outputPath.js.html @@ -0,0 +1,125 @@ + + + + + JSDoc: Source: migrate/outputPath/outputPath.js + + + + + + + + + + +
+ +

Source: migrate/outputPath/outputPath.js

+ + + + + + +
+
+
const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Transform which adds `path.join` call to `output.path` literals
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast) {
+	const literalOutputPath = ast
+		.find(j.ObjectExpression)
+		.filter(
+			p =>
+				utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+				"output"
+		)
+		.find(j.Property)
+		.filter(
+			p =>
+				utils.safeTraverse(p, ["value", "key", "name"]) === "path" &&
+				utils.safeTraverse(p, ["value", "value", "type"]) === "Literal"
+		);
+
+	if (literalOutputPath) {
+		let pathVarName = "path";
+		let isPathPresent = false;
+		const pathDecalaration = ast
+			.find(j.VariableDeclarator)
+			.filter(
+				p =>
+					utils.safeTraverse(p, ["value", "init", "callee", "name"]) ===
+					"require"
+			)
+			.filter(
+				p =>
+					utils.safeTraverse(p, ["value", "init", "arguments"]) &&
+					p.value.init.arguments.reduce((isPresent, a) => {
+						return (a.type === "Literal" && a.value === "path") || isPresent;
+					}, false)
+			);
+
+		if (pathDecalaration) {
+			isPathPresent = true;
+			pathDecalaration.forEach(p => {
+				pathVarName = utils.safeTraverse(p, ["value", "id", "name"]);
+			});
+		}
+		const finalPathName = pathVarName;
+		literalOutputPath
+			.find(j.Literal)
+			.replaceWith(p => replaceWithPath(j, p, finalPathName));
+
+		if (!isPathPresent) {
+			const pathRequire = utils.getRequire(j, "path", "path");
+			return ast
+				.find(j.Program)
+				.replaceWith(p =>
+					j.program([].concat(pathRequire).concat(p.value.body))
+				);
+		}
+	}
+	return ast;
+};
+
+function replaceWithPath(j, p, pathVarName) {
+	const convertedPath = j.callExpression(
+		j.memberExpression(j.identifier(pathVarName), j.identifier("join"), false),
+		[j.identifier("__dirname"), p.value]
+	);
+	return convertedPath;
+}
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_removeDeprecatedPlugins_removeDeprecatedPlugins.js.html b/docs/migrate_removeDeprecatedPlugins_removeDeprecatedPlugins.js.html new file mode 100644 index 00000000000..84f990c6293 --- /dev/null +++ b/docs/migrate_removeDeprecatedPlugins_removeDeprecatedPlugins.js.html @@ -0,0 +1,95 @@ + + + + + JSDoc: Source: migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js + + + + + + + + + + +
+ +

Source: migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js

+ + + + + + +
+
+
const chalk = require("chalk");
+const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Find deprecated plugins and remove them from the `plugins` array, if possible.
+ * Otherwise, warn the user about removing deprecated plugins manually.
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast, source) {
+	// List of deprecated plugins to remove
+	// each item refers to webpack.optimize.[NAME] construct
+	const deprecatedPlugingsList = [
+		"webpack.optimize.OccurrenceOrderPlugin",
+		"webpack.optimize.DedupePlugin"
+	];
+
+	return utils
+		.findPluginsByName(j, ast, deprecatedPlugingsList)
+		.forEach(path => {
+			// For now we only support the case where plugins are defined in an Array
+			const arrayPath = utils.safeTraverse(path, ["parent", "value"]);
+			if (arrayPath && utils.isType(arrayPath, "ArrayExpression")) {
+				// Check how many plugins are defined and
+				// if there is only last plugin left remove `plugins: []` node
+				const arrayElementsPath = utils.safeTraverse(arrayPath, ["elements"]);
+				if (arrayElementsPath && arrayElementsPath.length === 1) {
+					j(path.parent.parent).remove();
+				} else {
+					j(path).remove();
+				}
+			} else {
+				console.log(`
+${chalk.red("Please remove deprecated plugins manually. ")}
+See ${chalk.underline(
+		"https://webpack.js.org/guides/migrating/"
+	)} for more information.`);
+			}
+		});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_removeJsonLoader_removeJsonLoader.js.html b/docs/migrate_removeJsonLoader_removeJsonLoader.js.html new file mode 100644 index 00000000000..2caeabc0ccd --- /dev/null +++ b/docs/migrate_removeJsonLoader_removeJsonLoader.js.html @@ -0,0 +1,120 @@ + + + + + JSDoc: Source: migrate/removeJsonLoader/removeJsonLoader.js + + + + + + + + + + +
+ +

Source: migrate/removeJsonLoader/removeJsonLoader.js

+ + + + + + +
+
+
const utils = require("../../utils/ast-utils");
+
+/**
+ *
+ * Transform which removes the json loader from all possible declarations
+ *
+ * @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 the loader with name `name` from the given NodePath
+	 *
+	 * @param {Node} path - ast to remove the loader from
+	 * @param {String} name - the name of the loader to remove
+	 *
+	 */
+
+	function removeLoaderByName(path, name) {
+		const loadersNode = path.value.value;
+		switch (loadersNode.type) {
+			case j.ArrayExpression.name: {
+				let loaders = loadersNode.elements.map(p => {
+					return utils.safeTraverse(p, ["properties", "0", "value", "value"]);
+				});
+				const loaderIndex = loaders.indexOf(name);
+				if (loaders.length && loaderIndex > -1) {
+					// Remove loader from the array
+					loaders.splice(loaderIndex, 1);
+					// and from AST
+					loadersNode.elements.splice(loaderIndex, 1);
+				}
+
+				// If there are no loaders left, remove the whole Rule object
+				if (loaders.length === 0) {
+					j(path.parent).remove();
+				}
+				break;
+			}
+			case j.Literal.name: {
+				// If only the loader with the matching name was used
+				// we can remove the whole Property node completely
+				if (loadersNode.value === name) {
+					j(path.parent).remove();
+				}
+				break;
+			}
+		}
+	}
+
+	function removeLoaders(ast) {
+		ast
+			.find(j.Property, { key: { name: "use" } })
+			.forEach(path => removeLoaderByName(path, "json-loader"));
+
+		ast
+			.find(j.Property, { key: { name: "loader" } })
+			.forEach(path => removeLoaderByName(path, "json-loader"));
+	}
+
+	const transforms = [removeLoaders];
+
+	transforms.forEach(t => t(ast));
+
+	return ast;
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_resolve_resolve.js.html b/docs/migrate_resolve_resolve.js.html new file mode 100644 index 00000000000..ba7761ffffc --- /dev/null +++ b/docs/migrate_resolve_resolve.js.html @@ -0,0 +1,123 @@ + + + + + JSDoc: Source: migrate/resolve/resolve.js + + + + + + + + + + +
+ +

Source: migrate/resolve/resolve.js

+ + + + + + +
+
+
/**
+ *
+ * Transform which consolidates the `resolve.root` configuration option into the `resolve.modules` array
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function transformer(j, ast) {
+	const getRootVal = p => {
+		return p.node.value.properties.filter(prop => prop.key.name === "root")[0];
+	};
+
+	const getRootIndex = p => {
+		return p.node.value.properties.reduce((rootIndex, prop, index) => {
+			return prop.key.name === "root" ? index : rootIndex;
+		}, -1);
+	};
+
+	const isModulePresent = p => {
+		const modules = p.node.value.properties.filter(
+			prop => prop.key.name === "modules"
+		);
+		return modules.length > 0 && modules[0];
+	};
+
+	/**
+	 *
+	 * Add a `modules` property to the `resolve` object or update the existing one
+	 * based on what is already in `resolve.root`
+	 *
+	 * @param {Node} p - ast node that represents the `resolve` property
+	 * @returns {Node} p - ast node that represents the updated `resolve` property
+	 */
+
+	const createModuleArray = p => {
+		const rootVal = getRootVal(p);
+		let modulesVal = null;
+		if (rootVal.value.type === "ArrayExpression") {
+			modulesVal = rootVal.value.elements;
+		} else {
+			modulesVal = [rootVal.value];
+		}
+		let module = isModulePresent(p);
+
+		if (!module) {
+			module = j.property(
+				"init",
+				j.identifier("modules"),
+				j.arrayExpression(modulesVal)
+			);
+			p.node.value.properties = p.node.value.properties.concat([module]);
+		} else {
+			module.value.elements = module.value.elements.concat(modulesVal);
+		}
+		const rootIndex = getRootIndex(p);
+		p.node.value.properties.splice(rootIndex, 1);
+		return p;
+	};
+
+	return ast
+		.find(j.Property)
+		.filter(p => {
+			return (
+				p.node.key.name === "resolve" &&
+				p.node.value.properties.filter(prop => prop.key.name === "root")
+					.length === 1
+			);
+		})
+		.forEach(createModuleArray);
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/migrate_uglifyJsPlugin_uglifyJsPlugin.js.html b/docs/migrate_uglifyJsPlugin_uglifyJsPlugin.js.html new file mode 100644 index 00000000000..e1e6a73215f --- /dev/null +++ b/docs/migrate_uglifyJsPlugin_uglifyJsPlugin.js.html @@ -0,0 +1,84 @@ + + + + + JSDoc: Source: migrate/uglifyJsPlugin/uglifyJsPlugin.js + + + + + + + + + + +
+ +

Source: migrate/uglifyJsPlugin/uglifyJsPlugin.js

+ + + + + + +
+
+
const findPluginsByName = require("../../utils/ast-utils").findPluginsByName;
+
+/**
+ *
+ * Transform which adds a `sourceMap: true` option to instantiations of the UglifyJsPlugin
+ *
+ * @param {Object} j - jscodeshift top-level import
+ * @param {Node} ast - jscodeshift ast to transform
+ * @returns {Node} ast - jscodeshift ast
+ */
+
+module.exports = function(j, ast) {
+	function createSourceMapsProperty() {
+		return j.property("init", j.identifier("sourceMap"), j.identifier("true"));
+	}
+
+	return findPluginsByName(j, ast, ["webpack.optimize.UglifyJsPlugin"]).forEach(
+		path => {
+			const args = path.value.arguments;
+
+			if (args.length) {
+				// Plugin is called with object as arguments
+				j(path)
+					.find(j.ObjectExpression)
+					.get("properties")
+					.value.push(createSourceMapsProperty());
+			} else {
+				// Plugin is called without arguments
+				args.push(j.objectExpression([createSourceMapsProperty()]));
+			}
+		}
+	);
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST) +
+ + + + + diff --git a/docs/utils_ast-utils.js.html b/docs/utils_ast-utils.js.html index 163cc7bb031..5c3ac4d3735 100644 --- a/docs/utils_ast-utils.js.html +++ b/docs/utils_ast-utils.js.html @@ -712,13 +712,13 @@

Source: utils/ast-utils.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_copy-utils.js.html b/docs/utils_copy-utils.js.html index 2d0fe77b1b7..fd8813f1944 100644 --- a/docs/utils_copy-utils.js.html +++ b/docs/utils_copy-utils.js.html @@ -93,13 +93,13 @@

Source: utils/copy-utils.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_defineTest.js.html b/docs/utils_defineTest.js.html index 7623aeb5335..6ee2120c476 100644 --- a/docs/utils_defineTest.js.html +++ b/docs/utils_defineTest.js.html @@ -141,13 +141,13 @@

Source: utils/defineTest.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_hashtable.js.html b/docs/utils_hashtable.js.html index 81342b738c9..62a346122d9 100644 --- a/docs/utils_hashtable.js.html +++ b/docs/utils_hashtable.js.html @@ -56,13 +56,13 @@

Source: utils/hashtable.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_modify-config-helper.js.html b/docs/utils_modify-config-helper.js.html index 32461a21684..573ca5c33f2 100644 --- a/docs/utils_modify-config-helper.js.html +++ b/docs/utils_modify-config-helper.js.html @@ -76,13 +76,13 @@

Source: utils/modify-config-helper.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_npm-exists.js.html b/docs/utils_npm-exists.js.html index 48cb0726cd1..9c5f3796d25 100644 --- a/docs/utils_npm-exists.js.html +++ b/docs/utils_npm-exists.js.html @@ -59,13 +59,13 @@

Source: utils/npm-exists.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_npm-packages-exists.js.html b/docs/utils_npm-packages-exists.js.html index 52360d367d4..df3651a7c45 100644 --- a/docs/utils_npm-packages-exists.js.html +++ b/docs/utils_npm-packages-exists.js.html @@ -82,13 +82,13 @@

Source: utils/npm-packages-exists.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_package-manager.js.html b/docs/utils_package-manager.js.html index 30d9cd4a89a..0c0dfbd2ebf 100644 --- a/docs/utils_package-manager.js.html +++ b/docs/utils_package-manager.js.html @@ -113,13 +113,13 @@

Source: utils/package-manager.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_prop-types.js.html b/docs/utils_prop-types.js.html index 09a775af11e..b1ae2ff9195 100644 --- a/docs/utils_prop-types.js.html +++ b/docs/utils_prop-types.js.html @@ -71,13 +71,13 @@

Source: utils/prop-types.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_resolve-packages.js.html b/docs/utils_resolve-packages.js.html index 23ab49d00de..73a7f17ff29 100644 --- a/docs/utils_resolve-packages.js.html +++ b/docs/utils_resolve-packages.js.html @@ -109,13 +109,13 @@

Source: utils/resolve-packages.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/docs/utils_run-prettier.js.html b/docs/utils_run-prettier.js.html index 1deb65912a2..69a57e56fad 100644 --- a/docs/utils_run-prettier.js.html +++ b/docs/utils_run-prettier.js.html @@ -80,13 +80,13 @@

Source: utils/run-prettier.js


- Documentation generated by JSDoc 3.5.5 on Mon Jan 15 2018 00:04:44 GMT+0100 (CET) + Documentation generated by JSDoc 3.5.5 on Wed Feb 07 2018 11:36:26 GMT-0500 (EST)
diff --git a/jsdoc.json b/jsdoc.json index 569050835f4..44f76eb218c 100644 --- a/jsdoc.json +++ b/jsdoc.json @@ -4,7 +4,6 @@ "include": [ "lib/" ], - "includePattern": "lib/.+\\.js$", - "excludePattern": "lib/migrate" + "includePattern": "lib/.+\\.js$" } } diff --git a/lib/migrate/bannerPlugin/bannerPlugin.js b/lib/migrate/bannerPlugin/bannerPlugin.js index 44bbbdc8434..f7fbdc9fb87 100644 --- a/lib/migrate/bannerPlugin/bannerPlugin.js +++ b/lib/migrate/bannerPlugin/bannerPlugin.js @@ -1,5 +1,15 @@ const utils = require("../../utils/ast-utils"); +/** + * + * Transform for BannerPlugin arguments. Consolidates first and second argument (if + * both are present) into single options object. + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast) { return utils .findPluginsByName(j, ast, ["webpack.BannerPlugin"]) diff --git a/lib/migrate/extractTextPlugin/extractTextPlugin.js b/lib/migrate/extractTextPlugin/extractTextPlugin.js index b2473db7f98..20158d9081c 100644 --- a/lib/migrate/extractTextPlugin/extractTextPlugin.js +++ b/lib/migrate/extractTextPlugin/extractTextPlugin.js @@ -1,5 +1,15 @@ const utils = require("../../utils/ast-utils"); +/** + * + * Check whether `node` is the invocation of the plugin denoted by `pluginName` + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} node - ast node to check + * @param {String} pluginName - name of the plugin + * @returns {Boolean} isPluginInvocation - whether `node` is the invocation of the plugin denoted by `pluginName` + */ + function findInvocation(j, node, pluginName) { let found = false; found = @@ -10,6 +20,15 @@ function findInvocation(j, node, pluginName) { return found; } +/** + * + * Transform for ExtractTextPlugin arguments. Consolidates arguments into single options object. + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast) { const changeArguments = function(p) { const args = p.value.arguments; diff --git a/lib/migrate/index.js b/lib/migrate/index.js index 95567244527..caac4b179ce 100644 --- a/lib/migrate/index.js +++ b/lib/migrate/index.js @@ -40,17 +40,19 @@ function transformSingleAST(ast, source, transformFunction) { }); } -/* - * @function transform +/** * - * Tranforms a given source code by applying selected transformations to the AST + * Transforms a given piece of source code by applying selected transformations to the AST. + * By default, transforms a webpack version 1 configuration file into a webpack version 2 + * configuration file. * - * @param { String } source - Source file contents - * @param { Array } transformations - List of trnasformation functions in defined the - * order to apply. By default all defined transfomations. - * @param { Object } options - Reacst formatting options - * @returns { String } Transformed source code - * */ + * @param {String} source - source file contents + * @param {Function[]} [transforms] - List of transformation functions, defined in the + * order to apply them in. By default, all defined transfomations. + * @param {Object} [options] - recast formatting options + * @returns {String} source — transformed source code + */ + function transform(source, transforms, options) { const ast = jscodeshift(source); const recastOptions = Object.assign( diff --git a/lib/migrate/loaderOptionsPlugin/loaderOptionsPlugin.js b/lib/migrate/loaderOptionsPlugin/loaderOptionsPlugin.js index 8e1a540dad5..5019aeeed79 100644 --- a/lib/migrate/loaderOptionsPlugin/loaderOptionsPlugin.js +++ b/lib/migrate/loaderOptionsPlugin/loaderOptionsPlugin.js @@ -4,6 +4,16 @@ const createOrUpdatePluginByName = require("../../utils/ast-utils") .createOrUpdatePluginByName; const safeTraverse = require("../../utils/ast-utils").safeTraverse; +/** + * + * Transform which adds context information for old loaders by injecting a `LoaderOptionsPlugin` + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + * + */ + module.exports = function(j, ast) { const loaderOptions = {}; diff --git a/lib/migrate/loaders/loaders.js b/lib/migrate/loaders/loaders.js index bc991317ca9..a2820068be7 100644 --- a/lib/migrate/loaders/loaders.js +++ b/lib/migrate/loaders/loaders.js @@ -1,5 +1,16 @@ const utils = require("../../utils/ast-utils"); +/** + * + * Transform for loaders. Transforms pre- and postLoaders into enforce options, + * moves loader configuration into rules array, transforms query strings and + * props into loader options, and adds -loader suffix to loader names. + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast) { /** * Creates an Array expression out of loaders string @@ -36,8 +47,9 @@ module.exports = function(j, ast) { * loader: 'css' * }] * } - * @param {Node} path Must be an ObjectExpression - * @return {Node} [] + * + * @param {Node} path - object expression ast + * @returns {Node} path - object expression ast with array expression instead of loaders string */ const createArrayExpressionFromArray = function(path) { @@ -83,6 +95,14 @@ module.exports = function(j, ast) { return path; }; + /** + * + * Puts query parameters from loader value into options object + * + * @param {Node} p - object expression ast for loader object + * @returns {Node} objectExpression - an new object expression ast containing the query parameters + */ + const createLoaderWithQuery = p => { let properties = p.value.properties; let loaderValue = properties.reduce( @@ -106,6 +126,14 @@ module.exports = function(j, ast) { return j.objectExpression([loaderProp, queryProp]); }; + /** + * + * Determine whether a loader has a query string + * + * @param {Node} p - object expression ast for loader object + * @returns {Boolean} hasLoaderQueryString - whether the loader object contains a query string + */ + const findLoaderWithQueryString = p => { return p.value.properties.reduce((predicate, prop) => { return ( @@ -117,12 +145,14 @@ module.exports = function(j, ast) { }; /** - * If the path value is `loaders` and it's located in `module` object - * we assume it's the loader's section + * Check if the identifier is the `loaders` prop in the `module` object. + * If the path value is `loaders` and it’s located in `module` object + * we assume it’s the loader's section. * - * @param {Node} path [description] - * @return {Node} [description] + * @param {Node} path - identifier ast + * @returns {Boolean} isLoadersProp - whether the identifier is the `loaders` prop in the `module` object */ + const checkForLoader = path => path.value.name === "loaders" && utils.safeTraverse(path, [ @@ -135,11 +165,12 @@ module.exports = function(j, ast) { ]) === "module"; /** - * Puts node path that is pre- or postLoader into `enforce` key + * Puts pre- or postLoader into `loaders` object and adds the appropriate `enforce` property * - * @param {Node} p [] - * @returns {*} [] + * @param {Node} p - object expression ast that has a key for either 'preLoaders' or 'postLoaders' + * @returns {Node} p - object expression with a `loaders` object and appropriate `enforce` properties */ + const fitIntoLoaders = p => { let loaders; p.value.properties.map(prop => { @@ -171,10 +202,9 @@ module.exports = function(j, ast) { }; /** - * Find pre and postLoaders + * Find pre and postLoaders in the ast and put them into the `loaders` array * - * @param {[type]} IPath [description] - * @return {[type]} [description] + * @returns {Node} ast - jscodeshift ast */ const prepostLoaders = () => @@ -185,9 +215,8 @@ module.exports = function(j, ast) { /** * Convert top level `loaders` to `rules` - * See https://webpack.js.org/configuration/module/#module-rules - * @param {[type]} IPath [description] - * @return {[type]} [description] + * + * @returns {Node} ast - jscodeshift ast */ const loadersToRules = () => @@ -197,9 +226,9 @@ module.exports = function(j, ast) { .forEach(p => (p.value.name = "rules")); /** - * Converts 'loader' and 'loaders' to Array of {Rule.Use} + * Convert `loader` and `loaders` to Array of {Rule.Use} * - * @returns {Node} [] + * @returns {Node} ast - jscodeshift ast */ const loadersToArrayExpression = () => @@ -219,7 +248,7 @@ module.exports = function(j, ast) { .forEach(createArrayExpressionFromArray); /** - * Finds loaders with options encoded as query string and replaces it with options obejct + * Find loaders with options encoded as a query string and replace the string with an options object * * i.e. for loader like * @@ -237,8 +266,7 @@ module.exports = function(j, ast) { * } * } * - * @type {[type]} - * @returns {Node} [] + * @returns {Node} ast - jscodeshift ast */ const loaderWithQueryParam = () => @@ -249,7 +277,7 @@ module.exports = function(j, ast) { .replaceWith(createLoaderWithQuery); /** - * Finds nodes with `query` key and replaces it with `options` + * Find nodes with a `query` key and replace it with `options` * * i.e. for * { @@ -261,7 +289,8 @@ module.exports = function(j, ast) { * { * options: { ... } * } - * @returns {Node} [] + * + * @returns {Node} ast - jscodeshift ast */ const loaderWithQueryProp = () => @@ -271,9 +300,10 @@ module.exports = function(j, ast) { .replaceWith(j.identifier("options")); /** - * Adds required `-loader` suffix to loader with missing suffix - * i.e. for `babel` it should generate `babel-loader` - * @returns {Node} [] + * Add required `-loader` suffix to a loader with missing suffix + * e.g. for `babel` it should generate `babel-loader` + * + * @returns {Node} ast - jscodeshift ast */ const addLoaderSuffix = () => diff --git a/lib/migrate/outputPath/outputPath.js b/lib/migrate/outputPath/outputPath.js index 077b2ba8fdb..bbbcc846f2f 100644 --- a/lib/migrate/outputPath/outputPath.js +++ b/lib/migrate/outputPath/outputPath.js @@ -1,5 +1,14 @@ const utils = require("../../utils/ast-utils"); +/** + * + * Transform which adds `path.join` call to `output.path` literals + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast) { const literalOutputPath = ast .find(j.ObjectExpression) diff --git a/lib/migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js b/lib/migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js index dbde528bc6d..d6c060316f4 100644 --- a/lib/migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js +++ b/lib/migrate/removeDeprecatedPlugins/removeDeprecatedPlugins.js @@ -1,6 +1,16 @@ const chalk = require("chalk"); const utils = require("../../utils/ast-utils"); +/** + * + * Find deprecated plugins and remove them from the `plugins` array, if possible. + * Otherwise, warn the user about removing deprecated plugins manually. + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast, source) { // List of deprecated plugins to remove // each item refers to webpack.optimize.[NAME] construct @@ -12,7 +22,7 @@ module.exports = function(j, ast, source) { return utils .findPluginsByName(j, ast, deprecatedPlugingsList) .forEach(path => { - // For now we only support the case there plugins are defined in an Array + // For now we only support the case where plugins are defined in an Array const arrayPath = utils.safeTraverse(path, ["parent", "value"]); if (arrayPath && utils.isType(arrayPath, "ArrayExpression")) { // Check how many plugins are defined and diff --git a/lib/migrate/removeJsonLoader/removeJsonLoader.js b/lib/migrate/removeJsonLoader/removeJsonLoader.js index 4e9ec7aac73..f326c37508c 100644 --- a/lib/migrate/removeJsonLoader/removeJsonLoader.js +++ b/lib/migrate/removeJsonLoader/removeJsonLoader.js @@ -1,6 +1,24 @@ const utils = require("../../utils/ast-utils"); +/** + * + * Transform which removes the json loader from all possible declarations + * + * @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 the loader with name `name` from the given NodePath + * + * @param {Node} path - ast to remove the loader from + * @param {String} name - the name of the loader to remove + * + */ + function removeLoaderByName(path, name) { const loadersNode = path.value.value; switch (loadersNode.type) { diff --git a/lib/migrate/resolve/resolve.js b/lib/migrate/resolve/resolve.js index 15a3b5b845c..f0cb3b4b9df 100644 --- a/lib/migrate/resolve/resolve.js +++ b/lib/migrate/resolve/resolve.js @@ -1,3 +1,12 @@ +/** + * + * Transform which consolidates the `resolve.root` configuration option into the `resolve.modules` array + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function transformer(j, ast) { const getRootVal = p => { return p.node.value.properties.filter(prop => prop.key.name === "root")[0]; @@ -16,6 +25,15 @@ module.exports = function transformer(j, ast) { return modules.length > 0 && modules[0]; }; + /** + * + * Add a `modules` property to the `resolve` object or update the existing one + * based on what is already in `resolve.root` + * + * @param {Node} p - ast node that represents the `resolve` property + * @returns {Node} p - ast node that represents the updated `resolve` property + */ + const createModuleArray = p => { const rootVal = getRootVal(p); let modulesVal = null; diff --git a/lib/migrate/uglifyJsPlugin/uglifyJsPlugin.js b/lib/migrate/uglifyJsPlugin/uglifyJsPlugin.js index d529fd48b9b..a5bae15d0a3 100644 --- a/lib/migrate/uglifyJsPlugin/uglifyJsPlugin.js +++ b/lib/migrate/uglifyJsPlugin/uglifyJsPlugin.js @@ -1,5 +1,14 @@ const findPluginsByName = require("../../utils/ast-utils").findPluginsByName; +/** + * + * Transform which adds a `sourceMap: true` option to instantiations of the UglifyJsPlugin + * + * @param {Object} j - jscodeshift top-level import + * @param {Node} ast - jscodeshift ast to transform + * @returns {Node} ast - jscodeshift ast + */ + module.exports = function(j, ast) { function createSourceMapsProperty() { return j.property("init", j.identifier("sourceMap"), j.identifier("true")); diff --git a/yarn.lock b/yarn.lock index 7018c72d95c..8a7e955775f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1998,12 +1998,6 @@ escodegen@^1.6.1: optionalDependencies: source-map "~0.5.6" -eslint-plugin-flowtype@^2.35.1: - version "2.41.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.41.0.tgz#fd5221c60ba917c059d7ef69686a99cca09fd871" - dependencies: - lodash "^4.15.0" - eslint-plugin-node@^5.1.0: version "5.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-5.2.1.tgz#80df3253c4d7901045ec87fa660a284e32bdca29" @@ -3989,7 +3983,7 @@ lodash.unescape@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" -lodash@^4.11.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.3.0: +lodash@^4.11.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.3.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"