From 123a1507611c620086755ed556740b92f0c1f4b0 Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Tue, 4 Jun 2019 14:51:10 +0530 Subject: [PATCH 1/3] fix(generator): fixed the support of native plugins in add command refractored the code to fix the error of supporting the native plugin in add-generator. removed the toLowerCase() method, added the logic for more general plugin name from the input --- packages/generators/add-generator.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index 0bdcd282498..04f433eafb0 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -291,6 +291,13 @@ export default class AddGenerator extends Generator { * find the names of each natively plugin and check if it matches */ if (action === "plugins") { + let answeredPluginName = answerToAction.actionAnswer + let isPrefixPresent = /webpack./.test(answeredPluginName); + if( isPrefixPresent ){ + answeredPluginName = answeredPluginName.replace("webpack.","").trim() + }else{ + answeredPluginName = answeredPluginName.trim() + } const pluginExist: string = glob .sync(["node_modules/webpack/lib/*Plugin.js", "node_modules/webpack/lib/**/*Plugin.js"]) .map( @@ -300,7 +307,7 @@ export default class AddGenerator extends Generator { .pop() .replace(".js", "") ) - .find((p: string): boolean => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0); + .find((p: string): boolean => p.indexOf(answeredPluginName) >= 0); if (pluginExist) { this.configuration.config.item = pluginExist; @@ -315,8 +322,7 @@ export default class AddGenerator extends Generator { .split("/") .pop() .replace(".json", "") - .toLowerCase() - .indexOf(answerToAction.actionAnswer) >= 0 + .indexOf(answeredPluginName) >= 0 ); if (pluginsSchemaPath) { const constructorPrefix: string = From 20ff530dc21bf36327e1103e883c6833ea33f1cb Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Tue, 4 Jun 2019 15:56:49 +0200 Subject: [PATCH 2/3] chore: formatting --- packages/generators/add-generator.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index 04f433eafb0..f17663b1ad3 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -291,12 +291,13 @@ export default class AddGenerator extends Generator { * find the names of each natively plugin and check if it matches */ if (action === "plugins") { - let answeredPluginName = answerToAction.actionAnswer + let answeredPluginName = answerToAction.actionAnswer; let isPrefixPresent = /webpack./.test(answeredPluginName); - if( isPrefixPresent ){ - answeredPluginName = answeredPluginName.replace("webpack.","").trim() - }else{ - answeredPluginName = answeredPluginName.trim() + + if (isPrefixPresent) { + answeredPluginName = answeredPluginName.replace("webpack.", "").trim(); + } else { + answeredPluginName = answeredPluginName.trim(); } const pluginExist: string = glob .sync(["node_modules/webpack/lib/*Plugin.js", "node_modules/webpack/lib/**/*Plugin.js"]) From c01a80ba8651aba6f209aea4d950487d03fd6707 Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Tue, 4 Jun 2019 16:00:49 +0200 Subject: [PATCH 3/3] chore: keep lowercase --- packages/generators/add-generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/generators/add-generator.ts b/packages/generators/add-generator.ts index f17663b1ad3..a1fc3da8c20 100644 --- a/packages/generators/add-generator.ts +++ b/packages/generators/add-generator.ts @@ -308,7 +308,7 @@ export default class AddGenerator extends Generator { .pop() .replace(".js", "") ) - .find((p: string): boolean => p.indexOf(answeredPluginName) >= 0); + .find((p: string): boolean => p.toLowerCase().indexOf(answeredPluginName) >= 0); if (pluginExist) { this.configuration.config.item = pluginExist;