Skip to content

Commit

Permalink
refactor: remove usage of _.chain
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Mar 9, 2024
1 parent f98d613 commit 8f98129
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
15 changes: 4 additions & 11 deletions src/dependency.js
Expand Up @@ -60,10 +60,7 @@ export class Dependency {
if (!this.license && pkg.licenses) {
// Map it to a valid license field.
// See: https://docs.npmjs.com/files/package.json#license
this.license = `(${_.chain(pkg.licenses)
.map((license) => license.type || license)
.join(' OR ')
.value()})`;
this.license = `(${pkg.licenses.map((license) => license.type || license).join(' OR ')})`;
}
}

Expand Down Expand Up @@ -98,13 +95,9 @@ export class Dependency {

if (this.contributors.length > 0) {
lines.push(`Contributors:`);

const allContributors = _.chain(this.contributors)
.map((contributor) => contributor.text())
.map((line) => ` ${line}`)
.value();

lines.push(...allContributors);
lines.push(
...this.contributors.map((contributor) => ` ${contributor.text()}`),
);
}

if (this.licenseText) {
Expand Down
19 changes: 12 additions & 7 deletions src/index.js
Expand Up @@ -22,7 +22,6 @@
* SOFTWARE.
*/

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

/**
Expand Down Expand Up @@ -51,13 +50,19 @@ export default function rollupPluginLicense(options = {}) {
* @return {void}
*/
renderChunk(code, chunk, outputOptions = {}) {
const dependencies = [];

if (chunk.modules) {
Object.keys(chunk.modules).forEach((id) => {
const mod = chunk.modules[id];
if (mod && !mod.isAsset && mod.renderedLength > 0) {
dependencies.push(id);
}
});
}

plugin.scanDependencies(
_.chain(chunk.modules)
.toPairs()
.reject((mod) => mod[1].isAsset)
.filter((mod) => mod[1].renderedLength > 0)
.map((mod) => mod[0])
.value(),
dependencies,
);

return plugin.prependBanner(code, outputOptions.sourcemap !== false);
Expand Down
7 changes: 3 additions & 4 deletions src/license-plugin.js
Expand Up @@ -307,10 +307,9 @@ class LicensePlugin {
}

const includePrivate = thirdParty.includePrivate || false;
const outputDependencies = _.chain(this._dependencies)
.values()
.filter((dependency) => includePrivate || !dependency.private)
.value();
const outputDependencies = _.values(this._dependencies).filter((dependency) => (
includePrivate || !dependency.private
));

if (_.isFunction(thirdParty)) {
thirdParty(outputDependencies);
Expand Down
31 changes: 21 additions & 10 deletions src/schema-validator.js
Expand Up @@ -48,12 +48,18 @@ function doItemValidation(value, schema, path) {
];
}

// Run "sub-validators"
return _.chain(matchedValidators)
.filter((validator) => validator.schema)
.map((validator) => validate(value, validator.schema, path))
.flatten()
.value();
const outputs = [];

for (let i = 0; i < matchedValidators.length; ++i) {
const validator = matchedValidators[i];
if (validator.schema) {
outputs.push(
...validate(value, validator.schema, path),
);
}
}

return outputs;
}

/**
Expand Down Expand Up @@ -125,10 +131,15 @@ function validateArrayItem(item, idx, schema, current) {
* @return {Array<Object>} Found errors.
*/
function validateArray(array, schema, current) {
return _.chain(array)
.map((item, idx) => validateArrayItem(item, idx, schema, current))
.flatten()
.value();
const outputs = [];

for (let idx = 0; idx < array.length; ++idx) {
outputs.push(
...validateArrayItem(array[idx], idx, schema, current),
);
}

return outputs;
}

/**
Expand Down

0 comments on commit 8f98129

Please sign in to comment.