From 58e99961108aaea62b529eb6a16cef785dbe1c80 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sat, 14 Oct 2017 16:02:46 +0200 Subject: [PATCH 1/5] fix(schema): allow to pass an `{Object}` (`options.syntax/options.stringifier`) (#300) --- lib/options.json | 4 ++-- test/loader.test.js | 1 - test/options/__snapshots__/parser.test.js.snap | 2 +- test/options/__snapshots__/stringifier.test.js.snap | 2 ++ test/options/__snapshots__/syntax.test.js.snap | 2 ++ test/options/parser.test.js | 2 +- test/options/stringifier.test.js | 4 ++-- test/options/syntax.test.js | 4 ++-- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/options.json b/lib/options.json index 26bd708b..dd5f23c0 100644 --- a/lib/options.json +++ b/lib/options.json @@ -20,10 +20,10 @@ "type": [ "string", "object" ] }, "syntax": { - "type": "string" + "type": [ "string", "object" ] }, "stringifier": { - "type": "string" + "type": [ "string", "object" ] }, "sourceMap": { "type": [ "string", "boolean" ] diff --git a/test/loader.test.js b/test/loader.test.js index f8bc11c7..57e8ffcd 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -5,7 +5,6 @@ const { loader } = require('./helpers/compilation') describe('Loader', () => { test('Default', () => { - const _ = /style\.(exec\.js|js)$/ const config = { loader: { options: { diff --git a/test/options/__snapshots__/parser.test.js.snap b/test/options/__snapshots__/parser.test.js.snap index 67b13b7b..a9786e06 100644 --- a/test/options/__snapshots__/parser.test.js.snap +++ b/test/options/__snapshots__/parser.test.js.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Options Parser - {Function} 1`] = `"module.exports = \\"a {\\\\n color: black\\\\n}\\\\n\\""`; +exports[`Options Parser - {Object} 1`] = `"module.exports = \\"a {\\\\n color: black\\\\n}\\\\n\\""`; exports[`Options Parser - {String} 1`] = `"module.exports = \\"a {\\\\n color: black\\\\n}\\\\n\\""`; diff --git a/test/options/__snapshots__/stringifier.test.js.snap b/test/options/__snapshots__/stringifier.test.js.snap index 33c5e7db..3491b37d 100644 --- a/test/options/__snapshots__/stringifier.test.js.snap +++ b/test/options/__snapshots__/stringifier.test.js.snap @@ -1,3 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Stringifier - {Object} 1`] = `"module.exports = \\"a color: black\\\\n\\""`; + exports[`Options Stringifier - {String} 1`] = `"module.exports = \\"a color: black\\\\n\\""`; diff --git a/test/options/__snapshots__/syntax.test.js.snap b/test/options/__snapshots__/syntax.test.js.snap index 4c811493..87e4d50c 100644 --- a/test/options/__snapshots__/syntax.test.js.snap +++ b/test/options/__snapshots__/syntax.test.js.snap @@ -1,3 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Syntax - {Object} 1`] = `"module.exports = \\"a\\\\n color: black\\\\n\\""`; + exports[`Options Syntax - {String} 1`] = `"module.exports = \\"a\\\\n color: black\\\\n\\""`; diff --git a/test/options/parser.test.js b/test/options/parser.test.js index 8d052c2a..7c4bde78 100644 --- a/test/options/parser.test.js +++ b/test/options/parser.test.js @@ -21,7 +21,7 @@ describe('Options', () => { }) }) - test('Parser - {Function}', () => { + test('Parser - {Object}', () => { const config = { loader: { options: { diff --git a/test/options/stringifier.test.js b/test/options/stringifier.test.js index 3b2188d7..f4f450be 100644 --- a/test/options/stringifier.test.js +++ b/test/options/stringifier.test.js @@ -20,8 +20,8 @@ describe('Options', () => { expect(src).toMatchSnapshot() }) }) - // TODO fix schema - test.skip('Stringifier - {Function}', () => { + + test('Stringifier - {Object}', () => { const config = { loader: { options: { diff --git a/test/options/syntax.test.js b/test/options/syntax.test.js index 94decbe0..597c58c5 100644 --- a/test/options/syntax.test.js +++ b/test/options/syntax.test.js @@ -20,8 +20,8 @@ describe('Options', () => { expect(src).toMatchSnapshot() }) }) - // TODO fix schema - test.skip('Syntax - {Function}', () => { + + test('Syntax - {Object}', () => { const config = { loader: { options: { From d39b84e95dc128ecb2f3b1dfdc1284088452cf51 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sat, 14 Oct 2017 17:40:51 +0200 Subject: [PATCH 2/5] docs(README): add `option` types && links (#303) --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 57301f27..9e83df49 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ npm i -D postcss-loader

Usage

-### `Config` +### `Configuration` **postcss.config.js** ```js @@ -108,15 +108,15 @@ module.exports = {

Options

-|Name|Default|Description| -|:--:|:-----:|:----------| -|`exec`|`undefined`|Enable PostCSS Parser support in `CSS-in-JS`| -|`parser`|`undefined`|Set PostCSS Parser| -|`syntax`|`undefined`|Set PostCSS Syntax| -|`stringifier`|`undefined`|Set PostCSS Stringifier| -|`config`|`undefined`|Set `postcss.config.js` config path && `ctx`| -|`plugins`|`[]`|Set PostCSS Plugins| -|`sourceMap`|`false`|Enable Source Maps| +|Name|Type|Default|Description| +|:--:|:--:|:-----:|:----------| +|[`exec`](#exec)|`{Boolean}`|`undefined`|Enable PostCSS Parser support in `CSS-in-JS`| +|[`parser`](#syntaxes)|`{String\|Object}`|`undefined`|Set PostCSS Parser| +|[`syntax`](#syntaxes)|`{String\|Object}`|`undefined`|Set PostCSS Syntax| +|[`stringifier`](#syntaxes)|`{String\|Object}`|`undefined`|Set PostCSS Stringifier| +|[`config`](#config)|`{Object}`|`undefined`|Set `postcss.config.js` config path && `ctx`| +|[`plugins`](#plugins)|`{Array\|Function}`|`[]`|Set PostCSS Plugins| +|[`sourceMap`](#sourceMap)|`{String\|Boolean}`|`false`|Enable Source Maps| ### `Exec` @@ -135,6 +135,11 @@ If you use JS styles without the [`postcss-js`][postcss-js] parser, add the `exe ### `Config` +|Name|Type|Default|Description| +|:--:|:--:|:-----:|:----------| +|[`path`](#path)|`{String}`|`undefined`|PostCSS Config Path| +|[`context`](#context)|`{Object}`|`undefined`|PostCSS Config Context| + #### `Path` You can manually specify the path to search for your config (`postcss.config.js`) with the `config.path` option. This is needed if you store your config in a separate e.g `./config || ./.config` folder. @@ -216,9 +221,9 @@ module.exports = ({ file, options, env }) => ({ |Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| -|`syntax`|`{String\|Function}`|`undefined`|Custom PostCSS Syntax| -|`parser`|`{String\|Function}`|`undefined`|Custom PostCSS Parser| -|`stringifier`|`{String\|Function}`|`undefined`|Custom PostCSS Stringifier| +|[`parser`](#parser)|`{String\|Function}`|`undefined`|Custom PostCSS Parser| +|[`syntax`](#syntax)|`{String\|Function}`|`undefined`|Custom PostCSS Syntax| +|[`stringifier`](#stringifier)|`{String\|Function}`|`undefined`|Custom PostCSS Stringifier| #### `Parser` From e7e547864813a93c06713ca1f8dbf0397766c60a Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sat, 14 Oct 2017 17:50:29 +0200 Subject: [PATCH 3/5] refactor(lib/Error): remove unused branches (#302) --- lib/Error.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/Error.js b/lib/Error.js index 37247d7c..05ea46ea 100644 --- a/lib/Error.js +++ b/lib/Error.js @@ -4,18 +4,11 @@ class SyntaxError extends Error { constructor (err) { super(err) - this.err = err.input.source - this.name = 'Syntax Error' - this.message = '' - if (err.line) { - this.message += `${this.name} \n\n(${err.line}:${err.column}) ${err.reason}` - } - - if (err.input.source) { - this.message += `\n\n${err.showSourceCode()}\n` - } + this.message = '' + this.message += `${this.name} \n\n(${err.line}:${err.column}) ${err.reason}` + this.message += `\n\n${err.showSourceCode()}\n` this.stack = false } From df010a7b13acae2e9abd18690055c713cec4191a Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sat, 14 Oct 2017 17:50:57 +0200 Subject: [PATCH 4/5] fix(lib/options): handle `{Object}` return (`options.plugins`) (#301) --- lib/options.js | 2 +- lib/options.json | 7 ++++ .../__snapshots__/plugins.test.js.snap | 6 ++- test/options/plugins.test.js | 38 ++++++++++++++++++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/options.js b/lib/options.js index 56cff551..980e9366 100644 --- a/lib/options.js +++ b/lib/options.js @@ -9,7 +9,7 @@ module.exports = function parseOptions (params) { if (typeof params.plugins === 'undefined') plugins = [] else if (Array.isArray(params.plugins)) plugins = params.plugins - else plugins = params.plugins + else plugins = [ params.plugins ] const options = {} diff --git a/lib/options.json b/lib/options.json index dd5f23c0..f1b194aa 100644 --- a/lib/options.json +++ b/lib/options.json @@ -25,6 +25,13 @@ "stringifier": { "type": [ "string", "object" ] }, + "plugins": { + "anyOf": [ + { "type": "array" }, + { "type": "object" }, + { "instanceof": "Function" } + ] + }, "sourceMap": { "type": [ "string", "boolean" ] } diff --git a/test/options/__snapshots__/plugins.test.js.snap b/test/options/__snapshots__/plugins.test.js.snap index 913df0fe..e2b12345 100644 --- a/test/options/__snapshots__/plugins.test.js.snap +++ b/test/options/__snapshots__/plugins.test.js.snap @@ -2,4 +2,8 @@ exports[`Options Plugins - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`; -exports[`Options Plugins - {Function} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`; +exports[`Options Plugins - {Function} - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`; + +exports[`Options Plugins - {Function} - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`; + +exports[`Options Plugins - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`; diff --git a/test/options/plugins.test.js b/test/options/plugins.test.js index ddfc1bf2..32293cc6 100644 --- a/test/options/plugins.test.js +++ b/test/options/plugins.test.js @@ -22,7 +22,25 @@ describe('Options', () => { }) }) - test('Plugins - {Function}', () => { + test('Plugins - {Object}', () => { + const config = { + loader: { + options: { + ident: 'postcss', + plugins: require('../fixtures/config/plugin') + } + } + } + + return webpack('css/index.js', config).then((stats) => { + const src = loader(stats).src + + expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"") + expect(src).toMatchSnapshot() + }) + }) + + test('Plugins - {Function} - {Array}', () => { const config = { loader: { options: { @@ -39,4 +57,22 @@ describe('Options', () => { expect(src).toMatchSnapshot() }) }) + + test('Plugins - {Function} - {Object}', () => { + const config = { + loader: { + options: { + ident: 'postcss', + plugins: () => require('../fixtures/config/plugin')() + } + } + } + + return webpack('css/index.js', config).then((stats) => { + const src = loader(stats).src + + expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"") + expect(src).toMatchSnapshot() + }) + }) }) From bcc9ccf8b6dbe6143484853da4cac442ecf8aa58 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sat, 14 Oct 2017 17:52:35 +0200 Subject: [PATCH 5/5] chore(release): 2.0.8 --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbe9817..55d71220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [2.0.8](https://github.com/postcss/postcss-loader/compare/v2.0.6...v2.0.8) (2017-10-14) + + +### Bug Fixes + +* **lib/options:** handle `{Object}` return (`options.plugins`) ([#301](https://github.com/postcss/postcss-loader/issues/301)) ([df010a7](https://github.com/postcss/postcss-loader/commit/df010a7)) +* **schema:** allow to pass an `{Object}` (`options.syntax/options.stringifier`) ([#300](https://github.com/postcss/postcss-loader/issues/300)) ([58e9996](https://github.com/postcss/postcss-loader/commit/58e9996)) + + + ## [2.0.7](https://github.com/postcss/postcss-loader/compare/v2.0.6...v2.0.7) (2017-10-10) diff --git a/package.json b/package.json index 377f9abb..7510593d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-loader", - "version": "2.0.7", + "version": "2.0.8", "description": "PostCSS loader for webpack", "main": "lib/index.js", "engines": { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy