Skip to content

Commit 8f98129

Browse files
committedMar 9, 2024
refactor: remove usage of _.chain
1 parent f98d613 commit 8f98129

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed
 

‎src/dependency.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ export class Dependency {
6060
if (!this.license && pkg.licenses) {
6161
// Map it to a valid license field.
6262
// See: https://docs.npmjs.com/files/package.json#license
63-
this.license = `(${_.chain(pkg.licenses)
64-
.map((license) => license.type || license)
65-
.join(' OR ')
66-
.value()})`;
63+
this.license = `(${pkg.licenses.map((license) => license.type || license).join(' OR ')})`;
6764
}
6865
}
6966

@@ -98,13 +95,9 @@ export class Dependency {
9895

9996
if (this.contributors.length > 0) {
10097
lines.push(`Contributors:`);
101-
102-
const allContributors = _.chain(this.contributors)
103-
.map((contributor) => contributor.text())
104-
.map((line) => ` ${line}`)
105-
.value();
106-
107-
lines.push(...allContributors);
98+
lines.push(
99+
...this.contributors.map((contributor) => ` ${contributor.text()}`),
100+
);
108101
}
109102

110103
if (this.licenseText) {

‎src/index.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import _ from 'lodash';
2625
import {licensePlugin} from './license-plugin.js';
2726

2827
/**
@@ -51,13 +50,19 @@ export default function rollupPluginLicense(options = {}) {
5150
* @return {void}
5251
*/
5352
renderChunk(code, chunk, outputOptions = {}) {
53+
const dependencies = [];
54+
55+
if (chunk.modules) {
56+
Object.keys(chunk.modules).forEach((id) => {
57+
const mod = chunk.modules[id];
58+
if (mod && !mod.isAsset && mod.renderedLength > 0) {
59+
dependencies.push(id);
60+
}
61+
});
62+
}
63+
5464
plugin.scanDependencies(
55-
_.chain(chunk.modules)
56-
.toPairs()
57-
.reject((mod) => mod[1].isAsset)
58-
.filter((mod) => mod[1].renderedLength > 0)
59-
.map((mod) => mod[0])
60-
.value(),
65+
dependencies,
6166
);
6267

6368
return plugin.prependBanner(code, outputOptions.sourcemap !== false);

‎src/license-plugin.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,9 @@ class LicensePlugin {
307307
}
308308

309309
const includePrivate = thirdParty.includePrivate || false;
310-
const outputDependencies = _.chain(this._dependencies)
311-
.values()
312-
.filter((dependency) => includePrivate || !dependency.private)
313-
.value();
310+
const outputDependencies = _.values(this._dependencies).filter((dependency) => (
311+
includePrivate || !dependency.private
312+
));
314313

315314
if (_.isFunction(thirdParty)) {
316315
thirdParty(outputDependencies);

‎src/schema-validator.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ function doItemValidation(value, schema, path) {
4848
];
4949
}
5050

51-
// Run "sub-validators"
52-
return _.chain(matchedValidators)
53-
.filter((validator) => validator.schema)
54-
.map((validator) => validate(value, validator.schema, path))
55-
.flatten()
56-
.value();
51+
const outputs = [];
52+
53+
for (let i = 0; i < matchedValidators.length; ++i) {
54+
const validator = matchedValidators[i];
55+
if (validator.schema) {
56+
outputs.push(
57+
...validate(value, validator.schema, path),
58+
);
59+
}
60+
}
61+
62+
return outputs;
5763
}
5864

5965
/**
@@ -125,10 +131,15 @@ function validateArrayItem(item, idx, schema, current) {
125131
* @return {Array<Object>} Found errors.
126132
*/
127133
function validateArray(array, schema, current) {
128-
return _.chain(array)
129-
.map((item, idx) => validateArrayItem(item, idx, schema, current))
130-
.flatten()
131-
.value();
134+
const outputs = [];
135+
136+
for (let idx = 0; idx < array.length; ++idx) {
137+
outputs.push(
138+
...validateArrayItem(array[idx], idx, schema, current),
139+
);
140+
}
141+
142+
return outputs;
132143
}
133144

134145
/**

0 commit comments

Comments
 (0)
Please sign in to comment.