From 7fbc3a4b57c81bd7bff2c09c13adca56d7ec081a Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Fri, 24 May 2019 11:23:43 +0530 Subject: [PATCH 01/11] chore(add-generator): changed the naming of the plugin in config file Changed the naming of the plugin to better and standard and bug free name in add-generator in plugin question --- packages/generators/add-generator.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index bef3c32afd3..a911b75e6ce 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -395,15 +395,11 @@ export default class AddGenerator extends Generator { (p: boolean): void => { if (p) { this.dependencies.push(answerToAction.actionAnswer); - const normalizePluginName = answerToAction.actionAnswer.replace( - "-webpack-plugin", - "Plugin" - ); - const pluginName = replaceAt( - normalizePluginName, - 0, - normalizePluginName.charAt(0).toUpperCase() - ); + let myPluginNameArray = answerToAction.actionAnswer.split("-") + for (let i = 0; i < myPluginNameArray.length; i++) { + myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); + } + const pluginName = myPluginNameArray.join("") this.configuration.config.topScope.push( `const ${pluginName} = require("${answerToAction.actionAnswer}")` ); From 7d83453434171800d63b925f9470b68cc84ce0db Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Mon, 27 May 2019 22:45:40 +0530 Subject: [PATCH 02/11] chore: added a generatePluginName method in generators utils Added generatePluginName in generators/utils/plugins.ts and also moved the replaceAt method from add-generator.ts to generators/utils/plugins.ts. Added tests for the plugin name method --- .../__tests__/add-generator.test.ts | 14 +++++++ packages/generators/add-generator.ts | 23 +---------- packages/generators/utils/plugins.ts | 41 ++++++++++++++++++- 3 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 packages/generators/__tests__/add-generator.test.ts diff --git a/packages/generators/__tests__/add-generator.test.ts b/packages/generators/__tests__/add-generator.test.ts new file mode 100644 index 00000000000..d8a657f527d --- /dev/null +++ b/packages/generators/__tests__/add-generator.test.ts @@ -0,0 +1,14 @@ +import { generatePluginName } from "../utils/plugins" + +describe("generatePluginName", () => { + it("should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin", () => { + const pluginName = generatePluginName("extract-text-webpack-plugin"); + expect(pluginName).toEqual("ExtractTextWebpackPlugin"); + }); + + it("should return webpack Standard Plugin Name for Name : webpack.DefinePlugin", () => { + const pluginName = generatePluginName("webpack.DefinePlugin"); + expect(pluginName).toEqual("Webpack.DefinePlugin"); + }); +}); + diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index a911b75e6ce..03d8619c895 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -11,26 +11,11 @@ import { AutoComplete, Confirm, Input, List } from "@webpack-cli/webpack-scaffol import { SchemaProperties, WebpackOptions } from "./types"; import entryQuestions from "./utils/entry"; - +import { generatePluginName } from "./utils/plugins"; import webpackDevServerSchema from "webpack-dev-server/lib/options.json"; import webpackSchema from "./utils/optionsSchema.json"; const PROPS: string[] = Array.from(PROP_TYPES.keys()); -/** - * - * Replaces the string with a substring at the given index - * https://gist.github.com/efenacigiray/9367920 - * - * @param {String} str - string to be modified - * @param {Number} index - index to replace from - * @param {String} replace - string to replace starting from index - * - * @returns {String} string - The newly mutated string - * - */ -function replaceAt(str: string, index: number, replace: string): string { - return str.substring(0, index) + replace + str.substring(index + 1); -} /** * @@ -395,11 +380,7 @@ export default class AddGenerator extends Generator { (p: boolean): void => { if (p) { this.dependencies.push(answerToAction.actionAnswer); - let myPluginNameArray = answerToAction.actionAnswer.split("-") - for (let i = 0; i < myPluginNameArray.length; i++) { - myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); - } - const pluginName = myPluginNameArray.join("") + const pluginName = generatePluginName(answerToAction.actionAnswer) this.configuration.config.topScope.push( `const ${pluginName} = require("${answerToAction.actionAnswer}")` ); diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index 6dedb1fab9e..3982df796f2 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -1,3 +1,4 @@ + /** * * Callable function with the initial plugins @@ -6,6 +7,44 @@ * that consists of terser-webpack-plugin */ -export default function(): string[] { +export default function (): string[] { return ["new TerserPlugin()"]; } + +/** + * + * Replaces the string with a substring at the given index + * https://gist.github.com/efenacigiray/9367920 + * + * @param {String} str - string to be modified + * @param {Number} index - index to replace from + * @param {String} replace - string to replace starting from index + * + * @returns {String} string - The newly mutated string + * + */ + +export const replaceAt = (str: string, index: number, replace: string) : string => { + return str.substring(0, index) + replace + str.substring(index + 1); +} + + +/** + * + * Generate a webpack standard webpack plugin name from the plugin name from the Answer + * + * @param {String} rawPluginName - plugin name from answer + * + * @returns {String} string - the webpack standard plugin name + * + */ + + +export const generatePluginName = (rawPluginName: string): string => { + let myPluginNameArray : string[]; + myPluginNameArray = rawPluginName.split("-"); + for (let i = 0; i < myPluginNameArray.length; i++) { + myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); + } + return myPluginNameArray.join("") +} From fc9e2592d9e99692c6073ac028512ce58a9bf9a2 Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Mon, 27 May 2019 23:11:04 +0530 Subject: [PATCH 03/11] chore(plugins.ts): added if-stmt for native plugins Added if stmt for not doing anything when native plugins comes-in Also Changed the test --- packages/generators/__tests__/add-generator.test.ts | 2 +- packages/generators/utils/plugins.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/generators/__tests__/add-generator.test.ts b/packages/generators/__tests__/add-generator.test.ts index d8a657f527d..7906123cb4e 100644 --- a/packages/generators/__tests__/add-generator.test.ts +++ b/packages/generators/__tests__/add-generator.test.ts @@ -8,7 +8,7 @@ describe("generatePluginName", () => { it("should return webpack Standard Plugin Name for Name : webpack.DefinePlugin", () => { const pluginName = generatePluginName("webpack.DefinePlugin"); - expect(pluginName).toEqual("Webpack.DefinePlugin"); + expect(pluginName).toEqual("webpack.DefinePlugin"); }); }); diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index 3982df796f2..f2c571e7cda 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -43,8 +43,11 @@ export const replaceAt = (str: string, index: number, replace: string) : string export const generatePluginName = (rawPluginName: string): string => { let myPluginNameArray : string[]; myPluginNameArray = rawPluginName.split("-"); - for (let i = 0; i < myPluginNameArray.length; i++) { - myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); + if( myPluginNameArray.length <= 1 ){} + else{ + for (let i = 0; i < myPluginNameArray.length; i++) { + myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); + } } return myPluginNameArray.join("") } From e583aabd51442f427a3f92816153b01ac43288af Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Tue, 28 May 2019 11:52:04 +0530 Subject: [PATCH 04/11] chore(style): fixed the indentation fix the indentation --- packages/generators/utils/plugins.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index f2c571e7cda..ab3d3698a45 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -43,7 +43,7 @@ export const replaceAt = (str: string, index: number, replace: string) : string export const generatePluginName = (rawPluginName: string): string => { let myPluginNameArray : string[]; myPluginNameArray = rawPluginName.split("-"); - if( myPluginNameArray.length <= 1 ){} + if(myPluginNameArray.length <= 1){} else{ for (let i = 0; i < myPluginNameArray.length; i++) { myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); From 5e33f8a76bc9662df5ee2311b4a2155e48058ccf Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Mon, 27 May 2019 03:28:23 +0200 Subject: [PATCH 05/11] chore: add sec & versioning policy --- SECURITY.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000000..ef1676b50d2 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +This document explains the security policy of webpack-cli and how we intend to support webpack and webpack-cli. + +## Supported Versions + +webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes are released in patches. + +| webpack version | webpack-cli version | Supported | +| --------------- | ----------------------------- | ------------------ | +| 4.x.0 | ^3.1.2 | :white_check_mark: | +| 4.0.x | ^3.1.2 | :white_check_mark: | +| 5.x.0 | ^3.1.2 | :white_check_mark: | +| 5.0.x | ^3.1.2 | :white_check_mark: | +| < 4.x.x | (CLI included in webpack < 4) | :x: | + +**Note: Using webpack < 4 with webpack CLI is not required as CLI was [included](https://github.com/webpack/webpack/commit/4b0332d3909eea8115d84f9a03da2d52478daa70#diff-b9cfc7f2cdf78a7f4b91a753d10865a2) in webpack.** + +## Reporting a Vulnerability + +To report a vulnerability, please contact one of webpack maintainers through the email provided from either npm, GitHub or reach out at other social media platforms. For third party security vulnerabilities, submitting an issue or Pull Request to fix the security vulerability is much appreciated. From 818e43e54a7e7288d39a1d5811213054417ab926 Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Tue, 28 May 2019 14:37:41 +0530 Subject: [PATCH 06/11] chore: loop change changed the loop --- packages/generators/utils/plugins.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index ab3d3698a45..560eaa35b50 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -43,11 +43,8 @@ export const replaceAt = (str: string, index: number, replace: string) : string export const generatePluginName = (rawPluginName: string): string => { let myPluginNameArray : string[]; myPluginNameArray = rawPluginName.split("-"); - if(myPluginNameArray.length <= 1){} - else{ - for (let i = 0; i < myPluginNameArray.length; i++) { - myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); - } + for (let i = 0; i < myPluginNameArray.length && myPluginNameArray.length > 1 ; i++) { + myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase()); } return myPluginNameArray.join("") } From 90f397c7f136eda23969d00ea95d008e89ee580c Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Wed, 29 May 2019 10:00:06 +0200 Subject: [PATCH 07/11] chore: revise version support --- SECURITY.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index ef1676b50d2..3eb4961763c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,8 +8,8 @@ webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes ar | webpack version | webpack-cli version | Supported | | --------------- | ----------------------------- | ------------------ | -| 4.x.0 | ^3.1.2 | :white_check_mark: | -| 4.0.x | ^3.1.2 | :white_check_mark: | +| > 4.20.0 | ^3.1.2 | :white_check_mark: | +| 4.20.x | ^3.1.2 | :white_check_mark: | | 5.x.0 | ^3.1.2 | :white_check_mark: | | 5.0.x | ^3.1.2 | :white_check_mark: | | < 4.x.x | (CLI included in webpack < 4) | :x: | From 9cdc3570df687afd66eabe722e644e6537b8fc0b Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 May 2019 11:08:44 +0200 Subject: [PATCH 08/11] chore: revise SECURITY.md Co-Authored-By: Emanuele --- SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index 3eb4961763c..833651fcd0b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,7 +8,7 @@ webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes ar | webpack version | webpack-cli version | Supported | | --------------- | ----------------------------- | ------------------ | -| > 4.20.0 | ^3.1.2 | :white_check_mark: | +| >= 4.20.x | ^3.1.2 | :white_check_mark: | | 4.20.x | ^3.1.2 | :white_check_mark: | | 5.x.0 | ^3.1.2 | :white_check_mark: | | 5.0.x | ^3.1.2 | :white_check_mark: | From 2a9e3048bc5ed3cff37dd8ad57eb1e36aafbbcc7 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 May 2019 11:08:54 +0200 Subject: [PATCH 09/11] chore: revise SECURITY.md Co-Authored-By: Emanuele --- SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index 833651fcd0b..c54aedcf910 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -9,7 +9,7 @@ webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes ar | webpack version | webpack-cli version | Supported | | --------------- | ----------------------------- | ------------------ | | >= 4.20.x | ^3.1.2 | :white_check_mark: | -| 4.20.x | ^3.1.2 | :white_check_mark: | +| <= 4.19.x | ^3.1.1 | :white_check_mark: | | 5.x.0 | ^3.1.2 | :white_check_mark: | | 5.0.x | ^3.1.2 | :white_check_mark: | | < 4.x.x | (CLI included in webpack < 4) | :x: | From 4872416a5b2859021a2d969db0685227f108e253 Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Thu, 30 May 2019 11:34:56 +0530 Subject: [PATCH 10/11] chore: pluginarrlength for length of the plugin assigned length of the plugin to a constant --- packages/generators/utils/plugins.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/generators/utils/plugins.ts b/packages/generators/utils/plugins.ts index 560eaa35b50..4b60bd3f307 100644 --- a/packages/generators/utils/plugins.ts +++ b/packages/generators/utils/plugins.ts @@ -43,7 +43,8 @@ export const replaceAt = (str: string, index: number, replace: string) : string export const generatePluginName = (rawPluginName: string): string => { let myPluginNameArray : string[]; myPluginNameArray = rawPluginName.split("-"); - for (let i = 0; i < myPluginNameArray.length && myPluginNameArray.length > 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("") From 61697b8ea6a6923f173680b6ea35be743eca0d6f Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Thu, 30 May 2019 17:08:29 +0200 Subject: [PATCH 11/11] fix: json module resolve --- packages/generators/add-generator.ts | 4 ++-- tsconfig.base.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index 03d8619c895..705afb0da0c 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -12,8 +12,8 @@ import { AutoComplete, Confirm, Input, List } from "@webpack-cli/webpack-scaffol import { SchemaProperties, WebpackOptions } from "./types"; import entryQuestions from "./utils/entry"; import { generatePluginName } from "./utils/plugins"; -import webpackDevServerSchema from "webpack-dev-server/lib/options.json"; -import webpackSchema from "./utils/optionsSchema.json"; +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()); diff --git a/tsconfig.base.json b/tsconfig.base.json index d92fae8bb6a..dc260d82933 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -4,7 +4,8 @@ "module": "commonjs", "moduleResolution": "node", "allowSyntheticDefaultImports": true, - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true, }, "include": ["packages/**/*.ts"], "exclude": [