chore(connect-web): reduce bundle size

This commit is contained in:
Tomas Martykan
2024-01-17 11:09:47 +01:00
committed by martin
parent abae3b84c3
commit b41ce8e432
6 changed files with 15 additions and 22 deletions

View File

@@ -13,9 +13,9 @@ SIZE_S=$(du -s "$parent_path/../build/trezor-connect.js" | cut -f1)
# if you have considerably more, there is a chance that you accidentally included
# parts of code that shouldn't be in this build.
echo "size: $SIZE_S"
# todo: size should be smaller, it grew after https://github.com/trezor/trezor-suite/pull/10280 was merged
# plan is to decresase it https://github.com/trezor/trezor-suite/issues/10554
if [[ "$SIZE_S" -gt 610 ]]
# size grew after https://github.com/trezor/trezor-suite/pull/10280 was merged
#
if [[ "$SIZE_S" -gt 240 ]]
then
echo "suspiciously large build detected!"
exit 1;

View File

@@ -1,7 +1,5 @@
import {
parseConnectSettings as parseSettings,
ConnectSettings,
} from '@trezor/connect/lib/exports';
import { parseConnectSettings as parseSettings } from '@trezor/connect/lib/data/connectSettings';
import type { ConnectSettings } from '@trezor/connect/lib/types';
export const getEnv = () => {
if (typeof chrome !== 'undefined' && typeof chrome.runtime?.onConnect !== 'undefined') {

View File

@@ -1,7 +1,9 @@
// origin: https://github.com/trezor/connect/blob/develop/src/js/iframe/builder.js
import { createDeferred, Deferred } from '@trezor/utils/lib/createDeferred';
import { IFRAME, UI_EVENT, ERRORS, ConnectSettings } from '@trezor/connect/lib/exports';
import * as ERRORS from '@trezor/connect/lib/constants/errors';
import { IFRAME, UI_EVENT } from '@trezor/connect/lib/events';
import type { ConnectSettings } from '@trezor/connect/lib/types';
import { getOrigin } from '@trezor/connect/lib/utils/urlUtils';
import { setLogWriter, LogMessage, LogWriter } from '@trezor/connect/lib/utils/debug';
import css from './inlineStyles';

View File

@@ -2,11 +2,11 @@ import EventEmitter from 'events';
// NOTE: @trezor/connect part is intentionally not imported from the index due to NormalReplacementPlugin
// in packages/suite-build/configs/web.webpack.config.ts
import * as ERRORS from '@trezor/connect/lib/constants/errors';
import {
POPUP,
IFRAME,
UI,
ERRORS,
UI_EVENT,
DEVICE_EVENT,
RESPONSE_EVENT,
@@ -16,12 +16,11 @@ import {
parseMessage,
createUiMessage,
createErrorMessage,
ConnectSettings,
Manifest,
PostMessageEvent,
UiResponseEvent,
CallMethod,
} from '@trezor/connect/lib/exports';
} from '@trezor/connect/lib/events';
import type { ConnectSettings, Manifest } from '@trezor/connect/lib/types';
import { factory } from '@trezor/connect/lib/factory';
import { initLog } from '@trezor/connect/lib/utils/debug';
import { config } from '@trezor/connect/lib/data/config';

View File

@@ -2,14 +2,8 @@
import EventEmitter from 'events';
import { createDeferred, Deferred } from '@trezor/utils/lib/createDeferred';
import {
POPUP,
IFRAME,
UI,
ConnectSettings,
CoreMessage,
IFrameLoaded,
} from '@trezor/connect/lib/exports';
import { POPUP, IFRAME, UI, CoreMessage, IFrameLoaded } from '@trezor/connect/lib/events';
import type { ConnectSettings } from '@trezor/connect/lib/types';
import { getOrigin } from '@trezor/connect/lib/utils/urlUtils';
import { showPopupRequest } from './showPopupRequest';

View File

@@ -1,5 +1,5 @@
import { JavaScriptTypeBuilder, Static, TSchema, TObject, Optional } from '@sinclair/typebox';
import { Value, ValueErrorType } from '@sinclair/typebox/value';
import { ValueErrorType, Errors } from '@sinclair/typebox/errors';
import { Mixin } from 'ts-mixer';
import { ArrayBufferBuilder, BufferBuilder, KeyofEnumBuilder, UintBuilder } from './custom-types';
@@ -24,7 +24,7 @@ export function Validate<T extends TSchema>(schema: T, value: unknown): value is
}
export function Assert<T extends TSchema>(schema: T, value: unknown): asserts value is Static<T> {
const errors = [...Value.Errors(schema, value)];
const errors = [...Errors(schema, value)];
let [error] = errors;
while (error) {
if (error.path === '/' && errors.length > 1) {