diff --git a/api.ru.md b/api.ru.md index 747240a..bf59be6 100644 --- a/api.ru.md +++ b/api.ru.md @@ -47,7 +47,9 @@ #### requires -Тип: `Object`. По умолчанию: `{}`. +Устарело! Используйте `engineOptions.requires`. + +Тип: `Object`. По умолчанию: `undefined`. Задает имена или пути для подключения сторонних библиотек. @@ -198,7 +200,9 @@ var BemhtmlTech = require('enb-bemxjst/techs/bemhtml'), #### requires -Тип: `Object`. По умолчанию: `{}`. +Устарело! Используйте `engineOptions.requires`. + +Тип: `Object`. По умолчанию: `undefined`. Задает имена или пути для подключения сторонних библиотек. diff --git a/lib/bundle.js b/lib/bundle.js index c473632..662a516 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -11,13 +11,22 @@ var compileCommonJS = require('./compile-commonjs'), * @param {Object} options Options. * @param {String} opts.dirname Path to a directory with compiled file. * @param {String} [options.exportName=BEMHTML] Name for exports. - * @param {Object} [options.requires={}] Names for dependencies. + * @param {Object} [options.requires={}] Deprecated. Fallback for backward + * compatibility, use options.engineOptions.requires * @returns {String} */ exports.compile = function (code, options) { options || (options = {}); - var requires = options.requires || {}; + var requires; + + if (options.requires) { + requires = options.requires; + } else if (options.engineOptions && options.engineOptions.requires) { + requires = options.engineOptions.requires; + } else { + requires = {}; + } return compileCommonJS(requires, options.dirname) .then(function (commonJSModules) { diff --git a/package-lock.json b/package-lock.json index 0f789c9..4ffb6e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,14 +46,14 @@ "resolved": "https://registry.npmjs.org/acorn-node/-/acorn-node-1.3.0.tgz", "integrity": "sha512-efP54n3d1aLfjL2UMdaXa6DsswwzJeI5rqhbFvXMrKiJ6eJFpf+7R0zN7t8IC+XKn2YOAFAv6xbBNgHUkoHWLw==", "requires": { - "acorn": "5.4.1", + "acorn": "5.5.0", "xtend": "4.0.1" }, "dependencies": { "acorn": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.4.1.tgz", - "integrity": "sha512-XLmq3H/BVvW6/GbxKryGxWORz1ebilSsUDlyC27bXhWGWAZWkGwS6FLHjOlwFXNFoWFQEO/Df4u0YYd0K3BQgQ==" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.0.tgz", + "integrity": "sha512-arn53F07VXmls4o4pUhSzBa4fvaagPRe7AVZ8l7NHxFWUie2DsuFSBMMNAkgzRlOhEhzAnxeKyaWVzOH4xqp/g==" } } }, @@ -64,7 +64,7 @@ "dev": true, "requires": { "co": "4.6.0", - "fast-deep-equal": "1.0.0", + "fast-deep-equal": "1.1.0", "fast-json-stable-stringify": "2.0.0", "json-schema-traverse": "0.3.1" } @@ -329,7 +329,7 @@ "htmlescape": "1.1.1", "https-browserify": "0.0.1", "inherits": "2.0.3", - "insert-module-globals": "7.0.1", + "insert-module-globals": "7.0.2", "JSONStream": "1.3.2", "labeled-stream-splicer": "2.0.0", "module-deps": "4.1.1", @@ -340,7 +340,7 @@ "punycode": "1.4.1", "querystring-es3": "0.2.1", "read-only-stream": "2.0.0", - "readable-stream": "2.3.4", + "readable-stream": "2.3.5", "resolve": "1.5.0", "shasum": "1.0.2", "shell-quote": "1.6.1", @@ -671,7 +671,7 @@ "integrity": "sha1-PAPwd2uGo239mgosl8YwfzMggv4=", "dev": true, "requires": { - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "concat-map": { @@ -928,14 +928,14 @@ "resolved": "https://registry.npmjs.org/detective/-/detective-4.7.1.tgz", "integrity": "sha512-H6PmeeUcZloWtdt4DAkFyzFL94arpHr3NOwwmVILFiy+9Qd4JTxxXrzfyGk/lmct2qVGBwTSwSXagqu2BxmWig==", "requires": { - "acorn": "5.4.1", + "acorn": "5.5.0", "defined": "1.0.0" }, "dependencies": { "acorn": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.4.1.tgz", - "integrity": "sha512-XLmq3H/BVvW6/GbxKryGxWORz1ebilSsUDlyC27bXhWGWAZWkGwS6FLHjOlwFXNFoWFQEO/Df4u0YYd0K3BQgQ==" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.0.tgz", + "integrity": "sha512-arn53F07VXmls4o4pUhSzBa4fvaagPRe7AVZ8l7NHxFWUie2DsuFSBMMNAkgzRlOhEhzAnxeKyaWVzOH4xqp/g==" } } }, @@ -1023,7 +1023,7 @@ "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", "integrity": "sha1-ixLauHjA1p4+eJEFFmKjL8a93ME=", "requires": { - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "ee-first": { @@ -1257,21 +1257,21 @@ } }, "eslint": { - "version": "4.18.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.18.0.tgz", - "integrity": "sha512-Ep2lUbztzXLg0gNUl48I1xvbQFy1QuWyh1C9PSympmln33jwOr8B3QfuEcXpPPE4uSwEzDaWhUxBN0sNQkzrBg==", + "version": "4.18.2", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.18.2.tgz", + "integrity": "sha512-qy4i3wODqKMYfz9LUI8N2qYDkHkoieTbiHpMrYUI/WbjhXJQr7lI4VngixTgaG+yHX+NBCv7nW4hA0ShbvaNKw==", "dev": true, "requires": { "ajv": "5.5.2", "babel-code-frame": "6.26.0", - "chalk": "2.3.1", - "concat-stream": "1.6.0", + "chalk": "2.3.2", + "concat-stream": "1.6.1", "cross-spawn": "5.1.0", "debug": "3.1.0", "doctrine": "2.1.0", "eslint-scope": "3.7.1", "eslint-visitor-keys": "1.0.0", - "espree": "3.5.3", + "espree": "3.5.4", "esquery": "1.0.0", "esutils": "2.0.2", "file-entry-cache": "2.0.0", @@ -1308,33 +1308,33 @@ "dev": true }, "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { "color-convert": "1.9.1" } }, "chalk": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz", - "integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", "dev": true, "requires": { - "ansi-styles": "3.2.0", + "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", - "supports-color": "5.2.0" + "supports-color": "5.3.0" } }, "concat-stream": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", - "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.1.tgz", + "integrity": "sha512-gslSSJx03QKa59cIKqeJO9HQ/WZMotvYJCuaUULrLpjj8oG40kV2Z+gz82pVxlTkOADi4PJxQPPfhl1ELYrrXw==", "dev": true, "requires": { "inherits": "2.0.3", - "readable-stream": "2.3.4", + "readable-stream": "2.3.5", "typedarray": "0.0.6" } }, @@ -1363,9 +1363,9 @@ } }, "supports-color": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz", - "integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", "dev": true, "requires": { "has-flag": "3.0.0" @@ -1385,7 +1385,7 @@ "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", "dev": true, "requires": { - "esrecurse": "4.2.0", + "esrecurse": "4.2.1", "estraverse": "4.2.0" } }, @@ -1396,19 +1396,19 @@ "dev": true }, "espree": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.3.tgz", - "integrity": "sha512-Zy3tAJDORxQZLl2baguiRU1syPERAIg0L+JB2MWorORgTu/CplzvxS9WWA7Xh4+Q+eOQihNs/1o1Xep8cvCxWQ==", + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", "dev": true, "requires": { - "acorn": "5.4.1", + "acorn": "5.5.0", "acorn-jsx": "3.0.1" }, "dependencies": { "acorn": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.4.1.tgz", - "integrity": "sha512-XLmq3H/BVvW6/GbxKryGxWORz1ebilSsUDlyC27bXhWGWAZWkGwS6FLHjOlwFXNFoWFQEO/Df4u0YYd0K3BQgQ==", + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.0.tgz", + "integrity": "sha512-arn53F07VXmls4o4pUhSzBa4fvaagPRe7AVZ8l7NHxFWUie2DsuFSBMMNAkgzRlOhEhzAnxeKyaWVzOH4xqp/g==", "dev": true } } @@ -1429,13 +1429,12 @@ } }, "esrecurse": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.0.tgz", - "integrity": "sha1-+pVo2Y04I/mkHZHpAtyrnqblsWM=", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", "dev": true, "requires": { - "estraverse": "4.2.0", - "object-assign": "4.1.1" + "estraverse": "4.2.0" } }, "estraverse": { @@ -1494,9 +1493,9 @@ "dev": true }, "fast-deep-equal": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz", - "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, "fast-json-stable-stringify": { @@ -1685,6 +1684,12 @@ "ansi-regex": "2.1.1" } }, + "has-color": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/has-color/-/has-color-0.1.7.tgz", + "integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=", + "dev": true + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -1847,7 +1852,7 @@ "dev": true, "requires": { "ansi-escapes": "3.0.0", - "chalk": "2.3.1", + "chalk": "2.3.2", "cli-cursor": "2.1.0", "cli-width": "2.2.0", "external-editor": "2.1.0", @@ -1869,23 +1874,23 @@ "dev": true }, "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { "color-convert": "1.9.1" } }, "chalk": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz", - "integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", "dev": true, "requires": { - "ansi-styles": "3.2.0", + "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", - "supports-color": "5.2.0" + "supports-color": "5.3.0" } }, "strip-ansi": { @@ -1898,9 +1903,9 @@ } }, "supports-color": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz", - "integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", "dev": true, "requires": { "has-flag": "3.0.0" @@ -1909,9 +1914,9 @@ } }, "insert-module-globals": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-7.0.1.tgz", - "integrity": "sha1-wDv04BywhtW15azorQr+eInWOMM=", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-7.0.2.tgz", + "integrity": "sha512-p3s7g96Nm62MbHRuj9ZXab0DuJNWD7qcmdUXCOQ/ZZn42DtDXfsLill7bq19lDCx3K3StypqUnuE3H2VmIJFUw==", "requires": { "combine-source-map": "0.7.2", "concat-stream": "1.5.2", @@ -2112,7 +2117,7 @@ "js-yaml": "3.4.6", "jscs-jsdoc": "2.0.0", "jscs-preset-wikimedia": "1.0.0", - "jsonlint": "1.6.2", + "jsonlint": "1.6.3", "lodash": "3.10.1", "minimatch": "3.0.4", "natural-compare": "1.2.2", @@ -2261,13 +2266,13 @@ "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" }, "jsonlint": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/jsonlint/-/jsonlint-1.6.2.tgz", - "integrity": "sha1-VzcEUIX1XrRVxosf9OvAG9UOiDA=", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/jsonlint/-/jsonlint-1.6.3.tgz", + "integrity": "sha512-jMVTMzP+7gU/IyC6hvKyWpUU8tmTkK5b3BPNuMI9U8Sit+YAWLlZwB6Y6YrdCxfg2kNz05p3XY3Bmm4m26Nv3A==", "dev": true, "requires": { "JSV": "4.0.2", - "nomnom": "2.0.0" + "nomnom": "1.8.1" } }, "jsonparse": { @@ -2679,7 +2684,7 @@ "inherits": "2.0.3", "JSONStream": "1.3.2", "parents": "1.0.1", - "readable-stream": "2.3.4", + "readable-stream": "2.3.5", "resolve": "1.5.0", "stream-combiner2": "1.1.1", "subarg": "1.0.0", @@ -2725,9 +2730,9 @@ "dev": true }, "nise": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.2.5.tgz", - "integrity": "sha512-Es4hGuq3lpip5PckrB+Qpuma282M0UJANJ+jxAgI+0wWTL9X6MtNv+M385JgqsAE8hv6NvD3lv8CQtXgEnvlpQ==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.3.0.tgz", + "integrity": "sha512-U+Krdzhsw4losPP/Rij5UGTLQgS9gaWmXdRIbZQIQWVsUGDBo+N0m9mrY9CCEnmwssgswwydxLJUZtFfouC0gA==", "dev": true, "requires": { "@sinonjs/formatio": "2.0.0", @@ -2746,10 +2751,39 @@ } }, "nomnom": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/nomnom/-/nomnom-2.0.0.tgz", - "integrity": "sha512-frks+w18/6p+nAJ+zd6DdPpBytjt4tdTVnRY9nK4GoiCtG4gVgLs4MR+LCm83Bq4JtN6ol7a10BSPsS/qE+2dA==", - "dev": true + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/nomnom/-/nomnom-1.8.1.tgz", + "integrity": "sha1-IVH3Ikcrp55Qp2/BJbuMjy5Nwqc=", + "dev": true, + "requires": { + "chalk": "0.4.0", + "underscore": "1.6.0" + }, + "dependencies": { + "ansi-styles": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz", + "integrity": "sha1-yxAt8cVvUSPquLZ817mAJ6AnkXg=", + "dev": true + }, + "chalk": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz", + "integrity": "sha1-UZmj3c0MHv4jvAjBsCewYXbgxk8=", + "dev": true, + "requires": { + "ansi-styles": "1.0.0", + "has-color": "0.1.7", + "strip-ansi": "0.1.1" + } + }, + "strip-ansi": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz", + "integrity": "sha1-OeipjQRNFQZgq+SmgIrPcLt7yZE=", + "dev": true + } + } }, "nopt": { "version": "3.0.6", @@ -3145,13 +3179,13 @@ "resolved": "https://registry.npmjs.org/read-only-stream/-/read-only-stream-2.0.0.tgz", "integrity": "sha1-JyT9aoET1zdkrCiNQ4YnDB2/F/A=", "requires": { - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "readable-stream": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.4.tgz", - "integrity": "sha512-vuYxeWYM+fde14+rajzqgeohAI7YoJcHE7kXDAc4Nk0EbuKnJfqtY9YtRkLo/tqkuF7MsBQRhPnPeyjYITp3ZQ==", + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.5.tgz", + "integrity": "sha512-tK0yDhrkygt/knjowCUiWP9YdV7c5R+8cR0r/kt9ZhBU906Fs6RpQJCEilamRJj1Nx2rWI6LkW9gKqjTkshhEw==", "requires": { "core-util-is": "1.0.2", "inherits": "2.0.3", @@ -3401,24 +3435,24 @@ "dev": true }, "sinon": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-4.3.0.tgz", - "integrity": "sha512-pmf05hFgEZUS52AGJcsVjOjqAyJW2yo14cOwVYvzCyw7+inv06YXkLyW75WG6X6p951lzkoKh51L2sNbR9CDvw==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-4.4.2.tgz", + "integrity": "sha512-cpOHpnRyY3Dk9dTHBYMfVBB0HUCSKIpxW07X6OGW2NiYPovs4AkcL8Q8MzecbAROjbfRA9esJCmlZgikxDz7DA==", "dev": true, "requires": { "@sinonjs/formatio": "2.0.0", "diff": "3.2.0", "lodash.get": "4.4.2", "lolex": "2.3.2", - "nise": "1.2.5", - "supports-color": "5.2.0", + "nise": "1.3.0", + "supports-color": "5.3.0", "type-detect": "4.0.8" }, "dependencies": { "supports-color": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz", - "integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", "dev": true, "requires": { "has-flag": "3.0.0" @@ -3473,7 +3507,7 @@ "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", "requires": { "inherits": "2.0.3", - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "stream-combiner2": { @@ -3482,7 +3516,7 @@ "integrity": "sha1-+02KFCDqNidk4hrUeAOXvry0HL4=", "requires": { "duplexer2": "0.1.4", - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "stream-http": { @@ -3492,7 +3526,7 @@ "requires": { "builtin-status-codes": "3.0.0", "inherits": "2.0.3", - "readable-stream": "2.3.4", + "readable-stream": "2.3.5", "to-arraybuffer": "1.0.1", "xtend": "4.0.1" } @@ -3503,7 +3537,7 @@ "integrity": "sha1-G2O+Q4oTPktnHMGTUZdgAXWRDYM=", "requires": { "inherits": "2.0.3", - "readable-stream": "2.3.4" + "readable-stream": "2.3.5" } }, "string_decoder": { @@ -3597,36 +3631,36 @@ "requires": { "ajv": "5.5.2", "ajv-keywords": "2.1.1", - "chalk": "2.3.1", + "chalk": "2.3.2", "lodash": "4.17.4", "slice-ansi": "1.0.0", "string-width": "2.1.1" }, "dependencies": { "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { "color-convert": "1.9.1" } }, "chalk": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz", - "integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", "dev": true, "requires": { - "ansi-styles": "3.2.0", + "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", - "supports-color": "5.2.0" + "supports-color": "5.3.0" } }, "supports-color": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz", - "integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", "dev": true, "requires": { "has-flag": "3.0.0" @@ -3656,7 +3690,7 @@ "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz", "integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=", "requires": { - "readable-stream": "2.3.4", + "readable-stream": "2.3.5", "xtend": "4.0.1" } }, @@ -3743,6 +3777,12 @@ "resolved": "https://registry.npmjs.org/umd/-/umd-3.0.1.tgz", "integrity": "sha1-iuVW4RAR9jwllnCKiDclnwGz1g4=" }, + "underscore": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz", + "integrity": "sha1-izixDKze9jM3uLJOT/htRa6lKag=", + "dev": true + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/techs/bem-xjst.js b/techs/bem-xjst.js index f1276b0..caa160a 100644 --- a/techs/bem-xjst.js +++ b/techs/bem-xjst.js @@ -122,7 +122,18 @@ module.exports = buildFlow.create() engineOptions.naming = this._naming; } - engineOptions.exportName = engineOptions.exportName || this._exportName; + engineOptions.exportName || (engineOptions.exportName = this._exportName); + + if (this._requires) { + this.node.getLogger().logOptionIsDeprecated( + this.node.unmaskTargetName(this._target), + 'enb-bemxjst', + this.getName(), + 'requires', + 'engineOptions.requires', + ' It will be removed in v9.0.0.' + ); + } engineOptions.sourceMap = { from: this._target }; diff --git a/techs/bemhtml.js b/techs/bemhtml.js index 5ad6778..0a4042f 100644 --- a/techs/bemhtml.js +++ b/techs/bemhtml.js @@ -14,7 +14,8 @@ var path = require('path'); * @param {String} [options.filesTarget='?.files'] Path to a target with FileList. * @param {String[]} [options.sourceSuffixes] Files with specified suffixes involved in the assembly. * @param {String} [options.exportName='BEMHTML'] Name of BEMHTML template variable. - * @param {Object} [options.requires] Names of dependencies which should be available from + * @param {Object} [options.requires] Deprecated! Use `engineOptions.requires` instead. + * Names of dependencies which should be available from * code of templates. * @param {Boolean} [options.forceBaseTemplates=false] Include base templates if no user templates present * @param {Object} [options.engineOptions] Proxies options to bem-xjst @@ -52,7 +53,7 @@ module.exports = require('./bem-xjst').buildFlow() .defineOption('exportName', 'BEMHTML') .defineOption('naming') .defineOption('engineOptions') - .defineOption('requires', {}) + .defineOption('requires') .defineOption('iife', false) .defineOption('sourcemap', false) .defineOption('forceBaseTemplates', false) diff --git a/techs/bemtree.js b/techs/bemtree.js index 4d8a4ef..166be1d 100644 --- a/techs/bemtree.js +++ b/techs/bemtree.js @@ -14,7 +14,8 @@ var path = require('path'); * @param {String} [options.filesTarget='?.files'] Path to a target with FileList. * @param {String[]} [options.sourceSuffixes] Files with specified suffixes involved in the assembly. * @param {String} [options.exportName='BEMTREE'] Name of BEMTREE template variable. - * @param {Object} [options.requires] Names of dependencies which should be available from + * @param {Object} [options.requires] Deprecated! Use `engineOptions.requires` instead. + * Names of dependencies which should be available from * code of templates. * @param {Object} [options.engineOptions] Proxies options to bem-xjst * @param {Boolean} [options.forceBaseTemplates=false] Include base templates if no user templates present @@ -45,7 +46,7 @@ module.exports = require('./bem-xjst').buildFlow() .target('target', '?.bemtree.js') .defineOption('exportName', 'BEMTREE') .defineOption('engineOptions') - .defineOption('requires', {}) + .defineOption('requires') .defineOption('forceBaseTemplates', false) .useFileList(['bemtree.js']) .builder(function (fileList) { diff --git a/test/techs/bemhtml.test.js b/test/techs/bemhtml.test.js index d46029a..e23f94c 100644 --- a/test/techs/bemhtml.test.js +++ b/test/techs/bemhtml.test.js @@ -1,12 +1,17 @@ var fs = require('fs'), path = require('path'), mock = require('mock-fs'), + assert = require('assert'), MockNode = require('mock-enb/lib/mock-node'), Tech = require('../../techs/bemhtml'), loadDirSync = require('mock-enb/utils/dir-utils').loadDirSync, FileList = require('enb/lib/file-list'), bundlePath = path.resolve('lib/bundle.js'), - sinon = require('sinon'); + sinon = require('sinon'), + utils = require('../utils'), + run = function (code) { + return utils.run(code, { runtime: 'node' }); + }; describe('bemhtml', function () { before(function () { @@ -22,27 +27,29 @@ describe('bemhtml', function () { mock.restore(); }); - it('must generate mock if there is no templates', function () { - var templates = []; + describe('option: forceBaseTemplates', function () { + it('must generate mock if there is no templates', function () { + var templates = []; - return build(templates) - .spread(function (res) { - var bemjson = { block: 'block' }; + return build(templates) + .spread(function (res) { + var bemjson = { block: 'block' }; - res.BEMHTML.apply(bemjson).must.be(''); - }); - }); + res.BEMHTML.apply(bemjson).must.be(''); + }); + }); - it('must keep base templates if there is no templates and forceBaseTemplates option is true', function () { - var templates = []; + it('must keep base templates if there is no templates and forceBaseTemplates option is true', function () { + var templates = []; - return build(templates, { forceBaseTemplates: true }) - .spread(function (res) { - var bemjson = { block: 'block' }, - html = '
'; + return build(templates, { forceBaseTemplates: true }) + .spread(function (res) { + var bemjson = { block: 'block' }, + html = '
'; - res.BEMHTML.apply(bemjson).must.be(html); - }); + res.BEMHTML.apply(bemjson).must.be(html); + }); + }); }); it('must use `bemhtml.js` suffix', function () { @@ -60,7 +67,7 @@ describe('bemhtml', function () { }); }); - describe('base templates', function () { + describe('option: sourceSuffixes and base templates', function () { it('must ignore templates in `i-bem`', function () { var blocks = { 'i-bem.bemhtml.js': 'block("block").tag()("a")' @@ -90,7 +97,7 @@ describe('bemhtml', function () { }); }); - describe('naming', function () { + describe('option: naming', function () { it('must use origin naming', function () { var blocks = { 'block.bemhtml.js': 'block("block").tag()("div")' @@ -120,7 +127,7 @@ describe('bemhtml', function () { }); }); - describe('engineOptions', function () { + describe('option: engineOptions', function () { beforeEach(function () { sinon.stub(console, 'error'); }); @@ -143,7 +150,7 @@ describe('bemhtml', function () { }); }); - it('must add i-bem class with elemJsInstances option', function () { + it('should support engineOptions.elemJsInstances', function () { var blocks = { 'block.bemhtml.js': 'block("block").tag()("div")' }; @@ -157,7 +164,7 @@ describe('bemhtml', function () { }); }); - it('must support custom naming', function () { + it('should support engineOptions.naming', function () { var blocks = { 'block.bemhtml.js': 'block("block").tag()("div")' }; @@ -171,24 +178,7 @@ describe('bemhtml', function () { }); }); - it('must throw if template error in dev mode', function () { - var blocks = { - 'block.bemhtml.js': [ - 'block("block").attrs()(function() {', - ' var attrs = applyNext();', - ' attrs.undef.foo = "bar";', - ' return attrs;', - '});' - ].join('\n') - }; - - return build(blocks) - .fail(function (error) { - error.message.must.be.include('Cannot read property'); - }); - }); - - it('must skip template error in production mode', function () { + it('should support engineOptions.production', function () { var blocks = { 'block.bemhtml.js': [ 'block("block").attrs()(function() {', @@ -222,7 +212,7 @@ describe('bemhtml', function () { }); }); - it('must support off escaping for html tags', function () { + it('should support engineOptions.escapeContent', function () { var blocks = { 'block.bemhtml.js': 'block("block").tag()("div")' }; @@ -235,9 +225,35 @@ describe('bemhtml', function () { res.BEMHTML.apply(bemjson).must.be(html); }); }); + + it('should support engineOptions.exportName fallback for backward compatibility', function () { + var blocks = { 'b.bemhtml.js': 'block("b").tag()("span")' }; + + return build(blocks, { engineOptions: { exportName: 'htmlMaker' } }) + .spread(function (res) { + assert(res.htmlMaker, 'No BEMHTML exported as htmlMaker'); + + res + .htmlMaker + .apply({ block: 'b' }) + .must.be(''); + }); + }); + + it('should support engineOptions.requires', function () { + var code = 'global.text = "Hello world!"', + options = { + engineOptions: { requires: { text: { globals: 'text' } } } + }; + + return utils.compileBundle(code, options) + .then(run) + .then(utils.getLibs) + .should.become({ text: 'Hello world!' }); + }); }); - describe('compat', function () { + describe('option: compat', function () { it('must throw error if old syntax', function () { var templates = ['block bla, tag: "a"']; @@ -260,6 +276,26 @@ describe('bemhtml', function () { }); }); + describe('option: iife', function () { + it('should wrap templates into Immediately-Invoked Function Expression', function () { + var blocks = { + 'one.bemhtml.js': 'var private = 42;', + 'two.bemhtml.js': 'block("b").content()(function() { return private; });' + }; + + return build(blocks, { iife: true }) + .spread(function (res) { res.BEMHTML.apply({ block: 'b' }); }) + .fail(function (error) { + error.message.must.be.include('Template error in mode content in block b\n' + + ' private is not defined\n'); + }); + }); + }); + + describe('option: sourcemap', function () { + // TODO + }); + describe('handle template errors', function () { it('must throw syntax error', function () { var templates = ['block("bla")tag()("a")']; @@ -278,6 +314,23 @@ describe('bemhtml', function () { error.message.must.be.include('Predicate should not have arguments'); }); }); + + it('must throw if template error in dev mode', function () { + var blocks = { + 'block.bemhtml.js': [ + 'block("block").attrs()(function() {', + ' var attrs = applyNext();', + ' attrs.undef.foo = "bar";', + ' return attrs;', + '});' + ].join('\n') + }; + + return build(blocks) + .fail(function (error) { + error.message.must.be.include('Cannot read property'); + }); + }); }); }); diff --git a/test/techs/bemtree.test.js b/test/techs/bemtree.test.js index b766e90..6089e3d 100644 --- a/test/techs/bemtree.test.js +++ b/test/techs/bemtree.test.js @@ -5,7 +5,12 @@ var fs = require('fs'), Tech = require('../../techs/bemtree'), loadDirSync = require('mock-enb/utils/dir-utils').loadDirSync, FileList = require('enb/lib/file-list'), - bundlePath = path.resolve('lib/bundle.js'); + bundlePath = path.resolve('lib/bundle.js'), + assert = require('assert'), + utils = require('../utils'), + run = function (code) { + return utils.run(code, { runtime: 'node' }); + }; describe('bemtree', function () { before(function () { @@ -138,6 +143,33 @@ describe('bemtree', function () { res.BEMTREE.apply(data).must.eql(bemjson); }); }); + + it('must support engineOptions.exportName fallback for backward compatibility', function () { + var blocks = { 'b.bemtree.js': 'block("b").content()("test")' }; + + return build(blocks, { engineOptions: { exportName: 'bemtreeMaker' } }) + .spread(function (res) { + assert(res.bemtreeMaker, 'No BEMTREE exported as bemtreeMaker'); + + res + .bemtreeMaker + .apply({ block: 'b' }) + .content + .must.be('test'); + }); + }); + + it('must support engineOptions.requires', function () { + var code = 'global.text = "Hello world!"', + options = { + engineOptions: { requires: { text: { globals: 'text' } } } + }; + + return utils.compileBundle(code, options) + .then(run) + .then(utils.getLibs) + .should.become({ text: 'Hello world!' }); + }); }); describe('compat', function () { diff --git a/test/unit/bundle--browser+ym.test.js b/test/unit/bundle--browser+ym.test.js index 5deadf2..1f9f893 100644 --- a/test/unit/bundle--browser+ym.test.js +++ b/test/unit/bundle--browser+ym.test.js @@ -12,7 +12,7 @@ describe('bundle --browser+ym', function () { it('must get dependency from global scope', function () { var code = 'window.text = "Hello world!"', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text' } @@ -28,7 +28,7 @@ describe('bundle --browser+ym', function () { it('must get dependency from global scope using dot-delimited key', function () { var code = 'window.text = { text: "Hello world!" };', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text.text' } @@ -44,7 +44,7 @@ describe('bundle --browser+ym', function () { it('must require dependency from ym', function () { var code = 'modules.define("text", [], function (provide) { provide("Hello world!"); })', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { ym: 'text' } @@ -77,7 +77,7 @@ describe('bundle --browser+ym', function () { it('must require module from CommonJS', function () { var options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { commonJS: 'fake' } @@ -100,7 +100,7 @@ describe('bundle --browser+ym', function () { '});' ].join(EOL), options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { ym: 'text', commonJS: 'fake' diff --git a/test/unit/bundle--browser.test.js b/test/unit/bundle--browser.test.js index a02167e..f9dd7e0 100644 --- a/test/unit/bundle--browser.test.js +++ b/test/unit/bundle--browser.test.js @@ -19,7 +19,7 @@ describe('bundle --browser', function () { it('must get dependency from global scope', function () { var code = 'window.text = "Hello world!"', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text' } @@ -35,7 +35,7 @@ describe('bundle --browser', function () { it('must get dependency from global scope using dot-delimited key', function () { var code = 'window.text = { text: "Hello world!" };', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text.text' } @@ -68,7 +68,7 @@ describe('bundle --browser', function () { it('must require module from CommonJS', function () { var options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { commonJS: 'fake' } @@ -87,7 +87,7 @@ describe('bundle --browser', function () { it('must get dependency from global scope if it also is presented in CommonJS', function () { var code = 'window.fake = { getText: function () { return "globals"; } };', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { globals: 'fake', commonJS: 'fake' diff --git a/test/unit/bundle--node.test.js b/test/unit/bundle--node.test.js index 3fa8037..52726c7 100644 --- a/test/unit/bundle--node.test.js +++ b/test/unit/bundle--node.test.js @@ -19,7 +19,7 @@ describe('bundle --node', function () { it('must get dependency from global scope', function () { var code = 'global.text = "Hello world!"', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text' } @@ -35,7 +35,7 @@ describe('bundle --node', function () { it('must get dependency from global scope using dot-delimited key', function () { var code = 'global.text = { text: "Hello world!" };', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires text: { globals: 'text.text' } @@ -68,7 +68,7 @@ describe('bundle --node', function () { it('must require module from CommonJS', function () { var options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { commonJS: 'fake' } @@ -87,7 +87,7 @@ describe('bundle --node', function () { it('must get dependency from CommonJS if it also is presented in global scope', function () { var code = 'global.fake = { getText: function () { return "globals"; } };', options = { - requires: { + requires: { // fallback for backward compatibility, use engineOptions.requires fake: { globals: 'fake', commonJS: 'fake'