├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .npmrc ├── CHANGELOG.md ├── LICENSE ├── gulp-cssimport.js ├── package.json ├── readme.md └── test ├── bom ├── design │ ├── header.css │ ├── page.css │ └── root.css └── index.js ├── broken-url ├── index.js └── style.css ├── commented-import ├── design │ ├── a.css │ └── style.css ├── index.js └── result.css ├── complete ├── design │ ├── a.css │ ├── b.css │ ├── b1 │ │ └── b1.css │ ├── b2 │ │ └── b2.css │ └── style.css └── index.js ├── general ├── design │ ├── a.css │ ├── b.css │ ├── c │ │ └── c.css │ ├── d.css │ └── style.css ├── index.js └── result.css ├── include-paths ├── design │ ├── c │ │ └── c.css │ └── style.css ├── index.js └── result.css ├── index.js ├── minified ├── a.css ├── b.css ├── c.css ├── d.css ├── index.js ├── result.css └── style.css ├── options-extensions-exclude ├── a.css ├── b.sass ├── c.less ├── index.js ├── result.css └── style.css ├── options-extensions-only ├── a.css ├── b.sass ├── c.less ├── index.js ├── result.css └── style.css ├── options-filter ├── a.css ├── b.sass ├── c.less ├── index.js └── style.css ├── options-matchpattern ├── design │ ├── a.css │ └── style │ │ ├── b.css │ │ └── css │ │ └── main │ │ └── style.css ├── index.js └── result.css ├── parent ├── design │ ├── a.css │ └── style │ │ ├── b.css │ │ └── css │ │ └── main │ │ └── style.css ├── index.js └── result.css ├── recursive ├── design │ ├── a.css │ ├── b.css │ ├── c.css │ └── style.css └── index.js ├── sass-commented-import ├── design │ ├── a.css │ ├── b.css │ ├── c.css │ └── style.css ├── index.js └── result.css ├── sourcemaps ├── a.css ├── a1.css ├── b.css ├── index.js ├── style.css └── style2.css ├── transform ├── design │ ├── a.css │ ├── b.css │ └── style.css ├── index.js └── result.css ├── urls ├── index.js └── style.css └── wild-commented-import ├── design ├── a.css ├── b.css ├── c.css └── style.css ├── index.js └── result.css /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "node": true 4 | }, 5 | "globals": { 6 | "Promise": true 7 | }, 8 | "extends": "eslint:recommended", 9 | "rules": { 10 | "linebreak-style": [ 11 | 2, 12 | "unix" 13 | ], 14 | "semi": [ 15 | 2, 16 | "always" 17 | ] 18 | } 19 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | ~* 3 | /.idea/ 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /test/ 2 | /node_modules/ 3 | ~* 4 | .eslintrc.js 5 | gulpfile.js 6 | /.idea -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock = false 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 7.0.0 (2018-10-13) 2 | 3 | * docs: Moved changelog ([6584733](https://github.com/unlight/gulp-cssimport/commit/6584733)) 4 | * feat: Removed gulp-util ([180a775](https://github.com/unlight/gulp-cssimport/commit/180a775)), closes [#28](https://github.com/unlight/gulp-cssimport/issues/28) [#29](https://github.com/unlight/gulp-cssimport/issues/29) 5 | 6 | ### BREAKING CHANGE 7 | 8 | * Removed deprecated gulp-util 9 | 10 | ## 6.0.1 [23 Feb 2018] 11 | * fixed potential catastrophic backtracking vulnerability 12 | 13 | ## 6.0.0 [01 Sep 2017] 14 | * remove byte order mask from imported files 15 | 16 | ## 5.1.0 [13 Aug 2017] 17 | * added option 'transform' 18 | 19 | ## 5.0.0 [20 Nov 2016] 20 | * added option 'skipComments' 21 | 22 | ## 4.0.0 [06 Oct 2016] 23 | * added option 'includePaths' 24 | 25 | ## 3.0.0 [28 Feb 2016] 26 | * removed node streams support, now only gulp 27 | * removed directory option 28 | * added sourcemaps support 29 | * fixed bogus destination bugs 30 | 31 | ## 2.0.0 [30 Jun 2015] 32 | * changed parse algorithm 33 | * can handle recursive import 34 | * can handle minified css files 35 | * added option 'matchPattern' 36 | 37 | ## 1.3.0 [14 Nov 2014] 38 | * added option 'extensions' 39 | * added option 'filter' 40 | 41 | ## 1.2.0 [15 Feb 2014] 42 | * fixed processing urls 43 | 44 | ## 1.1.0 [15 Feb 2014] 45 | * switched to through2 46 | * process files asynchronously 47 | 48 | ## 1.0.0 [12 Feb 2014] 49 | * first release 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /gulp-cssimport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var through = require("through2"); 3 | var path = require("path"); 4 | var deepExtend = require("deep-extend"); 5 | var fs = require("fs"); 6 | var pify = require("pify"); 7 | var Vinyl = require("vinyl"); 8 | var PluginError = require("plugin-error"); 9 | var collect = require("collect-stream"); 10 | var hh = require("http-https"); 11 | var minimatch = require("minimatch"); 12 | var applySourceMap = require("vinyl-sourcemaps-apply"); 13 | var MagicString = require("magic-string"); 14 | var lookupPath = require("lookup-path"); 15 | 16 | var PLUGIN_NAME = "gulp-cssimport"; 17 | var readFile = pify(fs.readFile); 18 | var trim = require("lodash.trim"); 19 | var format = require("util").format; 20 | var stripBom = require("strip-bom"); 21 | 22 | var defaults = { 23 | skipComments: true, 24 | extensions: null, 25 | includePaths: [], 26 | filter: null, 27 | matchPattern: null, 28 | matchOptions: { 29 | matchBase: true 30 | }, 31 | limit: 5000, 32 | transform: null 33 | }; 34 | 35 | module.exports = function cssImport(options) { 36 | 37 | options = deepExtend({}, defaults, options || {}); 38 | 39 | if (options.extensions && !Array.isArray(options.extensions)) { 40 | options.extensions = options.extensions.toString().split(",").map(function(x) { 41 | return x.trim(); 42 | }); 43 | } 44 | 45 | var stream; 46 | var cssCount = 0; 47 | var transform = (options.transform && typeof options.transform === 'function') ? options.transform : null; 48 | 49 | function fileContents(vinyl, encoding, callback) { 50 | 51 | if (!stream) { 52 | stream = this; 53 | } 54 | // https://github.com/kevva/import-regex/ 55 | var regex = '(?:@import)(?:\\s)(?:url)?(?:(?:(?:\\()(["\'])?(?:[^"\')]+)\\1(?:\\))|(["\'])(?:.+)\\2)(?:[A-Z\\s])*)+(?:;)'; // eslint-disable-line 56 | var importRe = new RegExp(regex, "gi"); 57 | var match; 58 | var file = []; 59 | var lastpos = 0; 60 | var promises = []; 61 | var contents = vinyl.contents.toString(); 62 | while ((match = importRe.exec(contents)) !== null) { 63 | if (options.skipComments) { 64 | var matchIndex = match.index; 65 | // Check comment symbols 1. 66 | var startCommentPosition = contents.lastIndexOf('/*', matchIndex); 67 | var endCommentPosition = contents.lastIndexOf('*/', matchIndex); 68 | if (!(endCommentPosition > startCommentPosition) && startCommentPosition !== -1) { 69 | continue; 70 | } 71 | // Check comment symbols 2. 72 | var startCommentPosition2 = contents.lastIndexOf('//', matchIndex); 73 | var endCommentPosition2 = contents.lastIndexOf('\n', matchIndex); 74 | if (startCommentPosition2 > endCommentPosition2 && startCommentPosition2 !== -1) { 75 | continue; 76 | } 77 | } 78 | var match2 = /@import\s+(?:url\()?(.+(?=['")]))(?:\))?.*/ig.exec(match[0]); 79 | var importPath = trim(match2[1], "'\""); 80 | if (transform) { 81 | importPath = transform(importPath, { match: match[0] }); 82 | } 83 | var isMatched = isMatch(importPath, options); 84 | if (!isMatched) { 85 | continue; 86 | } 87 | file[file.length] = contents.slice(lastpos, match.index); 88 | var index = file.length; 89 | file[index] = format("importing file %s from %s", importPath, vinyl.relative); 90 | lastpos = importRe.lastIndex; 91 | // Start resolving. 92 | if (++cssCount > options.limit) { 93 | stream.emit("error", new Error("Exceed limit. Recursive include?")); 94 | return; 95 | } 96 | 97 | (function(index) { 98 | var result = { index: index, importPath: importPath }; 99 | if (!isUrl(importPath)) { 100 | var pathDirectory = path.dirname(vinyl.path); 101 | var importFile = resolveImportFile(pathDirectory, importPath, options.includePaths); 102 | if (!importFile) { 103 | var err = new Error("Cannot find file '" + importPath + "' from '" + pathDirectory + "' (includePaths: " + options.includePaths + ")"); 104 | callback(new PluginError(PLUGIN_NAME, err)); 105 | } 106 | promises[promises.length] = readFile(importFile, "utf8").then(function(contents) { 107 | result.importFile = importFile; 108 | result.contents = contents; 109 | return result; 110 | }); 111 | } else { 112 | promises[promises.length] = new Promise(function(resolve, reject) { 113 | var req = hh.request(importPath, function(res) { 114 | collect(res, function(err, data) { 115 | if (err) { 116 | return reject(err); 117 | } 118 | result.contents = data.toString(); 119 | resolve(result); 120 | }); 121 | }); 122 | req.on("error", reject); 123 | req.end(); 124 | }); 125 | } 126 | })(index); 127 | } 128 | // Nothing to import. 129 | if (promises.length === 0) { 130 | callback(null, vinyl); 131 | return; 132 | } 133 | // Adding trailing piece. 134 | file[file.length] = contents.slice(lastpos); 135 | // Waiting promises. 136 | Promise.all(promises) 137 | .then(function(results) { 138 | for (var i = 0; i < results.length; i++) { 139 | var result = results[i]; 140 | // Strip BOM. 141 | result.contents = stripBom(result.contents); 142 | var vfile = new Vinyl({ 143 | path: result.importFile, 144 | contents: new Buffer(result.contents) 145 | }); 146 | (function(result) { 147 | results[i] = pify(fileContents)(vfile, null).then(function(vfile) { 148 | result.contents = vfile.contents.toString(); 149 | return result; 150 | }); 151 | })(result); 152 | } 153 | return Promise.all(results); 154 | }) 155 | .then(function(results) { 156 | var iterator = function() { }; 157 | if (vinyl.sourceMap) { 158 | var bundle = new MagicString.Bundle(); 159 | iterator = function(file, result) { 160 | bundle.addSource({ 161 | filename: result.importPath, 162 | content: new MagicString(result.contents) 163 | }); 164 | }; 165 | } 166 | for (var i = 0; i < results.length; i++) { 167 | var result = results[i]; 168 | var index = result.index; 169 | var contents = result.contents; 170 | file[index] = contents; 171 | iterator(file, result); 172 | } 173 | vinyl.contents = new Buffer(file.join("")); 174 | if (vinyl.sourceMap) { 175 | var map = bundle.generateMap({ 176 | file: vinyl.relative, 177 | includeContent: true, 178 | hires: true 179 | }); 180 | applySourceMap(vinyl, map); 181 | } 182 | callback(null, vinyl); 183 | }) 184 | .catch(function(err) { 185 | callback(new PluginError(PLUGIN_NAME, err)); 186 | }); 187 | } 188 | 189 | return through.obj(fileContents); 190 | }; 191 | 192 | function resolveImportFile(pathDirectory, importPath, includePaths) { 193 | var result = lookupPath(importPath, pathDirectory); 194 | if (result) { 195 | return result; 196 | } 197 | for (var i = 0; i < includePaths.length; i++) { 198 | var includePath = includePaths[i]; 199 | 200 | var d1 = path.resolve(pathDirectory, includePath); 201 | if (d1 === pathDirectory) { 202 | continue; 203 | } 204 | result = lookupPath(importPath, d1); 205 | if (result) { 206 | return result; 207 | } 208 | 209 | var d2 = path.resolve(includePath); 210 | if (d2 === d1) { 211 | continue; 212 | } 213 | result = lookupPath(importPath, d2); 214 | if (result) { 215 | return result; 216 | } 217 | } 218 | return null; 219 | } 220 | 221 | function isMatch(path, options) { 222 | if (!options) { 223 | return true; 224 | } 225 | if (!path) { 226 | return false; 227 | } 228 | options = options || {}; 229 | var result; 230 | if (options.filter instanceof RegExp) { 231 | var filter = options.filter; 232 | filter.lastIndex = 0; 233 | result = filter.test(path); 234 | } 235 | if (options.matchPattern && !isUrl(path)) { 236 | var matchPattern = options.matchPattern; 237 | result = minimatch(path, matchPattern, options.matchOptions); 238 | } 239 | if (options.extensions) { 240 | var extensions = options.extensions; 241 | var fileExt = getExtension(path); 242 | for (var k = 0; k < extensions.length; k++) { 243 | var extension = extensions[k]; 244 | var isInverse = extension.charAt(0) === '!'; 245 | if (isInverse) { 246 | extension = extension.slice(1); 247 | } 248 | if (isInverse && fileExt === extension) { // !sass , sass === css 249 | return false; 250 | } else if (!isInverse && fileExt !== extension) { 251 | return false; 252 | } 253 | } 254 | } 255 | if (typeof result === 'undefined') { 256 | result = true; 257 | } 258 | return result; 259 | } 260 | 261 | function isUrl(s) { 262 | return /^(http|https):\/\//.test(s); 263 | } 264 | 265 | function getExtension(p) { 266 | p = String(p); 267 | return p.substr(p.lastIndexOf('.') + 1); 268 | } 269 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-cssimport", 3 | "version": "7.0.0", 4 | "description": "Parses a CSS file, finds imports, grabs the content of the linked file and replaces the import statement with it.", 5 | "main": "gulp-cssimport.js", 6 | "scripts": { 7 | "test": "cd test && node index.js", 8 | "prepublishOnly": "sed -i -e 's/devDependencies/_devDependencies/g' package.json" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/unlight/gulp-cssimport.git" 13 | }, 14 | "keywords": [ 15 | "css", 16 | "gulpplugin", 17 | "import" 18 | ], 19 | "dependencies": { 20 | "collect-stream": "^1.2.1", 21 | "deep-extend": "^0.6.0", 22 | "plugin-error": "^0.1.2", 23 | "vinyl": "^2.2.0", 24 | "http-https": "^1.0.0", 25 | "lodash.trim": "^4.5.1", 26 | "lookup-path": "^0.3.1", 27 | "magic-string": "^0.25.1", 28 | "minimatch": "^3.0.4", 29 | "pify": "^3.0.0", 30 | "strip-bom": "^3.0.0", 31 | "through2": "^2.0.3", 32 | "vinyl-sourcemaps-apply": "^0.2.1" 33 | }, 34 | "devDependencies": { 35 | "tape": "^4.9.1", 36 | "@semantic-release/changelog": "^3.0.0", 37 | "@semantic-release/git": "^7.0.4", 38 | "semantic-release": "^15.9.15", 39 | "@semantic-release/npm": "^5.0.4" 40 | }, 41 | "license": "MIT", 42 | "release": { 43 | "generateNotes": { 44 | "writerOpts": { 45 | "__keep": "me" 46 | } 47 | }, 48 | "verifyConditions": [ 49 | "@semantic-release/changelog", 50 | "@semantic-release/github", 51 | "@semantic-release/npm", 52 | "@semantic-release/git" 53 | ], 54 | "prepare": [ 55 | "@semantic-release/changelog", 56 | "@semantic-release/npm", 57 | "@semantic-release/git" 58 | ], 59 | "publish": [ 60 | "@semantic-release/npm", 61 | "@semantic-release/github" 62 | ], 63 | "success": [ 64 | "@semantic-release/github" 65 | ], 66 | "fail": [ 67 | "@semantic-release/github" 68 | ] 69 | }, 70 | "config": { 71 | "commitizen": { 72 | "path": "cz-conventional-changelog" 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gulp-cssimport 2 | Parses a CSS file, finds imports, grabs the content of the linked file and replaces the import statement with it. 3 | 4 | ## INSTALL 5 | ```sh 6 | npm install gulp-cssimport 7 | ``` 8 | 9 | ## USAGE 10 | ```js 11 | var gulp = require("gulp"); 12 | var cssimport = require("gulp-cssimport"); 13 | var options = {}; 14 | gulp.task("import", function() { 15 | gulp.src("src/style.css") 16 | .pipe(cssimport(options)) 17 | .pipe(gulp.dest("dist/")); 18 | }); 19 | ``` 20 | 21 | ## OPTIONS 22 | #### includePaths 23 | Array, default: `[]` 24 | Additional paths to resolve imports. 25 | 26 | #### skipComments 27 | Boolean, default: `true` 28 | gulp-cssimport plugin uses regular expressions which is fast but not solid as AST. 29 | If you have any unexpected result, missing imported content, etc. Try to disable this option. 30 | 31 | #### filter 32 | RegExp, default: `null` (no filter). 33 | Process only files which match to regexp. 34 | Any other non-matched lines will be leaved as is. 35 | Example: 36 | ```js 37 | var options = { 38 | filter: /^http:\/\//gi // process only http urls 39 | }; 40 | ``` 41 | 42 | #### matchPattern 43 | String, glob pattern string. See [minimatch](https://www.npmjs.com/package/minimatch) for more details. 44 | ```js 45 | var options = { 46 | matchPattern: "*.css" // process only css 47 | }; 48 | var options2 = { 49 | matchPattern: "!*.{less,sass}" // all except less and sass 50 | }; 51 | ``` 52 | **Note:** 53 | `matchPattern` will not be applied to urls (remote files, e.g. `http://fonts.googleapis.com/css?family=Tangerine`), only files. 54 | Urls are matched by default. If you do not want include them, use `filter` option (it is applicable to all). 55 | 56 | #### matchOptions 57 | Object, [minimatch](https://www.npmjs.com/package/minimatch) options for `matchPattern`. 58 | 59 | #### limit 60 | Number, default `5000`. 61 | Defence from infinite recursive import. 62 | 63 | #### transform 64 | Function, default `null` 65 | Transform function applied for each import path. 66 | Signature: 67 | ``` 68 | (path: string, data: {match: string}) => string 69 | ``` 70 | Arguments: 71 | * `path` - string, path in import statement 72 | * object with data: 73 | - `match` - string, matched import expression 74 | 75 | #### extensions 76 | Deprecated, use `matchPattern` instead. 77 | String or Array, default: `null` (process all). 78 | Case insensitive list of extension allowed to process. 79 | Any other non-matched lines will be leaved as is. 80 | Examples: 81 | ```js 82 | var options = { 83 | extensions: ["css"] // process only css 84 | }; 85 | var options = { 86 | extensions: ["!less", "!sass"] // all except less and sass 87 | }; 88 | ``` 89 | 90 | ## TIPS AND TRICKS 91 | **Be more precise and do not add to src importing file without necessary:** 92 | ```css 93 | // main.css 94 | @import "a.css"; 95 | @import "b.css"; 96 | ``` 97 | If you will do `gulp.src("*.css")` gulp will read `a.css` and `b.css`, 98 | and plugin also will try to read these files. It is extra job. 99 | Do instead: `gulp.src("main.css")` 100 | 101 | **Use filter option:** 102 | If you need exclude files from import, try use `filter` only option (it is faster) and avoid others. 103 | 104 | 105 | ## POSTCSS 106 | There are plugins for [PostCSS](https://github.com/postcss/postcss) which do same job or even better: 107 | * [postcss-import](https://github.com/postcss/postcss-import) inlines the stylesheets referred to by `@import` rules 108 | * [postcss-import-url](https://github.com/unlight/postcss-import-url) inlines remote files. 109 | 110 | 111 | ## SIMILAR PROJECTS 112 | https://npmjs.org/package/gulp-coimport/ 113 | https://npmjs.org/package/gulp-concat-css/ 114 | https://github.com/yuguo/gulp-import-css/ 115 | https://github.com/postcss/postcss-import 116 | https://www.npmjs.com/package/combine-css/ 117 | https://github.com/suisho/gulp-cssjoin 118 | https://github.com/jfromaniello/css-import 119 | https://github.com/mariocasciaro/gulp-concat-css 120 | 121 | 122 | ## KNOWN ISSUES 123 | - Cannot resolve `@import 'foo.css' (min-width: 25em);` 124 | 125 | ## TODO 126 | - Cache 127 | 128 | ## CHANGELOG 129 | See [CHANGELOG](CHANGELOG.md) 130 | 131 | ## Support 132 | 133 | [![Beerpay](https://beerpay.io/unlight/gulp-cssimport/badge.svg?style=beer-square)](https://beerpay.io/unlight/gulp-cssimport) [![Beerpay](https://beerpay.io/unlight/gulp-cssimport/make-wish.svg?style=flat-square)](https://beerpay.io/unlight/gulp-cssimport?focus=wish) 134 | -------------------------------------------------------------------------------- /test/bom/design/header.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: #808; 3 | background-color: #303; 4 | } 5 | -------------------------------------------------------------------------------- /test/bom/design/page.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-family: sans-serif; 3 | } 4 | -------------------------------------------------------------------------------- /test/bom/design/root.css: -------------------------------------------------------------------------------- 1 | @import url("page.css"); 2 | @import url("header.css"); -------------------------------------------------------------------------------- /test/bom/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | }; 9 | 10 | test("Strip bom", function(t) { 11 | var stream = gulp.src("design/root.css") 12 | .pipe(plugin(options)); 13 | collect(stream, function(err, data) { 14 | var file = data[0]; 15 | var boms = file.contents.toString() 16 | .split('') 17 | .map(a => a.charCodeAt()) 18 | .filter(char => char === 0xFEFF) 19 | t.assert(boms.length === 0); 20 | t.end(); 21 | }); 22 | 23 | }); -------------------------------------------------------------------------------- /test/broken-url/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | test('Broken urls', function(t) { 8 | var stream = gulp.src("style.css") 9 | .pipe(plugin()); 10 | collect(stream, function(err, vinyls) { 11 | t.assert(err); 12 | t.end(); 13 | }); 14 | }); -------------------------------------------------------------------------------- /test/broken-url/style.css: -------------------------------------------------------------------------------- 1 | @import 'http://foo.bar.com/x.css'; 2 | body {} -------------------------------------------------------------------------------- /test/commented-import/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/commented-import/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); 2 | /* 3 | @import url("./b.css"); 4 | */ -------------------------------------------------------------------------------- /test/commented-import/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = {}; 7 | 8 | test("Commented import", function (t) { 9 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 10 | var stream; 11 | var p = plugin(options); 12 | stream = gulp.src("design/style.css") 13 | .pipe(p); 14 | collect(stream, function(err, data) { 15 | if (err) throw err; 16 | var file = data[0]; 17 | data = file.contents.toString(); 18 | // fs.writeFileSync("x.css", data); 19 | t.equal(data, result); 20 | t.end(); 21 | }); 22 | }); -------------------------------------------------------------------------------- /test/commented-import/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* 3 | @import url("./b.css"); 4 | */ -------------------------------------------------------------------------------- /test/complete/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/complete/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ 2 | @import "b1/b1.css"; -------------------------------------------------------------------------------- /test/complete/design/b1/b1.css: -------------------------------------------------------------------------------- 1 | /* b1.css */ 2 | @import "../b2/b2.css"; 3 | strong {font-weight: bold} -------------------------------------------------------------------------------- /test/complete/design/b2/b2.css: -------------------------------------------------------------------------------- 1 | /* b2.css */ 2 | a {color: white } 3 | -------------------------------------------------------------------------------- /test/complete/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); 2 | @import url("b.css"); 3 | @import "http://fonts.googleapis.com/css?family=Tangerine"; 4 | body { 5 | font-size: 13px; 6 | } -------------------------------------------------------------------------------- /test/complete/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | }; 9 | 10 | test("Complete", {timeout: 5000}, function (t) { 11 | var stream = gulp.src("design/style.css") 12 | .pipe(plugin(options)); 13 | collect(stream, function (err, data) { 14 | var file = data[0]; 15 | data = file.contents.toString(); 16 | t.assert(data.indexOf('/* a.css */' !== -1)); 17 | t.assert(data.indexOf('/* b.css */' !== -1)); 18 | t.assert(data.indexOf('/* b1.css */' !== -1)); 19 | t.assert(data.indexOf('/* b2.css */' !== -1)); 20 | t.assert(data.indexOf('a {color: white }' !== -1)); 21 | t.assert(data.indexOf('strong {font-weight: bold}' !== -1)); 22 | t.assert(data.indexOf("src: local('Tangerine Regular'), local('Tangerine-Regular')") !== -1); 23 | t.end(); 24 | }); 25 | 26 | }); -------------------------------------------------------------------------------- /test/general/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/general/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ 2 | @import "c/c.css"; -------------------------------------------------------------------------------- /test/general/design/c/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ 2 | @import "../d.css"; -------------------------------------------------------------------------------- /test/general/design/d.css: -------------------------------------------------------------------------------- 1 | /* d.css */ -------------------------------------------------------------------------------- /test/general/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); 2 | @import url("./b.css"); -------------------------------------------------------------------------------- /test/general/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = {}; 7 | 8 | test("Recursive", function (t) { 9 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 10 | var stream; 11 | var p = plugin(options); 12 | stream = gulp.src("design/style.css") 13 | .pipe(p); 14 | collect(stream, function(err, data) { 15 | var file = data[0]; 16 | data = file.contents.toString(); 17 | // fs.writeFileSync("x.css", data); 18 | t.equal(data, result); 19 | t.end(); 20 | }); 21 | }); -------------------------------------------------------------------------------- /test/general/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* b.css */ 3 | /* c.css */ 4 | /* d.css */ -------------------------------------------------------------------------------- /test/include-paths/design/c/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ -------------------------------------------------------------------------------- /test/include-paths/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("c.css"); 2 | -------------------------------------------------------------------------------- /test/include-paths/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = { 7 | includePaths: ['d:/dev', 'c'] 8 | }; 9 | 10 | test("Include paths", function (t) { 11 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 12 | var stream; 13 | var p = plugin(options); 14 | stream = gulp.src("design/style.css") 15 | .pipe(p); 16 | collect(stream, function(err, data) { 17 | var file = data[0]; 18 | data = file.contents.toString(); 19 | // fs.writeFileSync("x.css", data); 20 | t.equal(data, result); 21 | t.end(); 22 | }); 23 | }); 24 | 25 | test("Include paths error", function (t) { 26 | var stream; 27 | var p = plugin({}); 28 | stream = gulp.src("design/style.css") 29 | .pipe(p); 30 | collect(stream, function(err, data) { 31 | t.ok(err.message.indexOf("Cannot find file 'c.css' from") === 0); 32 | t.end(); 33 | }); 34 | }); -------------------------------------------------------------------------------- /test/include-paths/result.css: -------------------------------------------------------------------------------- 1 | /* c.css */ 2 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var EventEmitter = require("events").EventEmitter; 3 | var emitter = new EventEmitter(); 4 | var tests = [ 5 | "complete", 6 | "general", 7 | "minified", 8 | "options-extensions-exclude", 9 | "options-extensions-only", 10 | "options-filter", 11 | "options-matchpattern", 12 | "parent", 13 | "include-paths", 14 | "recursive", 15 | "commented-import", 16 | "wild-commented-import", 17 | "sass-commented-import", 18 | ]; 19 | emitter.on("run", function(index) { 20 | var name = tests[index]; 21 | if (!name) { 22 | throw new Error("Index out of range."); 23 | } 24 | process.chdir(__dirname + "/" + name); 25 | var fn = require("./" + name); 26 | var t = test(fn); 27 | t.on("end", function() { 28 | var nextIndex = index + 1; 29 | if (nextIndex >= tests.length) { 30 | return; 31 | } 32 | emitter.emit("run", nextIndex); 33 | }); 34 | }); 35 | 36 | emitter.emit("run", 0); -------------------------------------------------------------------------------- /test/minified/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/minified/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/minified/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ -------------------------------------------------------------------------------- /test/minified/d.css: -------------------------------------------------------------------------------- 1 | /* d.css */ -------------------------------------------------------------------------------- /test/minified/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | test("Minified", function (t) { 8 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 9 | var stream = gulp.src("style.css") 10 | .pipe(plugin()); 11 | collect(stream, function (err, vinyls) { 12 | var data = vinyls[0].contents.toString(); 13 | t.equal(data, result); 14 | t.end(); 15 | }); 16 | }); -------------------------------------------------------------------------------- /test/minified/result.css: -------------------------------------------------------------------------------- 1 | /* a.css *//* b.css *//* c.css *//* d.css */body{} -------------------------------------------------------------------------------- /test/minified/style.css: -------------------------------------------------------------------------------- 1 | @import "a.css";@import 'b.css';@import url(c.css);@import url(d.css);body{} -------------------------------------------------------------------------------- /test/options-extensions-exclude/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/options-extensions-exclude/b.sass: -------------------------------------------------------------------------------- 1 | /* b.sass */ -------------------------------------------------------------------------------- /test/options-extensions-exclude/c.less: -------------------------------------------------------------------------------- 1 | /* c.less */ -------------------------------------------------------------------------------- /test/options-extensions-exclude/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | extensions: ["!sass", "!less"] 9 | }; 10 | var options2 = { 11 | matchPattern: "!*.{less,sass}" // all except less and sass 12 | }; 13 | 14 | test("Options extensions exclude", function (t) { 15 | 16 | var stream = gulp.src("style.css") 17 | .pipe(plugin(options)); 18 | collect(stream, function (err, vinyls) { 19 | var data = vinyls[0].contents.toString(); 20 | t.assert(data.indexOf("/* a.css */") !== -1); 21 | t.assert(data.indexOf("@import 'b.sass'") !== -1); 22 | t.assert(data.indexOf("@import 'c.less'") !== -1); 23 | t.assert(data.indexOf("src: local('Tangerine Regular'), local('Tangerine-Regular')") !== -1); 24 | t.assert(data.indexOf("font-size: 13px") !== -1); 25 | }); 26 | 27 | var stream = gulp.src("style.css") 28 | .pipe(plugin(options2)); 29 | collect(stream, function (err, vinyls) { 30 | var data = vinyls[0].contents.toString(); 31 | t.assert(data.indexOf("/* a.css */") !== -1); 32 | t.assert(data.indexOf("@import 'b.sass'") !== -1); 33 | t.assert(data.indexOf("@import 'c.less'") !== -1); 34 | t.assert(data.indexOf("src: local('Tangerine Regular'), local('Tangerine-Regular')") !== -1); 35 | t.assert(data.indexOf("font-size: 13px") !== -1); 36 | t.end(); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /test/options-extensions-exclude/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | @import 'b.sass'; 3 | @import 'c.less'; 4 | @font-face { 5 | font-family: 'Tangerine'; 6 | font-style: normal; 7 | font-weight: 400; 8 | src: local('Tangerine'), url(http://fonts.gstatic.com/s/tangerine/v7/HGfsyCL5WASpHOFnouG-RKCWcynf_cDxXwCLxiixG1c.ttf) format('truetype'); 9 | } 10 | 11 | 12 | body { 13 | font-size: 13px; 14 | } -------------------------------------------------------------------------------- /test/options-extensions-exclude/style.css: -------------------------------------------------------------------------------- 1 | @import url("a.css"); 2 | @import 'b.sass'; 3 | @import 'c.less'; 4 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 5 | 6 | body { 7 | font-size: 13px; 8 | } -------------------------------------------------------------------------------- /test/options-extensions-only/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/options-extensions-only/b.sass: -------------------------------------------------------------------------------- 1 | /* b.sass */ -------------------------------------------------------------------------------- /test/options-extensions-only/c.less: -------------------------------------------------------------------------------- 1 | /* c.less */ -------------------------------------------------------------------------------- /test/options-extensions-only/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | extensions: ["css"] 9 | }; 10 | 11 | var options2 = { 12 | matchPattern: "*.css", 13 | filter: /^[^(http)]/gi 14 | }; 15 | 16 | 17 | test("Options extensions only", function (t) { 18 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 19 | t.plan(2); 20 | var stream = gulp.src("style.css") 21 | .pipe(plugin(options)); 22 | collect(stream, function (err, vinyls) { 23 | var data = vinyls[0].contents.toString(); 24 | t.equal(data, result); 25 | }); 26 | 27 | var stream = gulp.src("style.css") 28 | .pipe(plugin(options2)); 29 | collect(stream, function (err, vinyls) { 30 | var data = vinyls[0].contents.toString(); 31 | t.equal(data, result, "options2"); 32 | }); 33 | 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /test/options-extensions-only/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | @import 'b.sass'; 3 | @import "c.less"; 4 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 5 | body { 6 | font-size: 13px; 7 | } -------------------------------------------------------------------------------- /test/options-extensions-only/style.css: -------------------------------------------------------------------------------- 1 | @import url("a.css"); 2 | @import 'b.sass'; 3 | @import "c.less"; 4 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 5 | body { 6 | font-size: 13px; 7 | } -------------------------------------------------------------------------------- /test/options-filter/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/options-filter/b.sass: -------------------------------------------------------------------------------- 1 | /* b.sass */ -------------------------------------------------------------------------------- /test/options-filter/c.less: -------------------------------------------------------------------------------- 1 | /* c.less */ -------------------------------------------------------------------------------- /test/options-filter/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | filter: /^http:\/\//gi 9 | }; 10 | 11 | test("Options filter http", function (t) { 12 | var stream; 13 | var stream = gulp.src("style.css") 14 | .pipe(plugin(options)); 15 | collect(stream, function (err, vinyls) { 16 | var data = vinyls[0].contents.toString(); 17 | t.assert(data.indexOf('@import url("a.css")') !== -1); 18 | t.assert(data.indexOf("@import 'b.sass'") !== -1); 19 | t.assert(data.indexOf("@import 'c.less'") !== -1); 20 | t.assert(data.indexOf("src: local('Tangerine Regular'), local('Tangerine-Regular')") !== -1); 21 | t.end(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/options-filter/style.css: -------------------------------------------------------------------------------- 1 | @import url("a.css"); 2 | @import 'b.sass'; 3 | @import 'c.less'; 4 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 5 | 6 | body { 7 | font-size: 13px; 8 | } -------------------------------------------------------------------------------- /test/options-matchpattern/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/options-matchpattern/design/style/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/options-matchpattern/design/style/css/main/style.css: -------------------------------------------------------------------------------- 1 | @import '../../../a.css'; 2 | @import url('../../b.css'); 3 | body {} -------------------------------------------------------------------------------- /test/options-matchpattern/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | matchPattern: '*.css', 9 | }; 10 | 11 | test("Parent", function(t) { 12 | var stream; 13 | t.plan(1); 14 | var result = fs.readFileSync("result.css", { 15 | encoding: "utf8" 16 | }); 17 | stream = gulp.src("design/style/css/main/style.css") 18 | .pipe(plugin(options)); 19 | collect(stream, function(err, data) { 20 | var file = data[0]; 21 | data = file.contents.toString(); 22 | // fs.writeFileSync("x.css", data); 23 | t.equal(data, result); 24 | t.end(); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/options-matchpattern/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* b.css */ 3 | body {} -------------------------------------------------------------------------------- /test/parent/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/parent/design/style/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/parent/design/style/css/main/style.css: -------------------------------------------------------------------------------- 1 | @import '../../../a.css'; 2 | @import url('../../b.css'); 3 | body {} -------------------------------------------------------------------------------- /test/parent/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { matchPattern: '*.css' }; 8 | 9 | test("Parent", function (t) { 10 | var stream; 11 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 12 | stream = gulp.src("design/style/css/main/style.css") 13 | .pipe(plugin(options)); 14 | collect(stream, function (err, data) { 15 | var file = data[0]; 16 | data = file.contents.toString(); 17 | // fs.writeFileSync("x.css", data); 18 | t.equal(data, result); 19 | t.end(); 20 | }); 21 | 22 | }); -------------------------------------------------------------------------------- /test/parent/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* b.css */ 3 | body {} -------------------------------------------------------------------------------- /test/recursive/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | @import "b.css"; -------------------------------------------------------------------------------- /test/recursive/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ 2 | @import "c.css"; 3 | -------------------------------------------------------------------------------- /test/recursive/design/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ 2 | @import "a.css"; 3 | -------------------------------------------------------------------------------- /test/recursive/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); -------------------------------------------------------------------------------- /test/recursive/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | var options = { 8 | limit: 100 9 | }; 10 | 11 | test("Recursive", function (t) { 12 | var stream; 13 | t.plan(1); 14 | var p = plugin(options); 15 | stream = gulp.src("design/style.css") 16 | .pipe(p) 17 | p.on("error", function (err) { 18 | t.ok(err.message.indexOf("Recursive include") != -1, "Emit error"); 19 | }); 20 | }); -------------------------------------------------------------------------------- /test/sass-commented-import/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/sass-commented-import/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/sass-commented-import/design/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ -------------------------------------------------------------------------------- /test/sass-commented-import/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); 2 | // @import url("./x1.css"); /**/ 3 | @import url("./b.css"); 4 | /* 5 | // // @import url("./x2.css"); /* 6 | /**/ 7 | @import url("./c.css"); -------------------------------------------------------------------------------- /test/sass-commented-import/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = {}; 7 | 8 | test("Sass commented import", function (t) { 9 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 10 | var stream; 11 | var p = plugin(options); 12 | stream = gulp.src("design/style.css") 13 | .pipe(p); 14 | collect(stream, function(err, data) { 15 | if (err) throw err; 16 | var file = data[0]; 17 | data = file.contents.toString(); 18 | // fs.writeFileSync("x.css", data); 19 | t.equal(data, result); 20 | t.end(); 21 | }); 22 | }); -------------------------------------------------------------------------------- /test/sass-commented-import/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | // @import url("./x1.css"); /**/ 3 | /* b.css */ 4 | /* 5 | // // @import url("./x2.css"); /* 6 | /**/ 7 | /* c.css */ -------------------------------------------------------------------------------- /test/sourcemaps/a.css: -------------------------------------------------------------------------------- 1 | .a { 2 | font-color: red; 3 | } -------------------------------------------------------------------------------- /test/sourcemaps/a1.css: -------------------------------------------------------------------------------- 1 | .a1 { 2 | font-color: black; 3 | } -------------------------------------------------------------------------------- /test/sourcemaps/b.css: -------------------------------------------------------------------------------- 1 | .b { 2 | font-weight: bold; 3 | } -------------------------------------------------------------------------------- /test/sourcemaps/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var sourcemaps = require("gulp-sourcemaps"); 7 | 8 | var options = {}; 9 | 10 | test("Sourcemaps", function (t) { 11 | // var result = fs.readFileSync("result.css", { encoding: "utf8" }); 12 | var stream = gulp.src("style*.css") 13 | .pipe(sourcemaps.init()) 14 | .pipe(plugin(options)) 15 | .pipe(sourcemaps.write()) 16 | .pipe(gulp.dest("./~dst")) 17 | collect(stream, function (err, vinyls) { 18 | data = vinyls[0].contents.toString(); 19 | t.notEqual(data.indexOf('# sourceMappingURL'), -1); 20 | t.end(); 21 | }); 22 | 23 | }); -------------------------------------------------------------------------------- /test/sourcemaps/style.css: -------------------------------------------------------------------------------- 1 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 2 | @import "a.css"; 3 | @import "a1.css"; -------------------------------------------------------------------------------- /test/sourcemaps/style2.css: -------------------------------------------------------------------------------- 1 | @import "b.css"; 2 | -------------------------------------------------------------------------------- /test/transform/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/transform/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/transform/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("/a.css"); 2 | @import url("/b.css"); -------------------------------------------------------------------------------- /test/transform/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = { 7 | transform: function(path) { 8 | return '.' + path; 9 | } 10 | }; 11 | 12 | test("Transform option", function (t) { 13 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 14 | var stream; 15 | var p = plugin(options); 16 | stream = gulp.src("design/style.css") 17 | .pipe(p); 18 | collect(stream, function(err, data) { 19 | if (err) throw err; 20 | var file = data[0]; 21 | data = file.contents.toString(); 22 | // fs.writeFileSync("x.css", data); 23 | t.equal(data, result); 24 | t.end(); 25 | }); 26 | }); -------------------------------------------------------------------------------- /test/transform/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* b.css */ -------------------------------------------------------------------------------- /test/urls/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | 7 | test("Urls", function(t) { 8 | var stream = gulp.src("style.css") 9 | .pipe(plugin()); 10 | collect(stream, function(err, vinyls) { 11 | var data = vinyls[0].contents.toString(); 12 | t.notEqual(data.indexOf("font-family: 'Tangerine'"), -1); 13 | t.notEqual(data.indexOf("fonts.gstatic.com"), -1); 14 | t.end(); 15 | }); 16 | }); -------------------------------------------------------------------------------- /test/urls/style.css: -------------------------------------------------------------------------------- 1 | @import 'http://fonts.googleapis.com/css?family=Tangerine'; 2 | @import url("http://fonts.googleapis.com/css?family=Tangerine"); 3 | body {} -------------------------------------------------------------------------------- /test/wild-commented-import/design/a.css: -------------------------------------------------------------------------------- 1 | /* a.css */ -------------------------------------------------------------------------------- /test/wild-commented-import/design/b.css: -------------------------------------------------------------------------------- 1 | /* b.css */ -------------------------------------------------------------------------------- /test/wild-commented-import/design/c.css: -------------------------------------------------------------------------------- 1 | /* c.css */ -------------------------------------------------------------------------------- /test/wild-commented-import/design/style.css: -------------------------------------------------------------------------------- 1 | @import url("./a.css"); 2 | /* @import url("./x1.css"); /**/ 3 | @import url("./b.css"); 4 | /* 5 | @import url("./x2.css"); /* 6 | /**/ 7 | @import url("./c.css"); -------------------------------------------------------------------------------- /test/wild-commented-import/index.js: -------------------------------------------------------------------------------- 1 | var test = require("tape"); 2 | var fs = require("fs"); 3 | var collect = require("collect-stream"); 4 | var plugin = require("../.."); 5 | var gulp = require("gulp"); 6 | var options = {}; 7 | 8 | test("Wild commented import", function (t) { 9 | var result = fs.readFileSync("result.css", { encoding: "utf8" }); 10 | var stream; 11 | var p = plugin(options); 12 | stream = gulp.src("design/style.css") 13 | .pipe(p); 14 | collect(stream, function(err, data) { 15 | if (err) throw err; 16 | var file = data[0]; 17 | data = file.contents.toString(); 18 | // fs.writeFileSync("x.css", data); 19 | t.equal(data, result); 20 | t.end(); 21 | }); 22 | }); -------------------------------------------------------------------------------- /test/wild-commented-import/result.css: -------------------------------------------------------------------------------- 1 | /* a.css */ 2 | /* @import url("./x1.css"); /**/ 3 | /* b.css */ 4 | /* 5 | @import url("./x2.css"); /* 6 | /**/ 7 | /* c.css */ --------------------------------------------------------------------------------