Merge pull request #39 from iclanton/fix-webpack-error-formatting
Fix an issue with webpack error printing.
This commit is contained in:
Коммит
1df6f05699
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@microsoft/gulp-core-build-webpack",
|
||||
"comment": "Fix an issue where webpack errors were printed as `[object Object]`.",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@microsoft/gulp-core-build-webpack"
|
||||
}
|
|
@ -10,6 +10,9 @@
|
|||
// node common/scripts/install-run-rush-pnpm.js pnpm-command
|
||||
//
|
||||
// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
||||
// See the @microsoft/rush package's LICENSE file for details.
|
||||
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
// node common/scripts/install-run-rush.js install
|
||||
//
|
||||
// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
||||
// See the @microsoft/rush package's LICENSE file for details.
|
||||
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
// node common/scripts/install-run-rushx.js custom-command
|
||||
//
|
||||
// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
||||
// See the @microsoft/rush package's LICENSE file for details.
|
||||
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
// node common/scripts/install-run.js qrcode@1.2.2 qrcode https://rushjs.io
|
||||
//
|
||||
// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
||||
// See the @microsoft/rush package's LICENSE file for details.
|
||||
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
|
@ -338,7 +341,7 @@ let _npmPath = undefined;
|
|||
function getNpmPath() {
|
||||
if (!_npmPath) {
|
||||
try {
|
||||
if (os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32') {
|
||||
if (_isWindows()) {
|
||||
// We're on Windows
|
||||
const whereOutput = child_process__WEBPACK_IMPORTED_MODULE_0__.execSync('where npm', { stdio: [] }).toString();
|
||||
const lines = whereOutput.split(os__WEBPACK_IMPORTED_MODULE_2__.EOL).filter((line) => !!line);
|
||||
|
@ -457,10 +460,13 @@ function _resolvePackageVersion(logger, rushCommonFolder, { name, version }) {
|
|||
// ```
|
||||
//
|
||||
// if only a single version matches.
|
||||
const npmVersionSpawnResult = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(npmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier', '--json'], {
|
||||
const spawnSyncOptions = {
|
||||
cwd: rushTempFolder,
|
||||
stdio: []
|
||||
});
|
||||
stdio: [],
|
||||
shell: _isWindows()
|
||||
};
|
||||
const platformNpmPath = _getPlatformPath(npmPath);
|
||||
const npmVersionSpawnResult = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier', '--json'], spawnSyncOptions);
|
||||
if (npmVersionSpawnResult.status !== 0) {
|
||||
throw new Error(`"npm view" returned error code ${npmVersionSpawnResult.status}`);
|
||||
}
|
||||
|
@ -593,10 +599,12 @@ function _installPackage(logger, packageInstallFolder, name, version, command) {
|
|||
try {
|
||||
logger.info(`Installing ${name}...`);
|
||||
const npmPath = getNpmPath();
|
||||
const result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(npmPath, [command], {
|
||||
const platformNpmPath = _getPlatformPath(npmPath);
|
||||
const result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, [command], {
|
||||
stdio: 'inherit',
|
||||
cwd: packageInstallFolder,
|
||||
env: process.env
|
||||
env: process.env,
|
||||
shell: _isWindows()
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`"npm ${command}" encountered an error`);
|
||||
|
@ -612,9 +620,18 @@ function _installPackage(logger, packageInstallFolder, name, version, command) {
|
|||
*/
|
||||
function _getBinPath(packageInstallFolder, binName) {
|
||||
const binFolderPath = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME, '.bin');
|
||||
const resolvedBinName = os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32' ? `${binName}.cmd` : binName;
|
||||
const resolvedBinName = _isWindows() ? `${binName}.cmd` : binName;
|
||||
return path__WEBPACK_IMPORTED_MODULE_3__.resolve(binFolderPath, resolvedBinName);
|
||||
}
|
||||
/**
|
||||
* Returns a cross-platform path - windows must enclose any path containing spaces within double quotes.
|
||||
*/
|
||||
function _getPlatformPath(platformPath) {
|
||||
return _isWindows() && platformPath.includes(' ') ? `"${platformPath}"` : platformPath;
|
||||
}
|
||||
function _isWindows() {
|
||||
return os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32';
|
||||
}
|
||||
/**
|
||||
* Write a flag file to the package's install directory, signifying that the install was successful.
|
||||
*/
|
||||
|
@ -656,15 +673,14 @@ function installAndRun(logger, packageName, packageVersion, packageBinName, pack
|
|||
const originalEnvPath = process.env.PATH || '';
|
||||
let result;
|
||||
try {
|
||||
// Node.js on Windows can not spawn a file when the path has a space on it
|
||||
// unless the path gets wrapped in a cmd friendly way and shell mode is used
|
||||
const shouldUseShell = binPath.includes(' ') && os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32';
|
||||
const platformBinPath = shouldUseShell ? `"${binPath}"` : binPath;
|
||||
// `npm` bin stubs on Windows are `.cmd` files
|
||||
// Node.js will not directly invoke a `.cmd` file unless `shell` is set to `true`
|
||||
const platformBinPath = _getPlatformPath(binPath);
|
||||
process.env.PATH = [binFolderPath, originalEnvPath].join(path__WEBPACK_IMPORTED_MODULE_3__.delimiter);
|
||||
result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformBinPath, packageBinArgs, {
|
||||
stdio: 'inherit',
|
||||
windowsVerbatimArguments: false,
|
||||
shell: shouldUseShell,
|
||||
shell: _isWindows(),
|
||||
cwd: process.cwd(),
|
||||
env: process.env
|
||||
});
|
||||
|
|
|
@ -46,6 +46,24 @@ export interface IWebpackResources {
|
|||
webpack: typeof Webpack;
|
||||
}
|
||||
|
||||
function normalizeWebpackError(error: Webpack.StatsError): string {
|
||||
if (typeof error === 'string') {
|
||||
return error;
|
||||
} else {
|
||||
const { loc, moduleName, moduleIdentifier } = error;
|
||||
const modulePath: string | undefined = moduleName ?? moduleIdentifier;
|
||||
if (modulePath) {
|
||||
if (loc) {
|
||||
return `${modulePath}:${loc}: ${error.message}`;
|
||||
} else {
|
||||
return `${modulePath}: ${error.message}`;
|
||||
}
|
||||
} else {
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
@ -141,7 +159,12 @@ export class WebpackTask<TExtendedConfig = {}> extends GulpTask<IWebpackTaskConf
|
|||
|
||||
if (statsResult) {
|
||||
if (statsResult.errors && statsResult.errors.length) {
|
||||
this.logError(`'${outputDir}':` + EOL + statsResult.errors.join(EOL) + EOL);
|
||||
const errorTexts: string[] = [];
|
||||
for (const error of statsResult.errors) {
|
||||
errorTexts.push(normalizeWebpackError(error));
|
||||
}
|
||||
|
||||
this.logError(`'${outputDir}':` + EOL + errorTexts.join(EOL) + EOL);
|
||||
}
|
||||
|
||||
if (statsResult.warnings && statsResult.warnings.length) {
|
||||
|
@ -168,18 +191,12 @@ export class WebpackTask<TExtendedConfig = {}> extends GulpTask<IWebpackTaskConf
|
|||
}
|
||||
|
||||
if (unsuppressedWarnings.length > 0) {
|
||||
this.logWarning(
|
||||
`'${outputDir}':` +
|
||||
EOL +
|
||||
unsuppressedWarnings
|
||||
.map(
|
||||
(unsuppressedWarning) =>
|
||||
(unsuppressedWarning.loc ? `${unsuppressedWarning.loc}: ` : '') +
|
||||
unsuppressedWarning.message
|
||||
)
|
||||
.join(EOL) +
|
||||
EOL
|
||||
);
|
||||
const warningTexts: string[] = [];
|
||||
for (const warning of unsuppressedWarnings) {
|
||||
warningTexts.push(normalizeWebpackError(warning));
|
||||
}
|
||||
|
||||
this.logWarning(`'${outputDir}':` + EOL + warningTexts.join(EOL) + EOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* path segment in the "$schema" field for all your Rush config files. This will ensure
|
||||
* correct error-underlining and tab-completion for editors such as VS Code.
|
||||
*/
|
||||
"rushVersion": "5.118.4",
|
||||
"rushVersion": "5.133.4",
|
||||
|
||||
/**
|
||||
* The next field selects which package manager should be installed and determines its version.
|
||||
|
|
Загрузка…
Ссылка в новой задаче