Skip to content

Commit

Permalink
dropRequireCache replaced with require-cache module
Browse files Browse the repository at this point in the history
  • Loading branch information
SwinX committed Sep 8, 2015
1 parent 3eeb929 commit 148dad6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ module.exports.createBuilder = function(options) { /* ... */ };
Пример использования:

```javascript
var clearRequire = require('clear-require');
var enbBuilder = require('enb/lib/server/server-middleware').createBuilder();
var dropRequireCache = require('enb/lib/fs/drop-require-cache');
app
.get('/', function (req, res, next) {
var bemhtmlFilePath = 'pages/index/index.bemhtml.js';
enbBuilder(bemhtmlFilePath).then(function() {
var bemhtmlAbsFilePath = process.process.cwd() + '/' + bemhtmlFilePath;
dropRequireCache(require, bemhtmlAbsFilePath);
clearRequire(bemhtmlAbsFilePath);
var bemhtml = require(bemhtmlAbsFilePath);
res.end(bemhtml.BEMHTML.apply({block: 'b-page', content: 'Hello World'}));
next();
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/cache-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ============
*/
var fs = require('fs');
var dropRequireCache = require('../fs/drop-require-cache');
var clearRequire = require('clear-require');
var Vow = require('vow');
var inherit = require('inherit');

Expand All @@ -29,7 +29,7 @@ var CacheStorage = inherit(/** @lends CacheStorage.prototype */ {
*/
load: function () {
if (fs.existsSync(this._filename)) {
dropRequireCache(require, this._filename);
clearRequire(this._filename);
try {
this._data = require(this._filename);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/config/project-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var ModeConfig = require('./mode-config');
var inherit = require('inherit');
var dirGlob = require('../fs/dir-glob');
var path = require('path');
var dropRequireCache = require('../fs/drop-require-cache');
var clearRequire = require('clear-require');

/**
* Инстанции класса ProjectConfig передаются в enb-make-файлы.
Expand Down Expand Up @@ -287,7 +287,7 @@ module.exports = inherit( /** @lends ProjectConfig.prototype */ {
includeConfig: function (filename) {
filename = require.resolve(filename);
(this._includedConfigFilenames || (this._includedConfigFilenames = [])).push(filename);
dropRequireCache(require, filename);
clearRequire(filename);
require(filename)(this);
return this;
},
Expand Down
4 changes: 2 additions & 2 deletions lib/fs/require-or-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
var asyncRequire = require('./async-require');
var vowFs = require('./async-fs');
var vm = require('vm');
var dropRequireCache = require('./drop-require-cache');
var clearRequire = require('clear-require');

/**
* @name requireOrEval
Expand All @@ -33,7 +33,7 @@ module.exports = function (filePath) {
var isWinPath = /^\w{1}:/.test(filePath);
filePath = isWinPath ? filePath.replace(/\//g, '\\') : filePath;

dropRequireCache(require, filePath);
clearRequire(filePath);
return asyncRequire(filePath).then(function (json) {
if (typeof json === 'object' && json !== null && !Array.isArray(json)) {
var hasData = false;
Expand Down
6 changes: 3 additions & 3 deletions lib/make.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Vow = require('vow');
var Node = require('./node');
var path = require('path');
var clearRequire = require('clear-require');
var Logger = require('./logger');
var colors = require('./ui/colorize');
var ProjectConfig = require('./config/project-config');
Expand All @@ -11,7 +12,6 @@ var vowFs = require('./fs/async-fs');
var fs = require('fs');
var BuildGraph = require('./ui/build-graph');
var TargetNotFoundError = require('./errors/target-not-found-error');
var dropRequireCache = require('./fs/drop-require-cache');
var SharedResources = require('./shared-resources');

/**
Expand Down Expand Up @@ -80,11 +80,11 @@ module.exports = inherit( /** @lends MakePlatform.prototype */ {

this._makefiles = [makefilePath, personalMakefilePath];

dropRequireCache(require, makefilePath);
clearRequire(makefilePath);
require(makefilePath)(projectConfig);

if (personalMakefilePath) {
dropRequireCache(require, personalMakefilePath);
clearRequire(personalMakefilePath);
require(personalMakefilePath)(projectConfig);
}
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
},
"dependencies": {
"borschik": "1.0.0",
"clear-require": "1.0.1",
"commander": "1.1.1",
"connect": "3.1.1",
"dom-js": "0.0.9",
"enb-source-map": "1.7.2",
"inherit": "~2.1.0",
"js-yaml": "2.1.0",
"lodash": "3.10.1",
Expand All @@ -61,8 +63,7 @@
"stylus": "0.40.x",
"vow": "~0.3.9",
"vow-fs": "~0.2.2",
"worker-farm": "1.3.1",
"enb-source-map": "1.7.2"
"worker-farm": "1.3.1"
},
"devDependencies": {
"bh": "0.1.14",
Expand Down
4 changes: 2 additions & 2 deletions test/lib/fs/async-fs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var vowFs = require('vow-fs');
var path = require('path');
var dropRequireCache = require('../../../lib/fs/drop-require-cache');
var clearRequire = require('clear-require');

describe('fs/async-fs', function () {
var previousLimit;
Expand All @@ -14,7 +14,7 @@ describe('fs/async-fs', function () {
});

beforeEach(function () {
dropRequireCache(require, asyncFsPath);
clearRequire(asyncFsPath);
optionsSpy.reset();
});

Expand Down
4 changes: 2 additions & 2 deletions test/lib/utils/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var vm = require('vm');
var clearRequire = require('clear-require');
var Logger = require('../../../lib/logger');
var dropRequireCache = require('../../../lib/fs/drop-require-cache');

describe('deprecate', function () {
var deprecate;
var deprecatePath = require.resolve('../../../lib/utils/deprecate.js');

beforeEach (function () {
//dropping cache because need to have uninitialized deprecate before each test
dropRequireCache(require, deprecatePath);
clearRequire(deprecatePath);
deprecate = require(deprecatePath);
sinon.sandbox.stub(Logger.prototype);
});
Expand Down

0 comments on commit 148dad6

Please sign in to comment.