From 7d557e681bba9a18e04c80e08f0d24257ab78293 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 15 Mar 2015 14:05:30 +0000 Subject: [PATCH] Makes `root` option implicitely default to `process.cwd()` unless given. --- History.md | 1 + lib/clean.js | 3 ++- lib/images/url-rebase.js | 4 ++-- lib/imports/inliner.js | 2 +- lib/selectors/tokenizer.js | 4 ++-- lib/utils/source-reader.js | 6 +++--- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/History.md b/History.md index 4f411a50..a7c6e0fa 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/lib/clean.js b/lib/clean.js index daa778fb..67f083b0 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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, diff --git a/lib/images/url-rebase.js b/lib/images/url-rebase.js index 1068b730..6d25470b 100644 --- a/lib/images/url-rebase.js +++ b/lib/images/url-rebase.js @@ -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 }; diff --git a/lib/imports/inliner.js b/lib/imports/inliner.js index 94405509..44a695ea 100644 --- a/lib/imports/inliner.js +++ b/lib/imports/inliner.js @@ -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, diff --git a/lib/selectors/tokenizer.js b/lib/selectors/tokenizer.js index 587174aa..27cbac66 100644 --- a/lib/selectors/tokenizer.js +++ b/lib/selectors/tokenizer.js @@ -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); diff --git a/lib/utils/source-reader.js b/lib/utils/source-reader.js index 8b22a40f..bc9c95e3 100644 --- a/lib/utils/source-reader.js +++ b/lib/utils/source-reader.js @@ -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)), -- 2.34.1