Skip to content

Commit

Permalink
chore: use bundt to build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jul 21, 2021
1 parent d3843bd commit 5591b98
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
node_modules
.DS_Store
*-lock.*
*.lock
*.log

/index.mjs
/index.js
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"name": "webpack-format-messages",
"repository": "lukeed/webpack-format-messages",
"description": "Beautiful formatting for Webpack messages; ported from Create React App!",
"module": "index.mjs",
"main": "index.js",
"license": "MIT",
"author": {
"name": "Luke Edwards",
Expand All @@ -13,11 +15,18 @@
"node": ">=6"
},
"files": [
"index.js"
"index.js",
"index.mjs"
],
"scripts": {
"build": "bundt"
},
"dependencies": {
"kleur": "^4.0.0"
},
"devDependencies": {
"bundt": "1.1.5"
},
"keywords": [
"create-react-app",
"console",
Expand Down
12 changes: 6 additions & 6 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* see: https://github.com/facebookincubator/create-react-app/tree/master/packages/react-dev-utils
*/

const { inverse } = require('kleur/colors');
import { inverse } from 'kleur/colors';

const errorLabel = 'Syntax error:';
const isLikelyASyntaxError = str => str.includes(errorLabel);

const exportRegex = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/;
const stackRegex = /^\s*at\s((?!webpack:).)*:\d+:\d+[\s\)]*(\n|$)/gm;

function formatMessage(message, isError) {
function format(message, isError) {
// Workaround to accommodate Webpack v5
// It gives us an Object now, not a string...
// Objects not identical; details > stack > message
Expand Down Expand Up @@ -66,12 +66,12 @@ function formatMessage(message, isError) {
return lines.join('\n').replace(stackRegex, '').trim();
}

module.exports = function (stats) {
export function formatMessage(stats) {
const json = stats.toJson({}, true);

const result = {
errors: json.errors.map(msg => formatMessage(msg, true)),
warnings: json.warnings.map(msg => formatMessage(msg, false))
errors: json.errors.map(msg => format(msg, true)),
warnings: json.warnings.map(msg => format(msg, false))
};

// Only show syntax errors if we have them
Expand All @@ -87,4 +87,4 @@ module.exports = function (stats) {
return result;
};

module.exports.formatMessage = formatMessage;
export default formatMessage;

0 comments on commit 5591b98

Please sign in to comment.