Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/webpack/webpack-cli into …
Browse files Browse the repository at this point in the history
…misc/improve-init-generator
  • Loading branch information
evenstensberg committed May 30, 2019
2 parents 4e8bc76 + de9c89c commit 2a92877
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 28 deletions.
21 changes: 21 additions & 0 deletions 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.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: |

**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.
14 changes: 14 additions & 0 deletions 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");
});
});

31 changes: 4 additions & 27 deletions packages/generators/add-generator.ts
Expand Up @@ -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 webpackDevServerSchema from "webpack-dev-server/lib/options.json";
import webpackSchema from "./utils/optionsSchema.json";
import { generatePluginName } from "./utils/plugins";
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());

/**
*
* 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);
}

/**
*
Expand Down Expand Up @@ -395,15 +380,7 @@ 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()
);
const pluginName = generatePluginName(answerToAction.actionAnswer)
this.configuration.config.topScope.push(
`const ${pluginName} = require("${answerToAction.actionAnswer}")`
);
Expand Down
51 changes: 51 additions & 0 deletions packages/generators/utils/plugins.ts
@@ -0,0 +1,51 @@

/**
*
* Callable function with the initial plugins
*
* @returns {Function} An function that returns an array
* that consists of terser-webpack-plugin
*/

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("-");
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("")
}
3 changes: 2 additions & 1 deletion tsconfig.base.json
Expand Up @@ -4,7 +4,8 @@
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"skipLibCheck": true,
"resolveJsonModule": true,
},
"include": ["packages/**/*.ts"],
"exclude": [
Expand Down

0 comments on commit 2a92877

Please sign in to comment.