Skip to content

Commit 75f018e

Browse files
committed
feat(types): add webpack types schema
1 parent 572df45 commit 75f018e

File tree

12 files changed

+249
-59
lines changed

12 files changed

+249
-59
lines changed

packages/generators/add-generator.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function replaceAt(str: string, index: number, replace: string): string {
5151
*/
5252
const traverseAndGetProperties = (arr: object[], prop: string): boolean => {
5353
let hasProp: boolean = false;
54-
arr.forEach((p: object) => {
54+
arr.forEach((p: object): void => {
5555
if (p[prop]) {
5656
hasProp = true;
5757
}
@@ -72,7 +72,7 @@ const traverseAndGetProperties = (arr: object[], prop: string): boolean => {
7272
const searchProps = (answers: object, input: string): Promise<string[]> => {
7373
input = input || "";
7474
return Promise.resolve(
75-
PROPS.filter((prop: string) =>
75+
PROPS.filter((prop: string): boolean =>
7676
prop.toLowerCase().includes(input.toLowerCase()),
7777
),
7878
);
@@ -207,15 +207,15 @@ export default class AddGenerator extends Generator {
207207
const originalPropDesc: object = defOrPropDescription[0].enum;
208208
// Array -> Object -> Merge objects into one for compat in manualOrListInput
209209
defOrPropDescription = Object.keys(defOrPropDescription[0].enum)
210-
.map((p: string) => {
210+
.map((p: string): object => {
211211
return Object.assign(
212212
{},
213213
{
214214
[originalPropDesc[p]]: "noop",
215215
},
216216
);
217217
})
218-
.reduce((result: object, currentObject: object) => {
218+
.reduce((result: object, currentObject: object): object => {
219219
for (const key in currentObject) {
220220
if (currentObject.hasOwnProperty(key)) {
221221
result[key] = currentObject[key];
@@ -323,14 +323,14 @@ export default class AddGenerator extends Generator {
323323
"node_modules/webpack/lib/*Plugin.js",
324324
"node_modules/webpack/lib/**/*Plugin.js",
325325
])
326-
.map((p: string) =>
326+
.map((p: string): string =>
327327
p
328328
.split("/")
329329
.pop()
330330
.replace(".js", ""),
331331
)
332332
.find(
333-
(p: string) => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0,
333+
(p: string): boolean => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0,
334334
);
335335

336336
if (pluginExist) {
@@ -341,7 +341,7 @@ export default class AddGenerator extends Generator {
341341
"node_modules/webpack/schemas/plugins/**/*Plugin.json",
342342
])
343343
.find(
344-
(p: string) =>
344+
(p: string): boolean =>
345345
p
346346
.split("/")
347347
.pop()
@@ -361,9 +361,9 @@ export default class AddGenerator extends Generator {
361361
let pluginsSchemaProps: string[] = ["other"];
362362
if (pluginSchema) {
363363
Object.keys(pluginSchema)
364-
.filter((p: string) => Array.isArray(pluginSchema[p]))
365-
.forEach((p: string) => {
366-
Object.keys(pluginSchema[p]).forEach((n: string) => {
364+
.filter((p: string): boolean => Array.isArray(pluginSchema[p]))
365+
.forEach((p: string): void => {
366+
Object.keys(pluginSchema[p]).forEach((n: string): void => {
367367
if (pluginSchema[p][n].properties) {
368368
pluginsSchemaProps = Object.keys(
369369
pluginSchema[p][n].properties,

packages/generators/addon-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function addonGenerator(
7474
public install() {
7575
this.npmInstall(["webpack-defaults", "bluebird"], {
7676
"save-dev": true,
77-
}).then((_: void) => {
77+
}).then((_: void): void => {
7878
this.spawnCommand("npm", ["run", "defaults"]);
7979
});
8080
}

packages/generators/loader-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const LoaderGenerator = addonGenerator(
3535
message: "Loader name",
3636
name: "name",
3737
type: "input",
38-
validate: (str: string) => str.length > 0,
38+
validate: (str: string): boolean => str.length > 0,
3939
},
4040
],
4141
path.resolve(__dirname, "..", "generate-loader"),
@@ -51,7 +51,7 @@ const LoaderGenerator = addonGenerator(
5151
"examples/simple/src/static-esm-module.js.tpl",
5252
],
5353
["src/_index.js.tpl"],
54-
(gen: IYeoman) => ({ name: gen.props.name }),
54+
(gen: IYeoman): object => ({ name: gen.props.name }),
5555
);
5656

5757
export default LoaderGenerator;

packages/generators/plugin-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const PluginGenerator = addonGenerator(
1919
message: "Plugin name",
2020
name: "name",
2121
type: "input",
22-
validate: (str: string) => str.length > 0,
22+
validate: (str: string): boolean => str.length > 0,
2323
},
2424
],
2525
path.resolve(__dirname, "..", "generate-plugin"),
@@ -32,7 +32,7 @@ const PluginGenerator = addonGenerator(
3232
"examples/simple/src/static-esm-module.js.tpl",
3333
],
3434
["src/_index.js.tpl", "examples/simple/_webpack.config.js.tpl"],
35-
(gen: IYeoman) => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }),
35+
(gen: IYeoman): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }),
3636
);
3737

3838
export default PluginGenerator;

packages/generators/remove-generator.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export default class RemoveGenerator extends Generator {
4949
public getModuleLoadersNames(): string[] {
5050
if (typeof this.webpackOptions === "object") {
5151
if (this.webpackOptions.module && this.webpackOptions.module.rules) {
52-
return this.webpackOptions.module.rules.map((rule: any) => rule ? rule.loader : null);
52+
return this.webpackOptions.module.rules.map((rule: {
53+
loader: string;
54+
}) => rule ? rule.loader : null);
5355
}
5456
}
5557
}
@@ -65,7 +67,7 @@ export default class RemoveGenerator extends Generator {
6567
Array.from(this.getPropTypes()),
6668
),
6769
])
68-
.then(({ propType }: { propType: string }) => {
70+
.then(({ propType }: { propType: string }): Promise<{}> => {
6971
if (!PROP_TYPES.has(propType)) {
7072
console.log("Invalid webpack config prop");
7173
return;
@@ -80,7 +82,7 @@ export default class RemoveGenerator extends Generator {
8082
`Which key do you want to remove from ${propType}?`,
8183
Array.from(propValue),
8284
),
83-
]).then(({ keyType }: { keyType: string }) => {
85+
]).then(({ keyType }: { keyType: string }): void => {
8486
this.configuration.config.webpackOptions[propType] = [ keyType ];
8587
});
8688
} else {
@@ -91,7 +93,7 @@ export default class RemoveGenerator extends Generator {
9193
Array.from(Object.keys(propValue)),
9294
),
9395
])
94-
.then(({ keyType }: { keyType: string }) => {
96+
.then(({ keyType }: { keyType: string }): Promise<{}> => {
9597
if (propType === "module" && keyType === "rules") {
9698
return this.prompt([
9799
List(
@@ -100,7 +102,7 @@ export default class RemoveGenerator extends Generator {
100102
Array.from(this.getModuleLoadersNames()),
101103
),
102104
])
103-
.then(({ rule }: { rule: string }) => {
105+
.then(({ rule }: { rule: string }): void => {
104106
if (typeof this.webpackOptions === "object") {
105107
const loaderIndex: number = this.getModuleLoadersNames().indexOf(rule);
106108
const loader: object = this.webpackOptions.module.rules[loaderIndex];
@@ -125,7 +127,7 @@ export default class RemoveGenerator extends Generator {
125127
this.configuration.config.webpackOptions[propType] = null;
126128
}
127129
})
128-
.then((_: void) => {
130+
.then((_: void): void => {
129131
done();
130132
});
131133
}

0 commit comments

Comments
 (0)