vigour-util
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "vigour-util", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Vigour.io <dev@vigour.io>", | ||
@@ -43,6 +43,12 @@ "scripts": { | ||
"nightmare": "^2.2.0", | ||
"node-lessify": "^0.1.1", | ||
"tap-difflet": "^0.4.0", | ||
"tape": "^4.5.1", | ||
"vigour-base": "^2.0.0" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"node-lessify" | ||
] | ||
} | ||
} |
@@ -408,5 +408,7 @@ <!-- VDOC.badges travis; standard; npm --> | ||
```javascript | ||
require('vigour-util/require') | ||
var enhanceRequire = require('vigour-util/require') | ||
enhanceRequire() | ||
require('styles.less') // ignored in node, processed elsewhere | ||
// Don't forget to add a browserify transform or similar for non-node | ||
enhanceRequire.restore() | ||
``` |
@@ -9,2 +9,4 @@ 'use strict' | ||
var originalRequire = require | ||
if (isNode) { // else let browserify (or similar) do it | ||
@@ -34,5 +36,19 @@ var require = function require (path) { | ||
require.next = Module.prototype.require | ||
module.exports = enhanceRequire | ||
} else { | ||
module.exports = enhanceRequireMock | ||
} | ||
function enhanceRequire (options) { | ||
Module.prototype.require = require | ||
} | ||
enhanceRequire.restore = function restoreRequire () { | ||
Module.prototype.require = originalRequire | ||
} | ||
module.exports = {} | ||
function enhanceRequireMock (options) { | ||
// Do nothing | ||
} | ||
enhanceRequireMock.restore = function restoreRequireMock () { | ||
// Do nothing | ||
} |
'use strict' | ||
var test = require('tape') | ||
var isNode = require('../is/node') | ||
test('require', function (t) { | ||
t.plan(1) | ||
require('../require') | ||
// require('./_files/styles.less') | ||
// require('./_files/styles.css') | ||
// require('./_files/scratch/this-should-be-ignored') | ||
t.equals(1, 1, 'required styles should be ignored in node') | ||
t.plan(3) | ||
var enhanceRequire = require('../require') | ||
var count = 0 | ||
try { | ||
require('./_files/styles.less') | ||
} catch (e) { | ||
count += 1 | ||
} | ||
t.equals(count, isNode ? 1 : 0, "`require('vigour-util/require')` shouldn't have any effect") | ||
enhanceRequire() | ||
count = 0 | ||
try { | ||
require('./_files/styles.less') | ||
require('./_files/styles.css') | ||
require('./_files/scratch/this-should-be-ignored') | ||
} catch (e) { | ||
count += 1 | ||
} | ||
t.equals(count, 0, "`require('vigour-util/require')()` makes `require` ignore styles and scratch") | ||
enhanceRequire.restore() | ||
count = 0 | ||
try { | ||
require('./_files/styles.less') | ||
} catch (e) { | ||
count += 1 | ||
} | ||
t.equals(count, isNode ? 1 : 0, "`require('vigour-util/require').restore()` should restore the original `require`") | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71445
1700
414
6
4