Skip to content
Permalink
Browse files

Chore: Scope lodash imports to reduce browser extension size

Ref #1499
  • Loading branch information...
antross committed Mar 19, 2019
1 parent 633378a commit 879d4b2c59ff8a4a58e547639624d3efc3e3e38b
@@ -9,7 +9,8 @@ import * as fs from 'fs';
import * as path from 'path';
import { URL } from 'url';

import { groupBy, every } from 'lodash';
import groupBy = require('lodash/groupBy');
import every = require('lodash/every');
import * as sinon from 'sinon';
import anyTest, { TestInterface } from 'ava';
import { Server } from '@hint/utils-create-server';
@@ -9,7 +9,8 @@ import * as fs from 'fs';
import * as path from 'path';
import { URL } from 'url';

import { groupBy, every } from 'lodash';
import groupBy = require('lodash/groupBy');
import every = require('lodash/every');
import * as sinon from 'sinon';
import test from 'ava';
import { Server } from '@hint/utils-create-server';
@@ -1,4 +1,4 @@
import { isEqual } from 'lodash';
import isEqual = require('lodash/isEqual');
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
import anyTest, { TestInterface, ExecutionContext } from 'ava';
@@ -12,11 +12,9 @@
*/

import chalk from 'chalk';
import {
groupBy,
reduce,
sortBy
} from 'lodash';
import groupBy = require('lodash/groupBy');
import reduce = require('lodash/reduce');
import sortBy = require('lodash/sortBy');
import * as logSymbols from 'log-symbols';
const stripAnsi = require('strip-ansi');

@@ -12,11 +12,9 @@
import * as path from 'path';

import * as Excel from 'exceljs';
import {
forEach,
groupBy,
sortBy
} from 'lodash';
import forEach = require('lodash/forEach');
import groupBy = require('lodash/groupBy');
import sortBy = require('lodash/sortBy');

import cwd from 'hint/dist/src/lib/utils/fs/cwd';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
@@ -1,7 +1,8 @@
import * as path from 'path';

import * as moment from 'moment';
import { cloneDeep } from 'lodash';

import cloneDeep = require('lodash/cloneDeep');

import { Severity, FormatterOptions } from 'hint/dist/src/lib/types';
import loadJSONFile from 'hint/dist/src/lib/utils/fs/load-json-file';
@@ -9,11 +9,9 @@
* ------------------------------------------------------------------------------
*/

import {
groupBy,
reduce,
sortBy
} from 'lodash';
import groupBy = require('lodash/groupBy');
import reduce = require('lodash/reduce');
import sortBy = require('lodash/sortBy');

import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IFormatter, Problem, FormatterOptions } from 'hint/dist/src/lib/types';
@@ -11,12 +11,10 @@
*/

import chalk from 'chalk';
import {
forEach,
groupBy,
reduce,
sortBy
} from 'lodash';
import forEach = require('lodash/forEach');
import groupBy = require('lodash/groupBy');
import reduce = require('lodash/reduce');
import sortBy = require('lodash/sortBy');
import * as logSymbols from 'log-symbols';
import * as table from 'text-table';
const stripAnsi = require('strip-ansi');
@@ -9,10 +9,8 @@
*/

import chalk from 'chalk';
import {
forEach,
groupBy
} from 'lodash';
import forEach = require('lodash/forEach');
import groupBy = require('lodash/groupBy');
import * as table from 'text-table';
import * as logSymbols from 'log-symbols';
const stripAnsi = require('strip-ansi');
@@ -5,7 +5,7 @@
// Waiting for this PR https://github.com/mdn/browser-compat-data/pull/3004
const mdnAPI: CompatData = require('mdn-browser-compat-data');

import { get } from 'lodash';
import get = require('lodash/get');

import { CompatNamespace } from '../enums';
import { browserVersions } from './normalize-version';
@@ -2,7 +2,7 @@
* @fileoverview Helper that contains all the logic related with CSS compat api, to use in different modules.
*/

import { find } from 'lodash';
import find = require('lodash/find');
import { AtRule, Rule, Declaration, ChildNode, ContainerBase } from 'postcss';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
@@ -3,8 +3,6 @@
* For more information on the issue: https://github.com/mdn/browser-compat-data/pull/2690#issuecomment-417237045
*/

import { padStart, padEnd } from 'lodash';

class BrowserVersions {
private columnSeparator = '.';
private charForPad = '0';
@@ -25,15 +23,15 @@ class BrowserVersions {
*/
public normalize(browserVersion: string): number {
const result = browserVersion.split(this.columnSeparator).map((column) => {
return padStart(column, this.itemsInColum, this.charForPad);
return column.padStart(this.itemsInColum, this.charForPad);
})
.join('');

return Number(padEnd(result, this.itemsInColumns, this.charForPad));
return Number(result.padEnd(this.itemsInColumns, this.charForPad));
}

public deNormalize(normalizedVersion: number): string {
const normalizedVersionString = padStart(`${normalizedVersion}`, this.itemsInColumns, this.charForPad);
const normalizedVersionString = `${normalizedVersion}`.padStart(this.itemsInColumns, this.charForPad);
const columns = normalizedVersionString.match(/..?/g);

if (!columns) {
@@ -9,7 +9,7 @@
* ------------------------------------------------------------------------------
*/

import { uniqBy } from 'lodash';
import uniqBy = require('lodash/uniqBy');
import { OptionsWithUrl } from 'request';

import { debug as d } from 'hint/dist/src/lib/utils/debug';
@@ -4,7 +4,7 @@
import * as fs from 'fs';
import { promisify } from 'util';

import { groupBy } from 'lodash';
import groupBy = require('lodash/groupBy');
import * as semver from 'semver';

import * as logger from 'hint/dist/src/lib/utils/logging';
@@ -18,7 +18,7 @@ import * as os from 'os';
import * as path from 'path';

import browserslist = require('browserslist'); // `require` used because `browserslist` exports a function
import { mergeWith } from 'lodash';
import mergeWith = require('lodash/mergeWith');

import { UserConfig, IgnoredUrl, CLIOptions, ConnectorConfig, HintsConfigObject, HintSeverity } from './types';
import { debug as d } from './utils/debug';
@@ -13,7 +13,7 @@ import * as url from 'url';

import chalk from 'chalk';
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
import { remove } from 'lodash';
import remove = require('lodash/remove');

import { debug as d } from './utils/debug';
import { getSeverity } from './config/config-hints';
@@ -1,6 +1,6 @@
import * as path from 'path';

import { merge } from 'lodash';
import merge = require('lodash/merge');

import { Engine } from '../engine';
import { getAsUri } from '../utils/network/as-uri';
@@ -1,7 +1,7 @@
import * as url from 'url';
import { URL } from 'url'; // this is necessary to avoid TypeScript mixes types.

import { compact } from 'lodash';
import compact = require('lodash/compact');
import fileUrl = require('file-url'); // `require` used because `file-url` exports a function

import { debug as d } from '../debug';
@@ -1,12 +1,9 @@
import * as ajv from 'ajv';
import {
cloneDeep,
forEach,
groupBy,
reduce,
without,
Dictionary
} from 'lodash';
import cloneDeep = require('lodash/cloneDeep');
import forEach = require('lodash/forEach');
import groupBy = require('lodash/groupBy');
import reduce = require('lodash/reduce');
import without = require('lodash/without');

import { IJSONLocationFunction, ISchemaValidationError, SchemaValidationResult } from '../types';
import { GroupedError } from '../types/schema-validation-result';
@@ -225,7 +222,7 @@ const generateErrorsMessage = (errors: ajv.ErrorObject[]): string[] => {
* * - 'root' should have required properties 'connector' or 'extends'
*/
const groupMessages = (errors: ISchemaValidationError[]): GroupedError[] => {
const grouped: Dictionary<ajv.ErrorObject[]> = groupBy(errors, 'dataPath');
const grouped = groupBy(errors, 'dataPath');

const result = reduce(grouped, (allErrors, groupErrors: ISchemaValidationError[]) => {
let errors = groupErrors;
@@ -1,4 +1,4 @@
import { cloneDeep } from 'lodash';
import cloneDeep = require('lodash/cloneDeep');
import test from 'ava';

import * as configValidator from '../../../src/lib/config/config-validator';
@@ -1,6 +1,6 @@
import * as path from 'path';

import { cloneDeep } from 'lodash';
import cloneDeep = require('lodash/cloneDeep');

import { FetchEnd, IJSONResult, Parser, SchemaValidationResult } from 'hint/dist/src/lib/types';
import { Engine } from 'hint';
@@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';

import { cloneDeep } from 'lodash';
import cloneDeep = require('lodash/cloneDeep');
import { debug as d } from 'hint/dist/src/lib/utils/debug';

import { FetchEnd, IJSONResult, Parser, SchemaValidationResult } from 'hint/dist/src/lib/types';
@@ -1,6 +1,7 @@
import { spawn, ChildProcess, SpawnOptions } from 'child_process';

import { map, reduce } from 'lodash';
import map = require('lodash/map');
import reduce = require('lodash/reduce');

import { Message, ServerConfiguration } from './types';
import { replacer, reviver } from './buffer-serialization';
@@ -5,7 +5,8 @@
import * as http from 'http';
import * as https from 'https';

import { forEach, random } from 'lodash';
import forEach = require('lodash/forEach');
import random = require('lodash/random');
import * as express from 'express';

// to work with option 'strict', we can't use import.
@@ -17,7 +17,8 @@ import { promisify } from 'util';
import * as cdp from 'chrome-remote-interface';

import * as lockfile from 'lockfile';
import { compact, filter } from 'lodash';
import compact = require('lodash/compact');
import filter = require('lodash/filter');

import { Crdp } from 'chrome-remote-debug-protocol';

0 comments on commit 879d4b2

Please sign in to comment.
You can’t perform that action at this time.