Skip to content

Commit 8ec1375

Browse files
authored
feat: added types
1 parent 6340c49 commit 8ec1375

31 files changed

+858
-372
lines changed

.eslintignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ coverage
22
.nyc_output
33
node_modules
44
dist
5-
packages/configtest/lib
6-
packages/generators/lib
7-
packages/info/lib
8-
packages/serve/lib
5+
packages/*/lib
96
test/**/dist/
107
test/**/bin/
118
test/**/binary/

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ packages/**/*.map
5555
# build files
5656
packages/**/lib
5757
packages/**/yarn.lock
58-
!packages/webpack-cli/lib
5958

6059
# test output files
6160
test/js/*

.prettierignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ coverage
22
.nyc_output
33
node_modules
44
dist
5-
packages/configtest/lib
6-
packages/generators/lib
7-
packages/info/lib
8-
packages/serve/lib
5+
packages/*/lib
96
test/**/dist/
107
test/**/bin/
118
test/**/binary/

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"./packages/*"
2323
],
2424
"scripts": {
25-
"clean": "del-cli \"*.tsbuildinfo\" \"packages/**/*.tsbuildinfo\" \"packages/!(webpack-cli)/lib/!(*.tpl)\" \"**/.yo-rc.json\"",
25+
"clean": "del-cli \"*.tsbuildinfo\" \"packages/**/*.tsbuildinfo\" \"packages/*/lib/!(*.tpl)\" \"**/.yo-rc.json\"",
2626
"prebuild": "yarn clean",
2727
"prebuild:ci": "yarn clean && node ./scripts/setupBuild.js",
2828
"build": "tsc --build",
@@ -54,6 +54,7 @@
5454
"@commitlint/config-conventional": "^16.0.0",
5555
"@types/jest": "^27.4.0",
5656
"@types/node": "^17.0.12",
57+
"@types/rechoir": "^0.6.1",
5758
"@typescript-eslint/eslint-plugin": "^5.10.1",
5859
"@typescript-eslint/parser": "^5.10.1",
5960
"@webpack-cli/migrate": "^1.1.2",

packages/configtest/src/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { IWebpackCLI } from "webpack-cli";
2+
13
const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
24

35
class ConfigTestCommand {
4-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
5-
async apply(cli: any): Promise<void> {
6+
async apply(cli: IWebpackCLI): Promise<void> {
67
await cli.makeCommand(
78
{
89
name: "configtest [config-path]",
@@ -19,15 +20,14 @@ class ConfigTestCommand {
1920
const configPaths = new Set<string>();
2021

2122
if (Array.isArray(config.options)) {
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
config.options.forEach((options: any) => {
23+
config.options.forEach((options) => {
2424
if (config.path.get(options)) {
25-
configPaths.add(config.path.get(options));
25+
configPaths.add(config.path.get(options) as string);
2626
}
2727
});
2828
} else {
2929
if (config.path.get(config.options)) {
30-
configPaths.add(config.path.get(config.options));
30+
configPaths.add(config.path.get(config.options) as string);
3131
}
3232
}
3333

@@ -39,14 +39,16 @@ class ConfigTestCommand {
3939
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`);
4040

4141
try {
42-
const error: Error[] = cli.webpack.validate(config.options);
42+
// @ts-expect-error cli.webpack.validate returns void
43+
const error: Error[] | undefined = cli.webpack.validate(config.options);
4344

4445
// TODO remove this after drop webpack@4
4546
if (error && error.length > 0) {
47+
// @ts-expect-error schema argument is missing
4648
throw new cli.webpack.WebpackOptionsValidationError(error);
4749
}
4850
} catch (error) {
49-
if (cli.isValidationError(error)) {
51+
if (cli.isValidationError(error as Error)) {
5052
cli.logger.error((error as Error).message);
5153
} else {
5254
cli.logger.error(error);

packages/configtest/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
"outDir": "./lib",
55
"rootDir": "./src"
66
},
7-
"include": ["./src"]
7+
"include": ["./src"],
8+
"references": [
9+
{
10+
"path": "../webpack-cli"
11+
}
12+
]
813
}

packages/generators/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import pluginGenerator from "./plugin-generator";
44
import addonGenerator from "./addon-generator";
55
import initGenerator from "./init-generator";
66
import type { InitOptions, LoaderOptions, PluginOptions } from "./types";
7+
import { IWebpackCLI } from "webpack-cli";
78

89
class GeneratorsCommand {
9-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
10-
async apply(cli: any): Promise<void> {
10+
async apply(cli: IWebpackCLI): Promise<void> {
1111
await cli.makeCommand(
1212
{
1313
name: "init [generation-path]",

packages/generators/src/types/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Generator from "yeoman-generator";
22
import path from "path";
3+
import { IWebpackCLI } from "webpack-cli";
34

45
export type InitOptions = { template: string; force?: boolean };
56
export type LoaderOptions = { template: string };
@@ -16,17 +17,15 @@ export type BaseCustomGeneratorOptions = {
1617
};
1718
export type CustomGeneratorOptions<T extends BaseCustomGeneratorOptions> =
1819
Generator.GeneratorOptions & {
19-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20-
cli: any;
20+
cli: IWebpackCLI;
2121
options: T;
2222
};
2323

2424
export class CustomGenerator<
2525
T extends BaseCustomGeneratorOptions = BaseCustomGeneratorOptions,
2626
Z extends CustomGeneratorOptions<T> = CustomGeneratorOptions<T>,
2727
> extends Generator<Z> {
28-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29-
public cli: any;
28+
public cli: IWebpackCLI;
3029
public template: string;
3130
public dependencies: string[];
3231
public force: boolean;

packages/generators/src/utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function getInstaller(this: CustomGenerator): Promise<string> {
3737
"packager",
3838
"Pick a package manager:",
3939
installers,
40-
defaultPackager,
40+
defaultPackager as string,
4141
this.force,
4242
);
4343
return packager;

packages/generators/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
"outDir": "lib",
66
"rootDir": "src"
77
},
8-
"include": ["src"]
8+
"include": ["src"],
9+
"references": [
10+
{
11+
"path": "../webpack-cli"
12+
}
13+
]
914
}

0 commit comments

Comments
 (0)