Skip to content

Commit 77ff99b

Browse files
chore: remove lodash from direct dependencies (#1834)
* chore: update loader generator * chore: update plugin-generator * chore: remove lodash Co-authored-by: Even Stensberg <evenstensberg@gmail.com>
1 parent 0f24fcb commit 77ff99b

File tree

8 files changed

+30
-20
lines changed

8 files changed

+30
-20
lines changed

packages/generators/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@webpack-cli/package-utils": "^1.0.1-rc.0",
1414
"@webpack-cli/utils": "^1.0.1-rc.0",
1515
"@webpack-cli/webpack-scaffold": "^1.0.1-rc.0",
16-
"lodash": "4.17.19",
1716
"colorette": "^1.2.1",
1817
"log-symbols": "3.0.0",
1918
"mkdirp": "1.0.3",
@@ -23,7 +22,6 @@
2322
"webpack-cli": "3.x.x || 4.x.x"
2423
},
2524
"devDependencies": {
26-
"@types/lodash": "4.14.149",
2725
"@types/mkdirp": "1.0.0",
2826
"@types/yeoman-assert": "^3.1.1",
2927
"@types/yeoman-generator": "3.1.4",

packages/generators/src/loader-generator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import _ from 'lodash';
21
import path from 'path';
32
import addonGenerator from './addon-generator';
4-
3+
import { toKebabCase } from './utils/helpers';
54
/**
65
* Formats a string into webpack loader format
76
* (eg: 'style-loader', 'raw-loader')
@@ -10,7 +9,7 @@ import addonGenerator from './addon-generator';
109
* @returns {string} The formatted string
1110
*/
1211
export function makeLoaderName(name: string): string {
13-
name = _.kebabCase(name);
12+
name = toKebabCase(name);
1413
if (!/loader$/.test(name)) {
1514
name += '-loader';
1615
}

packages/generators/src/plugin-generator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import _ from 'lodash';
21
import path from 'path';
32
import addonGenerator from './addon-generator';
4-
3+
import { toKebabCase, toUpperCamelCase } from './utils/helpers';
54
/**
65
* A yeoman generator class for creating a webpack
76
* plugin project. It adds some starter plugin code
@@ -14,7 +13,7 @@ const PluginGenerator = addonGenerator(
1413
[
1514
{
1615
default: 'my-webpack-plugin',
17-
filter: _.kebabCase,
16+
filter: toKebabCase,
1817
message: 'Plugin name',
1918
name: 'name',
2019
type: 'input',
@@ -31,7 +30,7 @@ const PluginGenerator = addonGenerator(
3130
'examples/simple/src/static-esm-module.js.tpl',
3231
],
3332
['src/_index.js.tpl', 'examples/simple/_webpack.config.js.tpl'],
34-
(gen): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }),
33+
(gen): object => ({ name: toUpperCamelCase(gen.props.name) }),
3534
);
3635

3736
export default PluginGenerator;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const regex = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
2+
3+
/**
4+
* Convert str to kebab-case
5+
* @param str input string
6+
* @returns output string
7+
*/
8+
export function toKebabCase(str: string): string {
9+
return str.match(regex).join('-').toLowerCase();
10+
}
11+
12+
/**
13+
* Convert str to UpperCamelCase
14+
* @param str import string
15+
* @returns {string} output string
16+
*/
17+
export function toUpperCamelCase(str: string): string {
18+
return str
19+
.match(regex)
20+
.map((x) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
21+
.join('');
22+
}

packages/migrate/__testfixtures__/failing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const webpack = require('webpack');
22
const nodeEnvironment = process.env.NODE_ENV;
3-
const _ = require("lodash");
43

54
const config = {
65
entry: {

packages/migrate/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"inquirer": "7.1.0",
1616
"jscodeshift": "0.7.0",
1717
"listr": "0.14.3",
18-
"lodash": "4.17.19",
1918
"p-each-series": "2.1.0",
2019
"p-lazy": "3.0.0"
2120
},
@@ -27,7 +26,6 @@
2726
"@types/diff": "4.0.2",
2827
"@types/inquirer": "6.5.0",
2928
"@types/listr": "0.14.2",
30-
"@types/lodash": "^4.14.149",
3129
"webpack": "4.x.x"
3230
},
3331
"files": [

packages/migrate/src/loaderOptionsPlugin/loaderOptionsPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import isEmpty = require('lodash/isEmpty');
2-
31
import { createOrUpdatePluginByName, findPluginsByName, safeTraverse } from '@webpack-cli/utils';
42

53
import { JSCodeshift, Node } from '../types/NodePath';
@@ -9,6 +7,8 @@ interface LoaderOptions {
97
minimize?: boolean;
108
}
119

10+
const isEmpty = (obj: LoaderOptions): boolean => Object.keys(obj).length === 0;
11+
1212
/**
1313
*
1414
* Transform which adds context information for old loaders by injecting a `LoaderOptionsPlugin`

yarn.lock

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,11 +2575,6 @@
25752575
"@types/node" "*"
25762576
rxjs "^6.5.1"
25772577

2578-
"@types/lodash@4.14.149", "@types/lodash@^4.14.149":
2579-
version "4.14.149"
2580-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
2581-
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
2582-
25832578
"@types/minimatch@*", "@types/minimatch@^3.0.3":
25842579
version "3.0.3"
25852580
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -8488,7 +8483,7 @@ lodash@4.17.15:
84888483
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
84898484
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
84908485

8491-
lodash@4.17.19, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.2.1:
8486+
lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.2.1:
84928487
version "4.17.19"
84938488
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
84948489
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==

0 commit comments

Comments
 (0)