From 46485ed823413b5f58be347e45825f907cb15593 Mon Sep 17 00:00:00 2001 From: sabio Date: Tue, 26 Nov 2024 14:44:07 +0300 Subject: [PATCH] Update rollup to v2.79.1 commit_hash:286fcc0ac2efd545266c9373459270b07d5a7d0f --- .mapping.json | 1 + package-lock.json | 56 +++++-------------- package.json | 2 +- scripts/build/build.ts | 1 + src/index.ts | 18 +++++- .../__tests__/counterOptions.spec.ts | 10 ++-- src/utils/counterOptions/counterOptions.ts | 41 ++++---------- .../counterOptions/counterOptionsStore.ts | 13 +++++ src/utils/counterOptions/types.ts | 2 + src/utils/errorLogger/handleError.ts | 47 ++++++++-------- tsconfig.json | 2 - tsconfig.rollup.json | 2 +- 12 files changed, 91 insertions(+), 104 deletions(-) create mode 100644 src/utils/counterOptions/counterOptionsStore.ts diff --git a/.mapping.json b/.mapping.json index 13ed4ee..5e91c67 100644 --- a/.mapping.json +++ b/.mapping.json @@ -388,6 +388,7 @@ "src/utils/counter/type.ts":"metrika/frontend/watch/public/src/utils/counter/type.ts", "src/utils/counterOptions/__tests__/counterOptions.spec.ts":"metrika/frontend/watch/public/src/utils/counterOptions/__tests__/counterOptions.spec.ts", "src/utils/counterOptions/counterOptions.ts":"metrika/frontend/watch/public/src/utils/counterOptions/counterOptions.ts", + "src/utils/counterOptions/counterOptionsStore.ts":"metrika/frontend/watch/public/src/utils/counterOptions/counterOptionsStore.ts", "src/utils/counterOptions/getCounterKey.ts":"metrika/frontend/watch/public/src/utils/counterOptions/getCounterKey.ts", "src/utils/counterOptions/index.ts":"metrika/frontend/watch/public/src/utils/counterOptions/index.ts", "src/utils/counterOptions/types.ts":"metrika/frontend/watch/public/src/utils/counterOptions/types.ts", diff --git a/package-lock.json b/package-lock.json index d0806af..f9d7c9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "prettier": "2.3.0", "ps-tree": "1.2.0", "regenerator-runtime": "0.14.0", - "rollup": "2.7.6", + "rollup": "2.79.1", "rollup-plugin-cleanup": "3.1.1", "rollup-plugin-progress": "1.1.2", "rollup-plugin-typescript2": "0.27.0", @@ -1913,21 +1913,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/chokidar/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -3575,12 +3560,11 @@ "license": "ISC" }, "node_modules/fsevents": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz", - "integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, - "license": "MIT", "optional": true, "os": [ "darwin" @@ -6459,11 +6443,10 @@ } }, "node_modules/rollup": { - "version": "2.7.6", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.7.6.tgz", - "integrity": "sha512-AdHosxHBKyBsdtbT1/AqbWNQ87O4SSxS4N9iMwEpoCDAT6e4Du3uJSy83mp3ckgmCxly5VeXGx0WHsm21Djytg==", + "version": "2.79.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", + "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", "dev": true, - "license": "MIT", "bin": { "rollup": "dist/bin/rollup" }, @@ -6471,7 +6454,7 @@ "node": ">=10.0.0" }, "optionalDependencies": { - "fsevents": "~2.1.2" + "fsevents": "~2.3.2" } }, "node_modules/rollup-plugin-cleanup": { @@ -9524,15 +9507,6 @@ "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" - }, - "dependencies": { - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - } } }, "cliui": { @@ -10740,9 +10714,9 @@ "dev": true }, "fsevents": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz", - "integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "optional": true }, @@ -12712,12 +12686,12 @@ } }, "rollup": { - "version": "2.7.6", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.7.6.tgz", - "integrity": "sha512-AdHosxHBKyBsdtbT1/AqbWNQ87O4SSxS4N9iMwEpoCDAT6e4Du3uJSy83mp3ckgmCxly5VeXGx0WHsm21Djytg==", + "version": "2.79.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", + "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", "dev": true, "requires": { - "fsevents": "~2.1.2" + "fsevents": "~2.3.2" } }, "rollup-plugin-cleanup": { diff --git a/package.json b/package.json index e0700ce..8bbccbe 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "prettier": "2.3.0", "ps-tree": "1.2.0", "regenerator-runtime": "0.14.0", - "rollup": "2.7.6", + "rollup": "2.79.1", "rollup-plugin-cleanup": "3.1.1", "rollup-plugin-progress": "1.1.2", "rollup-plugin-typescript2": "0.27.0", diff --git a/scripts/build/build.ts b/scripts/build/build.ts index 4b9ec0d..c15738e 100644 --- a/scripts/build/build.ts +++ b/scripts/build/build.ts @@ -55,6 +55,7 @@ const inputOptions: RollupOptions = { input: 'src/index.ts', treeshake: { annotations: true, + propertyReadSideEffects: false, }, plugins: [ replace({ diff --git a/src/index.ts b/src/index.ts index 96f957d..cf34a6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,11 @@ import { ProviderResultPromised, MetrikaCounterConstructor, } from 'src/types'; -import { normalizeOptions, getCounterKey } from 'src/utils/counterOptions'; +import { + normalizeOptions, + getCounterKey, + normalizeOriginalOptions, +} from 'src/utils/counterOptions'; import { bindArgs, firstArg, @@ -29,6 +33,7 @@ import { TELEMETRY_FEATURE, STACK_PROXY_FEATURE, DEBUG_EVENTS_FEATURE, + TURBO_PARAMS_FEATURE, } from 'generated/features'; import { getOriginalOptions, @@ -61,6 +66,8 @@ import { yaNamespace, ASYNC_PROVIDERS_MAX_EXEC_TIME } from './const'; import { stackProxy } from './providers/stackProxy/stackProxy'; import { DUPLICATE_COUNTERS_CONSOLE_MESSAGE } from './providers/consoleRenderer/dictionary'; import { dispatchDebuggerEvent } from './utils/debugEvents'; +import { getCounterOptionsState } from './utils/counterOptions/counterOptionsStore'; +import { setTurboInfo } from './utils/turboParams/turboParams'; type CounterMethod = keyof CounterObject; const globalConfig = getGlobalStorage(window); @@ -88,13 +95,18 @@ const MetrikaCounter: MetrikaCounterConstructor = function MetrikaCounter( } // eslint-disable-next-line @typescript-eslint/no-this-alias const thisInstance = this; - const counterOptions = normalizeOptions( + const counterData = normalizeOriginalOptions( counterId, - optionsKeysMap, counterParams, counterType, counterDefer, ); + const counterOptions = normalizeOptions(counterData, optionsKeysMap); + const state = getCounterOptionsState(counterOptions); + state.rawOptions = counterData; + if (flags[TURBO_PARAMS_FEATURE]) { + setTurboInfo(counterOptions, counterOptions.params || {}); + } const unsubscribeMethods: Array<() => void | null | undefined> = []; diff --git a/src/utils/counterOptions/__tests__/counterOptions.spec.ts b/src/utils/counterOptions/__tests__/counterOptions.spec.ts index c411d42..7eea45b 100644 --- a/src/utils/counterOptions/__tests__/counterOptions.spec.ts +++ b/src/utils/counterOptions/__tests__/counterOptions.spec.ts @@ -41,11 +41,13 @@ describe('Counter Options', () => { const opt: { [key: string]: any; } = normalizeOptions( - id, + { + id, + params, + type: counterType, + defer: counterDefer, + }, optionsKeysMapStub, - params, - counterType, - counterDefer, ); sinon.assert.calledOnce(normalizeIdFake); chai.expect(opt.id).to.eq(resultId); diff --git a/src/utils/counterOptions/counterOptions.ts b/src/utils/counterOptions/counterOptions.ts index 5086ce4..78801f5 100644 --- a/src/utils/counterOptions/counterOptions.ts +++ b/src/utils/counterOptions/counterOptions.ts @@ -1,24 +1,25 @@ -import { flags } from '@inject'; -import { TURBO_PARAMS_FEATURE } from 'generated/features'; import { RSYA_COUNTER_TYPE } from 'src/providers/counterOptions/const'; -import { OptionsKeysMaps } from 'src/providers/counterOptions/types'; +import type { OptionsKeysMaps } from 'src/providers/counterOptions/types'; import { cReduce } from 'src/utils/array'; import { equal } from 'src/utils/function'; import { entries, isObject } from 'src/utils/object'; -import { setTurboInfo } from 'src/utils/turboParams'; -import { CounterOptions, CounterTypeInterface } from './types'; +import type { + CounterOptions, + CounterTypeInterface, + RawCounterOptions, +} from './types'; // NOTE: Extend the type in order to be able to check all string inputs. export const isRsyaCounter = equal(RSYA_COUNTER_TYPE); export const normalizeOriginalOptions = ( - counterId: Record | number, + counterId: RawCounterOptions | number, counterParams?: Record, counterType?: number, counterDefer?: boolean, -): Record => { - return isObject(counterId) +): RawCounterOptions => + isObject(counterId) ? counterId : { ['id']: counterId, @@ -26,23 +27,12 @@ export const normalizeOriginalOptions = ( ['defer']: counterDefer, ['params']: counterParams, }; -}; export const normalizeOptions = ( - counterId: Record | number, + counterData: RawCounterOptions, optionsKeysMap: OptionsKeysMaps, - counterParams?: Record, - counterType?: number, - counterDefer?: boolean, -): CounterOptions => { - const counterData: Record = normalizeOriginalOptions( - counterId, - counterParams, - counterType, - counterDefer, - ); - - const options = cReduce( +): CounterOptions => + cReduce( ( acc: Record, [obfuscatedKey, { optKey: key, normalizeFunction: normalize }], @@ -55,10 +45,3 @@ export const normalizeOptions = ( {}, entries(optionsKeysMap), ) as unknown as CounterOptions; - - if (flags[TURBO_PARAMS_FEATURE]) { - setTurboInfo(options, options.params || {}); - } - - return options; -}; diff --git a/src/utils/counterOptions/counterOptionsStore.ts b/src/utils/counterOptions/counterOptionsStore.ts new file mode 100644 index 0000000..155c5e6 --- /dev/null +++ b/src/utils/counterOptions/counterOptionsStore.ts @@ -0,0 +1,13 @@ +import { constructObject } from 'src/utils/function/construct'; +import { memo } from 'src/utils/function/memo'; +import { getCounterKey } from './getCounterKey'; +import type { CounterOptions, RawCounterOptions } from './types'; + +type RawCounterOptionsState = { + rawOptions?: RawCounterOptions; +}; + +export const getCounterOptionsState = memo( + constructObject as (options: CounterOptions) => RawCounterOptionsState, + getCounterKey, +); diff --git a/src/utils/counterOptions/types.ts b/src/utils/counterOptions/types.ts index 00930e1..ec7fe69 100644 --- a/src/utils/counterOptions/types.ts +++ b/src/utils/counterOptions/types.ts @@ -3,6 +3,8 @@ import { RSYA_COUNTER_TYPE, } from 'src/providers/counterOptions/const'; +export type RawCounterOptions = Record; + export type RawTrackLinkParams = string | Record | boolean; export type CounterTypeInterface = diff --git a/src/utils/errorLogger/handleError.ts b/src/utils/errorLogger/handleError.ts index 05ffb7b..53c4f91 100644 --- a/src/utils/errorLogger/handleError.ts +++ b/src/utils/errorLogger/handleError.ts @@ -21,9 +21,24 @@ import { runOnErrorCallbacks } from './onError'; import { stringIncludes } from '../string'; export const handleError = (ctx: Window, scopeName: string, e: LoggerError) => { - // Undefined as error - let message = 'u.a.e'; - let stack = ''; + if (flags[DEBUG_FEATURE]) { + if (flags[DEBUG_EVENTS_FEATURE]) { + dispatchDebuggerEvent(ctx, { + ['data']: { + ['scopeName']: scopeName, + ['error']: e, + }, + ['name']: 'error', + }); + } + // break promise catch exceptions + const setTimeout: Window['setTimeout'] = getNativeFunction( + 'setTimeout', + ctx, + ); + // eslint-disable-next-line ban/ban + return setTimeout(bindArg(e, throwFunction), 0); + } if ( flags[LOCAL_FEATURE] && @@ -35,6 +50,11 @@ export const handleError = (ctx: Window, scopeName: string, e: LoggerError) => { // eslint-disable-next-line no-console console.error(e); } + + // Undefined as error + let message = 'u.a.e'; + let stack = ''; + if (e) { if (typeof e === 'object') { if (e[UNCATCHABLE_ERROR_PROPERTY]) { @@ -46,29 +66,10 @@ export const handleError = (ctx: Window, scopeName: string, e: LoggerError) => { e.stack.replace(/\n/g, '\\n')) || 'n.s.e.s'; } else { - message = `${e as any}`; + message = `${e}`; } } - // break promise catch exceptions - if (flags[DEBUG_FEATURE]) { - const setTimeout: Window['setTimeout'] = getNativeFunction( - 'setTimeout', - ctx, - ); - if (flags[DEBUG_EVENTS_FEATURE]) { - dispatchDebuggerEvent(ctx, { - ['data']: { - ['scopeName']: scopeName, - ['error']: e, - }, - ['name']: 'error', - }); - } - // eslint-disable-next-line ban/ban - return setTimeout(bindArg(e, throwFunction), 0); - } - const ignoreCondition = isKnownError(message) || cSome(bindArg(message, stringIncludes), IGNORED_ERRORS) || diff --git a/tsconfig.json b/tsconfig.json index c3ae1b6..b6a184b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,6 @@ { "experimentalDecorators": true, "compilerOptions": { - "jsx": "react-jsx", - "jsxImportSource": "preact", "incremental": true, "strict": true, "module": "commonjs", diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index dcda166..c3c89e8 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -2,6 +2,6 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "es2015", - "target": "ES3" + "target": "ES6" } }