Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-merge

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-merge - npm Package Compare versions

Comparing version 4.1.2 to 4.1.3

10

CHANGELOG.md

@@ -0,1 +1,11 @@

4.1.3 / 2018-06-14
==================
* Fix - Smart merge respects the existing loader order #79, #101
4.1.2 / 2017-02-22
==================
* Maintenance - Update lodash, #97, #98
4.1.1 / 2017-11-01

@@ -2,0 +12,0 @@ ==================

98

lib/join-arrays-smart.js

@@ -12,6 +12,2 @@ 'use strict';

var _unionWith2 = require('lodash/unionWith');
var _unionWith3 = _interopRequireDefault(_unionWith2);
var _mergeWith2 = require('lodash/mergeWith');

@@ -94,6 +90,3 @@

default:
rule[loadersKey] = (0, _unionWith3.default)(
// Remove existing entries so that we can respect the order of the new
// entries
(0, _differenceWith3.default)(entries, newEntries, _isEqual3.default), newEntries, uniteEntries).map(unwrapEntry);
rule[loadersKey] = combineEntries(newEntries, entries).map(unwrapEntry);
}

@@ -129,3 +122,3 @@ }

function uniteEntries(newEntry, entry) {
function areEqualEntries(newEntry, entry) {
var loaderNameRe = /^([^?]+)/ig;

@@ -141,12 +134,89 @@

if (loaderName !== newLoaderName) {
return false;
return loaderName === newLoaderName;
}
function uniteEntries(newEntry, entry) {
if (areEqualEntries(newEntry, entry)) {
// Replace query values with newer ones
(0, _mergeWith3.default)(entry, newEntry);
return true;
}
return false;
}
// Replace query values with newer ones
(0, _mergeWith3.default)(entry, newEntry);
return true;
/* Combines entries and newEntries, while respecting the order of loaders in each.
Iterates through new entries. If the new entry also exists in existing entries,
we'll put in all of the loaders from existing entries that come before it (in case
those are pre-requisites). Any remaining existing entries are added at the end.
Since webpack processes right-to-left, we're working backwards through the arrays
*/
function combineEntries(newEntries, existingEntries) {
var resultSet = [];
// We're iterating through newEntries, this keeps track of where we are in the existingEntries
var existingEntriesIteratorIndex = existingEntries.length - 1;
for (var i = newEntries.length - 1; i >= 0; i -= 1) {
var currentEntry = newEntries[i];
var indexInExistingEntries = findLastIndexUsingComparinator(existingEntries, currentEntry, areEqualEntries, existingEntriesIteratorIndex);
var hasEquivalentEntryInExistingEntries = indexInExistingEntries !== -1;
if (hasEquivalentEntryInExistingEntries) {
// If the same entry exists in existing entries, we should add all of the entries that
// come before to maintain order
for (var j = existingEntriesIteratorIndex; j > indexInExistingEntries; j -= 1) {
var existingEntry = existingEntries[j];
// If this entry also exists in new entries, we'll add as part of iterating through
// new entries so that if there's a conflict between existing entries and new entries,
// new entries order wins
var hasMatchingEntryInNewEntries = findLastIndexUsingComparinator(newEntries, existingEntry, areEqualEntries, i) !== -1;
if (!hasMatchingEntryInNewEntries) {
resultSet.unshift(existingEntry);
}
existingEntriesIteratorIndex -= 1;
}
uniteEntries(currentEntry, existingEntries[existingEntriesIteratorIndex]);
// uniteEntries mutates the second parameter to be a merged version, so that's what's pushed
resultSet.unshift(existingEntries[existingEntriesIteratorIndex]);
existingEntriesIteratorIndex -= 1;
} else {
var alreadyHasMatchingEntryInResultSet = findLastIndexUsingComparinator(resultSet, currentEntry, areEqualEntries) !== -1;
if (!alreadyHasMatchingEntryInResultSet) {
resultSet.unshift(currentEntry);
}
}
}
// Add remaining existing entries
for (existingEntriesIteratorIndex; existingEntriesIteratorIndex >= 0; existingEntriesIteratorIndex -= 1) {
var _existingEntry = existingEntries[existingEntriesIteratorIndex];
var _alreadyHasMatchingEntryInResultSet = findLastIndexUsingComparinator(resultSet, _existingEntry, areEqualEntries) !== -1;
if (!_alreadyHasMatchingEntryInResultSet) {
resultSet.unshift(_existingEntry);
}
}
return resultSet;
}
function findLastIndexUsingComparinator(entries, entryToFind, comparinator, startingIndex) {
startingIndex = startingIndex || entries.length - 1;
for (var i = startingIndex; i >= 0; i -= 1) {
if (areEqualEntries(entryToFind, entries[i])) {
return i;
}
}
return -1;
}
exports.uniteRules = uniteRules;
exports.uniteEntries = uniteEntries;

2

package.json

@@ -5,3 +5,3 @@ {

"author": "Juho Vepsalainen <bebraw@gmail.com>",
"version": "4.1.2",
"version": "4.1.3",
"scripts": {

@@ -8,0 +8,0 @@ "build": "babel src -d lib",

@@ -274,2 +274,65 @@ [![build status](https://secure.travis-ci.org/survivejs/webpack-merge.svg)](http://travis-ci.org/survivejs/webpack-merge) [![bitHound Score](https://www.bithound.io/github/survivejs/webpack-merge/badges/score.svg)](https://www.bithound.io/github/survivejs/webpack-merge) [![codecov](https://codecov.io/gh/survivejs/webpack-merge/branch/master/graph/badge.svg)](https://codecov.io/gh/survivejs/webpack-merge)

This also works in reverse - the existing order will be maintained if possible:
```javascript
merge.smart({
loaders: [{
test: /\.css$/,
use: [
{ loader: 'css-loader', options: { myOptions: true } },
{ loader: 'style-loader' }
]
}]
}, {
loaders: [{
test: /\.css$/,
use: [
{ loader: 'style-loader', options: { someSetting: true } }
]
}]
});
// will become
{
loaders: [{
test: /\.css$/,
use: [
{ loader: 'css-loader', options: { myOptions: true } },
{ loader: 'style-loader', options: { someSetting: true } }
]
}]
}
```
In the case of an order conflict, the second order wins:
```javascript
merge.smart({
loaders: [{
test: /\.css$/,
use: [
{ loader: 'css-loader' },
{ loader: 'style-loader' }
]
}]
}, {
loaders: [{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' }
]
}]
});
// will become
{
loaders: [{
test: /\.css$/,
use: [
{ loader: 'style-loader' }
{ loader: 'css-loader' },
]
}]
}
```
**Loader query strings `loaders: ['babel?plugins[]=object-assign']` will be overridden.**

@@ -276,0 +339,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc