Skip to content

Commit

Permalink
fix(cli-plugin-service): correct inspect plugins in webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
front-end-captain committed Apr 28, 2021
1 parent 56409ac commit e836506
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
10 changes: 2 additions & 8 deletions packages/@luban/cli-plugin-service/src/commands/build.ts
Expand Up @@ -38,10 +38,7 @@ class Build {
}

private async buildClient() {
const webpackConfig = this.api.resolveWebpackConfig(
"client",
this.api.resolveChainableWebpackConfig("client"),
);
const webpackConfig = this.api.resolveWebpackConfig("client");

return new Promise<void>((resolve, reject) => {
if (!webpackConfig) {
Expand Down Expand Up @@ -79,10 +76,7 @@ class Build {
}

private async buildServer() {
const webpackConfig = this.api.resolveWebpackConfig(
"server",
this.api.resolveChainableWebpackConfig("server"),
);
const webpackConfig = this.api.resolveWebpackConfig("server");
return new Promise<void>((resolve, reject) => {
if (!webpackConfig) {
reject("server side webpack config unable resolved; command [build]");
Expand Down
19 changes: 11 additions & 8 deletions packages/@luban/cli-plugin-service/src/commands/inspect.ts
Expand Up @@ -12,6 +12,8 @@ import {
WebpackConfigName,
} from "../definitions";

type InspectResult = WebpackConfiguration | webpack.Plugin | webpack.RuleSetRule | string[];

const accessWebpackConfigName: Array<WebpackConfigName> = ["client", "server"];

export default class Inspect implements CommandPluginInstance<InspectCliArgs> {
Expand Down Expand Up @@ -46,13 +48,10 @@ export default class Inspect implements CommandPluginInstance<InspectCliArgs> {
throw new Error(`${name} side webpack config unable resolved; command [inspect]`);
}

// paths is webpack config key, eg. entry, plugins and module
const { _: paths } = args;

let res:
| WebpackConfiguration
| webpack.Plugin
| webpack.RuleSetRule
| string[] = webpackConfig;
let res: InspectResult = webpackConfig;

let hasUnnamedRule: boolean = false;

Expand All @@ -64,11 +63,14 @@ export default class Inspect implements CommandPluginInstance<InspectCliArgs> {

if (args.plugin) {
res = webpackConfig.plugins
? webpackConfig.plugins.find((p) => (p as any).__pluginName === args.plugin) || {}
? webpackConfig.plugins.find(
(p) => ((p as any).__pluginName || p.constructor.name) === args.plugin,
) || {}
: {};
}

if (args.rules) {
// string[]
res = webpackConfig.module
? webpackConfig.module.rules.map((r) => {
const name = (r as any).__ruleNames
Expand All @@ -79,13 +81,14 @@ export default class Inspect implements CommandPluginInstance<InspectCliArgs> {

return name;
})
: {};
: [];
}

if (args.plugins) {
// string[]
res = webpackConfig.plugins
? webpackConfig.plugins.map((p) => (p as any).__pluginName || p.constructor.name)
: {};
: [];
}

if (paths.length > 1) {
Expand Down
7 changes: 2 additions & 5 deletions packages/@luban/cli-plugin-service/src/lib/PluginAPI.ts
Expand Up @@ -72,11 +72,8 @@ class CommandPluginAPI extends PluginAPI {
return this.service.resolveChainableWebpackConfig(name);
}

public resolveWebpackConfig(
name: WebpackConfigName,
config?: Config,
): WebpackConfiguration | undefined {
return this.service.resolveWebpackConfig(name, config);
public resolveWebpackConfig(name: WebpackConfigName): WebpackConfiguration | undefined {
return this.service.resolveWebpackConfig(name);
}
}

Expand Down
7 changes: 3 additions & 4 deletions packages/@luban/cli-plugin-service/src/lib/Service.ts
Expand Up @@ -233,10 +233,9 @@ class Service {
return configQueue?.config;
}

public resolveWebpackConfig(
name: WebpackConfigName,
chainableConfig = this.resolveChainableWebpackConfig(name),
): WebpackConfiguration | undefined {
public resolveWebpackConfig(name: WebpackConfigName): WebpackConfiguration | undefined {
const chainableConfig = this.resolveChainableWebpackConfig(name);

if (chainableConfig) {
let config = chainableConfig.toConfig();

Expand Down

0 comments on commit e836506

Please sign in to comment.