Skip to content

Commit 4657a97

Browse files
authored
chore(Worklets): export unpackers in prod env (#9029)
## Summary Required for #8673 Setting `NODE_ENV` to production when exporting unpackers. This has no impact on the current unpackers behavior but will come handy in the mentioned PR. ## Test plan Synchronizable runtime tests pass, other unpackers exported code didn't change.
1 parent 4fa68e5 commit 4657a97

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

apps/fabric-example/ios/Podfile.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-worklets/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace worklets {
88

99
const char SynchronizableUnpackerCode[] =
1010
R"DELIMITER__((function () {
11-
var serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE_ENABLED ? _serializable.createSerializable : function (value) {
11+
var serializer = globalThis.__RUNTIME_KIND === 1 || globalThis._WORKLETS_BUNDLE_MODE_ENABLED ? createSerializable : function (value) {
1212
return globalThis.__serializer(value);
1313
};
1414
function synchronizableUnpacker(synchronizableRef) {

packages/react-native-worklets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"scripts": {
1212
"build": "yarn workspace babel-plugin-worklets build && bob build && yarn build:unpackers",
13-
"build:unpackers": "node ./scripts/export-unpackers.js",
13+
"build:unpackers": "NODE_ENV='production' node ./scripts/export-unpackers.js",
1414
"circular-dependency-check": "yarn madge --extensions js,jsx --circular lib",
1515
"find-unused-code:js": "knip",
1616
"format": "yarn format:js && yarn format:plugin && yarn format:common && yarn format:android && yarn format:apple",

packages/react-native-worklets/scripts/export-unpackers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const generate = require('@babel/generator').default;
99
const path = require('path');
1010
const fs = require('fs');
1111
const assert = require('assert').strict;
12+
const workletsBabelPlugin = require('../plugin');
13+
14+
/** @type {import('../plugin/').PluginOptions} */
15+
const workletsBabelPluginOptions = {};
1216

1317
exportToCpp('valueUnpacker.native.ts', 'ValueUnpacker');
1418
exportToCpp('synchronizableUnpacker.native.ts', 'SynchronizableUnpacker');
@@ -31,10 +35,12 @@ function exportToCpp(sourceFilePath, outputFilename) {
3135
['@babel/preset-env', { modules: false }],
3236
'@babel/preset-typescript',
3337
],
38+
plugins: [[workletsBabelPlugin, workletsBabelPluginOptions]],
3439
sourceType: 'unambiguous',
3540
code: false,
3641
ast: true,
3742
comments: false,
43+
configFile: false,
3844
}
3945
);
4046

@@ -90,4 +96,6 @@ const char ${cstrName}[] =
9096
`,
9197
'utf8'
9298
);
99+
100+
console.log(`✅ Exported ${sourceFilePath} to ${outputFilename}.cpp`);
93101
}

packages/react-native-worklets/src/memory/synchronizableUnpacker.native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type Synchronizable, type SynchronizableRef } from './types';
66
export function __installUnpacker() {
77
// TODO: Add cache for synchronizables.
88
const serializer =
9-
!globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE_ENABLED
9+
globalThis.__RUNTIME_KIND === 1 || globalThis._WORKLETS_BUNDLE_MODE_ENABLED
1010
? createSerializable
1111
: (value: unknown) => globalThis.__serializer(value);
1212

0 commit comments

Comments
 (0)