Merge pull request #16916 from mozilla/chore/direct-lodash-imports

chore: use direct lodash imports for smaller bundle size
This commit is contained in:
Ben Bangert 2024-05-09 18:30:34 -07:00 коммит произвёл GitHub
Родитель 60fa969bc2 787c59f68e
Коммит 9b206779e7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 28 добавлений и 28 удалений

Просмотреть файл

@ -18,7 +18,7 @@ import {
SubscriptionEligibilityResult,
SubscriptionUpdateEligibility,
} from 'fxa-shared/subscriptions/types';
import { isEqual } from 'lodash';
import isEqual from 'lodash/isEqual';
import Stripe from 'stripe';
import Container from 'typedi';

Просмотреть файл

@ -7,7 +7,7 @@
const sinon = require('sinon');
const { assert } = require('chai');
const { default: Container } = require('typedi');
const { cloneDeep } = require('lodash');
const cloneDeep = require('lodash/cloneDeep');
const retry = require('async-retry');
const { deleteCollection } = require('../util');
const {

Просмотреть файл

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import _ from 'lodash';
import zipWith from 'lodash/zipWith';
import Backbone from 'backbone';
const t = (msg) => msg;
@ -42,7 +42,7 @@ const CATEGORY_TAGS = {
'Not listed': 'not_listed',
};
const topicOptions = _.zipWith(TOPICS, LOWERED_TOPICS, (topic, lowered) => ({
const topicOptions = zipWith(TOPICS, LOWERED_TOPICS, (topic, lowered) => ({
topic,
lowered,
}));

Просмотреть файл

@ -14,7 +14,7 @@
'use strict';
const _ = require('lodash');
const pick = require('lodash/pick');
const {
GROUPS,
initialize,
@ -878,7 +878,7 @@ function receiveEvent(event, request, data) {
version: VERSION,
emailTypes: EMAIL_TYPES,
userAgent: request.headers && request.headers['user-agent'],
..._.pick(data, [
...pick(data, [
'deviceId',
'devices',
'emailDomain',

Просмотреть файл

@ -3,7 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
const _ = require('lodash');
const assign = require('lodash/assign');
const mapValues = require('lodash/mapValues');
const pick = require('lodash/pick');
const pickBy = require('lodash/pickBy');
const amplitude = require('./amplitude');
const config = require('./configuration');
const flowMetrics = require('./flow-metrics');
@ -144,7 +147,7 @@ function estimateTime(times) {
function logFlowEvent(event, data, request) {
const { location } = data;
const eventData = _.assign(
const eventData = assign(
{
country: location && location.country,
event: event.type,
@ -158,7 +161,7 @@ function logFlowEvent(event, data, request) {
userAgent: request.headers['user-agent'],
v: VERSION,
},
_.mapValues(pickFlowData(data, request), sanitiseData)
mapValues(pickFlowData(data, request), sanitiseData)
);
optionallySetFallbackData(eventData, 'service', data.client_id);
@ -187,12 +190,12 @@ function logStatsdPerfEvent(eventData) {
function pickFlowData(data, request) {
if (isDNT(request)) {
return _.pick(data, DNT_ALLOWED_DATA);
return pick(data, DNT_ALLOWED_DATA);
}
const pickedData = _.pick(data, NO_DNT_ALLOWED_DATA);
const pickedData = pick(data, NO_DNT_ALLOWED_DATA);
return _.pickBy(pickedData, (value, key) => {
return pickBy(pickedData, (value, key) => {
if (key.indexOf('utm_') === 0) {
// Silently drop utm_ properties that contain unexpected characters.
return UTM_PATTERN.test(value);

Просмотреть файл

@ -7,7 +7,7 @@
*/
'use strict';
const _ = require('lodash');
const isString = require('lodash/isString');
const joi = require('joi');
const logger = require('../logging/log')();
const url = require('url');
@ -84,7 +84,7 @@ module.exports = function (options = {}) {
};
function stripPIIFromUrl(urlToScrub) {
if (!urlToScrub || !_.isString(urlToScrub)) {
if (!urlToScrub || !isString(urlToScrub)) {
return '';
}

Просмотреть файл

@ -5,7 +5,7 @@
'use strict';
const _ = require('lodash');
const find = require('lodash/find');
const config = require('../configuration');
const flowMetricsRequest = require('../flow-event').metricsRequest;
const joi = require('joi');
@ -233,8 +233,5 @@ module.exports = function (statsd) {
};
function findInvalidEventOffsets(events, maxOffset) {
return _.find(
events,
(event) => event.offset > maxOffset || event.offset < 0
);
return find(events, (event) => event.offset > maxOffset || event.offset < 0);
}

Просмотреть файл

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const _ = require('lodash');
const get = require('lodash/get');
const config = require('./configuration');
const STACKTRACE_FRAME_LENGTH = 10;
@ -29,19 +29,19 @@ function removeQuery(url) {
const eventFilter = (event) => {
event = tagCriticalEvent(event);
if (_.get(event, 'request.headers.Referer')) {
if (get(event, 'request.headers.Referer')) {
event.request.headers.Referer = removeQuery(event.request.headers.Referer);
}
if (_.get(event, 'request.url')) {
if (get(event, 'request.url')) {
event.request.url = removeQuery(event.request.url);
}
if (_.get(event, 'request.query_string')) {
if (get(event, 'request.query_string')) {
event.request.query_string = null; //eslint-disable-line camelcase
}
if (_.get(event, 'exception[0].stacktrace.frames')) {
if (get(event, 'exception[0].stacktrace.frames')) {
// trim the stacktrace to avoid sending a lot of event
// by default some traces may have 100+ frames
event.exception[0].stacktrace.frames.length = STACKTRACE_FRAME_LENGTH;

Просмотреть файл

@ -6,7 +6,7 @@ const assert = intern.getPlugin('chai').assert;
const config = require('../../../server/lib/configuration');
const crypto = require('crypto');
const css = require('css');
const { extend } = require('lodash');
const extend = require('lodash/extend');
const got = require('got');
const htmlparser2 = require('htmlparser2');
const path = require('path');

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { registerSuite } = intern.getInterface('object');
const assert = intern.getPlugin('chai').assert;
const _ = require('lodash');
const assign = require('lodash/assign');
const path = require('path');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
@ -291,7 +291,7 @@ function setupMetricsHandlerTests(options) {
};
if (options.data) {
_.assign(mocks.request.body, options.data);
assign(mocks.request.body, options.data);
}
mocks.response = { json: sandbox.spy() };
mocks.nextTick = sandbox.spy();

Просмотреть файл

@ -7,7 +7,7 @@ const logger = require('../logging')('server.web');
const Hapi = require('@hapi/hapi');
const Sentry = require('@sentry/node');
const cloneDeep = require('lodash').cloneDeep;
const cloneDeep = require('lodash/cloneDeep');
const ScopeSet = require('fxa-shared').oauth.scopes;
const AppError = require('../error');