initial commit
This commit is contained in:
10
node_modules/dynamic-dedupe/.jshintrc
generated
vendored
Normal file
10
node_modules/dynamic-dedupe/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"laxcomma" : true
|
||||
, "laxbreak" : true
|
||||
, "sub" : true
|
||||
, "onecase" : true
|
||||
, "node" : true
|
||||
, "expr" : true
|
||||
, "strict" : false
|
||||
, "validthis" : true
|
||||
}
|
15
node_modules/dynamic-dedupe/.npmignore
generated
vendored
Normal file
15
node_modules/dynamic-dedupe/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
||||
node_modules
|
23
node_modules/dynamic-dedupe/LICENSE
generated
vendored
Normal file
23
node_modules/dynamic-dedupe/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
Copyright 2013 Thorsten Lorenz.
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
110
node_modules/dynamic-dedupe/README.md
generated
vendored
Normal file
110
node_modules/dynamic-dedupe/README.md
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
# dynamic-dedupe
|
||||
|
||||
Dedupes node modules as they are being required which works even when dependencies are linked via ln -s or npm link.
|
||||
|
||||
### Not deduped
|
||||
|
||||
Loads `foo.js` module only twice.
|
||||
|
||||
```js
|
||||
var foo1 = require('./pack1/common/dep-uno/foo');
|
||||
var foo2 = require('./pack2/common/dep-uno/foo');
|
||||
|
||||
console.log(foo1.foo);
|
||||
console.log(foo2.foo);
|
||||
|
||||
console.log(foo1 === foo2);
|
||||
|
||||
// =>
|
||||
// loading foo from /Users/thlorenz/dev/projects/dynamic-dedupe/example/pack1/common/dep-uno
|
||||
// loading foo from /Users/thlorenz/dev/projects/dynamic-dedupe/example/pack2/common/dep-uno
|
||||
// foobiloo
|
||||
// foobiloo
|
||||
// false
|
||||
```
|
||||
|
||||
### Deduped
|
||||
|
||||
Loads `foo.js` module only once.
|
||||
|
||||
```js
|
||||
var dedupe = require('../');
|
||||
dedupe.activate();
|
||||
|
||||
var foo1 = require('./pack1/dep-uno/foo');
|
||||
var foo2 = require('./pack2/dep-uno/foo');
|
||||
|
||||
console.log(foo1.foo);
|
||||
console.log(foo2.foo);
|
||||
|
||||
console.log(foo1 === foo2);
|
||||
|
||||
// =>
|
||||
// loading foo from /Users/thlorenz/dev/projects/dynamic-dedupe/example/pack1/common/dep-uno
|
||||
// foobiloo
|
||||
// foobiloo
|
||||
// true
|
||||
```
|
||||
|
||||
Here instead of loading `pack2/dep-uno/foo1.js` we will get a reference to the exports of `pack1/dep-uno/foo`.js`
|
||||
returned.
|
||||
|
||||
|
||||
## Why?
|
||||
|
||||
In some cases an app may be split into multiple parts that need to get the same instance of a common dependency (i.e.
|
||||
Handlebars). This will work once you run `npm dedupe` from the main package. However once you try linking to a
|
||||
dependency via `npm link` or just `ln -s` it breaks.
|
||||
|
||||
This is where dynamic-dedupe comes in since it dedupes your modules as they are being required. Just **make sure that
|
||||
you are using the exact same version** of the packages whose modules you dedupe in order for this to work reliably.
|
||||
|
||||
## Installation
|
||||
|
||||
npm install dynamic-dedupe
|
||||
|
||||
## API
|
||||
|
||||
###*dedupe.activate([ext, subdirs])*
|
||||
|
||||
```
|
||||
/**
|
||||
* Activates deduping for files with the given extension.
|
||||
*
|
||||
* @name activate
|
||||
* @function
|
||||
* @param ext {String} (optional) extension for which to activate deduping (default: '.js')
|
||||
* @param subdirs {Number} (optional) how many subdirs right above the module
|
||||
* have to be the same in order for it to be considered identical (default: 2)
|
||||
*
|
||||
* Example: sudirs: 2 -- x/foo/bar/main.js === y/foo/bar/main.js
|
||||
* x/boo/bar/main.js !== y/foo/bar/main.js
|
||||
*/
|
||||
```
|
||||
|
||||
###*dedupe.deactivate([ext])*
|
||||
|
||||
```
|
||||
/**
|
||||
* Deactivates deduping files with the given extension.
|
||||
*
|
||||
* @name deactivate
|
||||
* @function
|
||||
* @param ext {String} (optional) extension for which to activate deduping (default: '.js')
|
||||
*/
|
||||
```
|
||||
|
||||
###*dedupe.reset()*
|
||||
|
||||
```
|
||||
/**
|
||||
* Clears the registry that contains previously loaded modules.
|
||||
*
|
||||
* @name reset
|
||||
* @function
|
||||
*/
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
10
node_modules/dynamic-dedupe/example/deduped.js
generated
vendored
Normal file
10
node_modules/dynamic-dedupe/example/deduped.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var dedupe = require('../');
|
||||
dedupe.activate();
|
||||
|
||||
var foo1 = require('./pack1/common/dep-uno/foo');
|
||||
var foo2 = require('./pack2/common/dep-uno/foo');
|
||||
|
||||
console.log(foo1.foo);
|
||||
console.log(foo2.foo);
|
||||
|
||||
console.log(foo1 === foo2);
|
7
node_modules/dynamic-dedupe/example/not-deduped.js
generated
vendored
Normal file
7
node_modules/dynamic-dedupe/example/not-deduped.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
var foo1 = require('./pack1/common/dep-uno/foo');
|
||||
var foo2 = require('./pack2/common/dep-uno/foo');
|
||||
|
||||
console.log(foo1.foo);
|
||||
console.log(foo2.foo);
|
||||
|
||||
console.log(foo1 === foo2);
|
4
node_modules/dynamic-dedupe/example/pack1/common/dep-uno/foo.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/example/pack1/common/dep-uno/foo.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
console.log('loading foo from', __dirname);
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
4
node_modules/dynamic-dedupe/example/pack2/common/dep-uno/foo.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/example/pack2/common/dep-uno/foo.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
console.log('loading foo from', __dirname);
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
80
node_modules/dynamic-dedupe/index.js
generated
vendored
Normal file
80
node_modules/dynamic-dedupe/index.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var xtend = require('xtend');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var loadeds = {};
|
||||
var extensions = xtend(require.extensions);
|
||||
|
||||
function getHash(data) {
|
||||
return crypto
|
||||
.createHash('md5')
|
||||
.update(data)
|
||||
.digest('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates deduping for files with the given extension.
|
||||
*
|
||||
* @name activate
|
||||
* @function
|
||||
* @param ext {String} (optional) extension for which to activate deduping (default: '.js')
|
||||
* @param subdirs {Number} (optional) how many subdirs right above the module
|
||||
* have to be the same in order for it to be considered identical (default: 2)
|
||||
*
|
||||
* Example: sudirs: 2 -- x/foo/bar/main.js === y/foo/bar/main.js
|
||||
* x/boo/bar/main.js !== y/foo/bar/main.js
|
||||
*/
|
||||
exports.activate = function (ext, subdirs) {
|
||||
ext = ext || '.js';
|
||||
subdirs = typeof subdirs === 'undefined' ? 2 : subdirs;
|
||||
|
||||
var ext_super = require.extensions[ext];
|
||||
|
||||
require.extensions[ext] = function dedupingExtension(module, file) {
|
||||
|
||||
var src = fs.readFileSync(file, 'utf8');
|
||||
|
||||
// hash includes filename and subdir name(s) to make override more strict
|
||||
var fulldir = path.dirname(file);
|
||||
var dirs = fulldir.split(path.sep);
|
||||
var dir = '';
|
||||
|
||||
for (var i = subdirs; i > 0 && dirs.length; i--) dir = dirs.pop() + dir;
|
||||
|
||||
var filename = path.basename(file);
|
||||
var hash = getHash(src + dir + filename);
|
||||
|
||||
var loaded = loadeds[hash];
|
||||
if (loaded) {
|
||||
module.exports = loaded.module.exports;
|
||||
} else {
|
||||
ext_super(module, file);
|
||||
loadeds[hash] = { file: file, module: module };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Deactivates deduping files with the given extension.
|
||||
*
|
||||
* @name deactivate
|
||||
* @function
|
||||
* @param ext {String} (optional) extension for which to activate deduping (default: '.js')
|
||||
*/
|
||||
exports.deactivate = function (ext) {
|
||||
ext = ext || '.js';
|
||||
require.extensions[ext] = extensions[ext];
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the registry that contains previously loaded modules.
|
||||
*
|
||||
* @name reset
|
||||
* @function
|
||||
*/
|
||||
exports.reset = function () {
|
||||
loadeds = {};
|
||||
};
|
44
node_modules/dynamic-dedupe/package.json
generated
vendored
Normal file
44
node_modules/dynamic-dedupe/package.json
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "dynamic-dedupe",
|
||||
"version": "0.3.0",
|
||||
"description": "Dedupes node modules as they are being required which works even when dependencies are linked via ln -s or npm link.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test-main": "tap test/*.js",
|
||||
"test-0.8": "nave use 0.8 npm run test-main",
|
||||
"test-0.10": "nave use 0.10 npm run test-main",
|
||||
"test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10",
|
||||
"test": "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/thlorenz/dynamic-dedupe.git"
|
||||
},
|
||||
"homepage": "https://github.com/thlorenz/dynamic-dedupe",
|
||||
"dependencies": {
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nave": "~0.4.3",
|
||||
"tap": "~0.4.3"
|
||||
},
|
||||
"keywords": [
|
||||
"dedupe",
|
||||
"npm",
|
||||
"require",
|
||||
"extension",
|
||||
"link"
|
||||
],
|
||||
"author": {
|
||||
"name": "Thorsten Lorenz",
|
||||
"email": "thlorenz@gmx.de",
|
||||
"url": "http://thlorenz.com"
|
||||
},
|
||||
"license": {
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/thlorenz/dynamic-dedupe/blob/master/LICENSE"
|
||||
},
|
||||
"engine": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
}
|
101
node_modules/dynamic-dedupe/test/dedupe.js
generated
vendored
Normal file
101
node_modules/dynamic-dedupe/test/dedupe.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
var dedupe = require('../');
|
||||
var count = require('./fixtures/count');
|
||||
|
||||
function reset() {
|
||||
var files = [
|
||||
'./fixtures/pack1/common/dep-uno/foo'
|
||||
, './fixtures/pack1/common/dep-uno/bar'
|
||||
, './fixtures/pack1/common/dep-dos/foo'
|
||||
, './fixtures/pack2/common/dep-uno/foo'
|
||||
, './fixtures/pack2/common/dep-uno/bar'
|
||||
].map(require.resolve);
|
||||
|
||||
files.forEach(function (k) { delete require.cache[k] });
|
||||
|
||||
dedupe.deactivate();
|
||||
dedupe.reset();
|
||||
count.count = 0;
|
||||
}
|
||||
|
||||
test('\nactive: when I require pack1/common/dep-uno/foo and pack2/common/dep-uno/foo', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js');
|
||||
var foo1 = require('./fixtures/pack1/common/dep-uno/foo');
|
||||
var foo2 = require('./fixtures/pack2/common/dep-uno/foo');
|
||||
|
||||
t.equal(count.count, 1, 'loads it only once')
|
||||
t.equal(foo1.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(foo2.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('\nactive: when I require pack1/common/dep-dos/foo and pack2/common/dep-uno/foo', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js');
|
||||
var foo1 = require('./fixtures/pack1/common/dep-dos/foo');
|
||||
var foo2 = require('./fixtures/pack2/common/dep-uno/foo');
|
||||
|
||||
t.equal(count.count, 2, 'loads it twice')
|
||||
t.equal(foo1.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(foo2.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('\nactive: when I require pack1/common/dep-uno/foo and pack1/common/dep-uno/bar', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js');
|
||||
var foo = require('./fixtures/pack1/common/dep-uno/foo');
|
||||
var bar = require('./fixtures/pack1/common/dep-uno/bar');
|
||||
|
||||
t.equal(count.count, 2, 'loads it twice')
|
||||
t.equal(foo.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(bar.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('\nactive: when I require pack1/common/dep-uno/bar and pack2/common/dep-uno/bar', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js');
|
||||
var bar1 = require('./fixtures/pack1/common/dep-uno/bar');
|
||||
var bar2 = require('./fixtures/pack2/common/dep-uno/bar');
|
||||
|
||||
t.equal(count.count, 1, 'loads it only once')
|
||||
t.equal(bar1.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(bar2.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('\nactive then deactivated: when I require pack1/common/dep-uno/foo and pack2/common/dep-uno/foo', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js');
|
||||
var foo1 = require('./fixtures/pack1/common/dep-uno/foo');
|
||||
dedupe.deactivate('.js');
|
||||
var foo2 = require('./fixtures/pack2/common/dep-uno/foo');
|
||||
|
||||
t.equal(count.count, 2, 'loads it twice')
|
||||
t.equal(foo1.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(foo2.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('\nactive: subdir 3, when I require pack1/common/dep-uno/foo and pack2/common/dep-uno/foo', function (t) {
|
||||
reset()
|
||||
|
||||
dedupe.activate('.js', 3);
|
||||
var foo1 = require('./fixtures/pack1/common/dep-uno/foo');
|
||||
var foo2 = require('./fixtures/pack2/common/dep-uno/foo');
|
||||
|
||||
t.equal(count.count, 2, 'loads it twice since only two subdirs match')
|
||||
t.equal(foo1.foo, 'foobiloo', 'returns exports 1')
|
||||
t.equal(foo2.foo, 'foobiloo', 'returns exports 2')
|
||||
t.end()
|
||||
})
|
1
node_modules/dynamic-dedupe/test/fixtures/count.js
generated
vendored
Normal file
1
node_modules/dynamic-dedupe/test/fixtures/count.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = { count: 0 };
|
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-dos/foo.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-dos/foo.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('../../../count').count++;
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-uno/bar.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-uno/bar.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('../../../count').count++;
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-uno/foo.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/test/fixtures/pack1/common/dep-uno/foo.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('../../../count').count++;
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
4
node_modules/dynamic-dedupe/test/fixtures/pack2/common/dep-uno/bar.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/test/fixtures/pack2/common/dep-uno/bar.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('../../../count').count++;
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
4
node_modules/dynamic-dedupe/test/fixtures/pack2/common/dep-uno/foo.js
generated
vendored
Normal file
4
node_modules/dynamic-dedupe/test/fixtures/pack2/common/dep-uno/foo.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('../../../count').count++;
|
||||
exports = module.exports = { foo: 'foobiloo' };
|
Reference in New Issue
Block a user