From e49ea357b567c89226680cb272e4c8322cb091ca Mon Sep 17 00:00:00 2001 From: Ian Craig Date: Tue, 27 Oct 2020 15:45:25 -0700 Subject: [PATCH] When webpack config is specified, don't search for others, include path in warnings (#479) * When webpack config is specified, don't search for others, include path in warnings * Change files --- ...-2020-10-20-14-15-03-webpack-config-option-strict.json | 8 ++++++++ packages/just-scripts/src/tasks/webpackDevServerTask.ts | 7 ++++--- packages/just-scripts/src/tasks/webpackTask.ts | 6 +++--- packages/just-scripts/src/webpack/findWebpackConfig.ts | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 change/just-scripts-2020-10-20-14-15-03-webpack-config-option-strict.json diff --git a/change/just-scripts-2020-10-20-14-15-03-webpack-config-option-strict.json b/change/just-scripts-2020-10-20-14-15-03-webpack-config-option-strict.json new file mode 100644 index 00000000..ef2fc02c --- /dev/null +++ b/change/just-scripts-2020-10-20-14-15-03-webpack-config-option-strict.json @@ -0,0 +1,8 @@ +{ + "type": "patch", + "comment": "Error if explicit webpack config path does not exist", + "packageName": "just-scripts", + "email": "iancra@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-10-20T21:15:03.019Z" +} diff --git a/packages/just-scripts/src/tasks/webpackDevServerTask.ts b/packages/just-scripts/src/tasks/webpackDevServerTask.ts index 2845e761..28cf1fed 100644 --- a/packages/just-scripts/src/tasks/webpackDevServerTask.ts +++ b/packages/just-scripts/src/tasks/webpackDevServerTask.ts @@ -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'; @@ -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'); @@ -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(); } }; diff --git a/packages/just-scripts/src/tasks/webpackTask.ts b/packages/just-scripts/src/tasks/webpackTask.ts index 5abd4f9a..38c3a9e8 100644 --- a/packages/just-scripts/src/tasks/webpackTask.ts +++ b/packages/just-scripts/src/tasks/webpackTask.ts @@ -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'; @@ -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}`); @@ -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; diff --git a/packages/just-scripts/src/webpack/findWebpackConfig.ts b/packages/just-scripts/src/webpack/findWebpackConfig.ts index 7009c688..ce3c751f 100644 --- a/packages/just-scripts/src/webpack/findWebpackConfig.ts +++ b/packages/just-scripts/src/webpack/findWebpackConfig.ts @@ -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;