From a577ec4ffe156adf74540f1bd13efff5ef0d38cc Mon Sep 17 00:00:00 2001 From: Vasiliy Loginevskiy Date: Thu, 14 Sep 2017 00:12:17 +0300 Subject: [PATCH] Time of changes --- index.js | 30 +++++++++++------------------- package.json | 2 +- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index ce29262..51f1fe8 100644 --- a/index.js +++ b/index.js @@ -1,30 +1,22 @@ 'use strict'; -var bemjsonToDecl = require('bemjson-to-decl'); -var loaderUtils = require('loader-utils'); +const bemjsonToDecl = require('bemjson-to-decl'); +const nEval = require('node-eval'); /** - * Converts bemjson file to bemdecl - * - * **query** - * - * * @param {boolean} stringify + * Extract bemdecl from bemjson * * @param {string} source - * @return {string} */ module.exports = function (source) { this.cacheable && this.cacheable(); + const callback = this.async(); - var bemjson = this.exec(source, this.resourcePath); - var query = loaderUtils.parseQuery(this.query); - var shouldStringify = typeof query.stringify === 'boolean' - ? query.stringify - : true; - - if (shouldStringify) { - return 'module.exports = ' + bemjsonToDecl.stringify(bemjson); - } - - return bemjsonToDecl.convert(bemjson); + new Promise(resolve => { + const bemjson = nEval(source); + const decls = bemjsonToDecl.convert(bemjson); + resolve(decls); + }) + .then(res => callback(null, res)) + .catch(callback); }; diff --git a/package.json b/package.json index bfbe757..a92fb13 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "homepage": "https://github.com/sullenor/bemjson-loader#readme", "dependencies": { "bemjson-to-decl": "^1.0.1", - "loader-utils": "^0.2.16" + "node-eval": "^1.1.0" }, "devDependencies": { "debug": "^2.2.0",