Skip to content

Commit

Permalink
When webpack config is specified, don't search for others, include pa…
Browse files Browse the repository at this point in the history
…th in warnings (#479)

* When webpack config is specified, don't search for others, include path in warnings

* Change files
  • Loading branch information
ian-craig authored Oct 27, 2020
1 parent 1f66390 commit e49ea35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Error if explicit webpack config path does not exist",
"packageName": "just-scripts",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-10-20T21:15:03.019Z"
}
7 changes: 4 additions & 3 deletions packages/just-scripts/src/tasks/webpackDevServerTask.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// // WARNING: Careful about add more imports - only import types from webpack
import { Configuration } from 'webpack';
import { encodeArgs, spawn } from 'just-scripts-utils';
import { logger, resolve } from 'just-task';
import { logger, resolve, resolveCwd } from 'just-task';
import * as fs from 'fs';
import * as path from 'path';
import { WebpackCliTaskOptions } from './webpackCliTask';
import { getTsNodeEnv } from '../typescript/getTsNodeEnv';
import { findWebpackConfig } from '../webpack/findWebpackConfig';
Expand Down Expand Up @@ -46,7 +47,7 @@ export interface WebpackDevServerTaskOptions extends WebpackCliTaskOptions, Conf
}

export function webpackDevServerTask(options: WebpackDevServerTaskOptions = {}) {
let configPath = findWebpackConfig('webpack.serve.config.js', options && options.config);
let configPath = options && options.config ? resolveCwd(path.join('.', options.config)) : findWebpackConfig('webpack.serve.config.js');

const devServerCmd = resolve('webpack-dev-server/bin/webpack-dev-server.js');

Expand All @@ -68,7 +69,7 @@ export function webpackDevServerTask(options: WebpackDevServerTaskOptions = {})
logger.info(process.execPath, encodeArgs(args).join(' '));
return spawn(process.execPath, args, { stdio: 'inherit', env: options.env });
} else {
logger.warn('no webpack.serve.config.js (or .ts) configuration found, skipping');
logger.warn(`${options?.config || 'webpack.serve.config.js'} not found, skipping`);
return Promise.resolve();
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/just-scripts/src/tasks/webpackTask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// // WARNING: Careful about add more imports - only import types from webpack
import { Configuration } from 'webpack';
import { logger, argv, TaskFunction } from 'just-task';
import { logger, argv, TaskFunction, resolveCwd } from 'just-task';
import { tryRequire } from '../tryRequire';
import * as fs from 'fs';
import * as path from 'path';
Expand Down Expand Up @@ -41,7 +41,7 @@ export function webpackTask(options?: WebpackTaskOptions): TaskFunction {

logger.info(`Running Webpack`);

let webpackConfigPath = findWebpackConfig('webpack.config.js', options && options.config);
let webpackConfigPath = options && options.config ? resolveCwd(path.join('.', options.config)) : findWebpackConfig('webpack.config.js');

logger.info(`Webpack Config Path: ${webpackConfigPath}`);

Expand Down Expand Up @@ -107,7 +107,7 @@ export function webpackTask(options?: WebpackTaskOptions): TaskFunction {
});
});
} else {
logger.info('webpack.config.js not found, skipping webpack');
logger.info(`${options?.config || 'webpack.config.js'} not found, skipping webpack`);
}

return;
Expand Down
4 changes: 2 additions & 2 deletions packages/just-scripts/src/webpack/findWebpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { resolveCwd } from 'just-task';
import * as path from 'path';

export function findWebpackConfig(target: string, config?: string) {
export function findWebpackConfig(target: string) {
let configPath: string = target;

const haystackConfigPaths = [config, target, target.replace(/\.js$/, '.ts')];
const haystackConfigPaths = [target, target.replace(/\.js$/, '.ts')];
for (const needle of haystackConfigPaths) {
if (needle && resolveCwd(path.join('.', needle))) {
configPath = needle;
Expand Down

0 comments on commit e49ea35

Please sign in to comment.