diff options
Diffstat (limited to 'node_modules/postcss-message-helpers')
| -rwxr-xr-x | node_modules/postcss-message-helpers/CHANGELOG.md | 17 | ||||
| -rwxr-xr-x | node_modules/postcss-message-helpers/LICENSE | 20 | ||||
| -rwxr-xr-x | node_modules/postcss-message-helpers/README.md | 80 | ||||
| -rwxr-xr-x | node_modules/postcss-message-helpers/index.js | 81 | ||||
| -rw-r--r-- | node_modules/postcss-message-helpers/package.json | 34 |
5 files changed, 232 insertions, 0 deletions
diff --git a/node_modules/postcss-message-helpers/CHANGELOG.md b/node_modules/postcss-message-helpers/CHANGELOG.md new file mode 100755 index 00000000..9f518ee8 --- /dev/null +++ b/node_modules/postcss-message-helpers/CHANGELOG.md @@ -0,0 +1,17 @@ +# 2.0.0 - 2014-01-26 + +- Added: compatibility with postcss v4.x +- Removed: compability with postcss v3.x + +# 1.1.1 - 2014-11-24 + +- Fixed: issue with multilines error message in stack trace +- Added: `originalMessage` property in the exception + +# 1.1.0 - 2014-11-24 + +- Added: `try` now returns the result of the callback + +# 1.0.0 - 2014-11-24 + +✨ First release diff --git a/node_modules/postcss-message-helpers/LICENSE b/node_modules/postcss-message-helpers/LICENSE new file mode 100755 index 00000000..8b39b8f1 --- /dev/null +++ b/node_modules/postcss-message-helpers/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 Maxime Thirouin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/postcss-message-helpers/README.md b/node_modules/postcss-message-helpers/README.md new file mode 100755 index 00000000..8c961567 --- /dev/null +++ b/node_modules/postcss-message-helpers/README.md @@ -0,0 +1,80 @@ +# postcss-message-helpers [](https://travis-ci.org/MoOx/postcss-message-helpers) + +> [PostCSS](https://github.com/postcss/postcss) helpers to throw or output GNU style messages. + +This modules offers you some function to throw or just output messages with [GNU style](https://www.gnu.org/prep/standards/html_node/Errors.html): `sourcefile:lineno:column: message` + +## Installation + +```console +$ npm install postcss-message-helpers +``` + +```js +var messageHelpers = require("postcss-message-helpers") +``` + +## Usage + +### `var fnValue = messageHelpers.try(fn, source)` + +Execute `fn` an return the value. +If an exception is thrown during the process, the exception will be catched, enhanced from source & re-throw. + +### `var sourceMessage = messageHelpers.message(message, source)` + +Returns a message like `sourcefile:lineno:column: message`. +`source` should be a postcss source object from a node. + +### `var source = messageHelpers.source(source)` + +Returns `sourcefile:lineno:column` for a given `source` postcss object. + +### Example + +```js +// dependencies +var fs = require("fs") +var postcss = require("postcss") +var messageHelpers = require("postcss-message-helpers") + +// css to be processed +var css = fs.readFileSync("input.css", "utf8") + +// process css +var output = postcss() + .use(function(styles) { + styles.eachDecl(function transformDecl(decl) { + // will catch, adjust error stack, line, column & message (gnu style) then re-throw + messageHelpers.try(function IwillThrow() { + if (decl.value.indexOf("error(") > -1) { + throw new Error("error detected: " + decl.value) + } + }, decl.source) + + // will output a gnu style warning + if (decl.value.indexOf("warning(") > -1) { + console.warning(messageHelpers.message("warning: " + decl.value, decl.source)) + } + }) + }) + .process(css) + .css +``` + +Checkout [tests](test) for more examples. + +--- + +## Contributing + +Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature. + + $ git clone https://github.com/MoOx/postcss-message-helpers.git + $ git checkout -b patch-1 + $ npm install + $ npm test + +## [Changelog](CHANGELOG.md) + +## [License](LICENSE) diff --git a/node_modules/postcss-message-helpers/index.js b/node_modules/postcss-message-helpers/index.js new file mode 100755 index 00000000..e57cc29f --- /dev/null +++ b/node_modules/postcss-message-helpers/index.js @@ -0,0 +1,81 @@ +/** + * Constants + */ +var SPLITTER = "\n at " + +/** + * PostCSS helpers + */ +module.exports = { + sourceString: sourceString, + message: formatMessage, + try: tryCatch +} + +/** + * Returns GNU style source + * + * @param {Object} source + */ +function sourceString(source) { + var message = "<css input>" + if (source) { + if (source.input && source.input.file) { + message = source.input.file + } + if (source.start) { + message += ":" + source.start.line + ":" + source.start.column + } + } + + return message +} + +/** + * Returns a GNU style message + * + * @param {String} message + * @param {Object} source a PostCSS source object + * @return {String} + */ +function formatMessage(message, source) { + return sourceString(source) + ": " + message +} + +/** + * Do something and throw an error with enhanced exception (from given source) + * + * @param {Function} fn [description] + * @param {[type]} source [description] + */ +function tryCatch(fn, source) { + try { + return fn() + } + catch (err) { + err.originalMessage = err.message + err.message = formatMessage(err.message, source) + + // if source seems interesting, enhance error + if (typeof source === "object") { + // add a stack item if something interesting available + if ((source.input && source.input.file) || source.start) { + var stack = err.stack.split(SPLITTER) + var firstStackItem = stack.shift() + stack.unshift(sourceString(source)) + stack.unshift(firstStackItem) + err.stack = stack.join(SPLITTER) + } + + if (source.input && source.input.file) { + err.fileName = source.input.file + } + if (source.start) { + err.lineNumber = source.start.line + err.columnNumber = source.start.column + } + } + + throw err + } +} diff --git a/node_modules/postcss-message-helpers/package.json b/node_modules/postcss-message-helpers/package.json new file mode 100644 index 00000000..a18a6379 --- /dev/null +++ b/node_modules/postcss-message-helpers/package.json @@ -0,0 +1,34 @@ +{ + "name": "postcss-message-helpers", + "version": "2.0.0", + "description": "PostCSS helpers to throw or output GNU style messages", + "keywords": [ + "css", + "postcss", + "postcss-plugins", + "messages", + "error", + "warning" + ], + "author": "Maxime Thirouin", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/MoOx/postcss-message-helpers.git" + }, + "files": [ + "CHANGELOG.md", + "LICENSE", + "index.js" + ], + "devDependencies": { + "jscs": "^1.6.2", + "jshint": "^2.5.6", + "postcss": "^4.0.2", + "tape": "^3.0.0" + }, + "scripts": { + "lint": "jscs *.js **/*.js && jshint . --exclude-path .gitignore", + "test": "npm run lint && tape test" + } +} |
