Skip to content

Commit

Permalink
Update rollup to v2.79.1
Browse files Browse the repository at this point in the history
commit_hash:286fcc0ac2efd545266c9373459270b07d5a7d0f
  • Loading branch information
sabio committed Nov 26, 2024
1 parent cf3652a commit 46485ed
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 104 deletions.
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 15 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions scripts/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const inputOptions: RollupOptions = {
input: 'src/index.ts',
treeshake: {
annotations: true,
propertyReadSideEffects: false,
},
plugins: [
replace({
Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +33,7 @@ import {
TELEMETRY_FEATURE,
STACK_PROXY_FEATURE,
DEBUG_EVENTS_FEATURE,
TURBO_PARAMS_FEATURE,
} from 'generated/features';
import {
getOriginalOptions,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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> = [];

Expand Down
10 changes: 6 additions & 4 deletions src/utils/counterOptions/__tests__/counterOptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 12 additions & 29 deletions src/utils/counterOptions/counterOptions.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
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<CounterTypeInterface | string>(RSYA_COUNTER_TYPE);

export const normalizeOriginalOptions = (
counterId: Record<string, unknown> | number,
counterId: RawCounterOptions | number,
counterParams?: Record<string, unknown>,
counterType?: number,
counterDefer?: boolean,
): Record<string, unknown> => {
return isObject(counterId)
): RawCounterOptions =>
isObject(counterId)
? counterId
: {
['id']: counterId,
['type']: counterType,
['defer']: counterDefer,
['params']: counterParams,
};
};

export const normalizeOptions = (
counterId: Record<string, unknown> | number,
counterData: RawCounterOptions,
optionsKeysMap: OptionsKeysMaps,
counterParams?: Record<string, unknown>,
counterType?: number,
counterDefer?: boolean,
): CounterOptions => {
const counterData: Record<string, unknown> = normalizeOriginalOptions(
counterId,
counterParams,
counterType,
counterDefer,
);

const options = cReduce(
): CounterOptions =>
cReduce(
(
acc: Record<string, unknown>,
[obfuscatedKey, { optKey: key, normalizeFunction: normalize }],
Expand All @@ -55,10 +45,3 @@ export const normalizeOptions = (
{},
entries(optionsKeysMap),
) as unknown as CounterOptions;

if (flags[TURBO_PARAMS_FEATURE]) {
setTurboInfo(options, options.params || {});
}

return options;
};
13 changes: 13 additions & 0 deletions src/utils/counterOptions/counterOptionsStore.ts
Original file line number Diff line number Diff line change
@@ -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,
);
2 changes: 2 additions & 0 deletions src/utils/counterOptions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
RSYA_COUNTER_TYPE,
} from 'src/providers/counterOptions/const';

export type RawCounterOptions = Record<string, unknown>;

export type RawTrackLinkParams = string | Record<string, unknown> | boolean;

export type CounterTypeInterface =
Expand Down
47 changes: 24 additions & 23 deletions src/utils/errorLogger/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] &&
Expand All @@ -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]) {
Expand All @@ -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) ||
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"experimentalDecorators": true,
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact",
"incremental": true,
"strict": true,
"module": "commonjs",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2015",
"target": "ES3"
"target": "ES6"
}
}

0 comments on commit 46485ed

Please sign in to comment.