From d625bac17edd7e3f1c39e3a3b8ad16269100cec2 Mon Sep 17 00:00:00 2001 From: bencergazda Date: Wed, 30 Oct 2019 14:23:37 +0100 Subject: [PATCH] chore(release): 1.1.0 --- CHANGELOG.md | 25 +++++++++++ ...ionsToNodeSass.js => JSFunctionsToSass.js} | 43 ++++++++++--------- dist/{JSVarsToNodeSass.js => JSVarsToSass.js} | 43 +++++++++++-------- ...arsToSassString.js => JSVarsToSassData.js} | 41 ++++++++++-------- dist/{NodeSassVarsToJs.js => SassVarsToJS.js} | 27 +++++++----- dist/node.js | 24 +++++------ package-lock.json | 2 +- package.json | 2 +- 8 files changed, 125 insertions(+), 82 deletions(-) create mode 100644 CHANGELOG.md rename dist/{JSFunctionsToNodeSass.js => JSFunctionsToSass.js} (81%) rename dist/{JSVarsToNodeSass.js => JSVarsToSass.js} (87%) rename dist/{JSVarsToSassString.js => JSVarsToSassData.js} (87%) rename dist/{NodeSassVarsToJs.js => SassVarsToJS.js} (82%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e624445 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# Changelog + +## 1.1.0 (2019-10-30) + +### Features + +* Adding support for Dart Sass ([ea9f65b5](https://github.com/body-builder/jsass/commit/ea9f65b5e27e1abd648f7f6743748a89456c1f33)) + +### API changes + +* Changing the names (and file path) of many classes ([adefaa71](https://github.com/body-builder/jsass/commit/adefaa71c77a22d6f3f36e6ce5ce184bd90d98f6)) + + To be more straightforward, as we are supporting not exclusively `node-sass` + + | Old name | New name | + |---|---| + | JSFunctionsToNodeSass | JSFunctionsToSass | + | JSVarsToNodeSass | JSVarsToSass | + | NodeSassVarsToJs | SassVarsToJS | + | JSVarsToSassString | JSVarsToSassData | + + (We should create a new major version in normal case, but since the package is quite new (1wo), we make an exception this time. Hopefully we will not have to change the API in the near future.) + +## 1.0.0 (2019-10-18) +Initial release diff --git a/dist/JSFunctionsToNodeSass.js b/dist/JSFunctionsToSass.js similarity index 81% rename from dist/JSFunctionsToNodeSass.js rename to dist/JSFunctionsToSass.js index bd7d04c..034491d 100644 --- a/dist/JSFunctionsToNodeSass.js +++ b/dist/JSFunctionsToSass.js @@ -16,15 +16,15 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var kindOf = require('kind-of'); -var JSVarsToNodeSass = require('./JSVarsToNodeSass'); +var JSVarsToSass = require('./JSVarsToSass'); -var NodeSassVarsToJs = require('./NodeSassVarsToJs'); +var SassVarsToJS = require('./SassVarsToJS'); -var JSFunctionsToNodeSass = +var JSFunctionsToSass = /*#__PURE__*/ function () { - function JSFunctionsToNodeSass(options) { - _classCallCheck(this, JSFunctionsToNodeSass); + function JSFunctionsToSass(options) { + _classCallCheck(this, JSFunctionsToSass); this._default_options = { listSeparator: ', ', @@ -32,18 +32,21 @@ function () { }; this._options = Object.assign({}, this._default_options, options); - this._jsVarsToNodeSass = new JSVarsToNodeSass(); - this._nodeSassVarsToJs = new NodeSassVarsToJs(); + this.implementation = this._options.implementation || require('node-sass'); + this._jsVarsToSass = new JSVarsToSass({ + implementation: this.implementation + }); + this._sassVarsToJS = new SassVarsToJS(); this.convert = this._wrapObject; } /** * Parses the Sass function declaration string and returns the extracted information in an Object - * @param key The Sass function declaration string (the `key` of the node-sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' + * @param key The Sass function declaration string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' * @returns {null|{name: string, args: string[], spreadArgs: number[]}} */ - _createClass(JSFunctionsToNodeSass, [{ + _createClass(JSFunctionsToSass, [{ key: "_getSassFunctionData", value: function _getSassFunctionData(key) { var matches = key.replace(')', '').split('('); // The name of the Sass function @@ -97,7 +100,7 @@ function () { } if (kindOf(args) !== 'array') { - throw new Error('JSFunctionsToSass - do not forget to pass the arguments from node-sass!'); + throw new Error('JSFunctionsToSass - do not forget to pass the arguments from Sass!'); } options = Object.assign({}, this._options, options); @@ -105,11 +108,11 @@ function () { var sassFunctionData = this._getSassFunctionData(sass_decl); var done = args.slice(-1)[0]; - var sassTypeArgs = args.slice(0, -1); // Converting raw node-sass type arguments to JS + var sassTypeArgs = args.slice(0, -1); // Converting raw Sass type arguments to JS var jsTypeArgs = []; sassTypeArgs.forEach(function (sassTypeArg, index) { - var jsTypeArg = _this._nodeSassVarsToJs._convert(sassTypeArg, options); // If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function. + var jsTypeArg = _this._sassVarsToJS._convert(sassTypeArg, options); // If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function. if (kindOf(jsTypeArg) === 'array' && sassFunctionData.spreadArgs.indexOf(index) !== -1) { @@ -124,24 +127,24 @@ function () { try { value = fn.apply(null, jsTypeArgs); } catch (error) { - return this._jsVarsToNodeSass._convert(this._createError(error), options); - } // Returning JS values in node-sass types + return this._jsVarsToSass._convert(this._createError(error), options); + } // Returning JS values in Sass types if (value instanceof Promise) { if (kindOf(done) !== 'function') { - throw new Error('JSFunctionsToSass - no callback provided from node-sass!'); + throw new Error('JSFunctionsToSass - no callback provided from Sass!'); } // TODO Finish error handling tests // eslint-disable-next-line prettier/prettier value["catch"](function (error) { - return done(_this._jsVarsToNodeSass._convert(_this._createError(error), options)); + return done(_this._jsVarsToSass._convert(_this._createError(error), options)); }).then(function (resolved) { - return done(_this._jsVarsToNodeSass._convert(resolved, options)); + return done(_this._jsVarsToSass._convert(resolved, options)); }); } else { - return this._jsVarsToNodeSass._convert(value, options); + return this._jsVarsToSass._convert(value, options); } } }, { @@ -174,7 +177,7 @@ function () { } }]); - return JSFunctionsToNodeSass; + return JSFunctionsToSass; }(); -module.exports = JSFunctionsToNodeSass; \ No newline at end of file +module.exports = JSFunctionsToSass; \ No newline at end of file diff --git a/dist/JSVarsToNodeSass.js b/dist/JSVarsToSass.js similarity index 87% rename from dist/JSVarsToNodeSass.js rename to dist/JSVarsToSass.js index dcd7809..41a2063 100644 --- a/dist/JSVarsToNodeSass.js +++ b/dist/JSVarsToSass.js @@ -26,21 +26,20 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var colorString = require('color-string'); -var sass = require('node-sass'); - var kindOf = require('kind-of'); -var JSVarsToNodeSass = +var JSVarsToSass = /*#__PURE__*/ function () { - function JSVarsToNodeSass(options) { - _classCallCheck(this, JSVarsToNodeSass); + function JSVarsToSass(options) { + _classCallCheck(this, JSVarsToSass); var _default_options = { listSeparator: ', ', strict: true }; this._options = Object.assign({}, _default_options, options); + this.implementation = this._options.implementation || require('node-sass'); this.unitKeywords_spec = ['cm', 'mm', 'in', 'px', 'pt', 'pc', 'em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', '%']; this.unitKeywords_experimental = ['Q', 'cap', 'ic', 'lh', 'rlh', 'vi', 'vb']; this.unitKeywords = [].concat(_toConsumableArray(this.unitKeywords_spec), _toConsumableArray(this.unitKeywords_experimental)); @@ -48,7 +47,7 @@ function () { return this; } - _createClass(JSVarsToNodeSass, [{ + _createClass(JSVarsToSass, [{ key: "_isVariable", value: function _isVariable(value) { return value.startsWith('$'); @@ -67,7 +66,7 @@ function () { if (arguments[1] !== undefined) { options = _defineProperty({}, options, arguments[1]); } else { - throw new Error('JSVarsToNodeSass: setOption needs an option'); + throw new Error('JSVarsToSass: setOption needs an option'); } } @@ -162,11 +161,11 @@ function () { default: if (this._options.strict === false) { - return sass.types.String("[JS ".concat(type.replace(/./, function (x) { + return new this.implementation.types.String("[JS ".concat(type.replace(/./, function (x) { return x.toUpperCase(); }), "]")); } else { - throw new Error('JSVarsToNodeSass - Unexpected variable type `' + kindOf(value) + '`'); + throw new Error('JSVarsToSass - Unexpected variable type `' + kindOf(value) + '`'); } } @@ -174,17 +173,23 @@ function () { }, { key: "_convert_null", value: function _convert_null(value, options) { - return sass.types.Null(); + return this.implementation.types.Null.NULL; } }, { key: "_convert_boolean", value: function _convert_boolean(value, options) { - return sass.types.Boolean(value); + switch (value) { + case true: + return this.implementation.types.Boolean.TRUE; + + case false: + return this.implementation.types.Boolean.FALSE; + } } }, { key: "_convert_error", value: function _convert_error(value, options) { - return sass.types.Error(value.message); + return new this.implementation.types.Error(value.message); } /** * Converts a JS Number or a { value: Number, unit: String } object to a SassNumber instance @@ -204,7 +209,7 @@ function () { }; } - return sass.types.Number(value.value, value.unit); + return new this.implementation.types.Number(value.value, value.unit); } /** * Converts a JS String to a SassString instance @@ -230,7 +235,7 @@ function () { return this._convert_number(hasUnit, options); } - return sass.types.String(value); + return new this.implementation.types.String(value); } }, { key: "_convert_color", @@ -239,7 +244,7 @@ function () { g = _ref.g, b = _ref.b, a = _ref.a; - return new sass.types.Color(r, g, b, a); + return new this.implementation.types.Color(r, g, b, a); } }, { key: "_convert_array", @@ -247,7 +252,7 @@ function () { var _this = this; if (kindOf(value) !== 'array') throw new Error('JSFunctionsToSass - _convert_array() needs an array, but got `' + kindOf(value) + '`'); - var list = new sass.types.List(value.length, options.listSeparator.trim() === ','); + var list = new this.implementation.types.List(value.length, options.listSeparator.trim() === ','); value.map(function (item, index) { return list.setValue(index, _this._convert(item, options)); }); @@ -259,7 +264,7 @@ function () { var _this2 = this; if (kindOf(value) !== 'object') throw new Error('JSFunctionsToSass - _convert_object() needs an array, but got `' + kindOf(value) + '`'); - var map = new sass.types.Map(Object.keys(value).length); + var map = new this.implementation.types.Map(Object.keys(value).length); Object.keys(value).map(function (key, index) { map.setKey(index, _this2._convert(key, options)); map.setValue(index, _this2._convert(value[key], options)); @@ -268,7 +273,7 @@ function () { } }]); - return JSVarsToNodeSass; + return JSVarsToSass; }(); -module.exports = JSVarsToNodeSass; \ No newline at end of file +module.exports = JSVarsToSass; \ No newline at end of file diff --git a/dist/JSVarsToSassString.js b/dist/JSVarsToSassData.js similarity index 87% rename from dist/JSVarsToSassString.js rename to dist/JSVarsToSassData.js index 9f337cc..a921553 100644 --- a/dist/JSVarsToSassString.js +++ b/dist/JSVarsToSassData.js @@ -26,32 +26,32 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func var kindOf = require('kind-of'); -var JSVarsToNodeSass = require('./JSVarsToNodeSass'); +var JSVarsToSass = require('./JSVarsToSass'); -var NodeSassVarsToJs = require('./NodeSassVarsToJs'); +var SassVarsToJS = require('./SassVarsToJS'); /** * Converts JS variables (Bool, Number, String, Array, Object) to the 'corresponding' Sass variable definitions (Array -> List, Object -> Map, String -> String|Color|Unit, etc...) - * Important: This Class outputs string data, which can be passed to the `data` option of node-sass (see https://github.com/sass/node-sass#data) + * Important: This Class outputs string data, which can be passed to the `data` option of Sass (see https://github.com/sass/node-sass#data) */ -var JSVarsToSassString = +var JSVarsToSassData = /*#__PURE__*/ -function (_JSVarsToNodeSass) { - _inherits(JSVarsToSassString, _JSVarsToNodeSass); +function (_JSVarsToSass) { + _inherits(JSVarsToSassData, _JSVarsToSass); /** * @param options - * @returns {{setOption: JSVarsToSassString.setOption|*, convert: JSVarsToSassString._iterator|*}} + * @returns {{setOption: JSVarsToSassData.setOption|*, convert: JSVarsToSassData._iterator|*}} * @constructor */ - function JSVarsToSassString(options) { + function JSVarsToSassData(options) { var _this; - _classCallCheck(this, JSVarsToSassString); + _classCallCheck(this, JSVarsToSassData); // prettier-ignore - _this = _possibleConstructorReturn(this, _getPrototypeOf(JSVarsToSassString).call(this, Object.assign({}, { + _this = _possibleConstructorReturn(this, _getPrototypeOf(JSVarsToSassData).call(this, Object.assign({}, { syntax: 'scss', quotedKeys: true, // Though Sass allows map keys to be of any Sass type, it is recommended to use quoted strings to avoid confusing problems (see https://sass-lang.com/documentation/values/maps) @@ -61,14 +61,17 @@ function (_JSVarsToNodeSass) { important: false, "default": false, global: false - } + }, + implementation: options.implementation || require('node-sass') }, options))); _this.convert = _this._iterator; - _this._nodeSassVarsToJs = new NodeSassVarsToJs(); + _this._sassVarsToJS = new SassVarsToJS({ + implementation: _this._options.implementation + }); return _possibleConstructorReturn(_this, _assertThisInitialized(_this)); } - _createClass(JSVarsToSassString, [{ + _createClass(JSVarsToSassData, [{ key: "_stringify", value: function _stringify(value, options) { return options.quote + value + options.quote; @@ -77,10 +80,10 @@ function (_JSVarsToNodeSass) { key: "_convert", value: function _convert(value) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._options; - value = _get(_getPrototypeOf(JSVarsToSassString.prototype), "_convert", this).call(this, value, options); // The super function may itself return value in edge-cases, and those values are in Sass types. We need to resolve it. + value = _get(_getPrototypeOf(JSVarsToSassData.prototype), "_convert", this).call(this, value, options); // The super function may itself return value in edge-cases, and those values are in Sass types. We need to resolve it. if (kindOf(value).startsWith('sass')) { - return this._convert(this._nodeSassVarsToJs.convert(value), options); + return this._convert(this._sassVarsToJS.convert(value), options); } return value; @@ -94,7 +97,7 @@ function (_JSVarsToNodeSass) { key: "_convert_boolean", value: function _convert_boolean(value, options) { return JSON.stringify(value); - } // _convert_error is implemented only because of JSFunctionsToNodeSass, we "skip" it here. + } // _convert_error is implemented only because of JSFunctionsToSass, we "skip" it here. }, { key: "_convert_error", @@ -201,7 +204,7 @@ function (_JSVarsToNodeSass) { } }]); - return JSVarsToSassString; -}(JSVarsToNodeSass); + return JSVarsToSassData; +}(JSVarsToSass); -module.exports = JSVarsToSassString; \ No newline at end of file +module.exports = JSVarsToSassData; \ No newline at end of file diff --git a/dist/NodeSassVarsToJs.js b/dist/SassVarsToJS.js similarity index 82% rename from dist/NodeSassVarsToJs.js rename to dist/SassVarsToJS.js index d4524af..5aed9e8 100644 --- a/dist/NodeSassVarsToJs.js +++ b/dist/SassVarsToJS.js @@ -8,13 +8,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var colorString = require('color-string'); -var kindOf = require('kind-of'); - -var NodeSassVarsToJs = +var SassVarsToJS = /*#__PURE__*/ function () { - function NodeSassVarsToJs(options) { - _classCallCheck(this, NodeSassVarsToJs); + function SassVarsToJS(options) { + _classCallCheck(this, SassVarsToJS); this._default_options = {}; this._options = Object.assign({}, this._default_options, options); @@ -22,7 +20,7 @@ function () { return this; } - _createClass(NodeSassVarsToJs, [{ + _createClass(SassVarsToJS, [{ key: "_convert_null", value: function _convert_null(value, options) { return null; @@ -93,8 +91,16 @@ function () { key: "_convert", value: function _convert(value) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._options; + var kindOfValue; + + if (value.dartValue) { + kindOfValue = value.dartValue.constructor.name.toLowerCase(); + } else { + // This does not rule it out that we are using _not_ a Dart Sass implementation. For example, `types.Null.NULL` in `Dart Sass` doesn't have a `dartValue` property. + kindOfValue = value.constructor.name.toLowerCase(); + } - switch (kindOf(value)) { + switch (kindOfValue) { case 'sassnull': return this._convert_null(value, options); @@ -111,18 +117,19 @@ function () { return this._convert_string(value, options); case 'sasslist': + case 'sassargumentlist': return this._convert_array(value, options); case 'sassmap': return this._convert_object(value, options); default: - throw new Error('NodeSassVarsToJs - Unexpected node-sass variable type `' + kindOf(value) + '`'); + throw new Error('SassVarsToJS - Unexpected Sass variable type `' + kindOfValue + '`'); } } }]); - return NodeSassVarsToJs; + return SassVarsToJS; }(); -module.exports = NodeSassVarsToJs; \ No newline at end of file +module.exports = SassVarsToJS; \ No newline at end of file diff --git a/dist/node.js b/dist/node.js index 2af026e..a61baf6 100644 --- a/dist/node.js +++ b/dist/node.js @@ -9,28 +9,28 @@ Object.defineProperty(exports, "jSass_extract", { return _jSassExtract["default"]; } }); -Object.defineProperty(exports, "JSFunctionsToNodeSass", { +Object.defineProperty(exports, "JSFunctionsToSass", { enumerable: true, get: function get() { - return _JSFunctionsToNodeSass["default"]; + return _JSFunctionsToSass["default"]; } }); -Object.defineProperty(exports, "JSVarsToNodeSass", { +Object.defineProperty(exports, "JSVarsToSass", { enumerable: true, get: function get() { - return _JSVarsToNodeSass["default"]; + return _JSVarsToSass["default"]; } }); -Object.defineProperty(exports, "JSVarsToSassString", { +Object.defineProperty(exports, "JSVarsToSassData", { enumerable: true, get: function get() { - return _JSVarsToSassString["default"]; + return _JSVarsToSassData["default"]; } }); -Object.defineProperty(exports, "NodeSassVarsToJs", { +Object.defineProperty(exports, "SassVarsToJS", { enumerable: true, get: function get() { - return _NodeSassVarsToJs["default"]; + return _SassVarsToJS["default"]; } }); Object.defineProperty(exports, "jsVarsToDefinePlugin", { @@ -42,13 +42,13 @@ Object.defineProperty(exports, "jsVarsToDefinePlugin", { var _jSassExtract = _interopRequireDefault(require("./jSass-extract")); -var _JSFunctionsToNodeSass = _interopRequireDefault(require("./JSFunctionsToNodeSass")); +var _JSFunctionsToSass = _interopRequireDefault(require("./JSFunctionsToSass")); -var _JSVarsToNodeSass = _interopRequireDefault(require("./JSVarsToNodeSass")); +var _JSVarsToSass = _interopRequireDefault(require("./JSVarsToSass")); -var _JSVarsToSassString = _interopRequireDefault(require("./JSVarsToSassString")); +var _JSVarsToSassData = _interopRequireDefault(require("./JSVarsToSassData")); -var _NodeSassVarsToJs = _interopRequireDefault(require("./NodeSassVarsToJs")); +var _SassVarsToJS = _interopRequireDefault(require("./SassVarsToJS")); var _jsVarsToDefinePlugin = _interopRequireDefault(require("./jsVarsToDefinePlugin")); diff --git a/package-lock.json b/package-lock.json index 5f85aa2..2f22b30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jsass", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 84b2873..e033f99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jsass", - "version": "1.0.0", + "version": "1.1.0", "description": "Pass and convert data between JS and node-sass", "homepage": "https://github.com/body-builder/jsass#readme", "repository": "https://github.com/body-builder/jsass",