Skip to content

Commit

Permalink
Merge pull request #40 from joscha/joscha/postcss
Browse files Browse the repository at this point in the history
feat: add CSS (PostCSS dialect)
  • Loading branch information
mrjoelkemp committed Apr 12, 2018
2 parents ab7f601 + 5068a88 commit 6553f16
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 4 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Supports:
* JavaScript modules: AMD, CommonJS, and ES6.
* Typescript
* CSS Preprocessors: Sass, Stylus, and Less
* CSS (PostCSS)

### Usage

Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var detectiveCjs = require('detective-cjs');
var detectiveAmd = require('detective-amd');
var detectiveEs6 = require('detective-es6');
var detectiveLess = require('detective-less');
var detectivePostcss = require('detective-postcss');
var detectiveSass = require('detective-sass');
var detectiveScss = require('detective-scss');
var detectiveStylus = require('detective-stylus');
Expand Down Expand Up @@ -71,6 +72,9 @@ function precinct(content, options) {
case 'commonjs':
theDetective = mixedMode ? detectiveEs6Cjs : detectiveCjs;
break;
case 'css':
theDetective = detectivePostcss;
break;
case 'amd':
theDetective = detectiveAmd;
break;
Expand Down Expand Up @@ -137,7 +141,7 @@ precinct.paperwork = function(filename, options) {
var ext = path.extname(filename);
var type;

if (ext === '.scss' || ext === '.sass' || ext === '.less' || ext === '.ts') {
if (ext === '.css' || ext === '.scss' || ext === '.sass' || ext === '.less' || ext === '.ts') {
type = ext.replace('.', '');

} else if (ext === '.styl') {
Expand Down
105 changes: 103 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"detective-cjs": "^2.0.0",
"detective-es6": "^1.2.0",
"detective-less": "^1.0.1",
"detective-postcss": "^2.0.0",
"detective-sass": "^2.0.0",
"detective-scss": "^1.0.0",
"detective-stylus": "^1.0.0",
Expand Down
8 changes: 7 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ describe('node-precinct', function() {
assert(cjs.length === 0);
});

it('grabs dependencies of css files', function() {
var css = precinct(read('styles.css'), 'css');
assert.deepEqual(css, ['foo.css', 'baz.css', 'bla.css', 'another.css']);
});

it('grabs dependencies of scss files', function() {
var scss = precinct(read('styles.scss'), 'scss');
assert.deepEqual(scss, ['_foo', 'baz.scss']);
});

it('grabs dependencies of scss files', function() {
it('grabs dependencies of sass files', function() {
var sass = precinct(read('styles.sass'), 'sass');
assert.deepEqual(sass, ['_foo']);
});
Expand Down Expand Up @@ -151,6 +156,7 @@ describe('node-precinct', function() {
assert.ok(precinct.paperwork(__dirname + '/es6.js').length);
assert.ok(precinct.paperwork(__dirname + '/styles.scss').length);
assert.ok(precinct.paperwork(__dirname + '/typescript.ts').length);
assert.ok(precinct.paperwork(__dirname + '/styles.css').length);
});

it('throws if the file cannot be found', function() {
Expand Down
4 changes: 4 additions & 0 deletions test/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "foo.css";
@import url("baz.css");
@value a from 'bla.css';
@value a, b as x from url(another.css);

0 comments on commit 6553f16

Please sign in to comment.