diff --git a/Readme.md b/Readme.md index d86a798..140df8b 100644 --- a/Readme.md +++ b/Readme.md @@ -11,6 +11,7 @@ Supports: * JavaScript modules: AMD, CommonJS, and ES6. * Typescript * CSS Preprocessors: Sass, Stylus, and Less +* CSS (PostCSS) ### Usage diff --git a/index.js b/index.js index 422e6c0..090d4bc 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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; @@ -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') { diff --git a/package-lock.json b/package-lock.json index f37d6b0..57c7f2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -317,6 +317,19 @@ "colors": "1.0.3" } }, + "color-convert": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, "colors": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", @@ -475,6 +488,17 @@ "node-source-walk": "3.3.0" } }, + "detective-postcss": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/detective-postcss/-/detective-postcss-2.0.0.tgz", + "integrity": "sha512-rVy1Zf0er4K32UYkKTOogPz6SGv88zDxOM3Kz/eubPNT4EK+LBfNhN2dydaKNkG+m0Utw/szOds68pyCckeoXA==", + "requires": { + "debug": "3.1.0", + "is-url": "1.2.4", + "postcss": "6.0.21", + "postcss-values-parser": "1.5.0" + } + }, "detective-sass": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/detective-sass/-/detective-sass-2.0.1.tgz", @@ -592,8 +616,7 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "escodegen": { "version": "1.9.0", @@ -639,6 +662,11 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, + "flatten": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz", + "integrity": "sha1-2uRqnXj74lKSJYzB54CkHZXAN4I=" + }, "formatio": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/formatio/-/formatio-1.2.0.tgz", @@ -758,6 +786,11 @@ "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0=", "dev": true }, + "indexes-of": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/indexes-of/-/indexes-of-1.0.1.tgz", + "integrity": "sha1-8w9xbI4r00bHtn0985FVZqfAVgc=" + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -798,6 +831,11 @@ "number-is-nan": "1.0.1" } }, + "is-url": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz", + "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==" + }, "is-utf8": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", @@ -1235,6 +1273,64 @@ "integrity": "sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=", "dev": true }, + "postcss": { + "version": "6.0.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.21.tgz", + "integrity": "sha512-y/bKfbQz2Nn/QBC08bwvYUxEFOVGfPIUOTsJ2CK5inzlXW9SdYR1x4pEsG9blRAF/PX+wRNdOah+gx/hv4q7dw==", + "requires": { + "chalk": "2.3.2", + "source-map": "0.6.1", + "supports-color": "5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "1.9.1" + } + }, + "chalk": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.3.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "supports-color": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", + "requires": { + "has-flag": "3.0.0" + } + } + } + }, + "postcss-values-parser": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/postcss-values-parser/-/postcss-values-parser-1.5.0.tgz", + "integrity": "sha512-3M3p+2gMp0AH3da530TlX8kiO1nxdTnc3C6vr8dMxRLIlh8UYkz0/wcwptSXjhtx2Fr0TySI7a+BHDQ8NL7LaQ==", + "requires": { + "flatten": "1.0.2", + "indexes-of": "1.0.1", + "uniq": "1.0.1" + } + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -1531,6 +1627,11 @@ "integrity": "sha1-izixDKze9jM3uLJOT/htRa6lKag=", "dev": true }, + "uniq": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", + "integrity": "sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8=" + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 805ed69..9e09899 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.js b/test/index.js index 3232cc1..d238acc 100644 --- a/test/index.js +++ b/test/index.js @@ -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']); }); @@ -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() { diff --git a/test/styles.css b/test/styles.css new file mode 100644 index 0000000..f87c5d9 --- /dev/null +++ b/test/styles.css @@ -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);