Skip to content

Commit

Permalink
🔧 remove lodash and fix inject script errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoventurini committed Jan 17, 2023
1 parent d540807 commit 2a15f96
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
export DEVTOOLS_HOME="$(git rev-parse --show-toplevel)"
export MAC_CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
export MAC_CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

function mpm {
meteor npm $@
Expand Down Expand Up @@ -45,7 +44,7 @@ function build-for-browser {
local BROWSER=$1
local VERSION=$(package-version)

mkdir releases -p
mkdir releases

yarn run build:${BROWSER}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ extension/chrome
extension/firefox
mongo-decimal-test-main
.eslintcache
yarn-error.log
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@tstt/eslint-config": "^0.1.4",
"@types/chrome": "0.0.178",
"@types/classnames": "^2.2.10",
"@types/lodash": "^4.14.149",
"@types/luxon": "^2.0.5",
"@types/meteor": "^2.0.4",
"@types/react": "^17.0.27",
Expand All @@ -56,7 +55,10 @@
"daisyui": "^2.15.2",
"dexie": "3.2.2",
"file-loader": "^6.2.0",
"lodash": "4.17.21",
"lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2",
"lodash.sortby": "^4.7.0",
"lodash.throttle": "^4.1.1",
"luxon": "2.3.0",
"mobx": "6.4.0",
"mobx-react-lite": "3.3.0",
Expand Down
Binary file removed releases/meteor-devtools-evolved-1.8.0.chrome.zip
Binary file not shown.
Binary file removed releases/meteor-devtools-evolved-1.8.0.firefox.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { exists } from './Utils'
import { v4 as uuid } from 'uuid'
import { isString } from 'lodash'
import { isString } from './Utils/StringUtils'

const GA_HOST = 'https://www.google-analytics.com'

Expand Down
5 changes: 2 additions & 3 deletions src/Browser/Background.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defer } from 'lodash'
import browser from 'webextension-polyfill'

type Connection = Map<number, any>
Expand Down Expand Up @@ -82,7 +81,7 @@ const handleConsole = (
const contentListener = () => {
// @ts-ignore
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
defer(() => {
setTimeout(() => {
const tabId = sender?.tab?.id

if (!tabId) return
Expand Down Expand Up @@ -115,7 +114,7 @@ const contentListener = () => {
if (connections.has(tabId)) {
connections.get(tabId).postMessage(request)
}
})
}, 0)

sendResponse()
})
Expand Down
3 changes: 1 addition & 2 deletions src/Browser/MeteorLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mapValues from 'lodash/mapValues'
import omit from 'lodash/omit'
import { JSONUtils } from '@/Utils/JSONUtils'
import { mapValues, omit } from '@/Utils/Objects'

export const getSubscriptions = () => {
const payload = mapValues(
Expand Down
3 changes: 1 addition & 2 deletions src/Injectors/MeteorAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Registry, sendMessage } from '@/Browser/Inject'
import { getSubscriptions } from '@/Browser/MeteorLibrary'
import isFunction from 'lodash/isFunction'
import { JSONUtils } from '@/Utils/JSONUtils'

export const MeteorAdapter = () => {
Expand Down Expand Up @@ -33,7 +32,7 @@ export const MeteorAdapter = () => {
['find', 'findOne', 'insert', 'update', 'upsert', 'remove'].includes(
key,
) &&
isFunction(val)
typeof val === 'function'
) {
const original = prototype[key]

Expand Down
12 changes: 9 additions & 3 deletions src/Injectors/MinimongoInjector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { warning } from '@/Log'
import { Registry, sendMessage } from '@/Browser/Inject'
import cloneDeep from 'lodash/cloneDeep'
import throttle from 'lodash/throttle'
import { isArray } from 'lodash'
import throttle from 'lodash.throttle'

function cloneDeep(obj: any) {
return JSON.parse(JSON.stringify(obj))
}

function isArray(obj: any) {
return Array.isArray(obj)
}

const cleanup = (object: any) => {
if (typeof object !== 'object') return object
Expand Down
4 changes: 1 addition & 3 deletions src/Pages/Panel/DDP/FilterConstants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { toPairs } from 'lodash'

export const FilterCriteria: FilterTypeMap<string[]> = {
heartbeat: ['ping', 'pong'],
subscription: ['sub', 'unsub', 'nosub', 'ready'],
Expand All @@ -10,7 +8,7 @@ export const FilterCriteria: FilterTypeMap<string[]> = {

export const FilterCriteriaMap: {
[key: string]: FilterType
} = toPairs(FilterCriteria).reduce(
} = Object.entries(FilterCriteria).reduce(
(previous: any, [key, matchers]) => ({
...previous,
...matchers.reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/Stores/Common/Searchable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_OFFSET } from '@/Constants'
import { calculatePagination } from '@/Utils/Pagination'
import { debounce } from 'lodash'
import debounce from 'lodash.debounce'
import { action, computed, observable, runInAction } from 'mobx'

type BufferCallback<T> = ((buffer: T[]) => void) | null
Expand Down
2 changes: 1 addition & 1 deletion src/Stores/Panel/DDPStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from 'lodash'
import debounce from 'lodash.debounce'
import { action, computed, makeObservable, observable, runInAction } from 'mobx'
import { Searchable } from '../Common/Searchable'
import { PanelStore } from '@/Stores/PanelStore'
Expand Down
3 changes: 2 additions & 1 deletion src/Stores/Panel/MinimongoStore/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { debounce, mapValues } from 'lodash'
import debounce from 'lodash.debounce'
import { action, computed, makeObservable, observable } from 'mobx'
import { CollectionStore } from './CollectionStore'
import { JSONUtils } from '@/Utils/JSONUtils'
import { StringUtils } from '@/Utils/StringUtils'
import prettyBytes from 'pretty-bytes'
import { mapValues } from '@/Utils/Objects'

export class MinimongoStore {
activeCollectionDocuments = new CollectionStore()
Expand Down
3 changes: 2 additions & 1 deletion src/Stores/Panel/PerformanceStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action, makeObservable, observable } from 'mobx'
import { debounce, sortBy } from 'lodash'
import sortBy from 'lodash.sortby'
import debounce from 'lodash.debounce'

type AccCallData = {
collectionName: string
Expand Down
4 changes: 2 additions & 2 deletions src/Stores/Panel/SettingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
toJS,
} from 'mobx'
import { PanelDatabase } from '@/Database/PanelDatabase'
import { assign, compact, flatten, omit } from 'lodash'
import { FilterCriteria } from '@/Pages/Panel/DDP/FilterConstants'
import { compact, flatten, omit } from '@/Utils/Objects'

export class SettingStore implements ISettings {
hydrated = false
Expand All @@ -30,7 +30,7 @@ export class SettingStore implements ISettings {

PanelDatabase.getSettings().then(settings => {
runInAction(() => {
assign(this, settings)
Object.assign(this, settings)
})

setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/Styles/Breakpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mapValues } from '@/Utils/Objects'
import { css, FlattenSimpleInterpolation } from 'styled-components'
import { mapValues } from 'lodash'

type BreakpointLabel = 'xs' | 'sm' | 'md' | 'lg' | 'xl'

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/MessageFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StringUtils } from '@/Utils/StringUtils'
import { isNumber, isString } from 'lodash'
import { isString, StringUtils } from '@/Utils/StringUtils'
import { isNumber } from './Numbers'

const MAX_CHARACTERS = 512

Expand Down
1 change: 1 addition & 0 deletions src/Utils/Numbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isNumber = (value: any) => typeof value === 'number'
31 changes: 31 additions & 0 deletions src/Utils/Objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const isObject = (value: any) => typeof value === 'object'

export function omit(object, keys) {
return Object.keys(object).reduce((result, key) => {
if (!keys.includes(key)) {
result[key] = object[key]
}

return result
}, {})
}

export function mapValues(object, fn) {
return Object.keys(object).reduce((result, key) => {
result[key] = fn(object[key])

return result
}, {})
}

export function flatten(array) {
return array.reduce((result, item) => result.concat(item), [])
}

export function compact(array) {
return array.filter(Boolean)
}

export const isNil = value => value === null || value === undefined

export const isUndefined = value => value === undefined
4 changes: 3 additions & 1 deletion src/Utils/StringUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isString, memoize } from 'lodash'
import memoize from 'lodash.memoize'

export const isString = (value: any) => typeof value === 'string'

export namespace StringUtils {
export const classPrefix = 'mde'
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Sunburst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { arc } from 'd3-shape'
import { hierarchy, partition } from 'd3-hierarchy'
import { entries, keys } from 'd3-collection'
import { StringUtils } from '@/Utils/StringUtils'
import { isNil, isObject } from 'lodash'
import { isNil, isObject } from './Objects'

export const typeBundle = 'bundle'
export const typePackage = 'package'
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isNil, isUndefined } from 'lodash'
import { DEVELOPMENT } from '@/Constants'
import browser from 'webextension-polyfill'
import { isNil } from './Objects'

export const inDevelopmentOnly = (callback: () => any) => {
if (DEVELOPMENT) {
Expand All @@ -15,4 +15,4 @@ export const checkFirefoxBrowser = async (): Promise<boolean> => {
return name === 'Firefox'
}

export const exists = (value: any) => !isNil(value) && !isUndefined(value)
export const exists = (value: any) => !isNil(value)
21 changes: 18 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/lodash@^4.14.149", "@types/lodash@^4.14.178":
"@types/lodash@^4.14.178":
version "4.14.178"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
Expand Down Expand Up @@ -4897,7 +4897,7 @@ lodash.curry@^4.1.1:
lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==

lodash.includes@^4.3.0:
version "4.3.0"
Expand Down Expand Up @@ -4929,6 +4929,11 @@ lodash.isstring@^4.0.1:
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
integrity sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==

lodash.merge@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
Expand All @@ -4939,7 +4944,17 @@ lodash.once@^4.0.0:
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
integrity sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==

lodash@4.17.21, lodash@^4.17.11, lodash@^4.17.21:
lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
integrity sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==

lodash@^4.17.11, lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down

0 comments on commit 2a15f96

Please sign in to comment.