Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/postcss-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 08c063ad664853efedbdc3526b10b74d5b45ade0
Choose a base ref
...
head repository: webpack-contrib/postcss-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6ddc2bb595fee7800908ac910d8d8fe91489e6cf
Choose a head ref
  • 6 commits
  • 13 files changed
  • 2 contributors

Commits on Feb 2, 2018

  1. Copy the full SHA
    a8921cc View commit details
  2. Copy the full SHA
    8242689 View commit details
  3. Copy the full SHA
    4e8e20c View commit details
  4. feat(index): pass AST (result.root) && Messages (result.messages)…

    … as metadata to other loaders (#322)
    michael-ciniawsky authored Feb 2, 2018
    Copy the full SHA
    56232e7 View commit details
  5. Copy the full SHA
    410bbf9 View commit details
  6. Copy the full SHA
    6ddc2bb View commit details
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js

node_js:
- "node"
- stable
- lts/*
- 6

after_success:
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,21 @@

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.

<a name="2.1.0"></a>
# [2.1.0](https://github.com/postcss/postcss-loader/compare/v2.0.10...v2.1.0) (2018-02-02)


### Bug Fixes

* **index:** continue watching after dependency `{Error}` ([#332](https://github.com/postcss/postcss-loader/issues/332)) ([a8921cc](https://github.com/postcss/postcss-loader/commit/a8921cc))


### Features

* **index:** pass AST (`result.root`) && Messages (`result.messages`) as metadata to other loaders ([#322](https://github.com/postcss/postcss-loader/issues/322)) ([56232e7](https://github.com/postcss/postcss-loader/commit/56232e7))



<a name="2.0.10"></a>
## [2.0.10](https://github.com/postcss/postcss-loader/compare/v2.0.9...v2.0.10) (2018-01-03)

12 changes: 10 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ const SyntaxError = require('./Error')
*
* @return {cb} cb Result
*/
module.exports = function loader (css, map) {
module.exports = function loader (css, map, meta) {
const options = Object.assign({}, loaderUtils.getOptions(this))

validateOptions(require('./options.json'), options, 'PostCSS Loader')
@@ -160,6 +160,11 @@ module.exports = function loader (css, map) {
map.sources = map.sources.map((src) => path.resolve(src))
}

if (!meta) meta = {}

meta.ast = { 'type': 'postcss', root: result.root }
meta.messages = result.messages

if (this.loaderIndex === 0) {
/**
* @memberof loader
@@ -173,6 +178,7 @@ module.exports = function loader (css, map) {

return null
}

/**
* @memberof loader
* @callback cb
@@ -181,11 +187,13 @@ module.exports = function loader (css, map) {
* @param {String} css Result (Raw Module)
* @param {Object} map Source Map
*/
cb(null, css, map)
cb(null, css, map, meta)

return null
})
}).catch((err) => {
if (err.file) this.addDependency(err.file)

return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
})
}
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-loader",
"version": "2.0.10",
"version": "2.1.0",
"description": "PostCSS loader for webpack",
"main": "lib/index.js",
"engines": {
@@ -13,21 +13,22 @@
"loader-utils": "^1.1.0",
"postcss": "^6.0.0",
"postcss-load-config": "^1.2.0",
"schema-utils": "^0.3.0"
"schema-utils": "^0.4.0"
},
"devDependencies": {
"coveralls": "^2.0.0",
"jest": "^21.0.0",
"jsdoc-to-markdown": "^3.0.0",
"jest": "^22.0.0",
"jsdoc-to-markdown": "^4.0.0",
"memory-fs": "^0.4.0",
"postcss-import": "^11.0.0",
"postcss-js": "^1.0.0",
"standard": "^10.0.0",
"standard-version": "^4.0.0",
"sugarss": "^1.0.0",
"util.promisify": "^1.0.0",
"webpack": "^3.0.0"
},
"scripts": {
"clean": "rm -rf dmd jest* coverage jsdoc-api test/results",
"clean": "rm -rf coverage test/outputs",
"lint": "standard",
"docs": "jsdoc2md lib/index.js > LOADER.md",
"postdocs": "npm run clean",
4 changes: 1 addition & 3 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -12,9 +12,7 @@ exports[`Errors Syntax Error 1`] = `
`;
exports[`Errors Validation Error 1`] = `
"Validation Error
PostCSS Loader Invalid Options
"PostCSS Loader Invalid Options
options.sourceMap should be string,boolean
"
6 changes: 6 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 2`] = `"throw new Error(\\"Module build failed: Syntax Error \\\\n\\\\n(1:5) Unknown word\\\\n\\\\n\\\\u001b[31m\\\\u001b[1m>\\\\u001b[22m\\\\u001b[39m\\\\u001b[90m 1 | \\\\u001b[39ma \\\\u001b[33m{\\\\u001b[39m color black \\\\u001b[33m}\\\\u001b[39m\\\\n \\\\u001b[90m | \\\\u001b[39m \\\\u001b[31m\\\\u001b[1m^\\\\u001b[22m\\\\u001b[39m\\\\n \\\\u001b[90m 2 | \\\\u001b[39m\\\\n\\");"`;
exports[`Loader Watching Dependencies Error 3`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
1 change: 1 addition & 0 deletions test/fixtures/watch/error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color black }
1 change: 1 addition & 0 deletions test/fixtures/watch/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color: black }
3 changes: 3 additions & 0 deletions test/fixtures/watch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import style from './style.css'

export default style
1 change: 1 addition & 0 deletions test/fixtures/watch/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "./import";
24 changes: 17 additions & 7 deletions test/helpers/compiler.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ module.exports = function compiler (fixture, config, options) {
output: {
path: path.resolve(
__dirname,
`../results/${config.path ? config.path : ''}`
`../outputs/${config.path ? config.path : ''}`
),
filename: '[name].bundle.js'
},
@@ -31,7 +31,7 @@ module.exports = function compiler (fixture, config, options) {
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['runtime'],
name: [ 'runtime' ],
minChunks: Infinity
})
].concat(config.plugins || [])
@@ -43,11 +43,21 @@ module.exports = function compiler (fixture, config, options) {

if (!options.emit) compiler.outputFileSystem = new MemoryFS()

return new Promise((resolve, reject) => {
return compiler.run((err, stats) => {
if (err) reject(err)
if (options.watch) {
return new Promise((resolve, reject) => {
const watcher = compiler.watch({}, (err, stats) => {
options.watch(err, stats, () => {
watcher.close(resolve)
})
})
})
} else {
return new Promise((resolve, reject) => {
return compiler.run((err, stats) => {
if (err) reject(err)

resolve(stats)
resolve(stats)
})
})
})
}
}
38 changes: 38 additions & 0 deletions test/helpers/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path')
const promisify = require('util.promisify')

const {
unlink: _unlink,
readFile: _readFile,
writeFile: _writeFile
} = require('fs')

const fs = {
readFile: promisify(_readFile),
writeFile: promisify(_writeFile),
unlink: promisify(_unlink)
}

function readFile (name) {
const file = path.join(__dirname, '../fixtures', name)

return fs.readFile(file)
.then((data) => data.toString())
}

function writeFile (name, data) {
const file = path.join(__dirname, '../fixtures', name)

return fs.writeFile(file, data)
}

module.exports.copyFile = function copyFile (src, dest) {
return readFile(src)
.then((data) => writeFile(dest, data))
}

module.exports.deleteFile = function deleteFile (name) {
const file = path.join(__dirname, '../fixtures', name)

return fs.unlink(file)
}
67 changes: 67 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

const webpack = require('./helpers/compiler')
const { loader } = require('./helpers/compilation')
const { copyFile, deleteFile } = require('./helpers/fs');

describe('Loader', () => {
test('Default', () => {
@@ -20,4 +21,70 @@ describe('Loader', () => {
expect(src).toMatchSnapshot()
})
})

describe('Watching', () => {
describe('Dependencies', () => {
const files = {
css: 'watch/index.css',
error: 'watch/error.css',
changed: 'watch/import.css'
}

beforeEach(() => copyFile(files.css, files.changed))

afterEach(() => deleteFile(files.changed))

test('Error', () => {
const config = {
loader: {
options: {
plugins: [
require('postcss-import')
],
}
}
}

const steps = [
(stats) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(err.length).toEqual(0)

return copyFile(files.error, files.changed)
},
(stats) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(err.length).toEqual(1)

return copyFile(files.css, files.changed)
},
(stats, close) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(src).toEqual("module.exports = \"a { color: black }\\n\"")
expect(err.length).toEqual(0)

return close()
}
]

let step = 0

const options = {
watch (err, stats, close) {
steps[step](stats, close)

step++
}
}

return webpack('watch/index.js', config, options)
})
})
})
})