From eb3909b06074b351e7a38e3eddec0d699bcf18da Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Thu, 30 May 2019 19:08:21 +0200 Subject: [PATCH] fix: formatting files --- bin/cli.js | 9 +- package-lock.json | 73 ++++++--- package.json | 11 +- .../__tests__/add-generator.test.ts | 3 +- packages/generators/add-generator.ts | 8 +- packages/generators/addon-generator.ts | 3 +- packages/generators/index.ts | 2 +- packages/generators/init-generator.ts | 153 +++++++----------- packages/generators/loader-generator.ts | 8 +- packages/generators/plugin-generator.ts | 8 +- packages/generators/templates/package.json.js | 5 +- packages/generators/utils/entry.ts | 75 ++++----- packages/generators/utils/languageSupport.ts | 66 ++++---- packages/generators/utils/plugins.ts | 19 +-- packages/generators/utils/styleSupport.ts | 128 ++++++--------- packages/generators/utils/webpackConfig.ts | 56 ++++--- packages/migrate/__tests__/migrate.test.ts | 46 +++--- .../__tests__/commonsChunkPlugin.test.ts | 24 +-- .../extractTextPlugin/extractTextPlugin.ts | 3 +- .../__tests__/loaderOptionsPlugin.test.ts | 24 +-- packages/migrate/loaders/loaders.ts | 22 ++- .../moduleConcatenationPlugin.test.ts | 18 +-- .../__tests__/noEmitOnErrorsPlugin.test.ts | 18 +-- packages/migrate/outputPath/outputPath.ts | 114 ++++++------- .../__tests__/removeDeprecatedPlugins.test.ts | 30 +--- .../__tests__/removeJsonLoader.test.ts | 24 +-- packages/migrate/resolve/resolve.ts | 7 +- packages/migrate/types/NodePath.ts | 6 +- .../migrate/uglifyJsPlugin/uglifyJsPlugin.ts | 6 +- packages/utils/__tests__/npm-exists.test.ts | 4 +- .../__tests__/npm-packages-exists.test.ts | 2 +- .../utils/__tests__/package-manager.test.ts | 10 +- .../utils/__tests__/recursive-parser.test.ts | 28 ++-- packages/utils/ast-utils.ts | 2 +- packages/utils/modify-config-helper.ts | 6 +- packages/utils/prop-types.ts | 2 +- packages/utils/run-prettier.ts | 6 +- packages/utils/scaffold.ts | 50 +++--- packages/utils/types/NodePath.ts | 6 +- .../webpack-scaffold/__tests__/index.test.ts | 34 ++-- packages/webpack-scaffold/index.ts | 10 +- 41 files changed, 476 insertions(+), 653 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index aea8f6fd3e4..03faa127ee2 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -326,19 +326,14 @@ For more information, see https://webpack.js.org/api/cli/.`); const SIX_DAYS = 518400000; const now = new Date(); if (now.getDay() === MONDAY) { - const { - access, - constants, - statSync, - utimesSync, - } = require("fs"); + const { access, constants, statSync, utimesSync } = require("fs"); const lastPrint = statSync(openCollectivePath).atime; const lastPrintTS = new Date(lastPrint).getTime(); const timeSinceLastPrint = now.getTime() - lastPrintTS; if (timeSinceLastPrint > SIX_DAYS) { require(openCollectivePath); // On windows we need to manually update the atime - access(openCollectivePath, constants.W_OK, (e) => { + access(openCollectivePath, constants.W_OK, e => { if (!e) utimesSync(openCollectivePath, now, now); }); } diff --git a/package-lock.json b/package-lock.json index 4e17dad8491..6677cfe9e17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2686,40 +2686,69 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.7.0.tgz", - "integrity": "sha512-NUSz1aTlIzzTjFFVFyzrbo8oFjHg3K/M9MzYByqbMCxeFdErhLAcGITVfXzSz+Yvp5OOpMu3HkIttB0NyKl54Q==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.9.0.tgz", + "integrity": "sha512-FOgfBorxjlBGpDIw+0LaZIXRX6GEEUfzj8LXwaQIUCp+gDOvkI+1WgugJ7SmWiISqK9Vj5r8S7NDKO/LB+6X9A==", "dev": true, "requires": { - "@typescript-eslint/parser": "1.7.0", - "@typescript-eslint/typescript-estree": "1.7.0", + "@typescript-eslint/experimental-utils": "1.9.0", + "@typescript-eslint/parser": "1.9.0", "eslint-utils": "^1.3.1", + "functional-red-black-tree": "^1.0.1", "regexpp": "^2.0.1", "requireindex": "^1.2.0", "tsutils": "^3.7.0" } }, - "@typescript-eslint/parser": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.7.0.tgz", - "integrity": "sha512-1QFKxs2V940372srm12ovSE683afqc1jB6zF/f8iKhgLz1yoSjYeGHipasao33VXKI+0a/ob9okeogGdKGvvlg==", + "@typescript-eslint/experimental-utils": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.0.tgz", + "integrity": "sha512-1s2dY9XxBwtS9IlSnRIlzqILPyeMly5tz1bfAmQ84Ul687xBBve5YsH5A5EKeIcGurYYqY2w6RkHETXIwnwV0A==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "1.7.0", - "eslint-scope": "^4.0.0", - "eslint-visitor-keys": "^1.0.0" + "@typescript-eslint/typescript-estree": "1.9.0" + }, + "dependencies": { + "@typescript-eslint/typescript-estree": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.0.tgz", + "integrity": "sha512-7Eg0TEQpCkTsEwsl1lIzd6i7L3pJLQFWesV08dS87bNz0NeSjbL78gNAP1xCKaCejkds4PhpLnZkaAjx9SU8OA==", + "dev": true, + "requires": { + "lodash.unescape": "4.0.1", + "semver": "5.5.0" + } + }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", + "dev": true + } } }, - "@typescript-eslint/typescript-estree": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.7.0.tgz", - "integrity": "sha512-K5uedUxVmlYrVkFbyV3htDipvLqTE3QMOUQEHYJaKtgzxj6r7c5Ca/DG1tGgFxX+fsbi9nDIrf4arq7Ib7H/Yw==", + "@typescript-eslint/parser": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.9.0.tgz", + "integrity": "sha512-CWgC1XrQ34H/+LwAU7vY5xteZDkNqeAkeidEpJnJgkKu0yqQ3ZhQ7S+dI6MX4vmmM1TKRbOrKuXc6W0fIHhdbA==", "dev": true, "requires": { - "lodash.unescape": "4.0.1", - "semver": "5.5.0" + "@typescript-eslint/experimental-utils": "1.9.0", + "@typescript-eslint/typescript-estree": "1.9.0", + "eslint-scope": "^4.0.0", + "eslint-visitor-keys": "^1.0.0" }, "dependencies": { + "@typescript-eslint/typescript-estree": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.0.tgz", + "integrity": "sha512-7Eg0TEQpCkTsEwsl1lIzd6i7L3pJLQFWesV08dS87bNz0NeSjbL78gNAP1xCKaCejkds4PhpLnZkaAjx9SU8OA==", + "dev": true, + "requires": { + "lodash.unescape": "4.0.1", + "semver": "5.5.0" + } + }, "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", @@ -12418,7 +12447,7 @@ }, "resolve-from": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "resolved": false, "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, @@ -16502,9 +16531,9 @@ "dev": true }, "tsutils": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.10.0.tgz", - "integrity": "sha512-q20XSMq7jutbGB8luhKKsQldRKWvyBO2BGqni3p4yq8Ys9bEP/xQw3KepKmMRt9gJ4lvQSScrihJrcKdKoSU7Q==", + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.12.0.tgz", + "integrity": "sha512-64KxDOb3+5ZVbz6NDZlCtOHstLk9+W96Y7d5Z/s5ge92gLaunxDeXYahvB7Rhl1dbaa3ifyq/W53o4mshIV1Tw==", "dev": true, "requires": { "tslib": "^1.8.1" diff --git a/package.json b/package.json index 5135a191ba4..9b3a166d93d 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "clean:all": "rimraf node_modules packages/*/{node_modules}", "commit": "git-cz", "docs": "typedoc", - "format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write", - "lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"", - "lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.ts\"", + "format": "npm run format:js && npm run format:ts", + "format:ts": "prettier-eslint ./bin/*.js ./bin/**/*.js ./test/**/*.js ./packages/**/**/*.js ./packages/**/*.js --write", + "format:js": "prettier-eslint ./packages/**/**/*.ts ./packages/**/*.ts ./packages/**/**/**/*.ts --write", + "lint": "eslint \"./bin/*.js\" \"./bin/**/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.ts\" \"packages/**/!(node_modules)/**/*.ts\"", "postinstall": "node ./bin/opencollective.js", "pretest": "npm run build && npm run lint", "reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov", @@ -145,8 +146,8 @@ "@commitlint/travis-cli": "^7.2.1", "@types/jest": "^23.3.14", "@types/node": "^10.12.9", - "@typescript-eslint/eslint-plugin": "^1.6.0", - "@typescript-eslint/parser": "^1.6.0", + "@typescript-eslint/eslint-plugin": "^1.9.0", + "@typescript-eslint/parser": "^1.9.0", "babel-preset-env": "^1.7.0", "babel-preset-jest": "^24.3.0", "bundlesize": "^0.17.2", diff --git a/packages/generators/__tests__/add-generator.test.ts b/packages/generators/__tests__/add-generator.test.ts index 7906123cb4e..76588aa87df 100644 --- a/packages/generators/__tests__/add-generator.test.ts +++ b/packages/generators/__tests__/add-generator.test.ts @@ -1,4 +1,4 @@ -import { generatePluginName } from "../utils/plugins" +import { generatePluginName } from "../utils/plugins"; describe("generatePluginName", () => { it("should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin", () => { @@ -11,4 +11,3 @@ describe("generatePluginName", () => { expect(pluginName).toEqual("webpack.DefinePlugin"); }); }); - diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index ced8cd62311..0bdcd282498 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -16,7 +16,6 @@ import * as webpackDevServerSchema from "webpack-dev-server/lib/options.json"; import * as webpackSchema from "./utils/optionsSchema.json"; const PROPS: string[] = Array.from(PROP_TYPES.keys()); - /** * * Checks if the given array has a given property @@ -91,8 +90,9 @@ export default class AddGenerator extends Generator { const done: () => {} = this.async(); let action: string; const self: this = this; - const manualOrListInput: (promptAction: string) => Generator.Question = (promptAction: string): Generator.Question => - Input("actionAnswer", `What do you want to add to ${promptAction}?`); + const manualOrListInput: (promptAction: string) => Generator.Question = ( + promptAction: string + ): Generator.Question => Input("actionAnswer", `What do you want to add to ${promptAction}?`); let inputPrompt: Generator.Question; // first index indicates if it has a deep prop, 2nd indicates what kind of @@ -380,7 +380,7 @@ export default class AddGenerator extends Generator { (p: boolean): void => { if (p) { this.dependencies.push(answerToAction.actionAnswer); - const pluginName = generatePluginName(answerToAction.actionAnswer) + const pluginName = generatePluginName(answerToAction.actionAnswer); this.configuration.config.topScope.push( `const ${pluginName} = require("${answerToAction.actionAnswer}")` ); diff --git a/packages/generators/addon-generator.ts b/packages/generators/addon-generator.ts index fbbcf7fc8e5..0e61f7748d8 100644 --- a/packages/generators/addon-generator.ts +++ b/packages/generators/addon-generator.ts @@ -31,7 +31,8 @@ const addonGenerator = ( copyFiles: string[], copyTemplateFiles: string[], templateFn: Function -): typeof Generator => class AddonGenerator extends Generator { +): typeof Generator => + class AddonGenerator extends Generator { public props: Generator.Question; public copy: (value: string, index: number, array: string[]) => void; public copyTpl: (value: string, index: number, array: string[]) => void; diff --git a/packages/generators/index.ts b/packages/generators/index.ts index dd4bd030f27..b537adb02f6 100644 --- a/packages/generators/index.ts +++ b/packages/generators/index.ts @@ -13,5 +13,5 @@ export { loaderGenerator, pluginGenerator, removeGenerator, - updateGenerator, + updateGenerator }; diff --git a/packages/generators/init-generator.ts b/packages/generators/init-generator.ts index 9d5b33f0b51..8ba18e4ca65 100644 --- a/packages/generators/init-generator.ts +++ b/packages/generators/init-generator.ts @@ -38,14 +38,9 @@ export default class InitGenerator extends Generator { public constructor(args, opts) { super(args, opts); - this.usingDefaults = false, - this.isProd = this.usingDefaults ? true : false; - - this.dependencies = [ - "webpack", - "webpack-cli", - "babel-plugin-syntax-dynamic-import", - ]; + (this.usingDefaults = false), (this.isProd = this.usingDefaults ? true : false); + + this.dependencies = ["webpack", "webpack-cli", "babel-plugin-syntax-dynamic-import"]; if (this.isProd) { this.dependencies.push("terser-webpack-plugin"); } else { @@ -62,10 +57,10 @@ export default class InitGenerator extends Generator { output: undefined, plugins: [], module: { - rules: [], - }, - }, - }, + rules: [] + } + } + } }; // add splitChunks options for transparency @@ -74,27 +69,25 @@ export default class InitGenerator extends Generator { "const path = require('path');", "const webpack = require('webpack');", "\n", - tooltip.splitChunks(), + tooltip.splitChunks() ); if (this.isProd) { this.configuration.config.topScope.push( tooltip.terser(), "const TerserPlugin = require('terser-webpack-plugin');", - "\n", + "\n" ); } - (this.configuration.config.webpackOptions.plugins as string[]).push( - "new webpack.ProgressPlugin()", - ); + (this.configuration.config.webpackOptions.plugins as string[]).push("new webpack.ProgressPlugin()"); let optimizationConfig = getDefaultOptimization(this.isProd); this.configuration.config.webpackOptions.optimization = optimizationConfig; if (!this.isProd) { this.configuration.config.webpackOptions.devServer = { - open: true, + open: true }; } } @@ -107,25 +100,21 @@ export default class InitGenerator extends Generator { process.stdout.write( `\n${logSymbols.info}${chalk.blue(" INFO ")} ` + - `For more information and a detailed description of each question, have a look at: ` + - `${chalk.bold.green("https://github.com/webpack/webpack-cli/blob/master/INIT.md")}\n`, + `For more information and a detailed description of each question, have a look at: ` + + `${chalk.bold.green("https://github.com/webpack/webpack-cli/blob/master/INIT.md")}\n` ); process.stdout.write( `${logSymbols.info}${chalk.blue(" INFO ")} ` + - `Alternatively, run "webpack(-cli) --help" for usage info\n\n`, + `Alternatively, run "webpack(-cli) --help" for usage info\n\n` ); const { multiEntries } = await this.prompt([ - Confirm( - "multiEntries", - "Will your application have multiple bundles?", - false - ), - ]); + Confirm("multiEntries", "Will your application have multiple bundles?", false) + ]); // TODO string | object const entryOption: void | {} = await entryQuestions(self, multiEntries); - + if (typeof entryOption === "string" && entryOption.length > 0) { this.configuration.config.webpackOptions.entry = `${entryOption}`; } else if (typeof entryOption === "object") { @@ -133,53 +122,41 @@ export default class InitGenerator extends Generator { } const { outputDir } = await this.prompt([ - Input( - "outputDir", - "In which folder do you want to store your generated bundles?", - "dist", - ), - ]); + Input("outputDir", "In which folder do you want to store your generated bundles?", "dist") + ]); // As entry is not required anymore and we dont set it to be an empty string or """"" // it can be undefined so falsy check is enough (vs entry.length); - if ( - !this.configuration.config.webpackOptions.entry && - !this.usingDefaults - ) { + if (!this.configuration.config.webpackOptions.entry && !this.usingDefaults) { this.configuration.config.webpackOptions.output = { chunkFilename: "'[name].[chunkhash].js'", - filename: "'[name].[chunkhash].js'", + filename: "'[name].[chunkhash].js'" }; } else if (!this.usingDefaults) { this.configuration.config.webpackOptions.output = { - filename: "'[name].[chunkhash].js'", + filename: "'[name].[chunkhash].js'" }; } if (!this.usingDefaults && outputDir.length) { - this.configuration.config.webpackOptions.output.path = - `path.resolve(__dirname, '${outputDir}')`; + this.configuration.config.webpackOptions.output.path = `path.resolve(__dirname, '${outputDir}')`; } - + const { langType } = await this.prompt([ - List("langType", "Will you use one of the below JS solutions?", [ - LangType.ES6, - LangType.Typescript, - "No", - ]), - ]); - + List("langType", "Will you use one of the below JS solutions?", [LangType.ES6, LangType.Typescript, "No"]) + ]); + langQuestionHandler(this, langType); this.langType = langType; - const { stylingType } = await this.prompt([ - List("stylingType", "Will you use one of the below CSS solutions?", [ - "No", - StylingType.CSS, - StylingType.SASS, - StylingType.LESS, - StylingType.PostCSS, - ]), - ]); + const { stylingType } = await this.prompt([ + List("stylingType", "Will you use one of the below CSS solutions?", [ + "No", + StylingType.CSS, + StylingType.SASS, + StylingType.LESS, + StylingType.PostCSS + ]) + ]); ({ ExtractUseProps, regExpForStyles } = styleQuestionHandler(self, stylingType)); @@ -188,10 +165,10 @@ export default class InitGenerator extends Generator { const { useExtractPlugin } = await this.prompt([ Input( "useExtractPlugin", - "If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)", - ), + "If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)" + ) ]); - + if (regExpForStyles) { if (this.isProd) { const cssBundleName: string = useExtractPlugin; @@ -199,44 +176,40 @@ export default class InitGenerator extends Generator { this.configuration.config.topScope.push( tooltip.cssPlugin(), "const MiniCssExtractPlugin = require('mini-css-extract-plugin');", - "\n", + "\n" ); if (cssBundleName.length !== 0) { (this.configuration.config.webpackOptions.plugins as string[]).push( // TODO: use [contenthash] after it is supported - `new MiniCssExtractPlugin({ filename:'${cssBundleName}.[chunkhash].css' })`, + `new MiniCssExtractPlugin({ filename:'${cssBundleName}.[chunkhash].css' })` ); } else { (this.configuration.config.webpackOptions.plugins as string[]).push( - "new MiniCssExtractPlugin({ filename:'style.css' })", + "new MiniCssExtractPlugin({ filename:'style.css' })" ); } ExtractUseProps.unshift({ - loader: "MiniCssExtractPlugin.loader", + loader: "MiniCssExtractPlugin.loader" }); } - this.configuration.config.webpackOptions.module.rules.push( - { - test: regExpForStyles, - use: ExtractUseProps, - }, - ); + this.configuration.config.webpackOptions.module.rules.push({ + test: regExpForStyles, + use: ExtractUseProps + }); } } - if(!this.isProd) { + if (!this.isProd) { this.dependencies.push("html-webpack-plugin"); const htmlWebpackDependency = "html-webpack-plugin"; const htmlwebpackPlugin = generatePluginName(htmlWebpackDependency); (this.configuration.config.topScope as string[]).push( `const ${htmlwebpackPlugin} = require('${htmlWebpackDependency}')`, "\n", - tooltip.html(), - ); - (this.configuration.config.webpackOptions.plugins as string[]).push( - `new ${htmlwebpackPlugin}()`, + tooltip.html() ); + (this.configuration.config.webpackOptions.plugins as string[]).push(`new ${htmlwebpackPlugin}()`); } done(); } @@ -244,11 +217,9 @@ export default class InitGenerator extends Generator { public installPlugins(): void { const packager = getPackageManager(); const opts: { - dev?: boolean, - "save-dev"?: boolean, - } = packager === "yarn" ? - { dev: true } : - { "save-dev": true }; + dev?: boolean; + "save-dev"?: boolean; + } = packager === "yarn" ? { dev: true } : { "save-dev": true }; this.scheduleInstallTask(packager, this.dependencies, opts); } @@ -261,29 +232,19 @@ export default class InitGenerator extends Generator { const generateEntryFile = (entryPath: string, name: string): void => { entryPath = entryPath.replace(/'/g, ""); - this.fs.copyTpl( - path.resolve(__dirname, "./templates/index.js"), - this.destinationPath(entryPath), - { name }, - ); + this.fs.copyTpl(path.resolve(__dirname, "./templates/index.js"), this.destinationPath(entryPath), { name }); }; // Generate entry file/files const entry = this.configuration.config.webpackOptions.entry; - if ( typeof entry === "string" ) { + if (typeof entry === "string") { generateEntryFile(entry, "your main file!"); } else if (typeof entry === "object") { - Object.keys(entry).forEach((name: string): void => - generateEntryFile(entry[name], `${name} main file!`), - ); + Object.keys(entry).forEach((name: string): void => generateEntryFile(entry[name], `${name} main file!`)); } // Generate README - this.fs.copyTpl( - path.resolve(__dirname, "./templates/README.md"), - this.destinationPath("README.md"), - {} - ); + this.fs.copyTpl(path.resolve(__dirname, "./templates/README.md"), this.destinationPath("README.md"), {}); // Genrate tsconfig if (this.langType === LangType.Typescript) { diff --git a/packages/generators/loader-generator.ts b/packages/generators/loader-generator.ts index aaec1666ae2..e36dab18f4d 100644 --- a/packages/generators/loader-generator.ts +++ b/packages/generators/loader-generator.ts @@ -35,8 +35,8 @@ const LoaderGenerator = addonGenerator( message: "Loader name", name: "name", type: "input", - validate: (str: string): boolean => str.length > 0, - }, + validate: (str: string): boolean => str.length > 0 + } ], path.resolve(__dirname, "..", "generate-loader"), [ @@ -48,10 +48,10 @@ const LoaderGenerator = addonGenerator( "examples/simple/webpack.config.js.tpl", "examples/simple/src/index.js.tpl", "examples/simple/src/lazy-module.js.tpl", - "examples/simple/src/static-esm-module.js.tpl", + "examples/simple/src/static-esm-module.js.tpl" ], ["src/_index.js.tpl"], - (gen): object => ({ name: gen.props.name }), + (gen): object => ({ name: gen.props.name }) ); export default LoaderGenerator; diff --git a/packages/generators/plugin-generator.ts b/packages/generators/plugin-generator.ts index 82550f520a2..22a0295332e 100644 --- a/packages/generators/plugin-generator.ts +++ b/packages/generators/plugin-generator.ts @@ -19,8 +19,8 @@ const PluginGenerator = addonGenerator( message: "Plugin name", name: "name", type: "input", - validate: (str: string): boolean => str.length > 0, - }, + validate: (str: string): boolean => str.length > 0 + } ], path.resolve(__dirname, "..", "generate-plugin"), [ @@ -29,10 +29,10 @@ const PluginGenerator = addonGenerator( "test/functional.test.js.tpl", "examples/simple/src/index.js.tpl", "examples/simple/src/lazy-module.js.tpl", - "examples/simple/src/static-esm-module.js.tpl", + "examples/simple/src/static-esm-module.js.tpl" ], ["src/_index.js.tpl", "examples/simple/_webpack.config.js.tpl"], - (gen): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }), + (gen): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }) ); export default PluginGenerator; diff --git a/packages/generators/templates/package.json.js b/packages/generators/templates/package.json.js index 54089edb516..caa852fbc6c 100644 --- a/packages/generators/templates/package.json.js +++ b/packages/generators/templates/package.json.js @@ -1,5 +1,4 @@ -module.exports = (isProd) => { - +module.exports = isProd => { let scripts = { build: "webpack" }; @@ -10,6 +9,6 @@ module.exports = (isProd) => { return { version: "1.0.0", description: "My webpack project", - scripts, + scripts }; }; diff --git a/packages/generators/utils/entry.ts b/packages/generators/utils/entry.ts index 2d29c7dda6b..3146d8b61de 100644 --- a/packages/generators/utils/entry.ts +++ b/packages/generators/utils/entry.ts @@ -16,10 +16,7 @@ interface CustomGenerator extends Generator { * @returns {Object} An Object that holds the answers given by the user, later used to scaffold */ -export default function entry( - self: CustomGenerator, - multiEntries: boolean, -): Promise { +export default function entry(self: CustomGenerator, multiEntries: boolean): Promise { let entryIdentifiers: string[]; let result: Promise; if (multiEntries) { @@ -78,49 +75,43 @@ export default function entry( `${entryProp}`, `What is the location of "${entryProp}"?`, validate, - `src/${entryProp}`, - ), - ])) - .then( - (entryPropAnswer: object): object => { - Object.keys(entryPropAnswer).forEach( - (val: string): void => { - if ( - entryPropAnswer[val].charAt(0) !== "(" && - entryPropAnswer[val].charAt(0) !== "[" && - !entryPropAnswer[val].includes("function") && - !entryPropAnswer[val].includes("path") && - !entryPropAnswer[val].includes("process") - ) { - entryPropAnswer[val] = `\'./${entryPropAnswer[val].replace(/"|'/g, "").concat(".js")}\'`; - } - webpackEntryPoint[val] = entryPropAnswer[val]; + `src/${entryProp}` + ) + ]) + ).then( + (entryPropAnswer: object): object => { + Object.keys(entryPropAnswer).forEach( + (val: string): void => { + if ( + entryPropAnswer[val].charAt(0) !== "(" && + entryPropAnswer[val].charAt(0) !== "[" && + !entryPropAnswer[val].includes("function") && + !entryPropAnswer[val].includes("path") && + !entryPropAnswer[val].includes("process") + ) { + entryPropAnswer[val] = `\'./${entryPropAnswer[val] + .replace(/"|'/g, "") + .concat(".js")}\'`; } - ); - return webpackEntryPoint; - } - ); + webpackEntryPoint[val] = entryPropAnswer[val]; + } + ); + return webpackEntryPoint; + } + ); } ); } else { - result = self - .prompt([ - Input( - "singularEntry", - "Which will be your application entry point?", - "src/index", - ) - ]) - .then( - (singularEntryAnswer: { singularEntry: string }): string => { - let { singularEntry } = singularEntryAnswer; - singularEntry = `\'./${singularEntry.replace(/"|'/g, "").concat(".js")}\'`; - if (singularEntry.length <= 0) { - self.usingDefaults = true; - } - return singularEntry; + result = self.prompt([Input("singularEntry", "Which will be your application entry point?", "src/index")]).then( + (singularEntryAnswer: { singularEntry: string }): string => { + let { singularEntry } = singularEntryAnswer; + singularEntry = `\'./${singularEntry.replace(/"|'/g, "").concat(".js")}\'`; + if (singularEntry.length <= 0) { + self.usingDefaults = true; } - ); + return singularEntry; + } + ); } return result; } diff --git a/packages/generators/utils/languageSupport.ts b/packages/generators/utils/languageSupport.ts index 7d3c1f901cf..b564d8a9dc1 100644 --- a/packages/generators/utils/languageSupport.ts +++ b/packages/generators/utils/languageSupport.ts @@ -2,11 +2,10 @@ import { Rule } from "../types"; export enum LangType { ES6 = "ES6", - Typescript = "Typescript", + Typescript = "Typescript" } -const replaceExt = (path: string, ext: string): string => - path.substr(0, path.lastIndexOf(".")) + `${ext}'`; +const replaceExt = (path: string, ext: string): string => path.substr(0, path.lastIndexOf(".")) + `${ext}'`; function updateEntryExt(self, newExt: string): void { const jsEntryOption = self.configuration.config.webpackOptions.entry; @@ -14,15 +13,21 @@ function updateEntryExt(self, newExt: string): void { if (typeof jsEntryOption === "string") { tsEntryOption = replaceExt(jsEntryOption, newExt); } else if (typeof jsEntryOption === "object") { - Object.keys(jsEntryOption).forEach((entry: string): void => { - tsEntryOption[entry] = replaceExt(jsEntryOption[entry], newExt); - }); + Object.keys(jsEntryOption).forEach( + (entry: string): void => { + tsEntryOption[entry] = replaceExt(jsEntryOption[entry], newExt); + } + ); } self.configuration.config.webpackOptions.entry = tsEntryOption; } const getFolder = (path: string): string => - path.replace("'./", "").split("/").slice(0, -1).join("/"); + path + .replace("'./", "") + .split("/") + .slice(0, -1) + .join("/"); function getEntryFolders(self): string[] { const entryOption = self.configuration.config.webpackOptions.entry; @@ -31,10 +36,12 @@ function getEntryFolders(self): string[] { const folder = getFolder(entryOption); if (folder.length > 0) entryFolders[folder] = true; } else if (typeof entryOption === "object") { - Object.keys(entryOption).forEach((entry: string): void => { - const folder = getFolder(entryOption[entry]); - if (folder.length > 0) entryFolders[folder] = true; - }); + Object.keys(entryOption).forEach( + (entry: string): void => { + const folder = getFolder(entryOption[entry]); + if (folder.length > 0) entryFolders[folder] = true; + } + ); } return Object.keys(entryFolders); } @@ -46,11 +53,9 @@ function getEntryFolders(self): string[] { * @returns {Rule} A configuration containing the babel-loader with env preset */ export function getBabelLoader(includeFolders: string[]): Rule { - const include = includeFolders.map((folder: string): string => - `path.resolve(__dirname, '${folder}')` - ); + const include = includeFolders.map((folder: string): string => `path.resolve(__dirname, '${folder}')`); return { - test: "/\.(js|jsx)$/", + test: "/.(js|jsx)$/", include, loader: "'babel-loader'", options: { @@ -63,7 +68,7 @@ export function getBabelLoader(includeFolders: string[]): Rule { } ] ] - }, + } }; } @@ -74,14 +79,12 @@ export function getBabelLoader(includeFolders: string[]): Rule { * @returns {Rule} A configuration containing the ts-loader */ export function getTypescriptLoader(includeFolders: string[]): Rule { - const include = includeFolders.map((folder: string): string => - `path.resolve(__dirname, '${folder}')` - ); + const include = includeFolders.map((folder: string): string => `path.resolve(__dirname, '${folder}')`); return { - test: "/\.(ts|tsx)?$/", + test: "/.(ts|tsx)?$/", loader: "'ts-loader'", include, - exclude: ["/node_modules/"], + exclude: ["/node_modules/"] }; } @@ -89,26 +92,15 @@ export default function language(self, langType: string): void { const entryFolders = getEntryFolders(self); switch (langType) { case LangType.ES6: - self.dependencies.push( - "babel-loader", - "@babel/core", - "@babel/preset-env", - ); - self.configuration.config.webpackOptions.module.rules.push( - getBabelLoader(entryFolders), - ); + self.dependencies.push("babel-loader", "@babel/core", "@babel/preset-env"); + self.configuration.config.webpackOptions.module.rules.push(getBabelLoader(entryFolders)); break; case LangType.Typescript: - self.dependencies.push( - "typescript", - "ts-loader", - ); - self.configuration.config.webpackOptions.module.rules.push( - getTypescriptLoader(entryFolders), - ); + self.dependencies.push("typescript", "ts-loader"); + self.configuration.config.webpackOptions.module.rules.push(getTypescriptLoader(entryFolders)); self.configuration.config.webpackOptions.resolve = { - extensions: [ "'.tsx'", "'.ts'", "'.js'" ], + extensions: ["'.tsx'", "'.ts'", "'.js'"] }; updateEntryExt(self, ".ts"); diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index 4b60bd3f307..ebc57bc0f79 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -1,4 +1,3 @@ - /** * * Callable function with the initial plugins @@ -7,7 +6,7 @@ * that consists of terser-webpack-plugin */ -export default function (): string[] { +export default function(): string[] { return ["new TerserPlugin()"]; } @@ -24,10 +23,9 @@ export default function (): string[] { * */ -export const replaceAt = (str: string, index: number, replace: string) : string => { +export const replaceAt = (str: string, index: number, replace: string): string => { return str.substring(0, index) + replace + str.substring(index + 1); -} - +}; /** * @@ -39,13 +37,12 @@ export const replaceAt = (str: string, index: number, replace: string) : string * */ - export const generatePluginName = (rawPluginName: string): string => { - let myPluginNameArray : string[]; + let myPluginNameArray: string[]; myPluginNameArray = rawPluginName.split("-"); - const pluginArrLength : number = myPluginNameArray.length; - for (let i = 0; i < pluginArrLength && pluginArrLength > 1 ; i++) { + const pluginArrLength: number = myPluginNameArray.length; + for (let i = 0; i < pluginArrLength && pluginArrLength > 1; i++) { myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); } - return myPluginNameArray.join("") -} + return myPluginNameArray.join(""); +}; diff --git a/packages/generators/utils/styleSupport.ts b/packages/generators/utils/styleSupport.ts index d05a5241a75..8a875626fa7 100644 --- a/packages/generators/utils/styleSupport.ts +++ b/packages/generators/utils/styleSupport.ts @@ -4,7 +4,7 @@ export enum StylingType { CSS = "CSS", SASS = "SASS", LESS = "LESS", - PostCSS = "PostCSS", + PostCSS = "PostCSS" } export enum LoaderName { @@ -12,14 +12,14 @@ export enum LoaderName { SASS = "sass-loader", STYLE = "style-loader", LESS = "less-loader", - POSTCSS = "postcss-loader", + POSTCSS = "postcss-loader" } export enum StyleRegex { - CSS = "/\.css$/", - SASS = "/\.(scss|css)$/", - LESS = "/\.(less|css)$/", - PostCSS = "/\.css$/", + CSS = "/.css$/", + SASS = "/.(scss|css)$/", + LESS = "/.(less|css)$/", + PostCSS = "/.css$/" } export interface Loader { @@ -31,9 +31,12 @@ export interface Loader { }; } -export default function style(self, stylingType: string): { - ExtractUseProps: Loader[], - regExpForStyles: StyleRegex, +export default function style( + self, + stylingType: string +): { + ExtractUseProps: Loader[]; + regExpForStyles: StyleRegex; } { const ExtractUseProps: Loader[] = []; let regExpForStyles: StyleRegex = null; @@ -42,92 +45,70 @@ export default function style(self, stylingType: string): { case StylingType.CSS: regExpForStyles = StyleRegex.CSS; - self.dependencies.push( - LoaderName.CSS, - ); + self.dependencies.push(LoaderName.CSS); if (!self.isProd) { - self.dependencies.push( - LoaderName.STYLE, - ); - ExtractUseProps.push( - { - loader: `"${LoaderName.STYLE}"`, - }, - ); + self.dependencies.push(LoaderName.STYLE); + ExtractUseProps.push({ + loader: `"${LoaderName.STYLE}"` + }); } ExtractUseProps.push({ loader: `"${LoaderName.CSS}"`, options: { - sourceMap: true, - }, + sourceMap: true + } }); break; case StylingType.SASS: regExpForStyles = StyleRegex.SASS; - self.dependencies.push( - "node-sass", - LoaderName.SASS, - LoaderName.CSS, - ); + self.dependencies.push("node-sass", LoaderName.SASS, LoaderName.CSS); if (!self.isProd) { - self.dependencies.push( - LoaderName.STYLE, - ); - ExtractUseProps.push( - { - loader: `"${LoaderName.STYLE}"`, - }, - ); + self.dependencies.push(LoaderName.STYLE); + ExtractUseProps.push({ + loader: `"${LoaderName.STYLE}"` + }); } ExtractUseProps.push( { loader: `"${LoaderName.CSS}"`, options: { - sourceMap: true, - }, + sourceMap: true + } }, { loader: `"${LoaderName.SASS}"`, options: { - sourceMap: true, - }, - }, + sourceMap: true + } + } ); break; case StylingType.LESS: regExpForStyles = StyleRegex.LESS; - self.dependencies.push( - "less", - LoaderName.LESS, - LoaderName.CSS, - ); + self.dependencies.push("less", LoaderName.LESS, LoaderName.CSS); if (!self.isProd) { - self.dependencies.push( - LoaderName.STYLE, - ); - ExtractUseProps.push( - { - loader: `"${LoaderName.STYLE}"`, - }, - ); + self.dependencies.push(LoaderName.STYLE); + ExtractUseProps.push({ + loader: `"${LoaderName.STYLE}"` + }); } ExtractUseProps.push( { loader: `"${LoaderName.CSS}"`, options: { - sourceMap: true, - }, + sourceMap: true + } }, { loader: `"${LoaderName.LESS}"`, options: { - sourceMap: true, - }, - }, + sourceMap: true + } + } ); break; @@ -138,32 +119,23 @@ export default function style(self, stylingType: string): { tooltip.postcss(), "const autoprefixer = require('autoprefixer');", "const precss = require('precss');", - "\n", + "\n" ); - self.dependencies.push( - "precss", - "autoprefixer", - LoaderName.CSS, - LoaderName.POSTCSS, - ); + self.dependencies.push("precss", "autoprefixer", LoaderName.CSS, LoaderName.POSTCSS); if (!self.isProd) { - self.dependencies.push( - LoaderName.STYLE, - ); - ExtractUseProps.push( - { - loader: `"${LoaderName.STYLE}"`, - }, - ); + self.dependencies.push(LoaderName.STYLE); + ExtractUseProps.push({ + loader: `"${LoaderName.STYLE}"` + }); } ExtractUseProps.push( { loader: `"${LoaderName.CSS}"`, options: { importLoaders: 1, - sourceMap: true, - }, + sourceMap: true + } }, { loader: `"${LoaderName.POSTCSS}"`, @@ -173,9 +145,9 @@ export default function style(self, stylingType: string): { precss, autoprefixer ]; - }`, - }, - }, + }` + } + } ); break; } diff --git a/packages/generators/utils/webpackConfig.ts b/packages/generators/utils/webpackConfig.ts index b67d3c6d0c5..16ef191970c 100644 --- a/packages/generators/utils/webpackConfig.ts +++ b/packages/generators/utils/webpackConfig.ts @@ -1,31 +1,29 @@ -import { WebpackOptions } from '../types'; +import { WebpackOptions } from "../types"; export function getDefaultOptimization(isProd: boolean): WebpackOptions["optimization"] { - let optimizationOptions; - if (isProd) { - optimizationOptions = { - minimizer: [ - "new TerserPlugin()", - ], - splitChunks: { - chunks: "'all'", - }, - }; - } else { - optimizationOptions = { - splitChunks: { - cacheGroups: { - vendors: { - priority: -10, - test: "/[\\\\/]node_modules[\\\\/]/", - }, - }, - chunks: "'async'", - minChunks: 1, - minSize: 30000, - name: !this.isProd, - }, - }; - } - return optimizationOptions; -} \ No newline at end of file + let optimizationOptions; + if (isProd) { + optimizationOptions = { + minimizer: ["new TerserPlugin()"], + splitChunks: { + chunks: "'all'" + } + }; + } else { + optimizationOptions = { + splitChunks: { + cacheGroups: { + vendors: { + priority: -10, + test: "/[\\\\/]node_modules[\\\\/]/" + } + }, + chunks: "'async'", + minChunks: 1, + minSize: 30000, + name: !this.isProd + } + }; + } + return optimizationOptions; +} diff --git a/packages/migrate/__tests__/migrate.test.ts b/packages/migrate/__tests__/migrate.test.ts index 4369f0f86b7..f367e19ee34 100644 --- a/packages/migrate/__tests__/migrate.test.ts +++ b/packages/migrate/__tests__/migrate.test.ts @@ -30,34 +30,34 @@ module.exports = { `; describe("transform", () => { - it("should not transform if no transformations defined", (done) => { - transform(input, []).then((output) => { - expect(output).toMatchSnapshot(input); - done(); + it("should not transform if no transformations defined", done => { + transform(input, []).then(output => { + expect(output).toMatchSnapshot(input); + done(); + }); }); - }); - it("should transform using all transformations", (done) => { - transform(input).then((output) => { - expect(output).toMatchSnapshot(); - done(); + it("should transform 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 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(); + it("should respect recast options", done => { + transform(input, undefined, { + quote: "double", + trailingComma: true + }).then(output => { + expect(output).toMatchSnapshot(); + done(); + }); }); - }); }); diff --git a/packages/migrate/commonsChunkPlugin/__tests__/commonsChunkPlugin.test.ts b/packages/migrate/commonsChunkPlugin/__tests__/commonsChunkPlugin.test.ts index 5c2e28e1f40..80ec6de5f7e 100644 --- a/packages/migrate/commonsChunkPlugin/__tests__/commonsChunkPlugin.test.ts +++ b/packages/migrate/commonsChunkPlugin/__tests__/commonsChunkPlugin.test.ts @@ -9,24 +9,8 @@ defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-2"); defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-3"); defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-4"); defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-5"); -defineTest( - dirName, - "commonsChunkPlugin", - "commonsChunkPlugin-6a", -); -defineTest( - dirName, - "commonsChunkPlugin", - "commonsChunkPlugin-6b", -); -defineTest( - dirName, - "commonsChunkPlugin", - "commonsChunkPlugin-6c", -); -defineTest( - dirName, - "commonsChunkPlugin", - "commonsChunkPlugin-6d", -); +defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-6a"); +defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-6b"); +defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-6c"); +defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-6d"); defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-7"); diff --git a/packages/migrate/extractTextPlugin/extractTextPlugin.ts b/packages/migrate/extractTextPlugin/extractTextPlugin.ts index fcc3931a394..565ff11c3ce 100644 --- a/packages/migrate/extractTextPlugin/extractTextPlugin.ts +++ b/packages/migrate/extractTextPlugin/extractTextPlugin.ts @@ -39,7 +39,8 @@ export default function(j: JSCodeshift, ast: Node): void | Node { if (literalArgs && literalArgs.length > 1) { const newArgs: object = j.objectExpression( literalArgs.map( - (p: Node, index: number): Node => utils.createProperty(j, index === 0 ? "fallback" : "use", p.value as Node) + (p: Node, index: number): Node => + utils.createProperty(j, index === 0 ? "fallback" : "use", p.value as Node) ) ); (path.value as Node).arguments = [newArgs]; diff --git a/packages/migrate/loaderOptionsPlugin/__tests__/loaderOptionsPlugin.test.ts b/packages/migrate/loaderOptionsPlugin/__tests__/loaderOptionsPlugin.test.ts index 0126a11b8cd..d827273f340 100644 --- a/packages/migrate/loaderOptionsPlugin/__tests__/loaderOptionsPlugin.test.ts +++ b/packages/migrate/loaderOptionsPlugin/__tests__/loaderOptionsPlugin.test.ts @@ -3,23 +3,7 @@ import { join } from "path"; const dirName: string = join(__dirname, ".."); -defineTest( - dirName, - "loaderOptionsPlugin", - "loaderOptionsPlugin-0", -); -defineTest( - dirName, - "loaderOptionsPlugin", - "loaderOptionsPlugin-1", -); -defineTest( - dirName, - "loaderOptionsPlugin", - "loaderOptionsPlugin-2", -); -defineTest( - dirName, - "loaderOptionsPlugin", - "loaderOptionsPlugin-3", -); +defineTest(dirName, "loaderOptionsPlugin", "loaderOptionsPlugin-0"); +defineTest(dirName, "loaderOptionsPlugin", "loaderOptionsPlugin-1"); +defineTest(dirName, "loaderOptionsPlugin", "loaderOptionsPlugin-2"); +defineTest(dirName, "loaderOptionsPlugin", "loaderOptionsPlugin-3"); diff --git a/packages/migrate/loaders/loaders.ts b/packages/migrate/loaders/loaders.ts index 0f5452c2ac1..54f75dac271 100644 --- a/packages/migrate/loaders/loaders.ts +++ b/packages/migrate/loaders/loaders.ts @@ -55,7 +55,7 @@ export default function(j: JSCodeshift, ast: Node): Node { */ const createArrayExpressionFromArray = (path: Node): Node => { - const value: Node = (path.value as Node); + const value: Node = path.value as Node; // Find paths with `loaders` keys in the given Object const paths: Node[] = value.properties.filter((prop: Node): boolean => prop.key.name.startsWith("loader")); // For each pair of key and value @@ -73,7 +73,9 @@ export default function(j: JSCodeshift, ast: Node): Node { // If items of the array are Strings if (arrElement.type === j.Literal.name) { // Replace with `{ loader: LOADER }` Object - return j.objectExpression([utils.createProperty(j, "loader", (arrElement.value as Node))]); + return j.objectExpression([ + utils.createProperty(j, "loader", arrElement.value as Node) + ]); } // otherwise keep the existing element return arrElement; @@ -108,7 +110,8 @@ export default function(j: JSCodeshift, ast: Node): Node { const createLoaderWithQuery = (p: Node): Node => { const properties: Node[] = (p.value as Node).properties; const loaderValue: string = properties.reduce( - (val: string, prop: Node): string => (prop.key.name === "loader" ? (prop.value as Node).value as string: val), + (val: string, prop: Node): string => + prop.key.name === "loader" ? ((prop.value as Node).value as string) : val, "" ); const loader: string = loaderValue.split("?")[0]; @@ -137,7 +140,8 @@ export default function(j: JSCodeshift, ast: Node): Node { const findLoaderWithQueryString = (p: Node): boolean => { return (p.value as Node).properties.reduce((predicate: boolean, prop: Node): boolean => { return ( - (utils.safeTraverse(prop, ["value", "value", "indexOf"]) && ((prop.value as Node).value as string).indexOf("?") > -1) || + (utils.safeTraverse(prop, ["value", "value", "indexOf"]) && + ((prop.value as Node).value as string).indexOf("?") > -1) || predicate ); }, false); @@ -192,7 +196,9 @@ export default function(j: JSCodeshift, ast: Node): Node { } ); if (loaders) { - (p.value as Node).properties = (p.value as Node).properties.filter((prop: Node): boolean => prop.key.name === "loaders"); + (p.value as Node).properties = (p.value as Node).properties.filter( + (prop: Node): boolean => prop.key.name === "loaders" + ); } return p; }; @@ -306,7 +312,7 @@ export default function(j: JSCodeshift, ast: Node): Node { utils.safeTraverse(prop, ["value", "value"]) && !((prop.value as Node).value as string).endsWith("-loader") ) { - prop.value = j.literal((prop.value as Node).value as string + "-loader"); + prop.value = j.literal(((prop.value as Node).value as string) + "-loader"); } } ); @@ -333,7 +339,9 @@ export default function(j: JSCodeshift, ast: Node): Node { ); if (options) { - (p.value as Node).properties = (p.value as Node).properties.filter((prop: Node): boolean => prop.key.name !== "options"); + (p.value as Node).properties = (p.value as Node).properties.filter( + (prop: Node): boolean => prop.key.name !== "options" + ); (p.value as Node).properties.forEach( (prop: Node): void => { diff --git a/packages/migrate/moduleConcatenationPlugin/__tests__/moduleConcatenationPlugin.test.ts b/packages/migrate/moduleConcatenationPlugin/__tests__/moduleConcatenationPlugin.test.ts index 840dee420a2..69fcf1c07a0 100644 --- a/packages/migrate/moduleConcatenationPlugin/__tests__/moduleConcatenationPlugin.test.ts +++ b/packages/migrate/moduleConcatenationPlugin/__tests__/moduleConcatenationPlugin.test.ts @@ -3,18 +3,6 @@ import { join } from "path"; const dirName: string = join(__dirname, ".."); -defineTest( - dirName, - "moduleConcatenationPlugin", - "moduleConcatenationPlugin-0", -); -defineTest( - dirName, - "moduleConcatenationPlugin", - "moduleConcatenationPlugin-1", -); -defineTest( - dirName, - "moduleConcatenationPlugin", - "moduleConcatenationPlugin-2", -); +defineTest(dirName, "moduleConcatenationPlugin", "moduleConcatenationPlugin-0"); +defineTest(dirName, "moduleConcatenationPlugin", "moduleConcatenationPlugin-1"); +defineTest(dirName, "moduleConcatenationPlugin", "moduleConcatenationPlugin-2"); diff --git a/packages/migrate/noEmitOnErrorsPlugin/__tests__/noEmitOnErrorsPlugin.test.ts b/packages/migrate/noEmitOnErrorsPlugin/__tests__/noEmitOnErrorsPlugin.test.ts index 760a5a1aa75..a1e43ea1021 100644 --- a/packages/migrate/noEmitOnErrorsPlugin/__tests__/noEmitOnErrorsPlugin.test.ts +++ b/packages/migrate/noEmitOnErrorsPlugin/__tests__/noEmitOnErrorsPlugin.test.ts @@ -3,18 +3,6 @@ import { join } from "path"; const dirName: string = join(__dirname, ".."); -defineTest( - dirName, - "noEmitOnErrorsPlugin", - "noEmitOnErrorsPlugin-0", -); -defineTest( - dirName, - "noEmitOnErrorsPlugin", - "noEmitOnErrorsPlugin-1", -); -defineTest( - dirName, - "noEmitOnErrorsPlugin", - "noEmitOnErrorsPlugin-2", -); +defineTest(dirName, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-0"); +defineTest(dirName, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-1"); +defineTest(dirName, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-2"); diff --git a/packages/migrate/outputPath/outputPath.ts b/packages/migrate/outputPath/outputPath.ts index e3d1c0bd087..90ea98f5ff6 100644 --- a/packages/migrate/outputPath/outputPath.ts +++ b/packages/migrate/outputPath/outputPath.ts @@ -2,18 +2,13 @@ import * as utils from "@webpack-cli/utils/ast-utils"; import { JSCodeshift, Node } from "../types/NodePath"; +function replaceWithPath(j: JSCodeshift, p: Node, pathVarName: string): Node { + const convertedPath: Node = j.callExpression( + j.memberExpression(j.identifier(pathVarName), j.identifier("join"), false), + [j.identifier("__dirname"), p.value as Node] + ); -function replaceWithPath( - j: JSCodeshift, - p: Node, - pathVarName: string, -): Node { - const convertedPath: Node = j.callExpression( - j.memberExpression(j.identifier(pathVarName), j.identifier("join"), false), - [j.identifier("__dirname"), p.value as Node], - ); - - return convertedPath; + return convertedPath; } /** @@ -25,67 +20,50 @@ function replaceWithPath( * @returns {Node} ast - jscodeshift ast */ export default function(j: JSCodeshift, ast: Node): Node | void { - const literalOutputPath: Node = ast - .find(j.ObjectExpression) - .filter( - (p: Node): boolean => - utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) === - "output", - ) - .find(j.Property) - .filter( - (p: Node): boolean => - utils.safeTraverse(p, ["value", "key", "name"]) === "path" && - utils.safeTraverse(p, ["value", "value", "type"]) === "Literal", - ); - - if (literalOutputPath) { - let pathVarName = "path"; - let isPathPresent = false; - const pathDeclaration: Node = ast - .find(j.VariableDeclarator) - .filter( - (p: Node): boolean => - utils.safeTraverse(p, ["value", "init", "callee", "name"]) === - "require", - ) + const literalOutputPath: Node = ast + .find(j.ObjectExpression) + .filter((p: Node): boolean => utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) === "output") + .find(j.Property) .filter( - (p: Node): boolean => - utils.safeTraverse(p, ["value", "init", "arguments"]) && - // TODO: to fix when we have proper typing (@types/jscodeshift) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (p.value as any).init.arguments.reduce( - (isPresent: boolean, a: Node): boolean => { - return (a.type === "Literal" && a.value === "path") || isPresent; - }, - false, - ), + (p: Node): boolean => + utils.safeTraverse(p, ["value", "key", "name"]) === "path" && + utils.safeTraverse(p, ["value", "value", "type"]) === "Literal" ); - if (pathDeclaration) { - isPathPresent = true; - pathDeclaration.forEach( - (p: Node): void => { - pathVarName = utils.safeTraverse(p, ["value", "id", "name"]) as string; - }, - ); - } - const finalPathName = pathVarName; - literalOutputPath - .find(j.Literal) - .replaceWith((p: Node): Node => replaceWithPath(j, p, finalPathName)); + if (literalOutputPath) { + let pathVarName = "path"; + let isPathPresent = false; + const pathDeclaration: Node = ast + .find(j.VariableDeclarator) + .filter((p: Node): boolean => utils.safeTraverse(p, ["value", "init", "callee", "name"]) === "require") + .filter( + (p: Node): boolean => + utils.safeTraverse(p, ["value", "init", "arguments"]) && + // TODO: to fix when we have proper typing (@types/jscodeshift) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (p.value as any).init.arguments.reduce((isPresent: boolean, a: Node): boolean => { + return (a.type === "Literal" && a.value === "path") || isPresent; + }, false) + ); - if (!isPathPresent) { - const pathRequire: Node = utils.getRequire(j, "path", "path"); - return ast - .find(j.Program) - .replaceWith( - (p: Node): Node => - j.program([].concat(pathRequire).concat((p.value as Node).body)), - ); + if (pathDeclaration) { + isPathPresent = true; + pathDeclaration.forEach( + (p: Node): void => { + pathVarName = utils.safeTraverse(p, ["value", "id", "name"]) as string; + } + ); + } + const finalPathName = pathVarName; + literalOutputPath.find(j.Literal).replaceWith((p: Node): Node => replaceWithPath(j, p, finalPathName)); + + if (!isPathPresent) { + const pathRequire: Node = utils.getRequire(j, "path", "path"); + return ast + .find(j.Program) + .replaceWith((p: Node): Node => j.program([].concat(pathRequire).concat((p.value as Node).body))); + } } - } - return ast; + return ast; } - diff --git a/packages/migrate/removeDeprecatedPlugins/__tests__/removeDeprecatedPlugins.test.ts b/packages/migrate/removeDeprecatedPlugins/__tests__/removeDeprecatedPlugins.test.ts index 922ca71424c..2e4285f1b77 100644 --- a/packages/migrate/removeDeprecatedPlugins/__tests__/removeDeprecatedPlugins.test.ts +++ b/packages/migrate/removeDeprecatedPlugins/__tests__/removeDeprecatedPlugins.test.ts @@ -3,28 +3,8 @@ import { join } from "path"; const dirName: string = join(__dirname, ".."); -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", -); +defineTest(dirName, "removeDeprecatedPlugins", "removeDeprecatedPlugins-0"); +defineTest(dirName, "removeDeprecatedPlugins", "removeDeprecatedPlugins-1"); +defineTest(dirName, "removeDeprecatedPlugins", "removeDeprecatedPlugins-2"); +defineTest(dirName, "removeDeprecatedPlugins", "removeDeprecatedPlugins-3"); +defineTest(dirName, "removeDeprecatedPlugins", "removeDeprecatedPlugins-4"); diff --git a/packages/migrate/removeJsonLoader/__tests__/removeJsonLoader.test.ts b/packages/migrate/removeJsonLoader/__tests__/removeJsonLoader.test.ts index 6d705023056..33274324889 100644 --- a/packages/migrate/removeJsonLoader/__tests__/removeJsonLoader.test.ts +++ b/packages/migrate/removeJsonLoader/__tests__/removeJsonLoader.test.ts @@ -3,23 +3,7 @@ import { join } from "path"; const dirName: string = join(__dirname, ".."); -defineTest( - dirName, - "removeJsonLoader", - "removeJsonLoader-0", -); -defineTest( - dirName, - "removeJsonLoader", - "removeJsonLoader-1", -); -defineTest( - dirName, - "removeJsonLoader", - "removeJsonLoader-2", -); -defineTest( - dirName, - "removeJsonLoader", - "removeJsonLoader-3", -); +defineTest(dirName, "removeJsonLoader", "removeJsonLoader-0"); +defineTest(dirName, "removeJsonLoader", "removeJsonLoader-1"); +defineTest(dirName, "removeJsonLoader", "removeJsonLoader-2"); +defineTest(dirName, "removeJsonLoader", "removeJsonLoader-3"); diff --git a/packages/migrate/resolve/resolve.ts b/packages/migrate/resolve/resolve.ts index be60e4e69b0..a9022039b1e 100644 --- a/packages/migrate/resolve/resolve.ts +++ b/packages/migrate/resolve/resolve.ts @@ -21,7 +21,9 @@ export default function transformer(j: JSCodeshift, ast: Node): Node { }; const isModulePresent = (p: Node): Node | false => { - const modules: Node[] = (p.node.value as Node).properties.filter((prop: Node): boolean => prop.key.name === "modules"); + const modules: Node[] = (p.node.value as Node).properties.filter( + (prop: Node): boolean => prop.key.name === "modules" + ); return modules.length > 0 && modules[0]; }; @@ -68,7 +70,8 @@ export default function transformer(j: JSCodeshift, ast: Node): Node { (p: Node): boolean => { return ( p.node.key.name === "resolve" && - (p.node.value as Node).properties.filter((prop: Node): boolean => prop.key.name === "root").length === 1 + (p.node.value as Node).properties.filter((prop: Node): boolean => prop.key.name === "root") + .length === 1 ); } ) diff --git a/packages/migrate/types/NodePath.ts b/packages/migrate/types/NodePath.ts index 1b828378ddb..66098c06894 100644 --- a/packages/migrate/types/NodePath.ts +++ b/packages/migrate/types/NodePath.ts @@ -39,11 +39,7 @@ export interface Node extends Object { size?: () => number; type?: string; value?: Node | string | Node[]; - toSource?: ( - object: { - quote?: string; - } - ) => string; + toSource?: (object: { quote?: string }) => string; source?: string; ast?: Node; rules?: ModuleRule[]; diff --git a/packages/migrate/uglifyJsPlugin/uglifyJsPlugin.ts b/packages/migrate/uglifyJsPlugin/uglifyJsPlugin.ts index 71980715a60..172d6f2f1d7 100644 --- a/packages/migrate/uglifyJsPlugin/uglifyJsPlugin.ts +++ b/packages/migrate/uglifyJsPlugin/uglifyJsPlugin.ts @@ -81,7 +81,11 @@ export default function(j: JSCodeshift, ast: Node): Node { j.arrayExpression([j.newExpression(j.identifier("TerserPlugin"), [pluginOptions[0]])]) ); } else { - expressionContent = j.property("init", j.identifier("minimizer"), j.arrayExpression([node.value as Node])); + expressionContent = j.property( + "init", + j.identifier("minimizer"), + j.arrayExpression([node.value as Node]) + ); } } else { searchForRequirePlugin.forEach((n: Node): void => j(n).remove()); diff --git a/packages/utils/__tests__/npm-exists.test.ts b/packages/utils/__tests__/npm-exists.test.ts index 2b773259af1..a5a98f168f0 100644 --- a/packages/utils/__tests__/npm-exists.test.ts +++ b/packages/utils/__tests__/npm-exists.test.ts @@ -3,13 +3,13 @@ import exists from "../npm-exists"; describe("npm-exists", () => { it("should successfully existence of a published module", () => { - exists("webpack-scaffold-demo").then((status) => { + exists("webpack-scaffold-demo").then(status => { expect(status).toBe(true); }); }); it("should return false for the existence of a fake module", () => { - exists("webpack-scaffold-noop").then((status) => { + exists("webpack-scaffold-noop").then(status => { expect(status).toBe(false); }); }); diff --git a/packages/utils/__tests__/npm-packages-exists.test.ts b/packages/utils/__tests__/npm-packages-exists.test.ts index 151eb82f863..4c75f72699d 100644 --- a/packages/utils/__tests__/npm-packages-exists.test.ts +++ b/packages/utils/__tests__/npm-packages-exists.test.ts @@ -1,5 +1,5 @@ import npmPackagesExists from "../npm-packages-exists"; -import {resolvePackages} from "../resolve-packages"; +import { resolvePackages } from "../resolve-packages"; jest.mock("../npm-exists"); jest.mock("../resolve-packages"); diff --git a/packages/utils/__tests__/package-manager.test.ts b/packages/utils/__tests__/package-manager.test.ts index baa4204822a..c21a0e45aa8 100644 --- a/packages/utils/__tests__/package-manager.test.ts +++ b/packages/utils/__tests__/package-manager.test.ts @@ -19,15 +19,15 @@ describe("package-manager", () => { signal: null, status: 1, stderr: null, - stdout: null, + stdout: null }; function mockSpawnErrorOnce() { spawn.sync.mockReturnValueOnce( Object.assign({}, defaultSyncResult, { error: new Error(), - status: null, - }), + status: null + }) ); } @@ -103,8 +103,8 @@ describe("package-manager", () => { // Mock stdout of `yarn global dir` spawn.sync.mockReturnValueOnce({ stdout: { - toString: () => `${yarnDir}\n`, - }, + toString: () => `${yarnDir}\n` + } }); const globalPath = packageManager.getPathToGlobalPackages(); const expected = path.join(yarnDir, "node_modules"); diff --git a/packages/utils/__tests__/recursive-parser.test.ts b/packages/utils/__tests__/recursive-parser.test.ts index 87778124f13..20de356e54e 100644 --- a/packages/utils/__tests__/recursive-parser.test.ts +++ b/packages/utils/__tests__/recursive-parser.test.ts @@ -15,11 +15,11 @@ defineTest(join(__dirname, ".."), "init", "fixture-1", "entry", { include: ["customObj", "'Stringy'"], loader: "'eslint-loader'", options: { - formatter: "'someOption'", + formatter: "'someOption'" }, - test: new RegExp(/\.(js|vue)$/), - }, - ], + test: new RegExp(/\.(js|vue)$/) + } + ] }); defineTest(join(__dirname, ".."), "add", "fixture-2", "entry", { @@ -35,31 +35,31 @@ defineTest(join(__dirname, ".."), "add", "fixture-2", "entry", { include: ["asd", "'Stringy'"], loader: "'pia-loader'", options: { - formatter: "'nao'", + formatter: "'nao'" }, - test: new RegExp(/\.(wasm|c)$/), - }, - ], + test: new RegExp(/\.(wasm|c)$/) + } + ] }); defineTest(join(__dirname, ".."), "remove", "fixture-3", "resolve", { - alias: null, + alias: null }); defineTest(join(__dirname, ".."), "remove", "fixture-3", "plugins", ["plugin2"]); defineTest(join(__dirname, ".."), "remove", "fixture-3", "module", { - noParse: null, + noParse: null }); defineTest(join(__dirname, ".."), "remove", "fixture-3", "entry", { - a: null, + a: null }); defineTest(join(__dirname, ".."), "remove", "fixture-3", "module", { rules: [ { - loader: "eslint-loader", - }, - ], + loader: "eslint-loader" + } + ] }); diff --git a/packages/utils/ast-utils.ts b/packages/utils/ast-utils.ts index 7a6fed5a657..5ff459b10b1 100644 --- a/packages/utils/ast-utils.ts +++ b/packages/utils/ast-utils.ts @@ -570,7 +570,7 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType * @returns ast - jscodeshift API */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars +// eslint-disable-next-line @typescript-eslint/no-unused-vars function parseTopScope(j: JSCodeshift, ast: Node, value: string[], action: string): boolean | Node { function createTopScopeProperty(p: Node): boolean { value.forEach( diff --git a/packages/utils/modify-config-helper.ts b/packages/utils/modify-config-helper.ts index 5d25385c8c0..d27b37bd608 100644 --- a/packages/utils/modify-config-helper.ts +++ b/packages/utils/modify-config-helper.ts @@ -5,7 +5,6 @@ import * as path from "path"; import * as yeoman from "yeoman-environment"; import * as Generator from "yeoman-generator"; - import runTransform from "./scaffold"; export interface Config extends Object { @@ -87,11 +86,12 @@ export default function modifyHelperUtil( } }; } - + env.registerStub(generator, generatorName); env.run(generatorName, { configFile - }).then( + }) + .then( (): void => { let configModule: object; try { diff --git a/packages/utils/prop-types.ts b/packages/utils/prop-types.ts index 894ec0e3c47..cccf77a1079 100644 --- a/packages/utils/prop-types.ts +++ b/packages/utils/prop-types.ts @@ -34,7 +34,7 @@ const PROP_TYPES: Set = new Set([ "target", "topScope", "watch", - "watchOptions", + "watchOptions" ]); export default PROP_TYPES; diff --git a/packages/utils/run-prettier.ts b/packages/utils/run-prettier.ts index bf4980150d9..5f0537f82ef 100644 --- a/packages/utils/run-prettier.ts +++ b/packages/utils/run-prettier.ts @@ -22,14 +22,14 @@ export default function runPrettier(outputPath: string, source: string, cb?: Fun parser: "babel", singleQuote: true, tabWidth: 1, - useTabs: true, + useTabs: true }); } 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", - )}`, + " due validation error, but the file has been created\n" + )}` ); prettySource = source; error = err; diff --git a/packages/utils/scaffold.ts b/packages/utils/scaffold.ts index 8da1fd7df79..f842d3a777e 100644 --- a/packages/utils/scaffold.ts +++ b/packages/utils/scaffold.ts @@ -70,35 +70,39 @@ export default function runTransform(transformConfig: TransformConfig, action: s return astTransform(j, ast, f, config[f] as any, transformAction); } return astTransform(j, ast, f, config.webpackOptions[f], transformAction); - }) - .then((): void | PromiseLike => { - let configurationName: string; - if (!config.configName) { - configurationName = "webpack.config.js"; - } else { - configurationName = "webpack." + config.configName + ".js"; + } + ) + .then( + (): void | PromiseLike => { + let configurationName: string; + if (!config.configName) { + configurationName = "webpack.config.js"; + } else { + configurationName = "webpack." + config.configName + ".js"; + } + const projectRoot = findProjectRoot(); + const outputPath: string = initActionNotDefined + ? transformConfig.configPath + : path.join(projectRoot || process.cwd(), configurationName); + const source: string = ast.toSource({ + quote: "single" + }); + runPrettier(outputPath, source); } - const projectRoot = findProjectRoot(); - const outputPath: string = initActionNotDefined - ? transformConfig.configPath - : path.join(projectRoot || process.cwd(), configurationName); - const source: string = ast.toSource({ - quote: "single", - }); - runPrettier(outputPath, source); - }) - .catch((err: Error): void => { - console.error(err.message ? err.message : err); - }); - }); + ) + .catch( + (err: Error): void => { + console.error(err.message ? err.message : err); + } + ); + } + ); let successMessage: string = chalk.green(`Congratulations! Your new webpack configuration file has been created!\n\n`) + `You can now run ${chalk.green("npm run start")} to run your project!\n\n`; if (initActionNotDefined && transformConfig.config.item) { - successMessage = chalk.green(`Congratulations! ${ - transformConfig.config.item - } has been ${action}ed!\n`); + successMessage = chalk.green(`Congratulations! ${transformConfig.config.item} has been ${action}ed!\n`); } process.stdout.write(`\n${successMessage}`); } diff --git a/packages/utils/types/NodePath.ts b/packages/utils/types/NodePath.ts index 1b828378ddb..66098c06894 100644 --- a/packages/utils/types/NodePath.ts +++ b/packages/utils/types/NodePath.ts @@ -39,11 +39,7 @@ export interface Node extends Object { size?: () => number; type?: string; value?: Node | string | Node[]; - toSource?: ( - object: { - quote?: string; - } - ) => string; + toSource?: (object: { quote?: string }) => string; source?: string; ast?: Node; rules?: ModuleRule[]; diff --git a/packages/webpack-scaffold/__tests__/index.test.ts b/packages/webpack-scaffold/__tests__/index.test.ts index 2d0ccef8582..f6b4d238c8d 100755 --- a/packages/webpack-scaffold/__tests__/index.test.ts +++ b/packages/webpack-scaffold/__tests__/index.test.ts @@ -17,9 +17,7 @@ describe("utils", () => { expect(utils.createDynamicPromise("app.js")).toMatchSnapshot(); }); it("should stringify an array", () => { - expect( - utils.createDynamicPromise(["app.js", "index.js"]), - ).toMatchSnapshot(); + expect(utils.createDynamicPromise(["app.js", "index.js"])).toMatchSnapshot(); }); }); describe("createAssetFilterFunction", () => { @@ -51,34 +49,30 @@ describe("utils", () => { choices: ["Yes", "Maybe"], message: "does it work?", name: "entry", - type: "list", + type: "list" }); }); it("should make a RawList object", () => { - expect( - utils.RawList("output", "does it work?", ["Yes", "Maybe"]), - ).toEqual({ + expect(utils.RawList("output", "does it work?", ["Yes", "Maybe"])).toEqual({ choices: ["Yes", "Maybe"], message: "does it work?", name: "output", - type: "rawlist", + type: "rawlist" }); }); it("should make a CheckList object", () => { - expect( - utils.CheckList("context", "does it work?", ["Yes", "Maybe"]), - ).toEqual({ + expect(utils.CheckList("context", "does it work?", ["Yes", "Maybe"])).toEqual({ choices: ["Yes", "Maybe"], message: "does it work?", name: "context", - type: "checkbox", + type: "checkbox" }); }); it("should make an Input object", () => { expect(utils.Input("plugins", "what is your plugin?")).toEqual({ message: "what is your plugin?", name: "plugins", - type: "input", + type: "input" }); }); it("should make an Input object", () => { @@ -86,7 +80,7 @@ describe("utils", () => { default: "my-plugin", message: "what is your plugin?", name: "plugins", - type: "input", + type: "input" }); }); it("should make a Confirm object", () => { @@ -94,7 +88,7 @@ describe("utils", () => { default: true, message: "what is your context?", name: "context", - type: "confirm", + type: "confirm" }); }); it("should make a Confirm object with No as default", () => { @@ -102,18 +96,14 @@ describe("utils", () => { default: false, message: "what is your context?", name: "context", - type: "confirm", + type: "confirm" }); }); it("should make an Input object with validation", () => { - expect( - utils.InputValidate("plugins", "what is your plugin?", () => true), - ).toMatchSnapshot(); + expect(utils.InputValidate("plugins", "what is your plugin?", () => true)).toMatchSnapshot(); }); it("should make an Input object with validation and default value", () => { - expect( - utils.InputValidate("plugins", "what is your plugin?", () => true, "my-plugin"), - ).toMatchSnapshot(); + expect(utils.InputValidate("plugins", "what is your plugin?", () => true, "my-plugin")).toMatchSnapshot(); }); }); }); diff --git a/packages/webpack-scaffold/index.ts b/packages/webpack-scaffold/index.ts index 6c609b8e522..77a0a7bcf6f 100755 --- a/packages/webpack-scaffold/index.ts +++ b/packages/webpack-scaffold/index.ts @@ -86,11 +86,11 @@ export function Input(name: string, message: string, defaultChoice?: string): Ge } export function InputValidate( - name: string, - message: string, - cb?: (input: string) => string | boolean, - defaultChoice?: string, - ): Generator.Question { + name: string, + message: string, + cb?: (input: string) => string | boolean, + defaultChoice?: string +): Generator.Question { const input: Generator.Question = { message, name,