@poi/dev-utils
Advanced tools
Comparing version 10.0.0 to 10.0.1
@@ -10,3 +10,3 @@ /* eslint-disable */ | ||
'use strict' | ||
'use strict'; | ||
@@ -20,8 +20,8 @@ // WARNING: this code is untranspiled and is used in browser too. | ||
const chalk = require('chalk') | ||
var chalk = require('chalk'); | ||
const friendlySyntaxErrorLabel = 'Syntax error:' | ||
var friendlySyntaxErrorLabel = 'Syntax error:'; | ||
function isLikelyASyntaxError(message) { | ||
return message.indexOf(friendlySyntaxErrorLabel) !== -1 | ||
return message.indexOf(friendlySyntaxErrorLabel) !== -1; | ||
} | ||
@@ -32,7 +32,7 @@ | ||
function formatMessage(message, isError) { | ||
let lines = message.split('\n') | ||
var lines = message.split('\n'); | ||
if (lines.length > 2 && lines[1] === '') { | ||
// Remove extra newline. | ||
lines.splice(1, 1) | ||
lines.splice(1, 1); | ||
} | ||
@@ -46,6 +46,6 @@ | ||
if (lines[0].lastIndexOf('!') !== -1) { | ||
lines[0] = lines[0].substr(lines[0].lastIndexOf('!') + 1) | ||
lines[0] = lines[0].substr(lines[0].lastIndexOf('!') + 1); | ||
} | ||
lines = lines.filter(line => { | ||
lines = lines.filter(function (line) { | ||
// Webpack adds a list of entry points to warning messages: | ||
@@ -56,4 +56,4 @@ // @ ./src/index.js | ||
// It is only useful for syntax errors but we have beautiful frames for them. | ||
return line.indexOf(' @ ') !== 0 | ||
}) | ||
return line.indexOf(' @ ') !== 0; | ||
}); | ||
@@ -63,3 +63,3 @@ // line #0 is filename | ||
if (!lines[0] || !lines[1]) { | ||
return lines.join('\n') | ||
return lines.join('\n'); | ||
} | ||
@@ -69,11 +69,5 @@ | ||
if (lines[1].indexOf('Module not found: ') === 0) { | ||
lines = [ | ||
lines[0], | ||
// Clean up message because "Module not found: " is descriptive enough. | ||
lines[1] | ||
.replace('Cannot resolve \'file\' or \'directory\' ', '') | ||
.replace('Cannot resolve module ', '') | ||
.replace('Error: ', '') | ||
.replace('[CaseSensitivePathsPlugin] ', '') | ||
] | ||
lines = [lines[0], | ||
// Clean up message because "Module not found: " is descriptive enough. | ||
lines[1].replace('Cannot resolve \'file\' or \'directory\' ', '').replace('Cannot resolve module ', '').replace('Error: ', '').replace('[CaseSensitivePathsPlugin] ', '')]; | ||
} | ||
@@ -83,6 +77,3 @@ | ||
if (lines[1].indexOf('Module build failed: ') === 0) { | ||
lines[1] = lines[1].replace( | ||
'Module build failed: SyntaxError:', | ||
friendlySyntaxErrorLabel | ||
) | ||
lines[1] = lines[1].replace('Module build failed: SyntaxError:', friendlySyntaxErrorLabel); | ||
} | ||
@@ -92,14 +83,11 @@ | ||
// TODO: we should really send a PR to Webpack for this. | ||
const exportError = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/ | ||
var exportError = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/; | ||
if (lines[1].match(exportError)) { | ||
lines[1] = lines[1].replace( | ||
exportError, | ||
'$1 \'$4\' does not contain an export named \'$3\'.' | ||
) | ||
lines[1] = lines[1].replace(exportError, '$1 \'$4\' does not contain an export named \'$3\'.'); | ||
} | ||
lines[0] = chalk.inverse(lines[0]) | ||
lines[0] = chalk.inverse(lines[0]); | ||
// Reassemble the message. | ||
message = lines.join('\n') | ||
message = lines.join('\n'); | ||
// Internal stacks are generally useless so we strip them... with the | ||
@@ -109,21 +97,18 @@ // exception of stacks containing `webpack:` because they're normally | ||
// https://github.com/facebookincubator/create-react-app/pull/1050 | ||
message = message.replace( | ||
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, | ||
'' | ||
) // at ... ...:x:y | ||
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y | ||
return message.trim() | ||
return message.trim(); | ||
} | ||
function formatWebpackMessages(json) { | ||
const formattedErrors = json.errors.map(message => { | ||
return formatMessage(message, true) | ||
}) | ||
const formattedWarnings = json.warnings.map(message => { | ||
return formatMessage(message, false) | ||
}) | ||
const result = { | ||
var formattedErrors = json.errors.map(function (message) { | ||
return formatMessage(message, true); | ||
}); | ||
var formattedWarnings = json.warnings.map(function (message) { | ||
return formatMessage(message, false); | ||
}); | ||
var result = { | ||
errors: formattedErrors, | ||
warnings: formattedWarnings | ||
} | ||
}; | ||
if (result.errors.some(isLikelyASyntaxError)) { | ||
@@ -133,7 +118,7 @@ // If there are any syntax errors, show just them. | ||
// preceding a much more useful Babel syntax error. | ||
result.errors = result.errors.filter(isLikelyASyntaxError) | ||
result.errors = result.errors.filter(isLikelyASyntaxError); | ||
} | ||
return result | ||
return result; | ||
} | ||
module.exports = formatWebpackMessages | ||
module.exports = formatWebpackMessages; |
{ | ||
"name": "@poi/dev-utils", | ||
"version": "10.0.0", | ||
"version": "10.0.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13437
365
2