react-native-worklets 0.3.0 → 0.4.0-bundle-mode-preview-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +532 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +40 -122
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +16 -40
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +2 -1
- package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/Shareables.cpp +200 -24
- package/Common/cpp/worklets/SharedItems/Shareables.h +108 -7
- package/Common/cpp/worklets/Tools/JSLogger.cpp +56 -4
- package/Common/cpp/worklets/Tools/JSLogger.h +17 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +12 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +10 -2
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +3 -1
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +19 -1
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +12 -3
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +136 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +4 -4
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +1 -1
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +85 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +55 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +8 -4
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +70 -24
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +24 -4
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +53 -1
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +2 -1
- package/RNWorklets.podspec +9 -4
- package/android/CMakeLists.txt +14 -36
- package/android/build.gradle +16 -33
- package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
- package/android/src/{main/java → legacyBundling}/com/swmansion/worklets/WorkletsModule.java +17 -2
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +49 -8
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +17 -2
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +1 -1
- package/apple/worklets/apple/WorkletsMessageThread.mm +4 -0
- package/apple/worklets/apple/WorkletsModule.h +16 -1
- package/apple/worklets/apple/WorkletsModule.mm +29 -2
- package/bundleMode/index.d.ts +3 -0
- package/bundleMode/index.js +55 -0
- package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
- package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
- package/lib/module/PlatformChecker/index.js +17 -0
- package/lib/module/PlatformChecker/index.js.map +1 -0
- package/lib/module/WorkletsError.js +2 -1
- package/lib/module/WorkletsError.js.map +1 -1
- package/lib/module/WorkletsModule/JSWorklets.js +36 -4
- package/lib/module/WorkletsModule/JSWorklets.js.map +1 -1
- package/lib/module/WorkletsModule/NativeWorklets.js +35 -15
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -1
- package/lib/module/WorkletsModule/workletsModuleInstance.js +2 -2
- package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -1
- package/lib/module/bundleUnpacker.js +47 -0
- package/lib/module/bundleUnpacker.js.map +1 -0
- package/lib/module/callGuard.js +30 -0
- package/lib/module/callGuard.js.map +1 -0
- package/lib/module/errors.js +30 -11
- package/lib/module/errors.js.map +1 -1
- package/lib/module/index.js +10 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers.js +123 -103
- package/lib/module/initializers.js.map +1 -1
- package/lib/module/logger.js +15 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/privateGlobals.d.js +0 -1
- package/lib/module/privateGlobals.d.js.map +1 -1
- package/lib/module/publicGlobals.js +5 -0
- package/lib/module/publicGlobals.js.map +1 -0
- package/lib/module/runLoop/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/requestAnimationFrame.js +50 -0
- package/lib/module/runLoop/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runtimes.js +6 -10
- package/lib/module/runtimes.js.map +1 -1
- package/lib/module/shareableMappingCache.js +1 -3
- package/lib/module/shareableMappingCache.js.map +1 -1
- package/lib/module/shareables.js +116 -34
- package/lib/module/shareables.js.map +1 -1
- package/lib/module/specs/index.js +2 -2
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/threads.js +49 -54
- package/lib/module/threads.js.map +1 -1
- package/lib/module/valueUnpacker.js +3 -3
- package/lib/module/valueUnpacker.js.map +1 -1
- package/lib/module/workletRuntimeEntry.js +30 -0
- package/lib/module/workletRuntimeEntry.js.map +1 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
- package/lib/typescript/PlatformChecker/index.d.ts +10 -0
- package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
- package/lib/typescript/WorkletsError.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +1 -3
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +12 -2
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/bundleUnpacker.d.ts +7 -0
- package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
- package/lib/typescript/callGuard.d.ts +4 -0
- package/lib/typescript/callGuard.d.ts.map +1 -0
- package/lib/typescript/errors.d.ts +13 -5
- package/lib/typescript/errors.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/initializers.d.ts +16 -5
- package/lib/typescript/initializers.d.ts.map +1 -1
- package/lib/typescript/logger.d.ts +5 -0
- package/lib/typescript/logger.d.ts.map +1 -0
- package/lib/typescript/publicGlobals.d.ts +22 -0
- package/lib/typescript/publicGlobals.d.ts.map +1 -0
- package/lib/typescript/runLoop/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts.map +1 -1
- package/lib/typescript/shareableMappingCache.d.ts.map +1 -1
- package/lib/typescript/shareables.d.ts +3 -2
- package/lib/typescript/shareables.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/lib/typescript/specs/index.d.ts +2 -2
- package/lib/typescript/specs/index.d.ts.map +1 -1
- package/lib/typescript/threads.d.ts.map +1 -1
- package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
- package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
- package/lib/typescript/workletTypes.d.ts +14 -3
- package/lib/typescript/workletTypes.d.ts.map +1 -1
- package/package.json +17 -8
- package/plugin/index.js +145 -52
- package/scripts/worklets_utils.rb +9 -0
- package/src/PlatformChecker/PlatformChecker.ts +7 -0
- package/src/PlatformChecker/index.ts +29 -0
- package/src/WorkletsError.ts +2 -1
- package/src/WorkletsModule/JSWorklets.ts +71 -4
- package/src/WorkletsModule/NativeWorklets.ts +83 -21
- package/src/WorkletsModule/workletsModuleInstance.ts +2 -2
- package/src/WorkletsModule/workletsModuleProxy.ts +49 -1
- package/src/bundleUnpacker.ts +75 -0
- package/src/callGuard.ts +33 -0
- package/src/errors.ts +35 -18
- package/src/index.ts +12 -12
- package/src/initializers.ts +143 -113
- package/src/logger.ts +16 -0
- package/src/privateGlobals.d.ts +22 -6
- package/src/publicGlobals.ts +26 -0
- package/src/runLoop/requestAnimationFrame.ts +67 -0
- package/src/runLoop/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/setTimeoutPolyfill.ts +40 -0
- package/src/runtimes.ts +6 -11
- package/src/shareableMappingCache.ts +1 -3
- package/src/shareables.ts +179 -65
- package/src/specs/NativeWorkletsModule.ts +1 -1
- package/src/specs/index.ts +5 -2
- package/src/threads.ts +75 -65
- package/src/valueUnpacker.ts +3 -3
- package/src/workletRuntimeEntry.ts +30 -0
- package/src/workletTypes.ts +22 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +0 -139
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +0 -61
- package/android/src/paper/com/swmansion/worklets/NativeWorkletsModuleSpec.java +0 -26
- package/lib/module/PlatformChecker.js +0 -26
- package/lib/module/PlatformChecker.js.map +0 -1
- package/lib/module/animationFrameQueue/mockedRequestAnimationFrame.js.map +0 -1
- package/lib/module/animationFrameQueue/requestAnimationFrame.js +0 -36
- package/lib/module/animationFrameQueue/requestAnimationFrame.js.map +0 -1
- package/lib/module/logger/LogBox.js +0 -15
- package/lib/module/logger/LogBox.js.map +0 -1
- package/lib/module/logger/index.js +0 -5
- package/lib/module/logger/index.js.map +0 -1
- package/lib/module/logger/logger.js +0 -137
- package/lib/module/logger/logger.js.map +0 -1
- package/lib/typescript/PlatformChecker.d.ts +0 -6
- package/lib/typescript/PlatformChecker.d.ts.map +0 -1
- package/lib/typescript/animationFrameQueue/mockedRequestAnimationFrame.d.ts.map +0 -1
- package/lib/typescript/animationFrameQueue/requestAnimationFrame.d.ts.map +0 -1
- package/lib/typescript/logger/LogBox.d.ts +0 -32
- package/lib/typescript/logger/LogBox.d.ts.map +0 -1
- package/lib/typescript/logger/index.d.ts +0 -3
- package/lib/typescript/logger/index.d.ts.map +0 -1
- package/lib/typescript/logger/logger.d.ts +0 -52
- package/lib/typescript/logger/logger.d.ts.map +0 -1
- package/src/PlatformChecker.ts +0 -30
- package/src/animationFrameQueue/requestAnimationFrame.ts +0 -41
- package/src/logger/LogBox.ts +0 -55
- package/src/logger/index.ts +0 -3
- package/src/logger/logger.ts +0 -155
- /package/lib/module/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.js +0 -0
- /package/lib/typescript/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.d.ts +0 -0
- /package/lib/typescript/{animationFrameQueue → runLoop}/requestAnimationFrame.d.ts +0 -0
- /package/src/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.ts +0 -0
package/src/PlatformChecker.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export function isJest(): boolean {
|
|
5
|
-
return !!process.env.JEST_WORKER_ID;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function isWeb(): boolean {
|
|
9
|
-
return Platform.OS === 'web';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isAndroid(): boolean {
|
|
13
|
-
return Platform.OS === 'android';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function isWindows(): boolean {
|
|
17
|
-
return Platform.OS === 'windows';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function shouldBeUseWeb() {
|
|
21
|
-
return isJest() || isWeb() || isWindows();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function isWindowAvailable() {
|
|
25
|
-
// the window object is unavailable when building the server portion of a site that uses SSG
|
|
26
|
-
// this function shouldn't be used to conditionally render components
|
|
27
|
-
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
28
|
-
// @ts-ignore Fallback if `window` is undefined.
|
|
29
|
-
return typeof window !== 'undefined';
|
|
30
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { callMicrotasks } from '../threads';
|
|
4
|
-
|
|
5
|
-
export function setupRequestAnimationFrame() {
|
|
6
|
-
'worklet';
|
|
7
|
-
|
|
8
|
-
// Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
|
|
9
|
-
// so we avoid doing requestAnimationFrame batching in Jest environment.
|
|
10
|
-
const nativeRequestAnimationFrame = global.requestAnimationFrame;
|
|
11
|
-
|
|
12
|
-
let animationFrameCallbacks: Array<(timestamp: number) => void> = [];
|
|
13
|
-
let flushRequested = false;
|
|
14
|
-
|
|
15
|
-
global.__flushAnimationFrame = (frameTimestamp: number) => {
|
|
16
|
-
const currentCallbacks = animationFrameCallbacks;
|
|
17
|
-
animationFrameCallbacks = [];
|
|
18
|
-
currentCallbacks.forEach((f) => f(frameTimestamp));
|
|
19
|
-
callMicrotasks();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
global.requestAnimationFrame = (
|
|
23
|
-
callback: (timestamp: number) => void
|
|
24
|
-
): number => {
|
|
25
|
-
animationFrameCallbacks.push(callback);
|
|
26
|
-
if (!flushRequested) {
|
|
27
|
-
flushRequested = true;
|
|
28
|
-
nativeRequestAnimationFrame((timestamp) => {
|
|
29
|
-
flushRequested = false;
|
|
30
|
-
global.__frameTimestamp = timestamp;
|
|
31
|
-
global.__flushAnimationFrame(timestamp);
|
|
32
|
-
global.__frameTimestamp = undefined;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
// Reanimated currently does not support cancelling callbacks requested with
|
|
36
|
-
// requestAnimationFrame. We return -1 as identifier which isn't in line
|
|
37
|
-
// with the spec but it should give users better clue in case they actually
|
|
38
|
-
// attempt to store the value returned from rAF and use it for cancelling.
|
|
39
|
-
return -1;
|
|
40
|
-
};
|
|
41
|
-
}
|
package/src/logger/LogBox.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* Copied from: react-native/Libraries/LogBox/Data/LogBoxData.js
|
|
4
|
-
* react-native/Libraries/LogBox/Data/parseLogBoxLog.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { LogBoxStatic } from 'react-native';
|
|
8
|
-
import { LogBox as RNLogBox } from 'react-native';
|
|
9
|
-
|
|
10
|
-
export type LogBoxLogLevel = 'warn' | 'error' | 'fatal' | 'syntax';
|
|
11
|
-
|
|
12
|
-
type Message = {
|
|
13
|
-
content: string;
|
|
14
|
-
substitutions: { length: number; offset: number }[];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type Category = string;
|
|
18
|
-
|
|
19
|
-
interface Location {
|
|
20
|
-
row: number;
|
|
21
|
-
column: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface CodeFrame {
|
|
25
|
-
content: string;
|
|
26
|
-
location?: Location | null;
|
|
27
|
-
fileName: string;
|
|
28
|
-
collapse?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type ComponentStack = CodeFrame[];
|
|
32
|
-
|
|
33
|
-
type ComponentStackType = 'legacy' | 'stack';
|
|
34
|
-
|
|
35
|
-
export type LogData = {
|
|
36
|
-
level: LogBoxLogLevel;
|
|
37
|
-
message: Message;
|
|
38
|
-
category: Category;
|
|
39
|
-
componentStack: ComponentStack;
|
|
40
|
-
componentStackType: ComponentStackType | null;
|
|
41
|
-
stack?: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
interface LogBoxExtended extends LogBoxStatic {
|
|
45
|
-
addLog(data: LogData): void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const LogBox = RNLogBox as LogBoxExtended;
|
|
49
|
-
|
|
50
|
-
const noop = () => {
|
|
51
|
-
// do nothing
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Do nothing when addLogBoxLog is called if LogBox is not available
|
|
55
|
-
export const addLogBoxLog = LogBox?.addLog?.bind(LogBox) ?? noop;
|
package/src/logger/index.ts
DELETED
package/src/logger/logger.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
import type { LogBoxLogLevel, LogData } from './LogBox';
|
|
3
|
-
import { addLogBoxLog } from './LogBox';
|
|
4
|
-
|
|
5
|
-
const DOCS_URL =
|
|
6
|
-
'https://docs.swmansion.com/react-native-reanimated/docs/debugging/logger-configuration';
|
|
7
|
-
const DOCS_REFERENCE = `If you don't want to see this message, you can disable the \`strict\` mode. Refer to:\n${DOCS_URL} for more details.`;
|
|
8
|
-
|
|
9
|
-
type LogFunction = (data: LogData) => void;
|
|
10
|
-
|
|
11
|
-
export enum LogLevel {
|
|
12
|
-
warn = 1,
|
|
13
|
-
error = 2,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type LoggerConfig = {
|
|
17
|
-
level?: LogLevel;
|
|
18
|
-
strict?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type LoggerConfigInternal = {
|
|
22
|
-
logFunction: LogFunction;
|
|
23
|
-
} & Required<LoggerConfig>;
|
|
24
|
-
|
|
25
|
-
function logToConsole(data: LogData) {
|
|
26
|
-
'worklet';
|
|
27
|
-
switch (data.level) {
|
|
28
|
-
case 'warn':
|
|
29
|
-
console.warn(data.message.content);
|
|
30
|
-
break;
|
|
31
|
-
case 'error':
|
|
32
|
-
case 'fatal':
|
|
33
|
-
case 'syntax':
|
|
34
|
-
console.error(data.message.content);
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const DEFAULT_LOGGER_CONFIG: LoggerConfigInternal = {
|
|
40
|
-
logFunction: logToConsole,
|
|
41
|
-
level: LogLevel.warn,
|
|
42
|
-
strict: true,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function formatMessage(message: string) {
|
|
46
|
-
'worklet';
|
|
47
|
-
return `[Worklets] ${message}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function createLog(level: LogBoxLogLevel, message: string): LogData {
|
|
51
|
-
'worklet';
|
|
52
|
-
const formattedMessage = formatMessage(message);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
level,
|
|
56
|
-
message: {
|
|
57
|
-
content: formattedMessage,
|
|
58
|
-
substitutions: [],
|
|
59
|
-
},
|
|
60
|
-
category: formattedMessage,
|
|
61
|
-
componentStack: [],
|
|
62
|
-
componentStackType: null,
|
|
63
|
-
// eslint-disable-next-line reanimated/use-worklets-error
|
|
64
|
-
stack: new Error().stack,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Function that logs to LogBox and console. Used to replace the default console
|
|
70
|
-
* logging with logging to LogBox on the UI thread when runOnJS is available.
|
|
71
|
-
*
|
|
72
|
-
* @param data - The details of the log.
|
|
73
|
-
*/
|
|
74
|
-
export function logToLogBoxAndConsole(data: LogData) {
|
|
75
|
-
addLogBoxLog(data);
|
|
76
|
-
logToConsole(data);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Registers the logger configuration. use it only for Worklet runtimes.
|
|
81
|
-
*
|
|
82
|
-
* @param config - The config to register.
|
|
83
|
-
*/
|
|
84
|
-
export function registerLoggerConfig(config: LoggerConfigInternal) {
|
|
85
|
-
'worklet';
|
|
86
|
-
global.__workletsLoggerConfig = config;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Replaces the default log function with a custom implementation.
|
|
91
|
-
*
|
|
92
|
-
* @param logFunction - The custom log function.
|
|
93
|
-
*/
|
|
94
|
-
export function replaceLoggerImplementation(logFunction: LogFunction) {
|
|
95
|
-
'worklet';
|
|
96
|
-
registerLoggerConfig({ ...global.__workletsLoggerConfig, logFunction });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Updates logger configuration.
|
|
101
|
-
*
|
|
102
|
-
* @param options - The new logger configuration to apply.
|
|
103
|
-
*
|
|
104
|
-
* - Level: The minimum log level to display.
|
|
105
|
-
* - Strict: Whether to log warnings and errors that are not strict. Defaults to
|
|
106
|
-
* false.
|
|
107
|
-
*/
|
|
108
|
-
export function updateLoggerConfig(options?: Partial<LoggerConfig>) {
|
|
109
|
-
'worklet';
|
|
110
|
-
registerLoggerConfig({
|
|
111
|
-
...global.__workletsLoggerConfig,
|
|
112
|
-
// Don't reuse previous level and strict values from the global config
|
|
113
|
-
level: options?.level ?? DEFAULT_LOGGER_CONFIG.level,
|
|
114
|
-
strict: options?.strict ?? DEFAULT_LOGGER_CONFIG.strict,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
type LogOptions = {
|
|
119
|
-
strict?: boolean;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
function handleLog(
|
|
123
|
-
level: Exclude<LogBoxLogLevel, 'syntax' | 'fatal'>,
|
|
124
|
-
message: string,
|
|
125
|
-
options: LogOptions
|
|
126
|
-
) {
|
|
127
|
-
'worklet';
|
|
128
|
-
const config = global.__workletsLoggerConfig;
|
|
129
|
-
if (
|
|
130
|
-
// Don't log if the log is marked as strict-only and the config doesn't
|
|
131
|
-
// enable strict logging
|
|
132
|
-
(options.strict && !config.strict) ||
|
|
133
|
-
// Don't log if the log level is below the minimum configured level
|
|
134
|
-
LogLevel[level] < config.level
|
|
135
|
-
) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (options.strict) {
|
|
140
|
-
message += `\n\n${DOCS_REFERENCE}`;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
config.logFunction(createLog(level, message));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export const logger = {
|
|
147
|
-
warn(message: string, options: LogOptions = {}) {
|
|
148
|
-
'worklet';
|
|
149
|
-
handleLog('warn', message, options);
|
|
150
|
-
},
|
|
151
|
-
error(message: string, options: LogOptions = {}) {
|
|
152
|
-
'worklet';
|
|
153
|
-
handleLog('error', message, options);
|
|
154
|
-
},
|
|
155
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|