diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e08b7c4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "stable" + - "10" + - "8" + - "6" diff --git a/index.js b/index.js index e699ddb..c17dce8 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ function transform (filename, source, options, done) { const plugins = defined(options.plugins, []) .map(plugin => { if (typeof plugin === 'string') { - plugin = [ plugin ] + plugin = [plugin] } return { @@ -36,13 +36,27 @@ function transform (filename, source, options, done) { delete ctx.plugins postcssrc(ctx, basedir).then(compile, function () { - return compile({options: ctx}) + return compile({ options: ctx }) }).then(function (result) { - done(null, result.css) + done(null, result) }, done) function compile (config) { return postcss(plugins.concat(config.plugins).filter(Boolean)) .process(source, config.options) + .then(function (result) { + // Collect imported files for watchify + const files = [filename] + result.messages.forEach(function (msg) { + if (msg.type === 'dependency') { + files.push(msg.file) + } + }) + + return { + css: result.css, + files: files + } + }) } } diff --git a/package.json b/package.json index b270e10..f787b49 100644 --- a/package.json +++ b/package.json @@ -22,20 +22,21 @@ }, "homepage": "https://github.com/stackcss/sheetify-postcss#readme", "devDependencies": { - "browserify": "^13.1.0", - "dependency-check": "^2.6.0", - "npm-run-all": "^3.0.0", - "postcss-color-function": "^2.0.1", + "browserify": "^16.0.0", + "dependency-check": "^3.4.1", + "npm-run-all": "^4.1.5", + "postcss-color-function": "^4.0.1", + "postcss-import": "^12.0.1", "pull-test": "^1.2.3", - "sheetify": "^5.1.0", - "standard": "^8.0.0", - "tape": "^4.5.1" + "sheetify": "^7.2.0", + "standard": "^13.0.2", + "tape": "^4.11.0" }, "dependencies": { "defined": "^1.0.0", - "postcss": "^5.1.2", - "postcss-load-config": "^1.2.0", - "resolve": "^1.1.7", - "xtend": "^4.0.1" + "postcss": "^7.0.17", + "postcss-load-config": "^2.1.0", + "resolve": "^1.11.1", + "xtend": "^4.0.2" } } diff --git a/test/index.js b/test/index.js index a29e633..a2bddb5 100644 --- a/test/index.js +++ b/test/index.js @@ -6,28 +6,40 @@ test(function (t) { t.test('module should work with postcss plugins without options', function (t) { t.plan(2) - sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [ './stubs/postcss-plugin' ] }, (err, css) => { + sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: ['./stubs/postcss-plugin'] }, (err, result) => { t.equal(err, null) - t.equal(css, '.ok {}') + t.equal(result.css, '.ok {}') }) }) t.test('module should work with postcss plugins and their options', function (t) { t.plan(2) - sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [ [ './stubs/postcss-plugin', { has: true } ] ] }, (err, css) => { + sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [['./stubs/postcss-plugin', { has: true }]] }, (err, result) => { t.equal(err, null) - t.equal(css, '.ok-with-options {}') + t.equal(result.css, '.ok-with-options {}') }) }) t.test('module should respect postcssrc config file', function (t) { t.plan(2) - sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, css) => { + sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, result) => { t.equal(err, null) - t.equal(css, '.ok-with-postcssrc {}') + t.equal(result.css, '.ok-with-postcssrc {}') }) }) -}) + t.test('should report imported files if postcss-import is used', function (t) { + t.plan(3) + + sheetifyPostcss(path.join(__dirname, 'test.css'), '@import "./stubs/dep.css"', { basedir: __dirname, plugins: ['postcss-import'] }, (err, result) => { + t.equal(err, null) + t.equal(result.css, '.dependency {}') + t.deepEqual(result.files, [ + path.join(__dirname, 'test.css'), + path.join(__dirname, 'stubs/dep.css') + ]) + }) + }) +}) diff --git a/test/stubs/dep.css b/test/stubs/dep.css new file mode 100644 index 0000000..e7b7702 --- /dev/null +++ b/test/stubs/dep.css @@ -0,0 +1 @@ +.dependency {}