From 00e59ce56f634d90b93a1da3186a718e169a910f Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 08:46:17 -0700 Subject: [PATCH 01/15] feat: move init generator to webpack-addons --- lib/creator/index.js | 4 +- lib/creator/utils/validate-options.js | 37 -- lib/creator/utils/validate-options.spec.js | 19 - .../{yeoman => utils}/webpack-adapter.js | 0 lib/creator/yeoman/utils/entry.js | 74 ---- lib/creator/yeoman/utils/module.js | 12 - lib/creator/yeoman/utils/plugins.js | 5 - lib/creator/yeoman/utils/tooltip.js | 49 --- lib/creator/yeoman/utils/validate.js | 7 - lib/creator/yeoman/webpack-generator.js | 337 ------------------ package.json | 2 +- 11 files changed, 3 insertions(+), 543 deletions(-) delete mode 100644 lib/creator/utils/validate-options.js delete mode 100644 lib/creator/utils/validate-options.spec.js rename lib/creator/{yeoman => utils}/webpack-adapter.js (100%) delete mode 100644 lib/creator/yeoman/utils/entry.js delete mode 100644 lib/creator/yeoman/utils/module.js delete mode 100644 lib/creator/yeoman/utils/plugins.js delete mode 100644 lib/creator/yeoman/utils/tooltip.js delete mode 100644 lib/creator/yeoman/utils/validate.js delete mode 100644 lib/creator/yeoman/webpack-generator.js diff --git a/lib/creator/index.js b/lib/creator/index.js index 12ec46c8fc8..e74ce91c630 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -1,8 +1,8 @@ const yeoman = require('yeoman-environment'); const Generator = require('yeoman-generator'); const path = require('path'); -const defaultGenerator = require('./yeoman/webpack-generator'); -const WebpackAdapter = require('./yeoman/webpack-adapter'); +const defaultGenerator = require('webpack-addons').WebpackGenerator; +const WebpackAdapter = require('./utils/webpack-adapter'); const runTransform = require('./transformations/index'); /* diff --git a/lib/creator/utils/validate-options.js b/lib/creator/utils/validate-options.js deleted file mode 100644 index 111bebd428b..00000000000 --- a/lib/creator/utils/validate-options.js +++ /dev/null @@ -1,37 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -/* -* @function getPath -* -* Finds the current filepath of a given string -* -* @param { String } part - The name of the file to be checked. -* @returns { String } - returns an string with the filepath -*/ - -function getPath(part) { - return path.join(process.cwd(), part); -} - -/* -* @function validateOptions -* -* Validates the options passed from an inquirer instance to make -* sure the path supplied exists -* -* @param { String } part - The name of the file to be checked. -* @returns { } part - checks if the path exists or throws an error -*/ - -module.exports = function validateOptions(opts) { - return Object.keys(opts).forEach( (location) => { - let part = getPath(opts[location]); - try { - fs.readFileSync(part); - } catch (err) { - console.error('Found no file at:', part); - process.exitCode = 1; - } - }); -}; diff --git a/lib/creator/utils/validate-options.spec.js b/lib/creator/utils/validate-options.spec.js deleted file mode 100644 index aae91533562..00000000000 --- a/lib/creator/utils/validate-options.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const validateOptions = require('../../../__mocks__/creator/validate-options.mock').validateOptions; - -describe('validate-options', () => { - - it('should throw on fake paths', () => { - expect(() => { - validateOptions({entry: 'noop', output: 'noopsi'}); - }).toThrowError('Did not find the file'); - }); - - it('should find the real files', () => { - expect(() => { - validateOptions({entry: 'package.json'}); - }).not.toThrowError(/'Did not find the file'/); - }); - -}); diff --git a/lib/creator/yeoman/webpack-adapter.js b/lib/creator/utils/webpack-adapter.js similarity index 100% rename from lib/creator/yeoman/webpack-adapter.js rename to lib/creator/utils/webpack-adapter.js diff --git a/lib/creator/yeoman/utils/entry.js b/lib/creator/yeoman/utils/entry.js deleted file mode 100644 index f1f2839e8f7..00000000000 --- a/lib/creator/yeoman/utils/entry.js +++ /dev/null @@ -1,74 +0,0 @@ -const InputValidate = require('webpack-addons').InputValidate; -const validate = require('./validate'); - -module.exports = (self, answer) => { - let entryIdentifiers; - let result; - if(answer['entryType'] === true) { - result = self.prompt([ - InputValidate( - 'multipleEntries', - 'Type the name you want for your modules (entry files), seperated by comma', - validate - ) - ]).then( (multipleEntriesAnswer) => { - let webpackEntryPoint = {}; - entryIdentifiers = multipleEntriesAnswer['multipleEntries'].split(','); - function forEachPromise(obj, fn) { - return obj.reduce(function (promise, prop) { - const trimmedProp = prop.trim(); - return promise.then(function (n) { - if(n) { - Object.keys(n).forEach( (val) => { - if( - n[val].charAt(0) !== '(' - && n[val].charAt(0) !== '[' - && n[val].indexOf('function') < 0 - && n[val].indexOf('path') < 0 - && n[val].indexOf('process') < 0 - ) { - n[val] = `'${n[val]}.js'`; - } - webpackEntryPoint[val] = n[val]; - }); - } else { - n = {}; - } - return fn(trimmedProp); - }); - }, Promise.resolve()); - } - return forEachPromise(entryIdentifiers, (entryProp) => self.prompt([ - InputValidate( - `${entryProp}`, - `What is the location of '${entryProp}'?`, - validate - ) - ])).then(propAns => { - Object.keys(propAns).forEach( (val) => { - if( - propAns[val].charAt(0) !== '(' - && propAns[val].charAt(0) !== '[' - && propAns[val].indexOf('function') < 0 - && propAns[val].indexOf('path') < 0 - && propAns[val].indexOf('process') < 0 - ) { - propAns[val] = `'${propAns[val]}.js'`; - } - webpackEntryPoint[val] = propAns[val]; - }); - return webpackEntryPoint; - }); - }); - } - else { - result = self.prompt([ - InputValidate( - 'singularEntry', - 'Which module will be the first to enter the application?', - validate - ) - ]).then( (singularAnswer) => `'${singularAnswer['singularEntry']}'`); - } - return result; -}; diff --git a/lib/creator/yeoman/utils/module.js b/lib/creator/yeoman/utils/module.js deleted file mode 100644 index 161ec111962..00000000000 --- a/lib/creator/yeoman/utils/module.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = () => { - return { - test: new RegExp(/\.js$/), - exclude: '/node_modules/', - loader: '\'babel-loader\'', - options: { - presets: [ - '\'es2015\'' - ] - } - }; -}; diff --git a/lib/creator/yeoman/utils/plugins.js b/lib/creator/yeoman/utils/plugins.js deleted file mode 100644 index 90b39179d41..00000000000 --- a/lib/creator/yeoman/utils/plugins.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = () => { - return [ - 'new UglifyJSPlugin()' - ]; -}; diff --git a/lib/creator/yeoman/utils/tooltip.js b/lib/creator/yeoman/utils/tooltip.js deleted file mode 100644 index 16a5e840276..00000000000 --- a/lib/creator/yeoman/utils/tooltip.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = { - uglify: () => { - return (`/* - * We've enabled UglifyJSPlugin for you! This minifies your app - * in order to load faster and run less javascript. - * - * https://github.com/webpack-contrib/uglifyjs-webpack-plugin - * - */`); - }, - commonsChunk: () => { - return (`/* - * We've enabled commonsChunkPlugin for you. This allows your app to - * load faster and it splits the modules you provided as entries across - * different bundles! - * - * https://webpack.js.org/plugins/commons-chunk-plugin/ - * - */`); - }, - cssPlugin: () => { - return( - `/* - * We've enabled ExtractTextPlugin for you. This allows your app to - * use css modules that will be moved into a separate CSS file instead of inside - * one of your module entries! - * - * https://github.com/webpack-contrib/extract-text-webpack-plugin - * - */`); - }, - postcss: () => { - return( - `/* - * We've enabled Postcss, autoprefixer and precss for you. This allows your app - * to lint CSS, support variables and mixins, transpile future CSS syntax, - * inline images, and more! - * - * To enable SASS or LESS, add the respective loaders to module.rules - * - * https://github.com/postcss/postcss - * - * https://github.com/postcss/autoprefixer - * - * https://github.com/jonathantneal/precss - * - */`); - } -}; diff --git a/lib/creator/yeoman/utils/validate.js b/lib/creator/yeoman/utils/validate.js deleted file mode 100644 index bf981fd454f..00000000000 --- a/lib/creator/yeoman/utils/validate.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = (value) => { - const pass = value.length; - if(pass) { - return true; - } - return 'Please specify an answer!'; -}; diff --git a/lib/creator/yeoman/webpack-generator.js b/lib/creator/yeoman/webpack-generator.js deleted file mode 100644 index 1381d30033a..00000000000 --- a/lib/creator/yeoman/webpack-generator.js +++ /dev/null @@ -1,337 +0,0 @@ -const Generator = require('yeoman-generator'); -const chalk = require('chalk'); - -const createCommonsChunkPlugin = require('webpack-addons').createCommonsChunkPlugin; - -const Input = require('webpack-addons').Input; -const Confirm = require('webpack-addons').Confirm; -const RawList = require('webpack-addons').RawList; - -const entryQuestions = require('./utils/entry'); -const getBabelPlugin = require('./utils/module'); -const getDefaultPlugins = require('./utils/plugins'); -const tooltip = require('./utils/tooltip'); - -module.exports = class WebpackGenerator extends Generator { - constructor(args, opts) { - super(args, opts); - this.isProd = false; - this.npmInstalls = ['webpack', 'uglifyjs-webpack-plugin']; - this.configuration = { - config: { - webpackOptions: {}, - topScope: [] - } - }; - } - prompting() { - - let done = this.async(); - let self = this; - let oneOrMoreEntries; - let regExpForStyles; - let ExtractUseProps; - process.stdout.write( - '\n' + chalk.bold('Insecure about some of the questions?') + '\n' - ); - process.stdout.write( - `\n${chalk.bold.green('https://github.com/webpack/webpack-cli/blob/master/INIT.md')}\n\n` - ); - this.configuration.config.webpackOptions.module = { - rules: [] - }; - this.configuration.config.webpackOptions.plugins = getDefaultPlugins(); - this.configuration.config.topScope.push( - 'const webpack = require(\'webpack\')', - 'const path = require(\'path\')', - tooltip.uglify(), - 'const UglifyJSPlugin = require(\'uglifyjs-webpack-plugin\');', - '\n' - ); - this.prompt([ - Confirm('entryType', 'Will your application have multiple bundles?') - ]).then( (entryTypeAnswer) => { - // Ask different questions for entry points - entryQuestions(self, entryTypeAnswer).then(entryOptions => { - this.configuration.config.webpackOptions.entry = entryOptions; - oneOrMoreEntries = Object.keys(entryOptions); - }).then( () => { - - this.prompt([ - Input( - 'outputType', - 'Which folder will your generated bundles be in? [default: dist]:' - ) - ]).then( (outputTypeAnswer) => { - if(!this.configuration.config.webpackOptions.entry.length) { - this.configuration.config.topScope.push(tooltip.commonsChunk()); - this.configuration.config.webpackOptions.output = { - filename: '\'[name].[chunkhash].js\'', - chunkFilename: '\'[name].[chunkhash].js\'' - }; - } else { - this.configuration.config.webpackOptions.output = { - filename: '\'[name].bundle.js\'', - }; - } - if(outputTypeAnswer['outputType'].length) { - this.configuration.config.webpackOptions.output.path = `'${outputTypeAnswer['outputType']}'`; - } else { - this.configuration.config.webpackOptions.output.path = '\path.resolve(__dirname, \'dist\')'; - } - }).then( () => { - this.prompt([ - Confirm('prodConfirm', 'Are you going to use this in production?') - ]).then( (prodAnswer) => { - if(prodAnswer['prodConfirm'] === true) { - this.isProd = true; - } else { - this.isProd = false; - } - }).then( () => { - this.prompt([ - Confirm('babelConfirm', 'Will you be using ES2015?') - ]).then( (ans) => { - if(ans['babelConfirm'] === true) { - this.configuration.config.webpackOptions.module.rules.push(getBabelPlugin()); - this.npmInstalls.push('babel-loader', 'babel-core', 'babel-preset-es2015'); - } - }).then( () => { - this.prompt([ - RawList( - 'stylingType', - 'Will you use one of the below CSS solutions?', - ['SASS', 'LESS', 'CSS', 'PostCSS', 'No'] - ) - ]).then( (stylingAnswer) => { - if(!this.isProd) { - ExtractUseProps = []; - } - if(stylingAnswer['stylingType'] === 'SASS') { - this.npmInstalls.push( - 'sass-loader', 'node-sass', - 'style-loader', 'css-loader' - ); - regExpForStyles = new RegExp(/\.(scss|css)$/); - if(this.isProd) { - ExtractUseProps = `use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }, { - loader: 'sass-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'' - }, { - loader: '\'css-loader\'' - }, { - loader: '\'sass-loader\'' - }); - } - } - else if(stylingAnswer['stylingType'] === 'LESS') { - regExpForStyles = new RegExp(/\.(less|css)$/); - this.npmInstalls.push( - 'less-loader', 'less', - 'style-loader', 'css-loader' - ); - if(this.isProd) { - ExtractUseProps = ` - use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }, { - loader: 'less-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'css-loader\'', - options: { - sourceMap: true - } - }, { - loader: '\'less-loader\'', - options: { - sourceMap: true - } - }); - } - } - else if(stylingAnswer['stylingType'] === 'PostCSS') { - this.configuration.config.topScope.push( - tooltip.postcss(), - 'const autoprefixer = require(\'autoprefixer\');', - 'const precss = require(\'precss\');', - '\n' - ); - this.npmInstalls.push( - 'style-loader', 'css-loader', - 'postcss-loader', 'precss', - 'autoprefixer' - ); - regExpForStyles = new RegExp(/\.css$/); - if(this.isProd) { - ExtractUseProps = ` - use: [{ - loader: 'style-loader' - },{ - loader: 'css-loader', - options: { - sourceMap: true, - importLoaders: 1 - } - }, { - loader: 'postcss-loader', - options: { - plugins: function () { - return [ - precss, - autoprefixer - ]; - } - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'' - },{ - loader: '\'css-loader\'', - options: { - sourceMap: true, - importLoaders: 1 - } - }, { - loader: '\'postcss-loader\'', - options: { - plugins: `function () { - return [ - precss, - autoprefixer - ]; - }` - } - }); - } - } - else if(stylingAnswer['stylingType'] === 'CSS') { - this.npmInstalls.push('style-loader', 'css-loader'); - regExpForStyles = new RegExp(/\.css$/); - if(this.isProd) { - ExtractUseProps = `use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'', - options: { - sourceMap: true - } - }, { - loader: '\'css-loader\'', - }); - } - } - else { - regExpForStyles = null; - } - }).then( () => { - // Ask if the user wants to use extractPlugin - this.prompt([ - Input( - 'extractPlugin', - 'If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)' - ) - ]).then( (extractAnswer) => { - if(regExpForStyles) { - if(this.isProd) { - - this.configuration.config.topScope.push(tooltip.cssPlugin()); - this.npmInstalls.push('extract-text-webpack-plugin'); - if(extractAnswer['extractPlugin'].length !== 0) { - this.configuration.config.webpackOptions.plugins.push( - 'new ExtractTextPlugin(\'' + - extractAnswer['extractPlugin'] + - '.[contentHash].css\')' - ); - } else { - this.configuration.config.webpackOptions.plugins.push( - 'new ExtractTextPlugin(\'' + - 'style.css\')' - ); - } - const moduleRulesObj = { - test: regExpForStyles, - use: `ExtractTextPlugin.extract({ - ${ExtractUseProps} - })` - }; - this.configuration.config.webpackOptions.module.rules.push( - moduleRulesObj - ); - this.configuration.config.topScope.push( - 'const ExtractTextPlugin = require(\'extract-text-webpack-plugin\');', - '\n' - ); - } else { - const moduleRulesObj = { - test: regExpForStyles, - use: ExtractUseProps - }; - this.configuration.config.webpackOptions.module.rules.push( - moduleRulesObj - ); - } - } - }).then( () => { - if(!this.configuration.config.webpackOptions.entry.length) { - oneOrMoreEntries.forEach( (prop) => { - this.configuration.config.webpackOptions.plugins.push( - createCommonsChunkPlugin(prop) - ); - }); - } - done(); - }); - }); - }); - }); - }); - }); - }); - } - installPlugins() { - let asyncNamePrompt = this.async(); - let defaultName = this.isProd ? 'prod' : 'config'; - this.prompt([ - Input('nameType', `Name your \'webpack.[name].js?\' [default: \'${defaultName}\']:`) - ]).then( (nameAnswer) => { - if(nameAnswer['nameType'].length) { - this.configuration.config.configName = nameAnswer['nameType']; - } else { - this.configuration.config.configName = defaultName; - } - }).then( () => { - asyncNamePrompt(); - this.npmInstall(this.npmInstalls, { 'save-dev': true }); - }); - } - -}; diff --git a/package.json b/package.json index 4a5d766037b..7db12acfcd6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "resolve-cwd": "^2.0.0", "supports-color": "^3.1.2", "webpack": "^2.5.1", - "webpack-addons": "^1.1.2", + "webpack-addons": "git://github.com/webpack-contrib/webpack-addons.git#yeoman-migration", "yargs": "^6.5.0", "yeoman-environment": "^1.6.6", "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" From b2232e71b603a42a864cdb1af32e8dc4c368aad9 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:01:05 -0700 Subject: [PATCH 02/15] feat: move transforms to webpack-addons --- __mocks__/creator/validate-options.mock.js | 21 - lib/creator/index.js | 11 +- .../__snapshots__/context.test.js.snap | 37 -- .../__testfixtures__/context-0.input.js | 6 - .../__testfixtures__/context-1.input.js | 6 - .../__testfixtures__/context-2.input.js | 6 - .../transformations/context/context.js | 22 - .../transformations/context/context.test.js | 5 - .../__snapshots__/devtool.test.js.snap | 49 -- .../__testfixtures__/devtool-0.input.js | 6 - .../__testfixtures__/devtool-1.input.js | 6 - .../transformations/devtool/devtool.js | 23 - .../transformations/devtool/devtool.test.js | 6 - .../entry/__snapshots__/entry.test.js.snap | 57 -- .../entry/__testfixtures__/entry-0.input.js | 1 - lib/creator/transformations/entry/entry.js | 40 -- .../transformations/entry/entry.test.js | 17 - .../__snapshots__/externals.test.js.snap | 137 ----- .../__testfixtures__/externals-0.input.js | 6 - .../__testfixtures__/externals-1.input.js | 6 - .../transformations/externals/externals.js | 38 -- .../externals/externals.test.js | 61 -- lib/creator/transformations/index.js | 111 ---- .../module/__snapshots__/module.test.js.snap | 119 ---- .../module/__testfixtures__/module-0.input.js | 6 - .../module/__testfixtures__/module-1.input.js | 6 - lib/creator/transformations/module/module.js | 33 -- .../transformations/module/module.test.js | 93 ---- .../node/__snapshots__/node.test.js.snap | 21 - .../node/__testfixtures__/node-0.input.js | 6 - lib/creator/transformations/node/node.js | 26 - lib/creator/transformations/node/node.test.js | 11 - .../other/__snapshots__/other.test.js.snap | 74 --- .../other/__testfixtures__/other-0.input.js | 6 - lib/creator/transformations/other/amd.js | 26 - lib/creator/transformations/other/bail.js | 23 - lib/creator/transformations/other/cache.js | 23 - lib/creator/transformations/other/merge.js | 44 -- .../transformations/other/other.test.js | 11 - lib/creator/transformations/other/profile.js | 22 - .../output/__snapshots__/output.test.js.snap | 18 - .../output/__testfixtures__/output-0.input.js | 3 - lib/creator/transformations/output/output.js | 26 - .../transformations/output/output.test.js | 13 - .../__snapshots__/performance.test.js.snap | 18 - .../__testfixtures__/performance-0.input.js | 6 - .../performance/performance.js | 27 - .../performance/performance.test.js | 10 - .../__snapshots__/plugins.test.js.snap | 15 - .../__testfixtures__/plugins-0.input.js | 6 - .../transformations/plugins/plugins.js | 25 - .../transformations/plugins/plugins.test.js | 5 - .../__snapshots__/resolve.test.js.snap | 39 -- .../__testfixtures__/resolve-0.input.js | 6 - .../transformations/resolve/resolve.js | 26 - .../transformations/resolve/resolve.test.js | 27 - .../stats/__snapshots__/stats.test.js.snap | 55 -- .../stats/__testfixtures__/stats-0.input.js | 6 - lib/creator/transformations/stats/stats.js | 29 - .../transformations/stats/stats.test.js | 34 -- .../target/__snapshots__/target.test.js.snap | 25 - .../target/__testfixtures__/target-0.input.js | 6 - .../target/__testfixtures__/target-1.input.js | 6 - lib/creator/transformations/target/target.js | 22 - .../transformations/target/target.test.js | 4 - .../__snapshots__/top-scope.test.js.snap | 7 - .../__testfixtures__/top-scope-0.input.js | 1 - .../transformations/top-scope/top-scope.js | 22 - .../top-scope/top-scope.test.js | 5 - .../watch/__snapshots__/watch.test.js.snap | 49 -- .../__snapshots__/watchOptions.test.js.snap | 49 -- .../watch/__testfixtures__/watch-0.input.js | 6 - .../watch/__testfixtures__/watch-1.input.js | 6 - .../watch/__testfixtures__/watch-2.input.js | 6 - lib/creator/transformations/watch/watch.js | 21 - .../transformations/watch/watch.test.js | 6 - .../transformations/watch/watchOptions.js | 25 - .../watch/watchOptions.test.js | 19 - lib/creator/utils/run-prettier.js | 33 -- lib/migrate.js | 2 +- .../__snapshots__/index.test.js.snap | 102 ---- .../__snapshots__/utils.test.js.snap | 130 ----- .../__testfixtures__/failing.js | 81 --- .../__snapshots__/bannerPlugin.test.js.snap | 32 -- .../__testfixtures__/.editorconfig | 3 - .../__testfixtures__/bannerPlugin-0.input.js | 5 - .../__testfixtures__/bannerPlugin-1.input.js | 4 - .../__testfixtures__/bannerPlugin-2.input.js | 6 - .../bannerPlugin/bannerPlugin.js | 19 - .../bannerPlugin/bannerPlugin.test.js | 5 - lib/transformations/defineTest.js | 65 --- .../extractTextPlugin.test.js.snap | 24 - .../__testfixtures__/.editorconfig | 3 - .../extractTextPlugin.input.js | 16 - .../extractTextPlugin/extractTextPlugin.js | 32 -- .../extractTextPlugin.test.js | 3 - lib/transformations/index.js | 72 --- lib/transformations/index.test.js | 64 --- .../loaderOptionsPlugin.test.js.snap | 60 -- .../__testfixtures__/.editorconfig | 3 - .../loaderOptionsPlugin-0.input.js | 6 - .../loaderOptionsPlugin-1.input.js | 9 - .../loaderOptionsPlugin-2.input.js | 9 - .../loaderOptionsPlugin-3.input.js | 17 - .../loaderOptionsPlugin.js | 28 - .../loaderOptionsPlugin.test.js | 6 - .../__snapshots__/loaders.test.js.snap | 169 ------ .../loaders/__testfixtures__/.editorconfig | 3 - .../__testfixtures__/loaders-0.input.js | 65 --- .../__testfixtures__/loaders-1.input.js | 8 - .../__testfixtures__/loaders-2.input.js | 15 - .../__testfixtures__/loaders-3.input.js | 8 - .../__testfixtures__/loaders-4.input.js | 8 - .../__testfixtures__/loaders-5.input.js | 12 - .../__testfixtures__/loaders-6.input.js | 12 - lib/transformations/loaders/loaders.js | 137 ----- lib/transformations/loaders/loaders.test.js | 9 - .../__snapshots__/outputPath.test.js.snap | 30 - .../__testfixtures__/outputPath-0.input.js | 5 - .../__testfixtures__/outputPath-1.input.js | 6 - .../__testfixtures__/outputPath-2.input.js | 6 - lib/transformations/outputPath/outputPath.js | 51 -- .../outputPath/outputPath.test.js | 5 - .../removeDeprecatedPlugins.test.js.snap | 44 -- .../__testfixtures__/.editorconfig | 3 - .../removeDeprecatedPlugins-0.input.js | 6 - .../removeDeprecatedPlugins-1.input.js | 6 - .../removeDeprecatedPlugins-2.input.js | 8 - .../removeDeprecatedPlugins-3.input.js | 7 - .../removeDeprecatedPlugins-4.input.js | 8 - .../removeDeprecatedPlugins.js | 47 -- .../removeDeprecatedPlugins.test.js | 7 - .../removeJsonLoader.test.js.snap | 51 -- .../__testfixtures__/.editorconfig | 3 - .../removeJsonLoader-0.input.js | 9 - .../removeJsonLoader-1.input.js | 8 - .../removeJsonLoader-2.input.js | 10 - .../removeJsonLoader-3.input.js | 15 - .../removeJsonLoader/removeJsonLoader.js | 48 -- .../removeJsonLoader/removeJsonLoader.test.js | 6 - .../__snapshots__/resolve.test.js.snap | 24 - .../resolve/__testfixtures__/.editorconfig | 3 - .../resolve/__testfixtures__/resolve.input.js | 20 - lib/transformations/resolve/resolve.js | 49 -- lib/transformations/resolve/resolve.test.js | 3 - .../__snapshots__/uglifyJsPlugin.test.js.snap | 37 -- .../__testfixtures__/.editorconfig | 3 - .../uglifyJsPlugin-0.input.js | 5 - .../uglifyJsPlugin-1.input.js | 6 - .../uglifyJsPlugin-2.input.js | 8 - .../uglifyJsPlugin/uglifyJsPlugin.js | 25 - .../uglifyJsPlugin/uglifyJsPlugin.test.js | 5 - lib/transformations/utils.js | 526 ------------------ lib/transformations/utils.test.js | 315 ----------- 154 files changed, 2 insertions(+), 4608 deletions(-) delete mode 100644 __mocks__/creator/validate-options.mock.js delete mode 100644 lib/creator/transformations/context/__snapshots__/context.test.js.snap delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-0.input.js delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-1.input.js delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-2.input.js delete mode 100644 lib/creator/transformations/context/context.js delete mode 100644 lib/creator/transformations/context/context.test.js delete mode 100644 lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap delete mode 100644 lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js delete mode 100644 lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js delete mode 100644 lib/creator/transformations/devtool/devtool.js delete mode 100644 lib/creator/transformations/devtool/devtool.test.js delete mode 100644 lib/creator/transformations/entry/__snapshots__/entry.test.js.snap delete mode 100644 lib/creator/transformations/entry/__testfixtures__/entry-0.input.js delete mode 100644 lib/creator/transformations/entry/entry.js delete mode 100644 lib/creator/transformations/entry/entry.test.js delete mode 100644 lib/creator/transformations/externals/__snapshots__/externals.test.js.snap delete mode 100644 lib/creator/transformations/externals/__testfixtures__/externals-0.input.js delete mode 100644 lib/creator/transformations/externals/__testfixtures__/externals-1.input.js delete mode 100644 lib/creator/transformations/externals/externals.js delete mode 100644 lib/creator/transformations/externals/externals.test.js delete mode 100644 lib/creator/transformations/index.js delete mode 100644 lib/creator/transformations/module/__snapshots__/module.test.js.snap delete mode 100644 lib/creator/transformations/module/__testfixtures__/module-0.input.js delete mode 100644 lib/creator/transformations/module/__testfixtures__/module-1.input.js delete mode 100644 lib/creator/transformations/module/module.js delete mode 100644 lib/creator/transformations/module/module.test.js delete mode 100644 lib/creator/transformations/node/__snapshots__/node.test.js.snap delete mode 100644 lib/creator/transformations/node/__testfixtures__/node-0.input.js delete mode 100644 lib/creator/transformations/node/node.js delete mode 100644 lib/creator/transformations/node/node.test.js delete mode 100644 lib/creator/transformations/other/__snapshots__/other.test.js.snap delete mode 100644 lib/creator/transformations/other/__testfixtures__/other-0.input.js delete mode 100644 lib/creator/transformations/other/amd.js delete mode 100644 lib/creator/transformations/other/bail.js delete mode 100644 lib/creator/transformations/other/cache.js delete mode 100644 lib/creator/transformations/other/merge.js delete mode 100644 lib/creator/transformations/other/other.test.js delete mode 100644 lib/creator/transformations/other/profile.js delete mode 100644 lib/creator/transformations/output/__snapshots__/output.test.js.snap delete mode 100644 lib/creator/transformations/output/__testfixtures__/output-0.input.js delete mode 100644 lib/creator/transformations/output/output.js delete mode 100644 lib/creator/transformations/output/output.test.js delete mode 100644 lib/creator/transformations/performance/__snapshots__/performance.test.js.snap delete mode 100644 lib/creator/transformations/performance/__testfixtures__/performance-0.input.js delete mode 100644 lib/creator/transformations/performance/performance.js delete mode 100644 lib/creator/transformations/performance/performance.test.js delete mode 100644 lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap delete mode 100644 lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js delete mode 100644 lib/creator/transformations/plugins/plugins.js delete mode 100644 lib/creator/transformations/plugins/plugins.test.js delete mode 100644 lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap delete mode 100644 lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js delete mode 100644 lib/creator/transformations/resolve/resolve.js delete mode 100644 lib/creator/transformations/resolve/resolve.test.js delete mode 100644 lib/creator/transformations/stats/__snapshots__/stats.test.js.snap delete mode 100644 lib/creator/transformations/stats/__testfixtures__/stats-0.input.js delete mode 100644 lib/creator/transformations/stats/stats.js delete mode 100644 lib/creator/transformations/stats/stats.test.js delete mode 100644 lib/creator/transformations/target/__snapshots__/target.test.js.snap delete mode 100644 lib/creator/transformations/target/__testfixtures__/target-0.input.js delete mode 100644 lib/creator/transformations/target/__testfixtures__/target-1.input.js delete mode 100644 lib/creator/transformations/target/target.js delete mode 100644 lib/creator/transformations/target/target.test.js delete mode 100644 lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap delete mode 100644 lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js delete mode 100644 lib/creator/transformations/top-scope/top-scope.js delete mode 100644 lib/creator/transformations/top-scope/top-scope.test.js delete mode 100644 lib/creator/transformations/watch/__snapshots__/watch.test.js.snap delete mode 100644 lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-0.input.js delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-1.input.js delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-2.input.js delete mode 100644 lib/creator/transformations/watch/watch.js delete mode 100644 lib/creator/transformations/watch/watch.test.js delete mode 100644 lib/creator/transformations/watch/watchOptions.js delete mode 100644 lib/creator/transformations/watch/watchOptions.test.js delete mode 100644 lib/creator/utils/run-prettier.js delete mode 100644 lib/transformations/__snapshots__/index.test.js.snap delete mode 100644 lib/transformations/__snapshots__/utils.test.js.snap delete mode 100644 lib/transformations/__testfixtures__/failing.js delete mode 100644 lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js delete mode 100644 lib/transformations/bannerPlugin/bannerPlugin.js delete mode 100644 lib/transformations/bannerPlugin/bannerPlugin.test.js delete mode 100644 lib/transformations/defineTest.js delete mode 100644 lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap delete mode 100644 lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js delete mode 100644 lib/transformations/extractTextPlugin/extractTextPlugin.js delete mode 100644 lib/transformations/extractTextPlugin/extractTextPlugin.test.js delete mode 100644 lib/transformations/index.js delete mode 100644 lib/transformations/index.test.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js delete mode 100644 lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js delete mode 100644 lib/transformations/loaders/__snapshots__/loaders.test.js.snap delete mode 100644 lib/transformations/loaders/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-0.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-1.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-2.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-3.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-4.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-5.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-6.input.js delete mode 100644 lib/transformations/loaders/loaders.js delete mode 100644 lib/transformations/loaders/loaders.test.js delete mode 100644 lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js delete mode 100644 lib/transformations/outputPath/outputPath.js delete mode 100644 lib/transformations/outputPath/outputPath.test.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js delete mode 100644 lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js delete mode 100644 lib/transformations/removeJsonLoader/removeJsonLoader.js delete mode 100644 lib/transformations/removeJsonLoader/removeJsonLoader.test.js delete mode 100644 lib/transformations/resolve/__snapshots__/resolve.test.js.snap delete mode 100644 lib/transformations/resolve/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/resolve/__testfixtures__/resolve.input.js delete mode 100644 lib/transformations/resolve/resolve.js delete mode 100644 lib/transformations/resolve/resolve.test.js delete mode 100644 lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js delete mode 100644 lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js delete mode 100644 lib/transformations/utils.js delete mode 100644 lib/transformations/utils.test.js diff --git a/__mocks__/creator/validate-options.mock.js b/__mocks__/creator/validate-options.mock.js deleted file mode 100644 index 593f51f2f6f..00000000000 --- a/__mocks__/creator/validate-options.mock.js +++ /dev/null @@ -1,21 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -function getPath(part) { - return path.join(process.cwd(), part); -} - -function validateOptions(opts) { - return Object.keys(opts).forEach( (location) => { - let part = getPath(opts[location]); - try { - fs.readFileSync(part); - } catch (err) { - throw new Error('Did not find the file'); - } - }); -} - -module.exports = { - validateOptions -}; diff --git a/lib/creator/index.js b/lib/creator/index.js index e74ce91c630..266995e8088 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -3,7 +3,6 @@ const Generator = require('yeoman-generator'); const path = require('path'); const defaultGenerator = require('webpack-addons').WebpackGenerator; const WebpackAdapter = require('./utils/webpack-adapter'); -const runTransform = require('./transformations/index'); /* * @function creator @@ -31,15 +30,7 @@ function creator(options) { env.registerStub(defaultGenerator, 'webpack-default-generator'); } - env.run(generatorName).on('end', () => { - if(generatorName !== 'webpack-default-generator') { - //HACK / FIXME - env = env.options.env; - return runTransform(env.configuration); - } else { - return runTransform(env.getArgument('configuration')); - } - }); + return env.run(generatorName); } /* diff --git a/lib/creator/transformations/context/__snapshots__/context.test.js.snap b/lib/creator/transformations/context/__snapshots__/context.test.js.snap deleted file mode 100644 index d707e07cda2..00000000000 --- a/lib/creator/transformations/context/__snapshots__/context.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`context transforms correctly using "context-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: path.resolve(__dirname, \\"app\\") -} -" -`; - -exports[`context transforms correctly using "context-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: './some/fake/path' -} -" -`; - -exports[`context transforms correctly using "context-2" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: contextVariable -} -" -`; diff --git a/lib/creator/transformations/context/__testfixtures__/context-0.input.js b/lib/creator/transformations/context/__testfixtures__/context-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/__testfixtures__/context-1.input.js b/lib/creator/transformations/context/__testfixtures__/context-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/__testfixtures__/context-2.input.js b/lib/creator/transformations/context/__testfixtures__/context-2.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/context.js b/lib/creator/transformations/context/context.js deleted file mode 100644 index 98fb0710b99..00000000000 --- a/lib/creator/transformations/context/context.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for context. Finds the context property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'context', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/context/context.test.js b/lib/creator/transformations/context/context.test.js deleted file mode 100644 index 0258c5528de..00000000000 --- a/lib/creator/transformations/context/context.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'context', 'context-0', 'path.resolve(__dirname, "app")'); -defineTest(__dirname, 'context', 'context-1', '\'./some/fake/path\''); -defineTest(__dirname, 'context', 'context-2', 'contextVariable'); diff --git a/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap b/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap deleted file mode 100644 index d343b1fc107..00000000000 --- a/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`devtool transforms correctly using "devtool-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: 'source-map' -} -" -`; - -exports[`devtool transforms correctly using "devtool-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: myVariable -} -" -`; - -exports[`devtool transforms correctly using "devtool-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: 'cheap-module-source-map' -} -" -`; - -exports[`devtool transforms correctly using "devtool-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: false -} -" -`; diff --git a/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js b/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js b/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/devtool/devtool.js b/lib/creator/transformations/devtool/devtool.js deleted file mode 100644 index ac3930ad366..00000000000 --- a/lib/creator/transformations/devtool/devtool.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for devtool. Finds the devtool property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'devtool', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/devtool/devtool.test.js b/lib/creator/transformations/devtool/devtool.test.js deleted file mode 100644 index 01f574301a5..00000000000 --- a/lib/creator/transformations/devtool/devtool.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'devtool', 'devtool-0', '\'source-map\''); -defineTest(__dirname, 'devtool', 'devtool-0', 'myVariable'); -defineTest(__dirname, 'devtool', 'devtool-1', '\'cheap-module-source-map\''); -defineTest(__dirname, 'devtool', 'devtool-1', 'false'); diff --git a/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap b/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap deleted file mode 100644 index 1fb3d3acd85..00000000000 --- a/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap +++ /dev/null @@ -1,57 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`entry transforms correctly using "entry-0" data 1`] = ` -"module.exports = { - entry: 'index.js' -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 2`] = ` -"module.exports = { - entry: ['index.js', 'app.js'] -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 3`] = ` -"module.exports = { - entry: { - index: 'index.js', - app: 'app.js' - } -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 4`] = ` -"module.exports = { - entry: { - something, - app: 'app.js', - else - } -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 5`] = ` -"module.exports = { - entry: () => 'index.js' -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 6`] = ` -"module.exports = { - entry: () => new Promise((resolve) => resolve(['./app', './router'])) -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 7`] = ` -"module.exports = { - entry: entryStringVariable -} -" -`; diff --git a/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js b/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js deleted file mode 100644 index 4ba52ba2c8d..00000000000 --- a/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/lib/creator/transformations/entry/entry.js b/lib/creator/transformations/entry/entry.js deleted file mode 100644 index 5f142907561..00000000000 --- a/lib/creator/transformations/entry/entry.js +++ /dev/null @@ -1,40 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for entry. Finds the entry property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - - -module.exports = function(j, ast, webpackProperties) { - - function createEntryProperty(p) { - - if(typeof(webpackProperties) === 'string') { - return utils.pushCreateProperty(j, p, 'entry', webpackProperties); - } - if(Array.isArray(webpackProperties)) { - const externalArray = utils.createArrayWithChildren( - j, 'entry', webpackProperties, true - ); - return p.value.properties.push(externalArray); - } - else { - utils.pushCreateProperty(j, p, 'entry', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'entry'); - } - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createEntryProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/entry/entry.test.js b/lib/creator/transformations/entry/entry.test.js deleted file mode 100644 index 27047eb84ee..00000000000 --- a/lib/creator/transformations/entry/entry.test.js +++ /dev/null @@ -1,17 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'entry', 'entry-0', '\'index.js\''); -defineTest(__dirname, 'entry', 'entry-0', ['\'index.js\'', '\'app.js\'']); -defineTest(__dirname, 'entry', 'entry-0', { - index: '\'index.js\'', - app: '\'app.js\'' -}); - -defineTest(__dirname, 'entry', 'entry-0', { - inject: 'something', - app: '\'app.js\'', - inject_1: 'else' -}); -defineTest(__dirname, 'entry', 'entry-0', '() => \'index.js\''); -defineTest(__dirname, 'entry', 'entry-0', '() => new Promise((resolve) => resolve([\'./app\', \'./router\']))'); -defineTest(__dirname, 'entry', 'entry-0', 'entryStringVariable'); diff --git a/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap b/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap deleted file mode 100644 index 1a77ae06b34..00000000000 --- a/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap +++ /dev/null @@ -1,137 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`externals transforms correctly using "externals-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: /react/ -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: 'react' - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: myObj -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 3`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: reactObj - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 4`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: [reactObj, path.join(__dirname, 'app'), 'jquery'] - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 5`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - lodash: { - commonjs: 'lodash', - amd: 'lodash', - root: '_' - } - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 6`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - lodash: { - commonjs: lodash, - amd: hidash, - root: _ - } - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 7`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: [{ - a: false, - b: true, - './ext': ./hey - }, function(context, request, callback) {if (/^yourregex$/.test(request)){return callback(null, 'commonjs ' + request);}callback();}] -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 8`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: [ - myObj, - function(context, request, callback) {if (/^yourregex$/.test(request)){return callback(null, 'commonjs ' + request);}callback();} - ] -} -" -`; diff --git a/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js b/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js b/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/externals/externals.js b/lib/creator/transformations/externals/externals.js deleted file mode 100644 index 9f20dc2d801..00000000000 --- a/lib/creator/transformations/externals/externals.js +++ /dev/null @@ -1,38 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for externals. Finds the externals property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createExternalProperty(p) { - if(webpackProperties instanceof RegExp || typeof(webpackProperties) === 'string') { - return utils.pushCreateProperty(j, p, 'externals', webpackProperties); - } - if(Array.isArray(webpackProperties)) { - const externalArray = utils.createArrayWithChildren( - j, 'externals', webpackProperties, true - ); - return p.value.properties.push(externalArray); - } - else { - utils.pushCreateProperty(j, p, 'externals', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'externals'); - } - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.safeTraverse(p , ['parent', 'value', 'left', 'property', 'name']) === 'exports') - .forEach(createExternalProperty); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/externals/externals.test.js b/lib/creator/transformations/externals/externals.test.js deleted file mode 100644 index 07331dda65a..00000000000 --- a/lib/creator/transformations/externals/externals.test.js +++ /dev/null @@ -1,61 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'externals', 'externals-0', /react/); -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: '\'react\'' -}); - -defineTest(__dirname, 'externals', 'externals-1', 'myObj'); - -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: 'reactObj' -}); - -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: ['reactObj', 'path.join(__dirname, \'app\')', '\'jquery\''] -}); - -defineTest(__dirname, 'externals', 'externals-1', { - lodash: { - commonjs: '\'lodash\'', - amd: '\'lodash\'', - root: '\'_\'' - } -}); - -defineTest(__dirname, 'externals', 'externals-1', { - lodash: { - commonjs: 'lodash', - amd: 'hidash', - root: '_' - } -}); - -defineTest(__dirname, 'externals', 'externals-1', [ - { - a: 'false', - b: 'true', - '\'./ext\'': './hey' - }, - 'function(context, request, callback) {' + - 'if (/^yourregex$/.test(request)){' + - 'return callback(null, \'commonjs \' + request);' + - '}' + - 'callback();' + - '}' -] -); - -defineTest(__dirname, 'externals', 'externals-1', [ - 'myObj', - 'function(context, request, callback) {' + - 'if (/^yourregex$/.test(request)){' + - 'return callback(null, \'commonjs \' + request);' + - '}' + - 'callback();' + - '}' -] -); diff --git a/lib/creator/transformations/index.js b/lib/creator/transformations/index.js deleted file mode 100644 index 779bede11c6..00000000000 --- a/lib/creator/transformations/index.js +++ /dev/null @@ -1,111 +0,0 @@ -const path = require('path'); -const j = require('jscodeshift'); -const chalk = require('chalk'); -const pEachSeries = require('p-each-series'); - -const runPrettier = require('../utils/run-prettier'); - -const entryTransform = require('./entry/entry'); -const outputTransform = require('./output/output'); -const contextTransform = require('./context/context'); -const resolveTransform = require('./resolve/resolve'); -const devtoolTransform = require('./devtool/devtool'); -const targetTransform = require('./target/target'); -const watchTransform = require('./watch/watch'); -const watchOptionsTransform = require('./watch/watchOptions'); -const externalsTransform = require('./externals/externals'); -const nodeTransform = require('./node/node'); -const performanceTransform = require('./performance/performance'); -const statsTransform = require('./stats/stats'); -const amdTransform = require('./other/amd'); -const bailTransform = require('./other/bail'); -const cacheTransform = require('./other/cache'); -const profileTransform = require('./other/profile'); -const mergeTransform = require('./other/merge'); -const moduleTransform = require('./module/module'); -const pluginsTransform = require('./plugins/plugins'); -const topScopeTransform = require('./top-scope/top-scope'); - -/* -* @function runTransform -* -* Runs the transformations from an object we get from yeoman -* -* @param { Object } transformObject - Options to transform -* @returns { } - A promise that writes each transform, runs prettier -* and writes the file -*/ - -const transformsObject = { - entryTransform, - outputTransform, - contextTransform, - resolveTransform, - devtoolTransform, - targetTransform, - watchTransform, - watchOptionsTransform, - externalsTransform, - nodeTransform, - performanceTransform, - statsTransform, - amdTransform, - bailTransform, - cacheTransform, - profileTransform, - moduleTransform, - pluginsTransform, - topScopeTransform, - mergeTransform -}; - -module.exports = function runTransform(webpackProperties) { - - // webpackOptions.name sent to nameTransform if match - Object.keys(webpackProperties).forEach( (scaffoldPiece) => { - const config = webpackProperties[scaffoldPiece]; - - const transformations = Object.keys(transformsObject).map(k => { - const stringVal = k.substr(0, k.indexOf('Transform')); - if(config.webpackOptions) { - if(config.webpackOptions[stringVal]) { - return [transformsObject[k], config.webpackOptions[stringVal]]; - } else { - return [transformsObject[k], config[stringVal]]; - } - } else { - return [transformsObject[k]]; - } - }); - - const ast = j('module.exports = {}'); - - return pEachSeries(transformations, f => { - if(!f[1]) { - return f[0](j, ast); - } else { - return f[0](j, ast, f[1]); - } - }) - .then(() => { - let configurationName; - if(!config.configName) { - configurationName = 'webpack.config.js'; - } else { - configurationName = 'webpack.' + config.configName + '.js'; - } - - const outputPath = path.join(process.cwd(), configurationName); - const source = ast.toSource({ - quote: 'single' - }); - - runPrettier(outputPath, source); - }).catch(err => { - console.error(err.message ? err.message : err); - }); - }); - process.stdout.write('\n' + chalk.green( - 'Congratulations! Your new webpack configuration file has been created!\n' - )); -}; diff --git a/lib/creator/transformations/module/__snapshots__/module.test.js.snap b/lib/creator/transformations/module/__snapshots__/module.test.js.snap deleted file mode 100644 index 6824146c497..00000000000 --- a/lib/creator/transformations/module/__snapshots__/module.test.js.snap +++ /dev/null @@ -1,119 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`module transforms correctly using "module-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - rules: [{ - test: /\\\\.(js|vue)$/, - loader: 'eslint-loader', - enforce: 'pre', - include: [customObj, 'Stringy'], - options: { - formatter: 'someOption' - } - }, { - test: /\\\\.vue$/, - loader: 'vue-loader', - options: vueObject - }, { - test: /\\\\.js$/, - loader: 'babel-loader', - include: [resolve('src'), resolve('test')] - }, { - test: /\\\\.(png|jpe?g|gif|svg)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('img/[name].[hash:7].[ext]') - } - }, { - test: /\\\\.(woff2?|eot|ttf|otf)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('fonts/[name].[hash:7].[ext]'), - someArr: [Hey] - } - }] - } -} -" -`; - -exports[`module transforms correctly using "module-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - rules: [{{#if_eq build 'standalone'}}, { - test: /\\\\.(js|vue)$/, - loader: 'eslint-loader', - enforce: 'pre', - include: [customObj, 'Stringy'], - options: { - formatter: 'someOption' - } - }, { - test: /\\\\.vue$/, - loader: 'vue-loader', - options: vueObject - }, { - test: /\\\\.js$/, - loader: 'babel-loader', - include: [resolve('src'), resolve('test')] - }, { - test: /\\\\.(png|jpe?g|gif|svg)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('img/[name].[hash:7].[ext]'), - {{#if_eq build 'standalone'}} - } - }, { - test: /\\\\.(woff2?|eot|ttf|otf)(\\\\?.*)?$/, - loader: 'url-loader', - {{#if_eq build 'standalone'}}, - options: { - limit: 10000, - name: utils.assetsPath('fonts/[name].[hash:7].[ext]') - } - }] - } -} -" -`; - -exports[`module transforms correctly using "module-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - noParse: /jquery|lodash/, - rules: [{ - test: /\\\\.js$/, - parser: { - amd: false - }, - - use: ['htmllint-loader', { - loader: 'html-loader', - options: { - hello: 'world' - } - }] - }] - } -} -" -`; diff --git a/lib/creator/transformations/module/__testfixtures__/module-0.input.js b/lib/creator/transformations/module/__testfixtures__/module-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/module/__testfixtures__/module-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/module/__testfixtures__/module-1.input.js b/lib/creator/transformations/module/__testfixtures__/module-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/module/__testfixtures__/module-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/module/module.js b/lib/creator/transformations/module/module.js deleted file mode 100644 index 66c1371dccb..00000000000 --- a/lib/creator/transformations/module/module.js +++ /dev/null @@ -1,33 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for module. Finds the module property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - function createModuleProperties(p) { - utils.pushCreateProperty(j, p, 'module', j.objectExpression([])); - return utils.safeTraverse(p, ['key', 'name'] === 'module'); - } - function createRules(p) { - return utils.pushObjectKeys( - j, p, webpackProperties, 'module' - ); - } - if(!webpackProperties) { - return ast; - } else { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createModuleProperties)) - .forEach(p => createRules(p)); - } -}; diff --git a/lib/creator/transformations/module/module.test.js b/lib/creator/transformations/module/module.test.js deleted file mode 100644 index 710060d9c5e..00000000000 --- a/lib/creator/transformations/module/module.test.js +++ /dev/null @@ -1,93 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'module', 'module-0', { - rules: [{ - test: new RegExp(/\.(js|vue)$/), - loader: '\'eslint-loader\'', - enforce: '\'pre\'', - include: ['customObj', '\'Stringy\''], - options: { - formatter: '\'someOption\'' - } - }, { - test: new RegExp(/\.vue$/), - loader: '\'vue-loader\'', - options: 'vueObject' - }, { - test: new RegExp(/\.js$/), - loader: '\'babel-loader\'', - include: ['resolve(\'src\')', 'resolve(\'test\')'] - }, { - test: new RegExp(/\.(png|jpe?g|gif|svg)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: 10000, - name: 'utils.assetsPath(\'img/[name].[hash:7].[ext]\')' - } - }, { - test: new RegExp(/\.(woff2?|eot|ttf|otf)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: '10000', - name: 'utils.assetsPath(\'fonts/[name].[hash:7].[ext]\')', - someArr: ['Hey'] - } - }] -}); - -defineTest(__dirname, 'module', 'module-1', { - noParse: /jquery|lodash/, - rules: [{ - test: new RegExp(/\.js$/), - parser: { - amd: false - }, - use: [ - '\'htmllint-loader\'', - { - loader: '\'html-loader\'', - options: { - hello: '\'world\'' - } - } - ] - }] -}); - -defineTest(__dirname, 'module', 'module-0', { - rules: [ - '{{#if_eq build \'standalone\'}}', - { - test: new RegExp(/\.(js|vue)$/), - loader: '\'eslint-loader\'', - enforce: '\'pre\'', - include: ['customObj', '\'Stringy\''], - options: { - formatter: '\'someOption\'' - } - }, { - test: new RegExp(/\.vue$/), - loader: '\'vue-loader\'', - options: 'vueObject' - }, { - test: new RegExp(/\.js$/), - loader: '\'babel-loader\'', - include: ['resolve(\'src\')', 'resolve(\'test\')'] - }, { - test: new RegExp(/\.(png|jpe?g|gif|svg)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: 10000, - name: 'utils.assetsPath(\'img/[name].[hash:7].[ext]\')', - inject: '{{#if_eq build \'standalone\'}}' - } - }, { - test: new RegExp(/\.(woff2?|eot|ttf|otf)(\?.*)?$/), - loader: '\'url-loader\'', - inject: '{{#if_eq build \'standalone\'}}', - options: { - limit: '10000', - name: 'utils.assetsPath(\'fonts/[name].[hash:7].[ext]\')' - } - }] -}); diff --git a/lib/creator/transformations/node/__snapshots__/node.test.js.snap b/lib/creator/transformations/node/__snapshots__/node.test.js.snap deleted file mode 100644 index 0046bc33d63..00000000000 --- a/lib/creator/transformations/node/__snapshots__/node.test.js.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`node transforms correctly using "node-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - node: { - console: false, - global: true, - process: true, - Buffer: true, - __filename: mock, - __dirname: mock, - setImmediate: true - } -} -" -`; diff --git a/lib/creator/transformations/node/__testfixtures__/node-0.input.js b/lib/creator/transformations/node/__testfixtures__/node-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/node/__testfixtures__/node-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/node/node.js b/lib/creator/transformations/node/node.js deleted file mode 100644 index 26a9a13ffe4..00000000000 --- a/lib/creator/transformations/node/node.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for node. Finds the node property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createNodeProperty(p) { - utils.pushCreateProperty(j, p, 'node', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'node'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createNodeProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/node/node.test.js b/lib/creator/transformations/node/node.test.js deleted file mode 100644 index 53cf24e541a..00000000000 --- a/lib/creator/transformations/node/node.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'node', 'node-0', { - console: false, - global: true, - process: true, - Buffer: true, - __filename: 'mock', - __dirname: 'mock', - setImmediate: true -}); diff --git a/lib/creator/transformations/other/__snapshots__/other.test.js.snap b/lib/creator/transformations/other/__snapshots__/other.test.js.snap deleted file mode 100644 index 5a3d06f1f94..00000000000 --- a/lib/creator/transformations/other/__snapshots__/other.test.js.snap +++ /dev/null @@ -1,74 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`amd transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - amd: { - jQuery: true, - kQuery: false - } -} -" -`; - -exports[`bail transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - bail: true -} -" -`; - -exports[`cache transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - cache: true -} -" -`; - -exports[`cache transforms correctly using "other-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - cache: cacheVal -} -" -`; - -exports[`merge transforms correctly using "other-0" data 1`] = ` -"module.exports = merge(myConfig, { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -}); -" -`; - -exports[`profile transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - profile: true -} -" -`; diff --git a/lib/creator/transformations/other/__testfixtures__/other-0.input.js b/lib/creator/transformations/other/__testfixtures__/other-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/other/__testfixtures__/other-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/other/amd.js b/lib/creator/transformations/other/amd.js deleted file mode 100644 index 8453e6105c1..00000000000 --- a/lib/creator/transformations/other/amd.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for amd. Finds the amd property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createAMDProperty(p) { - utils.pushCreateProperty(j, p, 'amd', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'amd'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createAMDProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/bail.js b/lib/creator/transformations/other/bail.js deleted file mode 100644 index b61d793f30a..00000000000 --- a/lib/creator/transformations/other/bail.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for bail. Finds the bail property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'bail', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/cache.js b/lib/creator/transformations/other/cache.js deleted file mode 100644 index ad0ee5d5e0c..00000000000 --- a/lib/creator/transformations/other/cache.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for cache. Finds the cache property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'cache', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/merge.js b/lib/creator/transformations/other/merge.js deleted file mode 100644 index b93d2f4bde8..00000000000 --- a/lib/creator/transformations/other/merge.js +++ /dev/null @@ -1,44 +0,0 @@ -/* -* -* Transform for merge. Finds the merge property from yeoman and creates a way -* for users to allow webpack-merge in their scaffold -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createMergeProperty(p) { - // FIXME Use j.callExp() - let exportsDecl = p.value.body.map( (n) => { - if(n.expression) { - return n.expression.right; - } - }); - const bodyLength = exportsDecl.length; - let newVal = {}; - newVal.type = 'ExpressionStatement'; - newVal.expression = { - type: 'AssignmentExpression', - operator: '=', - left: { - type: 'MemberExpression', - computed: false, - object: j.identifier('module'), - property: j.identifier('exports') - }, - right: j.callExpression( - j.identifier('merge'), - [j.identifier(webpackProperties), exportsDecl.pop()]) - }; - p.value.body[bodyLength - 1] = newVal; - } - if(webpackProperties) { - return ast.find(j.Program) - .filter(p => createMergeProperty(p)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/other.test.js b/lib/creator/transformations/other/other.test.js deleted file mode 100644 index ba9d0c66ac9..00000000000 --- a/lib/creator/transformations/other/other.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'amd', 'other-0', { - jQuery: true, - kQuery: false} -); -defineTest(__dirname, 'bail', 'other-0', true); -defineTest(__dirname, 'cache', 'other-0', true); -defineTest(__dirname, 'cache', 'other-0', 'cacheVal'); -defineTest(__dirname, 'profile', 'other-0', true); -defineTest(__dirname, 'merge', 'other-0', 'myConfig'); diff --git a/lib/creator/transformations/other/profile.js b/lib/creator/transformations/other/profile.js deleted file mode 100644 index bdb146dc9d4..00000000000 --- a/lib/creator/transformations/other/profile.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for profile. Finds the profile property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'profile', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/output/__snapshots__/output.test.js.snap b/lib/creator/transformations/output/__snapshots__/output.test.js.snap deleted file mode 100644 index 9c51ca710ee..00000000000 --- a/lib/creator/transformations/output/__snapshots__/output.test.js.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`output transforms correctly using "output-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle', - path: 'dist/assets', - pathinfo: true, - publicPath: 'https://google.com', - sourceMapFilename: '[name].map', - sourcePrefix: '\\\\t', - umdNamedDefine: true, - strictModuleExceptionHandling: true - } -} -" -`; diff --git a/lib/creator/transformations/output/__testfixtures__/output-0.input.js b/lib/creator/transformations/output/__testfixtures__/output-0.input.js deleted file mode 100644 index a9899df14fa..00000000000 --- a/lib/creator/transformations/output/__testfixtures__/output-0.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - entry: 'index.js' -} diff --git a/lib/creator/transformations/output/output.js b/lib/creator/transformations/output/output.js deleted file mode 100644 index ea69aaab02a..00000000000 --- a/lib/creator/transformations/output/output.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for output. Finds the output property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createOutputProperties(p) { - utils.pushCreateProperty(j, p, 'output', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'output'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createOutputProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/output/output.test.js b/lib/creator/transformations/output/output.test.js deleted file mode 100644 index 413ead9c291..00000000000 --- a/lib/creator/transformations/output/output.test.js +++ /dev/null @@ -1,13 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); -const jscodeshift = require('jscodeshift'); - -defineTest(__dirname, 'output', 'output-0', { - filename: '\'bundle\'', - path: '\'dist/assets\'', - pathinfo: true, - publicPath: '\'https://google.com\'', - sourceMapFilename: '\'[name].map\'', - sourcePrefix: jscodeshift('\'\t\''), - umdNamedDefine: true, - strictModuleExceptionHandling: true -}); diff --git a/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap b/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap deleted file mode 100644 index 93bd117add3..00000000000 --- a/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`performance transforms correctly using "performance-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - performance: { - hints: 'warning', - maxEntrypointSize: 400000, - maxAssetSize: 100000, - assetFilter: function(assetFilename) {return assetFilename.endsWith('.js');} - } -} -" -`; diff --git a/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js b/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/performance/performance.js b/lib/creator/transformations/performance/performance.js deleted file mode 100644 index 7450f12df62..00000000000 --- a/lib/creator/transformations/performance/performance.js +++ /dev/null @@ -1,27 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for performance. Finds the performance property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - function createPerformanceProperty(p) { - utils.pushCreateProperty(j, p, 'performance', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'performance'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createPerformanceProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/performance/performance.test.js b/lib/creator/transformations/performance/performance.test.js deleted file mode 100644 index 0e078cb5d24..00000000000 --- a/lib/creator/transformations/performance/performance.test.js +++ /dev/null @@ -1,10 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'performance', 'performance-0', { - hints: '\'warning\'', - maxEntrypointSize: 400000, - maxAssetSize: 100000, - assetFilter: 'function(assetFilename) {' + - 'return assetFilename.endsWith(\'.js\');' + - '}' -}); diff --git a/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap b/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap deleted file mode 100644 index 6fbe0c9fe35..00000000000 --- a/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`plugins transforms correctly using "plugins-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({name:'vendor',filename:'vendor-[hash].min.js'}) - ] -} -" -`; diff --git a/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js b/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/plugins/plugins.js b/lib/creator/transformations/plugins/plugins.js deleted file mode 100644 index 33167582f29..00000000000 --- a/lib/creator/transformations/plugins/plugins.js +++ /dev/null @@ -1,25 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for plugins. Finds the plugins property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createPluginsProperty(p) { - const pluginArray = utils.createArrayWithChildren(j, 'plugins', webpackProperties, true); - return p.value.properties.push(pluginArray); - } - if(webpackProperties && Array.isArray(webpackProperties)) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createPluginsProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/plugins/plugins.test.js b/lib/creator/transformations/plugins/plugins.test.js deleted file mode 100644 index dde8d0ae2d5..00000000000 --- a/lib/creator/transformations/plugins/plugins.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'plugins', 'plugins-0', [ - 'new webpack.optimize.CommonsChunkPlugin({name:' + '\'' + 'vendor' + '\'' + ',filename:' + '\'' + 'vendor' + '-[hash].min.js\'})' -]); diff --git a/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap b/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap deleted file mode 100644 index 8e78a7cc775..00000000000 --- a/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap +++ /dev/null @@ -1,39 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`resolve transforms correctly using "resolve-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - resolve: { - alias: { - {{#if_eq build 'standalone'}}, - hello: 'world', - {{/if_eq}}, - world: hello - }, - - aliasFields: ['browser', wars], - descriptionFiles: ['a', b], - enforceExtension: false, - enforceModuleExtension: false, - extensions: [hey, 'ho'], - mainFields: [main, 'story'], - mainFiles: ['noMainFileHere', iGuess], - modules: [one, 'two'], - unsafeCache: false, - resolveLoader: { - modules: ['node_modules', mode_nodules], - extensions: [jsVal, '.json'], - mainFields: [loader, 'main'], - moduleExtensions: ['-loader', value] - }, - - plugins: [somePlugin, 'stringVal'], - symlinks: true - } -} -" -`; diff --git a/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js b/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/resolve/resolve.js b/lib/creator/transformations/resolve/resolve.js deleted file mode 100644 index 66d572edb84..00000000000 --- a/lib/creator/transformations/resolve/resolve.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for resolve. Finds the resolve property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createResolveProperties(p) { - utils.pushCreateProperty(j, p, 'resolve', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'resolve'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createResolveProperties)); - } - else { - return ast; - } -}; diff --git a/lib/creator/transformations/resolve/resolve.test.js b/lib/creator/transformations/resolve/resolve.test.js deleted file mode 100644 index 53218c2a4f3..00000000000 --- a/lib/creator/transformations/resolve/resolve.test.js +++ /dev/null @@ -1,27 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'resolve', 'resolve-0', { - alias: { - inject: '{{#if_eq build \'standalone\'}}', - hello: '\'world\'', - inject_1: '{{/if_eq}}', - world: 'hello', - }, - aliasFields: ['\'browser\'', 'wars'], - descriptionFiles: ['\'a\'', 'b'], - enforceExtension: false, - enforceModuleExtension: false, - extensions: ['hey', '\'ho\''], - mainFields: ['main', '\'story\''], - mainFiles: ['\'noMainFileHere\'', 'iGuess'], - modules: ['one', '\'two\''], - unsafeCache: false, - resolveLoader: { - modules: ['\'node_modules\'', 'mode_nodules'], - extensions: ['jsVal', '\'.json\''], - mainFields: ['loader', '\'main\''], - moduleExtensions: ['\'-loader\'', 'value'] - }, - plugins: ['somePlugin', '\'stringVal\''], - symlinks: true -}); diff --git a/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap b/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap deleted file mode 100644 index b94252a2e01..00000000000 --- a/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap +++ /dev/null @@ -1,55 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`stats transforms correctly using "stats-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - stats: { - assets: true, - assetsSort: 'field', - cached: true, - cachedAssets: true, - children: true, - chunks: true, - chunkModules: true, - chunkOrigins: true, - chunksSort: 'field', - context: '../src/', - colors: true, - depth: false, - entrypoints: customVal, - errors: true, - errorDetails: true, - exclude: [], - hash: true, - maxModules: 15, - modules: true, - modulesSort: 'field', - performance: true, - providedExports: false, - publicPath: true, - reasons: true, - source: true, - timings: true, - usedExports: false, - version: true, - warnings: true - } -} -" -`; - -exports[`stats transforms correctly using "stats-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - stats: 'errors-only' -} -" -`; diff --git a/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js b/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/stats/stats.js b/lib/creator/transformations/stats/stats.js deleted file mode 100644 index 46a0e0ad5e3..00000000000 --- a/lib/creator/transformations/stats/stats.js +++ /dev/null @@ -1,29 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for stats. Finds the stats property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createStatsProperty(p) { - utils.pushCreateProperty(j, p, 'stats', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'stats'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createStatsProperty)); - } - else if(webpackProperties && webpackProperties.length) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'stats', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/stats/stats.test.js b/lib/creator/transformations/stats/stats.test.js deleted file mode 100644 index 432eac37522..00000000000 --- a/lib/creator/transformations/stats/stats.test.js +++ /dev/null @@ -1,34 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'stats', 'stats-0', { - assets: true, - assetsSort: '\'field\'', - cached: true, - cachedAssets: true, - children: true, - chunks: true, - chunkModules: true, - chunkOrigins: true, - chunksSort: '\'field\'', - context: '\'../src/\'', - colors: true, - depth: false, - entrypoints: 'customVal', - errors: true, - errorDetails: true, - exclude: [], - hash: true, - maxModules: 15, - modules: true, - modulesSort: '\'field\'', - performance: true, - providedExports: false, - publicPath: true, - reasons: true, - source: true, - timings: true, - usedExports: false, - version: true, - warnings: true -}); -defineTest(__dirname, 'stats', 'stats-0', '\'errors-only\''); diff --git a/lib/creator/transformations/target/__snapshots__/target.test.js.snap b/lib/creator/transformations/target/__snapshots__/target.test.js.snap deleted file mode 100644 index 3af819e1ce2..00000000000 --- a/lib/creator/transformations/target/__snapshots__/target.test.js.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`target transforms correctly using "target-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - target: 'async-node' -} -" -`; - -exports[`target transforms correctly using "target-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - target: node -} -" -`; diff --git a/lib/creator/transformations/target/__testfixtures__/target-0.input.js b/lib/creator/transformations/target/__testfixtures__/target-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/target/__testfixtures__/target-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/target/__testfixtures__/target-1.input.js b/lib/creator/transformations/target/__testfixtures__/target-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/target/__testfixtures__/target-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/target/target.js b/lib/creator/transformations/target/target.js deleted file mode 100644 index 01501315d1d..00000000000 --- a/lib/creator/transformations/target/target.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for target. Finds the target property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties && webpackProperties.length) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'target', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/target/target.test.js b/lib/creator/transformations/target/target.test.js deleted file mode 100644 index e42a7347a91..00000000000 --- a/lib/creator/transformations/target/target.test.js +++ /dev/null @@ -1,4 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'target', 'target-0', '\'async-node\''); -defineTest(__dirname, 'target', 'target-1', 'node'); diff --git a/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap b/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap deleted file mode 100644 index 9ceb4dcb14e..00000000000 --- a/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`top-scope transforms correctly using "top-scope-0" data 1`] = ` -"var test = 'me'; -module.exports = {} -" -`; diff --git a/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js b/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js deleted file mode 100644 index 4ba52ba2c8d..00000000000 --- a/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/lib/creator/transformations/top-scope/top-scope.js b/lib/creator/transformations/top-scope/top-scope.js deleted file mode 100644 index 06e681d4577..00000000000 --- a/lib/creator/transformations/top-scope/top-scope.js +++ /dev/null @@ -1,22 +0,0 @@ - -/* -* -* Get an property named topScope from yeoman and inject it to the top scope of -* the config, outside module.exports -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing topscope properties -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createTopScopeProperty(p) { - webpackProperties.forEach( (n) => { - p.value.body.splice(-1, 0, n); - }); - } - if(webpackProperties) { - return ast.find(j.Program).filter(p => createTopScopeProperty(p)); - } -}; diff --git a/lib/creator/transformations/top-scope/top-scope.test.js b/lib/creator/transformations/top-scope/top-scope.test.js deleted file mode 100644 index da1398e55f9..00000000000 --- a/lib/creator/transformations/top-scope/top-scope.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'top-scope', 'top-scope-0', [ - 'var test = \'me\';' -]); diff --git a/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap b/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap deleted file mode 100644 index 964ece52812..00000000000 --- a/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`watch transforms correctly using "watch-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: true -} -" -`; - -exports[`watch transforms correctly using "watch-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: false -} -" -`; - -exports[`watch transforms correctly using "watch-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: true -} -" -`; - -exports[`watch transforms correctly using "watch-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: false -} -" -`; diff --git a/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap b/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap deleted file mode 100644 index 6f93736f0fd..00000000000 --- a/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`watchOptions transforms correctly using "watch-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; - -exports[`watchOptions transforms correctly using "watch-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; - -exports[`watchOptions transforms correctly using "watch-2" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/watch.js b/lib/creator/transformations/watch/watch.js deleted file mode 100644 index 650ddd22805..00000000000 --- a/lib/creator/transformations/watch/watch.js +++ /dev/null @@ -1,21 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for watch. Finds the watch property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(typeof(webpackProperties) === 'boolean') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'watch', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/watch/watch.test.js b/lib/creator/transformations/watch/watch.test.js deleted file mode 100644 index c564fcba4ec..00000000000 --- a/lib/creator/transformations/watch/watch.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'watch', 'watch-0', true); -defineTest(__dirname, 'watch', 'watch-0', false); -defineTest(__dirname, 'watch', 'watch-1', true); -defineTest(__dirname, 'watch', 'watch-1', false); diff --git a/lib/creator/transformations/watch/watchOptions.js b/lib/creator/transformations/watch/watchOptions.js deleted file mode 100644 index b08c8218a5c..00000000000 --- a/lib/creator/transformations/watch/watchOptions.js +++ /dev/null @@ -1,25 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for watchOptions. Finds the watchOptions property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createWatchOptionsProperty(p) { - utils.pushCreateProperty(j, p, 'watchOptions', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'watchOptions'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createWatchOptionsProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/watch/watchOptions.test.js b/lib/creator/transformations/watch/watchOptions.test.js deleted file mode 100644 index 33eb8811e08..00000000000 --- a/lib/creator/transformations/watch/watchOptions.test.js +++ /dev/null @@ -1,19 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'watchOptions', 'watch-0', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); - -defineTest(__dirname, 'watchOptions', 'watch-1', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); - -defineTest(__dirname, 'watchOptions', 'watch-2', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); diff --git a/lib/creator/utils/run-prettier.js b/lib/creator/utils/run-prettier.js deleted file mode 100644 index 59f60b0e161..00000000000 --- a/lib/creator/utils/run-prettier.js +++ /dev/null @@ -1,33 +0,0 @@ -const prettier = require('prettier'); -const fs = require('fs'); -const chalk = require('chalk'); - -/* -* -* Runs prettier and later prints the output configuration -* -* @param { String } outputPath - Path to write the config to -* @param { Node } source - AST to write at the given path -* @returns fs - Writes a file at given location and prints messages accordingly -*/ - -module.exports = function runPrettier(outputPath, source) { - function validateConfig() { - let prettySource; - try { - prettySource = prettier.format(source, { - singleQuote: true, - useTabs: true, - tabWidth: 1, - }); - } catch(err) { - process.stdout.write('\n' + - chalk.yellow(`WARNING: Could not apply prettier to ${outputPath}` + - ' due validation error, but the file has been created\n') - ); - prettySource = source; - } - return fs.writeFileSync(outputPath, prettySource, 'utf8'); - } - return fs.writeFile(outputPath, source, 'utf8', validateConfig); -}; diff --git a/lib/migrate.js b/lib/migrate.js index 6a3db45a3cb..5ca27a3a67c 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -34,7 +34,7 @@ module.exports = function transformFile(currentConfigPath, outputConfigPath, opt { title: 'Migrating config from v1 to v2', task: (ctx) => { - const transformations = require('./transformations').transformations; + const transformations = require('webpack-addons').migrate; return new Listr(Object.keys(transformations).map(key => { const transform = transformations[key]; return { diff --git a/lib/transformations/__snapshots__/index.test.js.snap b/lib/transformations/__snapshots__/index.test.js.snap deleted file mode 100644 index 9391f6d62cc..00000000000 --- a/lib/transformations/__snapshots__/index.test.js.snap +++ /dev/null @@ -1,102 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -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: \\"babel\\", - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')], - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true, - }), - new webpack.optimize.LoaderOptionsPlugin({ - \\"debug\\": true, - \\"minimize\\": true, - }) - ], - debug: 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: ['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 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: 'babel', - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }), - new webpack.optimize.LoaderOptionsPlugin({ - 'debug': true, - 'minimize': true - }) - ], - debug: true -}; -" -`; diff --git a/lib/transformations/__snapshots__/utils.test.js.snap b/lib/transformations/__snapshots__/utils.test.js.snap deleted file mode 100644 index 9ebb6a83c1f..00000000000 --- a/lib/transformations/__snapshots__/utils.test.js.snap +++ /dev/null @@ -1,130 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`utils checkIfExistsAndAddValue should create new prop if none exist 1`] = ` -" - module.exports = { - entry: 'index.js', - externals: \\"React\\" - } - " -`; - -exports[`utils checkIfExistsAndAddValue should override prop if it exists 1`] = ` -" - module.exports = { - entry: \\"app.js\\" - } - " -`; - -exports[`utils createArrayWithChildren should add all children of an array to a new one with a supplied key 1`] = `"myVeryOwnKey: ['hello', world]"`; - -exports[`utils createArrayWithChildren should find an prop that matches key and create an array with it 1`] = `"react: ['bo']"`; - -exports[`utils createEmptyArrayProperty should create an array with no properties 1`] = `"its-lit: []"`; - -exports[`utils createExternalRegExp should create an regExp property that has been parsed by jscodeshift 1`] = `"\\"\\\\t\\""`; - -exports[`utils createIdentifierOrLiteral should create basic literal 1`] = `"'stringLiteral'"`; - -exports[`utils createIdentifierOrLiteral should create boolean 1`] = `"true"`; - -exports[`utils createLiteral should create basic literal 1`] = `"\\"stringLiteral\\""`; - -exports[`utils createLiteral should create boolean 1`] = `"true"`; - -exports[`utils createObjectWithSuppliedProperty should create an object with a property supplied by us 1`] = `"its-lit: {}"`; - -exports[`utils createOrUpdatePluginByName should add an object as an argument 1`] = ` -"[new Plugin({ - \\"foo\\": true -})]" -`; - -exports[`utils createOrUpdatePluginByName should create a new plugin with arguments 1`] = ` -"{ plugins: [new Plugin({ - \\"foo\\": \\"bar\\" -})] }" -`; - -exports[`utils createOrUpdatePluginByName should create a new plugin without arguments 1`] = `"{ plugins: [new Plugin()] }"`; - -exports[`utils createOrUpdatePluginByName should merge options objects 1`] = ` -"[new Plugin({ - \\"foo\\": false, - \\"bar\\": \\"baz\\", - \\"baz-long\\": true -})]" -`; - -exports[`utils createProperty should create properties for Boolean 1`] = ` -"{ - \\"foo\\": true -}" -`; - -exports[`utils createProperty should create properties for Number 1`] = ` -"{ - \\"foo\\": -1 -}" -`; - -exports[`utils createProperty should create properties for String 1`] = ` -"{ - \\"foo\\": \\"bar\\" -}" -`; - -exports[`utils createProperty should create properties for complex keys 1`] = ` -"{ - \\"foo-bar\\": \\"bar\\" -}" -`; - -exports[`utils createProperty should create properties for non-literal keys 1`] = ` -"{ - 1: \\"bar\\" -}" -`; - -exports[`utils getRequire should create a require statement 1`] = `"const filesys = require(\\"fs\\");"`; - -exports[`utils isAssignment should allow custom transform functions instead of singularProperty 1`] = ` -"module.exports = { - plugins: [one, two, three] -}" -`; - -exports[`utils isAssignment should invoke a callback if parent type is AssignmentExpression 1`] = ` -"module.exports = { - context: Heyho -}" -`; - -exports[`utils loopThroughObjects Use recursion and add elements to an node 1`] = ` -"module.exports = { - hello: { - webpack: cli - } -}" -`; - -exports[`utils pushCreateProperty should create an object or property and push the value to a node 1`] = ` -"module.exports = { - pushMe: { - just: pushed - } - }" -`; - -exports[`utils pushObjectKeys should push object to an node using Object.keys 1`] = ` -"module.exports = { - pushMe: { - hello: { - world: { - its: 'great' - } - } - } - }" -`; diff --git a/lib/transformations/__testfixtures__/failing.js b/lib/transformations/__testfixtures__/failing.js deleted file mode 100644 index 95de24dcb82..00000000000 --- a/lib/transformations/__testfixtures__/failing.js +++ /dev/null @@ -1,81 +0,0 @@ -var webpack = require('webpack'); -var nodeEnvironment = process.env.NODE_ENV -var _ = require('lodash'); - -var 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; \ No newline at end of file diff --git a/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap b/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap deleted file mode 100644 index c5460f20376..00000000000 --- a/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`bannerPlugin transforms correctly using "bannerPlugin-0" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.BannerPlugin({ - raw: true, - entryOnly: true, - 'banner': 'Banner' - }) - ] -} -" -`; - -exports[`bannerPlugin transforms correctly using "bannerPlugin-1" data 1`] = ` -"// Should do nothing if there is no banner plugin -module.exports = { - plugins: [] -} -" -`; - -exports[`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/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig b/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js deleted file mode 100644 index 56c89e72d84..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js deleted file mode 100644 index 0d66b9de1ac..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js deleted file mode 100644 index 90ecde8f0de..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/bannerPlugin.js b/lib/transformations/bannerPlugin/bannerPlugin.js deleted file mode 100644 index 9f40d172f7d..00000000000 --- a/lib/transformations/bannerPlugin/bannerPlugin.js +++ /dev/null @@ -1,19 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - return utils.findPluginsByName(j, ast, ['webpack.BannerPlugin']) - .forEach(path => { - const args = path.value.arguments; - // If the first argument is a literal replace it with object notation - // See https://webpack.js.org/guides/migrating/#bannerplugin-breaking-change - if (args && args.length > 1 && args[0].type === j.Literal.name) { - // and remove the first argument - path.value.arguments = [path.value.arguments[1]]; - utils.createOrUpdatePluginByName(j, path.parent, 'webpack.BannerPlugin', { - banner: args[0].value - }); - } - }); - - -}; diff --git a/lib/transformations/bannerPlugin/bannerPlugin.test.js b/lib/transformations/bannerPlugin/bannerPlugin.test.js deleted file mode 100644 index fee919e427e..00000000000 --- a/lib/transformations/bannerPlugin/bannerPlugin.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-0'); -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-1'); -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-2'); diff --git a/lib/transformations/defineTest.js b/lib/transformations/defineTest.js deleted file mode 100644 index 2824337e41e..00000000000 --- a/lib/transformations/defineTest.js +++ /dev/null @@ -1,65 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); - -/** - * Utility function to run a jscodeshift script within a unit test. This makes - * several assumptions about the environment: - * - * - `dirName` contains the name of the directory the test is located in. This - * should normally be passed via __dirname. - * - The test should be located in a subdirectory next to the transform itself. - * Commonly tests are located in a directory called __tests__. - * - `transformName` contains the filename of the transform being tested, - * excluding the .js extension. - * - `testFilePrefix` optionally contains the name of the file with the test - * data. If not specified, it defaults to the same value as `transformName`. - * This will be suffixed with ".input.js" for the input file and ".output.js" - * for the expected output. For example, if set to "foo", we will read the - * "foo.input.js" file, pass this to the transform, and expect its output to - * be equal to the contents of "foo.output.js". - * - Test data should be located in a directory called __testfixtures__ - * alongside the transform and __tests__ directory. - */ -function runSingleTansform(dirName, transformName, testFilePrefix, initOptions) { - if (!testFilePrefix) { - testFilePrefix = transformName; - } - const fixtureDir = path.join(dirName, '__testfixtures__'); - const inputPath = path.join(fixtureDir, testFilePrefix + '.input.js'); - const source = fs.readFileSync(inputPath, 'utf8'); - // Assumes transform and test are on the same level - const module = require(path.join(dirName, transformName + '.js')); - // Handle ES6 modules using default export for the transform - const transform = module.default ? module.default : module; - - // Jest resets the module registry after each test, so we need to always get - // a fresh copy of jscodeshift on every test run. - let jscodeshift = require('jscodeshift/dist/core'); - if (module.parser) { - jscodeshift = jscodeshift.withParser(module.parser); - } - const ast = jscodeshift(source); - if (initOptions || typeof(initOptions) === 'boolean') { - return transform(jscodeshift, ast, initOptions).toSource({ quote: 'single' }); - } - return transform(jscodeshift, ast, source).toSource({ quote: 'single' }); -} - -/** - * Handles some boilerplate around defining a simple jest/Jasmine test for a - * jscodeshift transform. - */ -function defineTest(dirName, transformName, testFilePrefix, type) { - const testName = testFilePrefix - ? `transforms correctly using "${testFilePrefix}" data` - : 'transforms correctly'; - describe(transformName, () => { - it(testName, () => { - const output = runSingleTansform(dirName, transformName, testFilePrefix, type); - expect(output).toMatchSnapshot(); - }); - }); -} -module.exports = defineTest; diff --git a/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap b/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap deleted file mode 100644 index 0726589536c..00000000000 --- a/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap +++ /dev/null @@ -1,24 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`extractTextPlugin transforms correctly 1`] = ` -"let ExtractTextPlugin = require('extract-text-webpack-plugin'); -let HTMLWebpackPlugin = require('html-webpack-plugin'); - -module.export = { - module: { - rules: [ - { - test: /\\\\.css$/, - use: ExtractTextPlugin.extract({ - 'fallback': 'style-loader', - 'use': 'css-loader' - }) - } - ] - }, - plugins: [ - new ExtractTextPlugin(\\"styles.css\\"), - ] -} -" -`; diff --git a/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig b/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js b/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js deleted file mode 100644 index f578bb4342d..00000000000 --- a/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js +++ /dev/null @@ -1,16 +0,0 @@ -let ExtractTextPlugin = require('extract-text-webpack-plugin'); -let HTMLWebpackPlugin = require('html-webpack-plugin'); - -module.export = { - module: { - rules: [ - { - test: /\.css$/, - use: ExtractTextPlugin.extract('style-loader', 'css-loader') - } - ] - }, - plugins: [ - new ExtractTextPlugin("styles.css"), - ] -} diff --git a/lib/transformations/extractTextPlugin/extractTextPlugin.js b/lib/transformations/extractTextPlugin/extractTextPlugin.js deleted file mode 100644 index 3d60fedffdb..00000000000 --- a/lib/transformations/extractTextPlugin/extractTextPlugin.js +++ /dev/null @@ -1,32 +0,0 @@ -const utils = require('../utils'); - -function findInvocation(j, node, pluginName) { - return j(node) - .find(j.MemberExpression) - .filter(p => p.get('object').value.name === pluginName).size() > 0; -} - -module.exports = function(j, ast) { - const changeArguments = function(p) { - const args = p.value.arguments; - // if(args.length === 1) { - // return p; - // } else - const literalArgs = args.filter(p => utils.isType(p, 'Literal')); - if (literalArgs && literalArgs.length > 1) { - const newArgs = j.objectExpression(literalArgs.map((p, index) => - utils.createProperty(j, index === 0 ? 'fallback': 'use', p.value) - )); - p.value.arguments = [newArgs]; - } - return p; - }; - const name = utils.findVariableToPlugin(j, ast, 'extract-text-webpack-plugin'); - if(!name) return ast; - - return ast.find(j.CallExpression) - .filter(p => findInvocation(j, p, name)) - .forEach(changeArguments); -}; - - diff --git a/lib/transformations/extractTextPlugin/extractTextPlugin.test.js b/lib/transformations/extractTextPlugin/extractTextPlugin.test.js deleted file mode 100644 index 66d74802356..00000000000 --- a/lib/transformations/extractTextPlugin/extractTextPlugin.test.js +++ /dev/null @@ -1,3 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'extractTextPlugin'); diff --git a/lib/transformations/index.js b/lib/transformations/index.js deleted file mode 100644 index 721b66612f5..00000000000 --- a/lib/transformations/index.js +++ /dev/null @@ -1,72 +0,0 @@ -const jscodeshift = require('jscodeshift'); -const pEachSeries = require('p-each-series'); -const PLazy = require('p-lazy'); - -const loadersTransform = require('./loaders/loaders'); -const resolveTransform = require('./resolve/resolve'); -const removeJsonLoaderTransform = require('./removeJsonLoader/removeJsonLoader'); -const uglifyJsPluginTransform = require('./uglifyJsPlugin/uglifyJsPlugin'); -const loaderOptionsPluginTransform = require('./loaderOptionsPlugin/loaderOptionsPlugin'); -const bannerPluginTransform = require('./bannerPlugin/bannerPlugin'); -const extractTextPluginTransform = require('./extractTextPlugin/extractTextPlugin'); -const removeDeprecatedPluginsTransform = require('./removeDeprecatedPlugins/removeDeprecatedPlugins'); - -const transformsObject = { - loadersTransform, - resolveTransform, - removeJsonLoaderTransform, - uglifyJsPluginTransform, - loaderOptionsPluginTransform, - bannerPluginTransform, - extractTextPluginTransform, - removeDeprecatedPluginsTransform -}; - -const transformations = Object.keys(transformsObject).reduce((res, key) => { - res[key] = (ast, source) => transformSingleAST(ast, source, transformsObject[key]); - return res; -}, {}); - -function transformSingleAST(ast, source, transformFunction) { - return new PLazy((resolve, reject) => { - setTimeout(() => { - try { - resolve(transformFunction(jscodeshift, ast, source)); - } catch (err) { - reject(err); - } - }, 0); - }); -} - -/* - * @function transform - * - * Tranforms a given source code by applying selected transformations to the AST - * - * @param { String } source - Source file contents - * @param { Array } transformations - List of trnasformation functions in defined the - * order to apply. By default all defined transfomations. - * @param { Object } options - Reacst formatting options - * @returns { String } Transformed source code - * */ -function transform(source, transforms, options) { - const ast = jscodeshift(source); - const recastOptions = Object.assign({ - quote: 'single' - }, options); - transforms = transforms || Object.keys(transformations).map(k => transformations[k]); - return pEachSeries(transforms, f => f(ast, source)) - .then(() => { - return ast.toSource(recastOptions); - }) - .catch(err => { - console.error(err); - }); -} - -module.exports = { - transform, - transformSingleAST, - transformations -}; diff --git a/lib/transformations/index.test.js b/lib/transformations/index.test.js deleted file mode 100644 index 4953beb8640..00000000000 --- a/lib/transformations/index.test.js +++ /dev/null @@ -1,64 +0,0 @@ -const transform = require('./index').transform; -const transformations = require('./index').transformations; - -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).toEqual(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/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap b/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap deleted file mode 100644 index 7dfde2ced53..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap +++ /dev/null @@ -1,60 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-0" data 1`] = ` -"// Do not create LoaderOptionsPlugin is not necessary -module.exports = { - plugins: [ - new SomePlugin() - ] -} -" -`; - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-1" data 1`] = ` -"module.exports = { - debug: true, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar', - 'debug': true, - 'minimize': true - }) - ] -} -" -`; - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-2" data 1`] = ` -"// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} -" -`; - -exports[`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/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig b/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js deleted file mode 100644 index e809d6a36a9..00000000000 --- a/lib/transformations/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/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js deleted file mode 100644 index 60493cf28ab..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - debug: true, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js deleted file mode 100644 index 94fad11f784..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js +++ /dev/null @@ -1,9 +0,0 @@ -// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js deleted file mode 100644 index 2a3baa56d23..00000000000 --- a/lib/transformations/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/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js b/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js deleted file mode 100644 index d959c4f56e0..00000000000 --- a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js +++ /dev/null @@ -1,28 +0,0 @@ -const isEmpty = require('lodash/isEmpty'); -const findPluginsByName = require('../utils').findPluginsByName; -const createOrUpdatePluginByName = require('../utils').createOrUpdatePluginByName; -const safeTraverse = require('../utils').safeTraverse; - -module.exports = function(j, ast) { - const loaderOptions = {}; - - // If there is debug: true, set debug: true in the plugin - // TODO: remove global debug setting - // TODO: I can't figure out how to find the topmost `debug: true`. help! - if (ast.find(j.Identifier, { name: 'debug' }).size()) { - loaderOptions.debug = true; - } - - // If there is UglifyJsPlugin, set minimize: true - if (findPluginsByName(j, ast, ['webpack.optimize.UglifyJsPlugin']).size()) { - loaderOptions.minimize = true; - } - - return ast - .find(j.ArrayExpression) - .filter(path => safeTraverse(path, ['parent', 'value', 'key', 'name']) === 'plugins') - .forEach(path => { - !isEmpty(loaderOptions) && - createOrUpdatePluginByName(j, path, 'webpack.optimize.LoaderOptionsPlugin', loaderOptions); - }); -}; diff --git a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js b/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js deleted file mode 100644 index 1339fc4bf35..00000000000 --- a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-0'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-1'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-2'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-3'); diff --git a/lib/transformations/loaders/__snapshots__/loaders.test.js.snap b/lib/transformations/loaders/__snapshots__/loaders.test.js.snap deleted file mode 100644 index b3c6522cca2..00000000000 --- a/lib/transformations/loaders/__snapshots__/loaders.test.js.snap +++ /dev/null @@ -1,169 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaders transforms correctly using "loaders-0" data 1`] = ` -"export default [{ - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - 'loader': 'style' - }, { - 'loader': 'css?modules&importLoaders=1&string=test123' - }] - }] - } -}, { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - options: { - modules: true - } - }] - }] - } -}, { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -}, { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -}]; -" -`; - -exports[`loaders transforms correctly using "loaders-1" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - 'loader': 'style' - }, { - 'loader': 'css?modules&importLoaders=1&string=test123' - }] - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-2" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - options: { - modules: true - } - }] - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-3" data 1`] = ` -"export default { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-4" data 1`] = ` -"export default { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-5" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-6" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -} -" -`; diff --git a/lib/transformations/loaders/__testfixtures__/.editorconfig b/lib/transformations/loaders/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/loaders/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/loaders/__testfixtures__/loaders-0.input.js b/lib/transformations/loaders/__testfixtures__/loaders-0.input.js deleted file mode 100644 index e0d498f6506..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-0.input.js +++ /dev/null @@ -1,65 +0,0 @@ -export default [{ - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel' - }] - } -}, { - module: { - loaders: [{ - test: /\.css$/, - loader: 'style!css?modules&importLoaders=1&string=test123' - }] - } -}, { - module: { - loaders: [{ - test: /\.css$/, - loaders: [{ - loader: 'style' - }, { - loader: 'css', - query: { - modules: true - } - }] - }] - } -}, { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint' - }] - } -}, { - module: { - postLoaders:[{ - test: /\.js$/, - loader: 'my-post' - }] - } -}, { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint-loader' - }], - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }] - } -}, { - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }], - postLoaders:[{ - test: /\.js$/, - loader: 'my-post-loader' - }] - } -}]; diff --git a/lib/transformations/loaders/__testfixtures__/loaders-1.input.js b/lib/transformations/loaders/__testfixtures__/loaders-1.input.js deleted file mode 100644 index eae75024e61..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-1.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.css$/, - loader: 'style!css?modules&importLoaders=1&string=test123' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-2.input.js b/lib/transformations/loaders/__testfixtures__/loaders-2.input.js deleted file mode 100644 index 771404a300c..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-2.input.js +++ /dev/null @@ -1,15 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.css$/, - loaders: [{ - loader: 'style' - }, { - loader: 'css', - query: { - modules: true - } - }] - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-3.input.js b/lib/transformations/loaders/__testfixtures__/loaders-3.input.js deleted file mode 100644 index 4d49e89a89b..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-3.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-4.input.js b/lib/transformations/loaders/__testfixtures__/loaders-4.input.js deleted file mode 100644 index cc3e076bed9..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-4.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - postLoaders:[{ - test: /\.js$/, - loader: 'my-post' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-5.input.js b/lib/transformations/loaders/__testfixtures__/loaders-5.input.js deleted file mode 100644 index 6fd315e4d08..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-5.input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint-loader' - }], - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-6.input.js b/lib/transformations/loaders/__testfixtures__/loaders-6.input.js deleted file mode 100644 index 184e4e1ad08..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-6.input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }], - postLoaders:[{ - test: /\.js$/, - loader: 'my-post-loader' - }] - } -} diff --git a/lib/transformations/loaders/loaders.js b/lib/transformations/loaders/loaders.js deleted file mode 100644 index 2bb15f17a24..00000000000 --- a/lib/transformations/loaders/loaders.js +++ /dev/null @@ -1,137 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - - const createArrayExpression = function(p) { - let objs = p.parent.node.value.value.split('!') - .map(val => j.objectExpression([ - utils.createProperty(j, 'loader', val) - ])); - let loaderArray = j.arrayExpression(objs); - p.parent.node.value = loaderArray; - return p; - }; - - const createLoaderWithQuery = p => { - let properties = p.value.properties; - let loaderValue = properties - .reduce((val, prop) => prop.key.name === 'loader' ? prop.value.value : val, ''); - let loader = loaderValue.split('?')[0]; - let query = loaderValue.split('?')[1]; - let options = query.split('&').map(option => { - const param = option.split('='); - const key = param[0]; - const val = param[1] || true; // No value in query string means it is truthy value - return j.objectProperty(j.identifier(key), utils.createLiteral(val)); - }); - let loaderProp = utils.createProperty(j, 'loader', loader); - let queryProp = j.property('init', j.identifier('options'), j.objectExpression(options)); - return j.objectExpression([loaderProp, queryProp]); - }; - - const findLoaderWithQueryString = p => { - return p.value.properties - .reduce((predicate, prop) => { - return utils.safeTraverse(prop, ['value', 'value', 'indexOf']) - && prop.value.value.indexOf('?') > -1 - || predicate; - }, false); - }; - - const checkForLoader = p => p.value.name === 'loaders' && utils.safeTraverse(p, - ['parent', 'parent', 'parent', 'node', 'key', 'name']) === 'module'; - - const fitIntoLoaders = p => { - let loaders; - p.value.properties.map(prop => { - const keyName = prop.key.name; - if (keyName === 'loaders') { - loaders = prop.value; - } - }); - p.value.properties.map(prop => { - const keyName = prop.key.name; - if (keyName !== 'loaders') { - const enforceVal = keyName === 'preLoaders' ? 'pre' : 'post'; - - prop.value.elements.map(elem => { - elem.properties.push(utils.createProperty(j, 'enforce', enforceVal)); - if (loaders && loaders.type === 'ArrayExpression') { - loaders.elements.push(elem); - } else { - prop.key.name = 'loaders'; - } - }); - } - }); - if (loaders) { - p.value.properties = p.value.properties.filter(prop => prop.key.name === 'loaders'); - } - return p; - }; - - const prepostLoaders = () => ast - .find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, ['preLoaders', 'postLoaders'])) - .forEach(p => p = fitIntoLoaders(p)); - - const loadersToRules = () => ast - .find(j.Identifier) - .filter(checkForLoader) - .forEach(p => p.value.name = 'rules'); - - const loaderToUse = () => ast - .find(j.Identifier) - .filter(p => { - return (p.value.name === 'loaders' || p.value.name === 'loader') - && utils.safeTraverse(p, - ['parent', 'parent', 'parent', 'parent', 'node', 'key', 'name']) === 'rules'; - }) - .forEach(p => p.value.name = 'use'); - - const loadersInArray = () => ast - .find(j.Identifier) - .filter(p => { - return p.value.name === 'use' - && p.parent.node.value.type === 'Literal' - && p.parent.node.value.value.indexOf('!') > 0; - }) - .forEach(createArrayExpression); - - const loaderWithQueryParam = () => ast - .find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, 'loader')) - .filter(findLoaderWithQueryString) - .replaceWith(createLoaderWithQuery); - - const loaderWithQueryProp = () => ast - .find(j.Identifier) - .filter(p => p.value.name === 'query') - .replaceWith(j.identifier('options')); - - const addLoaderSuffix = () => ast - .find(j.ObjectExpression) - .forEach(path => { - path.value.properties.forEach(prop => { - if ((prop.key.name === 'loader' || prop.key.name === 'use') - && utils.safeTraverse(prop, ['value', 'value']) - && prop.value.value.indexOf('-loader') === -1) { - prop.value = j.literal(prop.value.value + '-loader'); - } - }); - }) - .toSource(); - - const transforms = [ - prepostLoaders, - loadersToRules, - loaderToUse, - loadersInArray, - loaderWithQueryParam, - loaderWithQueryProp, - addLoaderSuffix - ]; - transforms.forEach(t => t()); - - return ast; -}; diff --git a/lib/transformations/loaders/loaders.test.js b/lib/transformations/loaders/loaders.test.js deleted file mode 100644 index 3e77665cbe2..00000000000 --- a/lib/transformations/loaders/loaders.test.js +++ /dev/null @@ -1,9 +0,0 @@ -const defineTest = require('../defineTest'); - -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'); diff --git a/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap b/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap deleted file mode 100644 index 27e07047768..00000000000 --- a/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap +++ /dev/null @@ -1,30 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`outputPath transforms correctly using "outputPath-0" data 1`] = ` -"module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} -" -`; - -exports[`outputPath transforms correctly using "outputPath-1" data 1`] = ` -"const path = require('path'); -module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} -" -`; - -exports[`outputPath transforms correctly using "outputPath-2" data 1`] = ` -"const p = require('path'); -module.exports = { - output: { - path: p.join(__dirname, 'dist') - } -} -" -`; diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js deleted file mode 100644 index 085268fadbe..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - path: 'dist' - } -} diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js deleted file mode 100644 index c7a0ed58e7a..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -const path = require('path'); -module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js deleted file mode 100644 index de8436ae6c3..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -const p = require('path'); -module.exports = { - output: { - path: 'dist' - } -} diff --git a/lib/transformations/outputPath/outputPath.js b/lib/transformations/outputPath/outputPath.js deleted file mode 100644 index 78226dc345f..00000000000 --- a/lib/transformations/outputPath/outputPath.js +++ /dev/null @@ -1,51 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - const literalOutputPath = ast - .find(j.ObjectExpression) - .filter(p => utils.safeTraverse(p, ['parentPath', 'value', 'key', 'name']) === 'output') - .find(j.Property) - .filter(p => utils.safeTraverse(p, ['value', 'key', 'name']) === 'path' - && utils.safeTraverse(p, ['value', 'value', 'type']) === 'Literal'); - - if (literalOutputPath) { - let pathVarName = 'path'; - let isPathPresent = false; - const pathDecalaration = ast - .find(j.VariableDeclarator) - .filter(p => utils.safeTraverse(p, ['value', 'init', 'callee', 'name']) === 'require') - .filter(p => utils.safeTraverse(p, ['value', 'init', 'arguments']) - && p.value.init.arguments.reduce((isPresent, a) => { - return a.type === 'Literal' && a.value === 'path' || isPresent; - }, false)); - - if (pathDecalaration) { - isPathPresent = true; - pathDecalaration.forEach(p => { - pathVarName = utils.safeTraverse(p, ['value', 'id', 'name']); - }); - } - - literalOutputPath - .find(j.Literal) - .replaceWith(p => replaceWithPath(j, p, pathVarName)); - - if(!isPathPresent){ - const pathRequire = utils.getRequire(j, 'path', 'path'); - return ast.find(j.Program) - .replaceWith(p => j.program([].concat(pathRequire).concat(p.value.body))); - } - } - return ast; -}; - -function replaceWithPath(j, p, pathVarName) { - const convertedPath = j.callExpression( - j.memberExpression( - j.identifier(pathVarName), - j.identifier('join'), - false), - [j.identifier('__dirname'), p.value]); - return convertedPath; -} - diff --git a/lib/transformations/outputPath/outputPath.test.js b/lib/transformations/outputPath/outputPath.test.js deleted file mode 100644 index d1041b30274..00000000000 --- a/lib/transformations/outputPath/outputPath.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'outputPath', 'outputPath-0'); -defineTest(__dirname, 'outputPath', 'outputPath-1'); -defineTest(__dirname, 'outputPath', 'outputPath-2'); diff --git a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap b/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap deleted file mode 100644 index 550faf1fba2..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap +++ /dev/null @@ -1,44 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-0" data 1`] = ` -"// Works for OccurrenceOrderPlugin -module.exports = {} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-1" data 1`] = ` -"// Works for DedupePlugin -module.exports = {} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-2" data 1`] = ` -"// Doesn't remove unmatched plugins -module.exports = { - plugins: [new webpack.optimize.UglifyJsPlugin()] -} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-3" data 1`] = ` -"// This should throw -export default (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[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-4" data 1`] = ` -"// This should throw -const inst = new webpack.optimize.OccurrenceOrderPlugin() -export default (config) => { - config.plugins = [ - inst - ] - return config -} -" -`; diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js deleted file mode 100644 index 133c4984bfd..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Works for OccurrenceOrderPlugin -module.exports = { - plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js deleted file mode 100644 index a64dab79b37..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Works for DedupePlugin -module.exports = { - plugins: [ - new webpack.optimize.DedupePlugin(), - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js deleted file mode 100644 index 26150117db4..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// Doesn't remove unmatched plugins -module.exports = { - plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.DedupePlugin() - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js deleted file mode 100644 index 1d5194460e3..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js +++ /dev/null @@ -1,7 +0,0 @@ -// This should throw -export default (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/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js deleted file mode 100644 index fab47caf971..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// This should throw -const inst = new webpack.optimize.OccurrenceOrderPlugin() -export default (config) => { - config.plugins = [ - inst - ] - return config -} diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js deleted file mode 100644 index a3d193800f3..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js +++ /dev/null @@ -1,47 +0,0 @@ -const codeFrame = require('babel-code-frame'); -const chalk = require('chalk'); -const utils = require('../utils'); - -const example = `plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.DedupePlugin() -]`; - -module.exports = function(j, ast, source) { - // List of deprecated plugins to remove - // each item refers to webpack.optimize.[NAME] construct - const deprecatedPlugingsList = [ - 'webpack.optimize.OccurrenceOrderPlugin', - 'webpack.optimize.DedupePlugin' - ]; - - return utils.findPluginsByName(j, ast, deprecatedPlugingsList) - .forEach(path => { - // For now we only support the case there plugins are defined in an Array - const arrayPath = utils.safeTraverse(path, ['parent','value']); - if (arrayPath && utils.isType(arrayPath, 'ArrayExpression')) { - // Check how many plugins are defined and - // if there is only last plugin left remove `plugins: []` node - const arrayElementsPath = utils.safeTraverse(arrayPath, ['elements']); - if (arrayElementsPath && arrayElementsPath.length === 1) { - j(path.parent.parent).remove(); - } else { - j(path).remove(); - } - } else { - const startLoc = path.value.loc.start; - console.log(` -${ chalk.red('Only plugins instantiated in the array can be automatically removed i.e.:') } - -${ codeFrame(example, null, null, { highlightCode: true }) } - -${ chalk.red('but you use it like this:') } - -${ codeFrame(source, startLoc.line, startLoc.column, { highlightCode: true }) } - -${ chalk.red('Please remove deprecated plugins manually. ') } -See ${ chalk.underline('https://webpack.js.org/guides/migrating/')} for more information.`); - } - }); -}; diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js deleted file mode 100644 index 748a0c35ea1..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js +++ /dev/null @@ -1,7 +0,0 @@ -const defineTest = require('../defineTest'); - -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/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap b/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap deleted file mode 100644 index d678b8950c8..00000000000 --- a/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap +++ /dev/null @@ -1,51 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-0" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: ['another-loader', 'yml-loader'] - }] - } -} - -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-1" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: 'yml-loader' - }] - } -} -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-2" data 1`] = ` -"export default { - module: { - rules: [] - } -} -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-3" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: ['another-loader', 'yml-loader'] - }, { - test: /\\\\.yml/, - use: 'yml-loader' - }] - } -} - -" -`; diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig b/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js deleted file mode 100644 index f6c9a9da3ab..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js +++ /dev/null @@ -1,9 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'another-loader', 'yml-loader'] - }] - } -} - diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js deleted file mode 100644 index 05d06f79820..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'yml-loader'] - }] - } -} diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js deleted file mode 100644 index cc35396659d..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js +++ /dev/null @@ -1,10 +0,0 @@ -export default { - module: { - rules: [ - { - test: /\.json/, - use: 'json-loader' - } - ] - } -} diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js deleted file mode 100644 index 247cb56f567..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js +++ /dev/null @@ -1,15 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'another-loader', 'yml-loader'] - }, { - test: /\.yml/, - use: ['json-loader', 'yml-loader'] - }, { - test: /\.json/, - use: 'json-loader' - }] - } -} - diff --git a/lib/transformations/removeJsonLoader/removeJsonLoader.js b/lib/transformations/removeJsonLoader/removeJsonLoader.js deleted file mode 100644 index 0b7bcbac56f..00000000000 --- a/lib/transformations/removeJsonLoader/removeJsonLoader.js +++ /dev/null @@ -1,48 +0,0 @@ -module.exports = function(j, ast) { - function getLoadersPropertyPaths(ast) { - return ast.find(j.Property, { key: { name: 'use' } }); - } - - function removeLoaderByName(path, name) { - const loadersNode = path.value.value; - switch (loadersNode.type) { - case j.ArrayExpression.name: { - let loaders = loadersNode.elements.map(p => p.value); - const loaderIndex = loaders.indexOf(name); - if (loaders.length && loaderIndex > -1) { - // Remove loader from the array - loaders.splice(loaderIndex, 1); - // and from AST - loadersNode.elements.splice(loaderIndex, 1); - } - - // If there is only one element left, convert to string - if (loaders.length === 1) { - j(path.get('value')).replaceWith(j.literal(loaders[0])); - } - break; - } - case j.Literal.name: { - // If only the loader with the matching name was used - // we can remove the whole Property node completely - if (loadersNode.value === name) { - j(path.parent).remove(); - } - break; - } - } - } - - function removeLoaders(ast) { - getLoadersPropertyPaths(ast) - .forEach(path => removeLoaderByName(path, 'json-loader')); - } - - const transforms = [ - removeLoaders - ]; - - transforms.forEach(t => t(ast)); - - return ast; -}; diff --git a/lib/transformations/removeJsonLoader/removeJsonLoader.test.js b/lib/transformations/removeJsonLoader/removeJsonLoader.test.js deleted file mode 100644 index 164f0045ee1..00000000000 --- a/lib/transformations/removeJsonLoader/removeJsonLoader.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-0'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-1'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-2'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-3'); diff --git a/lib/transformations/resolve/__snapshots__/resolve.test.js.snap b/lib/transformations/resolve/__snapshots__/resolve.test.js.snap deleted file mode 100644 index 820fc965a13..00000000000 --- a/lib/transformations/resolve/__snapshots__/resolve.test.js.snap +++ /dev/null @@ -1,24 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`resolve transforms correctly 1`] = ` -"import path from 'path'; - -export default [{ - resolve: { - modules: [path.resolve('/src')] - } -}, { - resolve: { - modules: [path.resolve('/src')] - } -}, { - resolve: { - modules: [path.resolve('/src'), 'node_modules'] - } -}, { - resolve: { - modules: ['node_modules', path.resolve('/src')] - } -}]; -" -`; diff --git a/lib/transformations/resolve/__testfixtures__/.editorconfig b/lib/transformations/resolve/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/resolve/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/resolve/__testfixtures__/resolve.input.js b/lib/transformations/resolve/__testfixtures__/resolve.input.js deleted file mode 100644 index 2b83fcf26ce..00000000000 --- a/lib/transformations/resolve/__testfixtures__/resolve.input.js +++ /dev/null @@ -1,20 +0,0 @@ -import path from 'path'; - -export default [{ - resolve: { - root: path.resolve('/src') - } -}, { - resolve: { - root: [path.resolve('/src')] - } -}, { - resolve: { - root: [path.resolve('/src'), 'node_modules'] - } -}, { - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - } -}]; diff --git a/lib/transformations/resolve/resolve.js b/lib/transformations/resolve/resolve.js deleted file mode 100644 index 3912703e9e0..00000000000 --- a/lib/transformations/resolve/resolve.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function transformer(j, ast) { - - const getRootVal = p => { - return p.node.value.properties.filter(prop => prop.key.name === 'root')[0]; - }; - - const getRootIndex = p => { - return p.node.value.properties - .reduce((rootIndex, prop, index) => { - return prop.key.name === 'root' ? index : rootIndex; - }, -1); - }; - - const isModulePresent = p => { - const modules = p.node.value.properties.filter(prop => prop.key.name === 'modules'); - return modules.length > 0 && modules[0]; - }; - - const createModuleArray = p => { - const rootVal = getRootVal(p); - let modulesVal = null; - if (rootVal.value.type === 'ArrayExpression') { - modulesVal = rootVal.value.elements; - } else { - modulesVal = [rootVal.value]; - } - let module = isModulePresent(p); - - if (!module) { - module = j.property('init', j.identifier('modules'), j.arrayExpression(modulesVal)); - p.node.value.properties = p.node.value.properties.concat([module]); - } else { - module.value.elements = module.value.elements.concat(modulesVal); - } - const rootIndex = getRootIndex(p); - p.node.value.properties.splice(rootIndex, 1); - return p; - }; - - return ast - .find(j.Property) - .filter(p => { - return p.node.key.name === 'resolve' - && p.node.value.properties - .filter(prop => prop.key.name === 'root') - .length === 1; - }) - .forEach(createModuleArray); -}; diff --git a/lib/transformations/resolve/resolve.test.js b/lib/transformations/resolve/resolve.test.js deleted file mode 100644 index 30a26b5348b..00000000000 --- a/lib/transformations/resolve/resolve.test.js +++ /dev/null @@ -1,3 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'resolve'); diff --git a/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap b/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap deleted file mode 100644 index 9d5fb3b28bb..00000000000 --- a/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }) - ] -} -" -`; - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-1" data 1`] = ` -"module.exports = { - devtool: \\"source-map\\", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }) - ] -} -" -`; - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-2" data 1`] = ` -"module.exports = { - devtool: \\"cheap-source-map\\", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - compress: {}, - sourceMap: true - }) - ] -} -" -`; diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig b/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js deleted file mode 100644 index 900f7042075..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - plugins: [ - new webpack.optimize.UglifyJsPlugin() - ] -} diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js deleted file mode 100644 index 57d7eb1c192..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - devtool: "source-map", - plugins: [ - new webpack.optimize.UglifyJsPlugin({}) - ] -} diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js deleted file mode 100644 index 3c13f02b203..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - devtool: "cheap-source-map", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - compress: {} - }) - ] -} diff --git a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js b/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js deleted file mode 100644 index f5c4a12af3b..00000000000 --- a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js +++ /dev/null @@ -1,25 +0,0 @@ -const findPluginsByName = require('../utils').findPluginsByName; - -module.exports = function(j, ast) { - - function createSourceMapsProperty() { - return j.property('init', j.identifier('sourceMap'), j.identifier('true')); - } - - return findPluginsByName(j, ast, ['webpack.optimize.UglifyJsPlugin']) - .forEach(path => { - const args = path.value.arguments; - - if (args.length) { - // Plugin is called with object as arguments - j(path) - .find(j.ObjectExpression) - .get('properties') - .value - .push(createSourceMapsProperty()); - } else { - // Plugin is called without arguments - args.push(j.objectExpression([createSourceMapsProperty()])); - } - }); -}; diff --git a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js b/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js deleted file mode 100644 index a0c309ccb1e..00000000000 --- a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-0'); -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-1'); -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-2'); diff --git a/lib/transformations/utils.js b/lib/transformations/utils.js deleted file mode 100644 index 73623e70276..00000000000 --- a/lib/transformations/utils.js +++ /dev/null @@ -1,526 +0,0 @@ -function safeTraverse(obj, paths) { - let val = obj; - let idx = 0; - - while (idx < paths.length) { - if (!val) { - return null; - } - val = val[paths[idx]]; - idx++; - } - return val; -} - -// Convert nested MemberExpressions to strings like webpack.optimize.DedupePlugin -function memberExpressionToPathString(path) { - if (path && path.object) { - return [memberExpressionToPathString(path.object), path.property.name].join('.'); - } - return path.name; -} - -// Convert Array like ['webpack', 'optimize', 'DedupePlugin'] to nested MemberExpressions -function pathsToMemberExpression(j, paths) { - if (!paths.length) { - return null; - } else if (paths.length === 1) { - return j.identifier(paths[0]); - } else { - const first = paths.slice(0, 1); - const rest = paths.slice(1); - return j.memberExpression( - pathsToMemberExpression(j, rest), - pathsToMemberExpression(j, first) - ); - } -} - -/* -* @function findPluginsByName -* -* Find paths that match `new name.space.PluginName()` for a given array of plugin names -* -* @param j — jscodeshift API -* @param { Node } node - Node to start search from -* @param { Array } pluginNamesArray - Array of plugin names like `webpack.optimize.LoaderOptionsPlugin` -* @returns Path - * */ -function findPluginsByName(j, node, pluginNamesArray) { - return node - .find(j.NewExpression) - .filter(path => { - return pluginNamesArray.some( - plugin => memberExpressionToPathString(path.get('callee').value) === plugin - ); - }); -} - -/* - * @function findPluginsRootNodes - * - * Finds the path to the `plugins: []` node - * - * @param j — jscodeshift API - * @param { Node } node - Node to start search from - * @returns Path - * */ -function findPluginsRootNodes(j, node) { - return node.find(j.Property, { key: { name: 'plugins' } }); -} - -/* - * @function createProperty - * - * Creates an Object's property with a given key and value - * - * @param j — jscodeshift API - * @param { string | number } key - Property key - * @param { string | number | boolean } value - Property value - * @returns Node - * */ -function createProperty(j, key, value) { - return j.property( - 'init', - createLiteral(j, key), - createLiteral(j, value) - ); -} - -/* - * @function createLiteral - * - * Creates an appropriate literal property - * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ - -function createLiteral(j, val) { - let literalVal = val; - // We'll need String to native type conversions - if (typeof val === 'string') { - // 'true' => true - if (val === 'true') literalVal = true; - // 'false' => false - if (val === 'false') literalVal = false; - // '1' => 1 - if (!isNaN(Number(val))) literalVal = Number(val); - } - return j.literal(literalVal); -} - -/* - * @function createIdentifierOrLiteral - * - * Creates an appropriate identifier or literal property - * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ - -function createIdentifierOrLiteral(j, val) { - let literalVal = val; - // We'll need String to native type conversions - if (typeof val === 'string' || val.__paths) { - // 'true' => true - if (val === 'true') { - literalVal = true; - return j.literal(literalVal); - } - // 'false' => false - if (val === 'false') { - literalVal = false; - return j.literal(literalVal); - } - // '1' => 1 - if (!isNaN(Number(val))) { - literalVal = Number(val); - return j.literal(literalVal); - } - - if(val.__paths) { - return createExternalRegExp(j, val); - } - // Use identifier instead - else { - return j.identifier(literalVal); - } - } - return j.literal(literalVal); -} -/* - * @function createOrUpdatePluginByName - * - * Findes or creates a node for a given plugin name string with options object - * If plugin decalaration already exist, options are merged. - * - * @param j — jscodeshift API - * @param { NodePath } rooNodePath - `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginName - ex. `webpack.optimize.LoaderOptionsPlugin` - * @param { Object } options - plugin options - * @returns void - * */ -function createOrUpdatePluginByName(j, rootNodePath, pluginName, options) { - const pluginInstancePath = findPluginsByName(j, j(rootNodePath), [pluginName]); - let optionsProps; - if (options) { - optionsProps = Object.keys(options).map(key => { - return createProperty(j, key, options[key]); - }); - } - - // If plugin declaration already exist - if (pluginInstancePath.size()) { - pluginInstancePath.forEach(path => { - // There are options we want to pass as argument - if (optionsProps) { - const args = path.value.arguments; - if (args.length) { - // Plugin is called with object as arguments - // we will merge those objects - let currentProps = j(path) - .find(j.ObjectExpression) - .get('properties'); - - optionsProps.forEach(opt => { - // Search for same keys in the existing object - const existingProps = j(currentProps) - .find(j.Identifier) - .filter(path => opt.key.value === path.value.name); - - if (existingProps.size()) { - // Replacing values for the same key - existingProps.forEach(path => { - j(path.parent).replaceWith(opt); - }); - } else { - // Adding new key:values - currentProps.value.push(opt); - } - }); - - } else { - // Plugin is called without arguments - args.push( - j.objectExpression(optionsProps) - ); - } - } - }); - } else { - let argumentsArray = []; - if (optionsProps) { - argumentsArray = [j.objectExpression(optionsProps)]; - } - const loaderPluginInstance = j.newExpression( - pathsToMemberExpression(j, pluginName.split('.').reverse()), - argumentsArray - ); - rootNodePath.value.elements.push(loaderPluginInstance); - } -} - -/* - * @function findVariableToPlugin - * - * Finds the variable to which a third party plugin is assigned to - * - * @param j — jscodeshift API - * @param { Node } rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginPackageName - ex. `extract-text-plugin` - * @returns { string } variable name - ex. 'var s = require(s) gives "s"` - * */ - -function findVariableToPlugin(j, rootNode, pluginPackageName){ - const moduleVarNames = rootNode.find(j.VariableDeclarator) - .filter(j.filters.VariableDeclarator.requiresModule(pluginPackageName)) - .nodes(); - if (moduleVarNames.length === 0) return null; - return moduleVarNames.pop().id.name; -} - -/* -* @function isType -* -* Returns true if type is given type -* @param { Node} path - pathNode -* @param { string } type - node type -* @returns {boolean} -*/ - -function isType(path, type) { - return path.type === type; -} - -function findObjWithOneOfKeys (p, keyNames) { - return p.value.properties - .reduce((predicate, prop) => { - const name = prop.key.name; - return keyNames.indexOf(name) > -1 - || predicate; - }, false); -} - -/* -* @function getRequire -* -* Returns constructed require symbol -* @param j — jscodeshift API -* @param { string } constName - Name of require -* @param { string } packagePath - path of required package -* @returns {NodePath} - the created ast -*/ - -function getRequire(j, constName, packagePath) { - return j.variableDeclaration('const', [ - j.variableDeclarator( - j.identifier(constName), - j.callExpression( - j.identifier('require'), - [j.literal(packagePath)] - ) - ) - ]); -} - -/* -* @function checkIfExistsAndAddValue -* -* If a prop exists, it overrides it, else it creates a new one -* @param j — jscodeshift API -* @param { Node } node - objectexpression to check -* @param { string } key - Key of the property -* @param { string } value - computed value of the property -* @returns - nothing -*/ - -function checkIfExistsAndAddValue(j, node, key, value) { - const existingProp = node.value.properties.filter(prop => prop.key.name === key); - let prop; - if (existingProp.length > 0){ - prop = existingProp[0]; - prop.value = value; - } else { - prop = j.property('init', j.identifier(key), value); - node.value.properties.push(prop); - } -} - -/* -* @function createEmptyArrayProperty -* -* Creates an empty array -* @param j — jscodeshift API -* @param { String } key - st name -* @returns - { Array } arr - An empty array -*/ -function createEmptyArrayProperty(j, key) { - return j.property('init', j.identifier(key), j.arrayExpression([])); -} - -/* -* @function createArrayWithChildren -* -* Creates an array and iterates on an object with properties -* @param j — jscodeshift API -* @param { String } key - object name -* @param { string } subProps - computed value of the property -* @returns - { Array } arr - An array with the object properties -*/ - -function createArrayWithChildren(j, key, subProps, shouldDropKeys) { - let arr = createEmptyArrayProperty(j, key); - if(shouldDropKeys) { - subProps.forEach( (subProperty) => { - let objectOfArray = j.objectExpression([]); - if(typeof(subProperty) !== 'string') { - loopThroughObjects(j, objectOfArray, subProperty); - arr.value.elements.push(objectOfArray); - } else { - return arr.value.elements.push(createIdentifierOrLiteral(j, subProperty)); - } - }); - } else { - Object.keys(subProps[key]).forEach( (subProperty) => { - arr.value.elements.push(createIdentifierOrLiteral(j, subProps[key][subProperty])); - }); - } - return arr; -} - -/* -* @function loopThroughObjects -* -* Loops through an object and adds property to an object with no identifier -* @param j — jscodeshift API -* @param { Node } p - node to add value to -* @param { Object } obj - Object to loop through -* @returns - { Function|Node } - Either pushes the node, or reruns until -* nothing is left -*/ - -function loopThroughObjects(j, p, obj) { - Object.keys(obj).forEach( (prop) => { - if(prop.indexOf('inject') >= 0) { - return p.properties.push(createIdentifierOrLiteral(j, obj[prop])); - } - // eslint-disable-next-line no-irregular-whitespace - if(typeof(obj[prop]) !== 'object' || obj[prop] instanceof RegExp) { - p.properties.push(createObjectWithSuppliedProperty( - j, prop, createIdentifierOrLiteral(j, obj[prop]) - )); - } else if(Array.isArray(obj[prop])) { - let arrayProp = createArrayWithChildren(j, prop, obj[prop], true); - p.properties.push(arrayProp); - } else { - let objectBlock = j.objectExpression([]); - let propertyOfBlock = createObjectWithSuppliedProperty(j, prop, objectBlock); - loopThroughObjects(j, objectBlock, obj[prop]); - p.properties.push(propertyOfBlock); - } - }); -} - -/* -* @function createObjectWithSuppliedProperty -* -* Creates an object with an supplied property as parameter -* @param j — jscodeshift API -* @param { String } key - object name -* @param { Node } prop - property to be added -* @returns - { Node } - An property with the supplied property -*/ - -function createObjectWithSuppliedProperty(j, key, prop) { - return j.property('init', j.identifier(key), prop); -} - -/* -* @function createExternalRegExp -* -* Finds a regexp property with an already parsed AST from the user -* @param j — jscodeshift API -* @param { String } prop - property to find the value at -* @returns - { Node } - A literal node with the found regexp -*/ - -function createExternalRegExp(j, prop) { - let regExpProp = prop.__paths[0].value.program.body[0].expression; - return j.literal(regExpProp.value); -} - -/* -* @function pushCreateProperty -* -* Creates a property and pushes the value to a node -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { String } key - key used as identifier -* @param { String } val - property value -* @returns - { Node } - Returns node the pushed property -*/ - -function pushCreateProperty(j, p, key, val) { - let property; - if(val.hasOwnProperty('type')) { - property = val; - } else { - property = createIdentifierOrLiteral(j, val); - } - return p.value.properties.push( - createObjectWithSuppliedProperty(j, key, property) - ); -} - -/* -* @function pushObjectKeys -* -* @param j — jscodeshift API -* @param { Node } p - path to push -* @param { Object } webpackProperties - The object to loop over -* @param { String } name - Key that will be the identifier we find and add values to -* @returns - { Node/Function } Returns a function that will push a node if -*subProperty is an array, else it will invoke a function that will push a single node -*/ - -function pushObjectKeys(j, p, webpackProperties, name) { - p.value.properties.filter(n => - (safeTraverse(n, ['key', 'name']) === name) - ).forEach( (prop) => { - Object.keys(webpackProperties).forEach( (webpackProp) => { - if(webpackProp.indexOf('inject') >= 0) { - return prop.value.properties.push(createIdentifierOrLiteral(j, webpackProperties[webpackProp])); - } - else if(Array.isArray(webpackProperties[webpackProp])) { - const propArray = createArrayWithChildren( - j, webpackProp, webpackProperties[webpackProp], true - ); - return prop.value.properties.push(propArray); - } - else if(typeof(webpackProperties[webpackProp]) !== 'object' || webpackProperties[webpackProp].__paths || webpackProperties[webpackProp] instanceof RegExp) { - return pushCreateProperty( - j, prop, webpackProp, webpackProperties[webpackProp] - ); - } else { - pushCreateProperty( - j, prop, webpackProp, j.objectExpression([]) - ); - return pushObjectKeys( - j, prop, webpackProperties[webpackProp], webpackProp - ); - } - }); - }); -} - -/* -* @function isAssignment -* -* Checks if we are at the correct node and later invokes a callback -* for the transforms to either use their own transform function or -* use pushCreateProperty if the transform doesn't expect any properties -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { Function } cb - callback to be invoked -* @param { String } identifier - key to use as property -* @param { Object } property - WebpackOptions that later will be converted via -* pushCreateProperty via WebpackOptions[identifier] -* @returns - { Function } cb - Returns the callback and pushes a new node -*/ - -function isAssignment(j, p, cb, identifier, property) { - if(p.parent.value.type === 'AssignmentExpression') { - if(j) { - return cb(j, p, identifier, property); - } - else { - return cb(p); - } - } -} - -module.exports = { - safeTraverse, - createProperty, - findPluginsByName, - findPluginsRootNodes, - createOrUpdatePluginByName, - findVariableToPlugin, - isType, - createLiteral, - createIdentifierOrLiteral, - findObjWithOneOfKeys, - getRequire, - checkIfExistsAndAddValue, - createArrayWithChildren, - createEmptyArrayProperty, - createObjectWithSuppliedProperty, - createExternalRegExp, - pushCreateProperty, - pushObjectKeys, - isAssignment, - loopThroughObjects -}; diff --git a/lib/transformations/utils.test.js b/lib/transformations/utils.test.js deleted file mode 100644 index 82a3c7a87b6..00000000000 --- a/lib/transformations/utils.test.js +++ /dev/null @@ -1,315 +0,0 @@ -const j = require('jscodeshift/dist/core'); -const utils = require('./utils'); - -describe('utils', () => { - describe('createProperty', () => { - it('should create properties for Boolean', () => { - const res = utils.createProperty(j, 'foo', true); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for Number', () => { - const res = utils.createProperty(j, 'foo', -1); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for String', () => { - const res = utils.createProperty(j, 'foo', 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for complex keys', () => { - const res = utils.createProperty(j, 'foo-bar', 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for non-literal keys', () => { - const res = utils.createProperty(j, 1, 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - }); - - describe('findPluginsByName', () => { - it('should find plugins in AST', () => { - const ast = j(` -{ foo: new webpack.optimize.UglifyJsPlugin() } -`); - const res = utils.findPluginsByName(j, ast, - ['webpack.optimize.UglifyJsPlugin']); - expect(res.size()).toEqual(1); - }); - - it('should find all plugins in AST', () => { - const ast = j(` -[ - new UglifyJsPlugin(), - new TestPlugin() -] -`); - const res = utils.findPluginsByName(j, ast, - ['UglifyJsPlugin', 'TestPlugin']); - expect(res.size()).toEqual(2); - }); - - it('should not find false positives', () => { - const ast = j(` -{ foo: new UglifyJsPlugin() } -`); - const res = utils.findPluginsByName(j, ast, - ['webpack.optimize.UglifyJsPlugin']); - expect(res.size()).toEqual(0); - }); - }); - - describe('findPluginsRootNodes', () => { - it('should find plugins: [] nodes', () => { - const ast = j(` -var a = { plugins: [], foo: { plugins: [] } } -`); - const res = utils.findPluginsRootNodes(j, ast); - expect(res.size()).toEqual(2); - }); - - it('should not find plugins: [] nodes', () => { - const ast = j(` -var a = { plugs: [] } -`); - const res = utils.findPluginsRootNodes(j, ast); - expect(res.size()).toEqual(0); - }); - }); - - describe('createOrUpdatePluginByName', () => { - it('should create a new plugin without arguments', () => { - const ast = j('{ plugins: [] }'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should create a new plugin with arguments', () => { - const ast = j('{ plugins: [] }'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { foo: 'bar' }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should add an object as an argument', () => { - const ast = j('[new Plugin()]'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { foo: true }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should merge options objects', () => { - const ast = j('[new Plugin({ foo: true })]'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { bar: 'baz', foo: false }); - utils.createOrUpdatePluginByName(j, node, 'Plugin', { 'baz-long': true }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - - describe('findVariableToPlugin', () => { - it('should find the variable name of a plugin', () => { - const ast = j(` - var packageName = require('package-name'); - var someOtherVar = somethingElse; - var otherPackage = require('other-package'); - `); - const foundVar = utils.findVariableToPlugin(j, ast, 'other-package'); - expect(foundVar).toEqual('otherPackage'); - }); - }); - - describe('createLiteral', () => { - it('should create basic literal', () => { - const literal = utils.createLiteral(j, 'stringLiteral'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - it('should create boolean', () => { - const literal = utils.createLiteral(j, 'true'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - - }); - - describe('createIdentifierOrLiteral', () => { - it('should create basic literal', () => { - const literal = utils.createIdentifierOrLiteral(j, '\'stringLiteral\''); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - it('should create boolean', () => { - const literal = utils.createIdentifierOrLiteral(j, 'true'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - }); - - describe('findObjWithOneOfKeys', () => { - it('should find keys', () => { - const ast = j(` - var ab = { - a: 1, - b: 2 - } - `); - expect(ast.find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, ['a'])).size()).toEqual(1); - }); - }); - - describe('getRequire', () => { - it('should create a require statement', () => { - const require = utils.getRequire(j, 'filesys', 'fs'); - expect(j(require).toSource()).toMatchSnapshot(); - }); - }); - - describe('checkIfExistsAndAddValue', () => { - it('should create new prop if none exist', () => { - const ast = j(` - module.exports = { - entry: 'index.js' - } - `); - ast.find(j.ObjectExpression).forEach(node => utils.checkIfExistsAndAddValue(j, node, 'externals', j.literal('React'))); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should override prop if it exists', () => { - const ast = j(` - module.exports = { - entry: 'index.js' - } - `); - ast.find(j.ObjectExpression).forEach(node => utils.checkIfExistsAndAddValue(j, node, 'entry', j.literal('app.js'))); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createArrayWithChildren', () => { - it('should find an prop that matches key and create an array with it', () => { - const ast = j('{}'); - let key = 'react'; - let reactArr = { - react: [ '\'bo\''] - }; - const arr = utils.createArrayWithChildren(j, key, reactArr, false); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should add all children of an array to a new one with a supplied key', () => { - const ast = j('{}'); - let key = 'myVeryOwnKey'; - let helloWorldArray = [ '\'hello\'', 'world']; - const arr = utils.createArrayWithChildren(j, key, helloWorldArray, true); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createEmptyArrayProperty', () => { - it('should create an array with no properties', () => { - const ast = j('{}'); - const arr = utils.createEmptyArrayProperty(j, 'its-lit'); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - - describe('createObjectWithSuppliedProperty', () => { - it('should create an object with a property supplied by us', () => { - const ast = j('{}'); - const prop = utils.createObjectWithSuppliedProperty(j, 'its-lit', j.objectExpression([])); - ast.find(j.Program).forEach(node => j(node).replaceWith(prop)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createExternalRegExp', () => { - it('should create an regExp property that has been parsed by jscodeshift', () => { - const ast = j('{}'); - const reg = j('\'\t\''); - const prop = utils.createExternalRegExp(j, reg); - ast.find(j.Program).forEach(node => j(node).replaceWith(prop)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('pushCreateProperty', () => { - it('should create an object or property and push the value to a node', () => { - const ast = j(`module.exports = { - pushMe: {} - }`); - ast.find(j.Identifier).filter(n => n.value.name === 'pushMe').forEach(node => { - const heavyNodeNoSafeTraverse = node.parentPath.value; - utils.pushCreateProperty(j, heavyNodeNoSafeTraverse, 'just', 'pushed'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('pushObjectKeys', () => { - it('should push object to an node using Object.keys', () => { - const ast = j(`module.exports = { - pushMe: {} - }`); - const webpackProperties = { - hello: { - world: { - its: '\'great\'' - } - } - }; - ast.find(j.ObjectExpression).forEach(node => { - utils.pushObjectKeys(j, node, webpackProperties, 'pushMe'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('loopThroughObjects', () => { - it('Use recursion and add elements to an node', () => { - const ast = j('module.exports = {}'); - const webpackProperties = { - hello: { - webpack: 'cli' - } - }; - ast.find(j.ObjectExpression).forEach(node => { - return utils.loopThroughObjects(j, node.value, webpackProperties); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('isAssignment', () => { - it('should invoke a callback if parent type is AssignmentExpression', () => { - const ast = j('module.exports = {}'); - const myObj = 'Heyho'; - const myKey = 'context'; - - ast.find(j.ObjectExpression) - .filter(n => utils.isAssignment(j, n, utils.pushCreateProperty, myKey, myObj)); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should allow custom transform functions instead of singularProperty', () => { - const ast = j('module.exports = {}'); - - function createPluginsProperty(p) { - const webpackProperties = { - plugins: ['one', 'two', 'three'] - }; - const pluginArray = utils.createArrayWithChildren(j, 'plugins', webpackProperties); - return p.value.properties.push(pluginArray); - } - ast.find(j.ObjectExpression) - .filter(n => utils.isAssignment(null, n, createPluginsProperty)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); -}); From b1e73914ecc844abeaed380ecc44de9077e10e31 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:04:29 -0700 Subject: [PATCH 03/15] feat: make test run using var instead of const --- lib/creator/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/creator/index.test.js b/lib/creator/index.test.js index cbe6ad75cf4..49c31e5c889 100644 --- a/lib/creator/index.test.js +++ b/lib/creator/index.test.js @@ -1,11 +1,11 @@ 'use strict'; -const replaceGeneratorName = require('./index').replaceGeneratorName; +var replaceGeneratorName = require('./index').replaceGeneratorName; describe('replaceGeneratorName', () => { it('should replace a pattern of an addon', () => { - const generatorName = replaceGeneratorName('webpack-addons-thefox'); + var generatorName = replaceGeneratorName('webpack-addons-thefox'); expect(generatorName).toEqual('generator-thefox'); }); From 73e462da585c8574d25f9444fb8faaee08142985 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:11:46 -0700 Subject: [PATCH 04/15] chore: add engines prop --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7db12acfcd6..881e711872b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ }, "main": "./bin/webpack.js", "engines": { - "node": ">=4.0.0" + "node": "4.x || 5.x || 6.x || 7.x", + "npm": "2.x || 3.x || 4.x || 5.x" }, "scripts": { "lint:bin": "eslint ./bin", From 9d722edaec7c17392ff67e6d938a67cc567af1a2 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:36:09 -0700 Subject: [PATCH 05/15] chore: move migrate to addons --- lib/migrate.js | 91 +-- lib/utils/WebpackOptionsValidationError.js | 189 ----- lib/utils/validateSchema.js | 67 -- lib/utils/webpackOptionsSchema.json | 905 --------------------- 4 files changed, 2 insertions(+), 1250 deletions(-) delete mode 100644 lib/utils/WebpackOptionsValidationError.js delete mode 100644 lib/utils/validateSchema.js delete mode 100644 lib/utils/webpackOptionsSchema.json diff --git a/lib/migrate.js b/lib/migrate.js index 5ca27a3a67c..9dd0ca591a2 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -1,92 +1,5 @@ -const fs = require('fs'); -const chalk = require('chalk'); -const diff = require('diff'); -const inquirer = require('inquirer'); -const PLazy = require('p-lazy'); -const Listr = require('listr'); -const validateSchema = require('./utils/validateSchema.js'); -const webpackOptionsSchema = require('./utils/webpackOptionsSchema.json'); -const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationError'); +const migrate = require('webpack-addons').migrate; module.exports = function transformFile(currentConfigPath, outputConfigPath, options) { - const recastOptions = Object.assign({ - quote: 'single' - }, options); - const tasks = new Listr([ - { - title: 'Reading webpack config', - task: (ctx) => new PLazy((resolve, reject) => { - fs.readFile(currentConfigPath, 'utf8', (err, content) => { - if (err) { - reject(err); - } - try { - const jscodeshift = require('jscodeshift'); - ctx.source = content; - ctx.ast = jscodeshift(content); - resolve(); - } catch (err) { - reject('Error generating AST', err); - } - }); - }) - }, - { - title: 'Migrating config from v1 to v2', - task: (ctx) => { - const transformations = require('webpack-addons').migrate; - return new Listr(Object.keys(transformations).map(key => { - const transform = transformations[key]; - return { - title: key, - task: () => transform(ctx.ast, ctx.source) - }; - })); - } - } - ]); - - tasks.run() - .then((ctx) => { - const result = ctx.ast.toSource(recastOptions); - const diffOutput = diff.diffLines(ctx.source, result); - diffOutput.forEach(diffLine => { - if (diffLine.added) { - process.stdout.write(chalk.green(`+ ${diffLine.value}`)); - } else if (diffLine.removed) { - process.stdout.write(chalk.red(`- ${diffLine.value}`)); - } - }); - inquirer - .prompt([ - { - type: 'confirm', - name: 'confirmMigration', - message: 'Are you sure these changes are fine?', - default: 'Y' - } - ]) - .then(answers => { - if (answers['confirmMigration']) { - fs.writeFile(outputConfigPath, result, 'utf8', (err) => { - const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, require(outputConfigPath)); - if (err) { - throw err; - } - else if (webpackOptionsValidationErrors.length) { - throw new WebpackOptionsValidationError(webpackOptionsValidationErrors); - } else { - console.log(chalk.green(`\n ✔︎ New webpack v2 config file is at ${outputConfigPath}`)); - } - }); - } else { - console.log(chalk.red('✖ Migration aborted')); - } - }); - }) - .catch(err => { - console.log(chalk.red('✖ ︎Migration aborted due to some errors')); - console.error(err); - process.exitCode = 1; - }); + return migrate(currentConfigPath, outputConfigPath, options); }; diff --git a/lib/utils/WebpackOptionsValidationError.js b/lib/utils/WebpackOptionsValidationError.js deleted file mode 100644 index 4fb7693faf3..00000000000 --- a/lib/utils/WebpackOptionsValidationError.js +++ /dev/null @@ -1,189 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Gajus Kuizinas @gajus -*/ -'use strict'; - -const webpackOptionsSchema = require('./webpackOptionsSchema.json'); - -const getSchemaPart = (path, parents, additionalPath) => { - parents = parents || 0; - path = path.split('/'); - path = path.slice(0, path.length - parents); - if(additionalPath) { - additionalPath = additionalPath.split('/'); - path = path.concat(additionalPath); - } - let schemaPart = webpackOptionsSchema; - for(let i = 1; i < path.length; i++) { - const inner = schemaPart[path[i]]; - if(inner) - schemaPart = inner; - } - return schemaPart; -}; - -const getSchemaPartText = (schemaPart, additionalPath) => { - if(additionalPath) { - for(let i = 0; i < additionalPath.length; i++) { - const inner = schemaPart[additionalPath[i]]; - if(inner) - schemaPart = inner; - } - } - while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref); - let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart); - if(schemaPart.description) - schemaText += `\n${schemaPart.description}`; - return schemaText; -}; - -const indent = (str, prefix, firstLine) => { - if(firstLine) { - return prefix + str.replace(/\n(?!$)/g, '\n' + prefix); - } else { - return str.replace(/\n(?!$)/g, `\n${prefix}`); - } -}; - -class WebpackOptionsValidationError extends Error { - constructor(validationErrors) { - super(); - if(Error.hasOwnProperty('captureStackTrace')) { - Error.captureStackTrace(this, this.constructor); - } - this.name = 'WebpackOptionsValidationError'; - - this.message = 'Invalid configuration object. ' + - 'Webpack has been initialised using a configuration object that does not match the API schema.\n' + - validationErrors.map(err => ' - ' + indent(WebpackOptionsValidationError.formatValidationError(err), ' ', false)).join('\n'); - this.validationErrors = validationErrors; - } - - static formatSchema(schema, prevSchemas) { - prevSchemas = prevSchemas || []; - - const formatInnerSchema = (innerSchema, addSelf) => { - if(!addSelf) return WebpackOptionsValidationError.formatSchema(innerSchema, prevSchemas); - if(prevSchemas.indexOf(innerSchema) >= 0) return '(recursive)'; - return WebpackOptionsValidationError.formatSchema(innerSchema, prevSchemas.concat(schema)); - }; - - if(schema.type === 'string') { - if(schema.minLength === 1) - return 'non-empty string'; - else if(schema.minLength > 1) - return `string (min length ${schema.minLength})`; - return 'string'; - } else if(schema.type === 'boolean') { - return 'boolean'; - } else if(schema.type === 'number') { - return 'number'; - } else if(schema.type === 'object') { - if(schema.properties) { - const required = schema.required || []; - return `object { ${Object.keys(schema.properties).map(property => { - if(required.indexOf(property) < 0) return property + '?'; - return property; - }).concat(schema.additionalProperties ? ['...'] : []).join(', ')} }`; - } - if(schema.additionalProperties) { - return `object { : ${formatInnerSchema(schema.additionalProperties)} }`; - } - return 'object'; - } else if(schema.type === 'array') { - return `[${formatInnerSchema(schema.items)}]`; - } - - switch(schema.instanceof) { - case 'Function': - return 'function'; - case 'RegExp': - return 'RegExp'; - } - if(schema.$ref) return formatInnerSchema(getSchemaPart(schema.$ref), true); - if(schema.allOf) return schema.allOf.map(formatInnerSchema).join(' & '); - if(schema.oneOf) return schema.oneOf.map(formatInnerSchema).join(' | '); - if(schema.anyOf) return schema.anyOf.map(formatInnerSchema).join(' | '); - if(schema.enum) return schema.enum.map(item => JSON.stringify(item)).join(' | '); - return JSON.stringify(schema, 0, 2); - } - - static formatValidationError(err) { - const dataPath = `configuration${err.dataPath}`; - if(err.keyword === 'additionalProperties') { - const baseMessage = `${dataPath} has an unknown property '${err.params.additionalProperty}'. These properties are valid:\n${getSchemaPartText(err.parentSchema)}`; - if(!err.dataPath) { - switch(err.params.additionalProperty) { - case 'debug': - return `${baseMessage}\n` + - 'The \'debug\' property was removed in webpack 2.\n' + - 'Loaders should be updated to allow passing this option via loader options in module.rules.\n' + - 'Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:\n' + - 'plugins: [\n' + - ' new webpack.LoaderOptionsPlugin({\n' + - ' debug: true\n' + - ' })\n' + - ']'; - } - return baseMessage + '\n' + - 'For typos: please correct them.\n' + - 'For loader options: webpack 2 no longer allows custom properties in configuration.\n' + - ' Loaders should be updated to allow passing options via loader options in module.rules.\n' + - ' Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n' + - ' plugins: [\n' + - ' new webpack.LoaderOptionsPlugin({\n' + - ' // test: /\\.xxx$/, // may apply this only for some modules\n' + - ' options: {\n' + - ` ${err.params.additionalProperty}: ...\n` + - ' }\n' + - ' })\n' + - ' ]'; - } - return baseMessage; - } else if(err.keyword === 'oneOf' || err.keyword === 'anyOf') { - if(err.children && err.children.length > 0) { - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` + - `Details:\n${err.children.map(err => ' * ' + indent(WebpackOptionsValidationError.formatValidationError(err), ' ', false)).join('\n')}`; - } - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; - - } else if(err.keyword === 'enum') { - if(err.parentSchema && err.parentSchema.enum && err.parentSchema.enum.length === 1) { - return `${dataPath} should be ${getSchemaPartText(err.parentSchema)}`; - } - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'allOf') { - return `${dataPath} should be:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'type') { - switch(err.params.type) { - case 'object': - return `${dataPath} should be an object.`; - case 'string': - return `${dataPath} should be a string.`; - case 'boolean': - return `${dataPath} should be a boolean.`; - case 'number': - return `${dataPath} should be a number.`; - case 'array': - return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`; - } - return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'instanceof') { - return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`; - } else if(err.keyword === 'required') { - const missingProperty = err.params.missingProperty.replace(/^\./, ''); - return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ['properties', missingProperty])}`; - } else if(err.keyword === 'minLength' || err.keyword === 'minItems') { - if(err.params.limit === 1) - return `${dataPath} should not be empty.`; - else - return `${dataPath} ${err.message}`; - } else { - // eslint-disable-line no-fallthrough - return `${dataPath} ${err.message} (${JSON.stringify(err, 0, 2)}).\n${getSchemaPartText(err.parentSchema)}`; - } - } -} - -module.exports = WebpackOptionsValidationError; diff --git a/lib/utils/validateSchema.js b/lib/utils/validateSchema.js deleted file mode 100644 index c6360de2367..00000000000 --- a/lib/utils/validateSchema.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Gajus Kuizinas @gajus -*/ -'use strict'; - -/* eslint-disable */ -const Ajv = require('ajv'); -const ajv = new Ajv({ - errorDataPath: 'configuration', - allErrors: true, - verbose: true -}); -require('ajv-keywords')(ajv, ['instanceof']); -/* eslint-enable */ - -function validateSchema(schema, options) { - if(Array.isArray(options)) { - const errors = options.map((options) => validateObject(schema, options)); - errors.forEach((list, idx) => { - list.forEach(function applyPrefix(err) { - err.dataPath = `[${idx}]${err.dataPath}`; - if(err.children) { - err.children.forEach(applyPrefix); - } - }); - }); - return errors.reduce((arr, items) => { - return arr.concat(items); - }, []); - } else { - return validateObject(schema, options); - } -} - -function validateObject(schema, options) { - const validate = ajv.compile(schema); - const valid = validate(options); - return valid ? [] : filterErrors(validate.errors); -} - -function filterErrors(errors) { - let newErrors = []; - errors.forEach((err) => { - const dataPath = err.dataPath; - let children = []; - newErrors = newErrors.filter((oldError) => { - if(oldError.dataPath.includes(dataPath)) { - if(oldError.children) { - children = children.concat(oldError.children.slice(0)); - } - oldError.children = undefined; - children.push(oldError); - return false; - } - return true; - }); - if(children.length) { - err.children = children; - } - newErrors.push(err); - }); - - return newErrors; -} - -module.exports = validateSchema; diff --git a/lib/utils/webpackOptionsSchema.json b/lib/utils/webpackOptionsSchema.json deleted file mode 100644 index 0d8a9741eb4..00000000000 --- a/lib/utils/webpackOptionsSchema.json +++ /dev/null @@ -1,905 +0,0 @@ -{ - "additionalProperties": false, - "definitions": { - "common.arrayOfStringOrStringArrayValues": { - "items": { - "anyOf": [ - { - "minLength": 1, - "type": "string" - }, - { - "items": { - "minLength": 1, - "type": "string" - }, - "type": "array" - } - ] - }, - "type": "array" - }, - "common.arrayOfStringValues": { - "items": { - "minLength": 1, - "type": "string" - }, - "type": "array" - }, - "common.nonEmptyArrayOfUniqueStringValues": { - "items": { - "minLength": 1, - "type": "string" - }, - "minItems": 1, - "type": "array", - "uniqueItems": true - }, - "entry": { - "description": "The entry point(s) of the compilation.", - "oneOf": [ - { - "minProperties": 1, - "additionalProperties": { - "oneOf": [ - { - "description": "The string is resolved to a module which is loaded upon startup.", - "minLength": 1, - "type": "string" - }, - { - "description": "All modules are loaded upon startup. The last one is exported.", - "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues" - } - ] - }, - "description": "Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.", - "type": "object" - }, - { - "description": "The string is resolved to a module which is loaded upon startup.", - "minLength": 1, - "type": "string" - }, - { - "allOf": [ - { - "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues" - } - ], - "description": "All modules are loaded upon startup. The last one is exported." - }, - { - "description": "function returning an entry object or a promise.", - "instanceof": "Function" - } - ] - }, - "externals": { - "anyOf": [ - { - "description": "An exact matched dependency becomes external. The same string is used as external dependency.", - "type": "string" - }, - { - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object" - }, - { - "type": "boolean" - } - ] - }, - "description": "If an dependency matches exactly a property of the object, the property value is used as dependency.", - "type": "object" - }, - { - "description": "`function(context, request, callback(err, result))` The function is called on each dependency.", - "instanceof": "Function" - }, - { - "description": "Every matched dependency becomes external.", - "instanceof": "RegExp" - }, - { - "items": { - "$ref": "#/definitions/externals" - }, - "type": "array" - } - ], - "description": "Specify dependencies that shouldn't be resolved by webpack, but should become dependencies of the resulting bundle. The kind of the dependency depends on `output.libraryTarget`." - }, - "module": { - "additionalProperties": false, - "description": "Options affecting the normal modules (`NormalModuleFactory`).", - "properties": { - "exprContextCritical": { - "type": "boolean" - }, - "exprContextRecursive": { - "type": "boolean" - }, - "exprContextRegExp": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "RegExp" - } - ] - }, - "exprContextRequest": { - "type": "string" - }, - "loaders": { - "allOf": [ - { - "$ref": "#/definitions/ruleSet-rules" - } - ], - "description": "An array of automatically applied loaders." - }, - "noParse": { - "description": "Don't parse files matching. It's matched against the full resolved request.", - "anyOf": [ - { - "items": { - "instanceof": "RegExp" - }, - "minItems": 1, - "type": "array" - }, - { - "instanceof": "RegExp" - } - ] - }, - "rules": { - "allOf": [ - { - "$ref": "#/definitions/ruleSet-rules" - } - ], - "description": "An array of rules applied for modules." - }, - "unknownContextCritical": { - "type": "boolean" - }, - "unknownContextRecursive": { - "type": "boolean" - }, - "unknownContextRegExp": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "RegExp" - } - ] - }, - "unknownContextRequest": { - "type": "string" - }, - "unsafeCache": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "Function" - } - ] - }, - "wrappedContextCritical": { - "type": "boolean" - }, - "wrappedContextRecursive": { - "type": "boolean" - }, - "wrappedContextRegExp": { - "instanceof": "RegExp" - } - }, - "type": "object" - }, - "output": { - "additionalProperties": false, - "description": "Options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.", - "properties": { - "auxiliaryComment": { - "description": "Add a comment in the UMD wrapper.", - "anyOf": [ - { - "description": "Append the same comment above each import style.", - "type": "string" - }, - { - "additionalProperties": false, - "description": "Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.", - "properties": { - "amd": { - "type": "string" - }, - "commonjs": { - "type": "string" - }, - "commonjs2": { - "type": "string" - }, - "root": { - "type": "string" - } - }, - "type": "object" - } - ] - }, - "chunkFilename": { - "description": "The filename of non-entry chunks as relative path inside the `output.path` directory.", - "type": "string" - }, - "crossOriginLoading": { - "description": "This option enables cross-origin loading of chunks.", - "enum": [ - false, - "anonymous", - "use-credentials" - ] - }, - "devtoolFallbackModuleFilenameTemplate": { - "description": "Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.", - "anyOf": [ - { - "type": "string" - }, - { - "instanceof": "Function" - } - ] - }, - "devtoolLineToLine": { - "description": "Enable line to line mapped mode for all/specified modules. Line to line mapped mode uses a simple SourceMap where each line of the generated source is mapped to the same line of the original source. It’s a performance optimization. Only use it if your performance need to be better and you are sure that input lines match which generated lines.", - "anyOf": [ - { - "description": "`true` enables it for all modules (not recommended)", - "type": "boolean" - }, - { - "description": "An object similar to `module.loaders` enables it for specific files.", - "properties": { - "exclude": { - "type": "string" - }, - "include": { - "type": "string" - }, - "test": { - "type": "string" - } - }, - "type": "object" - } - ] - }, - "devtoolModuleFilenameTemplate": { - "description": "Filename template string of function for the sources array in a generated SourceMap.", - "anyOf": [ - { - "type": "string" - }, - { - "instanceof": "Function" - } - ] - }, - "filename": { - "description": "Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.", - "type": "string" - }, - "hashDigest": { - "minLength": 1, - "type": "string" - }, - "hashDigestLength": { - "minimum": 1, - "type": "number" - }, - "hashFunction": { - "minLength": 1, - "type": "string" - }, - "hotUpdateChunkFilename": { - "description": "The filename of the Hot Update Chunks. They are inside the output.path directory.", - "type": "string" - }, - "hotUpdateFunction": { - "description": "The JSONP function used by webpack for async loading of hot update chunks.", - "type": "string" - }, - "hotUpdateMainFilename": { - "description": "The filename of the Hot Update Main File. It is inside the `output.path` directory.", - "type": "string" - }, - "jsonpFunction": { - "description": "The JSONP function used by webpack for async loading of chunks.", - "type": "string" - }, - "library": { - "anyOf": [ - { - "type": "string" - }, - { - "items": { - "type": "string" - }, - "type": "array" - } - ], - "description": "If set, export the bundle as library. `output.library` is the name." - }, - "libraryTarget": { - "enum": [ - "var", - "assign", - "this", - "window", - "global", - "commonjs", - "commonjs2", - "commonjs-module", - "amd", - "umd", - "umd2", - "jsonp" - ] - }, - "path": { - "description": "The output directory as **absolute path** (required).", - "type": "string" - }, - "pathinfo": { - "description": "Include comments with information about the modules.", - "type": "boolean" - }, - "publicPath": { - "description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.", - "type": "string" - }, - "sourceMapFilename": { - "description": "The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.", - "type": "string" - }, - "sourcePrefix": { - "description": "Prefixes every line of the source in the bundle with this string.", - "type": "string" - }, - "strictModuleExceptionHandling": { - "description": "Handles exceptions in module loading correctly at a performance cost.", - "type": "boolean" - }, - "umdNamedDefine": { - "description": "If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.", - "type": "boolean" - } - }, - "type": "object" - }, - "resolve": { - "additionalProperties": false, - "properties": { - "alias": { - "anyOf": [ - { - "additionalProperties": { - "type": "string" - }, - "type": "object" - }, - { - "items": { - "additionalProperties": false, - "properties": { - "alias": { - "type": "string" - }, - "name": { - "type": "string" - }, - "onlyModule": { - "type": "boolean" - } - }, - "type": "object" - }, - "type": "array" - } - ] - }, - "aliasFields": { - "$ref": "#/definitions/common.arrayOfStringOrStringArrayValues" - }, - "cachePredicate": { - "instanceof": "Function" - }, - "descriptionFiles": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "enforceExtension": { - "type": "boolean" - }, - "enforceModuleExtension": { - "type": "boolean" - }, - "extensions": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "fileSystem": {}, - "mainFields": { - "$ref": "#/definitions/common.arrayOfStringOrStringArrayValues" - }, - "mainFiles": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "moduleExtensions": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "modules": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "plugins": { - "type": "array" - }, - "resolver": {}, - "symlinks": { - "type": "boolean" - }, - "unsafeCache": { - "anyOf": [ - { - "type": "boolean" - }, - { - "additionalProperties": true, - "type": "object" - } - ] - }, - "useSyncFileSystemCalls": { - "type": "boolean" - } - }, - "type": "object" - }, - "ruleSet-condition": { - "anyOf": [ - { - "instanceof": "RegExp" - }, - { - "minLength": 1, - "type": "string" - }, - { - "instanceof": "Function" - }, - { - "$ref": "#/definitions/ruleSet-conditions" - }, - { - "additionalProperties": false, - "properties": { - "and": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "exclude": { - "$ref": "#/definitions/ruleSet-condition" - }, - "include": { - "$ref": "#/definitions/ruleSet-condition" - }, - "not": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "or": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "test": { - "$ref": "#/definitions/ruleSet-condition" - } - }, - "type": "object" - } - ] - }, - "ruleSet-conditions": { - "items": { - "$ref": "#/definitions/ruleSet-condition" - }, - "type": "array" - }, - "ruleSet-loader": { - "minLength": 1, - "type": "string" - }, - "ruleSet-query": { - "anyOf": [ - { - "type": "object" - }, - { - "type": "string" - } - ] - }, - "ruleSet-rule": { - "additionalProperties": false, - "properties": { - "enforce": { - "enum": [ - "pre", - "post" - ] - }, - "exclude": { - "$ref": "#/definitions/ruleSet-condition" - }, - "include": { - "$ref": "#/definitions/ruleSet-condition" - }, - "issuer": { - "$ref": "#/definitions/ruleSet-condition" - }, - "loader": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-loader" - }, - { - "$ref": "#/definitions/ruleSet-use" - } - ] - }, - "loaders": { - "$ref": "#/definitions/ruleSet-use" - }, - "oneOf": { - "$ref": "#/definitions/ruleSet-rules" - }, - "options": { - "$ref": "#/definitions/ruleSet-query" - }, - "parser": { - "additionalProperties": true, - "type": "object" - }, - "query": { - "$ref": "#/definitions/ruleSet-query" - }, - "resource": { - "$ref": "#/definitions/ruleSet-condition" - }, - "resourceQuery": { - "$ref": "#/definitions/ruleSet-condition" - }, - "rules": { - "$ref": "#/definitions/ruleSet-rules" - }, - "test": { - "$ref": "#/definitions/ruleSet-condition" - }, - "use": { - "$ref": "#/definitions/ruleSet-use" - } - }, - "type": "object" - }, - "ruleSet-rules": { - "items": { - "$ref": "#/definitions/ruleSet-rule" - }, - "type": "array" - }, - "ruleSet-use": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-use-item" - }, - { - "instanceof": "Function" - }, - { - "items": { - "$ref": "#/definitions/ruleSet-use-item" - }, - "type": "array" - } - ] - }, - "ruleSet-use-item": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-loader" - }, - { - "instanceof": "Function" - }, - { - "additionalProperties": false, - "properties": { - "loader": { - "$ref": "#/definitions/ruleSet-loader" - }, - "options": { - "$ref": "#/definitions/ruleSet-query" - }, - "query": { - "$ref": "#/definitions/ruleSet-query" - } - }, - "type": "object" - } - ] - } - }, - "properties": { - "amd": { - "description": "Set the value of `require.amd` and `define.amd`." - }, - "bail": { - "description": "Report the first error as a hard error instead of tolerating it.", - "type": "boolean" - }, - "cache": { - "description": "Cache generated modules and chunks to improve performance for multiple incremental builds.", - "anyOf": [ - { - "description": "You can pass `false` to disable it.", - "type": "boolean" - }, - { - "description": "You can pass an object to enable it and let webpack use the passed object as cache. This way you can share the cache object between multiple compiler calls.", - "type": "object" - } - ] - }, - "context": { - "description": "The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.", - "type": "string" - }, - "dependencies": { - "description": "References to other configurations to depend on.", - "items": { - "type": "string" - }, - "type": "array" - }, - "devServer": { - "type": "object" - }, - "devtool": { - "description": "A developer tool to enhance debugging.", - "anyOf": [ - { - "type": "string" - }, - { - "enum": [ - false - ] - } - ] - }, - "entry": { - "$ref": "#/definitions/entry" - }, - "externals": { - "$ref": "#/definitions/externals" - }, - "loader": { - "description": "Custom values available in the loader context.", - "type": "object" - }, - "module": { - "$ref": "#/definitions/module" - }, - "name": { - "description": "Name of the configuration. Used when loading multiple configurations.", - "type": "string" - }, - "node": { - "description": "Include polyfills or mocks for various node stuff.", - "additionalProperties": { - "enum": [ - false, - true, - "mock", - "empty" - ] - }, - "properties": { - "Buffer": { - "enum": [ - false, - true, - "mock" - ] - }, - "__dirname": { - "enum": [ - false, - true, - "mock" - ] - }, - "__filename": { - "enum": [ - false, - true, - "mock" - ] - }, - "console": { - "enum": [ - false, - true, - "mock" - ] - }, - "global": { - "type": "boolean" - }, - "process": { - "enum": [ - false, - true, - "mock" - ] - } - }, - "type": "object" - }, - "output": { - "$ref": "#/definitions/output" - }, - "performance": { - "description": "Configuration for web performance recommendations.", - "anyOf": [ - { - "enum": [ - false - ] - }, - { - "additionalProperties": false, - "properties": { - "assetFilter": { - "description": "Filter function to select assets that are checked", - "instanceof": "Function" - }, - "hints": { - "description": "Sets the format of the hints: warnings, errors or nothing at all", - "enum": [ - false, - "warning", - "error" - ] - }, - "maxEntrypointSize": { - "description": "Total size of an entry point (in bytes)", - "type": "number" - }, - "maxAssetSize": { - "description": "Filesize limit (in bytes) when exceeded, that webpack will provide performance hints", - "type": "number" - } - }, - "type": "object" - } - ] - }, - "plugins": { - "description": "Add additional plugins to the compiler.", - "type": "array" - }, - "profile": { - "description": "Capture timing information for each module.", - "type": "boolean" - }, - "recordsInputPath": { - "description": "Store compiler state to a json file.", - "type": "string" - }, - "recordsOutputPath": { - "description": "Load compiler state from a json file.", - "type": "string" - }, - "recordsPath": { - "description": "Store/Load compiler state from/to a json file. This will result in persistent ids of modules and chunks. An absolute path is expected. `recordsPath` is used for `recordsInputPath` and `recordsOutputPath` if they left undefined.", - "type": "string" - }, - "resolve": { - "$ref": "#/definitions/resolve" - }, - "resolveLoader": { - "$ref": "#/definitions/resolve" - }, - "stats": { - "description": "Used by the webpack CLI program to pass stats options.", - "anyOf": [ - { - "type": "object" - }, - { - "type": "boolean" - }, - { - "enum": [ - "none", - "errors-only", - "minimal", - "normal", - "verbose" - ] - } - ] - }, - "target": { - "anyOf": [ - { - "enum": [ - "web", - "webworker", - "node", - "async-node", - "node-webkit", - "atom", - "electron", - "electron-main", - "electron-renderer" - ] - }, - { - "instanceof": "Function" - } - ] - }, - "watch": { - "description": "Enter watch mode, which rebuilds on file change.", - "type": "boolean" - }, - "watchOptions": { - "properties": { - "aggregateTimeout": { - "description": "Delay the rebuilt after the first change. Value is a time in ms.", - "type": "number" - }, - "poll": { - "anyOf": [ - { - "description": "`true`: use polling.", - "type": "boolean" - }, - { - "description": "`number`: use polling with specified interval.", - "type": "number" - } - ] - } - }, - "type": "object" - } - }, - "required": [ - "entry" - ], - "type": "object" -} \ No newline at end of file From c020f12c3179bf4d460d948cd520777ffd0e3a15 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:47:02 -0700 Subject: [PATCH 06/15] fix: use correct naming conventions --- lib/migrate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/migrate.js b/lib/migrate.js index 9dd0ca591a2..226fb0c45ea 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -1,4 +1,4 @@ -const migrate = require('webpack-addons').migrate; +const migrate = require('webpack-addons').migrateTransform; module.exports = function transformFile(currentConfigPath, outputConfigPath, options) { return migrate(currentConfigPath, outputConfigPath, options); From 4e0f8870b58f2052bc4585460b3c427dd86bb4d8 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 11:57:15 -0700 Subject: [PATCH 07/15] feat: add default generator logic & remove old deps --- lib/creator/index.js | 19 +++++++++++++++++-- package.json | 6 +----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/creator/index.js b/lib/creator/index.js index 266995e8088..fbae21cfca6 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -1,9 +1,10 @@ const yeoman = require('yeoman-environment'); const Generator = require('yeoman-generator'); +const chalk = require('chalk'); const path = require('path'); const defaultGenerator = require('webpack-addons').WebpackGenerator; +const runTransform = require('webpack-addons').initTransform; const WebpackAdapter = require('./utils/webpack-adapter'); - /* * @function creator * @@ -30,7 +31,21 @@ function creator(options) { env.registerStub(defaultGenerator, 'webpack-default-generator'); } - return env.run(generatorName); + return env.run(generatorName).on('end', () => { + if(generatorName === 'webpack-default-generator') { + return runTransform(env.configuration).then( (didFinish) => { + if(didFinish) { + process.stdout.write('\n' + chalk.green( + 'Congratulations! Your new webpack configuration file has been created!\n' + )); + } else { + process.stdout.write('\n' + chalk.red( + 'Sorry! Your webpack configuration did not fully succeed !\n' + )); + } + }); + } + }); } /* diff --git a/package.json b/package.json index 881e711872b..e5516312349 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "babel-preset-stage-3": "^6.17.0", "chalk": "^1.1.3", "cross-spawn": "^5.0.1", - "diff": "^3.2.0", "enhanced-resolve": "^3.0.2", "fit-commit-js": "^0.3.1", "global-modules": "^0.2.3", @@ -46,18 +45,15 @@ "p-each-series": "^1.0.0", "p-lazy": "^1.0.0", "prettier": "^1.2.2", - "recast": "git://github.com/kalcifer/recast.git#bug/allowbreak", "resolve-cwd": "^2.0.0", "supports-color": "^3.1.2", "webpack": "^2.5.1", "webpack-addons": "git://github.com/webpack-contrib/webpack-addons.git#yeoman-migration", "yargs": "^6.5.0", "yeoman-environment": "^1.6.6", - "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" + "yeoman-generator": "^1.1.1" }, "devDependencies": { - "ajv": "^4.11.3", - "ajv-keywords": "^1.5.1", "babel-cli": "^6.18.0", "babel-eslint": "^6.1.2", "babel-jest": "^19.0.0", From dc2f494bd47f4f0a3479c455eecea5200f0611d8 Mon Sep 17 00:00:00 2001 From: Robert Mason Date: Thu, 18 May 2017 00:21:14 -0700 Subject: [PATCH 08/15] Fixed spelling of "separated" (#149) I know it's super trivial, but boy my 11th grade teacher sure did permanently burn the spelling of that word into my head. --- lib/creator/yeoman/utils/entry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/creator/yeoman/utils/entry.js b/lib/creator/yeoman/utils/entry.js index f1f2839e8f7..3bf92b94853 100644 --- a/lib/creator/yeoman/utils/entry.js +++ b/lib/creator/yeoman/utils/entry.js @@ -8,7 +8,7 @@ module.exports = (self, answer) => { result = self.prompt([ InputValidate( 'multipleEntries', - 'Type the name you want for your modules (entry files), seperated by comma', + 'Type the name you want for your modules (entry files), separated by comma', validate ) ]).then( (multipleEntriesAnswer) => { From 0ebf45201a4e7d1ae0ebb3f7611ae2f37884816d Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 08:46:17 -0700 Subject: [PATCH 09/15] feat: move init generator to webpack-addons --- lib/creator/index.js | 4 +- lib/creator/utils/validate-options.js | 37 -- lib/creator/utils/validate-options.spec.js | 19 - .../{yeoman => utils}/webpack-adapter.js | 0 lib/creator/yeoman/utils/module.js | 12 - lib/creator/yeoman/utils/plugins.js | 5 - lib/creator/yeoman/utils/tooltip.js | 49 --- lib/creator/yeoman/utils/validate.js | 7 - lib/creator/yeoman/webpack-generator.js | 337 ------------------ package.json | 2 +- 10 files changed, 3 insertions(+), 469 deletions(-) delete mode 100644 lib/creator/utils/validate-options.js delete mode 100644 lib/creator/utils/validate-options.spec.js rename lib/creator/{yeoman => utils}/webpack-adapter.js (100%) delete mode 100644 lib/creator/yeoman/utils/module.js delete mode 100644 lib/creator/yeoman/utils/plugins.js delete mode 100644 lib/creator/yeoman/utils/tooltip.js delete mode 100644 lib/creator/yeoman/utils/validate.js delete mode 100644 lib/creator/yeoman/webpack-generator.js diff --git a/lib/creator/index.js b/lib/creator/index.js index 12ec46c8fc8..e74ce91c630 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -1,8 +1,8 @@ const yeoman = require('yeoman-environment'); const Generator = require('yeoman-generator'); const path = require('path'); -const defaultGenerator = require('./yeoman/webpack-generator'); -const WebpackAdapter = require('./yeoman/webpack-adapter'); +const defaultGenerator = require('webpack-addons').WebpackGenerator; +const WebpackAdapter = require('./utils/webpack-adapter'); const runTransform = require('./transformations/index'); /* diff --git a/lib/creator/utils/validate-options.js b/lib/creator/utils/validate-options.js deleted file mode 100644 index 111bebd428b..00000000000 --- a/lib/creator/utils/validate-options.js +++ /dev/null @@ -1,37 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -/* -* @function getPath -* -* Finds the current filepath of a given string -* -* @param { String } part - The name of the file to be checked. -* @returns { String } - returns an string with the filepath -*/ - -function getPath(part) { - return path.join(process.cwd(), part); -} - -/* -* @function validateOptions -* -* Validates the options passed from an inquirer instance to make -* sure the path supplied exists -* -* @param { String } part - The name of the file to be checked. -* @returns { } part - checks if the path exists or throws an error -*/ - -module.exports = function validateOptions(opts) { - return Object.keys(opts).forEach( (location) => { - let part = getPath(opts[location]); - try { - fs.readFileSync(part); - } catch (err) { - console.error('Found no file at:', part); - process.exitCode = 1; - } - }); -}; diff --git a/lib/creator/utils/validate-options.spec.js b/lib/creator/utils/validate-options.spec.js deleted file mode 100644 index aae91533562..00000000000 --- a/lib/creator/utils/validate-options.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const validateOptions = require('../../../__mocks__/creator/validate-options.mock').validateOptions; - -describe('validate-options', () => { - - it('should throw on fake paths', () => { - expect(() => { - validateOptions({entry: 'noop', output: 'noopsi'}); - }).toThrowError('Did not find the file'); - }); - - it('should find the real files', () => { - expect(() => { - validateOptions({entry: 'package.json'}); - }).not.toThrowError(/'Did not find the file'/); - }); - -}); diff --git a/lib/creator/yeoman/webpack-adapter.js b/lib/creator/utils/webpack-adapter.js similarity index 100% rename from lib/creator/yeoman/webpack-adapter.js rename to lib/creator/utils/webpack-adapter.js diff --git a/lib/creator/yeoman/utils/module.js b/lib/creator/yeoman/utils/module.js deleted file mode 100644 index 161ec111962..00000000000 --- a/lib/creator/yeoman/utils/module.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = () => { - return { - test: new RegExp(/\.js$/), - exclude: '/node_modules/', - loader: '\'babel-loader\'', - options: { - presets: [ - '\'es2015\'' - ] - } - }; -}; diff --git a/lib/creator/yeoman/utils/plugins.js b/lib/creator/yeoman/utils/plugins.js deleted file mode 100644 index 90b39179d41..00000000000 --- a/lib/creator/yeoman/utils/plugins.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = () => { - return [ - 'new UglifyJSPlugin()' - ]; -}; diff --git a/lib/creator/yeoman/utils/tooltip.js b/lib/creator/yeoman/utils/tooltip.js deleted file mode 100644 index 16a5e840276..00000000000 --- a/lib/creator/yeoman/utils/tooltip.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = { - uglify: () => { - return (`/* - * We've enabled UglifyJSPlugin for you! This minifies your app - * in order to load faster and run less javascript. - * - * https://github.com/webpack-contrib/uglifyjs-webpack-plugin - * - */`); - }, - commonsChunk: () => { - return (`/* - * We've enabled commonsChunkPlugin for you. This allows your app to - * load faster and it splits the modules you provided as entries across - * different bundles! - * - * https://webpack.js.org/plugins/commons-chunk-plugin/ - * - */`); - }, - cssPlugin: () => { - return( - `/* - * We've enabled ExtractTextPlugin for you. This allows your app to - * use css modules that will be moved into a separate CSS file instead of inside - * one of your module entries! - * - * https://github.com/webpack-contrib/extract-text-webpack-plugin - * - */`); - }, - postcss: () => { - return( - `/* - * We've enabled Postcss, autoprefixer and precss for you. This allows your app - * to lint CSS, support variables and mixins, transpile future CSS syntax, - * inline images, and more! - * - * To enable SASS or LESS, add the respective loaders to module.rules - * - * https://github.com/postcss/postcss - * - * https://github.com/postcss/autoprefixer - * - * https://github.com/jonathantneal/precss - * - */`); - } -}; diff --git a/lib/creator/yeoman/utils/validate.js b/lib/creator/yeoman/utils/validate.js deleted file mode 100644 index bf981fd454f..00000000000 --- a/lib/creator/yeoman/utils/validate.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = (value) => { - const pass = value.length; - if(pass) { - return true; - } - return 'Please specify an answer!'; -}; diff --git a/lib/creator/yeoman/webpack-generator.js b/lib/creator/yeoman/webpack-generator.js deleted file mode 100644 index 1381d30033a..00000000000 --- a/lib/creator/yeoman/webpack-generator.js +++ /dev/null @@ -1,337 +0,0 @@ -const Generator = require('yeoman-generator'); -const chalk = require('chalk'); - -const createCommonsChunkPlugin = require('webpack-addons').createCommonsChunkPlugin; - -const Input = require('webpack-addons').Input; -const Confirm = require('webpack-addons').Confirm; -const RawList = require('webpack-addons').RawList; - -const entryQuestions = require('./utils/entry'); -const getBabelPlugin = require('./utils/module'); -const getDefaultPlugins = require('./utils/plugins'); -const tooltip = require('./utils/tooltip'); - -module.exports = class WebpackGenerator extends Generator { - constructor(args, opts) { - super(args, opts); - this.isProd = false; - this.npmInstalls = ['webpack', 'uglifyjs-webpack-plugin']; - this.configuration = { - config: { - webpackOptions: {}, - topScope: [] - } - }; - } - prompting() { - - let done = this.async(); - let self = this; - let oneOrMoreEntries; - let regExpForStyles; - let ExtractUseProps; - process.stdout.write( - '\n' + chalk.bold('Insecure about some of the questions?') + '\n' - ); - process.stdout.write( - `\n${chalk.bold.green('https://github.com/webpack/webpack-cli/blob/master/INIT.md')}\n\n` - ); - this.configuration.config.webpackOptions.module = { - rules: [] - }; - this.configuration.config.webpackOptions.plugins = getDefaultPlugins(); - this.configuration.config.topScope.push( - 'const webpack = require(\'webpack\')', - 'const path = require(\'path\')', - tooltip.uglify(), - 'const UglifyJSPlugin = require(\'uglifyjs-webpack-plugin\');', - '\n' - ); - this.prompt([ - Confirm('entryType', 'Will your application have multiple bundles?') - ]).then( (entryTypeAnswer) => { - // Ask different questions for entry points - entryQuestions(self, entryTypeAnswer).then(entryOptions => { - this.configuration.config.webpackOptions.entry = entryOptions; - oneOrMoreEntries = Object.keys(entryOptions); - }).then( () => { - - this.prompt([ - Input( - 'outputType', - 'Which folder will your generated bundles be in? [default: dist]:' - ) - ]).then( (outputTypeAnswer) => { - if(!this.configuration.config.webpackOptions.entry.length) { - this.configuration.config.topScope.push(tooltip.commonsChunk()); - this.configuration.config.webpackOptions.output = { - filename: '\'[name].[chunkhash].js\'', - chunkFilename: '\'[name].[chunkhash].js\'' - }; - } else { - this.configuration.config.webpackOptions.output = { - filename: '\'[name].bundle.js\'', - }; - } - if(outputTypeAnswer['outputType'].length) { - this.configuration.config.webpackOptions.output.path = `'${outputTypeAnswer['outputType']}'`; - } else { - this.configuration.config.webpackOptions.output.path = '\path.resolve(__dirname, \'dist\')'; - } - }).then( () => { - this.prompt([ - Confirm('prodConfirm', 'Are you going to use this in production?') - ]).then( (prodAnswer) => { - if(prodAnswer['prodConfirm'] === true) { - this.isProd = true; - } else { - this.isProd = false; - } - }).then( () => { - this.prompt([ - Confirm('babelConfirm', 'Will you be using ES2015?') - ]).then( (ans) => { - if(ans['babelConfirm'] === true) { - this.configuration.config.webpackOptions.module.rules.push(getBabelPlugin()); - this.npmInstalls.push('babel-loader', 'babel-core', 'babel-preset-es2015'); - } - }).then( () => { - this.prompt([ - RawList( - 'stylingType', - 'Will you use one of the below CSS solutions?', - ['SASS', 'LESS', 'CSS', 'PostCSS', 'No'] - ) - ]).then( (stylingAnswer) => { - if(!this.isProd) { - ExtractUseProps = []; - } - if(stylingAnswer['stylingType'] === 'SASS') { - this.npmInstalls.push( - 'sass-loader', 'node-sass', - 'style-loader', 'css-loader' - ); - regExpForStyles = new RegExp(/\.(scss|css)$/); - if(this.isProd) { - ExtractUseProps = `use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }, { - loader: 'sass-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'' - }, { - loader: '\'css-loader\'' - }, { - loader: '\'sass-loader\'' - }); - } - } - else if(stylingAnswer['stylingType'] === 'LESS') { - regExpForStyles = new RegExp(/\.(less|css)$/); - this.npmInstalls.push( - 'less-loader', 'less', - 'style-loader', 'css-loader' - ); - if(this.isProd) { - ExtractUseProps = ` - use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }, { - loader: 'less-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'css-loader\'', - options: { - sourceMap: true - } - }, { - loader: '\'less-loader\'', - options: { - sourceMap: true - } - }); - } - } - else if(stylingAnswer['stylingType'] === 'PostCSS') { - this.configuration.config.topScope.push( - tooltip.postcss(), - 'const autoprefixer = require(\'autoprefixer\');', - 'const precss = require(\'precss\');', - '\n' - ); - this.npmInstalls.push( - 'style-loader', 'css-loader', - 'postcss-loader', 'precss', - 'autoprefixer' - ); - regExpForStyles = new RegExp(/\.css$/); - if(this.isProd) { - ExtractUseProps = ` - use: [{ - loader: 'style-loader' - },{ - loader: 'css-loader', - options: { - sourceMap: true, - importLoaders: 1 - } - }, { - loader: 'postcss-loader', - options: { - plugins: function () { - return [ - precss, - autoprefixer - ]; - } - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'' - },{ - loader: '\'css-loader\'', - options: { - sourceMap: true, - importLoaders: 1 - } - }, { - loader: '\'postcss-loader\'', - options: { - plugins: `function () { - return [ - precss, - autoprefixer - ]; - }` - } - }); - } - } - else if(stylingAnswer['stylingType'] === 'CSS') { - this.npmInstalls.push('style-loader', 'css-loader'); - regExpForStyles = new RegExp(/\.css$/); - if(this.isProd) { - ExtractUseProps = `use: [{ - loader: 'css-loader', - options: { - sourceMap: true - } - }], - fallback: 'style-loader'`; - } else { - ExtractUseProps.push({ - loader: '\'style-loader\'', - options: { - sourceMap: true - } - }, { - loader: '\'css-loader\'', - }); - } - } - else { - regExpForStyles = null; - } - }).then( () => { - // Ask if the user wants to use extractPlugin - this.prompt([ - Input( - 'extractPlugin', - 'If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)' - ) - ]).then( (extractAnswer) => { - if(regExpForStyles) { - if(this.isProd) { - - this.configuration.config.topScope.push(tooltip.cssPlugin()); - this.npmInstalls.push('extract-text-webpack-plugin'); - if(extractAnswer['extractPlugin'].length !== 0) { - this.configuration.config.webpackOptions.plugins.push( - 'new ExtractTextPlugin(\'' + - extractAnswer['extractPlugin'] + - '.[contentHash].css\')' - ); - } else { - this.configuration.config.webpackOptions.plugins.push( - 'new ExtractTextPlugin(\'' + - 'style.css\')' - ); - } - const moduleRulesObj = { - test: regExpForStyles, - use: `ExtractTextPlugin.extract({ - ${ExtractUseProps} - })` - }; - this.configuration.config.webpackOptions.module.rules.push( - moduleRulesObj - ); - this.configuration.config.topScope.push( - 'const ExtractTextPlugin = require(\'extract-text-webpack-plugin\');', - '\n' - ); - } else { - const moduleRulesObj = { - test: regExpForStyles, - use: ExtractUseProps - }; - this.configuration.config.webpackOptions.module.rules.push( - moduleRulesObj - ); - } - } - }).then( () => { - if(!this.configuration.config.webpackOptions.entry.length) { - oneOrMoreEntries.forEach( (prop) => { - this.configuration.config.webpackOptions.plugins.push( - createCommonsChunkPlugin(prop) - ); - }); - } - done(); - }); - }); - }); - }); - }); - }); - }); - } - installPlugins() { - let asyncNamePrompt = this.async(); - let defaultName = this.isProd ? 'prod' : 'config'; - this.prompt([ - Input('nameType', `Name your \'webpack.[name].js?\' [default: \'${defaultName}\']:`) - ]).then( (nameAnswer) => { - if(nameAnswer['nameType'].length) { - this.configuration.config.configName = nameAnswer['nameType']; - } else { - this.configuration.config.configName = defaultName; - } - }).then( () => { - asyncNamePrompt(); - this.npmInstall(this.npmInstalls, { 'save-dev': true }); - }); - } - -}; diff --git a/package.json b/package.json index 4a5d766037b..7db12acfcd6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "resolve-cwd": "^2.0.0", "supports-color": "^3.1.2", "webpack": "^2.5.1", - "webpack-addons": "^1.1.2", + "webpack-addons": "git://github.com/webpack-contrib/webpack-addons.git#yeoman-migration", "yargs": "^6.5.0", "yeoman-environment": "^1.6.6", "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" From 91c9d333aa11983405a2ccb91e6c030ad21d895e Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:01:05 -0700 Subject: [PATCH 10/15] feat: move transforms to webpack-addons --- __mocks__/creator/validate-options.mock.js | 21 - lib/creator/index.js | 11 +- .../__snapshots__/context.test.js.snap | 37 -- .../__testfixtures__/context-0.input.js | 6 - .../__testfixtures__/context-1.input.js | 6 - .../__testfixtures__/context-2.input.js | 6 - .../transformations/context/context.js | 22 - .../transformations/context/context.test.js | 5 - .../__snapshots__/devtool.test.js.snap | 49 -- .../__testfixtures__/devtool-0.input.js | 6 - .../__testfixtures__/devtool-1.input.js | 6 - .../transformations/devtool/devtool.js | 23 - .../transformations/devtool/devtool.test.js | 6 - .../entry/__snapshots__/entry.test.js.snap | 57 -- .../entry/__testfixtures__/entry-0.input.js | 1 - lib/creator/transformations/entry/entry.js | 40 -- .../transformations/entry/entry.test.js | 17 - .../__snapshots__/externals.test.js.snap | 137 ----- .../__testfixtures__/externals-0.input.js | 6 - .../__testfixtures__/externals-1.input.js | 6 - .../transformations/externals/externals.js | 38 -- .../externals/externals.test.js | 61 -- lib/creator/transformations/index.js | 111 ---- .../module/__snapshots__/module.test.js.snap | 119 ---- .../module/__testfixtures__/module-0.input.js | 6 - .../module/__testfixtures__/module-1.input.js | 6 - lib/creator/transformations/module/module.js | 33 -- .../transformations/module/module.test.js | 93 ---- .../node/__snapshots__/node.test.js.snap | 21 - .../node/__testfixtures__/node-0.input.js | 6 - lib/creator/transformations/node/node.js | 26 - lib/creator/transformations/node/node.test.js | 11 - .../other/__snapshots__/other.test.js.snap | 74 --- .../other/__testfixtures__/other-0.input.js | 6 - lib/creator/transformations/other/amd.js | 26 - lib/creator/transformations/other/bail.js | 23 - lib/creator/transformations/other/cache.js | 23 - lib/creator/transformations/other/merge.js | 44 -- .../transformations/other/other.test.js | 11 - lib/creator/transformations/other/profile.js | 22 - .../output/__snapshots__/output.test.js.snap | 18 - .../output/__testfixtures__/output-0.input.js | 3 - lib/creator/transformations/output/output.js | 26 - .../transformations/output/output.test.js | 13 - .../__snapshots__/performance.test.js.snap | 18 - .../__testfixtures__/performance-0.input.js | 6 - .../performance/performance.js | 27 - .../performance/performance.test.js | 10 - .../__snapshots__/plugins.test.js.snap | 15 - .../__testfixtures__/plugins-0.input.js | 6 - .../transformations/plugins/plugins.js | 25 - .../transformations/plugins/plugins.test.js | 5 - .../__snapshots__/resolve.test.js.snap | 39 -- .../__testfixtures__/resolve-0.input.js | 6 - .../transformations/resolve/resolve.js | 26 - .../transformations/resolve/resolve.test.js | 27 - .../stats/__snapshots__/stats.test.js.snap | 55 -- .../stats/__testfixtures__/stats-0.input.js | 6 - lib/creator/transformations/stats/stats.js | 29 - .../transformations/stats/stats.test.js | 34 -- .../target/__snapshots__/target.test.js.snap | 25 - .../target/__testfixtures__/target-0.input.js | 6 - .../target/__testfixtures__/target-1.input.js | 6 - lib/creator/transformations/target/target.js | 22 - .../transformations/target/target.test.js | 4 - .../__snapshots__/top-scope.test.js.snap | 7 - .../__testfixtures__/top-scope-0.input.js | 1 - .../transformations/top-scope/top-scope.js | 22 - .../top-scope/top-scope.test.js | 5 - .../watch/__snapshots__/watch.test.js.snap | 49 -- .../__snapshots__/watchOptions.test.js.snap | 49 -- .../watch/__testfixtures__/watch-0.input.js | 6 - .../watch/__testfixtures__/watch-1.input.js | 6 - .../watch/__testfixtures__/watch-2.input.js | 6 - lib/creator/transformations/watch/watch.js | 21 - .../transformations/watch/watch.test.js | 6 - .../transformations/watch/watchOptions.js | 25 - .../watch/watchOptions.test.js | 19 - lib/creator/utils/run-prettier.js | 33 -- lib/migrate.js | 2 +- .../__snapshots__/index.test.js.snap | 102 ---- .../__snapshots__/utils.test.js.snap | 130 ----- .../__testfixtures__/failing.js | 81 --- .../__snapshots__/bannerPlugin.test.js.snap | 32 -- .../__testfixtures__/.editorconfig | 3 - .../__testfixtures__/bannerPlugin-0.input.js | 5 - .../__testfixtures__/bannerPlugin-1.input.js | 4 - .../__testfixtures__/bannerPlugin-2.input.js | 6 - .../bannerPlugin/bannerPlugin.js | 19 - .../bannerPlugin/bannerPlugin.test.js | 5 - lib/transformations/defineTest.js | 65 --- .../extractTextPlugin.test.js.snap | 24 - .../__testfixtures__/.editorconfig | 3 - .../extractTextPlugin.input.js | 16 - .../extractTextPlugin/extractTextPlugin.js | 32 -- .../extractTextPlugin.test.js | 3 - lib/transformations/index.js | 72 --- lib/transformations/index.test.js | 64 --- .../loaderOptionsPlugin.test.js.snap | 60 -- .../__testfixtures__/.editorconfig | 3 - .../loaderOptionsPlugin-0.input.js | 6 - .../loaderOptionsPlugin-1.input.js | 9 - .../loaderOptionsPlugin-2.input.js | 9 - .../loaderOptionsPlugin-3.input.js | 17 - .../loaderOptionsPlugin.js | 28 - .../loaderOptionsPlugin.test.js | 6 - .../__snapshots__/loaders.test.js.snap | 169 ------ .../loaders/__testfixtures__/.editorconfig | 3 - .../__testfixtures__/loaders-0.input.js | 65 --- .../__testfixtures__/loaders-1.input.js | 8 - .../__testfixtures__/loaders-2.input.js | 15 - .../__testfixtures__/loaders-3.input.js | 8 - .../__testfixtures__/loaders-4.input.js | 8 - .../__testfixtures__/loaders-5.input.js | 12 - .../__testfixtures__/loaders-6.input.js | 12 - lib/transformations/loaders/loaders.js | 137 ----- lib/transformations/loaders/loaders.test.js | 9 - .../__snapshots__/outputPath.test.js.snap | 30 - .../__testfixtures__/outputPath-0.input.js | 5 - .../__testfixtures__/outputPath-1.input.js | 6 - .../__testfixtures__/outputPath-2.input.js | 6 - lib/transformations/outputPath/outputPath.js | 51 -- .../outputPath/outputPath.test.js | 5 - .../removeDeprecatedPlugins.test.js.snap | 44 -- .../__testfixtures__/.editorconfig | 3 - .../removeDeprecatedPlugins-0.input.js | 6 - .../removeDeprecatedPlugins-1.input.js | 6 - .../removeDeprecatedPlugins-2.input.js | 8 - .../removeDeprecatedPlugins-3.input.js | 7 - .../removeDeprecatedPlugins-4.input.js | 8 - .../removeDeprecatedPlugins.js | 47 -- .../removeDeprecatedPlugins.test.js | 7 - .../removeJsonLoader.test.js.snap | 51 -- .../__testfixtures__/.editorconfig | 3 - .../removeJsonLoader-0.input.js | 9 - .../removeJsonLoader-1.input.js | 8 - .../removeJsonLoader-2.input.js | 10 - .../removeJsonLoader-3.input.js | 15 - .../removeJsonLoader/removeJsonLoader.js | 48 -- .../removeJsonLoader/removeJsonLoader.test.js | 6 - .../__snapshots__/resolve.test.js.snap | 24 - .../resolve/__testfixtures__/.editorconfig | 3 - .../resolve/__testfixtures__/resolve.input.js | 20 - lib/transformations/resolve/resolve.js | 49 -- lib/transformations/resolve/resolve.test.js | 3 - .../__snapshots__/uglifyJsPlugin.test.js.snap | 37 -- .../__testfixtures__/.editorconfig | 3 - .../uglifyJsPlugin-0.input.js | 5 - .../uglifyJsPlugin-1.input.js | 6 - .../uglifyJsPlugin-2.input.js | 8 - .../uglifyJsPlugin/uglifyJsPlugin.js | 25 - .../uglifyJsPlugin/uglifyJsPlugin.test.js | 5 - lib/transformations/utils.js | 526 ------------------ lib/transformations/utils.test.js | 315 ----------- 154 files changed, 2 insertions(+), 4608 deletions(-) delete mode 100644 __mocks__/creator/validate-options.mock.js delete mode 100644 lib/creator/transformations/context/__snapshots__/context.test.js.snap delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-0.input.js delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-1.input.js delete mode 100644 lib/creator/transformations/context/__testfixtures__/context-2.input.js delete mode 100644 lib/creator/transformations/context/context.js delete mode 100644 lib/creator/transformations/context/context.test.js delete mode 100644 lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap delete mode 100644 lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js delete mode 100644 lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js delete mode 100644 lib/creator/transformations/devtool/devtool.js delete mode 100644 lib/creator/transformations/devtool/devtool.test.js delete mode 100644 lib/creator/transformations/entry/__snapshots__/entry.test.js.snap delete mode 100644 lib/creator/transformations/entry/__testfixtures__/entry-0.input.js delete mode 100644 lib/creator/transformations/entry/entry.js delete mode 100644 lib/creator/transformations/entry/entry.test.js delete mode 100644 lib/creator/transformations/externals/__snapshots__/externals.test.js.snap delete mode 100644 lib/creator/transformations/externals/__testfixtures__/externals-0.input.js delete mode 100644 lib/creator/transformations/externals/__testfixtures__/externals-1.input.js delete mode 100644 lib/creator/transformations/externals/externals.js delete mode 100644 lib/creator/transformations/externals/externals.test.js delete mode 100644 lib/creator/transformations/index.js delete mode 100644 lib/creator/transformations/module/__snapshots__/module.test.js.snap delete mode 100644 lib/creator/transformations/module/__testfixtures__/module-0.input.js delete mode 100644 lib/creator/transformations/module/__testfixtures__/module-1.input.js delete mode 100644 lib/creator/transformations/module/module.js delete mode 100644 lib/creator/transformations/module/module.test.js delete mode 100644 lib/creator/transformations/node/__snapshots__/node.test.js.snap delete mode 100644 lib/creator/transformations/node/__testfixtures__/node-0.input.js delete mode 100644 lib/creator/transformations/node/node.js delete mode 100644 lib/creator/transformations/node/node.test.js delete mode 100644 lib/creator/transformations/other/__snapshots__/other.test.js.snap delete mode 100644 lib/creator/transformations/other/__testfixtures__/other-0.input.js delete mode 100644 lib/creator/transformations/other/amd.js delete mode 100644 lib/creator/transformations/other/bail.js delete mode 100644 lib/creator/transformations/other/cache.js delete mode 100644 lib/creator/transformations/other/merge.js delete mode 100644 lib/creator/transformations/other/other.test.js delete mode 100644 lib/creator/transformations/other/profile.js delete mode 100644 lib/creator/transformations/output/__snapshots__/output.test.js.snap delete mode 100644 lib/creator/transformations/output/__testfixtures__/output-0.input.js delete mode 100644 lib/creator/transformations/output/output.js delete mode 100644 lib/creator/transformations/output/output.test.js delete mode 100644 lib/creator/transformations/performance/__snapshots__/performance.test.js.snap delete mode 100644 lib/creator/transformations/performance/__testfixtures__/performance-0.input.js delete mode 100644 lib/creator/transformations/performance/performance.js delete mode 100644 lib/creator/transformations/performance/performance.test.js delete mode 100644 lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap delete mode 100644 lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js delete mode 100644 lib/creator/transformations/plugins/plugins.js delete mode 100644 lib/creator/transformations/plugins/plugins.test.js delete mode 100644 lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap delete mode 100644 lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js delete mode 100644 lib/creator/transformations/resolve/resolve.js delete mode 100644 lib/creator/transformations/resolve/resolve.test.js delete mode 100644 lib/creator/transformations/stats/__snapshots__/stats.test.js.snap delete mode 100644 lib/creator/transformations/stats/__testfixtures__/stats-0.input.js delete mode 100644 lib/creator/transformations/stats/stats.js delete mode 100644 lib/creator/transformations/stats/stats.test.js delete mode 100644 lib/creator/transformations/target/__snapshots__/target.test.js.snap delete mode 100644 lib/creator/transformations/target/__testfixtures__/target-0.input.js delete mode 100644 lib/creator/transformations/target/__testfixtures__/target-1.input.js delete mode 100644 lib/creator/transformations/target/target.js delete mode 100644 lib/creator/transformations/target/target.test.js delete mode 100644 lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap delete mode 100644 lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js delete mode 100644 lib/creator/transformations/top-scope/top-scope.js delete mode 100644 lib/creator/transformations/top-scope/top-scope.test.js delete mode 100644 lib/creator/transformations/watch/__snapshots__/watch.test.js.snap delete mode 100644 lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-0.input.js delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-1.input.js delete mode 100644 lib/creator/transformations/watch/__testfixtures__/watch-2.input.js delete mode 100644 lib/creator/transformations/watch/watch.js delete mode 100644 lib/creator/transformations/watch/watch.test.js delete mode 100644 lib/creator/transformations/watch/watchOptions.js delete mode 100644 lib/creator/transformations/watch/watchOptions.test.js delete mode 100644 lib/creator/utils/run-prettier.js delete mode 100644 lib/transformations/__snapshots__/index.test.js.snap delete mode 100644 lib/transformations/__snapshots__/utils.test.js.snap delete mode 100644 lib/transformations/__testfixtures__/failing.js delete mode 100644 lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js delete mode 100644 lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js delete mode 100644 lib/transformations/bannerPlugin/bannerPlugin.js delete mode 100644 lib/transformations/bannerPlugin/bannerPlugin.test.js delete mode 100644 lib/transformations/defineTest.js delete mode 100644 lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap delete mode 100644 lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js delete mode 100644 lib/transformations/extractTextPlugin/extractTextPlugin.js delete mode 100644 lib/transformations/extractTextPlugin/extractTextPlugin.test.js delete mode 100644 lib/transformations/index.js delete mode 100644 lib/transformations/index.test.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js delete mode 100644 lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js delete mode 100644 lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js delete mode 100644 lib/transformations/loaders/__snapshots__/loaders.test.js.snap delete mode 100644 lib/transformations/loaders/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-0.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-1.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-2.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-3.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-4.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-5.input.js delete mode 100644 lib/transformations/loaders/__testfixtures__/loaders-6.input.js delete mode 100644 lib/transformations/loaders/loaders.js delete mode 100644 lib/transformations/loaders/loaders.test.js delete mode 100644 lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js delete mode 100644 lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js delete mode 100644 lib/transformations/outputPath/outputPath.js delete mode 100644 lib/transformations/outputPath/outputPath.test.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js delete mode 100644 lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js delete mode 100644 lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js delete mode 100644 lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js delete mode 100644 lib/transformations/removeJsonLoader/removeJsonLoader.js delete mode 100644 lib/transformations/removeJsonLoader/removeJsonLoader.test.js delete mode 100644 lib/transformations/resolve/__snapshots__/resolve.test.js.snap delete mode 100644 lib/transformations/resolve/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/resolve/__testfixtures__/resolve.input.js delete mode 100644 lib/transformations/resolve/resolve.js delete mode 100644 lib/transformations/resolve/resolve.test.js delete mode 100644 lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js delete mode 100644 lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js delete mode 100644 lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js delete mode 100644 lib/transformations/utils.js delete mode 100644 lib/transformations/utils.test.js diff --git a/__mocks__/creator/validate-options.mock.js b/__mocks__/creator/validate-options.mock.js deleted file mode 100644 index 593f51f2f6f..00000000000 --- a/__mocks__/creator/validate-options.mock.js +++ /dev/null @@ -1,21 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -function getPath(part) { - return path.join(process.cwd(), part); -} - -function validateOptions(opts) { - return Object.keys(opts).forEach( (location) => { - let part = getPath(opts[location]); - try { - fs.readFileSync(part); - } catch (err) { - throw new Error('Did not find the file'); - } - }); -} - -module.exports = { - validateOptions -}; diff --git a/lib/creator/index.js b/lib/creator/index.js index e74ce91c630..266995e8088 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -3,7 +3,6 @@ const Generator = require('yeoman-generator'); const path = require('path'); const defaultGenerator = require('webpack-addons').WebpackGenerator; const WebpackAdapter = require('./utils/webpack-adapter'); -const runTransform = require('./transformations/index'); /* * @function creator @@ -31,15 +30,7 @@ function creator(options) { env.registerStub(defaultGenerator, 'webpack-default-generator'); } - env.run(generatorName).on('end', () => { - if(generatorName !== 'webpack-default-generator') { - //HACK / FIXME - env = env.options.env; - return runTransform(env.configuration); - } else { - return runTransform(env.getArgument('configuration')); - } - }); + return env.run(generatorName); } /* diff --git a/lib/creator/transformations/context/__snapshots__/context.test.js.snap b/lib/creator/transformations/context/__snapshots__/context.test.js.snap deleted file mode 100644 index d707e07cda2..00000000000 --- a/lib/creator/transformations/context/__snapshots__/context.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`context transforms correctly using "context-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: path.resolve(__dirname, \\"app\\") -} -" -`; - -exports[`context transforms correctly using "context-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: './some/fake/path' -} -" -`; - -exports[`context transforms correctly using "context-2" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - context: contextVariable -} -" -`; diff --git a/lib/creator/transformations/context/__testfixtures__/context-0.input.js b/lib/creator/transformations/context/__testfixtures__/context-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/__testfixtures__/context-1.input.js b/lib/creator/transformations/context/__testfixtures__/context-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/__testfixtures__/context-2.input.js b/lib/creator/transformations/context/__testfixtures__/context-2.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/context/__testfixtures__/context-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/context/context.js b/lib/creator/transformations/context/context.js deleted file mode 100644 index 98fb0710b99..00000000000 --- a/lib/creator/transformations/context/context.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for context. Finds the context property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'context', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/context/context.test.js b/lib/creator/transformations/context/context.test.js deleted file mode 100644 index 0258c5528de..00000000000 --- a/lib/creator/transformations/context/context.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'context', 'context-0', 'path.resolve(__dirname, "app")'); -defineTest(__dirname, 'context', 'context-1', '\'./some/fake/path\''); -defineTest(__dirname, 'context', 'context-2', 'contextVariable'); diff --git a/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap b/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap deleted file mode 100644 index d343b1fc107..00000000000 --- a/lib/creator/transformations/devtool/__snapshots__/devtool.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`devtool transforms correctly using "devtool-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: 'source-map' -} -" -`; - -exports[`devtool transforms correctly using "devtool-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: myVariable -} -" -`; - -exports[`devtool transforms correctly using "devtool-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: 'cheap-module-source-map' -} -" -`; - -exports[`devtool transforms correctly using "devtool-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - devtool: false -} -" -`; diff --git a/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js b/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/devtool/__testfixtures__/devtool-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js b/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/devtool/__testfixtures__/devtool-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/devtool/devtool.js b/lib/creator/transformations/devtool/devtool.js deleted file mode 100644 index ac3930ad366..00000000000 --- a/lib/creator/transformations/devtool/devtool.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for devtool. Finds the devtool property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'devtool', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/devtool/devtool.test.js b/lib/creator/transformations/devtool/devtool.test.js deleted file mode 100644 index 01f574301a5..00000000000 --- a/lib/creator/transformations/devtool/devtool.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'devtool', 'devtool-0', '\'source-map\''); -defineTest(__dirname, 'devtool', 'devtool-0', 'myVariable'); -defineTest(__dirname, 'devtool', 'devtool-1', '\'cheap-module-source-map\''); -defineTest(__dirname, 'devtool', 'devtool-1', 'false'); diff --git a/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap b/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap deleted file mode 100644 index 1fb3d3acd85..00000000000 --- a/lib/creator/transformations/entry/__snapshots__/entry.test.js.snap +++ /dev/null @@ -1,57 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`entry transforms correctly using "entry-0" data 1`] = ` -"module.exports = { - entry: 'index.js' -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 2`] = ` -"module.exports = { - entry: ['index.js', 'app.js'] -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 3`] = ` -"module.exports = { - entry: { - index: 'index.js', - app: 'app.js' - } -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 4`] = ` -"module.exports = { - entry: { - something, - app: 'app.js', - else - } -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 5`] = ` -"module.exports = { - entry: () => 'index.js' -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 6`] = ` -"module.exports = { - entry: () => new Promise((resolve) => resolve(['./app', './router'])) -} -" -`; - -exports[`entry transforms correctly using "entry-0" data 7`] = ` -"module.exports = { - entry: entryStringVariable -} -" -`; diff --git a/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js b/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js deleted file mode 100644 index 4ba52ba2c8d..00000000000 --- a/lib/creator/transformations/entry/__testfixtures__/entry-0.input.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/lib/creator/transformations/entry/entry.js b/lib/creator/transformations/entry/entry.js deleted file mode 100644 index 5f142907561..00000000000 --- a/lib/creator/transformations/entry/entry.js +++ /dev/null @@ -1,40 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for entry. Finds the entry property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - - -module.exports = function(j, ast, webpackProperties) { - - function createEntryProperty(p) { - - if(typeof(webpackProperties) === 'string') { - return utils.pushCreateProperty(j, p, 'entry', webpackProperties); - } - if(Array.isArray(webpackProperties)) { - const externalArray = utils.createArrayWithChildren( - j, 'entry', webpackProperties, true - ); - return p.value.properties.push(externalArray); - } - else { - utils.pushCreateProperty(j, p, 'entry', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'entry'); - } - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createEntryProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/entry/entry.test.js b/lib/creator/transformations/entry/entry.test.js deleted file mode 100644 index 27047eb84ee..00000000000 --- a/lib/creator/transformations/entry/entry.test.js +++ /dev/null @@ -1,17 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'entry', 'entry-0', '\'index.js\''); -defineTest(__dirname, 'entry', 'entry-0', ['\'index.js\'', '\'app.js\'']); -defineTest(__dirname, 'entry', 'entry-0', { - index: '\'index.js\'', - app: '\'app.js\'' -}); - -defineTest(__dirname, 'entry', 'entry-0', { - inject: 'something', - app: '\'app.js\'', - inject_1: 'else' -}); -defineTest(__dirname, 'entry', 'entry-0', '() => \'index.js\''); -defineTest(__dirname, 'entry', 'entry-0', '() => new Promise((resolve) => resolve([\'./app\', \'./router\']))'); -defineTest(__dirname, 'entry', 'entry-0', 'entryStringVariable'); diff --git a/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap b/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap deleted file mode 100644 index 1a77ae06b34..00000000000 --- a/lib/creator/transformations/externals/__snapshots__/externals.test.js.snap +++ /dev/null @@ -1,137 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`externals transforms correctly using "externals-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: /react/ -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: 'react' - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: myObj -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 3`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: reactObj - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 4`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - jquery: 'jQuery', - react: [reactObj, path.join(__dirname, 'app'), 'jquery'] - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 5`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - lodash: { - commonjs: 'lodash', - amd: 'lodash', - root: '_' - } - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 6`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: { - lodash: { - commonjs: lodash, - amd: hidash, - root: _ - } - } -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 7`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: [{ - a: false, - b: true, - './ext': ./hey - }, function(context, request, callback) {if (/^yourregex$/.test(request)){return callback(null, 'commonjs ' + request);}callback();}] -} -" -`; - -exports[`externals transforms correctly using "externals-1" data 8`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - externals: [ - myObj, - function(context, request, callback) {if (/^yourregex$/.test(request)){return callback(null, 'commonjs ' + request);}callback();} - ] -} -" -`; diff --git a/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js b/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/externals/__testfixtures__/externals-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js b/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/externals/__testfixtures__/externals-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/externals/externals.js b/lib/creator/transformations/externals/externals.js deleted file mode 100644 index 9f20dc2d801..00000000000 --- a/lib/creator/transformations/externals/externals.js +++ /dev/null @@ -1,38 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for externals. Finds the externals property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createExternalProperty(p) { - if(webpackProperties instanceof RegExp || typeof(webpackProperties) === 'string') { - return utils.pushCreateProperty(j, p, 'externals', webpackProperties); - } - if(Array.isArray(webpackProperties)) { - const externalArray = utils.createArrayWithChildren( - j, 'externals', webpackProperties, true - ); - return p.value.properties.push(externalArray); - } - else { - utils.pushCreateProperty(j, p, 'externals', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'externals'); - } - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.safeTraverse(p , ['parent', 'value', 'left', 'property', 'name']) === 'exports') - .forEach(createExternalProperty); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/externals/externals.test.js b/lib/creator/transformations/externals/externals.test.js deleted file mode 100644 index 07331dda65a..00000000000 --- a/lib/creator/transformations/externals/externals.test.js +++ /dev/null @@ -1,61 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'externals', 'externals-0', /react/); -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: '\'react\'' -}); - -defineTest(__dirname, 'externals', 'externals-1', 'myObj'); - -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: 'reactObj' -}); - -defineTest(__dirname, 'externals', 'externals-1', { - jquery: '\'jQuery\'', - react: ['reactObj', 'path.join(__dirname, \'app\')', '\'jquery\''] -}); - -defineTest(__dirname, 'externals', 'externals-1', { - lodash: { - commonjs: '\'lodash\'', - amd: '\'lodash\'', - root: '\'_\'' - } -}); - -defineTest(__dirname, 'externals', 'externals-1', { - lodash: { - commonjs: 'lodash', - amd: 'hidash', - root: '_' - } -}); - -defineTest(__dirname, 'externals', 'externals-1', [ - { - a: 'false', - b: 'true', - '\'./ext\'': './hey' - }, - 'function(context, request, callback) {' + - 'if (/^yourregex$/.test(request)){' + - 'return callback(null, \'commonjs \' + request);' + - '}' + - 'callback();' + - '}' -] -); - -defineTest(__dirname, 'externals', 'externals-1', [ - 'myObj', - 'function(context, request, callback) {' + - 'if (/^yourregex$/.test(request)){' + - 'return callback(null, \'commonjs \' + request);' + - '}' + - 'callback();' + - '}' -] -); diff --git a/lib/creator/transformations/index.js b/lib/creator/transformations/index.js deleted file mode 100644 index 779bede11c6..00000000000 --- a/lib/creator/transformations/index.js +++ /dev/null @@ -1,111 +0,0 @@ -const path = require('path'); -const j = require('jscodeshift'); -const chalk = require('chalk'); -const pEachSeries = require('p-each-series'); - -const runPrettier = require('../utils/run-prettier'); - -const entryTransform = require('./entry/entry'); -const outputTransform = require('./output/output'); -const contextTransform = require('./context/context'); -const resolveTransform = require('./resolve/resolve'); -const devtoolTransform = require('./devtool/devtool'); -const targetTransform = require('./target/target'); -const watchTransform = require('./watch/watch'); -const watchOptionsTransform = require('./watch/watchOptions'); -const externalsTransform = require('./externals/externals'); -const nodeTransform = require('./node/node'); -const performanceTransform = require('./performance/performance'); -const statsTransform = require('./stats/stats'); -const amdTransform = require('./other/amd'); -const bailTransform = require('./other/bail'); -const cacheTransform = require('./other/cache'); -const profileTransform = require('./other/profile'); -const mergeTransform = require('./other/merge'); -const moduleTransform = require('./module/module'); -const pluginsTransform = require('./plugins/plugins'); -const topScopeTransform = require('./top-scope/top-scope'); - -/* -* @function runTransform -* -* Runs the transformations from an object we get from yeoman -* -* @param { Object } transformObject - Options to transform -* @returns { } - A promise that writes each transform, runs prettier -* and writes the file -*/ - -const transformsObject = { - entryTransform, - outputTransform, - contextTransform, - resolveTransform, - devtoolTransform, - targetTransform, - watchTransform, - watchOptionsTransform, - externalsTransform, - nodeTransform, - performanceTransform, - statsTransform, - amdTransform, - bailTransform, - cacheTransform, - profileTransform, - moduleTransform, - pluginsTransform, - topScopeTransform, - mergeTransform -}; - -module.exports = function runTransform(webpackProperties) { - - // webpackOptions.name sent to nameTransform if match - Object.keys(webpackProperties).forEach( (scaffoldPiece) => { - const config = webpackProperties[scaffoldPiece]; - - const transformations = Object.keys(transformsObject).map(k => { - const stringVal = k.substr(0, k.indexOf('Transform')); - if(config.webpackOptions) { - if(config.webpackOptions[stringVal]) { - return [transformsObject[k], config.webpackOptions[stringVal]]; - } else { - return [transformsObject[k], config[stringVal]]; - } - } else { - return [transformsObject[k]]; - } - }); - - const ast = j('module.exports = {}'); - - return pEachSeries(transformations, f => { - if(!f[1]) { - return f[0](j, ast); - } else { - return f[0](j, ast, f[1]); - } - }) - .then(() => { - let configurationName; - if(!config.configName) { - configurationName = 'webpack.config.js'; - } else { - configurationName = 'webpack.' + config.configName + '.js'; - } - - const outputPath = path.join(process.cwd(), configurationName); - const source = ast.toSource({ - quote: 'single' - }); - - runPrettier(outputPath, source); - }).catch(err => { - console.error(err.message ? err.message : err); - }); - }); - process.stdout.write('\n' + chalk.green( - 'Congratulations! Your new webpack configuration file has been created!\n' - )); -}; diff --git a/lib/creator/transformations/module/__snapshots__/module.test.js.snap b/lib/creator/transformations/module/__snapshots__/module.test.js.snap deleted file mode 100644 index 6824146c497..00000000000 --- a/lib/creator/transformations/module/__snapshots__/module.test.js.snap +++ /dev/null @@ -1,119 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`module transforms correctly using "module-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - rules: [{ - test: /\\\\.(js|vue)$/, - loader: 'eslint-loader', - enforce: 'pre', - include: [customObj, 'Stringy'], - options: { - formatter: 'someOption' - } - }, { - test: /\\\\.vue$/, - loader: 'vue-loader', - options: vueObject - }, { - test: /\\\\.js$/, - loader: 'babel-loader', - include: [resolve('src'), resolve('test')] - }, { - test: /\\\\.(png|jpe?g|gif|svg)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('img/[name].[hash:7].[ext]') - } - }, { - test: /\\\\.(woff2?|eot|ttf|otf)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('fonts/[name].[hash:7].[ext]'), - someArr: [Hey] - } - }] - } -} -" -`; - -exports[`module transforms correctly using "module-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - rules: [{{#if_eq build 'standalone'}}, { - test: /\\\\.(js|vue)$/, - loader: 'eslint-loader', - enforce: 'pre', - include: [customObj, 'Stringy'], - options: { - formatter: 'someOption' - } - }, { - test: /\\\\.vue$/, - loader: 'vue-loader', - options: vueObject - }, { - test: /\\\\.js$/, - loader: 'babel-loader', - include: [resolve('src'), resolve('test')] - }, { - test: /\\\\.(png|jpe?g|gif|svg)(\\\\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('img/[name].[hash:7].[ext]'), - {{#if_eq build 'standalone'}} - } - }, { - test: /\\\\.(woff2?|eot|ttf|otf)(\\\\?.*)?$/, - loader: 'url-loader', - {{#if_eq build 'standalone'}}, - options: { - limit: 10000, - name: utils.assetsPath('fonts/[name].[hash:7].[ext]') - } - }] - } -} -" -`; - -exports[`module transforms correctly using "module-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - module: { - noParse: /jquery|lodash/, - rules: [{ - test: /\\\\.js$/, - parser: { - amd: false - }, - - use: ['htmllint-loader', { - loader: 'html-loader', - options: { - hello: 'world' - } - }] - }] - } -} -" -`; diff --git a/lib/creator/transformations/module/__testfixtures__/module-0.input.js b/lib/creator/transformations/module/__testfixtures__/module-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/module/__testfixtures__/module-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/module/__testfixtures__/module-1.input.js b/lib/creator/transformations/module/__testfixtures__/module-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/module/__testfixtures__/module-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/module/module.js b/lib/creator/transformations/module/module.js deleted file mode 100644 index 66c1371dccb..00000000000 --- a/lib/creator/transformations/module/module.js +++ /dev/null @@ -1,33 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for module. Finds the module property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - function createModuleProperties(p) { - utils.pushCreateProperty(j, p, 'module', j.objectExpression([])); - return utils.safeTraverse(p, ['key', 'name'] === 'module'); - } - function createRules(p) { - return utils.pushObjectKeys( - j, p, webpackProperties, 'module' - ); - } - if(!webpackProperties) { - return ast; - } else { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createModuleProperties)) - .forEach(p => createRules(p)); - } -}; diff --git a/lib/creator/transformations/module/module.test.js b/lib/creator/transformations/module/module.test.js deleted file mode 100644 index 710060d9c5e..00000000000 --- a/lib/creator/transformations/module/module.test.js +++ /dev/null @@ -1,93 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'module', 'module-0', { - rules: [{ - test: new RegExp(/\.(js|vue)$/), - loader: '\'eslint-loader\'', - enforce: '\'pre\'', - include: ['customObj', '\'Stringy\''], - options: { - formatter: '\'someOption\'' - } - }, { - test: new RegExp(/\.vue$/), - loader: '\'vue-loader\'', - options: 'vueObject' - }, { - test: new RegExp(/\.js$/), - loader: '\'babel-loader\'', - include: ['resolve(\'src\')', 'resolve(\'test\')'] - }, { - test: new RegExp(/\.(png|jpe?g|gif|svg)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: 10000, - name: 'utils.assetsPath(\'img/[name].[hash:7].[ext]\')' - } - }, { - test: new RegExp(/\.(woff2?|eot|ttf|otf)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: '10000', - name: 'utils.assetsPath(\'fonts/[name].[hash:7].[ext]\')', - someArr: ['Hey'] - } - }] -}); - -defineTest(__dirname, 'module', 'module-1', { - noParse: /jquery|lodash/, - rules: [{ - test: new RegExp(/\.js$/), - parser: { - amd: false - }, - use: [ - '\'htmllint-loader\'', - { - loader: '\'html-loader\'', - options: { - hello: '\'world\'' - } - } - ] - }] -}); - -defineTest(__dirname, 'module', 'module-0', { - rules: [ - '{{#if_eq build \'standalone\'}}', - { - test: new RegExp(/\.(js|vue)$/), - loader: '\'eslint-loader\'', - enforce: '\'pre\'', - include: ['customObj', '\'Stringy\''], - options: { - formatter: '\'someOption\'' - } - }, { - test: new RegExp(/\.vue$/), - loader: '\'vue-loader\'', - options: 'vueObject' - }, { - test: new RegExp(/\.js$/), - loader: '\'babel-loader\'', - include: ['resolve(\'src\')', 'resolve(\'test\')'] - }, { - test: new RegExp(/\.(png|jpe?g|gif|svg)(\?.*)?$/), - loader: '\'url-loader\'', - options: { - limit: 10000, - name: 'utils.assetsPath(\'img/[name].[hash:7].[ext]\')', - inject: '{{#if_eq build \'standalone\'}}' - } - }, { - test: new RegExp(/\.(woff2?|eot|ttf|otf)(\?.*)?$/), - loader: '\'url-loader\'', - inject: '{{#if_eq build \'standalone\'}}', - options: { - limit: '10000', - name: 'utils.assetsPath(\'fonts/[name].[hash:7].[ext]\')' - } - }] -}); diff --git a/lib/creator/transformations/node/__snapshots__/node.test.js.snap b/lib/creator/transformations/node/__snapshots__/node.test.js.snap deleted file mode 100644 index 0046bc33d63..00000000000 --- a/lib/creator/transformations/node/__snapshots__/node.test.js.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`node transforms correctly using "node-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - node: { - console: false, - global: true, - process: true, - Buffer: true, - __filename: mock, - __dirname: mock, - setImmediate: true - } -} -" -`; diff --git a/lib/creator/transformations/node/__testfixtures__/node-0.input.js b/lib/creator/transformations/node/__testfixtures__/node-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/node/__testfixtures__/node-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/node/node.js b/lib/creator/transformations/node/node.js deleted file mode 100644 index 26a9a13ffe4..00000000000 --- a/lib/creator/transformations/node/node.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for node. Finds the node property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createNodeProperty(p) { - utils.pushCreateProperty(j, p, 'node', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'node'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createNodeProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/node/node.test.js b/lib/creator/transformations/node/node.test.js deleted file mode 100644 index 53cf24e541a..00000000000 --- a/lib/creator/transformations/node/node.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'node', 'node-0', { - console: false, - global: true, - process: true, - Buffer: true, - __filename: 'mock', - __dirname: 'mock', - setImmediate: true -}); diff --git a/lib/creator/transformations/other/__snapshots__/other.test.js.snap b/lib/creator/transformations/other/__snapshots__/other.test.js.snap deleted file mode 100644 index 5a3d06f1f94..00000000000 --- a/lib/creator/transformations/other/__snapshots__/other.test.js.snap +++ /dev/null @@ -1,74 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`amd transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - amd: { - jQuery: true, - kQuery: false - } -} -" -`; - -exports[`bail transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - bail: true -} -" -`; - -exports[`cache transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - cache: true -} -" -`; - -exports[`cache transforms correctly using "other-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - cache: cacheVal -} -" -`; - -exports[`merge transforms correctly using "other-0" data 1`] = ` -"module.exports = merge(myConfig, { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -}); -" -`; - -exports[`profile transforms correctly using "other-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - profile: true -} -" -`; diff --git a/lib/creator/transformations/other/__testfixtures__/other-0.input.js b/lib/creator/transformations/other/__testfixtures__/other-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/other/__testfixtures__/other-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/other/amd.js b/lib/creator/transformations/other/amd.js deleted file mode 100644 index 8453e6105c1..00000000000 --- a/lib/creator/transformations/other/amd.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for amd. Finds the amd property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createAMDProperty(p) { - utils.pushCreateProperty(j, p, 'amd', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'amd'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createAMDProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/bail.js b/lib/creator/transformations/other/bail.js deleted file mode 100644 index b61d793f30a..00000000000 --- a/lib/creator/transformations/other/bail.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for bail. Finds the bail property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'bail', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/cache.js b/lib/creator/transformations/other/cache.js deleted file mode 100644 index ad0ee5d5e0c..00000000000 --- a/lib/creator/transformations/other/cache.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for cache. Finds the cache property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'cache', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/merge.js b/lib/creator/transformations/other/merge.js deleted file mode 100644 index b93d2f4bde8..00000000000 --- a/lib/creator/transformations/other/merge.js +++ /dev/null @@ -1,44 +0,0 @@ -/* -* -* Transform for merge. Finds the merge property from yeoman and creates a way -* for users to allow webpack-merge in their scaffold -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createMergeProperty(p) { - // FIXME Use j.callExp() - let exportsDecl = p.value.body.map( (n) => { - if(n.expression) { - return n.expression.right; - } - }); - const bodyLength = exportsDecl.length; - let newVal = {}; - newVal.type = 'ExpressionStatement'; - newVal.expression = { - type: 'AssignmentExpression', - operator: '=', - left: { - type: 'MemberExpression', - computed: false, - object: j.identifier('module'), - property: j.identifier('exports') - }, - right: j.callExpression( - j.identifier('merge'), - [j.identifier(webpackProperties), exportsDecl.pop()]) - }; - p.value.body[bodyLength - 1] = newVal; - } - if(webpackProperties) { - return ast.find(j.Program) - .filter(p => createMergeProperty(p)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/other/other.test.js b/lib/creator/transformations/other/other.test.js deleted file mode 100644 index ba9d0c66ac9..00000000000 --- a/lib/creator/transformations/other/other.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'amd', 'other-0', { - jQuery: true, - kQuery: false} -); -defineTest(__dirname, 'bail', 'other-0', true); -defineTest(__dirname, 'cache', 'other-0', true); -defineTest(__dirname, 'cache', 'other-0', 'cacheVal'); -defineTest(__dirname, 'profile', 'other-0', true); -defineTest(__dirname, 'merge', 'other-0', 'myConfig'); diff --git a/lib/creator/transformations/other/profile.js b/lib/creator/transformations/other/profile.js deleted file mode 100644 index bdb146dc9d4..00000000000 --- a/lib/creator/transformations/other/profile.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for profile. Finds the profile property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'profile', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/output/__snapshots__/output.test.js.snap b/lib/creator/transformations/output/__snapshots__/output.test.js.snap deleted file mode 100644 index 9c51ca710ee..00000000000 --- a/lib/creator/transformations/output/__snapshots__/output.test.js.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`output transforms correctly using "output-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle', - path: 'dist/assets', - pathinfo: true, - publicPath: 'https://google.com', - sourceMapFilename: '[name].map', - sourcePrefix: '\\\\t', - umdNamedDefine: true, - strictModuleExceptionHandling: true - } -} -" -`; diff --git a/lib/creator/transformations/output/__testfixtures__/output-0.input.js b/lib/creator/transformations/output/__testfixtures__/output-0.input.js deleted file mode 100644 index a9899df14fa..00000000000 --- a/lib/creator/transformations/output/__testfixtures__/output-0.input.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - entry: 'index.js' -} diff --git a/lib/creator/transformations/output/output.js b/lib/creator/transformations/output/output.js deleted file mode 100644 index ea69aaab02a..00000000000 --- a/lib/creator/transformations/output/output.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for output. Finds the output property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createOutputProperties(p) { - utils.pushCreateProperty(j, p, 'output', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'output'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createOutputProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/output/output.test.js b/lib/creator/transformations/output/output.test.js deleted file mode 100644 index 413ead9c291..00000000000 --- a/lib/creator/transformations/output/output.test.js +++ /dev/null @@ -1,13 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); -const jscodeshift = require('jscodeshift'); - -defineTest(__dirname, 'output', 'output-0', { - filename: '\'bundle\'', - path: '\'dist/assets\'', - pathinfo: true, - publicPath: '\'https://google.com\'', - sourceMapFilename: '\'[name].map\'', - sourcePrefix: jscodeshift('\'\t\''), - umdNamedDefine: true, - strictModuleExceptionHandling: true -}); diff --git a/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap b/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap deleted file mode 100644 index 93bd117add3..00000000000 --- a/lib/creator/transformations/performance/__snapshots__/performance.test.js.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`performance transforms correctly using "performance-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - performance: { - hints: 'warning', - maxEntrypointSize: 400000, - maxAssetSize: 100000, - assetFilter: function(assetFilename) {return assetFilename.endsWith('.js');} - } -} -" -`; diff --git a/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js b/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/performance/__testfixtures__/performance-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/performance/performance.js b/lib/creator/transformations/performance/performance.js deleted file mode 100644 index 7450f12df62..00000000000 --- a/lib/creator/transformations/performance/performance.js +++ /dev/null @@ -1,27 +0,0 @@ -const utils = require('../../../transformations/utils'); - - -/* -* -* Transform for performance. Finds the performance property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - function createPerformanceProperty(p) { - utils.pushCreateProperty(j, p, 'performance', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'performance'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createPerformanceProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/performance/performance.test.js b/lib/creator/transformations/performance/performance.test.js deleted file mode 100644 index 0e078cb5d24..00000000000 --- a/lib/creator/transformations/performance/performance.test.js +++ /dev/null @@ -1,10 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'performance', 'performance-0', { - hints: '\'warning\'', - maxEntrypointSize: 400000, - maxAssetSize: 100000, - assetFilter: 'function(assetFilename) {' + - 'return assetFilename.endsWith(\'.js\');' + - '}' -}); diff --git a/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap b/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap deleted file mode 100644 index 6fbe0c9fe35..00000000000 --- a/lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`plugins transforms correctly using "plugins-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - plugins: [ - new webpack.optimize.CommonsChunkPlugin({name:'vendor',filename:'vendor-[hash].min.js'}) - ] -} -" -`; diff --git a/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js b/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/plugins/plugins.js b/lib/creator/transformations/plugins/plugins.js deleted file mode 100644 index 33167582f29..00000000000 --- a/lib/creator/transformations/plugins/plugins.js +++ /dev/null @@ -1,25 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for plugins. Finds the plugins property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createPluginsProperty(p) { - const pluginArray = utils.createArrayWithChildren(j, 'plugins', webpackProperties, true); - return p.value.properties.push(pluginArray); - } - if(webpackProperties && Array.isArray(webpackProperties)) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createPluginsProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/plugins/plugins.test.js b/lib/creator/transformations/plugins/plugins.test.js deleted file mode 100644 index dde8d0ae2d5..00000000000 --- a/lib/creator/transformations/plugins/plugins.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'plugins', 'plugins-0', [ - 'new webpack.optimize.CommonsChunkPlugin({name:' + '\'' + 'vendor' + '\'' + ',filename:' + '\'' + 'vendor' + '-[hash].min.js\'})' -]); diff --git a/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap b/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap deleted file mode 100644 index 8e78a7cc775..00000000000 --- a/lib/creator/transformations/resolve/__snapshots__/resolve.test.js.snap +++ /dev/null @@ -1,39 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`resolve transforms correctly using "resolve-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - resolve: { - alias: { - {{#if_eq build 'standalone'}}, - hello: 'world', - {{/if_eq}}, - world: hello - }, - - aliasFields: ['browser', wars], - descriptionFiles: ['a', b], - enforceExtension: false, - enforceModuleExtension: false, - extensions: [hey, 'ho'], - mainFields: [main, 'story'], - mainFiles: ['noMainFileHere', iGuess], - modules: [one, 'two'], - unsafeCache: false, - resolveLoader: { - modules: ['node_modules', mode_nodules], - extensions: [jsVal, '.json'], - mainFields: [loader, 'main'], - moduleExtensions: ['-loader', value] - }, - - plugins: [somePlugin, 'stringVal'], - symlinks: true - } -} -" -`; diff --git a/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js b/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/resolve/__testfixtures__/resolve-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/resolve/resolve.js b/lib/creator/transformations/resolve/resolve.js deleted file mode 100644 index 66d572edb84..00000000000 --- a/lib/creator/transformations/resolve/resolve.js +++ /dev/null @@ -1,26 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for resolve. Finds the resolve property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createResolveProperties(p) { - utils.pushCreateProperty(j, p, 'resolve', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'resolve'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createResolveProperties)); - } - else { - return ast; - } -}; diff --git a/lib/creator/transformations/resolve/resolve.test.js b/lib/creator/transformations/resolve/resolve.test.js deleted file mode 100644 index 53218c2a4f3..00000000000 --- a/lib/creator/transformations/resolve/resolve.test.js +++ /dev/null @@ -1,27 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'resolve', 'resolve-0', { - alias: { - inject: '{{#if_eq build \'standalone\'}}', - hello: '\'world\'', - inject_1: '{{/if_eq}}', - world: 'hello', - }, - aliasFields: ['\'browser\'', 'wars'], - descriptionFiles: ['\'a\'', 'b'], - enforceExtension: false, - enforceModuleExtension: false, - extensions: ['hey', '\'ho\''], - mainFields: ['main', '\'story\''], - mainFiles: ['\'noMainFileHere\'', 'iGuess'], - modules: ['one', '\'two\''], - unsafeCache: false, - resolveLoader: { - modules: ['\'node_modules\'', 'mode_nodules'], - extensions: ['jsVal', '\'.json\''], - mainFields: ['loader', '\'main\''], - moduleExtensions: ['\'-loader\'', 'value'] - }, - plugins: ['somePlugin', '\'stringVal\''], - symlinks: true -}); diff --git a/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap b/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap deleted file mode 100644 index b94252a2e01..00000000000 --- a/lib/creator/transformations/stats/__snapshots__/stats.test.js.snap +++ /dev/null @@ -1,55 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`stats transforms correctly using "stats-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - stats: { - assets: true, - assetsSort: 'field', - cached: true, - cachedAssets: true, - children: true, - chunks: true, - chunkModules: true, - chunkOrigins: true, - chunksSort: 'field', - context: '../src/', - colors: true, - depth: false, - entrypoints: customVal, - errors: true, - errorDetails: true, - exclude: [], - hash: true, - maxModules: 15, - modules: true, - modulesSort: 'field', - performance: true, - providedExports: false, - publicPath: true, - reasons: true, - source: true, - timings: true, - usedExports: false, - version: true, - warnings: true - } -} -" -`; - -exports[`stats transforms correctly using "stats-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - stats: 'errors-only' -} -" -`; diff --git a/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js b/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/stats/__testfixtures__/stats-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/stats/stats.js b/lib/creator/transformations/stats/stats.js deleted file mode 100644 index 46a0e0ad5e3..00000000000 --- a/lib/creator/transformations/stats/stats.js +++ /dev/null @@ -1,29 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for stats. Finds the stats property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createStatsProperty(p) { - utils.pushCreateProperty(j, p, 'stats', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'stats'); - } - if(webpackProperties && typeof(webpackProperties) === 'object') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createStatsProperty)); - } - else if(webpackProperties && webpackProperties.length) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'stats', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/stats/stats.test.js b/lib/creator/transformations/stats/stats.test.js deleted file mode 100644 index 432eac37522..00000000000 --- a/lib/creator/transformations/stats/stats.test.js +++ /dev/null @@ -1,34 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'stats', 'stats-0', { - assets: true, - assetsSort: '\'field\'', - cached: true, - cachedAssets: true, - children: true, - chunks: true, - chunkModules: true, - chunkOrigins: true, - chunksSort: '\'field\'', - context: '\'../src/\'', - colors: true, - depth: false, - entrypoints: 'customVal', - errors: true, - errorDetails: true, - exclude: [], - hash: true, - maxModules: 15, - modules: true, - modulesSort: '\'field\'', - performance: true, - providedExports: false, - publicPath: true, - reasons: true, - source: true, - timings: true, - usedExports: false, - version: true, - warnings: true -}); -defineTest(__dirname, 'stats', 'stats-0', '\'errors-only\''); diff --git a/lib/creator/transformations/target/__snapshots__/target.test.js.snap b/lib/creator/transformations/target/__snapshots__/target.test.js.snap deleted file mode 100644 index 3af819e1ce2..00000000000 --- a/lib/creator/transformations/target/__snapshots__/target.test.js.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`target transforms correctly using "target-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - target: 'async-node' -} -" -`; - -exports[`target transforms correctly using "target-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - target: node -} -" -`; diff --git a/lib/creator/transformations/target/__testfixtures__/target-0.input.js b/lib/creator/transformations/target/__testfixtures__/target-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/target/__testfixtures__/target-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/target/__testfixtures__/target-1.input.js b/lib/creator/transformations/target/__testfixtures__/target-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/target/__testfixtures__/target-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/target/target.js b/lib/creator/transformations/target/target.js deleted file mode 100644 index 01501315d1d..00000000000 --- a/lib/creator/transformations/target/target.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for target. Finds the target property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - - if(webpackProperties && webpackProperties.length) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'target', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/target/target.test.js b/lib/creator/transformations/target/target.test.js deleted file mode 100644 index e42a7347a91..00000000000 --- a/lib/creator/transformations/target/target.test.js +++ /dev/null @@ -1,4 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'target', 'target-0', '\'async-node\''); -defineTest(__dirname, 'target', 'target-1', 'node'); diff --git a/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap b/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap deleted file mode 100644 index 9ceb4dcb14e..00000000000 --- a/lib/creator/transformations/top-scope/__snapshots__/top-scope.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`top-scope transforms correctly using "top-scope-0" data 1`] = ` -"var test = 'me'; -module.exports = {} -" -`; diff --git a/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js b/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js deleted file mode 100644 index 4ba52ba2c8d..00000000000 --- a/lib/creator/transformations/top-scope/__testfixtures__/top-scope-0.input.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/lib/creator/transformations/top-scope/top-scope.js b/lib/creator/transformations/top-scope/top-scope.js deleted file mode 100644 index 06e681d4577..00000000000 --- a/lib/creator/transformations/top-scope/top-scope.js +++ /dev/null @@ -1,22 +0,0 @@ - -/* -* -* Get an property named topScope from yeoman and inject it to the top scope of -* the config, outside module.exports -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing topscope properties -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createTopScopeProperty(p) { - webpackProperties.forEach( (n) => { - p.value.body.splice(-1, 0, n); - }); - } - if(webpackProperties) { - return ast.find(j.Program).filter(p => createTopScopeProperty(p)); - } -}; diff --git a/lib/creator/transformations/top-scope/top-scope.test.js b/lib/creator/transformations/top-scope/top-scope.test.js deleted file mode 100644 index da1398e55f9..00000000000 --- a/lib/creator/transformations/top-scope/top-scope.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'top-scope', 'top-scope-0', [ - 'var test = \'me\';' -]); diff --git a/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap b/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap deleted file mode 100644 index 964ece52812..00000000000 --- a/lib/creator/transformations/watch/__snapshots__/watch.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`watch transforms correctly using "watch-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: true -} -" -`; - -exports[`watch transforms correctly using "watch-0" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: false -} -" -`; - -exports[`watch transforms correctly using "watch-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: true -} -" -`; - -exports[`watch transforms correctly using "watch-1" data 2`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watch: false -} -" -`; diff --git a/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap b/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap deleted file mode 100644 index 6f93736f0fd..00000000000 --- a/lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`watchOptions transforms correctly using "watch-0" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; - -exports[`watchOptions transforms correctly using "watch-1" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; - -exports[`watchOptions transforms correctly using "watch-2" data 1`] = ` -"module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - }, - - watchOptions: { - aggregateTimeout: 300, - poll: 1000, - ignored: /node_modules/ - } -} -" -`; diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js b/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js deleted file mode 100644 index ea0822c2484..00000000000 --- a/lib/creator/transformations/watch/__testfixtures__/watch-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - entry: 'index.js', - output: { - filename: 'bundle.js' - } -} diff --git a/lib/creator/transformations/watch/watch.js b/lib/creator/transformations/watch/watch.js deleted file mode 100644 index 650ddd22805..00000000000 --- a/lib/creator/transformations/watch/watch.js +++ /dev/null @@ -1,21 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for watch. Finds the watch property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - if(typeof(webpackProperties) === 'boolean') { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(j, p, utils.pushCreateProperty, 'watch', webpackProperties)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/watch/watch.test.js b/lib/creator/transformations/watch/watch.test.js deleted file mode 100644 index c564fcba4ec..00000000000 --- a/lib/creator/transformations/watch/watch.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'watch', 'watch-0', true); -defineTest(__dirname, 'watch', 'watch-0', false); -defineTest(__dirname, 'watch', 'watch-1', true); -defineTest(__dirname, 'watch', 'watch-1', false); diff --git a/lib/creator/transformations/watch/watchOptions.js b/lib/creator/transformations/watch/watchOptions.js deleted file mode 100644 index b08c8218a5c..00000000000 --- a/lib/creator/transformations/watch/watchOptions.js +++ /dev/null @@ -1,25 +0,0 @@ -const utils = require('../../../transformations/utils'); - -/* -* -* Transform for watchOptions. Finds the watchOptions property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ - -module.exports = function(j, ast, webpackProperties) { - function createWatchOptionsProperty(p) { - utils.pushCreateProperty(j, p, 'watchOptions', j.objectExpression([])); - return utils.pushObjectKeys(j, p, webpackProperties, 'watchOptions'); - } - if(webpackProperties) { - return ast.find(j.ObjectExpression) - .filter(p => utils.isAssignment(null, p, createWatchOptionsProperty)); - } else { - return ast; - } -}; diff --git a/lib/creator/transformations/watch/watchOptions.test.js b/lib/creator/transformations/watch/watchOptions.test.js deleted file mode 100644 index 33eb8811e08..00000000000 --- a/lib/creator/transformations/watch/watchOptions.test.js +++ /dev/null @@ -1,19 +0,0 @@ -const defineTest = require('../../../transformations/defineTest'); - -defineTest(__dirname, 'watchOptions', 'watch-0', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); - -defineTest(__dirname, 'watchOptions', 'watch-1', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); - -defineTest(__dirname, 'watchOptions', 'watch-2', { - aggregateTimeout: 300, - poll: 1000, - ignored: '/node_modules/' -}); diff --git a/lib/creator/utils/run-prettier.js b/lib/creator/utils/run-prettier.js deleted file mode 100644 index 59f60b0e161..00000000000 --- a/lib/creator/utils/run-prettier.js +++ /dev/null @@ -1,33 +0,0 @@ -const prettier = require('prettier'); -const fs = require('fs'); -const chalk = require('chalk'); - -/* -* -* Runs prettier and later prints the output configuration -* -* @param { String } outputPath - Path to write the config to -* @param { Node } source - AST to write at the given path -* @returns fs - Writes a file at given location and prints messages accordingly -*/ - -module.exports = function runPrettier(outputPath, source) { - function validateConfig() { - let prettySource; - try { - prettySource = prettier.format(source, { - singleQuote: true, - useTabs: true, - tabWidth: 1, - }); - } catch(err) { - process.stdout.write('\n' + - chalk.yellow(`WARNING: Could not apply prettier to ${outputPath}` + - ' due validation error, but the file has been created\n') - ); - prettySource = source; - } - return fs.writeFileSync(outputPath, prettySource, 'utf8'); - } - return fs.writeFile(outputPath, source, 'utf8', validateConfig); -}; diff --git a/lib/migrate.js b/lib/migrate.js index 6a3db45a3cb..5ca27a3a67c 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -34,7 +34,7 @@ module.exports = function transformFile(currentConfigPath, outputConfigPath, opt { title: 'Migrating config from v1 to v2', task: (ctx) => { - const transformations = require('./transformations').transformations; + const transformations = require('webpack-addons').migrate; return new Listr(Object.keys(transformations).map(key => { const transform = transformations[key]; return { diff --git a/lib/transformations/__snapshots__/index.test.js.snap b/lib/transformations/__snapshots__/index.test.js.snap deleted file mode 100644 index 9391f6d62cc..00000000000 --- a/lib/transformations/__snapshots__/index.test.js.snap +++ /dev/null @@ -1,102 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -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: \\"babel\\", - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')], - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true, - }), - new webpack.optimize.LoaderOptionsPlugin({ - \\"debug\\": true, - \\"minimize\\": true, - }) - ], - debug: 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: ['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 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: 'babel', - include: path.join(__dirname, 'src') - }] - }, - resolve: { - modules: ['node_modules', path.resolve('/src')] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }), - new webpack.optimize.LoaderOptionsPlugin({ - 'debug': true, - 'minimize': true - }) - ], - debug: true -}; -" -`; diff --git a/lib/transformations/__snapshots__/utils.test.js.snap b/lib/transformations/__snapshots__/utils.test.js.snap deleted file mode 100644 index 9ebb6a83c1f..00000000000 --- a/lib/transformations/__snapshots__/utils.test.js.snap +++ /dev/null @@ -1,130 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`utils checkIfExistsAndAddValue should create new prop if none exist 1`] = ` -" - module.exports = { - entry: 'index.js', - externals: \\"React\\" - } - " -`; - -exports[`utils checkIfExistsAndAddValue should override prop if it exists 1`] = ` -" - module.exports = { - entry: \\"app.js\\" - } - " -`; - -exports[`utils createArrayWithChildren should add all children of an array to a new one with a supplied key 1`] = `"myVeryOwnKey: ['hello', world]"`; - -exports[`utils createArrayWithChildren should find an prop that matches key and create an array with it 1`] = `"react: ['bo']"`; - -exports[`utils createEmptyArrayProperty should create an array with no properties 1`] = `"its-lit: []"`; - -exports[`utils createExternalRegExp should create an regExp property that has been parsed by jscodeshift 1`] = `"\\"\\\\t\\""`; - -exports[`utils createIdentifierOrLiteral should create basic literal 1`] = `"'stringLiteral'"`; - -exports[`utils createIdentifierOrLiteral should create boolean 1`] = `"true"`; - -exports[`utils createLiteral should create basic literal 1`] = `"\\"stringLiteral\\""`; - -exports[`utils createLiteral should create boolean 1`] = `"true"`; - -exports[`utils createObjectWithSuppliedProperty should create an object with a property supplied by us 1`] = `"its-lit: {}"`; - -exports[`utils createOrUpdatePluginByName should add an object as an argument 1`] = ` -"[new Plugin({ - \\"foo\\": true -})]" -`; - -exports[`utils createOrUpdatePluginByName should create a new plugin with arguments 1`] = ` -"{ plugins: [new Plugin({ - \\"foo\\": \\"bar\\" -})] }" -`; - -exports[`utils createOrUpdatePluginByName should create a new plugin without arguments 1`] = `"{ plugins: [new Plugin()] }"`; - -exports[`utils createOrUpdatePluginByName should merge options objects 1`] = ` -"[new Plugin({ - \\"foo\\": false, - \\"bar\\": \\"baz\\", - \\"baz-long\\": true -})]" -`; - -exports[`utils createProperty should create properties for Boolean 1`] = ` -"{ - \\"foo\\": true -}" -`; - -exports[`utils createProperty should create properties for Number 1`] = ` -"{ - \\"foo\\": -1 -}" -`; - -exports[`utils createProperty should create properties for String 1`] = ` -"{ - \\"foo\\": \\"bar\\" -}" -`; - -exports[`utils createProperty should create properties for complex keys 1`] = ` -"{ - \\"foo-bar\\": \\"bar\\" -}" -`; - -exports[`utils createProperty should create properties for non-literal keys 1`] = ` -"{ - 1: \\"bar\\" -}" -`; - -exports[`utils getRequire should create a require statement 1`] = `"const filesys = require(\\"fs\\");"`; - -exports[`utils isAssignment should allow custom transform functions instead of singularProperty 1`] = ` -"module.exports = { - plugins: [one, two, three] -}" -`; - -exports[`utils isAssignment should invoke a callback if parent type is AssignmentExpression 1`] = ` -"module.exports = { - context: Heyho -}" -`; - -exports[`utils loopThroughObjects Use recursion and add elements to an node 1`] = ` -"module.exports = { - hello: { - webpack: cli - } -}" -`; - -exports[`utils pushCreateProperty should create an object or property and push the value to a node 1`] = ` -"module.exports = { - pushMe: { - just: pushed - } - }" -`; - -exports[`utils pushObjectKeys should push object to an node using Object.keys 1`] = ` -"module.exports = { - pushMe: { - hello: { - world: { - its: 'great' - } - } - } - }" -`; diff --git a/lib/transformations/__testfixtures__/failing.js b/lib/transformations/__testfixtures__/failing.js deleted file mode 100644 index 95de24dcb82..00000000000 --- a/lib/transformations/__testfixtures__/failing.js +++ /dev/null @@ -1,81 +0,0 @@ -var webpack = require('webpack'); -var nodeEnvironment = process.env.NODE_ENV -var _ = require('lodash'); - -var 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; \ No newline at end of file diff --git a/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap b/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap deleted file mode 100644 index c5460f20376..00000000000 --- a/lib/transformations/bannerPlugin/__snapshots__/bannerPlugin.test.js.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`bannerPlugin transforms correctly using "bannerPlugin-0" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.BannerPlugin({ - raw: true, - entryOnly: true, - 'banner': 'Banner' - }) - ] -} -" -`; - -exports[`bannerPlugin transforms correctly using "bannerPlugin-1" data 1`] = ` -"// Should do nothing if there is no banner plugin -module.exports = { - plugins: [] -} -" -`; - -exports[`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/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig b/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/bannerPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-0.input.js deleted file mode 100644 index 56c89e72d84..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-1.input.js deleted file mode 100644 index 0d66b9de1ac..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js b/lib/transformations/bannerPlugin/__testfixtures__/bannerPlugin-2.input.js deleted file mode 100644 index 90ecde8f0de..00000000000 --- a/lib/transformations/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/lib/transformations/bannerPlugin/bannerPlugin.js b/lib/transformations/bannerPlugin/bannerPlugin.js deleted file mode 100644 index 9f40d172f7d..00000000000 --- a/lib/transformations/bannerPlugin/bannerPlugin.js +++ /dev/null @@ -1,19 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - return utils.findPluginsByName(j, ast, ['webpack.BannerPlugin']) - .forEach(path => { - const args = path.value.arguments; - // If the first argument is a literal replace it with object notation - // See https://webpack.js.org/guides/migrating/#bannerplugin-breaking-change - if (args && args.length > 1 && args[0].type === j.Literal.name) { - // and remove the first argument - path.value.arguments = [path.value.arguments[1]]; - utils.createOrUpdatePluginByName(j, path.parent, 'webpack.BannerPlugin', { - banner: args[0].value - }); - } - }); - - -}; diff --git a/lib/transformations/bannerPlugin/bannerPlugin.test.js b/lib/transformations/bannerPlugin/bannerPlugin.test.js deleted file mode 100644 index fee919e427e..00000000000 --- a/lib/transformations/bannerPlugin/bannerPlugin.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-0'); -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-1'); -defineTest(__dirname, 'bannerPlugin', 'bannerPlugin-2'); diff --git a/lib/transformations/defineTest.js b/lib/transformations/defineTest.js deleted file mode 100644 index 2824337e41e..00000000000 --- a/lib/transformations/defineTest.js +++ /dev/null @@ -1,65 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); - -/** - * Utility function to run a jscodeshift script within a unit test. This makes - * several assumptions about the environment: - * - * - `dirName` contains the name of the directory the test is located in. This - * should normally be passed via __dirname. - * - The test should be located in a subdirectory next to the transform itself. - * Commonly tests are located in a directory called __tests__. - * - `transformName` contains the filename of the transform being tested, - * excluding the .js extension. - * - `testFilePrefix` optionally contains the name of the file with the test - * data. If not specified, it defaults to the same value as `transformName`. - * This will be suffixed with ".input.js" for the input file and ".output.js" - * for the expected output. For example, if set to "foo", we will read the - * "foo.input.js" file, pass this to the transform, and expect its output to - * be equal to the contents of "foo.output.js". - * - Test data should be located in a directory called __testfixtures__ - * alongside the transform and __tests__ directory. - */ -function runSingleTansform(dirName, transformName, testFilePrefix, initOptions) { - if (!testFilePrefix) { - testFilePrefix = transformName; - } - const fixtureDir = path.join(dirName, '__testfixtures__'); - const inputPath = path.join(fixtureDir, testFilePrefix + '.input.js'); - const source = fs.readFileSync(inputPath, 'utf8'); - // Assumes transform and test are on the same level - const module = require(path.join(dirName, transformName + '.js')); - // Handle ES6 modules using default export for the transform - const transform = module.default ? module.default : module; - - // Jest resets the module registry after each test, so we need to always get - // a fresh copy of jscodeshift on every test run. - let jscodeshift = require('jscodeshift/dist/core'); - if (module.parser) { - jscodeshift = jscodeshift.withParser(module.parser); - } - const ast = jscodeshift(source); - if (initOptions || typeof(initOptions) === 'boolean') { - return transform(jscodeshift, ast, initOptions).toSource({ quote: 'single' }); - } - return transform(jscodeshift, ast, source).toSource({ quote: 'single' }); -} - -/** - * Handles some boilerplate around defining a simple jest/Jasmine test for a - * jscodeshift transform. - */ -function defineTest(dirName, transformName, testFilePrefix, type) { - const testName = testFilePrefix - ? `transforms correctly using "${testFilePrefix}" data` - : 'transforms correctly'; - describe(transformName, () => { - it(testName, () => { - const output = runSingleTansform(dirName, transformName, testFilePrefix, type); - expect(output).toMatchSnapshot(); - }); - }); -} -module.exports = defineTest; diff --git a/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap b/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap deleted file mode 100644 index 0726589536c..00000000000 --- a/lib/transformations/extractTextPlugin/__snapshots__/extractTextPlugin.test.js.snap +++ /dev/null @@ -1,24 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`extractTextPlugin transforms correctly 1`] = ` -"let ExtractTextPlugin = require('extract-text-webpack-plugin'); -let HTMLWebpackPlugin = require('html-webpack-plugin'); - -module.export = { - module: { - rules: [ - { - test: /\\\\.css$/, - use: ExtractTextPlugin.extract({ - 'fallback': 'style-loader', - 'use': 'css-loader' - }) - } - ] - }, - plugins: [ - new ExtractTextPlugin(\\"styles.css\\"), - ] -} -" -`; diff --git a/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig b/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/extractTextPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js b/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js deleted file mode 100644 index f578bb4342d..00000000000 --- a/lib/transformations/extractTextPlugin/__testfixtures__/extractTextPlugin.input.js +++ /dev/null @@ -1,16 +0,0 @@ -let ExtractTextPlugin = require('extract-text-webpack-plugin'); -let HTMLWebpackPlugin = require('html-webpack-plugin'); - -module.export = { - module: { - rules: [ - { - test: /\.css$/, - use: ExtractTextPlugin.extract('style-loader', 'css-loader') - } - ] - }, - plugins: [ - new ExtractTextPlugin("styles.css"), - ] -} diff --git a/lib/transformations/extractTextPlugin/extractTextPlugin.js b/lib/transformations/extractTextPlugin/extractTextPlugin.js deleted file mode 100644 index 3d60fedffdb..00000000000 --- a/lib/transformations/extractTextPlugin/extractTextPlugin.js +++ /dev/null @@ -1,32 +0,0 @@ -const utils = require('../utils'); - -function findInvocation(j, node, pluginName) { - return j(node) - .find(j.MemberExpression) - .filter(p => p.get('object').value.name === pluginName).size() > 0; -} - -module.exports = function(j, ast) { - const changeArguments = function(p) { - const args = p.value.arguments; - // if(args.length === 1) { - // return p; - // } else - const literalArgs = args.filter(p => utils.isType(p, 'Literal')); - if (literalArgs && literalArgs.length > 1) { - const newArgs = j.objectExpression(literalArgs.map((p, index) => - utils.createProperty(j, index === 0 ? 'fallback': 'use', p.value) - )); - p.value.arguments = [newArgs]; - } - return p; - }; - const name = utils.findVariableToPlugin(j, ast, 'extract-text-webpack-plugin'); - if(!name) return ast; - - return ast.find(j.CallExpression) - .filter(p => findInvocation(j, p, name)) - .forEach(changeArguments); -}; - - diff --git a/lib/transformations/extractTextPlugin/extractTextPlugin.test.js b/lib/transformations/extractTextPlugin/extractTextPlugin.test.js deleted file mode 100644 index 66d74802356..00000000000 --- a/lib/transformations/extractTextPlugin/extractTextPlugin.test.js +++ /dev/null @@ -1,3 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'extractTextPlugin'); diff --git a/lib/transformations/index.js b/lib/transformations/index.js deleted file mode 100644 index 721b66612f5..00000000000 --- a/lib/transformations/index.js +++ /dev/null @@ -1,72 +0,0 @@ -const jscodeshift = require('jscodeshift'); -const pEachSeries = require('p-each-series'); -const PLazy = require('p-lazy'); - -const loadersTransform = require('./loaders/loaders'); -const resolveTransform = require('./resolve/resolve'); -const removeJsonLoaderTransform = require('./removeJsonLoader/removeJsonLoader'); -const uglifyJsPluginTransform = require('./uglifyJsPlugin/uglifyJsPlugin'); -const loaderOptionsPluginTransform = require('./loaderOptionsPlugin/loaderOptionsPlugin'); -const bannerPluginTransform = require('./bannerPlugin/bannerPlugin'); -const extractTextPluginTransform = require('./extractTextPlugin/extractTextPlugin'); -const removeDeprecatedPluginsTransform = require('./removeDeprecatedPlugins/removeDeprecatedPlugins'); - -const transformsObject = { - loadersTransform, - resolveTransform, - removeJsonLoaderTransform, - uglifyJsPluginTransform, - loaderOptionsPluginTransform, - bannerPluginTransform, - extractTextPluginTransform, - removeDeprecatedPluginsTransform -}; - -const transformations = Object.keys(transformsObject).reduce((res, key) => { - res[key] = (ast, source) => transformSingleAST(ast, source, transformsObject[key]); - return res; -}, {}); - -function transformSingleAST(ast, source, transformFunction) { - return new PLazy((resolve, reject) => { - setTimeout(() => { - try { - resolve(transformFunction(jscodeshift, ast, source)); - } catch (err) { - reject(err); - } - }, 0); - }); -} - -/* - * @function transform - * - * Tranforms a given source code by applying selected transformations to the AST - * - * @param { String } source - Source file contents - * @param { Array } transformations - List of trnasformation functions in defined the - * order to apply. By default all defined transfomations. - * @param { Object } options - Reacst formatting options - * @returns { String } Transformed source code - * */ -function transform(source, transforms, options) { - const ast = jscodeshift(source); - const recastOptions = Object.assign({ - quote: 'single' - }, options); - transforms = transforms || Object.keys(transformations).map(k => transformations[k]); - return pEachSeries(transforms, f => f(ast, source)) - .then(() => { - return ast.toSource(recastOptions); - }) - .catch(err => { - console.error(err); - }); -} - -module.exports = { - transform, - transformSingleAST, - transformations -}; diff --git a/lib/transformations/index.test.js b/lib/transformations/index.test.js deleted file mode 100644 index 4953beb8640..00000000000 --- a/lib/transformations/index.test.js +++ /dev/null @@ -1,64 +0,0 @@ -const transform = require('./index').transform; -const transformations = require('./index').transformations; - -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).toEqual(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/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap b/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap deleted file mode 100644 index 7dfde2ced53..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__snapshots__/loaderOptionsPlugin.test.js.snap +++ /dev/null @@ -1,60 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-0" data 1`] = ` -"// Do not create LoaderOptionsPlugin is not necessary -module.exports = { - plugins: [ - new SomePlugin() - ] -} -" -`; - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-1" data 1`] = ` -"module.exports = { - debug: true, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar', - 'debug': true, - 'minimize': true - }) - ] -} -" -`; - -exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-2" data 1`] = ` -"// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} -" -`; - -exports[`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/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig b/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-0.input.js deleted file mode 100644 index e809d6a36a9..00000000000 --- a/lib/transformations/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/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js deleted file mode 100644 index 60493cf28ab..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-1.input.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - debug: true, - plugins: [ - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js deleted file mode 100644 index 94fad11f784..00000000000 --- a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-2.input.js +++ /dev/null @@ -1,9 +0,0 @@ -// Don't modify LoaderOptionsPlugin -module.exports = { - plugins: [ - new SomePlugin(), - new webpack.optimize.LoaderOptionsPlugin({ - foo: 'bar' - }) - ] -} diff --git a/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js b/lib/transformations/loaderOptionsPlugin/__testfixtures__/loaderOptionsPlugin-3.input.js deleted file mode 100644 index 2a3baa56d23..00000000000 --- a/lib/transformations/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/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js b/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js deleted file mode 100644 index d959c4f56e0..00000000000 --- a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.js +++ /dev/null @@ -1,28 +0,0 @@ -const isEmpty = require('lodash/isEmpty'); -const findPluginsByName = require('../utils').findPluginsByName; -const createOrUpdatePluginByName = require('../utils').createOrUpdatePluginByName; -const safeTraverse = require('../utils').safeTraverse; - -module.exports = function(j, ast) { - const loaderOptions = {}; - - // If there is debug: true, set debug: true in the plugin - // TODO: remove global debug setting - // TODO: I can't figure out how to find the topmost `debug: true`. help! - if (ast.find(j.Identifier, { name: 'debug' }).size()) { - loaderOptions.debug = true; - } - - // If there is UglifyJsPlugin, set minimize: true - if (findPluginsByName(j, ast, ['webpack.optimize.UglifyJsPlugin']).size()) { - loaderOptions.minimize = true; - } - - return ast - .find(j.ArrayExpression) - .filter(path => safeTraverse(path, ['parent', 'value', 'key', 'name']) === 'plugins') - .forEach(path => { - !isEmpty(loaderOptions) && - createOrUpdatePluginByName(j, path, 'webpack.optimize.LoaderOptionsPlugin', loaderOptions); - }); -}; diff --git a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js b/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js deleted file mode 100644 index 1339fc4bf35..00000000000 --- a/lib/transformations/loaderOptionsPlugin/loaderOptionsPlugin.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-0'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-1'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-2'); -defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-3'); diff --git a/lib/transformations/loaders/__snapshots__/loaders.test.js.snap b/lib/transformations/loaders/__snapshots__/loaders.test.js.snap deleted file mode 100644 index b3c6522cca2..00000000000 --- a/lib/transformations/loaders/__snapshots__/loaders.test.js.snap +++ /dev/null @@ -1,169 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loaders transforms correctly using "loaders-0" data 1`] = ` -"export default [{ - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - 'loader': 'style' - }, { - 'loader': 'css?modules&importLoaders=1&string=test123' - }] - }] - } -}, { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - options: { - modules: true - } - }] - }] - } -}, { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -}, { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -}, { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -}]; -" -`; - -exports[`loaders transforms correctly using "loaders-1" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - 'loader': 'style' - }, { - 'loader': 'css?modules&importLoaders=1&string=test123' - }] - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-2" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.css$/, - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader', - options: { - modules: true - } - }] - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-3" data 1`] = ` -"export default { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-4" data 1`] = ` -"export default { - module: { - rules:[{ - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-5" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'eslint-loader', - 'enforce': 'pre' - }] - } -} -" -`; - -exports[`loaders transforms correctly using "loaders-6" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.js$/, - use: 'babel-loader' - }, { - test: /\\\\.js$/, - use: 'my-post-loader', - 'enforce': 'post' - }] - } -} -" -`; diff --git a/lib/transformations/loaders/__testfixtures__/.editorconfig b/lib/transformations/loaders/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/loaders/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/loaders/__testfixtures__/loaders-0.input.js b/lib/transformations/loaders/__testfixtures__/loaders-0.input.js deleted file mode 100644 index e0d498f6506..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-0.input.js +++ /dev/null @@ -1,65 +0,0 @@ -export default [{ - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel' - }] - } -}, { - module: { - loaders: [{ - test: /\.css$/, - loader: 'style!css?modules&importLoaders=1&string=test123' - }] - } -}, { - module: { - loaders: [{ - test: /\.css$/, - loaders: [{ - loader: 'style' - }, { - loader: 'css', - query: { - modules: true - } - }] - }] - } -}, { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint' - }] - } -}, { - module: { - postLoaders:[{ - test: /\.js$/, - loader: 'my-post' - }] - } -}, { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint-loader' - }], - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }] - } -}, { - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }], - postLoaders:[{ - test: /\.js$/, - loader: 'my-post-loader' - }] - } -}]; diff --git a/lib/transformations/loaders/__testfixtures__/loaders-1.input.js b/lib/transformations/loaders/__testfixtures__/loaders-1.input.js deleted file mode 100644 index eae75024e61..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-1.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.css$/, - loader: 'style!css?modules&importLoaders=1&string=test123' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-2.input.js b/lib/transformations/loaders/__testfixtures__/loaders-2.input.js deleted file mode 100644 index 771404a300c..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-2.input.js +++ /dev/null @@ -1,15 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.css$/, - loaders: [{ - loader: 'style' - }, { - loader: 'css', - query: { - modules: true - } - }] - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-3.input.js b/lib/transformations/loaders/__testfixtures__/loaders-3.input.js deleted file mode 100644 index 4d49e89a89b..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-3.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-4.input.js b/lib/transformations/loaders/__testfixtures__/loaders-4.input.js deleted file mode 100644 index cc3e076bed9..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-4.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - postLoaders:[{ - test: /\.js$/, - loader: 'my-post' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-5.input.js b/lib/transformations/loaders/__testfixtures__/loaders-5.input.js deleted file mode 100644 index 6fd315e4d08..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-5.input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default { - module: { - preLoaders:[{ - test: /\.js$/, - loader: 'eslint-loader' - }], - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }] - } -} diff --git a/lib/transformations/loaders/__testfixtures__/loaders-6.input.js b/lib/transformations/loaders/__testfixtures__/loaders-6.input.js deleted file mode 100644 index 184e4e1ad08..00000000000 --- a/lib/transformations/loaders/__testfixtures__/loaders-6.input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default { - module: { - loaders: [{ - test: /\.js$/, - loader: 'babel-loader' - }], - postLoaders:[{ - test: /\.js$/, - loader: 'my-post-loader' - }] - } -} diff --git a/lib/transformations/loaders/loaders.js b/lib/transformations/loaders/loaders.js deleted file mode 100644 index 2bb15f17a24..00000000000 --- a/lib/transformations/loaders/loaders.js +++ /dev/null @@ -1,137 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - - const createArrayExpression = function(p) { - let objs = p.parent.node.value.value.split('!') - .map(val => j.objectExpression([ - utils.createProperty(j, 'loader', val) - ])); - let loaderArray = j.arrayExpression(objs); - p.parent.node.value = loaderArray; - return p; - }; - - const createLoaderWithQuery = p => { - let properties = p.value.properties; - let loaderValue = properties - .reduce((val, prop) => prop.key.name === 'loader' ? prop.value.value : val, ''); - let loader = loaderValue.split('?')[0]; - let query = loaderValue.split('?')[1]; - let options = query.split('&').map(option => { - const param = option.split('='); - const key = param[0]; - const val = param[1] || true; // No value in query string means it is truthy value - return j.objectProperty(j.identifier(key), utils.createLiteral(val)); - }); - let loaderProp = utils.createProperty(j, 'loader', loader); - let queryProp = j.property('init', j.identifier('options'), j.objectExpression(options)); - return j.objectExpression([loaderProp, queryProp]); - }; - - const findLoaderWithQueryString = p => { - return p.value.properties - .reduce((predicate, prop) => { - return utils.safeTraverse(prop, ['value', 'value', 'indexOf']) - && prop.value.value.indexOf('?') > -1 - || predicate; - }, false); - }; - - const checkForLoader = p => p.value.name === 'loaders' && utils.safeTraverse(p, - ['parent', 'parent', 'parent', 'node', 'key', 'name']) === 'module'; - - const fitIntoLoaders = p => { - let loaders; - p.value.properties.map(prop => { - const keyName = prop.key.name; - if (keyName === 'loaders') { - loaders = prop.value; - } - }); - p.value.properties.map(prop => { - const keyName = prop.key.name; - if (keyName !== 'loaders') { - const enforceVal = keyName === 'preLoaders' ? 'pre' : 'post'; - - prop.value.elements.map(elem => { - elem.properties.push(utils.createProperty(j, 'enforce', enforceVal)); - if (loaders && loaders.type === 'ArrayExpression') { - loaders.elements.push(elem); - } else { - prop.key.name = 'loaders'; - } - }); - } - }); - if (loaders) { - p.value.properties = p.value.properties.filter(prop => prop.key.name === 'loaders'); - } - return p; - }; - - const prepostLoaders = () => ast - .find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, ['preLoaders', 'postLoaders'])) - .forEach(p => p = fitIntoLoaders(p)); - - const loadersToRules = () => ast - .find(j.Identifier) - .filter(checkForLoader) - .forEach(p => p.value.name = 'rules'); - - const loaderToUse = () => ast - .find(j.Identifier) - .filter(p => { - return (p.value.name === 'loaders' || p.value.name === 'loader') - && utils.safeTraverse(p, - ['parent', 'parent', 'parent', 'parent', 'node', 'key', 'name']) === 'rules'; - }) - .forEach(p => p.value.name = 'use'); - - const loadersInArray = () => ast - .find(j.Identifier) - .filter(p => { - return p.value.name === 'use' - && p.parent.node.value.type === 'Literal' - && p.parent.node.value.value.indexOf('!') > 0; - }) - .forEach(createArrayExpression); - - const loaderWithQueryParam = () => ast - .find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, 'loader')) - .filter(findLoaderWithQueryString) - .replaceWith(createLoaderWithQuery); - - const loaderWithQueryProp = () => ast - .find(j.Identifier) - .filter(p => p.value.name === 'query') - .replaceWith(j.identifier('options')); - - const addLoaderSuffix = () => ast - .find(j.ObjectExpression) - .forEach(path => { - path.value.properties.forEach(prop => { - if ((prop.key.name === 'loader' || prop.key.name === 'use') - && utils.safeTraverse(prop, ['value', 'value']) - && prop.value.value.indexOf('-loader') === -1) { - prop.value = j.literal(prop.value.value + '-loader'); - } - }); - }) - .toSource(); - - const transforms = [ - prepostLoaders, - loadersToRules, - loaderToUse, - loadersInArray, - loaderWithQueryParam, - loaderWithQueryProp, - addLoaderSuffix - ]; - transforms.forEach(t => t()); - - return ast; -}; diff --git a/lib/transformations/loaders/loaders.test.js b/lib/transformations/loaders/loaders.test.js deleted file mode 100644 index 3e77665cbe2..00000000000 --- a/lib/transformations/loaders/loaders.test.js +++ /dev/null @@ -1,9 +0,0 @@ -const defineTest = require('../defineTest'); - -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'); diff --git a/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap b/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap deleted file mode 100644 index 27e07047768..00000000000 --- a/lib/transformations/outputPath/__snapshots__/outputPath.test.js.snap +++ /dev/null @@ -1,30 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`outputPath transforms correctly using "outputPath-0" data 1`] = ` -"module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} -" -`; - -exports[`outputPath transforms correctly using "outputPath-1" data 1`] = ` -"const path = require('path'); -module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} -" -`; - -exports[`outputPath transforms correctly using "outputPath-2" data 1`] = ` -"const p = require('path'); -module.exports = { - output: { - path: p.join(__dirname, 'dist') - } -} -" -`; diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js deleted file mode 100644 index 085268fadbe..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - output: { - path: 'dist' - } -} diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js deleted file mode 100644 index c7a0ed58e7a..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -const path = require('path'); -module.exports = { - output: { - path: path.join(__dirname, 'dist') - } -} diff --git a/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js b/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js deleted file mode 100644 index de8436ae6c3..00000000000 --- a/lib/transformations/outputPath/__testfixtures__/outputPath-2.input.js +++ /dev/null @@ -1,6 +0,0 @@ -const p = require('path'); -module.exports = { - output: { - path: 'dist' - } -} diff --git a/lib/transformations/outputPath/outputPath.js b/lib/transformations/outputPath/outputPath.js deleted file mode 100644 index 78226dc345f..00000000000 --- a/lib/transformations/outputPath/outputPath.js +++ /dev/null @@ -1,51 +0,0 @@ -const utils = require('../utils'); - -module.exports = function(j, ast) { - const literalOutputPath = ast - .find(j.ObjectExpression) - .filter(p => utils.safeTraverse(p, ['parentPath', 'value', 'key', 'name']) === 'output') - .find(j.Property) - .filter(p => utils.safeTraverse(p, ['value', 'key', 'name']) === 'path' - && utils.safeTraverse(p, ['value', 'value', 'type']) === 'Literal'); - - if (literalOutputPath) { - let pathVarName = 'path'; - let isPathPresent = false; - const pathDecalaration = ast - .find(j.VariableDeclarator) - .filter(p => utils.safeTraverse(p, ['value', 'init', 'callee', 'name']) === 'require') - .filter(p => utils.safeTraverse(p, ['value', 'init', 'arguments']) - && p.value.init.arguments.reduce((isPresent, a) => { - return a.type === 'Literal' && a.value === 'path' || isPresent; - }, false)); - - if (pathDecalaration) { - isPathPresent = true; - pathDecalaration.forEach(p => { - pathVarName = utils.safeTraverse(p, ['value', 'id', 'name']); - }); - } - - literalOutputPath - .find(j.Literal) - .replaceWith(p => replaceWithPath(j, p, pathVarName)); - - if(!isPathPresent){ - const pathRequire = utils.getRequire(j, 'path', 'path'); - return ast.find(j.Program) - .replaceWith(p => j.program([].concat(pathRequire).concat(p.value.body))); - } - } - return ast; -}; - -function replaceWithPath(j, p, pathVarName) { - const convertedPath = j.callExpression( - j.memberExpression( - j.identifier(pathVarName), - j.identifier('join'), - false), - [j.identifier('__dirname'), p.value]); - return convertedPath; -} - diff --git a/lib/transformations/outputPath/outputPath.test.js b/lib/transformations/outputPath/outputPath.test.js deleted file mode 100644 index d1041b30274..00000000000 --- a/lib/transformations/outputPath/outputPath.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'outputPath', 'outputPath-0'); -defineTest(__dirname, 'outputPath', 'outputPath-1'); -defineTest(__dirname, 'outputPath', 'outputPath-2'); diff --git a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap b/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap deleted file mode 100644 index 550faf1fba2..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap +++ /dev/null @@ -1,44 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-0" data 1`] = ` -"// Works for OccurrenceOrderPlugin -module.exports = {} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-1" data 1`] = ` -"// Works for DedupePlugin -module.exports = {} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-2" data 1`] = ` -"// Doesn't remove unmatched plugins -module.exports = { - plugins: [new webpack.optimize.UglifyJsPlugin()] -} -" -`; - -exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-3" data 1`] = ` -"// This should throw -export default (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[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-4" data 1`] = ` -"// This should throw -const inst = new webpack.optimize.OccurrenceOrderPlugin() -export default (config) => { - config.plugins = [ - inst - ] - return config -} -" -`; diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js deleted file mode 100644 index 133c4984bfd..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-0.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Works for OccurrenceOrderPlugin -module.exports = { - plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js deleted file mode 100644 index a64dab79b37..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -// Works for DedupePlugin -module.exports = { - plugins: [ - new webpack.optimize.DedupePlugin(), - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js deleted file mode 100644 index 26150117db4..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-2.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// Doesn't remove unmatched plugins -module.exports = { - plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.DedupePlugin() - ] -} diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js deleted file mode 100644 index 1d5194460e3..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-3.input.js +++ /dev/null @@ -1,7 +0,0 @@ -// This should throw -export default (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/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js deleted file mode 100644 index fab47caf971..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js +++ /dev/null @@ -1,8 +0,0 @@ -// This should throw -const inst = new webpack.optimize.OccurrenceOrderPlugin() -export default (config) => { - config.plugins = [ - inst - ] - return config -} diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js deleted file mode 100644 index a3d193800f3..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js +++ /dev/null @@ -1,47 +0,0 @@ -const codeFrame = require('babel-code-frame'); -const chalk = require('chalk'); -const utils = require('../utils'); - -const example = `plugins: [ - new webpack.optimize.OccurrenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.DedupePlugin() -]`; - -module.exports = function(j, ast, source) { - // List of deprecated plugins to remove - // each item refers to webpack.optimize.[NAME] construct - const deprecatedPlugingsList = [ - 'webpack.optimize.OccurrenceOrderPlugin', - 'webpack.optimize.DedupePlugin' - ]; - - return utils.findPluginsByName(j, ast, deprecatedPlugingsList) - .forEach(path => { - // For now we only support the case there plugins are defined in an Array - const arrayPath = utils.safeTraverse(path, ['parent','value']); - if (arrayPath && utils.isType(arrayPath, 'ArrayExpression')) { - // Check how many plugins are defined and - // if there is only last plugin left remove `plugins: []` node - const arrayElementsPath = utils.safeTraverse(arrayPath, ['elements']); - if (arrayElementsPath && arrayElementsPath.length === 1) { - j(path.parent.parent).remove(); - } else { - j(path).remove(); - } - } else { - const startLoc = path.value.loc.start; - console.log(` -${ chalk.red('Only plugins instantiated in the array can be automatically removed i.e.:') } - -${ codeFrame(example, null, null, { highlightCode: true }) } - -${ chalk.red('but you use it like this:') } - -${ codeFrame(source, startLoc.line, startLoc.column, { highlightCode: true }) } - -${ chalk.red('Please remove deprecated plugins manually. ') } -See ${ chalk.underline('https://webpack.js.org/guides/migrating/')} for more information.`); - } - }); -}; diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js deleted file mode 100644 index 748a0c35ea1..00000000000 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js +++ /dev/null @@ -1,7 +0,0 @@ -const defineTest = require('../defineTest'); - -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/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap b/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap deleted file mode 100644 index d678b8950c8..00000000000 --- a/lib/transformations/removeJsonLoader/__snapshots__/removeJsonLoader.test.js.snap +++ /dev/null @@ -1,51 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-0" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: ['another-loader', 'yml-loader'] - }] - } -} - -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-1" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: 'yml-loader' - }] - } -} -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-2" data 1`] = ` -"export default { - module: { - rules: [] - } -} -" -`; - -exports[`removeJsonLoader transforms correctly using "removeJsonLoader-3" data 1`] = ` -"export default { - module: { - rules: [{ - test: /\\\\.yml/, - use: ['another-loader', 'yml-loader'] - }, { - test: /\\\\.yml/, - use: 'yml-loader' - }] - } -} - -" -`; diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig b/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js deleted file mode 100644 index f6c9a9da3ab..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-0.input.js +++ /dev/null @@ -1,9 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'another-loader', 'yml-loader'] - }] - } -} - diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js deleted file mode 100644 index 05d06f79820..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-1.input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'yml-loader'] - }] - } -} diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js deleted file mode 100644 index cc35396659d..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-2.input.js +++ /dev/null @@ -1,10 +0,0 @@ -export default { - module: { - rules: [ - { - test: /\.json/, - use: 'json-loader' - } - ] - } -} diff --git a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js b/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js deleted file mode 100644 index 247cb56f567..00000000000 --- a/lib/transformations/removeJsonLoader/__testfixtures__/removeJsonLoader-3.input.js +++ /dev/null @@ -1,15 +0,0 @@ -export default { - module: { - rules: [{ - test: /\.yml/, - use: ['json-loader', 'another-loader', 'yml-loader'] - }, { - test: /\.yml/, - use: ['json-loader', 'yml-loader'] - }, { - test: /\.json/, - use: 'json-loader' - }] - } -} - diff --git a/lib/transformations/removeJsonLoader/removeJsonLoader.js b/lib/transformations/removeJsonLoader/removeJsonLoader.js deleted file mode 100644 index 0b7bcbac56f..00000000000 --- a/lib/transformations/removeJsonLoader/removeJsonLoader.js +++ /dev/null @@ -1,48 +0,0 @@ -module.exports = function(j, ast) { - function getLoadersPropertyPaths(ast) { - return ast.find(j.Property, { key: { name: 'use' } }); - } - - function removeLoaderByName(path, name) { - const loadersNode = path.value.value; - switch (loadersNode.type) { - case j.ArrayExpression.name: { - let loaders = loadersNode.elements.map(p => p.value); - const loaderIndex = loaders.indexOf(name); - if (loaders.length && loaderIndex > -1) { - // Remove loader from the array - loaders.splice(loaderIndex, 1); - // and from AST - loadersNode.elements.splice(loaderIndex, 1); - } - - // If there is only one element left, convert to string - if (loaders.length === 1) { - j(path.get('value')).replaceWith(j.literal(loaders[0])); - } - break; - } - case j.Literal.name: { - // If only the loader with the matching name was used - // we can remove the whole Property node completely - if (loadersNode.value === name) { - j(path.parent).remove(); - } - break; - } - } - } - - function removeLoaders(ast) { - getLoadersPropertyPaths(ast) - .forEach(path => removeLoaderByName(path, 'json-loader')); - } - - const transforms = [ - removeLoaders - ]; - - transforms.forEach(t => t(ast)); - - return ast; -}; diff --git a/lib/transformations/removeJsonLoader/removeJsonLoader.test.js b/lib/transformations/removeJsonLoader/removeJsonLoader.test.js deleted file mode 100644 index 164f0045ee1..00000000000 --- a/lib/transformations/removeJsonLoader/removeJsonLoader.test.js +++ /dev/null @@ -1,6 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-0'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-1'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-2'); -defineTest(__dirname, 'removeJsonLoader', 'removeJsonLoader-3'); diff --git a/lib/transformations/resolve/__snapshots__/resolve.test.js.snap b/lib/transformations/resolve/__snapshots__/resolve.test.js.snap deleted file mode 100644 index 820fc965a13..00000000000 --- a/lib/transformations/resolve/__snapshots__/resolve.test.js.snap +++ /dev/null @@ -1,24 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`resolve transforms correctly 1`] = ` -"import path from 'path'; - -export default [{ - resolve: { - modules: [path.resolve('/src')] - } -}, { - resolve: { - modules: [path.resolve('/src')] - } -}, { - resolve: { - modules: [path.resolve('/src'), 'node_modules'] - } -}, { - resolve: { - modules: ['node_modules', path.resolve('/src')] - } -}]; -" -`; diff --git a/lib/transformations/resolve/__testfixtures__/.editorconfig b/lib/transformations/resolve/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/resolve/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/resolve/__testfixtures__/resolve.input.js b/lib/transformations/resolve/__testfixtures__/resolve.input.js deleted file mode 100644 index 2b83fcf26ce..00000000000 --- a/lib/transformations/resolve/__testfixtures__/resolve.input.js +++ /dev/null @@ -1,20 +0,0 @@ -import path from 'path'; - -export default [{ - resolve: { - root: path.resolve('/src') - } -}, { - resolve: { - root: [path.resolve('/src')] - } -}, { - resolve: { - root: [path.resolve('/src'), 'node_modules'] - } -}, { - resolve: { - root: path.resolve('/src'), - modules: ['node_modules'] - } -}]; diff --git a/lib/transformations/resolve/resolve.js b/lib/transformations/resolve/resolve.js deleted file mode 100644 index 3912703e9e0..00000000000 --- a/lib/transformations/resolve/resolve.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function transformer(j, ast) { - - const getRootVal = p => { - return p.node.value.properties.filter(prop => prop.key.name === 'root')[0]; - }; - - const getRootIndex = p => { - return p.node.value.properties - .reduce((rootIndex, prop, index) => { - return prop.key.name === 'root' ? index : rootIndex; - }, -1); - }; - - const isModulePresent = p => { - const modules = p.node.value.properties.filter(prop => prop.key.name === 'modules'); - return modules.length > 0 && modules[0]; - }; - - const createModuleArray = p => { - const rootVal = getRootVal(p); - let modulesVal = null; - if (rootVal.value.type === 'ArrayExpression') { - modulesVal = rootVal.value.elements; - } else { - modulesVal = [rootVal.value]; - } - let module = isModulePresent(p); - - if (!module) { - module = j.property('init', j.identifier('modules'), j.arrayExpression(modulesVal)); - p.node.value.properties = p.node.value.properties.concat([module]); - } else { - module.value.elements = module.value.elements.concat(modulesVal); - } - const rootIndex = getRootIndex(p); - p.node.value.properties.splice(rootIndex, 1); - return p; - }; - - return ast - .find(j.Property) - .filter(p => { - return p.node.key.name === 'resolve' - && p.node.value.properties - .filter(prop => prop.key.name === 'root') - .length === 1; - }) - .forEach(createModuleArray); -}; diff --git a/lib/transformations/resolve/resolve.test.js b/lib/transformations/resolve/resolve.test.js deleted file mode 100644 index 30a26b5348b..00000000000 --- a/lib/transformations/resolve/resolve.test.js +++ /dev/null @@ -1,3 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'resolve'); diff --git a/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap b/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap deleted file mode 100644 index 9d5fb3b28bb..00000000000 --- a/lib/transformations/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = ` -"module.exports = { - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }) - ] -} -" -`; - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-1" data 1`] = ` -"module.exports = { - devtool: \\"source-map\\", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true - }) - ] -} -" -`; - -exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-2" data 1`] = ` -"module.exports = { - devtool: \\"cheap-source-map\\", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - compress: {}, - sourceMap: true - }) - ] -} -" -`; diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig b/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig deleted file mode 100644 index adbdb1ba476..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*] -indent_style = space -indent_size = 4 diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js deleted file mode 100644 index 900f7042075..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-0.input.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - plugins: [ - new webpack.optimize.UglifyJsPlugin() - ] -} diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js deleted file mode 100644 index 57d7eb1c192..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-1.input.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - devtool: "source-map", - plugins: [ - new webpack.optimize.UglifyJsPlugin({}) - ] -} diff --git a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js b/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js deleted file mode 100644 index 3c13f02b203..00000000000 --- a/lib/transformations/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - devtool: "cheap-source-map", - plugins: [ - new webpack.optimize.UglifyJsPlugin({ - compress: {} - }) - ] -} diff --git a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js b/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js deleted file mode 100644 index f5c4a12af3b..00000000000 --- a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js +++ /dev/null @@ -1,25 +0,0 @@ -const findPluginsByName = require('../utils').findPluginsByName; - -module.exports = function(j, ast) { - - function createSourceMapsProperty() { - return j.property('init', j.identifier('sourceMap'), j.identifier('true')); - } - - return findPluginsByName(j, ast, ['webpack.optimize.UglifyJsPlugin']) - .forEach(path => { - const args = path.value.arguments; - - if (args.length) { - // Plugin is called with object as arguments - j(path) - .find(j.ObjectExpression) - .get('properties') - .value - .push(createSourceMapsProperty()); - } else { - // Plugin is called without arguments - args.push(j.objectExpression([createSourceMapsProperty()])); - } - }); -}; diff --git a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js b/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js deleted file mode 100644 index a0c309ccb1e..00000000000 --- a/lib/transformations/uglifyJsPlugin/uglifyJsPlugin.test.js +++ /dev/null @@ -1,5 +0,0 @@ -const defineTest = require('../defineTest'); - -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-0'); -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-1'); -defineTest(__dirname, 'uglifyJsPlugin', 'uglifyJsPlugin-2'); diff --git a/lib/transformations/utils.js b/lib/transformations/utils.js deleted file mode 100644 index 73623e70276..00000000000 --- a/lib/transformations/utils.js +++ /dev/null @@ -1,526 +0,0 @@ -function safeTraverse(obj, paths) { - let val = obj; - let idx = 0; - - while (idx < paths.length) { - if (!val) { - return null; - } - val = val[paths[idx]]; - idx++; - } - return val; -} - -// Convert nested MemberExpressions to strings like webpack.optimize.DedupePlugin -function memberExpressionToPathString(path) { - if (path && path.object) { - return [memberExpressionToPathString(path.object), path.property.name].join('.'); - } - return path.name; -} - -// Convert Array like ['webpack', 'optimize', 'DedupePlugin'] to nested MemberExpressions -function pathsToMemberExpression(j, paths) { - if (!paths.length) { - return null; - } else if (paths.length === 1) { - return j.identifier(paths[0]); - } else { - const first = paths.slice(0, 1); - const rest = paths.slice(1); - return j.memberExpression( - pathsToMemberExpression(j, rest), - pathsToMemberExpression(j, first) - ); - } -} - -/* -* @function findPluginsByName -* -* Find paths that match `new name.space.PluginName()` for a given array of plugin names -* -* @param j — jscodeshift API -* @param { Node } node - Node to start search from -* @param { Array } pluginNamesArray - Array of plugin names like `webpack.optimize.LoaderOptionsPlugin` -* @returns Path - * */ -function findPluginsByName(j, node, pluginNamesArray) { - return node - .find(j.NewExpression) - .filter(path => { - return pluginNamesArray.some( - plugin => memberExpressionToPathString(path.get('callee').value) === plugin - ); - }); -} - -/* - * @function findPluginsRootNodes - * - * Finds the path to the `plugins: []` node - * - * @param j — jscodeshift API - * @param { Node } node - Node to start search from - * @returns Path - * */ -function findPluginsRootNodes(j, node) { - return node.find(j.Property, { key: { name: 'plugins' } }); -} - -/* - * @function createProperty - * - * Creates an Object's property with a given key and value - * - * @param j — jscodeshift API - * @param { string | number } key - Property key - * @param { string | number | boolean } value - Property value - * @returns Node - * */ -function createProperty(j, key, value) { - return j.property( - 'init', - createLiteral(j, key), - createLiteral(j, value) - ); -} - -/* - * @function createLiteral - * - * Creates an appropriate literal property - * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ - -function createLiteral(j, val) { - let literalVal = val; - // We'll need String to native type conversions - if (typeof val === 'string') { - // 'true' => true - if (val === 'true') literalVal = true; - // 'false' => false - if (val === 'false') literalVal = false; - // '1' => 1 - if (!isNaN(Number(val))) literalVal = Number(val); - } - return j.literal(literalVal); -} - -/* - * @function createIdentifierOrLiteral - * - * Creates an appropriate identifier or literal property - * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ - -function createIdentifierOrLiteral(j, val) { - let literalVal = val; - // We'll need String to native type conversions - if (typeof val === 'string' || val.__paths) { - // 'true' => true - if (val === 'true') { - literalVal = true; - return j.literal(literalVal); - } - // 'false' => false - if (val === 'false') { - literalVal = false; - return j.literal(literalVal); - } - // '1' => 1 - if (!isNaN(Number(val))) { - literalVal = Number(val); - return j.literal(literalVal); - } - - if(val.__paths) { - return createExternalRegExp(j, val); - } - // Use identifier instead - else { - return j.identifier(literalVal); - } - } - return j.literal(literalVal); -} -/* - * @function createOrUpdatePluginByName - * - * Findes or creates a node for a given plugin name string with options object - * If plugin decalaration already exist, options are merged. - * - * @param j — jscodeshift API - * @param { NodePath } rooNodePath - `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginName - ex. `webpack.optimize.LoaderOptionsPlugin` - * @param { Object } options - plugin options - * @returns void - * */ -function createOrUpdatePluginByName(j, rootNodePath, pluginName, options) { - const pluginInstancePath = findPluginsByName(j, j(rootNodePath), [pluginName]); - let optionsProps; - if (options) { - optionsProps = Object.keys(options).map(key => { - return createProperty(j, key, options[key]); - }); - } - - // If plugin declaration already exist - if (pluginInstancePath.size()) { - pluginInstancePath.forEach(path => { - // There are options we want to pass as argument - if (optionsProps) { - const args = path.value.arguments; - if (args.length) { - // Plugin is called with object as arguments - // we will merge those objects - let currentProps = j(path) - .find(j.ObjectExpression) - .get('properties'); - - optionsProps.forEach(opt => { - // Search for same keys in the existing object - const existingProps = j(currentProps) - .find(j.Identifier) - .filter(path => opt.key.value === path.value.name); - - if (existingProps.size()) { - // Replacing values for the same key - existingProps.forEach(path => { - j(path.parent).replaceWith(opt); - }); - } else { - // Adding new key:values - currentProps.value.push(opt); - } - }); - - } else { - // Plugin is called without arguments - args.push( - j.objectExpression(optionsProps) - ); - } - } - }); - } else { - let argumentsArray = []; - if (optionsProps) { - argumentsArray = [j.objectExpression(optionsProps)]; - } - const loaderPluginInstance = j.newExpression( - pathsToMemberExpression(j, pluginName.split('.').reverse()), - argumentsArray - ); - rootNodePath.value.elements.push(loaderPluginInstance); - } -} - -/* - * @function findVariableToPlugin - * - * Finds the variable to which a third party plugin is assigned to - * - * @param j — jscodeshift API - * @param { Node } rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginPackageName - ex. `extract-text-plugin` - * @returns { string } variable name - ex. 'var s = require(s) gives "s"` - * */ - -function findVariableToPlugin(j, rootNode, pluginPackageName){ - const moduleVarNames = rootNode.find(j.VariableDeclarator) - .filter(j.filters.VariableDeclarator.requiresModule(pluginPackageName)) - .nodes(); - if (moduleVarNames.length === 0) return null; - return moduleVarNames.pop().id.name; -} - -/* -* @function isType -* -* Returns true if type is given type -* @param { Node} path - pathNode -* @param { string } type - node type -* @returns {boolean} -*/ - -function isType(path, type) { - return path.type === type; -} - -function findObjWithOneOfKeys (p, keyNames) { - return p.value.properties - .reduce((predicate, prop) => { - const name = prop.key.name; - return keyNames.indexOf(name) > -1 - || predicate; - }, false); -} - -/* -* @function getRequire -* -* Returns constructed require symbol -* @param j — jscodeshift API -* @param { string } constName - Name of require -* @param { string } packagePath - path of required package -* @returns {NodePath} - the created ast -*/ - -function getRequire(j, constName, packagePath) { - return j.variableDeclaration('const', [ - j.variableDeclarator( - j.identifier(constName), - j.callExpression( - j.identifier('require'), - [j.literal(packagePath)] - ) - ) - ]); -} - -/* -* @function checkIfExistsAndAddValue -* -* If a prop exists, it overrides it, else it creates a new one -* @param j — jscodeshift API -* @param { Node } node - objectexpression to check -* @param { string } key - Key of the property -* @param { string } value - computed value of the property -* @returns - nothing -*/ - -function checkIfExistsAndAddValue(j, node, key, value) { - const existingProp = node.value.properties.filter(prop => prop.key.name === key); - let prop; - if (existingProp.length > 0){ - prop = existingProp[0]; - prop.value = value; - } else { - prop = j.property('init', j.identifier(key), value); - node.value.properties.push(prop); - } -} - -/* -* @function createEmptyArrayProperty -* -* Creates an empty array -* @param j — jscodeshift API -* @param { String } key - st name -* @returns - { Array } arr - An empty array -*/ -function createEmptyArrayProperty(j, key) { - return j.property('init', j.identifier(key), j.arrayExpression([])); -} - -/* -* @function createArrayWithChildren -* -* Creates an array and iterates on an object with properties -* @param j — jscodeshift API -* @param { String } key - object name -* @param { string } subProps - computed value of the property -* @returns - { Array } arr - An array with the object properties -*/ - -function createArrayWithChildren(j, key, subProps, shouldDropKeys) { - let arr = createEmptyArrayProperty(j, key); - if(shouldDropKeys) { - subProps.forEach( (subProperty) => { - let objectOfArray = j.objectExpression([]); - if(typeof(subProperty) !== 'string') { - loopThroughObjects(j, objectOfArray, subProperty); - arr.value.elements.push(objectOfArray); - } else { - return arr.value.elements.push(createIdentifierOrLiteral(j, subProperty)); - } - }); - } else { - Object.keys(subProps[key]).forEach( (subProperty) => { - arr.value.elements.push(createIdentifierOrLiteral(j, subProps[key][subProperty])); - }); - } - return arr; -} - -/* -* @function loopThroughObjects -* -* Loops through an object and adds property to an object with no identifier -* @param j — jscodeshift API -* @param { Node } p - node to add value to -* @param { Object } obj - Object to loop through -* @returns - { Function|Node } - Either pushes the node, or reruns until -* nothing is left -*/ - -function loopThroughObjects(j, p, obj) { - Object.keys(obj).forEach( (prop) => { - if(prop.indexOf('inject') >= 0) { - return p.properties.push(createIdentifierOrLiteral(j, obj[prop])); - } - // eslint-disable-next-line no-irregular-whitespace - if(typeof(obj[prop]) !== 'object' || obj[prop] instanceof RegExp) { - p.properties.push(createObjectWithSuppliedProperty( - j, prop, createIdentifierOrLiteral(j, obj[prop]) - )); - } else if(Array.isArray(obj[prop])) { - let arrayProp = createArrayWithChildren(j, prop, obj[prop], true); - p.properties.push(arrayProp); - } else { - let objectBlock = j.objectExpression([]); - let propertyOfBlock = createObjectWithSuppliedProperty(j, prop, objectBlock); - loopThroughObjects(j, objectBlock, obj[prop]); - p.properties.push(propertyOfBlock); - } - }); -} - -/* -* @function createObjectWithSuppliedProperty -* -* Creates an object with an supplied property as parameter -* @param j — jscodeshift API -* @param { String } key - object name -* @param { Node } prop - property to be added -* @returns - { Node } - An property with the supplied property -*/ - -function createObjectWithSuppliedProperty(j, key, prop) { - return j.property('init', j.identifier(key), prop); -} - -/* -* @function createExternalRegExp -* -* Finds a regexp property with an already parsed AST from the user -* @param j — jscodeshift API -* @param { String } prop - property to find the value at -* @returns - { Node } - A literal node with the found regexp -*/ - -function createExternalRegExp(j, prop) { - let regExpProp = prop.__paths[0].value.program.body[0].expression; - return j.literal(regExpProp.value); -} - -/* -* @function pushCreateProperty -* -* Creates a property and pushes the value to a node -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { String } key - key used as identifier -* @param { String } val - property value -* @returns - { Node } - Returns node the pushed property -*/ - -function pushCreateProperty(j, p, key, val) { - let property; - if(val.hasOwnProperty('type')) { - property = val; - } else { - property = createIdentifierOrLiteral(j, val); - } - return p.value.properties.push( - createObjectWithSuppliedProperty(j, key, property) - ); -} - -/* -* @function pushObjectKeys -* -* @param j — jscodeshift API -* @param { Node } p - path to push -* @param { Object } webpackProperties - The object to loop over -* @param { String } name - Key that will be the identifier we find and add values to -* @returns - { Node/Function } Returns a function that will push a node if -*subProperty is an array, else it will invoke a function that will push a single node -*/ - -function pushObjectKeys(j, p, webpackProperties, name) { - p.value.properties.filter(n => - (safeTraverse(n, ['key', 'name']) === name) - ).forEach( (prop) => { - Object.keys(webpackProperties).forEach( (webpackProp) => { - if(webpackProp.indexOf('inject') >= 0) { - return prop.value.properties.push(createIdentifierOrLiteral(j, webpackProperties[webpackProp])); - } - else if(Array.isArray(webpackProperties[webpackProp])) { - const propArray = createArrayWithChildren( - j, webpackProp, webpackProperties[webpackProp], true - ); - return prop.value.properties.push(propArray); - } - else if(typeof(webpackProperties[webpackProp]) !== 'object' || webpackProperties[webpackProp].__paths || webpackProperties[webpackProp] instanceof RegExp) { - return pushCreateProperty( - j, prop, webpackProp, webpackProperties[webpackProp] - ); - } else { - pushCreateProperty( - j, prop, webpackProp, j.objectExpression([]) - ); - return pushObjectKeys( - j, prop, webpackProperties[webpackProp], webpackProp - ); - } - }); - }); -} - -/* -* @function isAssignment -* -* Checks if we are at the correct node and later invokes a callback -* for the transforms to either use their own transform function or -* use pushCreateProperty if the transform doesn't expect any properties -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { Function } cb - callback to be invoked -* @param { String } identifier - key to use as property -* @param { Object } property - WebpackOptions that later will be converted via -* pushCreateProperty via WebpackOptions[identifier] -* @returns - { Function } cb - Returns the callback and pushes a new node -*/ - -function isAssignment(j, p, cb, identifier, property) { - if(p.parent.value.type === 'AssignmentExpression') { - if(j) { - return cb(j, p, identifier, property); - } - else { - return cb(p); - } - } -} - -module.exports = { - safeTraverse, - createProperty, - findPluginsByName, - findPluginsRootNodes, - createOrUpdatePluginByName, - findVariableToPlugin, - isType, - createLiteral, - createIdentifierOrLiteral, - findObjWithOneOfKeys, - getRequire, - checkIfExistsAndAddValue, - createArrayWithChildren, - createEmptyArrayProperty, - createObjectWithSuppliedProperty, - createExternalRegExp, - pushCreateProperty, - pushObjectKeys, - isAssignment, - loopThroughObjects -}; diff --git a/lib/transformations/utils.test.js b/lib/transformations/utils.test.js deleted file mode 100644 index 82a3c7a87b6..00000000000 --- a/lib/transformations/utils.test.js +++ /dev/null @@ -1,315 +0,0 @@ -const j = require('jscodeshift/dist/core'); -const utils = require('./utils'); - -describe('utils', () => { - describe('createProperty', () => { - it('should create properties for Boolean', () => { - const res = utils.createProperty(j, 'foo', true); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for Number', () => { - const res = utils.createProperty(j, 'foo', -1); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for String', () => { - const res = utils.createProperty(j, 'foo', 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for complex keys', () => { - const res = utils.createProperty(j, 'foo-bar', 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - - it('should create properties for non-literal keys', () => { - const res = utils.createProperty(j, 1, 'bar'); - expect(j(j.objectExpression([res])).toSource()).toMatchSnapshot(); - }); - }); - - describe('findPluginsByName', () => { - it('should find plugins in AST', () => { - const ast = j(` -{ foo: new webpack.optimize.UglifyJsPlugin() } -`); - const res = utils.findPluginsByName(j, ast, - ['webpack.optimize.UglifyJsPlugin']); - expect(res.size()).toEqual(1); - }); - - it('should find all plugins in AST', () => { - const ast = j(` -[ - new UglifyJsPlugin(), - new TestPlugin() -] -`); - const res = utils.findPluginsByName(j, ast, - ['UglifyJsPlugin', 'TestPlugin']); - expect(res.size()).toEqual(2); - }); - - it('should not find false positives', () => { - const ast = j(` -{ foo: new UglifyJsPlugin() } -`); - const res = utils.findPluginsByName(j, ast, - ['webpack.optimize.UglifyJsPlugin']); - expect(res.size()).toEqual(0); - }); - }); - - describe('findPluginsRootNodes', () => { - it('should find plugins: [] nodes', () => { - const ast = j(` -var a = { plugins: [], foo: { plugins: [] } } -`); - const res = utils.findPluginsRootNodes(j, ast); - expect(res.size()).toEqual(2); - }); - - it('should not find plugins: [] nodes', () => { - const ast = j(` -var a = { plugs: [] } -`); - const res = utils.findPluginsRootNodes(j, ast); - expect(res.size()).toEqual(0); - }); - }); - - describe('createOrUpdatePluginByName', () => { - it('should create a new plugin without arguments', () => { - const ast = j('{ plugins: [] }'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should create a new plugin with arguments', () => { - const ast = j('{ plugins: [] }'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { foo: 'bar' }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should add an object as an argument', () => { - const ast = j('[new Plugin()]'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { foo: true }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - - it('should merge options objects', () => { - const ast = j('[new Plugin({ foo: true })]'); - ast - .find(j.ArrayExpression) - .forEach(node => { - utils.createOrUpdatePluginByName(j, node, 'Plugin', { bar: 'baz', foo: false }); - utils.createOrUpdatePluginByName(j, node, 'Plugin', { 'baz-long': true }); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - - describe('findVariableToPlugin', () => { - it('should find the variable name of a plugin', () => { - const ast = j(` - var packageName = require('package-name'); - var someOtherVar = somethingElse; - var otherPackage = require('other-package'); - `); - const foundVar = utils.findVariableToPlugin(j, ast, 'other-package'); - expect(foundVar).toEqual('otherPackage'); - }); - }); - - describe('createLiteral', () => { - it('should create basic literal', () => { - const literal = utils.createLiteral(j, 'stringLiteral'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - it('should create boolean', () => { - const literal = utils.createLiteral(j, 'true'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - - }); - - describe('createIdentifierOrLiteral', () => { - it('should create basic literal', () => { - const literal = utils.createIdentifierOrLiteral(j, '\'stringLiteral\''); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - it('should create boolean', () => { - const literal = utils.createIdentifierOrLiteral(j, 'true'); - expect(j(literal).toSource()).toMatchSnapshot(); - }); - }); - - describe('findObjWithOneOfKeys', () => { - it('should find keys', () => { - const ast = j(` - var ab = { - a: 1, - b: 2 - } - `); - expect(ast.find(j.ObjectExpression) - .filter(p => utils.findObjWithOneOfKeys(p, ['a'])).size()).toEqual(1); - }); - }); - - describe('getRequire', () => { - it('should create a require statement', () => { - const require = utils.getRequire(j, 'filesys', 'fs'); - expect(j(require).toSource()).toMatchSnapshot(); - }); - }); - - describe('checkIfExistsAndAddValue', () => { - it('should create new prop if none exist', () => { - const ast = j(` - module.exports = { - entry: 'index.js' - } - `); - ast.find(j.ObjectExpression).forEach(node => utils.checkIfExistsAndAddValue(j, node, 'externals', j.literal('React'))); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should override prop if it exists', () => { - const ast = j(` - module.exports = { - entry: 'index.js' - } - `); - ast.find(j.ObjectExpression).forEach(node => utils.checkIfExistsAndAddValue(j, node, 'entry', j.literal('app.js'))); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createArrayWithChildren', () => { - it('should find an prop that matches key and create an array with it', () => { - const ast = j('{}'); - let key = 'react'; - let reactArr = { - react: [ '\'bo\''] - }; - const arr = utils.createArrayWithChildren(j, key, reactArr, false); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should add all children of an array to a new one with a supplied key', () => { - const ast = j('{}'); - let key = 'myVeryOwnKey'; - let helloWorldArray = [ '\'hello\'', 'world']; - const arr = utils.createArrayWithChildren(j, key, helloWorldArray, true); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createEmptyArrayProperty', () => { - it('should create an array with no properties', () => { - const ast = j('{}'); - const arr = utils.createEmptyArrayProperty(j, 'its-lit'); - ast.find(j.Program).forEach(node => j(node).replaceWith(arr)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - - describe('createObjectWithSuppliedProperty', () => { - it('should create an object with a property supplied by us', () => { - const ast = j('{}'); - const prop = utils.createObjectWithSuppliedProperty(j, 'its-lit', j.objectExpression([])); - ast.find(j.Program).forEach(node => j(node).replaceWith(prop)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('createExternalRegExp', () => { - it('should create an regExp property that has been parsed by jscodeshift', () => { - const ast = j('{}'); - const reg = j('\'\t\''); - const prop = utils.createExternalRegExp(j, reg); - ast.find(j.Program).forEach(node => j(node).replaceWith(prop)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('pushCreateProperty', () => { - it('should create an object or property and push the value to a node', () => { - const ast = j(`module.exports = { - pushMe: {} - }`); - ast.find(j.Identifier).filter(n => n.value.name === 'pushMe').forEach(node => { - const heavyNodeNoSafeTraverse = node.parentPath.value; - utils.pushCreateProperty(j, heavyNodeNoSafeTraverse, 'just', 'pushed'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('pushObjectKeys', () => { - it('should push object to an node using Object.keys', () => { - const ast = j(`module.exports = { - pushMe: {} - }`); - const webpackProperties = { - hello: { - world: { - its: '\'great\'' - } - } - }; - ast.find(j.ObjectExpression).forEach(node => { - utils.pushObjectKeys(j, node, webpackProperties, 'pushMe'); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('loopThroughObjects', () => { - it('Use recursion and add elements to an node', () => { - const ast = j('module.exports = {}'); - const webpackProperties = { - hello: { - webpack: 'cli' - } - }; - ast.find(j.ObjectExpression).forEach(node => { - return utils.loopThroughObjects(j, node.value, webpackProperties); - }); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); - describe('isAssignment', () => { - it('should invoke a callback if parent type is AssignmentExpression', () => { - const ast = j('module.exports = {}'); - const myObj = 'Heyho'; - const myKey = 'context'; - - ast.find(j.ObjectExpression) - .filter(n => utils.isAssignment(j, n, utils.pushCreateProperty, myKey, myObj)); - expect(ast.toSource()).toMatchSnapshot(); - }); - it('should allow custom transform functions instead of singularProperty', () => { - const ast = j('module.exports = {}'); - - function createPluginsProperty(p) { - const webpackProperties = { - plugins: ['one', 'two', 'three'] - }; - const pluginArray = utils.createArrayWithChildren(j, 'plugins', webpackProperties); - return p.value.properties.push(pluginArray); - } - ast.find(j.ObjectExpression) - .filter(n => utils.isAssignment(null, n, createPluginsProperty)); - expect(ast.toSource()).toMatchSnapshot(); - }); - }); -}); From 847c4ac1c8fba3edc141a4a16fe055db3145c646 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:04:29 -0700 Subject: [PATCH 11/15] feat: make test run using var instead of const --- lib/creator/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/creator/index.test.js b/lib/creator/index.test.js index cbe6ad75cf4..49c31e5c889 100644 --- a/lib/creator/index.test.js +++ b/lib/creator/index.test.js @@ -1,11 +1,11 @@ 'use strict'; -const replaceGeneratorName = require('./index').replaceGeneratorName; +var replaceGeneratorName = require('./index').replaceGeneratorName; describe('replaceGeneratorName', () => { it('should replace a pattern of an addon', () => { - const generatorName = replaceGeneratorName('webpack-addons-thefox'); + var generatorName = replaceGeneratorName('webpack-addons-thefox'); expect(generatorName).toEqual('generator-thefox'); }); From 7d975504c56379798760b8be99a7d3b69d976a2b Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:11:46 -0700 Subject: [PATCH 12/15] chore: add engines prop --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7db12acfcd6..881e711872b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ }, "main": "./bin/webpack.js", "engines": { - "node": ">=4.0.0" + "node": "4.x || 5.x || 6.x || 7.x", + "npm": "2.x || 3.x || 4.x || 5.x" }, "scripts": { "lint:bin": "eslint ./bin", From 21c345d2e308d7d0038bfe676b0f531509b0782b Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:36:09 -0700 Subject: [PATCH 13/15] chore: move migrate to addons --- lib/migrate.js | 91 +-- lib/utils/WebpackOptionsValidationError.js | 189 ----- lib/utils/validateSchema.js | 67 -- lib/utils/webpackOptionsSchema.json | 905 --------------------- 4 files changed, 2 insertions(+), 1250 deletions(-) delete mode 100644 lib/utils/WebpackOptionsValidationError.js delete mode 100644 lib/utils/validateSchema.js delete mode 100644 lib/utils/webpackOptionsSchema.json diff --git a/lib/migrate.js b/lib/migrate.js index 5ca27a3a67c..9dd0ca591a2 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -1,92 +1,5 @@ -const fs = require('fs'); -const chalk = require('chalk'); -const diff = require('diff'); -const inquirer = require('inquirer'); -const PLazy = require('p-lazy'); -const Listr = require('listr'); -const validateSchema = require('./utils/validateSchema.js'); -const webpackOptionsSchema = require('./utils/webpackOptionsSchema.json'); -const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationError'); +const migrate = require('webpack-addons').migrate; module.exports = function transformFile(currentConfigPath, outputConfigPath, options) { - const recastOptions = Object.assign({ - quote: 'single' - }, options); - const tasks = new Listr([ - { - title: 'Reading webpack config', - task: (ctx) => new PLazy((resolve, reject) => { - fs.readFile(currentConfigPath, 'utf8', (err, content) => { - if (err) { - reject(err); - } - try { - const jscodeshift = require('jscodeshift'); - ctx.source = content; - ctx.ast = jscodeshift(content); - resolve(); - } catch (err) { - reject('Error generating AST', err); - } - }); - }) - }, - { - title: 'Migrating config from v1 to v2', - task: (ctx) => { - const transformations = require('webpack-addons').migrate; - return new Listr(Object.keys(transformations).map(key => { - const transform = transformations[key]; - return { - title: key, - task: () => transform(ctx.ast, ctx.source) - }; - })); - } - } - ]); - - tasks.run() - .then((ctx) => { - const result = ctx.ast.toSource(recastOptions); - const diffOutput = diff.diffLines(ctx.source, result); - diffOutput.forEach(diffLine => { - if (diffLine.added) { - process.stdout.write(chalk.green(`+ ${diffLine.value}`)); - } else if (diffLine.removed) { - process.stdout.write(chalk.red(`- ${diffLine.value}`)); - } - }); - inquirer - .prompt([ - { - type: 'confirm', - name: 'confirmMigration', - message: 'Are you sure these changes are fine?', - default: 'Y' - } - ]) - .then(answers => { - if (answers['confirmMigration']) { - fs.writeFile(outputConfigPath, result, 'utf8', (err) => { - const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, require(outputConfigPath)); - if (err) { - throw err; - } - else if (webpackOptionsValidationErrors.length) { - throw new WebpackOptionsValidationError(webpackOptionsValidationErrors); - } else { - console.log(chalk.green(`\n ✔︎ New webpack v2 config file is at ${outputConfigPath}`)); - } - }); - } else { - console.log(chalk.red('✖ Migration aborted')); - } - }); - }) - .catch(err => { - console.log(chalk.red('✖ ︎Migration aborted due to some errors')); - console.error(err); - process.exitCode = 1; - }); + return migrate(currentConfigPath, outputConfigPath, options); }; diff --git a/lib/utils/WebpackOptionsValidationError.js b/lib/utils/WebpackOptionsValidationError.js deleted file mode 100644 index 4fb7693faf3..00000000000 --- a/lib/utils/WebpackOptionsValidationError.js +++ /dev/null @@ -1,189 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Gajus Kuizinas @gajus -*/ -'use strict'; - -const webpackOptionsSchema = require('./webpackOptionsSchema.json'); - -const getSchemaPart = (path, parents, additionalPath) => { - parents = parents || 0; - path = path.split('/'); - path = path.slice(0, path.length - parents); - if(additionalPath) { - additionalPath = additionalPath.split('/'); - path = path.concat(additionalPath); - } - let schemaPart = webpackOptionsSchema; - for(let i = 1; i < path.length; i++) { - const inner = schemaPart[path[i]]; - if(inner) - schemaPart = inner; - } - return schemaPart; -}; - -const getSchemaPartText = (schemaPart, additionalPath) => { - if(additionalPath) { - for(let i = 0; i < additionalPath.length; i++) { - const inner = schemaPart[additionalPath[i]]; - if(inner) - schemaPart = inner; - } - } - while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref); - let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart); - if(schemaPart.description) - schemaText += `\n${schemaPart.description}`; - return schemaText; -}; - -const indent = (str, prefix, firstLine) => { - if(firstLine) { - return prefix + str.replace(/\n(?!$)/g, '\n' + prefix); - } else { - return str.replace(/\n(?!$)/g, `\n${prefix}`); - } -}; - -class WebpackOptionsValidationError extends Error { - constructor(validationErrors) { - super(); - if(Error.hasOwnProperty('captureStackTrace')) { - Error.captureStackTrace(this, this.constructor); - } - this.name = 'WebpackOptionsValidationError'; - - this.message = 'Invalid configuration object. ' + - 'Webpack has been initialised using a configuration object that does not match the API schema.\n' + - validationErrors.map(err => ' - ' + indent(WebpackOptionsValidationError.formatValidationError(err), ' ', false)).join('\n'); - this.validationErrors = validationErrors; - } - - static formatSchema(schema, prevSchemas) { - prevSchemas = prevSchemas || []; - - const formatInnerSchema = (innerSchema, addSelf) => { - if(!addSelf) return WebpackOptionsValidationError.formatSchema(innerSchema, prevSchemas); - if(prevSchemas.indexOf(innerSchema) >= 0) return '(recursive)'; - return WebpackOptionsValidationError.formatSchema(innerSchema, prevSchemas.concat(schema)); - }; - - if(schema.type === 'string') { - if(schema.minLength === 1) - return 'non-empty string'; - else if(schema.minLength > 1) - return `string (min length ${schema.minLength})`; - return 'string'; - } else if(schema.type === 'boolean') { - return 'boolean'; - } else if(schema.type === 'number') { - return 'number'; - } else if(schema.type === 'object') { - if(schema.properties) { - const required = schema.required || []; - return `object { ${Object.keys(schema.properties).map(property => { - if(required.indexOf(property) < 0) return property + '?'; - return property; - }).concat(schema.additionalProperties ? ['...'] : []).join(', ')} }`; - } - if(schema.additionalProperties) { - return `object { : ${formatInnerSchema(schema.additionalProperties)} }`; - } - return 'object'; - } else if(schema.type === 'array') { - return `[${formatInnerSchema(schema.items)}]`; - } - - switch(schema.instanceof) { - case 'Function': - return 'function'; - case 'RegExp': - return 'RegExp'; - } - if(schema.$ref) return formatInnerSchema(getSchemaPart(schema.$ref), true); - if(schema.allOf) return schema.allOf.map(formatInnerSchema).join(' & '); - if(schema.oneOf) return schema.oneOf.map(formatInnerSchema).join(' | '); - if(schema.anyOf) return schema.anyOf.map(formatInnerSchema).join(' | '); - if(schema.enum) return schema.enum.map(item => JSON.stringify(item)).join(' | '); - return JSON.stringify(schema, 0, 2); - } - - static formatValidationError(err) { - const dataPath = `configuration${err.dataPath}`; - if(err.keyword === 'additionalProperties') { - const baseMessage = `${dataPath} has an unknown property '${err.params.additionalProperty}'. These properties are valid:\n${getSchemaPartText(err.parentSchema)}`; - if(!err.dataPath) { - switch(err.params.additionalProperty) { - case 'debug': - return `${baseMessage}\n` + - 'The \'debug\' property was removed in webpack 2.\n' + - 'Loaders should be updated to allow passing this option via loader options in module.rules.\n' + - 'Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:\n' + - 'plugins: [\n' + - ' new webpack.LoaderOptionsPlugin({\n' + - ' debug: true\n' + - ' })\n' + - ']'; - } - return baseMessage + '\n' + - 'For typos: please correct them.\n' + - 'For loader options: webpack 2 no longer allows custom properties in configuration.\n' + - ' Loaders should be updated to allow passing options via loader options in module.rules.\n' + - ' Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n' + - ' plugins: [\n' + - ' new webpack.LoaderOptionsPlugin({\n' + - ' // test: /\\.xxx$/, // may apply this only for some modules\n' + - ' options: {\n' + - ` ${err.params.additionalProperty}: ...\n` + - ' }\n' + - ' })\n' + - ' ]'; - } - return baseMessage; - } else if(err.keyword === 'oneOf' || err.keyword === 'anyOf') { - if(err.children && err.children.length > 0) { - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` + - `Details:\n${err.children.map(err => ' * ' + indent(WebpackOptionsValidationError.formatValidationError(err), ' ', false)).join('\n')}`; - } - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; - - } else if(err.keyword === 'enum') { - if(err.parentSchema && err.parentSchema.enum && err.parentSchema.enum.length === 1) { - return `${dataPath} should be ${getSchemaPartText(err.parentSchema)}`; - } - return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'allOf') { - return `${dataPath} should be:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'type') { - switch(err.params.type) { - case 'object': - return `${dataPath} should be an object.`; - case 'string': - return `${dataPath} should be a string.`; - case 'boolean': - return `${dataPath} should be a boolean.`; - case 'number': - return `${dataPath} should be a number.`; - case 'array': - return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`; - } - return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`; - } else if(err.keyword === 'instanceof') { - return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`; - } else if(err.keyword === 'required') { - const missingProperty = err.params.missingProperty.replace(/^\./, ''); - return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ['properties', missingProperty])}`; - } else if(err.keyword === 'minLength' || err.keyword === 'minItems') { - if(err.params.limit === 1) - return `${dataPath} should not be empty.`; - else - return `${dataPath} ${err.message}`; - } else { - // eslint-disable-line no-fallthrough - return `${dataPath} ${err.message} (${JSON.stringify(err, 0, 2)}).\n${getSchemaPartText(err.parentSchema)}`; - } - } -} - -module.exports = WebpackOptionsValidationError; diff --git a/lib/utils/validateSchema.js b/lib/utils/validateSchema.js deleted file mode 100644 index c6360de2367..00000000000 --- a/lib/utils/validateSchema.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Gajus Kuizinas @gajus -*/ -'use strict'; - -/* eslint-disable */ -const Ajv = require('ajv'); -const ajv = new Ajv({ - errorDataPath: 'configuration', - allErrors: true, - verbose: true -}); -require('ajv-keywords')(ajv, ['instanceof']); -/* eslint-enable */ - -function validateSchema(schema, options) { - if(Array.isArray(options)) { - const errors = options.map((options) => validateObject(schema, options)); - errors.forEach((list, idx) => { - list.forEach(function applyPrefix(err) { - err.dataPath = `[${idx}]${err.dataPath}`; - if(err.children) { - err.children.forEach(applyPrefix); - } - }); - }); - return errors.reduce((arr, items) => { - return arr.concat(items); - }, []); - } else { - return validateObject(schema, options); - } -} - -function validateObject(schema, options) { - const validate = ajv.compile(schema); - const valid = validate(options); - return valid ? [] : filterErrors(validate.errors); -} - -function filterErrors(errors) { - let newErrors = []; - errors.forEach((err) => { - const dataPath = err.dataPath; - let children = []; - newErrors = newErrors.filter((oldError) => { - if(oldError.dataPath.includes(dataPath)) { - if(oldError.children) { - children = children.concat(oldError.children.slice(0)); - } - oldError.children = undefined; - children.push(oldError); - return false; - } - return true; - }); - if(children.length) { - err.children = children; - } - newErrors.push(err); - }); - - return newErrors; -} - -module.exports = validateSchema; diff --git a/lib/utils/webpackOptionsSchema.json b/lib/utils/webpackOptionsSchema.json deleted file mode 100644 index 0d8a9741eb4..00000000000 --- a/lib/utils/webpackOptionsSchema.json +++ /dev/null @@ -1,905 +0,0 @@ -{ - "additionalProperties": false, - "definitions": { - "common.arrayOfStringOrStringArrayValues": { - "items": { - "anyOf": [ - { - "minLength": 1, - "type": "string" - }, - { - "items": { - "minLength": 1, - "type": "string" - }, - "type": "array" - } - ] - }, - "type": "array" - }, - "common.arrayOfStringValues": { - "items": { - "minLength": 1, - "type": "string" - }, - "type": "array" - }, - "common.nonEmptyArrayOfUniqueStringValues": { - "items": { - "minLength": 1, - "type": "string" - }, - "minItems": 1, - "type": "array", - "uniqueItems": true - }, - "entry": { - "description": "The entry point(s) of the compilation.", - "oneOf": [ - { - "minProperties": 1, - "additionalProperties": { - "oneOf": [ - { - "description": "The string is resolved to a module which is loaded upon startup.", - "minLength": 1, - "type": "string" - }, - { - "description": "All modules are loaded upon startup. The last one is exported.", - "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues" - } - ] - }, - "description": "Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.", - "type": "object" - }, - { - "description": "The string is resolved to a module which is loaded upon startup.", - "minLength": 1, - "type": "string" - }, - { - "allOf": [ - { - "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues" - } - ], - "description": "All modules are loaded upon startup. The last one is exported." - }, - { - "description": "function returning an entry object or a promise.", - "instanceof": "Function" - } - ] - }, - "externals": { - "anyOf": [ - { - "description": "An exact matched dependency becomes external. The same string is used as external dependency.", - "type": "string" - }, - { - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object" - }, - { - "type": "boolean" - } - ] - }, - "description": "If an dependency matches exactly a property of the object, the property value is used as dependency.", - "type": "object" - }, - { - "description": "`function(context, request, callback(err, result))` The function is called on each dependency.", - "instanceof": "Function" - }, - { - "description": "Every matched dependency becomes external.", - "instanceof": "RegExp" - }, - { - "items": { - "$ref": "#/definitions/externals" - }, - "type": "array" - } - ], - "description": "Specify dependencies that shouldn't be resolved by webpack, but should become dependencies of the resulting bundle. The kind of the dependency depends on `output.libraryTarget`." - }, - "module": { - "additionalProperties": false, - "description": "Options affecting the normal modules (`NormalModuleFactory`).", - "properties": { - "exprContextCritical": { - "type": "boolean" - }, - "exprContextRecursive": { - "type": "boolean" - }, - "exprContextRegExp": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "RegExp" - } - ] - }, - "exprContextRequest": { - "type": "string" - }, - "loaders": { - "allOf": [ - { - "$ref": "#/definitions/ruleSet-rules" - } - ], - "description": "An array of automatically applied loaders." - }, - "noParse": { - "description": "Don't parse files matching. It's matched against the full resolved request.", - "anyOf": [ - { - "items": { - "instanceof": "RegExp" - }, - "minItems": 1, - "type": "array" - }, - { - "instanceof": "RegExp" - } - ] - }, - "rules": { - "allOf": [ - { - "$ref": "#/definitions/ruleSet-rules" - } - ], - "description": "An array of rules applied for modules." - }, - "unknownContextCritical": { - "type": "boolean" - }, - "unknownContextRecursive": { - "type": "boolean" - }, - "unknownContextRegExp": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "RegExp" - } - ] - }, - "unknownContextRequest": { - "type": "string" - }, - "unsafeCache": { - "anyOf": [ - { - "type": "boolean" - }, - { - "instanceof": "Function" - } - ] - }, - "wrappedContextCritical": { - "type": "boolean" - }, - "wrappedContextRecursive": { - "type": "boolean" - }, - "wrappedContextRegExp": { - "instanceof": "RegExp" - } - }, - "type": "object" - }, - "output": { - "additionalProperties": false, - "description": "Options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.", - "properties": { - "auxiliaryComment": { - "description": "Add a comment in the UMD wrapper.", - "anyOf": [ - { - "description": "Append the same comment above each import style.", - "type": "string" - }, - { - "additionalProperties": false, - "description": "Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.", - "properties": { - "amd": { - "type": "string" - }, - "commonjs": { - "type": "string" - }, - "commonjs2": { - "type": "string" - }, - "root": { - "type": "string" - } - }, - "type": "object" - } - ] - }, - "chunkFilename": { - "description": "The filename of non-entry chunks as relative path inside the `output.path` directory.", - "type": "string" - }, - "crossOriginLoading": { - "description": "This option enables cross-origin loading of chunks.", - "enum": [ - false, - "anonymous", - "use-credentials" - ] - }, - "devtoolFallbackModuleFilenameTemplate": { - "description": "Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.", - "anyOf": [ - { - "type": "string" - }, - { - "instanceof": "Function" - } - ] - }, - "devtoolLineToLine": { - "description": "Enable line to line mapped mode for all/specified modules. Line to line mapped mode uses a simple SourceMap where each line of the generated source is mapped to the same line of the original source. It’s a performance optimization. Only use it if your performance need to be better and you are sure that input lines match which generated lines.", - "anyOf": [ - { - "description": "`true` enables it for all modules (not recommended)", - "type": "boolean" - }, - { - "description": "An object similar to `module.loaders` enables it for specific files.", - "properties": { - "exclude": { - "type": "string" - }, - "include": { - "type": "string" - }, - "test": { - "type": "string" - } - }, - "type": "object" - } - ] - }, - "devtoolModuleFilenameTemplate": { - "description": "Filename template string of function for the sources array in a generated SourceMap.", - "anyOf": [ - { - "type": "string" - }, - { - "instanceof": "Function" - } - ] - }, - "filename": { - "description": "Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.", - "type": "string" - }, - "hashDigest": { - "minLength": 1, - "type": "string" - }, - "hashDigestLength": { - "minimum": 1, - "type": "number" - }, - "hashFunction": { - "minLength": 1, - "type": "string" - }, - "hotUpdateChunkFilename": { - "description": "The filename of the Hot Update Chunks. They are inside the output.path directory.", - "type": "string" - }, - "hotUpdateFunction": { - "description": "The JSONP function used by webpack for async loading of hot update chunks.", - "type": "string" - }, - "hotUpdateMainFilename": { - "description": "The filename of the Hot Update Main File. It is inside the `output.path` directory.", - "type": "string" - }, - "jsonpFunction": { - "description": "The JSONP function used by webpack for async loading of chunks.", - "type": "string" - }, - "library": { - "anyOf": [ - { - "type": "string" - }, - { - "items": { - "type": "string" - }, - "type": "array" - } - ], - "description": "If set, export the bundle as library. `output.library` is the name." - }, - "libraryTarget": { - "enum": [ - "var", - "assign", - "this", - "window", - "global", - "commonjs", - "commonjs2", - "commonjs-module", - "amd", - "umd", - "umd2", - "jsonp" - ] - }, - "path": { - "description": "The output directory as **absolute path** (required).", - "type": "string" - }, - "pathinfo": { - "description": "Include comments with information about the modules.", - "type": "boolean" - }, - "publicPath": { - "description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.", - "type": "string" - }, - "sourceMapFilename": { - "description": "The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.", - "type": "string" - }, - "sourcePrefix": { - "description": "Prefixes every line of the source in the bundle with this string.", - "type": "string" - }, - "strictModuleExceptionHandling": { - "description": "Handles exceptions in module loading correctly at a performance cost.", - "type": "boolean" - }, - "umdNamedDefine": { - "description": "If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.", - "type": "boolean" - } - }, - "type": "object" - }, - "resolve": { - "additionalProperties": false, - "properties": { - "alias": { - "anyOf": [ - { - "additionalProperties": { - "type": "string" - }, - "type": "object" - }, - { - "items": { - "additionalProperties": false, - "properties": { - "alias": { - "type": "string" - }, - "name": { - "type": "string" - }, - "onlyModule": { - "type": "boolean" - } - }, - "type": "object" - }, - "type": "array" - } - ] - }, - "aliasFields": { - "$ref": "#/definitions/common.arrayOfStringOrStringArrayValues" - }, - "cachePredicate": { - "instanceof": "Function" - }, - "descriptionFiles": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "enforceExtension": { - "type": "boolean" - }, - "enforceModuleExtension": { - "type": "boolean" - }, - "extensions": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "fileSystem": {}, - "mainFields": { - "$ref": "#/definitions/common.arrayOfStringOrStringArrayValues" - }, - "mainFiles": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "moduleExtensions": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "modules": { - "$ref": "#/definitions/common.arrayOfStringValues" - }, - "plugins": { - "type": "array" - }, - "resolver": {}, - "symlinks": { - "type": "boolean" - }, - "unsafeCache": { - "anyOf": [ - { - "type": "boolean" - }, - { - "additionalProperties": true, - "type": "object" - } - ] - }, - "useSyncFileSystemCalls": { - "type": "boolean" - } - }, - "type": "object" - }, - "ruleSet-condition": { - "anyOf": [ - { - "instanceof": "RegExp" - }, - { - "minLength": 1, - "type": "string" - }, - { - "instanceof": "Function" - }, - { - "$ref": "#/definitions/ruleSet-conditions" - }, - { - "additionalProperties": false, - "properties": { - "and": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "exclude": { - "$ref": "#/definitions/ruleSet-condition" - }, - "include": { - "$ref": "#/definitions/ruleSet-condition" - }, - "not": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "or": { - "$ref": "#/definitions/ruleSet-conditions" - }, - "test": { - "$ref": "#/definitions/ruleSet-condition" - } - }, - "type": "object" - } - ] - }, - "ruleSet-conditions": { - "items": { - "$ref": "#/definitions/ruleSet-condition" - }, - "type": "array" - }, - "ruleSet-loader": { - "minLength": 1, - "type": "string" - }, - "ruleSet-query": { - "anyOf": [ - { - "type": "object" - }, - { - "type": "string" - } - ] - }, - "ruleSet-rule": { - "additionalProperties": false, - "properties": { - "enforce": { - "enum": [ - "pre", - "post" - ] - }, - "exclude": { - "$ref": "#/definitions/ruleSet-condition" - }, - "include": { - "$ref": "#/definitions/ruleSet-condition" - }, - "issuer": { - "$ref": "#/definitions/ruleSet-condition" - }, - "loader": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-loader" - }, - { - "$ref": "#/definitions/ruleSet-use" - } - ] - }, - "loaders": { - "$ref": "#/definitions/ruleSet-use" - }, - "oneOf": { - "$ref": "#/definitions/ruleSet-rules" - }, - "options": { - "$ref": "#/definitions/ruleSet-query" - }, - "parser": { - "additionalProperties": true, - "type": "object" - }, - "query": { - "$ref": "#/definitions/ruleSet-query" - }, - "resource": { - "$ref": "#/definitions/ruleSet-condition" - }, - "resourceQuery": { - "$ref": "#/definitions/ruleSet-condition" - }, - "rules": { - "$ref": "#/definitions/ruleSet-rules" - }, - "test": { - "$ref": "#/definitions/ruleSet-condition" - }, - "use": { - "$ref": "#/definitions/ruleSet-use" - } - }, - "type": "object" - }, - "ruleSet-rules": { - "items": { - "$ref": "#/definitions/ruleSet-rule" - }, - "type": "array" - }, - "ruleSet-use": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-use-item" - }, - { - "instanceof": "Function" - }, - { - "items": { - "$ref": "#/definitions/ruleSet-use-item" - }, - "type": "array" - } - ] - }, - "ruleSet-use-item": { - "anyOf": [ - { - "$ref": "#/definitions/ruleSet-loader" - }, - { - "instanceof": "Function" - }, - { - "additionalProperties": false, - "properties": { - "loader": { - "$ref": "#/definitions/ruleSet-loader" - }, - "options": { - "$ref": "#/definitions/ruleSet-query" - }, - "query": { - "$ref": "#/definitions/ruleSet-query" - } - }, - "type": "object" - } - ] - } - }, - "properties": { - "amd": { - "description": "Set the value of `require.amd` and `define.amd`." - }, - "bail": { - "description": "Report the first error as a hard error instead of tolerating it.", - "type": "boolean" - }, - "cache": { - "description": "Cache generated modules and chunks to improve performance for multiple incremental builds.", - "anyOf": [ - { - "description": "You can pass `false` to disable it.", - "type": "boolean" - }, - { - "description": "You can pass an object to enable it and let webpack use the passed object as cache. This way you can share the cache object between multiple compiler calls.", - "type": "object" - } - ] - }, - "context": { - "description": "The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.", - "type": "string" - }, - "dependencies": { - "description": "References to other configurations to depend on.", - "items": { - "type": "string" - }, - "type": "array" - }, - "devServer": { - "type": "object" - }, - "devtool": { - "description": "A developer tool to enhance debugging.", - "anyOf": [ - { - "type": "string" - }, - { - "enum": [ - false - ] - } - ] - }, - "entry": { - "$ref": "#/definitions/entry" - }, - "externals": { - "$ref": "#/definitions/externals" - }, - "loader": { - "description": "Custom values available in the loader context.", - "type": "object" - }, - "module": { - "$ref": "#/definitions/module" - }, - "name": { - "description": "Name of the configuration. Used when loading multiple configurations.", - "type": "string" - }, - "node": { - "description": "Include polyfills or mocks for various node stuff.", - "additionalProperties": { - "enum": [ - false, - true, - "mock", - "empty" - ] - }, - "properties": { - "Buffer": { - "enum": [ - false, - true, - "mock" - ] - }, - "__dirname": { - "enum": [ - false, - true, - "mock" - ] - }, - "__filename": { - "enum": [ - false, - true, - "mock" - ] - }, - "console": { - "enum": [ - false, - true, - "mock" - ] - }, - "global": { - "type": "boolean" - }, - "process": { - "enum": [ - false, - true, - "mock" - ] - } - }, - "type": "object" - }, - "output": { - "$ref": "#/definitions/output" - }, - "performance": { - "description": "Configuration for web performance recommendations.", - "anyOf": [ - { - "enum": [ - false - ] - }, - { - "additionalProperties": false, - "properties": { - "assetFilter": { - "description": "Filter function to select assets that are checked", - "instanceof": "Function" - }, - "hints": { - "description": "Sets the format of the hints: warnings, errors or nothing at all", - "enum": [ - false, - "warning", - "error" - ] - }, - "maxEntrypointSize": { - "description": "Total size of an entry point (in bytes)", - "type": "number" - }, - "maxAssetSize": { - "description": "Filesize limit (in bytes) when exceeded, that webpack will provide performance hints", - "type": "number" - } - }, - "type": "object" - } - ] - }, - "plugins": { - "description": "Add additional plugins to the compiler.", - "type": "array" - }, - "profile": { - "description": "Capture timing information for each module.", - "type": "boolean" - }, - "recordsInputPath": { - "description": "Store compiler state to a json file.", - "type": "string" - }, - "recordsOutputPath": { - "description": "Load compiler state from a json file.", - "type": "string" - }, - "recordsPath": { - "description": "Store/Load compiler state from/to a json file. This will result in persistent ids of modules and chunks. An absolute path is expected. `recordsPath` is used for `recordsInputPath` and `recordsOutputPath` if they left undefined.", - "type": "string" - }, - "resolve": { - "$ref": "#/definitions/resolve" - }, - "resolveLoader": { - "$ref": "#/definitions/resolve" - }, - "stats": { - "description": "Used by the webpack CLI program to pass stats options.", - "anyOf": [ - { - "type": "object" - }, - { - "type": "boolean" - }, - { - "enum": [ - "none", - "errors-only", - "minimal", - "normal", - "verbose" - ] - } - ] - }, - "target": { - "anyOf": [ - { - "enum": [ - "web", - "webworker", - "node", - "async-node", - "node-webkit", - "atom", - "electron", - "electron-main", - "electron-renderer" - ] - }, - { - "instanceof": "Function" - } - ] - }, - "watch": { - "description": "Enter watch mode, which rebuilds on file change.", - "type": "boolean" - }, - "watchOptions": { - "properties": { - "aggregateTimeout": { - "description": "Delay the rebuilt after the first change. Value is a time in ms.", - "type": "number" - }, - "poll": { - "anyOf": [ - { - "description": "`true`: use polling.", - "type": "boolean" - }, - { - "description": "`number`: use polling with specified interval.", - "type": "number" - } - ] - } - }, - "type": "object" - } - }, - "required": [ - "entry" - ], - "type": "object" -} \ No newline at end of file From 622d951fe25b2997601b3ced0dac86e12deaf1cf Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 10:47:02 -0700 Subject: [PATCH 14/15] fix: use correct naming conventions --- lib/migrate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/migrate.js b/lib/migrate.js index 9dd0ca591a2..226fb0c45ea 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -1,4 +1,4 @@ -const migrate = require('webpack-addons').migrate; +const migrate = require('webpack-addons').migrateTransform; module.exports = function transformFile(currentConfigPath, outputConfigPath, options) { return migrate(currentConfigPath, outputConfigPath, options); From 1870f35379a1a166b79ffe0fb939cdfc0ce066f5 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 16 May 2017 11:57:15 -0700 Subject: [PATCH 15/15] feat: add default generator logic & remove old deps --- lib/creator/index.js | 19 +++++++++++++++++-- package.json | 6 +----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/creator/index.js b/lib/creator/index.js index 266995e8088..fbae21cfca6 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -1,9 +1,10 @@ const yeoman = require('yeoman-environment'); const Generator = require('yeoman-generator'); +const chalk = require('chalk'); const path = require('path'); const defaultGenerator = require('webpack-addons').WebpackGenerator; +const runTransform = require('webpack-addons').initTransform; const WebpackAdapter = require('./utils/webpack-adapter'); - /* * @function creator * @@ -30,7 +31,21 @@ function creator(options) { env.registerStub(defaultGenerator, 'webpack-default-generator'); } - return env.run(generatorName); + return env.run(generatorName).on('end', () => { + if(generatorName === 'webpack-default-generator') { + return runTransform(env.configuration).then( (didFinish) => { + if(didFinish) { + process.stdout.write('\n' + chalk.green( + 'Congratulations! Your new webpack configuration file has been created!\n' + )); + } else { + process.stdout.write('\n' + chalk.red( + 'Sorry! Your webpack configuration did not fully succeed !\n' + )); + } + }); + } + }); } /* diff --git a/package.json b/package.json index 881e711872b..e5516312349 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "babel-preset-stage-3": "^6.17.0", "chalk": "^1.1.3", "cross-spawn": "^5.0.1", - "diff": "^3.2.0", "enhanced-resolve": "^3.0.2", "fit-commit-js": "^0.3.1", "global-modules": "^0.2.3", @@ -46,18 +45,15 @@ "p-each-series": "^1.0.0", "p-lazy": "^1.0.0", "prettier": "^1.2.2", - "recast": "git://github.com/kalcifer/recast.git#bug/allowbreak", "resolve-cwd": "^2.0.0", "supports-color": "^3.1.2", "webpack": "^2.5.1", "webpack-addons": "git://github.com/webpack-contrib/webpack-addons.git#yeoman-migration", "yargs": "^6.5.0", "yeoman-environment": "^1.6.6", - "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" + "yeoman-generator": "^1.1.1" }, "devDependencies": { - "ajv": "^4.11.3", - "ajv-keywords": "^1.5.1", "babel-cli": "^6.18.0", "babel-eslint": "^6.1.2", "babel-jest": "^19.0.0",