From 5396c91b09a56d2a22f3e30fe6770b9c4746fc72 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 5 Jan 2021 22:33:18 +0530 Subject: [PATCH 1/5] fix: deprecate migrate package --- .cz-config.js | 2 +- MIGRATE.md | 207 ---------- README.md | 2 +- packages/README.md | 2 +- packages/migrate/CHANGELOG.md | 57 --- packages/migrate/README.md | 35 -- packages/migrate/__testfixtures__/failing.js | 79 ---- .../__snapshots__/migrate.test.ts.snap | 158 -------- .../__snapshots__/bannerPlugin.test.ts.snap | 32 -- .../__testfixtures__/bannerPlugin-0.input.js | 5 - .../__testfixtures__/bannerPlugin-1.input.js | 4 - .../__testfixtures__/bannerPlugin-2.input.js | 6 - .../bannerPlugin/bannerPlugin.test.ts | 12 - .../commonsChunkPlugin.test.ts.snap | 302 --------------- .../commonsChunkPlugin-0.input.js | 12 - .../commonsChunkPlugin-1.input.js | 11 - .../commonsChunkPlugin-2.input.js | 11 - .../commonsChunkPlugin-3.input.js | 8 - .../commonsChunkPlugin-4.input.js | 13 - .../commonsChunkPlugin-5.input.js | 11 - .../commonsChunkPlugin-6a.input.js | 12 - .../commonsChunkPlugin-6b.input.js | 15 - .../commonsChunkPlugin-6c.input.js | 15 - .../commonsChunkPlugin-6d.input.js | 18 - .../commonsChunkPlugin-7.input.js | 12 - .../commonsChunkPlugin.test.ts | 19 - .../extractTextPlugin.test.ts.snap | 21 -- .../extractTextPlugin.input.js | 13 - .../extractTextPlugin.test.ts | 10 - .../loaderOptionsPlugin.test.ts.snap | 59 --- .../loaderOptionsPlugin-0.input.js | 6 - .../loaderOptionsPlugin-1.input.js | 9 - .../loaderOptionsPlugin-2.input.js | 9 - .../loaderOptionsPlugin-3.input.js | 17 - .../loaderOptionsPlugin.test.ts | 12 - .../__snapshots__/loaders.test.ts.snap | 289 -------------- .../__testfixtures__/loaders-0.input.js | 94 ----- .../__testfixtures__/loaders-1.input.js | 10 - .../__testfixtures__/loaders-2.input.js | 20 - .../__testfixtures__/loaders-3.input.js | 10 - .../__testfixtures__/loaders-4.input.js | 10 - .../__testfixtures__/loaders-5.input.js | 17 - .../__testfixtures__/loaders-6.input.js | 16 - .../__testfixtures__/loaders-7.input.js | 14 - .../__testfixtures__/loaders-8.input.js | 11 - .../__testfixtures__/loaders-9.input.js | 14 - .../migrate/__tests__/loaders/loaders.test.ts | 18 - packages/migrate/__tests__/migrate.test.ts | 63 ---- .../moduleConcatenationPlugin.test.ts.snap | 31 -- .../moduleConcatenationPlugin-0.input.js | 3 - .../moduleConcatenationPlugin-1.input.js | 6 - .../moduleConcatenationPlugin-2.input.js | 6 - .../moduleConcatenationPlugin.test.ts | 12 - .../namedModulesPlugin.test.ts.snap | 31 -- .../namedModulesPlugin-0.input.js | 5 - .../namedModulesPlugin-1.input.js | 9 - .../namedModulesPlugin-2.input.js | 9 - .../namedModulesPlugin.test.ts | 12 - .../noEmitOnErrorsPlugin.test.ts.snap | 31 -- .../noEmitOnErrorsPlugin-0.input.js | 3 - .../noEmitOnErrorsPlugin-1.input.js | 6 - .../noEmitOnErrorsPlugin-2.input.js | 6 - .../noEmitOnErrorsPlugin.test.ts | 12 - .../__snapshots__/outputPath.test.ts.snap | 28 -- .../__testfixtures__/outputPath-0.input.js | 5 - .../__testfixtures__/outputPath-1.input.js | 5 - .../__testfixtures__/outputPath-2.input.js | 5 - .../__tests__/outputPath/outputPath.test.ts | 12 - .../removeDeprecatedPlugins.test.ts.snap | 42 --- .../removeDeprecatedPlugins-0.input.js | 3 - .../removeDeprecatedPlugins-1.input.js | 3 - .../removeDeprecatedPlugins-2.input.js | 3 - .../removeDeprecatedPlugins-3.input.js | 8 - .../removeDeprecatedPlugins-4.input.js | 8 - .../removeDeprecatedPlugins.test.ts | 14 - .../removeJsonLoader.test.ts.snap | 53 --- .../removeJsonLoader-0.input.js | 20 - .../removeJsonLoader-1.input.js | 17 - .../removeJsonLoader-2.input.js | 10 - .../removeJsonLoader-3.input.js | 14 - .../removeJsonLoader/removeJsonLoader.test.ts | 13 - .../__snapshots__/resolve.test.ts.snap | 29 -- .../resolve/__testfixtures__/resolve.input.js | 25 -- .../migrate/__tests__/resolve/resolve.test.ts | 10 - .../__snapshots__/uglifyJsPlugin.test.ts.snap | 119 ------ .../uglifyJsPlugin-0.input.js | 7 - .../uglifyJsPlugin-1.input.js | 10 - .../uglifyJsPlugin-2.input.js | 10 - .../uglifyJsPlugin-3.input.js | 26 -- .../uglifyJsPlugin-4.input.js | 28 -- .../uglifyJsPlugin/uglifyJsPlugin.test.ts | 14 - packages/migrate/package.json | 34 -- .../migrate/src/bannerPlugin/bannerPlugin.ts | 28 -- .../commonsChunkPlugin/commonsChunkPlugin.ts | 235 ------------ .../extractTextPlugin/extractTextPlugin.ts | 56 --- packages/migrate/src/index.ts | 200 ---------- .../loaderOptionsPlugin.ts | 47 --- packages/migrate/src/loaders/loaders.ts | 354 ------------------ packages/migrate/src/migrate.ts | 123 ------ .../moduleConcatenationPlugin.ts | 24 -- .../namedModulesPlugin/namedModulesPlugin.ts | 24 -- .../noEmitOnErrorsPlugin.ts | 23 -- packages/migrate/src/outputPath/outputPath.ts | 64 ---- .../removeDeprecatedPlugins.ts | 46 --- .../src/removeJsonLoader/removeJsonLoader.ts | 73 ---- packages/migrate/src/resolve/resolve.ts | 74 ---- packages/migrate/src/types/NodePath.ts | 95 ----- .../src/uglifyJsPlugin/uglifyJsPlugin.ts | 98 ----- packages/migrate/tsconfig.json | 9 - test/help/help.test.js | 4 +- test/migrate/config/bad-webpack.config.js | 5 - test/migrate/config/migrate-config.test.js | 83 ---- test/migrate/config/webpack.config.js | 32 -- test/version/version.test.js | 12 - tsconfig.json | 8 + 115 files changed, 12 insertions(+), 4264 deletions(-) delete mode 100644 MIGRATE.md delete mode 100644 packages/migrate/CHANGELOG.md delete mode 100644 packages/migrate/README.md delete mode 100644 packages/migrate/__testfixtures__/failing.js delete mode 100644 packages/migrate/__tests__/__snapshots__/migrate.test.ts.snap delete mode 100644 packages/migrate/__tests__/bannerPlugin/__snapshots__/bannerPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/bannerPlugin/bannerPlugin.test.ts delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-3.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-4.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-5.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6a.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6b.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6c.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6d.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-7.input.js delete mode 100644 packages/migrate/__tests__/commonsChunkPlugin/commonsChunkPlugin.test.ts delete mode 100644 packages/migrate/__tests__/extractTextPlugin/__snapshots__/extractTextPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js delete mode 100644 packages/migrate/__tests__/extractTextPlugin/extractTextPlugin.test.ts delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js delete mode 100644 packages/migrate/__tests__/loaderOptionsPlugin/loaderOptionsPlugin.test.ts delete mode 100644 packages/migrate/__tests__/loaders/__snapshots__/loaders.test.ts.snap delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-0.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-1.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-2.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-3.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-4.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-5.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-6.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-7.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-8.input.js delete mode 100644 packages/migrate/__tests__/loaders/__testfixtures__/loaders-9.input.js delete mode 100644 packages/migrate/__tests__/loaders/loaders.test.ts delete mode 100644 packages/migrate/__tests__/migrate.test.ts delete mode 100644 packages/migrate/__tests__/moduleConcatenationPlugin/__snapshots__/moduleConcatenationPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/moduleConcatenationPlugin/moduleConcatenationPlugin.test.ts delete mode 100644 packages/migrate/__tests__/namedModulesPlugin/__snapshots__/namedModulesPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/namedModulesPlugin/namedModulesPlugin.test.ts delete mode 100644 packages/migrate/__tests__/noEmitOnErrorsPlugin/__snapshots__/noEmitOnErrorsPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.test.ts delete mode 100644 packages/migrate/__tests__/outputPath/__snapshots__/outputPath.test.ts.snap delete mode 100644 packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-0.input.js delete mode 100644 packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-1.input.js delete mode 100644 packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-2.input.js delete mode 100644 packages/migrate/__tests__/outputPath/outputPath.test.ts delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.ts.snap delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js delete mode 100644 packages/migrate/__tests__/removeDeprecatedPlugins/removeDeprecatedPlugins.test.ts delete mode 100644 packages/migrate/__tests__/removeJsonLoader/__snapshots__/removeJsonLoader.test.ts.snap delete mode 100644 packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js delete mode 100644 packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js delete mode 100644 packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js delete mode 100644 packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js delete mode 100644 packages/migrate/__tests__/removeJsonLoader/removeJsonLoader.test.ts delete mode 100644 packages/migrate/__tests__/resolve/__snapshots__/resolve.test.ts.snap delete mode 100644 packages/migrate/__tests__/resolve/__testfixtures__/resolve.input.js delete mode 100644 packages/migrate/__tests__/resolve/resolve.test.ts delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.ts.snap delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-3.input.js delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-4.input.js delete mode 100644 packages/migrate/__tests__/uglifyJsPlugin/uglifyJsPlugin.test.ts delete mode 100644 packages/migrate/package.json delete mode 100644 packages/migrate/src/bannerPlugin/bannerPlugin.ts delete mode 100644 packages/migrate/src/commonsChunkPlugin/commonsChunkPlugin.ts delete mode 100644 packages/migrate/src/extractTextPlugin/extractTextPlugin.ts delete mode 100644 packages/migrate/src/index.ts delete mode 100644 packages/migrate/src/loaderOptionsPlugin/loaderOptionsPlugin.ts delete mode 100644 packages/migrate/src/loaders/loaders.ts delete mode 100644 packages/migrate/src/migrate.ts delete mode 100644 packages/migrate/src/moduleConcatenationPlugin/moduleConcatenationPlugin.ts delete mode 100644 packages/migrate/src/namedModulesPlugin/namedModulesPlugin.ts delete mode 100644 packages/migrate/src/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.ts delete mode 100644 packages/migrate/src/outputPath/outputPath.ts delete mode 100644 packages/migrate/src/removeDeprecatedPlugins/removeDeprecatedPlugins.ts delete mode 100644 packages/migrate/src/removeJsonLoader/removeJsonLoader.ts delete mode 100644 packages/migrate/src/resolve/resolve.ts delete mode 100644 packages/migrate/src/types/NodePath.ts delete mode 100644 packages/migrate/src/uglifyJsPlugin/uglifyJsPlugin.ts delete mode 100644 packages/migrate/tsconfig.json delete mode 100644 test/migrate/config/bad-webpack.config.js delete mode 100644 test/migrate/config/migrate-config.test.js delete mode 100644 test/migrate/config/webpack.config.js diff --git a/.cz-config.js b/.cz-config.js index 36c25512e7c..11703d0b2a1 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -18,7 +18,7 @@ module.exports = { scopes: [], // sort type values in asc types: [ - { value: 'ast', name: 'ast: init, migrate, add, etc' }, + { value: 'ast', name: 'ast: init, add, etc' }, { value: 'break', name: 'break: Changes that break the behaviour of the cli' }, { value: 'chore', name: 'chore: Updating deps, docs, linting, etc' }, { value: 'cli', name: 'cli: Core CLI things' }, diff --git a/MIGRATE.md b/MIGRATE.md deleted file mode 100644 index 150418dfc62..00000000000 --- a/MIGRATE.md +++ /dev/null @@ -1,207 +0,0 @@ -# webpack-cli migrate - -The `webpack-cli migrate` feature eases the transition from: - -- `version 1` to `version 2` -- `version 2` to `version 4` - -`webpack-cli migrate` also allows users to switch to the new version of webpack without having to do it extensively. - -## Table of Contents - -- [Installation](#installation) - - [Local Setup](#local-setup) - - [Global Setup](#global-setup) -- [Usage](#usage) - - [Local Setup](#local-setup) - - [Global Setup](#global-setup) - - [Usage Example](#usage-example) -- [Changes reflected after migration](#changes-reflected-after-migration) - -## Installation - -> Requires installation of `webpack` and `webpack-cli` - -### A. Local Setup - -```shell -$ npm install --save-dev @webpack-cli/migrate -``` - -### B. Global Setup - -```shell -$ npm install -g @webpack-cli/migrate -``` - -## Usage - -To use `webpack-cli migrate`, run the following command, with the value of `` being a path to an existing webpack configuration file. `` can be `webpack.config.js` , `webpack.prod.js` or any webpack configuration. - -### A. Local Setup - -```bash -$ npx webpack-cli migrate -``` - -### B. Global Setup - -```bash -$ webpack-cli migrate -``` - -### Usage Example - -Given a basic configuration file like so: - -```javascript -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const path = require('path'); -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); -const webpack = require('webpack'); - -module.exports = { - entry: { - index: './src/index.js', - vendor: './src/vendor.js', - }, - - output: { - filename: '[name].[chunkhash].js', - chunkFilename: '[name].[chunkhash].js', - path: path.resolve(__dirname, 'dist'), - }, - - module: { - loaders: [ - { - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel', - query: { - presets: ['@babel/preset-env'], - }, - }, - { - test: /\.(scss|css)$/, - loader: ExtractTextPlugin.extract('style', 'css!sass'), - }, - ], - }, - - plugins: [ - new UglifyJSPlugin(), - - new ExtractTextPlugin('styles-[contentHash].css'), - - new webpack.optimize.CommonsChunkPlugin({ - name: 'common', - filename: 'common-[hash].min.js', - }), - - new HtmlWebpackPlugin(), - ], -}; -``` - -The `migrate` command, when run, will show the proposed changes to the config file in the terminal, prompting the user to -accept the changes or not: - -```diff -$ webpack-cli migrate ./webpack.config.js - ✔ Reading webpack config - ✔ Migrating config from v1 to v2 -- loaders: [ -+ rules: [ -- loader: 'babel', -- query: { -+ use: [{ -+ loader: 'babel-loader' -+ }], -+ options: { -- loader: ExtractTextPlugin.extract('style', 'css!sass') -+ use: ExtractTextPlugin.extract({ -+ fallback: 'style', -+ use: 'css!sass' -+ }) -? Are you sure these changes are fine? Yes - - ✔︎ New webpack v2 config file is at /Users/obuckley/Workspace/github/repos/webpack-migrate-sandbox/webpack.config.js -``` - -After it has run, we have our new webpack config file! - -```javascript -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const path = require('path'); -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); -const webpack = require('webpack'); - -module.exports = { - entry: { - index: './src/index.js', - vendor: './src/vendor.js', - }, - - output: { - filename: '[name].[chunkhash].js', - chunkFilename: '[name].[chunkhash].js', - path: path.resolve(__dirname, 'dist'), - }, - - module: { - rules: [ - { - test: /\.js$/, - exclude: /node_modules/, - use: [ - { - loader: 'babel-loader', - }, - ], - options: { - presets: ['@babel/preset-env'], - }, - }, - { - test: /\.(scss|css)$/, - use: ExtractTextPlugin.extract({ - fallback: 'style', - use: 'css!sass', - }), - }, - ], - }, - - plugins: [ - new UglifyJSPlugin(), - - new ExtractTextPlugin('styles-[contentHash].css'), - - new webpack.optimize.CommonsChunkPlugin({ - name: 'common', - filename: 'common-[hash].min.js', - }), - - new HtmlWebpackPlugin(), - ], -}; -``` - -## Changes reflected after migration - -We can see the following changes after migration: - -1. The webpack schema for using loaders has changed - - `loaders` is now `module.rules` - - `query` is now `options` -2. All loaders now have to have the _loader_ suffix, e.g. `babel` -> `babel-loader` -3. `NamedModulesPlugin` migrated to `optimizations.namedModules` -4. `NoEmitOnErrorsPlugin` migrated to `optimizations.noEmitOnErrors` -5. `ModuleConcatenationPlugin` migrated to `optimizations.concatenateModules` - ---- - -**Note: This command does NOT handle updating dependencies in _package.json_, it is only a migration tool for the config file itself. Users are expected to manage dependencies themselves.** diff --git a/README.md b/README.md index f4b7691cbca..bdf33ce0f0f 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Thus, webpack CLI provides different commands for many common tasks. - [`webpack-cli init`](./packages/init/README.md#webpack-cli-init) - Create a new webpack configuration. - [`webpack-cli info`](./packages/info/README.md#webpack-cli-info) - Returns information related to the local environment. -- [`webpack-cli migrate`](./packages/migrate/README.md#webpack-cli-migrate) - Migrate project from one version to another. +- [`webpack-cli migrate`](https://www.npmjs.com/package/@webpack-cli/migrate) - Migrate project from one version to another. - [`webpack-cli plugin`](./packages/generators#generators) - Initiate new plugin project. - [`webpack-cli loader`](./packages/generators#generators) - Initiate new loader project. - [`webpack-cli serve`](./packages/serve/README.md#webpack-cli-serve) - Use webpack with a development server that provides live reloading. diff --git a/packages/README.md b/packages/README.md index 450fcb1b56e..2791329cf10 100644 --- a/packages/README.md +++ b/packages/README.md @@ -16,7 +16,7 @@ This folder is the collection of those packages. 1. [generators](https://github.com/webpack/webpack-cli/tree/master/packages/generators) 2. [info](https://github.com/webpack/webpack-cli/tree/master/packages/info) 3. [init](https://github.com/webpack/webpack-cli/tree/master/packages/init) -4. [migrate](https://github.com/webpack/webpack-cli/tree/master/packages/migrate) +4. [migrate](https://www.npmjs.com/package/@webpack-cli/migrate) 5. [serve](https://github.com/webpack/webpack-cli/tree/master/packages/serve) 6. [utils](https://github.com/webpack/webpack-cli/tree/master/packages/utils) 7. [webpack-cli](https://github.com/webpack/webpack-cli/tree/master/packages/webpack-cli) diff --git a/packages/migrate/CHANGELOG.md b/packages/migrate/CHANGELOG.md deleted file mode 100644 index 7415e2633a7..00000000000 --- a/packages/migrate/CHANGELOG.md +++ /dev/null @@ -1,57 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.1.2](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.1.1...@webpack-cli/migrate@1.1.2) (2020-12-31) - -### Bug Fixes - -- the `--help` option is working without `webpack-dev-server` ([#2267](https://github.com/webpack/webpack-cli/issues/2267)) ([1dae54d](https://github.com/webpack/webpack-cli/commit/1dae54da94d3220437b9257efe512447023de1d3)) - -## [1.1.1](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.1.0...@webpack-cli/migrate@1.1.1) (2020-12-25) - -**Note:** Version bump only for package @webpack-cli/migrate - -# [1.1.0](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.2...@webpack-cli/migrate@1.1.0) (2020-11-04) - -### Features - -- export utils from core for other packages ([#2011](https://github.com/webpack/webpack-cli/issues/2011)) ([3004549](https://github.com/webpack/webpack-cli/commit/3004549c06b3fe00708d8e1eecf42419e0f72f66)) - -## [1.0.2](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.1...@webpack-cli/migrate@1.0.2) (2020-10-19) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.1-rc.1...@webpack-cli/migrate@1.0.1) (2020-10-10) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1-rc.1](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.5...@webpack-cli/migrate@1.0.1-rc.1) (2020-10-06) - -### Bug Fixes - -- **packages:** make packages have correct main paths to index ([#1366](https://github.com/webpack/webpack-cli/issues/1366)) ([5dd7bd6](https://github.com/webpack/webpack-cli/commit/5dd7bd62046568481996e48328b15a335557f8ae)) -- regression with migrate command ([7ebcbb8](https://github.com/webpack/webpack-cli/commit/7ebcbb8030b9111df797abdd67e504178b18aeac)) - -## [1.0.1-alpha.5](https://github.com/ematipico/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.4...@webpack-cli/migrate@1.0.1-alpha.5) (2020-03-02) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1-alpha.4](https://github.com/ematipico/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.3...@webpack-cli/migrate@1.0.1-alpha.4) (2020-02-29) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1-alpha.3](https://github.com/ematipico/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.2...@webpack-cli/migrate@1.0.1-alpha.3) (2020-02-23) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1-alpha.2](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.1...@webpack-cli/migrate@1.0.1-alpha.2) (2020-02-23) - -**Note:** Version bump only for package @webpack-cli/migrate - -## [1.0.1-alpha.1](https://github.com/webpack/webpack-cli/compare/@webpack-cli/migrate@1.0.1-alpha.0...@webpack-cli/migrate@1.0.1-alpha.1) (2020-02-23) - -### Bug Fixes - -- **init:** fix webpack config scaffold ([#1231](https://github.com/webpack/webpack-cli/issues/1231)) ([2dc495a](https://github.com/webpack/webpack-cli/commit/2dc495a8d050d28478c6c2533d7839e9ff78d76c)), closes [#1230](https://github.com/webpack/webpack-cli/issues/1230) diff --git a/packages/migrate/README.md b/packages/migrate/README.md deleted file mode 100644 index 0919ec3db8f..00000000000 --- a/packages/migrate/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# webpack-cli migrate - -[![npm][downloads]][downloads-url] - -## Description - -This package contains the logic to migrate a project from one version to the other. - -## Installation - -```bash -npm i -D webpack-cli @webpack-cli/migrate -``` - -## Usage - -To run the package programmatically, install it as a dependency. When using the package programmatically, one does not have to install webpack-cli. - -### Node - -```js -const migrate = require('@webpack-cli/migrate').default; - -// add null to mock process.env -migrate(null, null, inputPath, outputPath); -``` - -### CLI (via `webpack-cli`) - -```bash -npx webpack-cli migrate -``` - -[downloads]: https://img.shields.io/npm/dm/@webpack-cli/migrate.svg -[downloads-url]: https://www.npmjs.com/package/@webpack-cli/migrate diff --git a/packages/migrate/__testfixtures__/failing.js b/packages/migrate/__testfixtures__/failing.js deleted file mode 100644 index aed54036dea..00000000000 --- a/packages/migrate/__testfixtures__/failing.js +++ /dev/null @@ -1,79 +0,0 @@ -const webpack = require('webpack'); -const nodeEnvironment = process.env.NODE_ENV; - -const config = { - entry: { - lib: "./app/index.js", - email: "./app/email.js" - }, - plugins: [ - new webpack.DefinePlugin({ - INCLUDE_ALL_MODULES: function includeAllModulesGlobalFn(modulesArray, application) { - modulesArray.forEach(function executeModuleIncludesFn(moduleFn) { - moduleFn(application); - }); - }, - ENVIRONMENT: JSON.stringify(nodeEnvironment) - }) - ], - output: { - path: __dirname + "/app", - filename: "bundle.js" - }, - resolve: { - root: __dirname + "/app" - }, - module: { - // preLoaders: [ - // { test: /\.js?$/, loader: 'eslint', exclude: /node_modules/ } - // ], - loaders: [ - { test: /\.js$/, exclude: /(node_modules)/, loader: "babel" }, - { test: /\.html/, exclude: [/(node_modules)/, /src\/index\.html/], loader: "html-loader" }, - { test: /\.s?css$/, loader: "style!css!sass" }, - { test: /\.(png|jpg)$/, loader: "url-loader?mimetype=image/png" } - ] - }, - // extra configuration options. - // eslint: { - // configFile: '.eslintrc.js' - // } -}; - -switch (nodeEnvironment) { - case "production": - config.plugins.push(new webpack.optimize.UglifyJsPlugin()); - case "preproduction": - config.output.path = __dirname + "/dist"; - config.plugins.push(new webpack.optimize.DedupePlugin()); - config.plugins.push(new webpack.optimize.OccurenceOrderPlugin()); - - config.output.filename = "[name].js"; - - config.entry = { - lib: ["./app/index.js", "angular", "lodash"], - email: ["./app/email.js", "angular"] - }; - - config.devtool = "source-map"; - config.output.libraryTarget = "commonjs2"; - break; - - case "test": - config.entry = "./index.js"; - break; - - case "development": - config.entry = { - lib: ["./app/index.js", "webpack/hot/dev-server"], - email: ["./app/email.js", "webpack/hot/dev-server"] - }; - config.output.filename = "[name].js"; - config.devtool = "source-map"; - break; - - default: - console.warn("Unknown or Undefined Node Environment. Please refer to package.json for available build commands."); -} - -module.exports = config; diff --git a/packages/migrate/__tests__/__snapshots__/migrate.test.ts.snap b/packages/migrate/__tests__/__snapshots__/migrate.test.ts.snap deleted file mode 100644 index 7da8c9cc8a4..00000000000 --- a/packages/migrate/__tests__/__snapshots__/migrate.test.ts.snap +++ /dev/null @@ -1,158 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`transform should not transform if no transformations defined: -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; - 1`] = ` -" -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; -" -`; - -exports[`transform should respect recast options 1`] = ` -" -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - rules: [{ - test: /.js$/, - use: [{ - loader: \\"babel-loader\\", - }], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')], - }, - plugins: [new webpack.LoaderOptionsPlugin({ - debug: true, - })], - optimization: { - minimize: true, - } -}; -" -`; - -exports[`transform should transform only using specified transformations 1`] = ` -" -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - rules: [{ - test: /.js$/, - use: [{ - loader: 'babel-loader' - }], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; -" -`; - -exports[`transform should transform using all transformations 1`] = ` -" -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - rules: [{ - test: /.js$/, - use: [{ - loader: 'babel-loader' - }], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')] - }, - plugins: [new webpack.LoaderOptionsPlugin({ - debug: true - })], - optimization: { - minimize: true - } -}; -" -`; diff --git a/packages/migrate/__tests__/bannerPlugin/__snapshots__/bannerPlugin.test.ts.snap b/packages/migrate/__tests__/bannerPlugin/__snapshots__/bannerPlugin.test.ts.snap deleted file mode 100644 index 30d5fa15421..00000000000 --- a/packages/migrate/__tests__/bannerPlugin/__snapshots__/bannerPlugin.test.ts.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`banner plugin bannerPlugin transforms correctly using "bannerPlugin-0" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.BannerPlugin({ - raw: true, - entryOnly: true, - banner: 'Banner' - }) - ] -} -" -`; - -exports[`banner plugin bannerPlugin transforms correctly using "bannerPlugin-1" data 1`] = ` -"// Should do nothing if there is no banner plugin -module.exports = { - plugins: [] -} -" -`; - -exports[`banner plugin bannerPlugin transforms correctly using "bannerPlugin-2" data 1`] = ` -"// Only transform if it uses the old format -module.exports = { - plugins: [ - new webpack.BannerPlugin({}) - ] -} -" -`; diff --git a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js b/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js deleted file mode 100644 index 56c89e72d84..00000000000 --- a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - plugins: [ - new webpack.BannerPlugin('Banner', { raw: true, entryOnly: true }) - ] -} diff --git a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js b/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js deleted file mode 100644 index 0d66b9de1ac..00000000000 --- a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js +++ /dev/null @@ -1,4 +0,0 @@ -// Should do nothing if there is no banner plugin -module.exports = { - plugins: [] -} diff --git a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js b/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js deleted file mode 100644 index 90ecde8f0de..00000000000 --- a/packages/migrate/__tests__/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Only transform if it uses the old format -module.exports = { - plugins: [ - new webpack.BannerPlugin({}) - ] -} diff --git a/packages/migrate/__tests__/bannerPlugin/bannerPlugin.test.ts b/packages/migrate/__tests__/bannerPlugin/bannerPlugin.test.ts deleted file mode 100644 index b29851c5280..00000000000 --- a/packages/migrate/__tests__/bannerPlugin/bannerPlugin.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('banner plugin', function () { - { - defineTest(dirName, 'bannerPlugin', 'bannerPlugin-0'); - defineTest(dirName, 'bannerPlugin', 'bannerPlugin-1'); - defineTest(dirName, 'bannerPlugin', 'bannerPlugin-2'); - } -}); diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.ts.snap b/packages/migrate/__tests__/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.ts.snap deleted file mode 100644 index 593db1cc8cd..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.ts.snap +++ /dev/null @@ -1,302 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-0" data 1`] = ` -"module.exports = { - entry: { - app: './src/app.js', - vendor: './src/vendors.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - app: { - name: 'app', - chunks: 'initial', - enforce: true, - test: 'app' - }, - - vendor: { - name: 'vendor', - chunks: 'initial', - enforce: true, - test: 'vendor' - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-1" data 1`] = ` -"module.exports = { - entry: { - vendor: './src/vendors.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - common: { - name: 'common', - chunks: 'initial', - enforce: true - }, - - vendor: { - name: 'vendor', - chunks: 'initial', - enforce: true, - test: 'vendor' - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-2" data 1`] = ` -"module.exports = { - entry: { - vendor: './src/vendors.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'initial', - enforce: true, - test: 'vendor' - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-3" data 1`] = ` -"module.exports = { - optimizations: { - splitChunks: { - cacheGroups: { - commons: { - name: 'commons', - chunks: 'initial', - enforce: true, - filename: 'commons.js' - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-4" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - enforce: true, - test: 'main', - chunks: 'async', - minSize: 2000 - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - test: 'main' - } - } - }, - - runtimeChunk: { - name: 'runtime' - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6a" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - - test: module => { - if (module.getChunks().some(chunk => chunk.name === 'main')) - return true; - - const fn = ({ resource }) => /node_modules/.test(resource); - return fn(module); - } - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6b" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - - test: module => { - if (module.getChunks().some(chunk => chunk.name === 'main')) - return true; - - const fn = ({ resource }) => { - // some code - return /node_modules/.test(resource); - }; - - return fn(module); - } - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6c" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - - test: module => { - if (module.getChunks().some(chunk => chunk.name === 'main')) - return true; - - const fn = function ({ resource }) { - // some code - return /node_modules/.test(resource); - }; - - return fn(module); - } - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6d" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - - test: module => { - if (module.getChunks().some(chunk => chunk.name === 'main')) - return true; - - const fn = function ({ resource }) { - if (foo) { - return /node_modulesfoo/.test(resource); - } else { - return /node_modulesbaz/.test(resource); - } - }; - - return fn(module); - } - } - } - } - } -} -" -`; - -exports[`commons chunk plugin commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" data 1`] = ` -"module.exports = { - entry: { - main: './src/index.js', - }, - - optimizations: { - splitChunks: { - cacheGroups: { - main: { - name: 'main', - chunks: 'initial', - enforce: true, - test: 'main', - minSize: 3000 - } - } - } - } -} -" -`; diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-0.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-0.input.js deleted file mode 100644 index 5174a051ee1..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-0.input.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - entry: { - app: './src/app.js', - vendor: './src/vendors.js', - }, - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - names: ["app", "vendor"], - minChunks: 2 - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-1.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-1.input.js deleted file mode 100644 index 278b2581639..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-1.input.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - entry: { - vendor: './src/vendors.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - names: ["common", "vendor"] - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-2.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-2.input.js deleted file mode 100644 index 83a4fb6d3c5..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-2.input.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - entry: { - vendor: './src/vendors.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - names: ["vendor"] - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-3.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-3.input.js deleted file mode 100644 index 0c4289d6290..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-3.input.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "commons", - filename: "commons.js", - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-4.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-4.input.js deleted file mode 100644 index 973867a9866..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-4.input.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - async: true, - minSize: 2000, - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-5.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-5.input.js deleted file mode 100644 index c7b2dc1c53d..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-5.input.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - names: ["main", "runtime"], - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6a.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6a.input.js deleted file mode 100644 index 641965277fa..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6a.input.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - minChunks: ({ resource }) => /node_modules/.test(resource), - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6b.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6b.input.js deleted file mode 100644 index fd48b62e34c..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6b.input.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - minChunks: ({ resource }) => { - // some code - return /node_modules/.test(resource); - }, - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6c.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6c.input.js deleted file mode 100644 index 9fe78cbc0fa..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6c.input.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - minChunks: function ({ resource }) { - // some code - return /node_modules/.test(resource); - }, - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6d.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6d.input.js deleted file mode 100644 index bab003418a4..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-6d.input.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - minChunks: function ({ resource }) { - if (foo) { - return /node_modulesfoo/.test(resource); - } else { - return /node_modulesbaz/.test(resource); - } - } - }) - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-7.input.js b/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-7.input.js deleted file mode 100644 index 9999d11bd64..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/__testfixtures__/commonsChunkPlugin-7.input.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - entry: { - main: './src/index.js', - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({ - name: "main", - minSize: 3000, - }), - ] -} diff --git a/packages/migrate/__tests__/commonsChunkPlugin/commonsChunkPlugin.test.ts b/packages/migrate/__tests__/commonsChunkPlugin/commonsChunkPlugin.test.ts deleted file mode 100644 index 3e97a576042..00000000000 --- a/packages/migrate/__tests__/commonsChunkPlugin/commonsChunkPlugin.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; -const dirName: string = join(__dirname); - -describe('commons chunk plugin', function () { - { - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-0'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-1'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-2'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-3'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-4'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-5'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-6a'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-6b'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-6c'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-6d'); - defineTest(dirName, 'commonsChunkPlugin', 'commonsChunkPlugin-7'); - } -}); diff --git a/packages/migrate/__tests__/extractTextPlugin/__snapshots__/extractTextPlugin.test.ts.snap b/packages/migrate/__tests__/extractTextPlugin/__snapshots__/extractTextPlugin.test.ts.snap deleted file mode 100644 index 4e2ee40db6c..00000000000 --- a/packages/migrate/__tests__/extractTextPlugin/__snapshots__/extractTextPlugin.test.ts.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`extractTextPlugin extractTextPlugin transforms correctly 1`] = ` -"const ExtractTextPlugin = require(\\"extract-text-webpack-plugin\\"); - -module.exports = { - module: { - rules: [ - { - test: /\\\\.css$/, - use: ExtractTextPlugin.extract({ - fallback: 'style-loader', - use: 'css-loader' - }) - } - ] - }, - plugins: [new ExtractTextPlugin(\\"styles.css\\")] -}; -" -`; diff --git a/packages/migrate/__tests__/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js b/packages/migrate/__tests__/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js deleted file mode 100644 index 07d46e38cc0..00000000000 --- a/packages/migrate/__tests__/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js +++ /dev/null @@ -1,13 +0,0 @@ -const ExtractTextPlugin = require("extract-text-webpack-plugin"); - -module.exports = { - module: { - rules: [ - { - test: /\.css$/, - use: ExtractTextPlugin.extract("style-loader", "css-loader") - } - ] - }, - plugins: [new ExtractTextPlugin("styles.css")] -}; diff --git a/packages/migrate/__tests__/extractTextPlugin/extractTextPlugin.test.ts b/packages/migrate/__tests__/extractTextPlugin/extractTextPlugin.test.ts deleted file mode 100644 index 71d9f3d2e14..00000000000 --- a/packages/migrate/__tests__/extractTextPlugin/extractTextPlugin.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('extractTextPlugin', function () { - { - defineTest(dirName, 'extractTextPlugin'); - } -}); diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.ts.snap b/packages/migrate/__tests__/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.ts.snap deleted file mode 100644 index 6d0877f5f11..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.ts.snap +++ /dev/null @@ -1,59 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaderOptionsPlugin loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-0" data 1`] = ` -"// Do not create LoaderOptionsPlugin is not necessary -module.exports = { - plugins: [ - new SomePlugin() - ] -} -" -`; - -exports[`loaderOptionsPlugin loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-1" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.LoaderOptionsPlugin({ - foo: 'bar', - debug: true, - minimize: true - }) - ] -} -" -`; - -exports[`loaderOptionsPlugin loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-2" data 1`] = ` -"// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} -" -`; - -exports[`loaderOptionsPlugin loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-3" data 1`] = ` -"// Don't modify LoaderOptionsPlugin - -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -module.exports = { - entry: ['./index.js'], - output: { - filename: 'bundle.js' - }, - module: { - rules: [{ - test: /\\\\.css$/, - use: ExtractTextPlugin.extract([ - 'css-loader' - ]) - }] - }, -} -" -`; diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js b/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js deleted file mode 100644 index e809d6a36a9..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Do not create LoaderOptionsPlugin is not necessary -module.exports = { - plugins: [ - new SomePlugin() - ] -} diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js b/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js deleted file mode 100644 index 3b8ac854d12..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - debug: true, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js b/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js deleted file mode 100644 index eea1c515164..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js +++ /dev/null @@ -1,9 +0,0 @@ -// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js b/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js deleted file mode 100644 index 2a3baa56d23..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js +++ /dev/null @@ -1,17 +0,0 @@ -// Don't modify LoaderOptionsPlugin - -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -module.exports = { - entry: ['./index.js'], - output: { - filename: 'bundle.js' - }, - module: { - rules: [{ - test: /\.css$/, - use: ExtractTextPlugin.extract([ - 'css-loader' - ]) - }] - }, -} diff --git a/packages/migrate/__tests__/loaderOptionsPlugin/loaderOptionsPlugin.test.ts b/packages/migrate/__tests__/loaderOptionsPlugin/loaderOptionsPlugin.test.ts deleted file mode 100644 index 0d16e54022b..00000000000 --- a/packages/migrate/__tests__/loaderOptionsPlugin/loaderOptionsPlugin.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); -describe('loaderOptionsPlugin', function () { - { - defineTest(dirName, 'loaderOptionsPlugin', 'loaderOptionsPlugin-0'); - defineTest(dirName, 'loaderOptionsPlugin', 'loaderOptionsPlugin-1'); - defineTest(dirName, 'loaderOptionsPlugin', 'loaderOptionsPlugin-2'); - defineTest(dirName, 'loaderOptionsPlugin', 'loaderOptionsPlugin-3'); - } -}); diff --git a/packages/migrate/__tests__/loaders/__snapshots__/loaders.test.ts.snap b/packages/migrate/__tests__/loaders/__snapshots__/loaders.test.ts.snap deleted file mode 100644 index 5fb72ae39e0..00000000000 --- a/packages/migrate/__tests__/loaders/__snapshots__/loaders.test.ts.snap +++ /dev/null @@ -1,289 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaders loaders transforms correctly using "loaders-0" data 1`] = ` -"module.exports = [ - { - module: { - rules: [ - { - use: [{ - loader: 'babel-loader' - }], - test: /\\\\.js$/, - }, - ], - }, - }, - { - module: { - rules: [ - { - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - - options: { - modules: true, - importLoaders: 1, - string: 'test123' - } - }], - test: /\\\\.css$/, - }, - ], - }, - }, - { - module: { - rules: [ - { - use: [{ - loader: 'style-loader', - }, { - loader: 'css-loader', - options: { - modules: true, - }, - }], - test: /\\\\.css$/, - }, - ], - }, - }, - { - module: { - rules: [ - { - use: [{ - loader: 'eslint-loader' - }], - - test: /\\\\.js$/, - enforce: 'pre' - }, - ], - }, - }, - { - module: { - rules: [ - { - use: [{ - loader: 'my-post-loader' - }], - - test: /\\\\.js$/, - enforce: 'post' - }, - ], - }, - }, - { - module: { - rules: [{ - use: [{ - loader: 'babel-loader' - }], - test: /\\\\.js$/, - }, { - use: [{ - loader: 'eslint-loader' - }], - - test: /\\\\.js$/, - enforce: 'pre' - }] - }, - }, - { - module: { - rules: [{ - use: [{ - loader: 'babel-loader' - }], - test: /\\\\.js$/, - }, { - use: [{ - loader: 'my-post-loader' - }], - - test: /\\\\.js$/, - enforce: 'post' - }] - }, - }, -]; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-1" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - - options: { - modules: true, - importLoaders: 1, - string: 'test123' - } - }], - test: /\\\\.css$/, - }, - ], - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-2" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - use: [{ - loader: 'style-loader', - }, { - loader: 'css-loader', - options: { - modules: true, - }, - }], - test: /\\\\.css$/, - }, - ], - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-3" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - use: [{ - loader: 'eslint-loader' - }], - - test: /\\\\.js$/, - enforce: 'pre' - }, - ], - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-4" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - use: [{ - loader: 'my-post-loader' - }], - - test: /\\\\.js$/, - enforce: 'post' - }, - ], - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-5" data 1`] = ` -"module.exports = { - module: { - rules: [{ - use: [{ - loader: 'babel-loader' - }], - test: /\\\\.js$/, - }, { - use: [{ - loader: 'eslint-loader' - }], - - test: /\\\\.js$/, - enforce: 'pre' - }] - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-6" data 1`] = ` -"module.exports = { - module: { - rules: [{ - use: [{ - loader: 'babel-loader' - }], - test: /\\\\.js$/, - }, { - use: [{ - loader: 'my-post-loader' - }], - - test: /\\\\.js$/, - enforce: 'post' - }] - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-7" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - exclude: /(node_modules)/, - - use: [{ - loader: 'babel-loader', - - options: { - presets: [\\"@babel/preset-env\\"], - } - }], - - test: /\\\\.js$/ - }, - ], - }, -}; -" -`; - -exports[`loaders loaders transforms correctly using "loaders-8" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - include: path.join(__dirname, \\"src\\"), - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - - options: { - modules: true, - importLoaders: 1, - string: 'test123' - } - }], - test: /\\\\.js$/ - } - ] - } -}; -" -`; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-0.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-0.input.js deleted file mode 100644 index e58bb6f88ef..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-0.input.js +++ /dev/null @@ -1,94 +0,0 @@ -module.exports = [ - { - module: { - loaders: [ - { - loader: "babel", - test: /\.js$/, - }, - ], - }, - }, - { - module: { - loaders: [ - { - loader: "style!css?modules&importLoaders=1&string=test123", - test: /\.css$/, - }, - ], - }, - }, - { - module: { - loaders: [ - { - loaders: [ - { - loader: "style", - }, - { - loader: "css", - query: { - modules: true, - }, - }, - ], - test: /\.css$/, - }, - ], - }, - }, - { - module: { - preLoaders: [ - { - loader: "eslint", - test: /\.js$/, - }, - ], - }, - }, - { - module: { - postLoaders: [ - { - loader: "my-post", - test: /\.js$/, - }, - ], - }, - }, - { - module: { - loaders: [ - { - loader: "babel-loader", - test: /\.js$/, - }, - ], - preLoaders: [ - { - loader: "eslint-loader", - test: /\.js$/, - }, - ], - }, - }, - { - module: { - loaders: [ - { - loader: "babel-loader", - test: /\.js$/, - }, - ], - postLoaders: [ - { - loader: "my-post-loader", - test: /\.js$/, - }, - ], - }, - }, -]; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-1.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-1.input.js deleted file mode 100644 index 0662abea05e..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-1.input.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - loader: "style!css?modules&importLoaders=1&string=test123", - test: /\.css$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-2.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-2.input.js deleted file mode 100644 index 388182d1d9e..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-2.input.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - loaders: [ - { - loader: "style", - }, - { - loader: "css", - query: { - modules: true, - }, - }, - ], - test: /\.css$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-3.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-3.input.js deleted file mode 100644 index cef7c100bb7..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-3.input.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - module: { - preLoaders: [ - { - loader: "eslint", - test: /\.js$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-4.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-4.input.js deleted file mode 100644 index 863f7acb499..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-4.input.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - module: { - postLoaders: [ - { - loader: "my-post", - test: /\.js$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-5.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-5.input.js deleted file mode 100644 index 63758597dcf..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-5.input.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - loader: "babel-loader", - test: /\.js$/, - }, - ], - - preLoaders: [ - { - loader: "eslint-loader", - test: /\.js$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-6.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-6.input.js deleted file mode 100644 index 405e508e2d7..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-6.input.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - loader: "babel-loader", - test: /\.js$/, - }, - ], - postLoaders: [ - { - loader: "my-post-loader", - test: /\.js$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-7.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-7.input.js deleted file mode 100644 index 40c46492632..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-7.input.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - exclude: /(node_modules)/, - loader: "babel-loader", - query: { - presets: ["@babel/preset-env"], - }, - test: /\.js$/, - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-8.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-8.input.js deleted file mode 100644 index 1be3161d4b7..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-8.input.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - include: path.join(__dirname, "src"), - loaders: ["style", "css?modules&importLoaders=1&string=test123"], - test: /\.js$/ - } - ] - } -}; diff --git a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-9.input.js b/packages/migrate/__tests__/loaders/__testfixtures__/loaders-9.input.js deleted file mode 100644 index d100038d9a6..00000000000 --- a/packages/migrate/__tests__/loaders/__testfixtures__/loaders-9.input.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - module: { - loaders: [ - { - loader: "url-loader", - options: { - limit: 10000, - name: "static/media/[name].[hash:8].[ext]", - }, - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], - }, - ], - }, -}; diff --git a/packages/migrate/__tests__/loaders/loaders.test.ts b/packages/migrate/__tests__/loaders/loaders.test.ts deleted file mode 100644 index ad94c6dcbea..00000000000 --- a/packages/migrate/__tests__/loaders/loaders.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('loaders', function () { - { - defineTest(dirName, 'loaders', 'loaders-0'); - defineTest(dirName, 'loaders', 'loaders-1'); - defineTest(dirName, 'loaders', 'loaders-2'); - defineTest(dirName, 'loaders', 'loaders-3'); - defineTest(dirName, 'loaders', 'loaders-4'); - defineTest(dirName, 'loaders', 'loaders-5'); - defineTest(dirName, 'loaders', 'loaders-6'); - defineTest(dirName, 'loaders', 'loaders-7'); - defineTest(dirName, 'loaders', 'loaders-8'); - } -}); diff --git a/packages/migrate/__tests__/migrate.test.ts b/packages/migrate/__tests__/migrate.test.ts deleted file mode 100644 index 4ac4c12bd64..00000000000 --- a/packages/migrate/__tests__/migrate.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { transform, transformations } from '../src/migrate'; - -const input = ` -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; -`; - -describe('transform', () => { - it('should not transform if no transformations defined', (done) => { - transform(input, []).then((output) => { - expect(output).toMatchSnapshot(input); - done(); - }); - }); - - it('should transform using all transformations', (done) => { - transform(input).then((output) => { - expect(output).toMatchSnapshot(); - done(); - }); - }); - - it('should transform only using specified transformations', (done) => { - transform(input, [transformations.loadersTransform]).then((output) => { - expect(output).toMatchSnapshot(); - done(); - }); - }); - - it('should respect recast options', (done) => { - transform(input, undefined, { - quote: 'double', - trailingComma: true, - }).then((output) => { - expect(output).toMatchSnapshot(); - done(); - }); - }); -}); diff --git a/packages/migrate/__tests__/moduleConcatenationPlugin/__snapshots__/moduleConcatenationPlugin.test.ts.snap b/packages/migrate/__tests__/moduleConcatenationPlugin/__snapshots__/moduleConcatenationPlugin.test.ts.snap deleted file mode 100644 index 76320d16f65..00000000000 --- a/packages/migrate/__tests__/moduleConcatenationPlugin/__snapshots__/moduleConcatenationPlugin.test.ts.snap +++ /dev/null @@ -1,31 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`moduleConcatenationPlugin moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-0" data 1`] = ` -"module.exports = { - optimizations: { - concatenateModules: true - } -}; -" -`; - -exports[`moduleConcatenationPlugin moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-1" data 1`] = ` -"module.exports = { - optimizations: { - splitChunks: false, - concatenateModules: true - }, - plugins: [new Foo()] -}; -" -`; - -exports[`moduleConcatenationPlugin moduleConcatenationPlugin transforms correctly using "moduleConcatenationPlugin-2" data 1`] = ` -"module.exports = { - optimizations: { - concatenateModules: true - }, - plugins: [new Foo()] -}; -" -`; diff --git a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-0.input.js b/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-0.input.js deleted file mode 100644 index cd8dd6c0e65..00000000000 --- a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-0.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: [new webpack.optimize.ModuleConcatenationPlugin()] -}; diff --git a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-1.input.js b/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-1.input.js deleted file mode 100644 index 4681fe01cb8..00000000000 --- a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - optimizations: { - splitChunks: false - }, - plugins: [new Foo(), new webpack.optimize.ModuleConcatenationPlugin()] -}; diff --git a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-2.input.js b/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-2.input.js deleted file mode 100644 index 1cae8402ad0..00000000000 --- a/packages/migrate/__tests__/moduleConcatenationPlugin/__testfixtures__/moduleConcatenationPlugin-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - optimizations: { - concatenateModules: false - }, - plugins: [new Foo(), new webpack.optimize.ModuleConcatenationPlugin()] -}; diff --git a/packages/migrate/__tests__/moduleConcatenationPlugin/moduleConcatenationPlugin.test.ts b/packages/migrate/__tests__/moduleConcatenationPlugin/moduleConcatenationPlugin.test.ts deleted file mode 100644 index 39d4aff5197..00000000000 --- a/packages/migrate/__tests__/moduleConcatenationPlugin/moduleConcatenationPlugin.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('moduleConcatenationPlugin', function () { - { - defineTest(dirName, 'moduleConcatenationPlugin', 'moduleConcatenationPlugin-0'); - defineTest(dirName, 'moduleConcatenationPlugin', 'moduleConcatenationPlugin-1'); - defineTest(dirName, 'moduleConcatenationPlugin', 'moduleConcatenationPlugin-2'); - } -}); diff --git a/packages/migrate/__tests__/namedModulesPlugin/__snapshots__/namedModulesPlugin.test.ts.snap b/packages/migrate/__tests__/namedModulesPlugin/__snapshots__/namedModulesPlugin.test.ts.snap deleted file mode 100644 index 5aea9ec1444..00000000000 --- a/packages/migrate/__tests__/namedModulesPlugin/__snapshots__/namedModulesPlugin.test.ts.snap +++ /dev/null @@ -1,31 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`namedModulesPlugin namedModulesPlugin transforms correctly using "namedModulesPlugin-0" data 1`] = ` -"module.export = { - optimizations: { - namedModules: true - } -} -" -`; - -exports[`namedModulesPlugin namedModulesPlugin transforms correctly using "namedModulesPlugin-1" data 1`] = ` -"module.export = { - optimizations: { - splitChunks: false, - namedModules: true - }, - plugins: [new Foo()] -} -" -`; - -exports[`namedModulesPlugin namedModulesPlugin transforms correctly using "namedModulesPlugin-2" data 1`] = ` -"module.export = { - optimizations: { - namedModules: true - }, - plugins: [new Foo()] -} -" -`; diff --git a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-0.input.js b/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-0.input.js deleted file mode 100644 index 0f1dc70d1a2..00000000000 --- a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.export = { - plugins: [ - new webpack.NamedModulesPlugin() - ] -} diff --git a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-1.input.js b/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-1.input.js deleted file mode 100644 index 834cb39181a..00000000000 --- a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-1.input.js +++ /dev/null @@ -1,9 +0,0 @@ -module.export = { - optimizations: { - splitChunks: false - }, - plugins: [ - new Foo(), - new webpack.NamedModulesPlugin() - ] -} diff --git a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-2.input.js b/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-2.input.js deleted file mode 100644 index d5f3facf0f4..00000000000 --- a/packages/migrate/__tests__/namedModulesPlugin/__testfixtures__/namedModulesPlugin-2.input.js +++ /dev/null @@ -1,9 +0,0 @@ -module.export = { - optimizations: { - namedModules: false - }, - plugins: [ - new Foo(), - new webpack.NamedModulesPlugin() - ] -} diff --git a/packages/migrate/__tests__/namedModulesPlugin/namedModulesPlugin.test.ts b/packages/migrate/__tests__/namedModulesPlugin/namedModulesPlugin.test.ts deleted file mode 100644 index 73b6321a87f..00000000000 --- a/packages/migrate/__tests__/namedModulesPlugin/namedModulesPlugin.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('namedModulesPlugin', function () { - { - defineTest(dirName, 'namedModulesPlugin', 'namedModulesPlugin-0'); - defineTest(dirName, 'namedModulesPlugin', 'namedModulesPlugin-1'); - defineTest(dirName, 'namedModulesPlugin', 'namedModulesPlugin-2'); - } -}); diff --git a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__snapshots__/noEmitOnErrorsPlugin.test.ts.snap b/packages/migrate/__tests__/noEmitOnErrorsPlugin/__snapshots__/noEmitOnErrorsPlugin.test.ts.snap deleted file mode 100644 index c5f215b09da..00000000000 --- a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__snapshots__/noEmitOnErrorsPlugin.test.ts.snap +++ /dev/null @@ -1,31 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`noEmitOnErrorsPlugin noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-0" data 1`] = ` -"module.exports = { - optimizations: { - noEmitOnErrors: true - } -}; -" -`; - -exports[`noEmitOnErrorsPlugin noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-1" data 1`] = ` -"module.exports = { - optimizations: { - splitChunks: false, - noEmitOnErrors: true - }, - plugins: [new Foo()] -}; -" -`; - -exports[`noEmitOnErrorsPlugin noEmitOnErrorsPlugin transforms correctly using "noEmitOnErrorsPlugin-2" data 1`] = ` -"module.exports = { - optimizations: { - noEmitOnErrors: true - }, - plugins: [new Foo()] -}; -" -`; diff --git a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-0.input.js b/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-0.input.js deleted file mode 100644 index 7eb2fa30679..00000000000 --- a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-0.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: [new webpack.NoEmitOnErrorsPlugin()] -}; diff --git a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-1.input.js b/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-1.input.js deleted file mode 100644 index 9d409eb31d0..00000000000 --- a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - optimizations: { - splitChunks: false - }, - plugins: [new Foo(), new webpack.NoEmitOnErrorsPlugin()] -}; diff --git a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-2.input.js b/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-2.input.js deleted file mode 100644 index b30145bcc85..00000000000 --- a/packages/migrate/__tests__/noEmitOnErrorsPlugin/__testfixtures__/noEmitOnErrorsPlugin-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - optimizations: { - noEmitOnErrors: false - }, - plugins: [new Foo(), new webpack.NoEmitOnErrorsPlugin()] -}; diff --git a/packages/migrate/__tests__/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.test.ts b/packages/migrate/__tests__/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.test.ts deleted file mode 100644 index 5866d0d4b75..00000000000 --- a/packages/migrate/__tests__/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('noEmitOnErrorsPlugin', function () { - { - defineTest(dirName, 'noEmitOnErrorsPlugin', 'noEmitOnErrorsPlugin-0'); - defineTest(dirName, 'noEmitOnErrorsPlugin', 'noEmitOnErrorsPlugin-1'); - defineTest(dirName, 'noEmitOnErrorsPlugin', 'noEmitOnErrorsPlugin-2'); - } -}); diff --git a/packages/migrate/__tests__/outputPath/__snapshots__/outputPath.test.ts.snap b/packages/migrate/__tests__/outputPath/__snapshots__/outputPath.test.ts.snap deleted file mode 100644 index ceb019922fc..00000000000 --- a/packages/migrate/__tests__/outputPath/__snapshots__/outputPath.test.ts.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`outputPath outputPath transforms correctly using "outputPath-0" data 1`] = ` -"module.exports = { - output: { - path: path.join(__dirname, \\"dist\\"), - }, -}; -" -`; - -exports[`outputPath outputPath transforms correctly using "outputPath-1" data 1`] = ` -"module.exports = { - output: { - path: path.join(__dirname, \\"dist\\") - } -}; -" -`; - -exports[`outputPath outputPath transforms correctly using "outputPath-2" data 1`] = ` -"module.exports = { - output: { - path: path.join(__dirname, \\"dist\\") - } -}; -" -`; diff --git a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-0.input.js b/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-0.input.js deleted file mode 100644 index e111b266b50..00000000000 --- a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - path: "dist", - }, -}; diff --git a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-1.input.js b/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-1.input.js deleted file mode 100644 index 18e3d927d8f..00000000000 --- a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-1.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - path: path.join(__dirname, "dist") - } -}; diff --git a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-2.input.js b/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-2.input.js deleted file mode 100644 index 9f9c30a0420..00000000000 --- a/packages/migrate/__tests__/outputPath/__testfixtures__/outputPath-2.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - path: "dist" - } -}; diff --git a/packages/migrate/__tests__/outputPath/outputPath.test.ts b/packages/migrate/__tests__/outputPath/outputPath.test.ts deleted file mode 100644 index 7f0f266b761..00000000000 --- a/packages/migrate/__tests__/outputPath/outputPath.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('outputPath', function () { - { - defineTest(dirName, 'outputPath', 'outputPath-0'); - defineTest(dirName, 'outputPath', 'outputPath-1'); - defineTest(dirName, 'outputPath', 'outputPath-2'); - } -}); diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.ts.snap b/packages/migrate/__tests__/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.ts.snap deleted file mode 100644 index 5955bd27226..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.ts.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`remove deprecated plugin removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-0" data 1`] = ` -"module.exports = {}; -" -`; - -exports[`remove deprecated plugin removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-1" data 1`] = ` -"module.exports = {}; -" -`; - -exports[`remove deprecated plugin removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-2" data 1`] = ` -"module.exports = { - plugins: [new webpack.optimize.UglifyJsPlugin()] -}; -" -`; - -exports[`remove deprecated plugin removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-3" data 1`] = ` -"// This should throw - -module.exports = config => { - config.plugins.push(new webpack.optimize.UglifyJsPlugin()); - config.plugins.push(new webpack.optimize.DedupePlugin()); - config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin()); - return config; -}; -" -`; - -exports[`remove deprecated plugin removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-4" data 1`] = ` -"// This should throw -const webpack = require(\\"webpack\\"); - -const inst = new webpack.optimize.OccurrenceOrderPlugin(); -module.exports = config => { - config.plugins = [inst]; - return config; -}; -" -`; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js b/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js deleted file mode 100644 index 5171ac6d172..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: [new webpack.optimize.OccurrenceOrderPlugin()] -}; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js b/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js deleted file mode 100644 index 73c1c9554fd..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: [new webpack.optimize.DedupePlugin()] -}; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js b/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js deleted file mode 100644 index 93c058b3fff..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: [new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin(), new webpack.optimize.DedupePlugin()] -}; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js b/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js deleted file mode 100644 index abdd8a4599b..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// This should throw - -module.exports = config => { - config.plugins.push(new webpack.optimize.UglifyJsPlugin()); - config.plugins.push(new webpack.optimize.DedupePlugin()); - config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin()); - return config; -}; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js b/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js deleted file mode 100644 index b436cbdb8ad..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// This should throw -const webpack = require("webpack"); - -const inst = new webpack.optimize.OccurrenceOrderPlugin(); -module.exports = config => { - config.plugins = [inst]; - return config; -}; diff --git a/packages/migrate/__tests__/removeDeprecatedPlugins/removeDeprecatedPlugins.test.ts b/packages/migrate/__tests__/removeDeprecatedPlugins/removeDeprecatedPlugins.test.ts deleted file mode 100644 index 130fd973c03..00000000000 --- a/packages/migrate/__tests__/removeDeprecatedPlugins/removeDeprecatedPlugins.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('remove deprecated plugin', function () { - { - defineTest(dirName, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-0'); - defineTest(dirName, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-1'); - defineTest(dirName, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-2'); - defineTest(dirName, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-3'); - defineTest(dirName, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-4'); - } -}); diff --git a/packages/migrate/__tests__/removeJsonLoader/__snapshots__/removeJsonLoader.test.ts.snap b/packages/migrate/__tests__/removeJsonLoader/__snapshots__/removeJsonLoader.test.ts.snap deleted file mode 100644 index fbdf946613a..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/__snapshots__/removeJsonLoader.test.ts.snap +++ /dev/null @@ -1,53 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`removeJsonLoader removeJsonLoader transforms correctly using "removeJsonLoader-0" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - test: /\\\\.yml/, - use: [{ - loader: \\"another-loader\\" - }, { - loader: \\"yml-loader\\" - }] - } - ] - } -}; -" -`; - -exports[`removeJsonLoader removeJsonLoader transforms correctly using "removeJsonLoader-1" data 1`] = ` -"module.exports = { - module: { - rules: [ - { - test: /\\\\.yml/, - use: [{ - loader: \\"yml-loader\\" - }] - } - ] - } -}; -" -`; - -exports[`removeJsonLoader removeJsonLoader transforms correctly using "removeJsonLoader-2" data 1`] = ` -"module.exports = { - module: { - rules: [] - } -}; -" -`; - -exports[`removeJsonLoader removeJsonLoader transforms correctly using "removeJsonLoader-3" data 1`] = ` -"module.exports = { - module: { - rules: [] - } -}; -" -`; diff --git a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js b/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js deleted file mode 100644 index a492d057aec..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - module: { - rules: [ - { - test: /\.yml/, - use: [ - { - loader: "json-loader" - }, - { - loader: "another-loader" - }, - { - loader: "yml-loader" - } - ] - } - ] - } -}; diff --git a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js b/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js deleted file mode 100644 index cf3e50853c4..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - module: { - rules: [ - { - test: /\.yml/, - use: [ - { - loader: "json-loader" - }, - { - loader: "yml-loader" - } - ] - } - ] - } -}; diff --git a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js b/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js deleted file mode 100644 index 5a8709cb4b4..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - module: { - rules: [ - { - loader: "json-loader", - test: /\.json/ - } - ] - } -}; diff --git a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js b/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js deleted file mode 100644 index c4050edc398..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - module: { - rules: [ - { - test: /\.json/, - use: [ - { - loader: "json-loader" - } - ] - } - ] - } -}; diff --git a/packages/migrate/__tests__/removeJsonLoader/removeJsonLoader.test.ts b/packages/migrate/__tests__/removeJsonLoader/removeJsonLoader.test.ts deleted file mode 100644 index 621b531a70a..00000000000 --- a/packages/migrate/__tests__/removeJsonLoader/removeJsonLoader.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('removeJsonLoader', function () { - { - defineTest(dirName, 'removeJsonLoader', 'removeJsonLoader-0'); - defineTest(dirName, 'removeJsonLoader', 'removeJsonLoader-1'); - defineTest(dirName, 'removeJsonLoader', 'removeJsonLoader-2'); - defineTest(dirName, 'removeJsonLoader', 'removeJsonLoader-3'); - } -}); diff --git a/packages/migrate/__tests__/resolve/__snapshots__/resolve.test.ts.snap b/packages/migrate/__tests__/resolve/__snapshots__/resolve.test.ts.snap deleted file mode 100644 index 8c95bc6fa11..00000000000 --- a/packages/migrate/__tests__/resolve/__snapshots__/resolve.test.ts.snap +++ /dev/null @@ -1,29 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`resolve resolve transforms correctly 1`] = ` -"const path = require(\\"path\\"); -const rootPath = path.resolve(\\"/src\\"); -module.exports = [ - { - resolve: { - modules: [rootPath] - } - }, - { - resolve: { - modules: [rootPath] - } - }, - { - resolve: { - modules: [rootPath, \\"node_modules\\"] - } - }, - { - resolve: { - modules: [\\"node_modules\\", rootPath] - } - } -]; -" -`; diff --git a/packages/migrate/__tests__/resolve/__testfixtures__/resolve.input.js b/packages/migrate/__tests__/resolve/__testfixtures__/resolve.input.js deleted file mode 100644 index f90803ff3d0..00000000000 --- a/packages/migrate/__tests__/resolve/__testfixtures__/resolve.input.js +++ /dev/null @@ -1,25 +0,0 @@ -const path = require("path"); -const rootPath = path.resolve("/src"); -module.exports = [ - { - resolve: { - root: rootPath - } - }, - { - resolve: { - root: [rootPath] - } - }, - { - resolve: { - root: [rootPath, "node_modules"] - } - }, - { - resolve: { - modules: ["node_modules"], - root: rootPath - } - } -]; diff --git a/packages/migrate/__tests__/resolve/resolve.test.ts b/packages/migrate/__tests__/resolve/resolve.test.ts deleted file mode 100644 index 295b1df5e78..00000000000 --- a/packages/migrate/__tests__/resolve/resolve.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('resolve', function () { - { - defineTest(dirName, 'resolve'); - } -}); diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.ts.snap b/packages/migrate/__tests__/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.ts.snap deleted file mode 100644 index 5f584a014f8..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.ts.snap +++ /dev/null @@ -1,119 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`uglifyJsPluginu uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = ` -"module.exports = { - optimization: { - minimize: true - } -} -" -`; - -exports[`uglifyJsPluginu uglifyJsPlugin transforms correctly using "uglifyJsPlugin-1" data 1`] = ` -"const TerserPlugin = require('terser-webpack-plugin'); -module.exports = { - devtool: \\"source-map\\", - optimization: { - minimize: true, - - minimizer: [new TerserPlugin({ - sourceMap: true, - compress: {} - })] - } -} -" -`; - -exports[`uglifyJsPluginu uglifyJsPlugin transforms correctly using "uglifyJsPlugin-2" data 1`] = ` -"const TerserPlugin = require('terser-webpack-plugin'); -module.exports = { - devtool: \\"source-map\\", - optimization: { - minimize: true, - - minimizer: [new TerserPlugin({ - sourceMap: true, - compress: {} - })] - } -} -" -`; - -exports[`uglifyJsPluginu uglifyJsPlugin transforms correctly using "uglifyJsPlugin-3" data 1`] = ` -"module.exports = { - devtool: 'eval', - - entry: [ - './src/index' - ], - - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - - plugins: [new webpack.optimize.OccurrenceOrderPlugin()], - debug: true, - - optimization: { - minimize: true - } -}; -" -`; - -exports[`uglifyJsPluginu uglifyJsPlugin transforms correctly using "uglifyJsPlugin-4" data 1`] = ` -"const TerserPlugin = require('terser-webpack-plugin'); -module.exports = { - devtool: 'eval', - - entry: [ - './src/index' - ], - - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - - plugins: [new webpack.optimize.OccurrenceOrderPlugin()], - debug: true, - - optimization: { - minimize: true, - - minimizer: [new TerserPlugin({ - sourceMap: true - })] - } -}; -" -`; diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js b/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js deleted file mode 100644 index a577b5143a6..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js +++ /dev/null @@ -1,7 +0,0 @@ -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); - -module.exports = { - plugins: [ - new UglifyJsPlugin() - ] -} diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js b/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js deleted file mode 100644 index 1b8d983f3bd..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js +++ /dev/null @@ -1,10 +0,0 @@ -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); -module.exports = { - devtool: "source-map", - plugins: [ - new UglifyJsPlugin({ - sourceMap: true, - compress: {} - }) - ] -} diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js b/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js deleted file mode 100644 index db172f05e29..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js +++ /dev/null @@ -1,10 +0,0 @@ -const Uglify = require('uglifyjs-webpack-plugin'); -module.exports = { - devtool: "source-map", - plugins: [ - new Uglify({ - sourceMap: true, - compress: {} - }) - ] -} diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-3.input.js b/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-3.input.js deleted file mode 100644 index 4f104918915..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-3.input.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; diff --git a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-4.input.js b/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-4.input.js deleted file mode 100644 index 707400c20bd..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-4.input.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = { - devtool: 'eval', - entry: [ - './src/index' - ], - output: { - path: path.join(__dirname, 'dist'), - filename: 'index.js' - }, - module: { - loaders: [{ - test: /.js$/, - loaders: ['babel'], - include: path.join(__dirname, 'src') - }] - }, - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }), - new webpack.optimize.OccurrenceOrderPlugin() - ], - debug: true -}; diff --git a/packages/migrate/__tests__/uglifyJsPlugin/uglifyJsPlugin.test.ts b/packages/migrate/__tests__/uglifyJsPlugin/uglifyJsPlugin.test.ts deleted file mode 100644 index 3d075bd0fe0..00000000000 --- a/packages/migrate/__tests__/uglifyJsPlugin/uglifyJsPlugin.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import defineTest from '../../../utils/__tests__/defineTest'; -import { join } from 'path'; - -const dirName: string = join(__dirname); - -describe('uglifyJsPluginu', function () { - { - defineTest(dirName, 'uglifyJsPlugin', 'uglifyJsPlugin-0'); - defineTest(dirName, 'uglifyJsPlugin', 'uglifyJsPlugin-1'); - defineTest(dirName, 'uglifyJsPlugin', 'uglifyJsPlugin-2'); - defineTest(dirName, 'uglifyJsPlugin', 'uglifyJsPlugin-3'); - defineTest(dirName, 'uglifyJsPlugin', 'uglifyJsPlugin-4'); - } -}); diff --git a/packages/migrate/package.json b/packages/migrate/package.json deleted file mode 100644 index e4e74bc21ac..00000000000 --- a/packages/migrate/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "@webpack-cli/migrate", - "version": "1.1.2", - "description": "Migrate command for webpack-cli", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "files": [ - "lib" - ], - "dependencies": { - "@webpack-cli/utils": "^1.2.1", - "colorette": "^1.2.1", - "diff": "^4.0.2", - "inquirer": "^7.3.3", - "jscodeshift": "^0.11.0", - "listr": "^0.14.3", - "p-each-series": "^2.1.0", - "p-lazy": "^3.0.0" - }, - "peerDependencies": { - "webpack": "4.x.x || 5.x.x", - "webpack-cli": "4.x.x" - }, - "devDependencies": { - "@types/diff": "^4.0.2", - "@types/inquirer": "^7.3.1", - "@types/listr": "^0.14.2" - }, - "gitHead": "fb50f766851f500ca12867a2aa9de81fa6e368f9" -} diff --git a/packages/migrate/src/bannerPlugin/bannerPlugin.ts b/packages/migrate/src/bannerPlugin/bannerPlugin.ts deleted file mode 100644 index e8277e82bc1..00000000000 --- a/packages/migrate/src/bannerPlugin/bannerPlugin.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { createOrUpdatePluginByName, findPluginsByName } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ - -export default function (j: JSCodeshift, ast: Node): Node { - return findPluginsByName(j, ast, ['webpack.BannerPlugin']).forEach((path: Node): void => { - const args: Node[] = (path.value as Node).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 as Node).arguments = [(path.value as Node).arguments[1]]; - createOrUpdatePluginByName(j, path.parent, 'webpack.BannerPlugin', { - banner: args[0].value, - }); - } - }); -} diff --git a/packages/migrate/src/commonsChunkPlugin/commonsChunkPlugin.ts b/packages/migrate/src/commonsChunkPlugin/commonsChunkPlugin.ts deleted file mode 100644 index 4bc15bbda2f..00000000000 --- a/packages/migrate/src/commonsChunkPlugin/commonsChunkPlugin.ts +++ /dev/null @@ -1,235 +0,0 @@ -import { - addOrUpdateConfigObject, - createIdentifierOrLiteral, - createProperty, - findAndRemovePluginByName, - findPluginsByName, - findRootNodesByName, -} from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -// merge test entry prop and function expression. case 6[x] -// TODO: set the proper type once moved to @types/jscodeshift -// eslint-disable-next-line -const mergeTestPropArrowFunction = (j, chunkKey, testFunc): any => { - return j.property( - 'init', - createIdentifierOrLiteral(j, 'test'), - j.arrowFunctionExpression( - [j.identifier('module')], - j.blockStatement([ - j.ifStatement( - j.callExpression( - j.memberExpression( - j.callExpression(j.memberExpression(j.identifier('module'), j.identifier('getChunks')), []), - j.identifier('some'), - false, - ), - [ - j.arrowFunctionExpression( - [j.identifier('chunk')], - j.binaryExpression( - '===', - j.memberExpression(j.identifier('chunk'), j.identifier('name')), - j.literal(chunkKey), - ), - ), - ], - ), - j.returnStatement(j.literal(true)), - ), - j.variableDeclaration('const', [j.variableDeclarator(j.identifier('fn'), testFunc)]), - j.returnStatement(j.callExpression(j.identifier('fn'), [j.identifier('module')])), - ]), - ), - ); -}; - -/** - * - * Transform for CommonsChunkPlugin. 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 - */ -export default function (j: JSCodeshift, ast: Node): Node { - const splitChunksProps: Node[] = []; - const cacheGroupsProps: Node[] = []; - const optimizationProps: object = {}; - - let commonCacheGroupsProps: Node[] = [createProperty(j, 'chunks', 'initial'), createProperty(j, 'enforce', true)]; - - // find old options - const CommonsChunkPlugin: Node = findPluginsByName(j, ast, ['webpack.optimize.CommonsChunkPlugin']); - - if (!CommonsChunkPlugin.size()) { - return ast; - } - - // cache group options based on keys - let cacheGroup: object = {}; - let cacheGroups: Node[] = []; - - // iterate each CommonsChunkPlugin instance - CommonsChunkPlugin.forEach((path: Node): void => { - const CCPProps: Node[] = (path.value as Node).arguments[0].properties; - - // reset chunks from old props - cacheGroup = {}; - cacheGroups = []; - - commonCacheGroupsProps = [createProperty(j, 'chunks', 'initial'), createProperty(j, 'enforce', true)]; - - let chunkKey: string; - let chunkCount = 0; - - // iterate CCP props and map SCP props - CCPProps.forEach((p: Node): void => { - const propKey: string = p.key.name; - - switch (propKey) { - case 'names': - (p.value as Node).elements.forEach(({ value: chunkValue }): void => { - if (chunkValue === 'runtime') { - optimizationProps['runtimeChunk'] = j.objectExpression([createProperty(j, 'name', chunkValue)]); - } else { - if (!Array.isArray(cacheGroup[chunkValue as string])) { - cacheGroup[chunkValue as string] = []; - } - - findRootNodesByName(j, ast, 'entry').forEach(({ value }): void => { - const { properties: entries } = (value as Node).value as Node; - chunkCount = entries.length; - entries.forEach(({ key: { name: entryName } }): void => { - if (entryName === chunkValue) { - cacheGroup[chunkValue as string].push(createProperty(j, 'test', entryName)); - } - }); - }); - } - }); - break; - - case 'name': { - const nameKey = (p.value as Node).value as string; - - if (nameKey === 'runtime') { - optimizationProps['runtimeChunk'] = j.objectExpression([createProperty(j, 'name', nameKey)]); - } else { - chunkKey = nameKey; - - if (!Array.isArray(cacheGroup[nameKey])) { - cacheGroup[nameKey] = []; - } - - findRootNodesByName(j, ast, 'entry').forEach(({ value }): void => { - const { properties: entries } = (value as Node).value as Node; - chunkCount = entries.length; - entries.forEach(({ key: { name: entryName } }): void => { - if (entryName === nameKey) { - cacheGroup[nameKey].push(createProperty(j, 'test', entryName)); - } - }); - }); - } - break; - } - - case 'filename': - if (chunkKey) { - if (!Array.isArray(cacheGroup[chunkKey])) { - cacheGroup[chunkKey] = []; - } - cacheGroup[chunkKey].push(createProperty(j, propKey, (p.value as Node).value as string)); - } - break; - - case 'async': - if (!Array.isArray(cacheGroup[chunkKey])) { - cacheGroup[chunkKey] = []; - } - cacheGroup[chunkKey].push(createProperty(j, 'chunks', 'async')); - break; - - case 'minSize': - if (!Array.isArray(cacheGroup[chunkKey])) { - cacheGroup[chunkKey] = []; - } - cacheGroup[chunkKey].push(j.property('init', createIdentifierOrLiteral(j, propKey), p.value as Node)); - break; - - case 'minChunks': { - const { value: pathValue }: Node = p; - - // minChunk is a function - if ((pathValue as Node).type === 'ArrowFunctionExpression' || (pathValue as Node).type === 'FunctionExpression') { - if (!Array.isArray(cacheGroup[chunkKey])) { - cacheGroup[chunkKey] = []; - } - - cacheGroup[chunkKey] = cacheGroup[chunkKey].map((prop): string | void => - prop.key.name === 'test' ? mergeTestPropArrowFunction(j, chunkKey, pathValue) : prop, - ); - } - break; - } - } - }); - - Object.keys(cacheGroup).forEach((chunkName: string): void => { - let chunkProps: Node[] = [createProperty(j, 'name', chunkName)]; - - const chunkPropsToAdd = cacheGroup[chunkName]; - const chunkPropsKeys = chunkPropsToAdd.map((prop): string => prop.key.name); - - commonCacheGroupsProps = commonCacheGroupsProps.filter((commonProp): boolean => !chunkPropsKeys.includes(commonProp.key.name)); - - chunkProps.push(...commonCacheGroupsProps); - - if (chunkCount > 1) { - chunkProps.push(j.property('init', createIdentifierOrLiteral(j, 'minChunks'), createIdentifierOrLiteral(j, chunkCount))); - } - - const chunkPropsContainTest = chunkPropsToAdd.some( - (prop): boolean => prop.key.name === 'test' && prop.value.type === 'Literal', - ); - - if (chunkPropsContainTest) { - chunkProps = chunkProps.filter((prop): boolean => prop.key.name !== 'minChunks'); - } - - if (chunkPropsToAdd && Array.isArray(chunkPropsToAdd) && chunkPropsToAdd.length > 0) { - chunkProps.push(...chunkPropsToAdd); - } - - cacheGroups.push(j.property('init', createIdentifierOrLiteral(j, chunkName), j.objectExpression([...chunkProps]))); - }); - - if (cacheGroups.length > 0) { - cacheGroupsProps.push(...cacheGroups); - } - }); - - // Remove old plugin - const root: Node = findAndRemovePluginByName(j, ast, 'webpack.optimize.CommonsChunkPlugin'); - - const rootProps: Node[] = [...splitChunksProps]; - - if (cacheGroupsProps.length > 0) { - rootProps.push(j.property('init', createIdentifierOrLiteral(j, 'cacheGroups'), j.objectExpression([...cacheGroupsProps]))); - } - - // Add new optimizations splitChunks option - if (root) { - addOrUpdateConfigObject(j, root, 'optimizations', 'splitChunks', j.objectExpression([...rootProps])); - - Object.keys(optimizationProps).forEach((key: string): void => { - addOrUpdateConfigObject(j, root, 'optimizations', key, optimizationProps[key]); - }); - } - - return ast; -} diff --git a/packages/migrate/src/extractTextPlugin/extractTextPlugin.ts b/packages/migrate/src/extractTextPlugin/extractTextPlugin.ts deleted file mode 100644 index 1569271cadd..00000000000 --- a/packages/migrate/src/extractTextPlugin/extractTextPlugin.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { createProperty, findVariableToPlugin, isType } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * Check whether `node` is the invocation of the plugin denoted by `pluginName` - * - * @param {Object} j - jscodeshift top-level import - * @param {Path} 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: JSCodeshift, path: Node, pluginName: string): boolean { - let found = false; - found = - j(path) - .find(j.MemberExpression) - .filter((p: Node): boolean => (p.get('object').value as Node).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 - */ - -export default function (j: JSCodeshift, ast: Node): void | Node { - const changeArguments = (path: Node): Node => { - const args: Node[] = (path.value as Node).arguments; - - const literalArgs: Node[] = args.filter((p: Node): boolean => isType(p, 'Literal')); - if (literalArgs && literalArgs.length > 1) { - const newArgs: object = j.objectExpression( - literalArgs.map((p: Node, index: number): Node => createProperty(j, index === 0 ? 'fallback' : 'use', p.value as Node)), - ); - (path.value as Node).arguments = [newArgs]; - } - return path; - }; - const name: string = findVariableToPlugin(j, ast, 'extract-text-webpack-plugin'); - if (!name) { - return ast; - } - - return ast - .find(j.CallExpression) - .filter((p: Node): boolean => findInvocation(j, p, name)) - .forEach(changeArguments); -} diff --git a/packages/migrate/src/index.ts b/packages/migrate/src/index.ts deleted file mode 100644 index 3e7789a5e6c..00000000000 --- a/packages/migrate/src/index.ts +++ /dev/null @@ -1,200 +0,0 @@ -import { green, red } from 'colorette'; -import { Change, diffLines } from 'diff'; -import fs from 'fs'; -import inquirer from 'inquirer'; -import Listr from 'listr'; -import pLazy = require('p-lazy'); -import path from 'path'; -import { validate, WebpackOptionsValidationError } from 'webpack'; -import { runPrettier } from '@webpack-cli/utils'; -import { transformations } from './migrate'; -import { Node } from './types/NodePath'; -import jscodeshift from 'jscodeshift'; - -declare let process: { - cwd: Function; - webpackModule: { - validate: Function; - WebpackOptionsValidationError: { - new: ( - errors: string[], - ) => { - message: string; - }; - }; - }; - stdout: { - write: Function; - }; - exitCode: number; -}; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function runMigration(currentConfigPath: string, outputConfigPath: string, logger: any): Promise | void { - const recastOptions: object = { - quote: 'single', - }; - - const tasks: Listr = new Listr([ - { - task: (ctx: Node): string | void | Listr | Promise<{}> => - new pLazy((resolve: (value?: object) => void, reject: (reason?: string | object, err?: object) => void): void => { - fs.readFile(currentConfigPath, 'utf8', (err: object, content: string): void => { - if (err) { - reject(err); - } - try { - ctx.source = content; - ctx.ast = jscodeshift(content); - resolve(); - } catch (err) { - reject('Error generating AST', err); - } - }); - }), - title: 'Reading webpack config', - }, - { - task: (ctx: Node): string | void | Listr | Promise<{}> => { - return new Listr( - Object.keys(transformations).map((key: string): { - task: () => string; - title: string; - } => { - const transform: Function = transformations[key]; - return { - task: (): string => transform(ctx.ast, ctx.source), - title: key, - }; - }), - ); - }, - title: 'Migrating config to newest version', - }, - ]); - - return tasks - .run() - .then((ctx: Node): void | Promise => { - const result: string = ctx.ast.toSource(recastOptions); - const diffOutput: Change[] = diffLines(ctx.source, result); - - diffOutput.forEach((diffLine: Change): void => { - if (diffLine.added) { - process.stdout.write(green(`+ ${diffLine.value}`)); - } else if (diffLine.removed) { - process.stdout.write(red(`- ${diffLine.value}`)); - } - }); - - return inquirer - .prompt([ - { - default: 'Y', - message: 'Are you sure these changes are fine?', - name: 'confirmMigration', - type: 'confirm', - }, - ]) - .then( - (answers: { confirmMigration: boolean }): Promise<{}> => { - if (answers.confirmMigration) { - return inquirer.prompt([ - { - default: 'Y', - message: - 'Do you want to validate your configuration? ' + - "(If you're using webpack merge, validation isn't useful)", - name: 'confirmValidation', - type: 'confirm', - }, - ]); - } else { - logger.error('✖ Migration aborted'); - } - }, - ) - .then( - async (answer: { confirmValidation: boolean }): Promise => { - if (!answer) { - return; - } - - runPrettier(outputConfigPath, result); - - if (answer.confirmValidation) { - const outputConfig = (await import(outputConfigPath)).default; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const webpackOptionsValidationErrors: any = validate(outputConfig); - if (webpackOptionsValidationErrors && webpackOptionsValidationErrors.length) { - logger.error("\n✖ Your configuration validation wasn't successful\n"); - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore - // @ts-ignore - logger.error(new WebpackOptionsValidationError(webpackOptionsValidationErrors)); - } - } - - logger.success(`\n✔︎ New webpack config file is at ${outputConfigPath}.`); - logger.success('✔︎ Heads up! Updating to the latest version could contain breaking changes.'); - - logger.success('✔︎ Plugin and loader dependencies may need to be updated.'); - }, - ); - }) - .catch((err: object): void => { - logger.error('\n ✖ ︎Migration aborted due to some errors:\n'); - logger.error(err); - process.exitCode = 1; - }); -} - -class MigrationCommand { - async apply(cli): Promise { - const { logger } = cli; - - await cli.makeCommand( - { - name: 'migrate [new-config-path]', - alias: 'm', - description: 'Migrate a configuration to a new version.', - pkg: '@webpack-cli/migrate', - }, - [], - async (configPath: string, newConfigPath: string | undefined) => { - const currentConfigPath = path.resolve(configPath); - let outputConfigPath: string; - - if (!newConfigPath) { - try { - const { confirmPath } = await inquirer.prompt([ - { - default: 'Y', - message: 'Migration output path not specified. Do you want to use your existing webpack configuration?', - name: 'confirmPath', - type: 'confirm', - }, - ]); - if (!confirmPath) { - logger.error('︎Migration aborted due to no output path'); - return; - } - outputConfigPath = path.resolve(configPath); - - await runMigration(currentConfigPath, outputConfigPath, logger); - } catch (err) { - logger.error(err); - return; - } - - return; - } - - outputConfigPath = path.resolve(newConfigPath); - - await runMigration(currentConfigPath, outputConfigPath, logger); - }, - ); - } -} - -export default MigrationCommand; diff --git a/packages/migrate/src/loaderOptionsPlugin/loaderOptionsPlugin.ts b/packages/migrate/src/loaderOptionsPlugin/loaderOptionsPlugin.ts deleted file mode 100644 index 9df7f512070..00000000000 --- a/packages/migrate/src/loaderOptionsPlugin/loaderOptionsPlugin.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { createOrUpdatePluginByName, findPluginsByName, safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -interface LoaderOptions { - debug?: boolean; - minimize?: boolean; -} - -const isEmpty = (obj: LoaderOptions): boolean => Object.keys(obj).length === 0; - -/** - * - * 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 - * - */ - -export default function (j: JSCodeshift, ast: Node): Node { - const loaderOptions: LoaderOptions = {}; - - // If there is debug: true, set debug: true in the plugin - if (ast.find(j.Identifier, { name: 'debug' }).size()) { - loaderOptions.debug = true; - - ast.find(j.Identifier, { name: 'debug' }).forEach((p: Node): void => { - p.parent.prune(); - }); - } - - // 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: Node): boolean => safeTraverse(path, ['parent', 'value', 'key', 'name']) === 'plugins') - .forEach((path: Node): void => { - if (!isEmpty(loaderOptions)) { - createOrUpdatePluginByName(j, path, 'webpack.LoaderOptionsPlugin', loaderOptions); - } - }); -} diff --git a/packages/migrate/src/loaders/loaders.ts b/packages/migrate/src/loaders/loaders.ts deleted file mode 100644 index 0e3c85e4189..00000000000 --- a/packages/migrate/src/loaders/loaders.ts +++ /dev/null @@ -1,354 +0,0 @@ -import { createLiteral, createProperty, findObjWithOneOfKeys, safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ - -export default function (j: JSCodeshift, ast: Node): Node { - /** - * 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 = (path: Node): Node => { - const value: Node = path.value as Node; - // Find paths with `loaders` keys in the given Object - const paths: Node[] = value.properties.filter((prop: Node): boolean => prop.key.name.startsWith('loader')); - // For each pair of key and value - paths.forEach((pair: Node): void => { - // Replace 'loaders' Identifier with 'use' - pair.key.name = 'use'; - // If the value is an Array - if ((pair.value as Node).type === j.ArrayExpression.name) { - // replace its elements - const pairValue = pair.value as Node; - pair.value = j.arrayExpression( - pairValue.elements.map( - (arrElement: Node): Node => { - // If items of the array are Strings - if (arrElement.type === j.Literal.name) { - // Replace with `{ loader: LOADER }` Object - return j.objectExpression([createProperty(j, 'loader', arrElement.value as Node)]); - } - // otherwise keep the existing element - return arrElement; - }, - ), - ); - // If the value is String of loaders like 'style!css' - } else if ((pair.value as Node).type === j.Literal.name) { - // Replace it with Array expression of loaders - const literalValue = pair.value as Node; - pair.value = j.arrayExpression( - (literalValue.value as string).split('!').map( - (loader: string): Node => { - return j.objectExpression([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: Node): Node => { - const properties: Node[] = (p.value as Node).properties; - const loaderValue: string = properties.reduce( - (val: string, prop: Node): string => (prop.key.name === 'loader' ? ((prop.value as Node).value as string) : val), - '', - ); - const loader: string = loaderValue.split('?')[0]; - const query: string = loaderValue.split('?')[1]; - const options: Node[] = query.split('&').map( - (option: string): Node => { - const param: string[] = option.split('='); - const key: string = param[0]; - const val: string | boolean = param[1] || true; // No value in query string means it is truthy value - return j.objectProperty(j.identifier(key), createLiteral(j, val)); - }, - ); - const loaderProp: Node = createProperty(j, 'loader', loader); - const queryProp: Node = 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: Node): boolean => { - return (p.value as Node).properties.reduce((predicate: boolean, prop: Node): boolean => { - return ( - (safeTraverse(prop, ['value', 'value', 'indexOf']) && ((prop.value as Node).value as string).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: Node): boolean => - (path.value as Node).name === 'loaders' && 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: Node): Node => { - let loaders: Node = null; - (p.value as Node).properties.map((prop: Node): void => { - const keyName = prop.key.name; - if (keyName === 'loaders') { - loaders = prop.value as Node; - } - }); - (p.value as Node).properties.map((prop: Node): void => { - const keyName = prop.key.name; - if (keyName !== 'loaders') { - const enforceVal: string = keyName === 'preLoaders' ? 'pre' : 'post'; - (prop.value as Node).elements.map((elem: Node): void => { - elem.properties.push(createProperty(j, 'enforce', enforceVal)); - if (loaders && loaders.type === 'ArrayExpression') { - loaders.elements.push(elem); - } else { - prop.key.name = 'loaders'; - } - }); - } - }); - if (loaders) { - (p.value as Node).properties = (p.value as Node).properties.filter((prop: Node): boolean => 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 = (): Node => - ast - .find(j.ObjectExpression) - .filter((p: Node): boolean => findObjWithOneOfKeys(p, ['preLoaders', 'postLoaders'])) - .forEach(fitIntoLoaders); - - /** - * Convert top level `loaders` to `rules` - * - * @returns {Node} ast - jscodeshift ast - */ - - const loadersToRules = (): Node => - ast - .find(j.Identifier) - .filter(checkForLoader) - .forEach((p: Node): string => ((p.value as Node).name = 'rules')); - - /** - * Convert `loader` and `loaders` to Array of {Rule.Use} - * - * @returns {Node} ast - jscodeshift ast - */ - - const loadersToArrayExpression = (): Node | void => - ast - .find(j.ObjectExpression) - .filter((path: Node): boolean => findObjWithOneOfKeys(path, ['loader', 'loaders'])) - .filter((path: Node): boolean => 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 = (): Node => - ast - .find(j.ObjectExpression) - .filter((p: Node): boolean => 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 = (): Node => - ast - .find(j.Identifier) - .filter((p: Node): boolean => (p.value as Node).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 = (): Node => - ast.find(j.ObjectExpression).forEach((path: Node): void => { - (path.value as Node).properties.forEach((prop: Node): void => { - if ( - prop.key.name === 'loader' && - safeTraverse(prop, ['value', 'value']) && - !((prop.value as Node).value as string).endsWith('-loader') - ) { - prop.value = j.literal(((prop.value as Node).value as string) + '-loader'); - } - }); - }); - - /** - * - * Puts options object outside use object into use object - * - * @param {Node} p - object expression ast that has a key for either 'options' or 'use' - * @returns {Node} objectExpression - an use object expression ast containing the options and loader - */ - - const fitOptionsToUse = (p: Node): Node => { - let options: Node = null; - (p.value as Node).properties.forEach((prop: Node): void => { - const keyName: string = prop.key.name; - if (keyName === 'options') { - options = prop; - } - }); - - if (options) { - (p.value as Node).properties = (p.value as Node).properties.filter((prop: Node): boolean => prop.key.name !== 'options'); - - (p.value as Node).properties.forEach((prop: Node): void => { - const keyName = prop.key.name; - if (keyName === 'use') { - (prop.value as Node).elements[0].properties.push(options); - } - }); - } - - return p; - }; - - /** - * Move `options` inside the Array of {Rule.Use} - * - * @returns {Node} ast - jscodeshift ast - */ - - const moveOptionsToUse = (): Node => - ast - .find(j.ObjectExpression) - .filter((p: Node): boolean => findObjWithOneOfKeys(p, ['use'])) - .forEach(fitOptionsToUse); - - const transforms = [ - prepostLoaders, - loadersToRules, - loadersToArrayExpression, - loaderWithQueryParam, - loaderWithQueryProp, - addLoaderSuffix, - moveOptionsToUse, - ]; - transforms.forEach((t: Function): void => t()); - - return ast; -} diff --git a/packages/migrate/src/migrate.ts b/packages/migrate/src/migrate.ts deleted file mode 100644 index fc771a777ba..00000000000 --- a/packages/migrate/src/migrate.ts +++ /dev/null @@ -1,123 +0,0 @@ -import jscodeshift from 'jscodeshift'; -import pEachSeries = require('p-each-series'); -import pLazy = require('p-lazy'); -import bannerPluginTransform from './bannerPlugin/bannerPlugin'; -import commonsChunkPluginTransform from './commonsChunkPlugin/commonsChunkPlugin'; -import extractTextPluginTransform from './extractTextPlugin/extractTextPlugin'; -import loaderOptionsPluginTransform from './loaderOptionsPlugin/loaderOptionsPlugin'; -import loadersTransform from './loaders/loaders'; -import noEmitOnErrorsPluginTransform from './noEmitOnErrorsPlugin/noEmitOnErrorsPlugin'; -import removeDeprecatedPluginsTransform from './removeDeprecatedPlugins/removeDeprecatedPlugins'; -import removeJsonLoaderTransform from './removeJsonLoader/removeJsonLoader'; -import resolveTransform from './resolve/resolve'; -import uglifyJsPluginTransform from './uglifyJsPlugin/uglifyJsPlugin'; - -interface TransformsObject { - bannerPluginTransform: object; - commonsChunkPluginTransform?: object; - extractTextPluginTransform: object; - loaderOptionsPluginTransform: object; - loadersTransform: object; - noEmitOnErrorsPluginTransform: object; - removeDeprecatedPluginsTransform: object; - removeJsonLoaderTransform: object; - resolveTransform: object; - uglifyJsPluginTransform: object; -} - -const transformsObject: TransformsObject = { - loadersTransform, - resolveTransform, - removeJsonLoaderTransform, - uglifyJsPluginTransform, - loaderOptionsPluginTransform, - bannerPluginTransform, - extractTextPluginTransform, - noEmitOnErrorsPluginTransform, - removeDeprecatedPluginsTransform, - commonsChunkPluginTransform, -}; - -interface LazyTransformObject { - loadersTransform?: (ast: object, source: string) => pLazy<{}>; - resolveTransform?: (ast: object, source: string) => pLazy<{}>; - removeJsonLoaderTransform?: (ast: object, source: string) => pLazy<{}>; - uglifyJsPluginTransform?: (ast: object, source: string) => pLazy<{}>; - loaderOptionsPluginTransform?: (ast: object, source: string) => pLazy<{}>; - bannerPluginTransform?: (ast: object, source: string) => pLazy<{}>; - extractTextPluginTransform?: (ast: object, source: string) => pLazy<{}>; - noEmitOnErrorsPluginTransform?: (ast: object, source: string) => pLazy<{}>; - removeDeprecatedPluginsTransform?: (ast: object, source: string) => pLazy<{}>; - commonsChunkPluginTransform?: (ast: object, source: string) => pLazy<{}>; -} - -/** - * - * Transforms single AST based on given transform function - * and returns back a promise with resolved transformation - * - * @param {Object} ast - AST object - * @param {String} source - source string - * @param {Function} transformFunction - Transformation function with source object - * @returns {Object} pLazy promise with resolved transform function - */ - -export const transformSingleAST = ( - ast: object, - source: string, - transformFunction: (jscodeshift: object, ast: object, source: string) => object, -): pLazy<{}> => { - return new pLazy((resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: object) => void): void => { - setTimeout((): void => { - try { - resolve(transformFunction(jscodeshift, ast, source)); - } catch (err) { - reject(err); - } - }, 0); - }); -}; - -export const transformations: LazyTransformObject = Object.keys(transformsObject).reduce( - (res: object, key: string): LazyTransformObject => { - res[key] = (ast: object, source: string): object => transformSingleAST(ast, source, transformsObject[key]); - return res; - }, - {}, -); - -/** - * - * 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 transformations. - * @param {Object} [options] - recast formatting options - * @returns {Promise} promise functions for series - */ - -export const transform = ( - source: string, - transforms?: Iterable>, - options?: object, -): Promise => { - const ast = jscodeshift(source); - const recastOptions: object = Object.assign( - { - quote: 'single', - }, - options, - ); - transforms = transforms || Object.keys(transformations).map((k: string): Function => transformations[k]); - - return pEachSeries(transforms, (f: Function): void => f(ast, source)) - .then((): string | PromiseLike => { - return ast.toSource(recastOptions); - }) - .catch((err: object): void => { - console.error(err); - }); -}; diff --git a/packages/migrate/src/moduleConcatenationPlugin/moduleConcatenationPlugin.ts b/packages/migrate/src/moduleConcatenationPlugin/moduleConcatenationPlugin.ts deleted file mode 100644 index d3d5fcc3b70..00000000000 --- a/packages/migrate/src/moduleConcatenationPlugin/moduleConcatenationPlugin.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { addOrUpdateConfigObject, findAndRemovePluginByName } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ -export default function (j: JSCodeshift, ast: Node): Node { - // Remove old plugin - const root: Node = findAndRemovePluginByName(j, ast, 'webpack.optimize.ModuleConcatenationPlugin'); - - // Add new optimizations option - if (root) { - addOrUpdateConfigObject(j, root, 'optimizations', 'concatenateModules', j.booleanLiteral(true)); - } - - return ast; -} diff --git a/packages/migrate/src/namedModulesPlugin/namedModulesPlugin.ts b/packages/migrate/src/namedModulesPlugin/namedModulesPlugin.ts deleted file mode 100644 index a4fe8dfc043..00000000000 --- a/packages/migrate/src/namedModulesPlugin/namedModulesPlugin.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { addOrUpdateConfigObject, findAndRemovePluginByName } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ -export default function (j: JSCodeshift, ast: Node): Node { - // Remove old plugin - const root: Node = findAndRemovePluginByName(j, ast, 'webpack.NamedModulesPlugin'); - - // Add new optimizations option - if (root) { - addOrUpdateConfigObject(j, root, 'optimizations', 'namedModules', j.booleanLiteral(true)); - } - - return ast; -} diff --git a/packages/migrate/src/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.ts b/packages/migrate/src/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.ts deleted file mode 100644 index c2611c3a0ba..00000000000 --- a/packages/migrate/src/noEmitOnErrorsPlugin/noEmitOnErrorsPlugin.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { addOrUpdateConfigObject, findAndRemovePluginByName } from '@webpack-cli/utils'; -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ -export default function (j: JSCodeshift, ast: Node): Node { - // Remove old plugin - const root: Node = findAndRemovePluginByName(j, ast, 'webpack.NoEmitOnErrorsPlugin'); - - // Add new optimizations option - if (root) { - addOrUpdateConfigObject(j, root, 'optimizations', 'noEmitOnErrors', j.booleanLiteral(true)); - } - - return ast; -} diff --git a/packages/migrate/src/outputPath/outputPath.ts b/packages/migrate/src/outputPath/outputPath.ts deleted file mode 100644 index 14ac10bb082..00000000000 --- a/packages/migrate/src/outputPath/outputPath.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { getRequire, safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -function replaceWithPath(j: JSCodeshift, p: Node, pathVarName: string): Node { - const convertedPath: Node = j.callExpression(j.memberExpression(j.identifier(pathVarName), j.identifier('join'), false), [ - j.identifier('__dirname'), - p.value as Node, - ]); - - return convertedPath; -} - -/** - * - * 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 - */ -export default function (j: JSCodeshift, ast: Node): Node | void { - const literalOutputPath: Node = ast - .find(j.ObjectExpression) - .filter((p: Node): boolean => safeTraverse(p, ['parentPath', 'value', 'key', 'name']) === 'output') - .find(j.Property) - .filter( - (p: Node): boolean => - safeTraverse(p, ['value', 'key', 'name']) === 'path' && safeTraverse(p, ['value', 'value', 'type']) === 'Literal', - ); - - if (literalOutputPath) { - let pathVarName = 'path'; - let isPathPresent = false; - const pathDeclaration: Node = ast - .find(j.VariableDeclarator) - .filter((p: Node): boolean => safeTraverse(p, ['value', 'init', 'callee', 'name']) === 'require') - .filter( - (p: Node): boolean => - safeTraverse(p, ['value', 'init', 'arguments']) && - // TODO: to fix when we have proper typing (@types/jscodeshift) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (p.value as any).init.arguments.reduce((isPresent: boolean, a: Node): boolean => { - return (a.type === 'Literal' && a.value === 'path') || isPresent; - }, false), - ); - - if (pathDeclaration) { - isPathPresent = true; - pathDeclaration.forEach((p: Node): void => { - pathVarName = safeTraverse(p, ['value', 'id', 'name']) as string; - }); - } - const finalPathName = pathVarName; - literalOutputPath.find(j.Literal).replaceWith((p: Node): Node => replaceWithPath(j, p, finalPathName)); - - if (!isPathPresent) { - const pathRequire: Node = getRequire(j, 'path', 'path'); - return ast.find(j.Program).replaceWith((p: Node): Node => j.program([].concat(pathRequire).concat((p.value as Node).body))); - } - } - - return ast; -} diff --git a/packages/migrate/src/removeDeprecatedPlugins/removeDeprecatedPlugins.ts b/packages/migrate/src/removeDeprecatedPlugins/removeDeprecatedPlugins.ts deleted file mode 100644 index 12d270e48e8..00000000000 --- a/packages/migrate/src/removeDeprecatedPlugins/removeDeprecatedPlugins.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { red, underline } from 'colorette'; - -import { findPluginsByName, isType, safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -import { utils } from 'webpack-cli'; - -const { logger } = 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 - */ - -export default function (j: JSCodeshift, ast: Node): Node { - // List of deprecated plugins to remove - // each item refers to webpack.optimize.[NAME] construct - const deprecatedPlugingsList: string[] = ['webpack.optimize.OccurrenceOrderPlugin', 'webpack.optimize.DedupePlugin']; - - return findPluginsByName(j, ast, deprecatedPlugingsList).forEach((path: Node): void => { - // For now we only support the case where plugins are defined in an Array - const arrayPath = safeTraverse(path, ['parent', 'value']) as Node; - - if (arrayPath && isType(arrayPath, 'ArrayExpression')) { - // Check how many plugins are defined and - // if there is only last plugin left remove `plugins: []` node - // - const arrayElementsPath = safeTraverse(arrayPath, ['elements']) as Node[]; - if (arrayElementsPath && arrayElementsPath.length === 1) { - j(path.parent.parent).remove(); - } else { - j(path).remove(); - } - } else { - logger.log(` -${red('Please remove deprecated plugins manually. ')} -See ${underline('https://webpack.js.org/guides/migrating/')} for more information.`); - } - }); -} diff --git a/packages/migrate/src/removeJsonLoader/removeJsonLoader.ts b/packages/migrate/src/removeJsonLoader/removeJsonLoader.ts deleted file mode 100644 index 9f8a884400e..00000000000 --- a/packages/migrate/src/removeJsonLoader/removeJsonLoader.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -type TransformCallback = (astNode: Node) => void; - -/** - * - * 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 - */ - -export default function (j: JSCodeshift, ast: Node): Node { - /** - * - * 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 - * @returns {void} - */ - - function removeLoaderByName(path: Node, name: string): void { - const loadersNode = (path.value as Node).value as Node; - - switch (loadersNode.type) { - case j.ArrayExpression.name: { - const loaders: Node[] = loadersNode.elements.map( - (p: Node): Node => { - return safeTraverse(p, ['properties', '0', 'value', 'value']) as Node; - }, - ); - - const loaderIndex: number = 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(astNode: Node): void { - astNode.find(j.Property, { key: { name: 'use' } }).forEach((path: Node): void => removeLoaderByName(path, 'json-loader')); - - astNode.find(j.Property, { key: { name: 'loader' } }).forEach((path: Node): void => removeLoaderByName(path, 'json-loader')); - } - - const transforms: TransformCallback[] = [removeLoaders]; - - transforms.forEach((t: TransformCallback): void => t(ast)); - - return ast; -} diff --git a/packages/migrate/src/resolve/resolve.ts b/packages/migrate/src/resolve/resolve.ts deleted file mode 100644 index 01cc27eade8..00000000000 --- a/packages/migrate/src/resolve/resolve.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * 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 - */ - -export default function transformer(j: JSCodeshift, ast: Node): Node { - const getRootVal = (p: Node): Node => { - return (p.node.value as Node).properties.filter((prop: Node): boolean => prop.key.name === 'root')[0]; - }; - - const getRootIndex = (p: Node): number => { - return (p.node.value as Node).properties.reduce((rootIndex: number, prop: Node, index: number): number => { - return prop.key.name === 'root' ? index : rootIndex; - }, -1); - }; - - const isModulePresent = (p: Node): Node | false => { - const modules: Node[] = (p.node.value as Node).properties.filter((prop: Node): boolean => 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} ast - ast node - */ - - const createModuleArray = (p: Node): Node => { - const rootVal: Node = getRootVal(p); - - let modulesVal: Node[] = null; - - if ((rootVal.value as Node).type === 'ArrayExpression') { - modulesVal = (rootVal.value as Node).elements; - } else { - modulesVal = [rootVal.value as Node]; - } - - let module: Node | false = isModulePresent(p); - - if (!module) { - module = j.property('init', j.identifier('modules'), j.arrayExpression(modulesVal)); - (p.node.value as Node).properties = (p.node.value as Node).properties.concat([module]); - } else { - (module.value as Node).elements = (module.value as Node).elements.concat(modulesVal); - } - - const rootIndex: number = getRootIndex(p); - - (p.node.value as Node).properties.splice(rootIndex, 1); - - return p; - }; - - return ast - .find(j.Property) - .filter((p: Node): boolean => { - return ( - p.node.key.name === 'resolve' && - (p.node.value as Node).properties.filter((prop: Node): boolean => prop.key.name === 'root').length === 1 - ); - }) - .forEach(createModuleArray); -} diff --git a/packages/migrate/src/types/NodePath.ts b/packages/migrate/src/types/NodePath.ts deleted file mode 100644 index fb2a3877348..00000000000 --- a/packages/migrate/src/types/NodePath.ts +++ /dev/null @@ -1,95 +0,0 @@ -export interface Node extends Object { - id?: { - name: string; - }; - arguments?: Node[]; - body?: Node[]; - elements?: Node[]; - expression?: { - left: { - computed: boolean; - object: Node; - property: Node; - type: string; - }; - operator: string; - right: Node; - type: string; - value?: string; - }; - filter?: (p: (p: Node) => boolean) => Node; - find?: (objectExpression: object, filterExpression?: object) => Node; - forEach?: (p: (p: Node) => void) => Node; - get?: (property: string) => Node; - remove?: () => void; - nodes?: () => Node[]; - pop?: () => Node; - key?: { - name: string; - value: Node | string; - }; - node?: Node; - name?: string; - object?: object; - parent?: Node; - properties?: Node[]; - property?: Node; - prune?: Function; - replaceWith?: (objectExpression: object) => Node; - size?: () => number; - type?: string; - value?: Node | string | Node[]; - toSource?: (object: { quote?: string }) => string; - source?: string; - ast?: Node; - rules?: ModuleRule[]; - - declarations?: Node[]; - - __paths?: Node[]; -} - -interface ModuleRule { - loader?: string; -} - -interface ExpressionObject { - name?: string; -} - -export interface JSCodeshift extends Object { - (source?: Node | string): Node; - withParser?: (parser: string) => JSCodeshift; - identifier?: (key: string) => Node; - literal?: (key: valueType) => Node; - memberExpression?: (node1: Node, node2: Node, bool?: boolean) => Node; - objectProperty?: (key: Node, property: valueType) => Node; - objectExpression?: (properties: Node[]) => Node; - newExpression?: (expression: Node, args: Node[]) => Node; - callExpression?: (expression: Node, args: Node[]) => Node; - variableDeclarator?: (key: Node, args: Node) => Node; - variableDeclaration?: (key: string, args: Node[]) => Node; - arrayExpression?: (args?: Node[]) => Node; - property?: (type: string, key: Node, value: Node) => Node; - program?: (nodes: Node[]) => Node; - booleanLiteral?: (bool: boolean) => Node; - Property?: ExpressionObject; - NewExpression?: ExpressionObject; - CallExpression?: ExpressionObject; - VariableDeclarator?: ExpressionObject; - Identifier?: ExpressionObject; - Literal?: ExpressionObject; - ArrayExpression?: ExpressionObject; - MemberExpression?: ExpressionObject; - FunctionExpression?: ExpressionObject; - ObjectExpression?: ExpressionObject; - BlockStatement?: ExpressionObject; - Program?: ExpressionObject; - filters?: { - VariableDeclarator: { - requiresModule: Function; - }; - }; -} - -export type valueType = string | number | boolean | Node | null; diff --git a/packages/migrate/src/uglifyJsPlugin/uglifyJsPlugin.ts b/packages/migrate/src/uglifyJsPlugin/uglifyJsPlugin.ts deleted file mode 100644 index 8d297a54791..00000000000 --- a/packages/migrate/src/uglifyJsPlugin/uglifyJsPlugin.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { createProperty, findPluginsArrayAndRemoveIfEmpty, findPluginsByName, getRequire, safeTraverse } from '@webpack-cli/utils'; - -import { JSCodeshift, Node } from '../types/NodePath'; - -/** - * - * Transform which: - * Removes UglifyWebpackPlugin from plugins array, if no options is passed to the plugin. - * and adds `optimization.minimize: true` to config - * - * If any configuration is passed to UglifyWebpackPlugin - * UglifyWebpackPlugin is replaced with TerserPlugin - * and plugin instantiation is moved to `optimization.minimizer`. - * - * @param {Object} j - jscodeshift top-level import - * @param {Node} ast - jscodeshift ast to transform - * @returns {Node} ast - jscodeshift ast - */ - -export default function (j: JSCodeshift, ast: Node): Node { - let pluginVariableAssignment: string = null; - - const searchForRequirePlugin: Node = ast - .find(j.VariableDeclarator) - .filter(j.filters.VariableDeclarator.requiresModule('uglifyjs-webpack-plugin')); - - /** - * Look for a variable declaration which requires uglifyjs-webpack-plugin - * saves the name of this variable. - */ - searchForRequirePlugin.forEach((node: Node): void => { - pluginVariableAssignment = (node.value as Node).id.name; - }); - - pluginVariableAssignment = !pluginVariableAssignment ? 'webpack.optimize.UglifyJsPlugin' : pluginVariableAssignment; - - findPluginsByName(j, ast, [pluginVariableAssignment]).forEach((node: Node): void => { - let expressionContent: object = null; - - const configBody = safeTraverse(node, ['parent', 'parent', 'parent']); - - // options passed to plugin - const pluginOptions: Node[] = (node.value as Node).arguments; - - /** - * check if there are any options passed to UglifyWebpackPlugin - * If so, they are moved to optimization.minimizer. - * Otherwise, rely on default options - */ - if (pluginOptions.length) { - /* - * If user is using UglifyJsPlugin directly from webpack - * transformation must: - * - remove it - * - add require for terser-webpack-plugin - * - add to minimizer - */ - if (pluginVariableAssignment) { - // remove require for uglify-webpack-plugin - searchForRequirePlugin.remove(); - - // create require for terser-webpack-plugin - const pathRequire: Node = getRequire(j, 'TerserPlugin', 'terser-webpack-plugin'); - // prepend to source code. - ast.find(j.Program).replaceWith((p: Node): Node => j.program([].concat(pathRequire).concat((p.value as Node).body))); - - expressionContent = j.property( - 'init', - j.identifier('minimizer'), - j.arrayExpression([j.newExpression(j.identifier('TerserPlugin'), [pluginOptions[0]])]), - ); - } else { - expressionContent = j.property('init', j.identifier('minimizer'), j.arrayExpression([node.value as Node])); - } - } else { - searchForRequirePlugin.forEach((n: Node): void => j(n).remove()); - } - - const minimizeProperty = createProperty(j, 'minimize', 'true'); - // creates optimization property at the body of the config. - if (expressionContent) { - ((configBody as Node).value as Node).properties.push( - j.property('init', j.identifier('optimization'), j.objectExpression([minimizeProperty, expressionContent])), - ); - } else { - ((configBody as Node).value as Node).properties.push( - j.property('init', j.identifier('optimization'), j.objectExpression([minimizeProperty])), - ); - } - - // remove the old Uglify plugin from Plugins array. - j(node).remove(); - }); - - findPluginsArrayAndRemoveIfEmpty(j, ast); - - return ast; -} diff --git a/packages/migrate/tsconfig.json b/packages/migrate/tsconfig.json deleted file mode 100644 index c06b88a4409..00000000000 --- a/packages/migrate/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib", - "rootDir": "./src" - }, - "include": ["./src"], - "references": [{ "path": "../utils" }] -} diff --git a/test/help/help.test.js b/test/help/help.test.js index 41be8093ff5..5fbfd041f2d 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -26,7 +26,6 @@ describe('help', () => { expect(stdout.match(/info\|i/g)).toHaveLength(1); expect(stdout.match(/init\|c/g)).toHaveLength(1); expect(stdout.match(/loader\|l/g)).toHaveLength(1); - expect(stdout.match(/migrate\|m/g)).toHaveLength(1); expect(stdout.match(/plugin\|p/g)).toHaveLength(1); expect(stdout.match(/configtest\|t/g)).toHaveLength(1); expect(stdout).toContain("To see list of all supported commands and options run 'webpack --help=verbose'."); @@ -58,7 +57,6 @@ describe('help', () => { expect(stdout.match(/info\|i/g)).toHaveLength(1); expect(stdout.match(/init\|c/g)).toHaveLength(1); expect(stdout.match(/loader\|l/g)).toHaveLength(1); - expect(stdout.match(/migrate\|m/g)).toHaveLength(1); expect(stdout.match(/plugin\|p/g)).toHaveLength(1); expect(stdout).toContain("To see list of all supported commands and options run 'webpack --help=verbose'."); expect(stdout).toContain('CLI documentation: https://webpack.js.org/api/cli/.'); @@ -155,7 +153,7 @@ describe('help', () => { expect(stdout).toContain('Made with ♥ by the webpack team'); }); - const commands = ['bundle', 'loader', 'plugin', 'info', 'init', 'migrate', 'serve']; + const commands = ['bundle', 'loader', 'plugin', 'info', 'init', 'serve']; commands.forEach((command) => { it(`should show help information for '${command}' command using the "--help" option`, () => { diff --git a/test/migrate/config/bad-webpack.config.js b/test/migrate/config/bad-webpack.config.js deleted file mode 100644 index ff6b82b575e..00000000000 --- a/test/migrate/config/bad-webpack.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - badOption: true, - }, -}; diff --git a/test/migrate/config/migrate-config.test.js b/test/migrate/config/migrate-config.test.js deleted file mode 100644 index 35dcb6000b9..00000000000 --- a/test/migrate/config/migrate-config.test.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const rimraf = require('rimraf'); -const stripAnsi = require('strip-ansi'); -const { run, runAndGetWatchProc, runPromptWithAnswers } = require('../../utils/test-utils'); - -const ENTER = '\x0D'; -const outputDir = 'test-assets'; -const outputPath = path.join(__dirname, outputDir); -const outputFile = `${outputDir}/updated-webpack.config.js`; -const outputFilePath = path.join(__dirname, outputFile); - -describe('migrate command', () => { - beforeEach(() => { - rimraf.sync(outputPath); - fs.mkdirSync(outputPath); - }); - - it('should warn if the source config file is not specified', () => { - const { stderr } = run(__dirname, ['migrate'], false); - expect(stderr).toContain("missing required argument 'config-path'"); - }); - - it('should prompt accordingly if an output path is not specified', () => { - const { stdout } = run(__dirname, ['migrate', 'webpack.config.js'], false); - expect(stripAnsi(stdout)).toContain('? Migration output path not specified'); - }); - - it('should throw an error if the user refused to overwrite the source file and no output path is provided', async () => { - const { stderr } = await runAndGetWatchProc(__dirname, ['migrate', 'webpack.config.js'], false, 'n'); - expect(stderr).toContain('︎Migration aborted due to no output path'); - }); - - it('should prompt for config validation when an output path is provided', async () => { - const { stdout } = await runAndGetWatchProc(__dirname, ['migrate', 'webpack.config.js', outputFile], false, 'y'); - // should show the diff of the config file - expect(stdout).toContain('rules: ['); - expect(stripAnsi(stdout)).toContain('? Do you want to validate your configuration?'); - }); - - it('should generate an updated config file when an output path is provided', async () => { - const { stdout, stderr } = await runPromptWithAnswers( - __dirname, - ['migrate', 'webpack.config.js', outputFile], - [ENTER, ENTER], - true, - ); - expect(stripAnsi(stdout)).toContain('? Do you want to validate your configuration?'); - // should show the diff of the config file - expect(stdout).toContain('rules: ['); - expect(stderr).toBeFalsy(); - - expect(fs.existsSync(outputFilePath)).toBeTruthy(); - // the output file should be a valid config file - const config = require(outputFilePath); - expect(config.module.rules).toEqual([ - { - test: /\.js$/, - exclude: /node_modules/, - - use: [ - { - loader: 'babel-loader', - - options: { - presets: ['@babel/preset-env'], - }, - }, - ], - }, - ]); - }); - - it('should generate an updated config file and warn of an invalid webpack config', async () => { - const { stdout, stderr } = await runPromptWithAnswers(__dirname, ['migrate', 'bad-webpack.config.js', outputFile], [ENTER, ENTER]); - expect(stripAnsi(stdout)).toContain('? Do you want to validate your configuration?'); - expect(stderr).toContain("configuration.output has an unknown property 'badOption'"); - - expect(fs.existsSync(outputFilePath)).toBeTruthy(); - }); -}); diff --git a/test/migrate/config/webpack.config.js b/test/migrate/config/webpack.config.js deleted file mode 100644 index b55e44c03e6..00000000000 --- a/test/migrate/config/webpack.config.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-disable */ -const path = require('path'); - -module.exports = { - entry: { - index: './src/index.js', - vendor: './src/vendor.js', - }, - - output: { - filename: '[name].[chunkhash].js', - chunkFilename: '[name].[chunkhash].js', - path: path.resolve(__dirname, 'dist'), - }, - - optimization: { - minimize: true - }, - - module: { - loaders: [ - { - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel', - query: { - presets: ['@babel/preset-env'], - }, - }, - ], - }, -}; diff --git a/test/version/version.test.js b/test/version/version.test.js index ac2b3deb1ca..530d22ec531 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -6,7 +6,6 @@ const { run } = require('../utils/test-utils'); const pkgJSON = require('../../packages/webpack-cli/package.json'); const initPkgJSON = require('../../packages/init/package.json'); const servePkgJSON = require('../../packages/serve/package.json'); -const migratePkgJSON = require('../../packages/migrate/package.json'); const infoPkgJSON = require('../../packages/info/package.json'); const generatorsPkgJSON = require('../../packages/generators/package.json'); const webpackDevServerPkgJSON = require('webpack-dev-server/package.json'); @@ -140,17 +139,6 @@ describe('single version flag', () => { expect(stdout).toContain(`webpack-dev-server ${webpackDevServerPkgJSON.version}`); }); - it('outputs version with migrate', () => { - const { exitCode, stderr, stdout } = run(__dirname, ['migrate', '--version'], false); - - expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toContain(`@webpack-cli/migrate ${migratePkgJSON.version}`); - expect(stdout).toContain(`webpack-cli ${pkgJSON.version}`); - expect(stdout).toContain(`webpack ${webpack.version}`); - expect(stdout).toContain(`webpack-dev-server ${webpackDevServerPkgJSON.version}`); - }); - it('outputs version with the alias c for init', () => { const { exitCode, stderr, stdout } = run(__dirname, ['i', '--version'], false); diff --git a/tsconfig.json b/tsconfig.json index 9062547bfb5..6f2490669e6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,7 @@ "declaration": true }, "references": [ +<<<<<<< HEAD { "path": "packages/generators" }, @@ -41,5 +42,12 @@ { "path": "packages/configtest" } +======= + { "path": "packages/generators" }, + { "path": "packages/info" }, + { "path": "packages/init" }, + { "path": "packages/serve" }, + { "path": "packages/utils" } +>>>>>>> fix: deprecate migrate package ] } From 823ca317a6e7f5ef874cd1b88c58bace3dff0648 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Wed, 6 Jan 2021 21:56:23 +0530 Subject: [PATCH 2/5] fix: support migrate externally --- package.json | 1 + packages/webpack-cli/lib/webpack-cli.js | 1 - test/help/help.test.js | 2 +- test/version/version.test.js | 9 ++++++++ yarn.lock | 28 +++++++++++++++---------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index c7c117f6011..e972121ad46 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "@types/node": "^14.14.6", "@typescript-eslint/eslint-plugin": "^2.34.0", "@typescript-eslint/parser": "^2.34.0", + "@webpack-cli/migrate": "^1.1.2", "colorette": "^1.2.1", "commitlint": "^11.0.0", "commitlint-config-cz": "^0.13.2", diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index cae401941d8..ce64b835d7e 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -349,7 +349,6 @@ class WebpackCLI { } else { pkg = commandName; } - if (pkg !== 'webpack-cli' && !getPkg(pkg)) { if (!allowToInstall) { return; diff --git a/test/help/help.test.js b/test/help/help.test.js index 5fbfd041f2d..088ca5e3b1e 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -153,7 +153,7 @@ describe('help', () => { expect(stdout).toContain('Made with ♥ by the webpack team'); }); - const commands = ['bundle', 'loader', 'plugin', 'info', 'init', 'serve']; + const commands = ['bundle', 'loader', 'plugin', 'info', 'init', 'serve', 'migrate']; commands.forEach((command) => { it(`should show help information for '${command}' command using the "--help" option`, () => { diff --git a/test/version/version.test.js b/test/version/version.test.js index 530d22ec531..5961154d220 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -139,6 +139,15 @@ describe('single version flag', () => { expect(stdout).toContain(`webpack-dev-server ${webpackDevServerPkgJSON.version}`); }); + it('outputs version with migrate', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['migrate', '--version'], false); + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(stdout).toContain(`webpack-cli ${pkgJSON.version}`); + expect(stdout).toContain(`webpack ${webpack.version}`); + expect(stdout).toContain(`webpack-dev-server ${webpackDevServerPkgJSON.version}`); + }); + it('outputs version with the alias c for init', () => { const { exitCode, stderr, stdout } = run(__dirname, ['i', '--version'], false); diff --git a/yarn.lock b/yarn.lock index 1e74bbb5f56..1eb88b51162 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1790,7 +1790,7 @@ resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd" integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ== -"@types/diff@*", "@types/diff@^4.0.2": +"@types/diff@*": version "4.0.2" resolved "https://registry.yarnpkg.com/@types/diff/-/diff-4.0.2.tgz#2e9bb89f9acc3ab0108f0f3dc4dbdcf2fff8a99c" integrity sha512-mIenTfsIe586/yzsyfql69KRnA75S8SVXQbTLpDejRrjH0QSJcpu3AUOi/Vjnt9IOsXKxPhJfGpQUNMueIU1fQ== @@ -1860,7 +1860,7 @@ resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz#9140779736aa2655635ee756e2467d787cfe8a2a" integrity sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A== -"@types/inquirer@*", "@types/inquirer@^7.3.1": +"@types/inquirer@*": version "7.3.1" resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-7.3.1.tgz#1f231224e7df11ccfaf4cf9acbcc3b935fea292d" integrity sha512-osD38QVIfcdgsPCT0V3lD7eH0OFurX71Jft18bZrsVQWVRt6TuxRzlr0GJLrxoHZR2V5ph7/qP8se/dcnI7o0g== @@ -1907,14 +1907,6 @@ dependencies: "@types/node" "*" -"@types/listr@^0.14.2": - version "0.14.2" - resolved "https://registry.yarnpkg.com/@types/listr/-/listr-0.14.2.tgz#2e5f80fbc3ca8dceb9940ce9bf8e3113ab452545" - integrity sha512-wCipMbQr3t2UHTm90LldVp+oTBj1TX6zvpkCJcWS4o8nn6kS8SN93oUvKJAgueIRZ5M36yOlFmScqBxYH8Ajig== - dependencies: - "@types/node" "*" - rxjs "^6.5.1" - "@types/mem-fs-editor@*": version "7.0.0" resolved "https://registry.yarnpkg.com/@types/mem-fs-editor/-/mem-fs-editor-7.0.0.tgz#e6576e0f66e20055481b2cdbf193457f1a2c4e65" @@ -2239,6 +2231,20 @@ "@webassemblyjs/wast-parser" "1.9.1" "@xtuc/long" "4.2.2" +"@webpack-cli/migrate@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@webpack-cli/migrate/-/migrate-1.1.2.tgz#7bac28243c63a99f6fc809cff4585a5aa9c9b907" + integrity sha512-wbIaaL88LXAcExzp9iG09Pp3sf+FPPQb/g7qCLJAVYAkN8P5L3Km7dLix9K2VQpDfGvEBE0tbEK//ot86F35ZQ== + dependencies: + "@webpack-cli/utils" "^1.2.1" + colorette "^1.2.1" + diff "^4.0.2" + inquirer "^7.3.3" + jscodeshift "^0.11.0" + listr "^0.14.3" + p-each-series "^2.1.0" + p-lazy "^3.0.0" + "@xtuc/ieee754@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790" @@ -9485,7 +9491,7 @@ run-queue@^1.0.0, run-queue@^1.0.3: dependencies: aproba "^1.1.1" -rxjs@>=6.4.0, rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.5.1, rxjs@^6.6.0, rxjs@^6.6.3: +rxjs@>=6.4.0, rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.6.0, rxjs@^6.6.3: version "6.6.3" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552" integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ== From ff8cb4196f58df78ebdfaa45b9dc557257deb256 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Fri, 8 Jan 2021 22:59:36 +0530 Subject: [PATCH 3/5] fix: tests --- packages/webpack-cli/lib/webpack-cli.js | 1 + test/help/help.test.js | 1 + test/version/version.test.js | 1 + tsconfig.json | 11 ----------- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index ce64b835d7e..cae401941d8 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -349,6 +349,7 @@ class WebpackCLI { } else { pkg = commandName; } + if (pkg !== 'webpack-cli' && !getPkg(pkg)) { if (!allowToInstall) { return; diff --git a/test/help/help.test.js b/test/help/help.test.js index 088ca5e3b1e..e5844fb7ada 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -27,6 +27,7 @@ describe('help', () => { expect(stdout.match(/init\|c/g)).toHaveLength(1); expect(stdout.match(/loader\|l/g)).toHaveLength(1); expect(stdout.match(/plugin\|p/g)).toHaveLength(1); + expect(stdout.match(/migrate\|m/g)).toHaveLength(1); expect(stdout.match(/configtest\|t/g)).toHaveLength(1); expect(stdout).toContain("To see list of all supported commands and options run 'webpack --help=verbose'."); expect(stdout).toContain('CLI documentation: https://webpack.js.org/api/cli/.'); diff --git a/test/version/version.test.js b/test/version/version.test.js index 5961154d220..42749637dbc 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -144,6 +144,7 @@ describe('single version flag', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`webpack-cli ${pkgJSON.version}`); + expect(stdout).toContain(`@webpack-cli/migrate`); expect(stdout).toContain(`webpack ${webpack.version}`); expect(stdout).toContain(`webpack-dev-server ${webpackDevServerPkgJSON.version}`); }); diff --git a/tsconfig.json b/tsconfig.json index 6f2490669e6..ea484876822 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,6 @@ "declaration": true }, "references": [ -<<<<<<< HEAD { "path": "packages/generators" }, @@ -30,9 +29,6 @@ { "path": "packages/init" }, - { - "path": "packages/migrate" - }, { "path": "packages/serve" }, @@ -42,12 +38,5 @@ { "path": "packages/configtest" } -======= - { "path": "packages/generators" }, - { "path": "packages/info" }, - { "path": "packages/init" }, - { "path": "packages/serve" }, - { "path": "packages/utils" } ->>>>>>> fix: deprecate migrate package ] } From 68dc453b73b475930d76ee60ce192849aaf345bb Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Fri, 8 Jan 2021 23:26:44 +0530 Subject: [PATCH 4/5] fix: tests --- test/help/help.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/help/help.test.js b/test/help/help.test.js index e5844fb7ada..56e863512f1 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -59,6 +59,7 @@ describe('help', () => { expect(stdout.match(/init\|c/g)).toHaveLength(1); expect(stdout.match(/loader\|l/g)).toHaveLength(1); expect(stdout.match(/plugin\|p/g)).toHaveLength(1); + expect(stdout.match(/migrate\|m/g)).toHaveLength(1); expect(stdout).toContain("To see list of all supported commands and options run 'webpack --help=verbose'."); expect(stdout).toContain('CLI documentation: https://webpack.js.org/api/cli/.'); expect(coloretteEnabled ? stripAnsi(stdout) : stdout).toContain('Made with ♥ by the webpack team.'); From 51f56482f1c732256624447c4345ed8652a95cc1 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Fri, 8 Jan 2021 23:51:16 +0530 Subject: [PATCH 5/5] fix: tests --- test/entry/flag-entry/entry-with-flag.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/entry/flag-entry/entry-with-flag.test.js b/test/entry/flag-entry/entry-with-flag.test.js index 03475c99ae3..90e465042ad 100644 --- a/test/entry/flag-entry/entry-with-flag.test.js +++ b/test/entry/flag-entry/entry-with-flag.test.js @@ -23,7 +23,6 @@ describe('entry flag', () => { it('should resolve the path to /src/a.js as ./src/a.js', (done) => { const { exitCode, stderr, stdout } = run(__dirname, ['--entry', '/src/a.js']); - expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy();