Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support options.requires fallback for backward compatibility #286

Merged
merged 4 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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