mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-01 21:15:13 +01:00
chore(utils): remove build step requirement from @trezor/utils (#11176)
* chore: remove build step requirement from utils * chore: dissalow imports from utils/lib * chore: remove outdated comment from TypedEmitter * chore: enable tree shaking for connect-iframe build * chore: bring back usage example comment
This commit is contained in:
@@ -221,7 +221,7 @@ module.exports = {
|
||||
'error',
|
||||
{
|
||||
paths: [{ name: '.' }, { name: '..' }, { name: '../..' }],
|
||||
patterns: ['**/libDev/src'],
|
||||
patterns: ['**/libDev/src', '@trezor/utils/lib', '@trezor/utils/lib/*'],
|
||||
},
|
||||
],
|
||||
'no-restricted-syntax': [
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { createDeferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { createDeferredManager } from '@trezor/utils/lib/createDeferredManager';
|
||||
import { createDeferred, createDeferredManager, TypedEmitter } from '@trezor/utils';
|
||||
import { CustomError } from '@trezor/blockchain-link-types/lib/constants/errors';
|
||||
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/lib/constants';
|
||||
import { Throttler } from './workers/throttler';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import WebSocket from 'ws';
|
||||
import { createDeferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { createDeferredManager } from '@trezor/utils/lib/createDeferredManager';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { createDeferred } from '@trezor/utils';
|
||||
import { createDeferredManager } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import { CustomError } from '@trezor/blockchain-link-types/lib/constants/errors';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import { CoinjoinBackendClient } from './CoinjoinBackendClient';
|
||||
import { CoinjoinFilterController } from './CoinjoinFilterController';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { scheduleAction, arrayShuffle, urlToOnion } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import type { BlockbookAPI } from '@trezor/blockchain-link/lib/workers/blockbook/websocket';
|
||||
|
||||
import { RequestOptions, resetIdentityCircuit } from '../utils/http';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import { Status } from './Status';
|
||||
import { Account } from './Account';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import { CoinjoinPrisonInmate, CoinjoinPrisonEvents } from '../types/client';
|
||||
import { WabiSabiProtocolErrorCode } from '../enums';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { scheduleAction, arrayDistinct, arrayPartition } from '@trezor/utils';
|
||||
import { Network } from '@trezor/utxo-lib';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import * as coordinator from './coordinator';
|
||||
import { transformStatus } from '../utils/roundUtils';
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
* this file is bundled into content script so be careful what you are importing not to bloat the bundle
|
||||
*/
|
||||
|
||||
import { Deferred, createDeferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { scheduleAction } from '@trezor/utils/lib/scheduleAction';
|
||||
import { Deferred, createDeferred } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { scheduleAction } from '@trezor/utils';
|
||||
|
||||
// TODO: so logger should be probably moved to connect common, or this file should be moved to connect
|
||||
// import type { Log } from '@trezor/connect/lib/utils/debug';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// https://github.com/trezor/connect/blob/develop/src/js/storage/index.js
|
||||
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
const storageVersion = 2;
|
||||
const storageName = `storage_v${storageVersion}`;
|
||||
|
||||
@@ -170,7 +170,7 @@ export const config: webpack.Configuration = {
|
||||
},
|
||||
}),
|
||||
],
|
||||
usedExports: false,
|
||||
usedExports: true,
|
||||
},
|
||||
// We are using WASM package - it's much faster (https://github.com/Emurgo/cardano-serialization-lib)
|
||||
// This option makes it possible
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/iframe/builder.js
|
||||
|
||||
import { createDeferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { createDeferred } from '@trezor/utils';
|
||||
import * as ERRORS from '@trezor/connect/lib/constants/errors';
|
||||
import { IFRAME, CoreRequestMessage } from '@trezor/connect/lib/events';
|
||||
import type { ConnectSettings } from '@trezor/connect/lib/types';
|
||||
|
||||
@@ -24,7 +24,7 @@ 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';
|
||||
import { createDeferredManager } from '@trezor/utils/lib/createDeferredManager';
|
||||
import { createDeferredManager } from '@trezor/utils';
|
||||
|
||||
import * as iframe from './iframe';
|
||||
import * as popup from './popup';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/popup/PopupManager.js
|
||||
|
||||
import EventEmitter from 'events';
|
||||
import { createDeferred, Deferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { createDeferred, Deferred } from '@trezor/utils';
|
||||
import { POPUP, IFRAME, UI, CoreEventMessage, IFrameLoaded } from '@trezor/connect/lib/events';
|
||||
import type { ConnectSettings } from '@trezor/connect/lib/types';
|
||||
import { getOrigin } from '@trezor/connect/lib/utils/urlUtils';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { arrayPartition } from '@trezor/utils/lib/arrayPartition';
|
||||
import { arrayPartition } from '@trezor/utils';
|
||||
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
|
||||
// @ts-ignore
|
||||
import commonFixtures from '../../../../submodules/trezor-common/tests/fixtures/ethereum/signmessage.json';
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
Transaction as BitcoinJsTransaction,
|
||||
Network,
|
||||
} from '@trezor/utxo-lib';
|
||||
import * as bufferUtils from '@trezor/utils/lib/bufferUtils';
|
||||
import { bufferUtils } from '@trezor/utils';
|
||||
import { getHDPath, getScriptType, getOutputScriptType } from '../../utils/pathUtils';
|
||||
import { TypedError } from '../../constants/errors';
|
||||
import type {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/helpers/paramsValidator.js
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
|
||||
import { ERRORS } from '../../constants';
|
||||
import { fromHardened } from '../../utils/pathUtils';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
|
||||
import { httpRequest } from '../../utils/assets';
|
||||
import { isStrictFeatures } from '../../utils/firmwareUtils';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
|
||||
import type { Features } from '../../types';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as crypto from 'crypto';
|
||||
import * as bufferUtils from '@trezor/utils/lib/bufferUtils';
|
||||
import { bufferUtils } from '@trezor/utils';
|
||||
|
||||
import { PROTO } from '../../constants';
|
||||
import { DeviceAuthenticityConfig } from '../../data/deviceAuthenticityConfig';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { storage } from '@trezor/connect-common';
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { Deferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import { Deferred } from '@trezor/utils';
|
||||
import { DataManager } from '../data/DataManager';
|
||||
import { ERRORS, NETWORK } from '../constants';
|
||||
import {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import EventEmitter from 'events';
|
||||
|
||||
import { TRANSPORT, TRANSPORT_ERROR } from '@trezor/transport';
|
||||
import { createDeferred, Deferred } from '@trezor/utils/lib/createDeferred';
|
||||
import { getSynchronize } from '@trezor/utils/lib/getSynchronize';
|
||||
import { createDeferred, Deferred } from '@trezor/utils';
|
||||
import { getSynchronize } from '@trezor/utils';
|
||||
import { storage } from '@trezor/connect-common';
|
||||
|
||||
import { DataManager } from '../data/DataManager';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/data/CoinInfo.js
|
||||
import { cloneObject } from '@trezor/utils/lib/cloneObject';
|
||||
import { cloneObject } from '@trezor/utils';
|
||||
import { getBitcoinFeeLevels, getEthereumFeeLevels, getMiscFeeLevels } from './defaultFeeLevels';
|
||||
import { ERRORS } from '../constants';
|
||||
import { toHardened, fromHardened } from '../utils/pathUtils';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/data/FirmwareInfo.js
|
||||
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import {
|
||||
filterSafeListByFirmware,
|
||||
filterSafeListByBootloader,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// original file https://github.com/trezor/connect/blob/develop/src/js/device/Device.js
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { createDeferred, Deferred } from '@trezor/utils/lib/createDeferred';
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { createDeferred, Deferred } from '@trezor/utils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import { TransportProtocol, v1 as v1Protocol, bridge as bridgeProtocol } from '@trezor/protocol';
|
||||
import { DeviceCommands, PassphrasePromptResponse } from './DeviceCommands';
|
||||
import { PROTO, ERRORS, NETWORK } from '../constants';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { randomBytes } from 'crypto';
|
||||
import { Transport } from '@trezor/transport';
|
||||
import * as Messages from '@trezor/protobuf/lib/messages-schema';
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import { ERRORS, NETWORK } from '../constants';
|
||||
import { DEVICE } from '../events';
|
||||
import * as hdnodeUtils from '../utils/hdnodeUtils';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// original file https://github.com/trezor/connect/blob/develop/src/js/device/DeviceList.js
|
||||
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import {
|
||||
BridgeTransport,
|
||||
WebUsbTransport,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Deferred } from '@trezor/utils/lib/createDeferred';
|
||||
import type { Deferred } from '@trezor/utils';
|
||||
import type { DEVICE } from './device';
|
||||
import type { Device } from '../device/Device';
|
||||
import type { UiResponseEvent } from './ui-response';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import EventEmitter from 'events';
|
||||
|
||||
import { createDeferredManager } from '@trezor/utils/lib/createDeferredManager';
|
||||
import { createDeferredManager } from '@trezor/utils';
|
||||
|
||||
import { Core, initCore } from './core';
|
||||
import { factory } from './factory';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import { PROTO } from '../constants';
|
||||
import { config } from '../data/config';
|
||||
import { Features, CoinInfo, UnavailableCapabilities, DeviceModelInternal } from '../types';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as versionUtils from '@trezor/utils/lib/versionUtils';
|
||||
import { versionUtils } from '@trezor/utils';
|
||||
import type { Features, StrictFeatures, FirmwareRelease, VersionArray } from '../types';
|
||||
|
||||
export const isStrictFeatures = (extFeatures: Features): extFeatures is StrictFeatures =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// origin: https://github.com/trezor/connect/blob/develop/src/js/utils/urlUtils.js
|
||||
|
||||
import { urlToOnion } from '@trezor/utils/lib/urlToOnion';
|
||||
import { urlToOnion } from '@trezor/utils';
|
||||
|
||||
export const getOrigin = (url: unknown) => {
|
||||
if (typeof url !== 'string') return 'unknown';
|
||||
|
||||
@@ -3,8 +3,8 @@ import * as net from 'net';
|
||||
import * as url from 'url';
|
||||
|
||||
import type { RequiredKey } from '@trezor/type-utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { arrayPartition } from '@trezor/utils/lib/arrayPartition';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { arrayPartition } from '@trezor/utils';
|
||||
|
||||
import { getFreePort } from './getFreePort';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from 'path';
|
||||
|
||||
import { isNotUndefined } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { InterceptedEvent } from '@trezor/request-manager';
|
||||
import { isDevEnv } from '@suite-common/suite-utils';
|
||||
import type { HandshakeClient, TorStatus } from '@trezor/suite-desktop-api';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { HttpServer, parseBodyJSON, parseBodyText, Handler } from '@trezor/node-utils';
|
||||
import { Descriptor } from '@trezor/transport/src/types';
|
||||
import { arrayPartition } from '@trezor/utils/lib/arrayPartition';
|
||||
import { arrayPartition } from '@trezor/utils';
|
||||
|
||||
import { sessionsClient, enumerate, acquire, release, call, send, receive } from './core';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import type { AnyError, AsyncResultWithTypedError, Success, Logger } from '../types';
|
||||
import { success, error, unknownError } from '../utils/result';
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
import { createDeferred, Deferred } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import type {
|
||||
EnumerateDoneRequest,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getWeakRandomId } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
|
||||
import { Descriptor } from '../types';
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as protobuf from 'protobufjs/light';
|
||||
import { scheduleAction, ScheduleActionParams, ScheduledAction, Deferred } from '@trezor/utils';
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
import { TypedEmitter } from '@trezor/utils';
|
||||
import { PROTOCOL_MALFORMED, TransportProtocol } from '@trezor/protocol';
|
||||
import { MessageFromTrezor } from '@trezor/protobuf';
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
"url": "https://github.com/trezor/trezor-suite/issues"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"main": "lib/index",
|
||||
"publishConfig": {
|
||||
"main": "lib/index"
|
||||
},
|
||||
"main": "src/index",
|
||||
"files": [
|
||||
"lib/",
|
||||
"!**/*.map"
|
||||
|
||||
@@ -36,3 +36,4 @@ export * as versionUtils from './versionUtils';
|
||||
export * as xssFilters from './xssFilters';
|
||||
export * from './getLocaleSeparators';
|
||||
export * from './addDashesToSpaces';
|
||||
export * from './typedEventEmitter';
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
/*
|
||||
|
||||
This file should not be exported from index to prevent missing dependency/polyfill error.
|
||||
EventEmitter is accessible in nodejs but requires polyfills in web builds.
|
||||
|
||||
use:
|
||||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
||||
|
||||
example:
|
||||
Usage example:
|
||||
type EventMap = {
|
||||
obj: { id: string };
|
||||
primitive: boolean | number | string | symbol;
|
||||
@@ -14,9 +7,7 @@ type EventMap = {
|
||||
multipleArgs: (a: number, b: string, c: boolean) => void;
|
||||
[type: `dynamic/${string}`]: boolean;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
type EventMap = Record<string, any>;
|
||||
|
||||
Reference in New Issue
Block a user