Socket
Socket
Sign inDemoInstall

lodash-webpack-plugin

Package Overview
Dependencies
1
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

82

lib/index.js

@@ -27,24 +27,28 @@ 'use strict';

var reLodashPath = RegExp('/lodash(?:/(?!fp/)|-es/|-amd/)');
var reLodashRaw = RegExp('^lodash(?:/|-es/|-amd/)\\w+$');
var rePath = RegExp('/lodash(?:/(?!fp/)|-es/|-amd/)');
var reRequest = RegExp('^lodash(?:/|-es/|-amd/)\\w+$');
var stubs = ['./identity.js', './noop.js', './stubArray.js', './stubFalse.js', './stubObject.js', './stubString.js', './stubTrue.js'];
function getPatterns(options) {
var result = [];
_lodash2.default.forOwn(_mapping.features, function (pairs, key) {
if (!options[key]) {
_lodash2.default.each(pairs, function (pair) {
result.push(['/' + pair[0] + '.js', './' + pair[1] + '.js']);
});
}
});
return result;
}
/*----------------------------------------------------------------------------*/
var LodashModuleReplacementPlugin = function () {
function LodashModuleReplacementPlugin(options) {
var _this = this;
_classCallCheck(this, LodashModuleReplacementPlugin);
options || (options = {});
this.matches = [];
this.patterns = [];
_lodash2.default.forOwn(_mapping.features, function (pairs, key) {
if (!options[key]) {
_lodash2.default.each(pairs, function (pair) {
_this.patterns.push(['/' + pair[0] + '.js', './' + pair[1] + '.js']);
});
}
});
this.options = options || {};
this.patterns = getPatterns(this.options);
}

@@ -55,3 +59,3 @@

value: function apply(compiler) {
var _this2 = this;
var _this = this;

@@ -62,19 +66,20 @@ var resolvePath = _lodash2.default.memoize(function (data) {

if (reLodashPath.test(resource)) {
var length = _this2.patterns.length;
while (length--) {
var pair = _this2.patterns[length];
// Replace the resource if it end swith the first pattern of the pair as
// long as it isn't an explicit request for a module which is to be stubbed.
if (_lodash2.default.endsWith(resource, pair[0]) && !(reLodashRaw.test(rawRequest) && _lodash2.default.includes(stubs, pair[1]))) {
var result = _path2.default.resolve(_path2.default.dirname(resource), pair[1]);
if (_fs2.default.existsSync(result)) {
_this2.matches.push([resource, result]);
return result;
}
}
var result = resource;
if (!rePath.test(resource)) {
return result;
}
_lodash2.default.each(_this.patterns, function (pair) {
// Replace the resource, if it ends with the first pattern of the pair,
// as long as it isn't an explicit request for a stubbed module.
if (!_lodash2.default.endsWith(resource, pair[0]) || reRequest.test(rawRequest) && _lodash2.default.includes(stubs, pair[1])) {
return;
}
}
return resource;
var modulePath = _path2.default.resolve(_path2.default.dirname(resource), pair[1]);
if (_fs2.default.existsSync(modulePath)) {
result = modulePath;
_this.matches.push([resource, result]);
return false;
}
});
return result;
}, function (data) {

@@ -85,2 +90,17 @@ return data.resource;

compiler.plugin('normal-module-factory', function (nmf) {
nmf.plugin('before-resolve', function (data, callback) {
if (!data) {
return callback();
}
var request = data.request;
if (reRequest.test(request)) {
var override = _mapping.overrides[_path2.default.basename(request, '.js')];
if (!_lodash2.default.isMatch(_this.options, override)) {
_this.patterns = getPatterns(_lodash2.default.assign(_this.options, override));
}
}
return callback(null, data);
});
nmf.plugin('after-resolve', function (data, callback) {

@@ -87,0 +107,0 @@ if (!data) {

@@ -16,3 +16,3 @@ 'use strict';

'metadata': [['_baseSetData', 'identity'], ['_getData', 'noop'], ['_mergeData', 'identity'], ['_setData', 'identity']],
'paths': [['_castPath', 'identity'], ['_isKey', 'identity']],
'paths': [['_baseGet', '_getValue'], ['_castPath', 'identity'], ['_isKey', 'identity'], ['has', '_baseHas'], ['hasIn', '_baseHasIn'], ['property', '_baseProperty']],
'placeholders': [['_composeArgs', 'identity'], ['_composeArgsRight', 'identity'], ['_getHolder', 'noop'], ['_getPlaceholder', 'noop'], ['_replaceHolders', 'stubArray'], ['_replaceHolders', 'constant']],

@@ -22,2 +22,8 @@ 'shorthands': [['_baseIteratee', 'identity']]

exports.default = { features: features };
var overrides = exports.overrides = {
'curry': { 'currying': true },
'curryRight': { 'currying': true },
'partialRight': { 'currying': true }
};
exports.default = { features: features, overrides: overrides };
{
"name": "lodash-webpack-plugin",
"version": "0.4.0",
"version": "0.5.0",
"description": "Smaller modular Lodash builds.",

@@ -24,7 +24,7 @@ "keywords": "webpack-plugin, lodash, modules",

"devDependencies": {
"babel-cli": "^6.7.7",
"babel-core": "^6.7.7",
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "~0.2.1",
"babel-plugin-lodash": "^3.1.3",
"babel-plugin-lodash": "^3.1.4",
"babel-preset-es2015": "^6.6.0",

@@ -31,0 +31,0 @@ "bluebird": "^3.3.5",

@@ -1,2 +0,2 @@

# lodash-webpack-plugin v0.4.0
# lodash-webpack-plugin v0.5.0

@@ -3,0 +3,0 @@ Create smaller Lodash builds by replacing [feature sets](#feature-sets) of modules

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc