Makes `root` option implicitely default to `process.cwd()` unless given.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 15 Mar 2015 14:05:30 +0000 (14:05 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 15 Mar 2015 14:05:30 +0000 (14:05 +0000)
History.md
lib/clean.js
lib/images/url-rebase.js
lib/imports/inliner.js
lib/selectors/tokenizer.js
lib/utils/source-reader.js

index 4f411a5..a7c6e0f 100644 (file)
@@ -1,6 +1,7 @@
 [3.2.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.1...HEAD)
 ==================
 
+* Makes `root` option implicitely default to `process.cwd()`.
 * Fixed issue [#376](https://github.com/jakubpawlowicz/clean-css/issues/376) - option to disable `0[unit]` -> `0`.
 * Fixed issue [#396](https://github.com/jakubpawlowicz/clean-css/issues/396) - better input source maps tracking.
 * Fixed issue [#480](https://github.com/jakubpawlowicz/clean-css/issues/480) - extracting uppercase property names.
index daa778f..67f083b 100644 (file)
@@ -32,6 +32,7 @@ var CleanCSS = module.exports = function CleanCSS(options) {
     benchmark: options.benchmark,
     compatibility: new Compatibility(options.compatibility).toOptions(),
     debug: options.debug,
+    explicitRoot: !!options.root,
     inliner: options.inliner || {},
     keepBreaks: options.keepBreaks || false,
     keepSpecialComments: 'keepSpecialComments' in options ? options.keepSpecialComments : '*',
@@ -40,7 +41,7 @@ var CleanCSS = module.exports = function CleanCSS(options) {
     rebase: undefined === options.rebase ? true : !!options.rebase,
     relativeTo: options.relativeTo,
     restructuring: undefined === options.restructuring ? true : !!options.restructuring,
-    root: options.root,
+    root: options.root || process.cwd(),
     roundingPrecision: options.roundingPrecision,
     shorthandCompacting: !!options.sourceMap ? false : (undefined === options.shorthandCompacting ? true : !!options.shorthandCompacting),
     sourceMap: options.sourceMap,
index 1068b73..6d25470 100644 (file)
@@ -11,8 +11,8 @@ UrlRebase.prototype.process = function (data) {
   var options = this.outerContext.options;
 
   var rebaseOpts = {
-    absolute: !!options.root,
-    relative: !options.root && !!options.target,
+    absolute: options.explicitRoot,
+    relative: !options.explicitRoot && !!options.target,
     fromBase: options.relativeTo
   };
 
index 9440550..44a695e 100644 (file)
@@ -16,7 +16,7 @@ function ImportInliner (context) {
 }
 
 ImportInliner.prototype.process = function (data, context) {
-  var root = this.outerContext.options.root || process.cwd();
+  var root = this.outerContext.options.root;
 
   context = override(context, {
     baseRelativeTo: this.outerContext.options.relativeTo || root,
index 587174a..27cbac6 100644 (file)
@@ -34,7 +34,7 @@ Tokenizer.prototype.toTokens = function (data) {
     source: undefined
   };
 
-  if (this.minifyContext.options.root)
+  if (this.minifyContext.options.explicitRoot)
     context.resolvePath = absolutePathResolver(context);
   else if (this.minifyContext.options.target)
     context.resolvePath = relativePathResolver(context);
@@ -51,7 +51,7 @@ function absolutePathResolver(context) {
 }
 
 function relativePathResolver(context) {
-  var rebaseTo = path.resolve(process.cwd(), context.outer.options.target);
+  var rebaseTo = path.resolve(context.outer.options.root, context.outer.options.target);
   if (!fs.existsSync(rebaseTo) || fs.statSync(rebaseTo).isFile())
     rebaseTo = path.dirname(rebaseTo);
 
index 8b22a40..bc9c95e 100644 (file)
@@ -35,15 +35,15 @@ function fromArray(outerContext, sources) {
 
 function fromHash(outerContext, sources) {
   var data = [];
-  var toBase = path.resolve(outerContext.options.target || process.cwd());
+  var toBase = path.resolve(outerContext.options.target || outerContext.options.root);
 
   for (var source in sources) {
     var styles = sources[source].styles;
     var inputSourceMap = sources[source].sourceMap;
 
     var rewriter = new UrlRewriter({
-      absolute: !!outerContext.options.root,
-      relative: !outerContext.options.root,
+      absolute: outerContext.options.explicitRoot,
+      relative: !outerContext.options.explicitRoot,
       imports: true,
       urls: outerContext.options.rebase,
       fromBase: path.dirname(path.resolve(source)),