Skip to content

Commit a2bd00a

Browse files
committed
feat: implement new configtest command
1 parent d34dfb7 commit a2bd00a

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

packages/configtest/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@webpack-cli/configtest",
3+
"version": "1.2.1",
4+
"description": "Test your webpack configuration",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"license": "MIT",
8+
"publishConfig": {
9+
"access": "public"
10+
},
11+
"files": [
12+
"lib"
13+
],
14+
"peerDependencies": {
15+
"webpack": "4.x.x || 5.x.x",
16+
"webpack-cli": "4.x.x"
17+
}
18+
}

packages/configtest/src/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { validate } from 'webpack';
2+
3+
class ConfigTestCommand {
4+
async apply(cli): Promise<void> {
5+
const { logger } = cli;
6+
7+
await cli.makeCommand(
8+
{
9+
name: 'configtest',
10+
alias: 't',
11+
description: 'Outputs information about your system.',
12+
usage: '[configs]',
13+
pkg: '@webpack-cli/configtest',
14+
},
15+
[],
16+
async (program) => {
17+
const { options } = await cli.resolveConfig({ config: program.args });
18+
//eslint-disable-next-line @typescript-eslint/no-explicit-any
19+
const validationErrors: any = validate(options);
20+
21+
if (validationErrors) {
22+
logger.error("Your configuration validation wasn't successful");
23+
logger.error(validationErrors);
24+
}
25+
26+
logger.success('No errors found');
27+
},
28+
);
29+
}
30+
}
31+
32+
export default ConfigTestCommand;

packages/configtest/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./src"
6+
},
7+
"include": ["./src"]
8+
}

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ class WebpackCLI {
279279
alias: 'm',
280280
pkg: '@webpack-cli/migrate',
281281
},
282+
{
283+
name: 'configtest',
284+
alias: 't',
285+
pkg: '@webpack-cli/configtest',
286+
},
282287
];
283288

284289
const knownCommands = [bundleCommandOptions, versionCommandOptions, helpCommandOptions, ...externalBuiltInCommandsInfo];

tsconfig.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@
2020
"declaration": true
2121
},
2222
"references": [
23-
{ "path": "packages/generators" },
24-
{ "path": "packages/info" },
25-
{ "path": "packages/init" },
26-
{ "path": "packages/migrate" },
27-
{ "path": "packages/serve" },
28-
{ "path": "packages/utils" }
23+
{
24+
"path": "packages/generators"
25+
},
26+
{
27+
"path": "packages/info"
28+
},
29+
{
30+
"path": "packages/init"
31+
},
32+
{
33+
"path": "packages/migrate"
34+
},
35+
{
36+
"path": "packages/serve"
37+
},
38+
{
39+
"path": "packages/utils"
40+
},
41+
{
42+
"path": "packages/configtest"
43+
}
2944
]
3045
}

0 commit comments

Comments
 (0)