Skip to content

Commit

Permalink
Merge pull request #286 from /issues/285.requires.tadatuta
Browse files Browse the repository at this point in the history
Support options.requires fallback for backward compatibility
  • Loading branch information
miripiruni authored Mar 5, 2018
2 parents d1a0520 + 1552380 commit 28103c3
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 172 deletions.
8 changes: 6 additions & 2 deletions api.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

#### requires

Тип: `Object`. По умолчанию: `{}`.
Устарело! Используйте `engineOptions.requires`.

Тип: `Object`. По умолчанию: `undefined`.

Задает имена или пути для подключения сторонних библиотек.

Expand Down Expand Up @@ -198,7 +200,9 @@ var BemhtmlTech = require('enb-bemxjst/techs/bemhtml'),

#### requires

Тип: `Object`. По умолчанию: `{}`.
Устарело! Используйте `engineOptions.requires`.

Тип: `Object`. По умолчанию: `undefined`.

Задает имена или пути для подключения сторонних библиотек.

Expand Down
13 changes: 11 additions & 2 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 28103c3

Please sign in to comment.