Skip to content

Commit 123a150

Browse files
committedJun 4, 2019
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
1 parent 6ee3c0b commit 123a150

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎packages/generators/add-generator.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ export default class AddGenerator extends Generator {
291291
* find the names of each natively plugin and check if it matches
292292
*/
293293
if (action === "plugins") {
294+
let answeredPluginName = answerToAction.actionAnswer
295+
let isPrefixPresent = /webpack./.test(answeredPluginName);
296+
if( isPrefixPresent ){
297+
answeredPluginName = answeredPluginName.replace("webpack.","").trim()
298+
}else{
299+
answeredPluginName = answeredPluginName.trim()
300+
}
294301
const pluginExist: string = glob
295302
.sync(["node_modules/webpack/lib/*Plugin.js", "node_modules/webpack/lib/**/*Plugin.js"])
296303
.map(
@@ -300,7 +307,7 @@ export default class AddGenerator extends Generator {
300307
.pop()
301308
.replace(".js", "")
302309
)
303-
.find((p: string): boolean => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0);
310+
.find((p: string): boolean => p.indexOf(answeredPluginName) >= 0);
304311

305312
if (pluginExist) {
306313
this.configuration.config.item = pluginExist;
@@ -315,8 +322,7 @@ export default class AddGenerator extends Generator {
315322
.split("/")
316323
.pop()
317324
.replace(".json", "")
318-
.toLowerCase()
319-
.indexOf(answerToAction.actionAnswer) >= 0
325+
.indexOf(answeredPluginName) >= 0
320326
);
321327
if (pluginsSchemaPath) {
322328
const constructorPrefix: string =

0 commit comments

Comments
 (0)
Please sign in to comment.