pax_global_header00006660000000000000000000000064134775151370014527gustar00rootroot0000000000000052 comment=bdaf431ef1142b5d0253aeb534aad8f42e46877e postcss-load-config-2.1.0/000077500000000000000000000000001347751513700154055ustar00rootroot00000000000000postcss-load-config-2.1.0/.editorconfig000066400000000000000000000001641347751513700200630ustar00rootroot00000000000000root = true [*] charset = utf-8 indent_style = spaces insert_final_newline = true trim_trailing_whitespace = true postcss-load-config-2.1.0/.github/000077500000000000000000000000001347751513700167455ustar00rootroot00000000000000postcss-load-config-2.1.0/.github/CODEOWNERS000066400000000000000000000000251347751513700203350ustar00rootroot00000000000000* @michael-ciniawsky postcss-load-config-2.1.0/.github/ISSUE_TEMPLATE/000077500000000000000000000000001347751513700211305ustar00rootroot00000000000000postcss-load-config-2.1.0/.github/ISSUE_TEMPLATE/BUG.md000066400000000000000000000023351347751513700220720ustar00rootroot00000000000000--- name: 🐛 Bug about: Report a Bug --- ### `Details` ## `Error (Logs|Stacks)` ### `Reproduction (Code)` ```bash $ git clone https://github.com// ``` ### `Environment` |OS|node|npm/yarn|package| |:-:|:-:|:-----:|:------:| |[name][version]|[version]|[version]|[version]| postcss-load-config-2.1.0/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000030531347751513700225470ustar00rootroot00000000000000### `Notable Changes` #### `Commit Message Summary (CHANGELOG)` ``` commit message body... ``` ### `Type` - [ ] CI - [ ] Fix - [ ] Perf - [ ] Docs - [ ] Test - [ ] Chore - [ ] Style - [ ] Build - [ ] Feature - [ ] Refactor ### `SemVer` - [ ] Fix (:label: Patch) - [ ] Feature (:label: Minor) - [ ] Breaking Change (:label: Major) ### `Issues` - Fixes `#1` ### `Checklist` - [ ] Lint and unit tests pass with my changes - [ ] I have added tests that prove my fix is effective/works - [ ] I have added necessary documentation (if appropriate) - [ ] Any dependent changes are merged and published in downstream modules postcss-load-config-2.1.0/.gitignore000066400000000000000000000003041347751513700173720ustar00rootroot00000000000000# OS DS_Store Thumbs.db # Logs *.log npm-debug.log* yarn-debug.log* # Build /logs /dist /local /reports /coverage /node_modules # Editor .idea .vscode *.sublime-project *.sublime-workspace postcss-load-config-2.1.0/.npmignore000066400000000000000000000002001347751513700173740ustar00rootroot00000000000000# FILES .travis.yml .gitignore .editorconfig npm-debug.log # DIRECTORIES .github dmd jest* coverage jsdoc-api node_modules postcss-load-config-2.1.0/.npmrc000066400000000000000000000000231347751513700165200ustar00rootroot00000000000000package-lock=false postcss-load-config-2.1.0/.travis.yml000066400000000000000000000003261347751513700175170ustar00rootroot00000000000000language: node_js node_js: - 'stable' - 'lts/*' - 6 script: npm run lint && npm t after_success: npm i -D coveralls && cat ./coverage/lcov.info | node_modules/.bin/coveralls notifications: email: false postcss-load-config-2.1.0/CHANGELOG.md000066400000000000000000000056221347751513700172230ustar00rootroot00000000000000# Changelog 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.1.0](https://github.com/michael-ciniawsky/postcss-load-config/compare/v2.0.0...v2.1.0) (2019-06-10) ### Bug Fixes * **plugins:** add `undefined` to plugin `options` check ([#177](https://github.com/michael-ciniawsky/postcss-load-config/issues/177)) ([4349ea9](https://github.com/michael-ciniawsky/postcss-load-config/commit/4349ea9)) ### Features * **src/index:** support synchronous config loading (`rc.sync`) ([f230d40](https://github.com/michael-ciniawsky/postcss-load-config/commit/f230d40)) # [2.0.0](https://github.com/michael-ciniawsky/postcss-load-config/compare/v1.2.0...v2.0.0) (2018-07-10) ### Bug Fixes * **package:** `require-from-string` memory leak, updates `cosmiconfig` v2.1.0...4.0.0 (`dependencies`) ([17f9621](https://github.com/michael-ciniawsky/postcss-load-config/commit/17f9621)) * **src/index.js:** clone the config `{Object}` on assignment instead of mutating it ([8669a90](https://github.com/michael-ciniawsky/postcss-load-config/commit/8669a90)) ### Features * **src:** load plugins from the current working directory ([9745bf0](https://github.com/michael-ciniawsky/postcss-load-config/commit/9745bf0)) * **src:** show config file in `err.message` ([4baff47](https://github.com/michael-ciniawsky/postcss-load-config/commit/4baff47)) ### BREAKING CHANGES * **package:** requires `node >= v4.0.0` * **package:** removes `argv` option (`options.argv`) * **package:** removes `--config` parsing # [1.2.0](https://github.com/michael-ciniawsky/postcss-load-config/compare/v1.1.0...v1.2.0) (2017-02-13) ### Features * **index:** allow extensions for .postcssrc ([0d3bf35](https://github.com/michael-ciniawsky/postcss-load-config/commit/0d3bf35)) # [1.1.0](https://github.com/michael-ciniawsky/postcss-load-config/compare/v1.0.0...v1.1.0) (2017-01-11) ### Features * **index:** config.file, improve error handling ([a6c32fd](https://github.com/michael-ciniawsky/postcss-load-config/commit/a6c32fd)) # [1.0.0]((https://github.com/michael-ciniawsky/postcss-load-config/compare/v1.0.0-rc...1.0.0)) (2016-10-27) ### Bug Fixes * **index:** behavior when config loading fails ([b549bc6](https://github.com/michael-ciniawsky/postcss-load-config/commit/b549bc6)), closes [#26](https://github.com/michael-ciniawsky/postcss-load-config/issues/26) * **index:** set NODE_ENV when undefined ([b24501c](https://github.com/michael-ciniawsky/postcss-load-config/commit/b24501c)) * **index:** support node v0.12 ([0bbfa94](https://github.com/michael-ciniawsky/postcss-load-config/commit/0bbfa94)) ### Features * **index:** function support, jsdoc, cleanups ([a78c580](https://github.com/michael-ciniawsky/postcss-load-config/commit/a78c580)) postcss-load-config-2.1.0/CONTRIBUTING.md000066400000000000000000000015051347751513700176370ustar00rootroot00000000000000- Commit summaries must be in the following format `(): ` - type - `ci`, `fix`, `feat`, `docs`, `test`, `perf`, `style`, `build`, `chore`, `revert`, `refactor` - scope - file affected e.g (`fix(lib/index): `), or general scope of commit - description - Your commit summary - Add docs if appropriate - Write tests that cover your changes - Make sure `npm run lint` and `npm test` both pass before submitting a PR - Add yourself as a contributor in `README.md` && `package.json` **README.md** ```html
{{ Name }} ``` **package.json** ``` { "contributors": [ "{{ firstname }} {{ lastname }} " ] } ``` postcss-load-config-2.1.0/DOCS.md000066400000000000000000000037231347751513700164640ustar00rootroot00000000000000## Modules
postcss-load-config

Autoload Config for PostCSS

## Functions
rc(ctx, path, options) ⇒ Promise

Load Config

## postcss-load-config Autoload Config for PostCSS **Requires**: module:comsiconfig, module:./options, module:./plugins **Version**: 2.0.0 **Author**: Michael Ciniawsky @michael-ciniawsky **License**: MIT ## rc(ctx, path, options) ⇒ Promise Load Config **Kind**: global function **Returns**: Promise - config PostCSS Config | Param | Type | Description | | --- | --- | --- | | ctx | Object | Config Context | | path | String | Config Path | | options | Object | Config Options | * [rc(ctx, path, options)](#rc) ⇒ Promise * [~ctx](#rc..ctx) : Object * [~path](#rc..path) : String * [~options](#rc..options) : Object ### rc~ctx : Object **Kind**: inner property of [rc](#rc) **Properties** | Name | Type | Default | Description | | --- | --- | --- | --- | | cwd | String | process.cwd() | Config search start location | | env | String | process.env.NODE_ENV | Config Enviroment, will be set to `development` by `postcss-load-config` if `process.env.NODE_ENV` is `undefined` | ### rc~path : String `process.cwd()` **Kind**: inner property of [rc](#rc) ### rc~options : Object **Kind**: inner property of [rc](#rc) **Properties** | Name | Type | Default | | --- | --- | --- | | rcExtensions | Boolean | true | postcss-load-config-2.1.0/LICENSE000066400000000000000000000021151347751513700164110ustar00rootroot00000000000000License (MIT) Copyright (c) Michael Ciniawsky 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. postcss-load-config-2.1.0/README.md000066400000000000000000000241751347751513700166750ustar00rootroot00000000000000[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![test][test]][test-url] [![coverage][cover]][cover-url] [![code style][style]][style-url] [![chat][chat]][chat-url]

Load Config

Install

```bash npm i -D postcss-load-config ```

Usage

```bash npm i -S|-D postcss-plugin ``` Install all required postcss plugins and save them to your **package.json** `dependencies`/`devDependencies` Then create a postcss config file by choosing one of the following formats ### `package.json` Create a **`postcss`** section in your projects **`package.json`** ``` Project (Root) |– client |– public | |- package.json ``` ```json { "postcss": { "parser": "sugarss", "map": false, "plugins": { "postcss-plugin": {} } } } ``` ### `.postcssrc` Create a **`.postcssrc`** file in JSON or YAML format > â„šī¸ It's recommended to use an extension (e.g **`.postcssrc.json`** or **`.postcssrc.yml`**) instead of `.postcssrc` ``` Project (Root) |– client |– public | |- (.postcssrc|.postcssrc.json|.postcssrc.yml) |- package.json ``` **`.postcssrc.json`** ```json { "parser": "sugarss", "map": false, "plugins": { "postcss-plugin": {} } } ``` **`.postcssrc.yml`** ```yaml parser: sugarss map: false plugins: postcss-plugin: {} ``` ### `.postcssrc.js` or `postcss.config.js` You may need some logic within your config. In this case create JS file named **`.postcssrc.js`** or **`postcss.config.js`** ``` Project (Root) |– client |– public | |- (.postcssrc.js|postcss.config.js) |- package.json ``` You can export the config as an `{Object}` **.postcssrc.js** ```js module.exports = { parser: 'sugarss', map: false, plugins: { 'postcss-plugin': {} } } ``` Or export a `{Function}` that returns the config (more about the `ctx` param below) **.postcssrc.js** ```js module.exports = (ctx) => ({ parser: ctx.parser ? 'sugarss' : false, map: ctx.env === 'development' ? ctx.map : false, plugins: { 'postcss-plugin': ctx.options.plugin } }) ``` Plugins can be loaded either using an `{Object}` or an `{Array}` #### `{Object}` **.postcssrc.js** ```js module.exports = ({ env }) => ({ ...options plugins: { 'postcss-plugin': env === 'production' ? {} : false } }) ``` #### `{Array}` **.postcssrc.js** ```js module.exports = ({ env }) => ({ ...options plugins: [ env === 'production' ? require('postcss-plugin')() : false ] }) ``` > :warning: When using an `{Array}`, make sure to `require()` each plugin

Options

|Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| |[**`to`**](#to)|`{String}`|`undefined`|Destination File Path| |[**`map`**](#map)|`{String\|Object}`|`false`|Enable/Disable Source Maps| |[**`from`**](#from)|`{String}`|`undefined`|Source File Path| |[**`parser`**](#parser)|`{String\|Function}`|`false`|Custom PostCSS Parser| |[**`syntax`**](#syntax)|`{String\|Function}`|`false`|Custom PostCSS Syntax| |[**`stringifier`**](#stringifier)|`{String\|Function}`|`false`|Custom PostCSS Stringifier| ### `parser` **.postcssrc.js** ```js module.exports = { parser: 'sugarss' } ``` ### `syntax` **.postcssrc.js** ```js module.exports = { syntax: 'postcss-scss' } ``` ### `stringifier` **.postcssrc.js** ```js module.exports = { stringifier: 'midas' } ``` ### [**`map`**](https://github.com/postcss/postcss/blob/master/docs/source-maps.md) **.postcssrc.js** ```js module.exports = { map: 'inline' } ``` > :warning: In most cases `options.from` && `options.to` are set by the third-party which integrates this package (CLI, gulp, webpack). It's unlikely one needs to set/use `options.from` && `options.to` within a config file. Unless you're a third-party plugin author using this module and its Node API directly **dont't set `options.from` && `options.to` yourself** ### `to` ```js module.exports = { to: 'path/to/dest.css' } ``` ### `from` ```js module.exports = { from: 'path/to/src.css' } ```

Plugins

### `{} || null` The plugin will be loaded with defaults ```js 'postcss-plugin': {} || null ``` **.postcssrc.js** ```js module.exports = { plugins: { 'postcss-plugin': {} || null } } ``` > :warning: `{}` must be an **empty** `{Object}` literal ### `{Object}` The plugin will be loaded with given options ```js 'postcss-plugin': { option: '', option: '' } ``` **.postcssrc.js** ```js module.exports = { plugins: { 'postcss-plugin': { option: '', option: '' } } } ``` ### `false` The plugin will not be loaded ```js 'postcss-plugin': false ``` **.postcssrc.js** ```js module.exports = { plugins: { 'postcss-plugin': false } } ``` ### `Ordering` Plugin **execution order** is determined by declaration in the plugins section (**top-down**) ```js { plugins: { 'postcss-plugin': {}, // [0] 'postcss-plugin': {}, // [1] 'postcss-plugin': {} // [2] } } ```

Context

When using a `{Function}` (`postcss.config.js` or `.postcssrc.js`), it's possible to pass context to `postcss-load-config`, which will be evaluated while loading your config. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available on the `ctx` `{Object}` > â„šī¸ Most third-party integrations add additional properties to the `ctx` (e.g `postcss-loader`). Check the specific module's README for more information about what is available on the respective `ctx`

Examples

**postcss.config.js** ```js module.exports = (ctx) => ({ parser: ctx.parser ? 'sugarss' : false, map: ctx.env === 'development' ? ctx.map : false, plugins: { 'postcss-import': {}, 'postcss-nested': {}, cssnano: ctx.env === 'production' ? {} : false } }) ```
```json "scripts": { "build": "NODE_ENV=production node postcss", "start": "NODE_ENV=development node postcss" } ``` ### `Async` ```js const { readFileSync } = require('fs') const postcss = require('postcss') const postcssrc = require('postcss-load-config') const css = readFileSync('index.sss', 'utf8') const ctx = { parser: true, map: 'inline' } postcssrc(ctx).then(({ plugins, options }) => { postcss(plugins) .process(css, options) .then((result) => console.log(result.css)) }) ``` ### `Sync` ```js const { readFileSync } = require('fs') const postcss = require('postcss') const postcssrc = require('postcss-load-config') const css = readFileSync('index.sss', 'utf8') const ctx = { parser: true, map: 'inline' } const { plugins, options } = postcssrc.sync(ctx) ```
```json "scripts": { "build": "NODE_ENV=production gulp", "start": "NODE_ENV=development gulp" } ``` ```js const { task, src, dest, series, watch } = require('gulp') const postcss = require('gulp-postcssrc') const css = () => { src('src/*.css') .pipe(postcss()) .pipe(dest('dest')) }) task('watch', () => { watch(['src/*.css', 'postcss.config.js'], css) }) task('default', series(css, 'watch')) ```
```json "scripts": { "build": "NODE_ENV=production webpack", "start": "NODE_ENV=development webpack-dev-server" } ``` **webpack.config.js** ```js module.exports = (env) => ({ module: { rules: [ { test: /\.css$/, use: [ 'style-loader', 'css-loader', 'postcss-loader' ] } ] } }) ```

Maintainers


Michael Ciniawsky

Mateusz Derks

Contributors


Ryan Dunckel

Patrick Gilday

Dalton Santos
[npm]: https://img.shields.io/npm/v/postcss-load-config.svg [npm-url]: https://npmjs.com/package/postcss-load-config [node]: https://img.shields.io/node/v/postcss-load-plugins.svg [node-url]: https://nodejs.org/ [deps]: https://david-dm.org/michael-ciniawsky/postcss-load-config.svg [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-config [test]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-config.svg [test-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-config [cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-config/badge.svg [cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-config [style]: https://img.shields.io/badge/code%20style-standard-yellow.svg [style-url]: http://standardjs.com/ [chat]: https://img.shields.io/gitter/room/postcss/postcss.svg [chat-url]: https://gitter.im/postcss/postcss postcss-load-config-2.1.0/appveyor.yml000066400000000000000000000005661347751513700200040ustar00rootroot00000000000000init: - git config --global core.autocrlf input build: 'off' matrix: fast_finish: true install: - ps: Install-Product node $env:nodejs_version x64 - npm i -g npm - npm i test_script: - node --version - npm --version - cmd: npm run lint && npm t environment: matrix: - nodejs_version: 'stable' - nodejs_version: 'lts' - nodejs_version: '6' postcss-load-config-2.1.0/package.json000066400000000000000000000024011347751513700176700ustar00rootroot00000000000000{ "name": "postcss-load-config", "version": "2.1.0", "description": "Autoload Config for PostCSS", "main": "src/index.js", "files": [ "src" ], "engines": { "node": ">= 4" }, "scripts": { "lint": "standard --env jest", "test": "jest --verbose --coverage", "docs": "jsdoc2md src/*.js > DOCS.md", "clean": "npx rimraf ./coverage", "release": "standard-version" }, "dependencies": { "cosmiconfig": "^5.0.0", "import-cwd": "^2.0.0" }, "devDependencies": { "cssnano": "^4.0.0", "jest": "^24.0.0", "jsdoc-to-markdown": "^5.0.0", "postcss": "^7.0.0", "postcss-import": "^12.0.0", "postcss-nested": "^4.0.0", "standard": "^12.0.0", "standard-version": "6.0.0", "sugarss": "^2.0.0" }, "keywords": [ "postcss", "postcssrc", "postcss.config.js" ], "author": "Michael Ciniawky ", "contributors": [ "Ryan Dunckel", "Mateusz Derks", "Dalton Santos", "Patrick Gilday" ], "repository": "https://github.com/michael-ciniawsky/postcss-load-config.git", "bugs": "https://github.com/michael-ciniawsky/postcss-load-config/issues", "homepage": "https://github.com/michael-ciniawsky/postcss-load-config#readme", "license": "MIT" } postcss-load-config-2.1.0/src/000077500000000000000000000000001347751513700161745ustar00rootroot00000000000000postcss-load-config-2.1.0/src/index.js000066400000000000000000000051501347751513700176420ustar00rootroot00000000000000'use strict' const resolve = require('path').resolve const config = require('cosmiconfig') const loadOptions = require('./options.js') const loadPlugins = require('./plugins.js') /** * Process the result from cosmiconfig * * @param {Object} ctx Config Context * @param {Object} result Cosmiconfig result * * @return {Object} PostCSS Config */ const processResult = (ctx, result) => { let file = result.filepath || '' let config = result.config || {} if (typeof config === 'function') { config = config(ctx) } else { config = Object.assign({}, config, ctx) } if (!config.plugins) { config.plugins = [] } return { plugins: loadPlugins(config, file), options: loadOptions(config, file), file: file } } /** * Builds the Config Context * * @param {Object} ctx Config Context * * @return {Object} Config Context */ const createContext = (ctx) => { /** * @type {Object} * * @prop {String} cwd=process.cwd() Config search start location * @prop {String} env=process.env.NODE_ENV Config Enviroment, will be set to `development` by `postcss-load-config` if `process.env.NODE_ENV` is `undefined` */ ctx = Object.assign({ cwd: process.cwd(), env: process.env.NODE_ENV }, ctx) if (!ctx.env) { process.env.NODE_ENV = 'development' } return ctx } /** * Load Config * * @method rc * * @param {Object} ctx Config Context * @param {String} path Config Path * @param {Object} options Config Options * * @return {Promise} config PostCSS Config */ const rc = (ctx, path, options) => { /** * @type {Object} The full Config Context */ ctx = createContext(ctx) /** * @type {String} `process.cwd()` */ path = path ? resolve(path) : process.cwd() return config('postcss', options) .search(path) .then((result) => { if (!result) { throw new Error(`No PostCSS Config found in: ${path}`) } return processResult(ctx, result) }) } rc.sync = (ctx, path, options) => { /** * @type {Object} The full Config Context */ ctx = createContext(ctx) /** * @type {String} `process.cwd()` */ path = path ? resolve(path) : process.cwd() const result = config('postcss', options).searchSync(path) if (!result) { throw new Error(`No PostCSS Config found in: ${path}`) } return processResult(ctx, result) } /** * Autoload Config for PostCSS * * @author Michael Ciniawsky @michael-ciniawsky * @license MIT * * @module postcss-load-config * @version 2.0.0 * * @requires comsiconfig * @requires ./options * @requires ./plugins */ module.exports = rc postcss-load-config-2.1.0/src/options.js000066400000000000000000000020211347751513700202200ustar00rootroot00000000000000'use strict' const req = require('import-cwd') /** * Load Options * * @private * @method options * * @param {Object} config PostCSS Config * * @return {Object} options PostCSS Options */ const options = (config, file) => { if (config.parser && typeof config.parser === 'string') { try { config.parser = req(config.parser) } catch (err) { throw new Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`) } } if (config.syntax && typeof config.syntax === 'string') { try { config.syntax = req(config.syntax) } catch (err) { throw new Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`) } } if (config.stringifier && typeof config.stringifier === 'string') { try { config.stringifier = req(config.stringifier) } catch (err) { throw new Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`) } } if (config.plugins) { delete config.plugins } return config } module.exports = options postcss-load-config-2.1.0/src/plugins.js000066400000000000000000000032271347751513700202170ustar00rootroot00000000000000'use strict' const req = require('import-cwd') /** * Plugin Loader * * @private * @method load * * @param {String} plugin PostCSS Plugin Name * @param {Object} options PostCSS Plugin Options * * @return {Function} PostCSS Plugin */ const load = (plugin, options, file) => { try { if ( options === null || options === undefined || Object.keys(options).length === 0 ) { return req(plugin) } else { return req(plugin)(options) } } catch (err) { throw new Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`) } } /** * Load Plugins * * @private * @method plugins * * @param {Object} config PostCSS Config Plugins * * @return {Array} plugins PostCSS Plugins */ const plugins = (config, file) => { let plugins = [] if (Array.isArray(config.plugins)) { plugins = config.plugins.filter(Boolean) } else { plugins = Object.keys(config.plugins) .filter((plugin) => { return config.plugins[plugin] !== false ? plugin : '' }) .map((plugin) => { return load(plugin, config.plugins[plugin], file) }) } if (plugins.length && plugins.length > 0) { plugins.forEach((plugin, i) => { if (plugin.postcss) { plugin = plugin.postcss } if (plugin.default) { plugin = plugin.default } if ( // eslint-disable-next-line !(typeof plugin === 'object' && Array.isArray(plugin.plugins) || typeof plugin === 'function') ) { throw new TypeError(`Invalid PostCSS Plugin found at: plugins[${i}]\n\n(@${file})`) } }) } return plugins } module.exports = plugins postcss-load-config-2.1.0/test/000077500000000000000000000000001347751513700163645ustar00rootroot00000000000000postcss-load-config-2.1.0/test/Errors.test.js000066400000000000000000000100401347751513700211470ustar00rootroot00000000000000'use strict' const postcssrc = require('../src/index.js') test('Loading Config - {Error}', () => { return postcssrc({}, 'test/err').catch((err) => { expect(err.message).toMatch( /^No PostCSS Config found in: (.*)$/ ) }) }) test('Loading Config - Sync - {Error}', () => { try { postcssrc.sync({}, 'test/err') } catch (err) { expect(err.message).toMatch( /^No PostCSS Config found in: (.*)$/ ) } }) describe('Loading Plugins - {Error}', () => { test('Plugin - {Type} - Invalid', () => { return postcssrc({}, 'test/err/plugins').catch((err) => { expect(err.message).toMatch( /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/ ) }) }) test('Plugin - {Object}', () => { return postcssrc({}, 'test/err/plugins/object').catch((err) => { expect(err.message).toMatch( /^Loading PostCSS Plugin failed: .*$/m ) }) }) test('Plugin - {Object} - Options', () => { return postcssrc({}, 'test/err/plugins/object/options').catch((err) => { expect(err.message).toMatch( /^Loading PostCSS Plugin failed: .*$/m ) }) }) test('Plugin - {Array}', () => { return postcssrc({}, 'test/err/plugins/array').catch((err) => { expect(err.message).toMatch( /^Cannot find (.*)$/ ) }) }) test('Plugin - {Array} - Options', () => { return postcssrc({}, 'test/err/plugins/array/options').catch((err) => { expect(err.message).toMatch( /^Cannot find (.*)$/ ) }) }) }) describe('Loading Plugins - Sync - {Error}', () => { test('Plugin - {Type} - Invalid', () => { try { postcssrc.sync({}, 'test/err/plugins') } catch (err) { expect(err.message).toMatch( /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/ ) } }) test('Plugin - {Object}', () => { try { postcssrc.sync({}, 'test/err/plugins/object') } catch (err) { expect(err.message).toMatch( /^Loading PostCSS Plugin failed: .*$/m ) } }) test('Plugin - {Object} - Options', () => { try { postcssrc.sync({}, 'test/err/plugins/object/options') } catch (err) { expect(err.message).toMatch( /^Loading PostCSS Plugin failed: .*$/m ) } }) test('Plugin - {Array}', () => { try { postcssrc.sync({}, 'test/err/plugins/array') } catch (err) { expect(err.message).toMatch( /^Cannot find (.*)$/ ) } }) test('Plugin - {Array} - Options', () => { try { postcssrc.sync({}, 'test/err/plugins/array/options') } catch (err) { expect(err.message).toMatch( /^Cannot find (.*)$/ ) } }) }) describe('Loading Options - {Error}', () => { test('Parser - {String}', () => { return postcssrc({}, 'test/err/options/parser').catch((err) => { expect(err.message).toMatch( /^Loading PostCSS Parser failed: .*$/m ) }) }) test('Syntax - {String}', () => { return postcssrc({}, 'test/err/options/syntax').catch((err) => { expect(err.message).toMatch( /^Loading PostCSS Syntax failed: .*$/m ) }) }) test('Stringifier - {String}', () => { return postcssrc({}, 'test/err/options/stringifier').catch((err) => { expect(err.message).toMatch( /^Loading PostCSS Stringifier failed: .*$/m ) }) }) }) describe('Loading Options - Sync - {Error}', () => { test('Parser - {String}', () => { try { postcssrc.sync({}, 'test/err/options/parser') } catch (err) { expect(err.message).toMatch( /^Loading PostCSS Parser failed: .*$/m ) } }) test('Syntax - {String}', () => { try { postcssrc.sync({}, 'test/err/options/syntax') } catch (err) { expect(err.message).toMatch( /^Loading PostCSS Syntax failed: .*$/m ) } }) test('Stringifier - {String}', () => { try { postcssrc.sync({}, 'test/err/options/stringifier') } catch (err) { expect(err.message).toMatch( /^Loading PostCSS Stringifier failed: .*$/m ) } }) }) postcss-load-config-2.1.0/test/err/000077500000000000000000000000001347751513700171545ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/options/000077500000000000000000000000001347751513700206475ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/options/parser/000077500000000000000000000000001347751513700221435ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/options/parser/.postcssrc.js000066400000000000000000000001201347751513700245730ustar00rootroot00000000000000module.exports = function (ctx) { return { parser: 'postcss-parser' } } postcss-load-config-2.1.0/test/err/options/stringifier/000077500000000000000000000000001347751513700231745ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/options/stringifier/.postcssrc.js000066400000000000000000000001321347751513700256270ustar00rootroot00000000000000module.exports = function (ctx) { return { stringifier: 'postcss-stringifier' } } postcss-load-config-2.1.0/test/err/options/syntax/000077500000000000000000000000001347751513700221755ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/options/syntax/.postcssrc.js000066400000000000000000000001201347751513700246250ustar00rootroot00000000000000module.exports = function (ctx) { return { syntax: 'postcss-syntax' } } postcss-load-config-2.1.0/test/err/plugins/000077500000000000000000000000001347751513700206355ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/plugins/.postcssrc.js000066400000000000000000000001421347751513700232710ustar00rootroot00000000000000module.exports = function (ctx) { return { plugins: [ require('./plugin') ] } } postcss-load-config-2.1.0/test/err/plugins/array/000077500000000000000000000000001347751513700217535ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/plugins/array/.postcssrc.js000066400000000000000000000001501347751513700244060ustar00rootroot00000000000000module.exports = function (ctx) { return { plugins: [ require('postcss-plugin') ] } } postcss-load-config-2.1.0/test/err/plugins/array/options/000077500000000000000000000000001347751513700234465ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/plugins/array/options/.postcssrc.js000066400000000000000000000001501347751513700261010ustar00rootroot00000000000000module.exports = function (ctx) { return { plugins: [ require('postcss-plugin') ] } } postcss-load-config-2.1.0/test/err/plugins/object/000077500000000000000000000000001347751513700221035ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/plugins/object/.postcssrc.js000066400000000000000000000001431347751513700245400ustar00rootroot00000000000000module.exports = function (ctx) { return { plugins: { 'postcss-plugin': {} } } } postcss-load-config-2.1.0/test/err/plugins/object/options/000077500000000000000000000000001347751513700235765ustar00rootroot00000000000000postcss-load-config-2.1.0/test/err/plugins/object/options/.postcssrc.js000066400000000000000000000001611347751513700262330ustar00rootroot00000000000000module.exports = function (ctx) { return { plugins: { 'postcss-plugin': { option: true } } } } postcss-load-config-2.1.0/test/err/plugins/plugin.js000066400000000000000000000000421347751513700224650ustar00rootroot00000000000000module.exports = 'Invalid Plugin' postcss-load-config-2.1.0/test/js.test.js000066400000000000000000000071521347751513700203210ustar00rootroot00000000000000'use strict' const path = require('path') const postcss = require('postcss') const postcssrc = require('../src/index.js') const { fixture, expected } = require('./utils.js') describe('postcss.config.js - {Object} - Load Config', () => { const ctx = { parser: true, syntax: true } const expected = (config) => { expect(config.options.parser).toEqual(require('sugarss')) expect(config.options.syntax).toEqual(require('sugarss')) expect(config.options.map).toEqual(false) expect(config.options.from).toEqual('./test/js/object/fixtures/index.css') expect(config.options.to).toEqual('./test/js/object/expect/index.css') expect(config.plugins.length).toEqual(2) expect(typeof config.plugins[0]).toBe('function') expect(typeof config.plugins[1]).toBe('function') expect(config.file) .toEqual(path.resolve('test/js/object', 'postcss.config.js')) } test('Async', () => { return postcssrc(ctx, 'test/js/object').then(expected) }) test('Sync', () => { const config = postcssrc.sync(ctx, 'test/js/object') expected(config) }) }) test('postcss.config.js - {Object} - Process CSS', () => { const ctx = { parser: false, syntax: false } return postcssrc(ctx, 'test/js/object').then((config) => { return postcss(config.plugins) .process(fixture('js/object', 'index.css'), config.options) .then((result) => { expect(result.css).toEqual(expected('js/object', 'index.css')) }) }) }) test('postcss.config.js - {Object} - Process SSS', () => { const ctx = { from: './test/js/object/fixtures/index.sss', parser: true, syntax: false } return postcssrc(ctx, 'test/js/object').then((config) => { return postcss(config.plugins) .process(fixture('js/object', 'index.sss'), config.options) .then((result) => { expect(result.css).toEqual(expected('js/object', 'index.sss')) }) }) }) describe('postcss.config.js - {Array} - Load Config', () => { const ctx = { parser: true, syntax: true } const expected = (config) => { expect(config.options.parser).toEqual(require('sugarss')) expect(config.options.syntax).toEqual(require('sugarss')) expect(config.options.map).toEqual(false) expect(config.options.from).toEqual('./test/js/array/fixtures/index.css') expect(config.options.to).toEqual('./test/js/array/expect/index.css') expect(config.plugins.length).toEqual(2) expect(typeof config.plugins[0]).toBe('function') expect(typeof config.plugins[1]).toBe('function') expect(config.file) .toEqual(path.resolve('test/js/array', 'postcss.config.js')) } test('Async', () => { return postcssrc(ctx, 'test/js/array').then(expected) }) test('Sync', () => { const config = postcssrc.sync(ctx, 'test/js/array') expected(config) }) }) test('postcss.config.js - {Array} - Process CSS', () => { const ctx = { parser: false, syntax: false } return postcssrc(ctx, 'test/js/array').then((config) => { return postcss(config.plugins) .process(fixture('js/array', 'index.css'), config.options) .then((result) => { expect(result.css).toEqual(expected('js/array', 'index.css')) }) }) }) test('postcss.config.js - {Array} - Process SSS', () => { const ctx = { from: './test/js/array/fixtures/index.sss', parser: true, syntax: false } return postcssrc(ctx, 'test/js/array').then((config) => { return postcss(config.plugins) .process(fixture('js/array', 'index.sss'), config.options) .then((result) => { expect(result.css).toEqual(expected('js/array', 'index.sss')) }) }) }) postcss-load-config-2.1.0/test/js/000077500000000000000000000000001347751513700170005ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/array/000077500000000000000000000000001347751513700201165ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/array/expect/000077500000000000000000000000001347751513700214065ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/array/expect/index.css000066400000000000000000000000721347751513700232260ustar00rootroot00000000000000.import { color: goldenrod; } .test { color: cyan; } postcss-load-config-2.1.0/test/js/array/expect/index.sss000066400000000000000000000000701347751513700232440ustar00rootroot00000000000000.import { color: goldenrod } .test { color: cyan } postcss-load-config-2.1.0/test/js/array/fixtures/000077500000000000000000000000001347751513700217675ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/array/fixtures/imports/000077500000000000000000000000001347751513700234645ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/array/fixtures/imports/section.css000066400000000000000000000000401347751513700256340ustar00rootroot00000000000000.import { color: goldenrod; } postcss-load-config-2.1.0/test/js/array/fixtures/imports/section.sss000066400000000000000000000000331347751513700256560ustar00rootroot00000000000000.import color: goldenrod postcss-load-config-2.1.0/test/js/array/fixtures/index.css000066400000000000000000000000711347751513700236060ustar00rootroot00000000000000@import 'imports/section.css'; .test { color: cyan; } postcss-load-config-2.1.0/test/js/array/fixtures/index.sss000066400000000000000000000000631347751513700236270ustar00rootroot00000000000000@import 'imports/section.sss' .test color: cyan postcss-load-config-2.1.0/test/js/array/postcss.config.js000066400000000000000000000006451347751513700234230ustar00rootroot00000000000000module.exports = function (ctx) { return { parser: ctx.parser ? 'sugarss' : false, syntax: ctx.syntax ? 'sugarss' : false, map: ctx.map ? 'inline' : false, from: './test/js/array/fixtures/index.css', to: './test/js/array/expect/index.css', plugins: [ require('postcss-import')(), require('postcss-nested')(), ctx.env === 'production' ? require('cssnano')() : false ] } } postcss-load-config-2.1.0/test/js/object/000077500000000000000000000000001347751513700202465ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/object/expect/000077500000000000000000000000001347751513700215365ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/object/expect/index.css000066400000000000000000000000641347751513700233570ustar00rootroot00000000000000.import { color: red; } .test { color: blue; } postcss-load-config-2.1.0/test/js/object/expect/index.sss000066400000000000000000000000621347751513700233750ustar00rootroot00000000000000.import { color: red } .test { color: blue } postcss-load-config-2.1.0/test/js/object/fixtures/000077500000000000000000000000001347751513700221175ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/object/fixtures/imports/000077500000000000000000000000001347751513700236145ustar00rootroot00000000000000postcss-load-config-2.1.0/test/js/object/fixtures/imports/section.css000066400000000000000000000000321347751513700257650ustar00rootroot00000000000000.import { color: red; } postcss-load-config-2.1.0/test/js/object/fixtures/imports/section.sss000066400000000000000000000000251347751513700260070ustar00rootroot00000000000000.import color: red postcss-load-config-2.1.0/test/js/object/fixtures/index.css000066400000000000000000000000711347751513700237360ustar00rootroot00000000000000@import "imports/section.css"; .test { color: blue; } postcss-load-config-2.1.0/test/js/object/fixtures/index.sss000066400000000000000000000000631347751513700237570ustar00rootroot00000000000000@import "imports/section.sss" .test color: blue postcss-load-config-2.1.0/test/js/object/postcss.config.js000066400000000000000000000006221347751513700235460ustar00rootroot00000000000000module.exports = function (ctx) { return { parser: ctx.parser ? 'sugarss' : false, syntax: ctx.syntax ? 'sugarss' : false, map: ctx.map ? 'inline' : false, from: './test/js/object/fixtures/index.css', to: './test/js/object/expect/index.css', plugins: { 'postcss-import': {}, 'postcss-nested': {}, 'cssnano': ctx.env === 'production' ? {} : false } } } postcss-load-config-2.1.0/test/pkg.test.js000066400000000000000000000033551347751513700204670ustar00rootroot00000000000000'use strict' const path = require('path') const postcss = require('postcss') const postcssrc = require('../src/index.js') const { fixture, expected } = require('./utils.js') describe('package.json - {Object} - Load Config', () => { const expected = (config) => { expect(config.options.parser).toEqual(require('sugarss')) expect(config.options.syntax).toEqual(require('sugarss')) expect(config.options.map).toEqual(false) expect(config.options.from).toEqual('./test/pkg/fixtures/index.css') expect(config.options.to).toEqual('./test/pkg/expect/index.css') expect(config.plugins.length).toEqual(2) expect(typeof config.plugins[0]).toBe('function') expect(typeof config.plugins[1]).toBe('function') expect(config.file) .toEqual(path.resolve('test/pkg', 'package.json')) } test('Async', () => { return postcssrc({}, 'test/pkg').then(expected) }) test('Sync', () => { const config = postcssrc.sync({}, 'test/pkg') expected(config) }) }) test('package.json - {Object} - Process CSS', () => { const ctx = { parser: false, syntax: false } return postcssrc(ctx, 'test/pkg').then((config) => { return postcss(config.plugins) .process(fixture('pkg', 'index.css'), config.options) .then((result) => { expect(result.css).toEqual(expected('pkg', 'index.css')) }) }) }) test('package.json - {Object} - Process SSS', () => { const ctx = { from: './test/pkg/fixtures/index.sss', syntax: false } return postcssrc(ctx, 'test/pkg').then((config) => { return postcss(config.plugins) .process(fixture('pkg', 'index.sss'), config.options) .then((result) => { expect(result.css).toEqual(expected('pkg', 'index.sss')) }) }) }) postcss-load-config-2.1.0/test/pkg/000077500000000000000000000000001347751513700171455ustar00rootroot00000000000000postcss-load-config-2.1.0/test/pkg/expect/000077500000000000000000000000001347751513700204355ustar00rootroot00000000000000postcss-load-config-2.1.0/test/pkg/expect/index.css000066400000000000000000000000641347751513700222560ustar00rootroot00000000000000.import { color: red; } .test { color: blue; } postcss-load-config-2.1.0/test/pkg/expect/index.sss000066400000000000000000000000621347751513700222740ustar00rootroot00000000000000.import { color: red } .test { color: blue } postcss-load-config-2.1.0/test/pkg/fixtures/000077500000000000000000000000001347751513700210165ustar00rootroot00000000000000postcss-load-config-2.1.0/test/pkg/fixtures/imports/000077500000000000000000000000001347751513700225135ustar00rootroot00000000000000postcss-load-config-2.1.0/test/pkg/fixtures/imports/section.css000066400000000000000000000000321347751513700246640ustar00rootroot00000000000000.import { color: red; } postcss-load-config-2.1.0/test/pkg/fixtures/imports/section.sss000066400000000000000000000000251347751513700247060ustar00rootroot00000000000000.import color: red postcss-load-config-2.1.0/test/pkg/fixtures/index.css000066400000000000000000000000711347751513700226350ustar00rootroot00000000000000@import "imports/section.css"; .test { color: blue; } postcss-load-config-2.1.0/test/pkg/fixtures/index.sss000066400000000000000000000000631347751513700226560ustar00rootroot00000000000000@import "imports/section.sss" .test color: blue postcss-load-config-2.1.0/test/pkg/package.json000066400000000000000000000005111347751513700214300ustar00rootroot00000000000000{ "name": "postcss-config", "version": "1.0.0", "postcss": { "parser": "sugarss", "syntax": "sugarss", "map": false, "from": "./test/pkg/fixtures/index.css", "to": "./test/pkg/expect/index.css", "plugins": { "postcss-import": {}, "postcss-nested": {}, "cssnano": false } } } postcss-load-config-2.1.0/test/rc.test.js000066400000000000000000000033311347751513700203040ustar00rootroot00000000000000'use strict' const path = require('path') const postcss = require('postcss') const postcssrc = require('../src/index.js') const { fixture, expected } = require('./utils.js') describe('.postcssrc - {Object} - Load Config', () => { const expected = (config) => { expect(config.options.parser).toEqual(require('sugarss')) expect(config.options.syntax).toEqual(require('sugarss')) expect(config.options.map).toEqual(false) expect(config.options.from).toEqual('./test/rc/fixtures/index.css') expect(config.options.to).toEqual('./test/rc/expect/index.css') expect(config.plugins.length).toEqual(2) expect(typeof config.plugins[0]).toBe('function') expect(typeof config.plugins[1]).toBe('function') expect(config.file) .toEqual(path.resolve('test/rc', '.postcssrc')) } test('Async', () => { return postcssrc({}, 'test/rc').then(expected) }) test('Sync', () => { const config = postcssrc.sync({}, 'test/rc') expected(config) }) }) test('.postcssrc - {Object} - Process CSS', () => { const ctx = { parser: false, syntax: false } return postcssrc(ctx, 'test/rc').then((config) => { return postcss(config.plugins) .process(fixture('rc', 'index.css'), config.options) .then((result) => { expect(result.css).toEqual(expected('rc', 'index.css')) }) }) }) test('.postcssrc - {Object} - Process SSS', () => { const ctx = { from: './test/rc/fixtures/index.sss', syntax: false } return postcssrc(ctx, 'test/rc').then((config) => { return postcss(config.plugins) .process(fixture('rc', 'index.sss'), config.options) .then((result) => { expect(result.css).toEqual(expected('rc', 'index.sss')) }) }) }) postcss-load-config-2.1.0/test/rc/000077500000000000000000000000001347751513700167705ustar00rootroot00000000000000postcss-load-config-2.1.0/test/rc/.postcssrc000066400000000000000000000003561347751513700210200ustar00rootroot00000000000000{ "parser": "sugarss", "syntax": "sugarss", "map": false, "from": "./test/rc/fixtures/index.css", "to": "./test/rc/expect/index.css", "plugins": { "postcss-import": {}, "postcss-nested": {}, "cssnano": false } } postcss-load-config-2.1.0/test/rc/expect/000077500000000000000000000000001347751513700202605ustar00rootroot00000000000000postcss-load-config-2.1.0/test/rc/expect/index.css000066400000000000000000000000641347751513700221010ustar00rootroot00000000000000.import { color: red; } .test { color: blue; } postcss-load-config-2.1.0/test/rc/expect/index.sss000066400000000000000000000000621347751513700221170ustar00rootroot00000000000000.import { color: red } .test { color: blue } postcss-load-config-2.1.0/test/rc/fixtures/000077500000000000000000000000001347751513700206415ustar00rootroot00000000000000postcss-load-config-2.1.0/test/rc/fixtures/imports/000077500000000000000000000000001347751513700223365ustar00rootroot00000000000000postcss-load-config-2.1.0/test/rc/fixtures/imports/section.css000066400000000000000000000000321347751513700245070ustar00rootroot00000000000000.import { color: red; } postcss-load-config-2.1.0/test/rc/fixtures/imports/section.sss000066400000000000000000000000251347751513700245310ustar00rootroot00000000000000.import color: red postcss-load-config-2.1.0/test/rc/fixtures/index.css000066400000000000000000000000711347751513700224600ustar00rootroot00000000000000@import "imports/section.css"; .test { color: blue; } postcss-load-config-2.1.0/test/rc/fixtures/index.sss000066400000000000000000000000631347751513700225010ustar00rootroot00000000000000@import "imports/section.sss" .test color: blue postcss-load-config-2.1.0/test/utils.js000066400000000000000000000005231347751513700200620ustar00rootroot00000000000000'use strict' const fs = require('fs') const path = require('path') const fixture = (dir, file) => { return fs.readFileSync(path.resolve('test', dir, 'fixtures', file), 'utf8') } const expected = (dir, file) => { return fs.readFileSync(path.resolve('test', dir, 'expect', file), 'utf8') } module.exports = { fixture, expected }