@react-native-windows/codegen 0.82.0-preview.1 → 0.82.0-preview.2
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/CHANGELOG.md +13 -5
- package/lib-commonjs/generators/GenerateModuleCpp.d.ts +1 -0
- package/lib-commonjs/generators/GenerateModuleCpp.js +186 -0
- package/lib-commonjs/generators/GenerateModuleCpp.js.map +1 -0
- package/lib-commonjs/index.js +3 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/generators/GenerateModuleCpp.js +245 -0
- package/src/index.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Tue, 20 Jan 2026 18:42:21 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.82.0-preview.
|
|
7
|
+
## 0.82.0-preview.2
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Tue, 20 Jan 2026 18:42:21 GMT
|
|
10
10
|
|
|
11
11
|
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
- Bump @react-native-windows/fs to v0.82.0-preview.1
|
|
13
|
+
- forking GenerateModuleCpp (66076509+vineethkuttan@users.noreply.github.com)
|
|
15
14
|
|
|
15
|
+
## 0.82.0-preview.1
|
|
16
|
+
|
|
17
|
+
Wed, 14 Jan 2026 13:07:18 GMT
|
|
18
|
+
|
|
19
|
+
### Changes
|
|
20
|
+
|
|
21
|
+
- Promote 0.82 to preview (74712637+iamAbhi-916@users.noreply.github.com)
|
|
22
|
+
- Bump @react-native-windows/fs to v0.82.0-preview.1
|
|
23
|
+
|
|
16
24
|
## 0.0.0-canary.129
|
|
17
25
|
|
|
18
26
|
Sat, 10 Jan 2026 06:40:18 GMT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function generate(libraryName: any, schema: any, packageName: any, assumeNonnull: boolean | undefined, headerPrefix: any): Map<string, string>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
const path = require('path');
|
|
12
|
+
// Load dependencies from @react-native/codegen
|
|
13
|
+
const rnPath = path.dirname(require.resolve('react-native/package.json'));
|
|
14
|
+
const rncodegenPath = path.dirname(require.resolve('@react-native/codegen/package.json', { paths: [rnPath] }));
|
|
15
|
+
const { unwrapNullable } = require(path.resolve(rncodegenPath, 'lib/parsers/parsers-commons'));
|
|
16
|
+
const { createAliasResolver, getModules } = require(path.resolve(rncodegenPath, 'lib/generators/modules/Utils'));
|
|
17
|
+
const HostFunctionTemplate = ({ hasteModuleName, methodName, returnTypeAnnotation, args, }) => {
|
|
18
|
+
const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation';
|
|
19
|
+
const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation';
|
|
20
|
+
const methodCallArgs = [' rt', ...args].join(',\n ');
|
|
21
|
+
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`;
|
|
22
|
+
return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${isVoid ? `\n ${methodCall};` : isNullable ? `\n auto result = ${methodCall};` : ''}
|
|
23
|
+
return ${isVoid ? 'jsi::Value::undefined()' : isNullable ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' : methodCall};
|
|
24
|
+
}`;
|
|
25
|
+
};
|
|
26
|
+
const ModuleTemplate = ({ hasteModuleName, hostFunctions, moduleName, methods, }) => {
|
|
27
|
+
return `${hostFunctions.join('\n')}
|
|
28
|
+
|
|
29
|
+
${hasteModuleName}CxxSpecJSI::${hasteModuleName}CxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
30
|
+
: TurboModule("${moduleName}", jsInvoker) {
|
|
31
|
+
${methods
|
|
32
|
+
.map(({ methodName, paramCount }) => {
|
|
33
|
+
return ` methodMap_["${methodName}"] = MethodMetadata {${paramCount}, __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}};`;
|
|
34
|
+
})
|
|
35
|
+
.join('\n')}
|
|
36
|
+
}`;
|
|
37
|
+
};
|
|
38
|
+
const FileTemplate = ({ libraryName, modules }) => {
|
|
39
|
+
return `/**
|
|
40
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
41
|
+
*
|
|
42
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
43
|
+
* once the code is regenerated.
|
|
44
|
+
*
|
|
45
|
+
* ${'@'}generated by codegen project: GenerateModuleCpp.js
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
#include "${libraryName}JSI.h"
|
|
49
|
+
|
|
50
|
+
namespace facebook::react {
|
|
51
|
+
|
|
52
|
+
${modules}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
} // namespace facebook::react
|
|
56
|
+
`;
|
|
57
|
+
};
|
|
58
|
+
function serializeArg(moduleName, arg, index, resolveAlias, enumMap) {
|
|
59
|
+
const { typeAnnotation: nullableTypeAnnotation, optional } = arg;
|
|
60
|
+
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
61
|
+
let realTypeAnnotation = typeAnnotation;
|
|
62
|
+
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
|
63
|
+
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
|
64
|
+
}
|
|
65
|
+
function wrap(callback) {
|
|
66
|
+
const val = `args[${index}]`;
|
|
67
|
+
const expression = callback(val);
|
|
68
|
+
// param?: T
|
|
69
|
+
if (optional && !nullable) {
|
|
70
|
+
// throw new Error('are we hitting this case? ' + moduleName);
|
|
71
|
+
return `count <= ${index} || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;
|
|
72
|
+
}
|
|
73
|
+
// param: ?T
|
|
74
|
+
// param?: ?T
|
|
75
|
+
if (nullable || optional) {
|
|
76
|
+
return `count <= ${index} || ${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;
|
|
77
|
+
}
|
|
78
|
+
// param: T
|
|
79
|
+
//return `count <= ${index} ? throw jsi::JSError(rt, "Expected argument in position ${index} to be passed") : ${expression}`;
|
|
80
|
+
//Windows #15545
|
|
81
|
+
return `(count > ${index} || (throw jsi::JSError(rt, "Expected argument in position ${index} to be passed"), false), ${expression})`;
|
|
82
|
+
//Windows
|
|
83
|
+
}
|
|
84
|
+
switch (realTypeAnnotation.type) {
|
|
85
|
+
case 'ReservedTypeAnnotation':
|
|
86
|
+
switch (realTypeAnnotation.name) {
|
|
87
|
+
case 'RootTag':
|
|
88
|
+
return wrap(val => `${val}.asNumber()`);
|
|
89
|
+
default:
|
|
90
|
+
realTypeAnnotation.name;
|
|
91
|
+
throw new Error(`Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.name}"`);
|
|
92
|
+
}
|
|
93
|
+
case 'StringTypeAnnotation':
|
|
94
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
95
|
+
case 'StringLiteralTypeAnnotation':
|
|
96
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
97
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
98
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
99
|
+
case 'BooleanTypeAnnotation':
|
|
100
|
+
return wrap(val => `${val}.asBool()`);
|
|
101
|
+
case 'EnumDeclaration':
|
|
102
|
+
switch (realTypeAnnotation.memberType) {
|
|
103
|
+
case 'NumberTypeAnnotation':
|
|
104
|
+
return wrap(val => `${val}.asNumber()`);
|
|
105
|
+
case 'StringTypeAnnotation':
|
|
106
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unknown enum type for "${arg.name}, found: ${realTypeAnnotation.type}"`);
|
|
109
|
+
}
|
|
110
|
+
case 'NumberTypeAnnotation':
|
|
111
|
+
return wrap(val => `${val}.asNumber()`);
|
|
112
|
+
case 'FloatTypeAnnotation':
|
|
113
|
+
return wrap(val => `${val}.asNumber()`);
|
|
114
|
+
case 'DoubleTypeAnnotation':
|
|
115
|
+
return wrap(val => `${val}.asNumber()`);
|
|
116
|
+
case 'Int32TypeAnnotation':
|
|
117
|
+
return wrap(val => `${val}.asNumber()`);
|
|
118
|
+
case 'NumberLiteralTypeAnnotation':
|
|
119
|
+
return wrap(val => `${val}.asNumber()`);
|
|
120
|
+
case 'ArrayTypeAnnotation':
|
|
121
|
+
return wrap(val => `${val}.asObject(rt).asArray(rt)`);
|
|
122
|
+
case 'FunctionTypeAnnotation':
|
|
123
|
+
return wrap(val => `${val}.asObject(rt).asFunction(rt)`);
|
|
124
|
+
case 'GenericObjectTypeAnnotation':
|
|
125
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
126
|
+
case 'UnionTypeAnnotation':
|
|
127
|
+
switch (typeAnnotation.memberType) {
|
|
128
|
+
case 'NumberTypeAnnotation':
|
|
129
|
+
return wrap(val => `${val}.asNumber()`);
|
|
130
|
+
case 'ObjectTypeAnnotation':
|
|
131
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
132
|
+
case 'StringTypeAnnotation':
|
|
133
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
134
|
+
default:
|
|
135
|
+
throw new Error(`Unsupported union member type for param "${arg.name}, found: ${realTypeAnnotation.memberType}"`);
|
|
136
|
+
}
|
|
137
|
+
case 'ObjectTypeAnnotation':
|
|
138
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
139
|
+
case 'MixedTypeAnnotation':
|
|
140
|
+
return wrap(val => `jsi::Value(rt, ${val})`);
|
|
141
|
+
default:
|
|
142
|
+
realTypeAnnotation.type;
|
|
143
|
+
throw new Error(`Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.type}"`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function serializePropertyIntoHostFunction(moduleName, hasteModuleName, property, resolveAlias, enumMap) {
|
|
147
|
+
const [propertyTypeAnnotation] = unwrapNullable(property.typeAnnotation);
|
|
148
|
+
return HostFunctionTemplate({
|
|
149
|
+
hasteModuleName,
|
|
150
|
+
methodName: property.name,
|
|
151
|
+
returnTypeAnnotation: propertyTypeAnnotation.returnTypeAnnotation,
|
|
152
|
+
args: propertyTypeAnnotation.params.map((p, i) => serializeArg(moduleName, p, i, resolveAlias, enumMap)),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
module.exports = {
|
|
156
|
+
generate(libraryName, schema, packageName, assumeNonnull = false, headerPrefix) {
|
|
157
|
+
const nativeModules = getModules(schema);
|
|
158
|
+
const modules = Object.keys(nativeModules)
|
|
159
|
+
.map(hasteModuleName => {
|
|
160
|
+
const nativeModule = nativeModules[hasteModuleName];
|
|
161
|
+
const { aliasMap, enumMap, spec: { methods }, moduleName, } = nativeModule;
|
|
162
|
+
const resolveAlias = createAliasResolver(aliasMap);
|
|
163
|
+
const hostFunctions = methods.map(property => serializePropertyIntoHostFunction(moduleName, hasteModuleName, property, resolveAlias, enumMap));
|
|
164
|
+
return ModuleTemplate({
|
|
165
|
+
hasteModuleName,
|
|
166
|
+
hostFunctions,
|
|
167
|
+
moduleName,
|
|
168
|
+
methods: methods.map(({ name: propertyName, typeAnnotation: nullableTypeAnnotation }) => {
|
|
169
|
+
const [{ params }] = unwrapNullable(nullableTypeAnnotation);
|
|
170
|
+
return {
|
|
171
|
+
methodName: propertyName,
|
|
172
|
+
paramCount: params.length,
|
|
173
|
+
};
|
|
174
|
+
}),
|
|
175
|
+
});
|
|
176
|
+
})
|
|
177
|
+
.join('\n');
|
|
178
|
+
const fileName = `${libraryName}JSI-generated.cpp`;
|
|
179
|
+
const replacedTemplate = FileTemplate({
|
|
180
|
+
modules,
|
|
181
|
+
libraryName,
|
|
182
|
+
});
|
|
183
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=GenerateModuleCpp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateModuleCpp.js","sourceRoot":"","sources":["../../src/generators/GenerateModuleCpp.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,CAAC;AAEb,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,+CAA+C;AAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,oCAAoC,EAAE,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,CACzE,CAAC;AAEF,MAAM,EAAC,cAAc,EAAC,GAAG,OAAO,CAC9B,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,6BAA6B,CAAC,CAC3D,CAAC;AACF,MAAM,EAAC,mBAAmB,EAAE,UAAU,EAAC,GAAG,OAAO,CAC/C,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,8BAA8B,CAAC,CAC5D,CAAC;AACF,MAAM,oBAAoB,GAAG,CAAC,EAC5B,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,IAAI,GACL,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,oBAAoB,CAAC,IAAI,KAAK,wBAAwB,CAAC;IAC1E,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,KAAK,oBAAoB,CAAC;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C1D,OAAO;wBACL,UAAU,EAAE,YAAY;wBACxB,UAAU,EAAE,MAAM,CAAC,MAAM;qBAC1B,CAAC;gBACJ,CAAC,CACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,QAAQ,GAAG,GAAG,WAAW,mBAAmB,CAAC;QACnD,MAAM,gBAAgB,GAAG,YAAY,CAAC;YACpC,OAAO;YACP,WAAW;SACZ,CAAC,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;CACF,CAAC","sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * @format\n */\n\n'use strict';\n\nconst path = require('path');\n\n// Load dependencies from @react-native/codegen\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),\n);\n\nconst {unwrapNullable} = require(\n path.resolve(rncodegenPath, 'lib/parsers/parsers-commons'),\n);\nconst {createAliasResolver, getModules} = require(\n path.resolve(rncodegenPath, 'lib/generators/modules/Utils'),\n);\nconst HostFunctionTemplate = ({\n hasteModuleName,\n methodName,\n returnTypeAnnotation,\n args,\n}) => {\n const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation';\n const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation';\n const methodCallArgs = [' rt', ...args].join(',\\n ');\n const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\\n${methodCallArgs}\\n )`;\n return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${isVoid ? `\\n ${methodCall};` : isNullable ? `\\n auto result = ${methodCall};` : ''}\n return ${isVoid ? 'jsi::Value::undefined()' : isNullable ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' : methodCall};\n}`;\n};\nconst ModuleTemplate = ({\n hasteModuleName,\n hostFunctions,\n moduleName,\n methods,\n}) => {\n return `${hostFunctions.join('\\n')}\n\n${hasteModuleName}CxxSpecJSI::${hasteModuleName}CxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)\n : TurboModule(\"${moduleName}\", jsInvoker) {\n${methods\n .map(({methodName, paramCount}) => {\n return ` methodMap_[\"${methodName}\"] = MethodMetadata {${paramCount}, __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}};`;\n })\n .join('\\n')}\n}`;\n};\nconst FileTemplate = ({libraryName, modules}) => {\n return `/**\n * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).\n *\n * Do not edit this file as changes may cause incorrect behavior and will be lost\n * once the code is regenerated.\n *\n * ${'@'}generated by codegen project: GenerateModuleCpp.js\n */\n\n#include \"${libraryName}JSI.h\"\n\nnamespace facebook::react {\n\n${modules}\n\n\n} // namespace facebook::react\n`;\n};\nfunction serializeArg(moduleName, arg, index, resolveAlias, enumMap) {\n const {typeAnnotation: nullableTypeAnnotation, optional} = arg;\n const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);\n let realTypeAnnotation = typeAnnotation;\n if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {\n realTypeAnnotation = resolveAlias(realTypeAnnotation.name);\n }\n function wrap(callback) {\n const val = `args[${index}]`;\n const expression = callback(val);\n\n // param?: T\n if (optional && !nullable) {\n // throw new Error('are we hitting this case? ' + moduleName);\n return `count <= ${index} || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;\n }\n\n // param: ?T\n // param?: ?T\n if (nullable || optional) {\n return `count <= ${index} || ${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;\n }\n\n // param: T\n //return `count <= ${index} ? throw jsi::JSError(rt, \"Expected argument in position ${index} to be passed\") : ${expression}`;\n //Windows #15545\n return `(count > ${index} || (throw jsi::JSError(rt, \"Expected argument in position ${index} to be passed\"), false), ${expression})`;\n //Windows\n }\n switch (realTypeAnnotation.type) {\n case 'ReservedTypeAnnotation':\n switch (realTypeAnnotation.name) {\n case 'RootTag':\n return wrap(val => `${val}.asNumber()`);\n default:\n realTypeAnnotation.name;\n throw new Error(\n `Unknown prop type for \"${arg.name}, found: ${realTypeAnnotation.name}\"`,\n );\n }\n case 'StringTypeAnnotation':\n return wrap(val => `${val}.asString(rt)`);\n case 'StringLiteralTypeAnnotation':\n return wrap(val => `${val}.asString(rt)`);\n case 'StringLiteralUnionTypeAnnotation':\n return wrap(val => `${val}.asString(rt)`);\n case 'BooleanTypeAnnotation':\n return wrap(val => `${val}.asBool()`);\n case 'EnumDeclaration':\n switch (realTypeAnnotation.memberType) {\n case 'NumberTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'StringTypeAnnotation':\n return wrap(val => `${val}.asString(rt)`);\n default:\n throw new Error(\n `Unknown enum type for \"${arg.name}, found: ${realTypeAnnotation.type}\"`,\n );\n }\n case 'NumberTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'FloatTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'DoubleTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'Int32TypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'NumberLiteralTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'ArrayTypeAnnotation':\n return wrap(val => `${val}.asObject(rt).asArray(rt)`);\n case 'FunctionTypeAnnotation':\n return wrap(val => `${val}.asObject(rt).asFunction(rt)`);\n case 'GenericObjectTypeAnnotation':\n return wrap(val => `${val}.asObject(rt)`);\n case 'UnionTypeAnnotation':\n switch (typeAnnotation.memberType) {\n case 'NumberTypeAnnotation':\n return wrap(val => `${val}.asNumber()`);\n case 'ObjectTypeAnnotation':\n return wrap(val => `${val}.asObject(rt)`);\n case 'StringTypeAnnotation':\n return wrap(val => `${val}.asString(rt)`);\n default:\n throw new Error(\n `Unsupported union member type for param \"${arg.name}, found: ${realTypeAnnotation.memberType}\"`,\n );\n }\n case 'ObjectTypeAnnotation':\n return wrap(val => `${val}.asObject(rt)`);\n case 'MixedTypeAnnotation':\n return wrap(val => `jsi::Value(rt, ${val})`);\n default:\n realTypeAnnotation.type;\n throw new Error(\n `Unknown prop type for \"${arg.name}, found: ${realTypeAnnotation.type}\"`,\n );\n }\n}\nfunction serializePropertyIntoHostFunction(\n moduleName,\n hasteModuleName,\n property,\n resolveAlias,\n enumMap,\n) {\n const [propertyTypeAnnotation] = unwrapNullable(property.typeAnnotation);\n return HostFunctionTemplate({\n hasteModuleName,\n methodName: property.name,\n returnTypeAnnotation: propertyTypeAnnotation.returnTypeAnnotation,\n args: propertyTypeAnnotation.params.map((p, i) =>\n serializeArg(moduleName, p, i, resolveAlias, enumMap),\n ),\n });\n}\nmodule.exports = {\n generate(\n libraryName,\n schema,\n packageName,\n assumeNonnull = false,\n headerPrefix,\n ) {\n const nativeModules = getModules(schema);\n const modules = Object.keys(nativeModules)\n .map(hasteModuleName => {\n const nativeModule = nativeModules[hasteModuleName];\n const {\n aliasMap,\n enumMap,\n spec: {methods},\n moduleName,\n } = nativeModule;\n const resolveAlias = createAliasResolver(aliasMap);\n const hostFunctions = methods.map(property =>\n serializePropertyIntoHostFunction(\n moduleName,\n hasteModuleName,\n property,\n resolveAlias,\n enumMap,\n ),\n );\n return ModuleTemplate({\n hasteModuleName,\n hostFunctions,\n moduleName,\n methods: methods.map(\n ({name: propertyName, typeAnnotation: nullableTypeAnnotation}) => {\n const [{params}] = unwrapNullable(nullableTypeAnnotation);\n return {\n methodName: propertyName,\n paramCount: params.length,\n };\n },\n ),\n });\n })\n .join('\\n');\n const fileName = `${libraryName}JSI-generated.cpp`;\n const replacedTemplate = FileTemplate({\n modules,\n libraryName,\n });\n return new Map([[fileName, replacedTemplate]]);\n },\n};\n"]}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -150,7 +150,9 @@ function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes,
|
|
|
150
150
|
separateDataTypes,
|
|
151
151
|
});
|
|
152
152
|
const generateJsiModuleH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleH')).generate;
|
|
153
|
-
|
|
153
|
+
// Use local fixed version instead of upstream to fix x86 union padding issue
|
|
154
|
+
// with MixedTypeAnnotation. See GenerateModuleCpp.js for details.
|
|
155
|
+
const generateJsiModuleCpp = require('./generators/GenerateModuleCpp').generate;
|
|
154
156
|
const generatorPropsH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsH')).generate;
|
|
155
157
|
const generatorPropsCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsCpp')).generate;
|
|
156
158
|
const generatorShadowNodeH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateShadowNodeH')).generate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAE5B,0DAA4D;AAC5D,oFAA+E;AAC/E,wEAGyC;AAMzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,oCAAoC,EAAE,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,CACzE,CAAC;AAEF,SAAS,SAAS,CAAC,YAAqB;IACtC,IAAI,YAAY,EAAE;QAChB,MAAM,EAAE,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC7B,aAAa,EACb,+BAA+B,CAChC,CAAC,CAAC;QACH,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AAc,EAAE,eAAe,CAAC,CAAC;KAC9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AA1JD,4BA0JC;AAQD,SAAgB,UAAU,CAAC,OAAuB;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,sBAAsB;QACtB,cAAc;QACd,iBAAiB;QACjB,kBAAkB;QAClB,SAAS;QACT,eAAe;QACf,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAxCD,gCAwCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {createComponentGenerator} from './generators/GenerateComponentWindows';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport type {Parser} from '@react-native/codegen/lib/parsers/parser';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\n\n// Load @react-native/codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),\n);\n\nfunction getParser(isTypeScript: boolean): Parser {\n if (isTypeScript) {\n const fp = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript/parser',\n ));\n return new fp.TypeScriptParser();\n } else {\n const fp = require(path.resolve(rncodegenPath, 'lib/parsers/flow/parser'));\n return new fp.FlowParser();\n }\n}\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/SchemaValidator',\n));\n\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n componentsWindows: boolean;\n internalComponents: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n const allExistingFiles = globby\n .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true})\n .map(_ => path.normalize(_));\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allGeneratedFiles.every(filepath =>\n allExistingFiles.includes(\n path.normalize(path.resolve(process.cwd(), filepath)),\n ),\n )\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(\n [`${globbyDir}/**`, `${globbyDir}/**/.*`],\n {absolute: true},\n );\n\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n allExistingFiles.forEach(existingFile => {\n if (!allGeneratedFiles.includes(path.normalize(existingFile))) {\n console.log('Deleting ', existingFile);\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n console.log('Writing ', fileName);\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n const contents = fs.readFileSync(filename, 'utf8');\n const schema = getParser(isTypeScript).parseString(contents, filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nexport function combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n internalComponents,\n componentsWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCpp',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCpp',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [];\n\n if (internalComponents) {\n componentGenerators.push(\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\n generatorStateCPP,\n generatorStateH,\n );\n }\n\n if (componentsWindows) {\n const generateComponentWindows = createComponentGenerator({\n namespace,\n cppStringType,\n });\n\n componentGenerators.push(generateComponentWindows);\n }\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nexport interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: string[];\n test: boolean;\n}\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n componentsWindows,\n internalComponents,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n componentsWindows,\n internalComponents,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAE5B,0DAA4D;AAC5D,oFAA+E;AAC/E,wEAGyC;AAMzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,oCAAoC,EAAE,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,CACzE,CAAC;AAEF,SAAS,SAAS,CAAC,YAAqB;IACtC,IAAI,YAAY,EAAE;QAChB,MAAM,EAAE,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC7B,aAAa,EACb,+BAA+B,CAChC,CAAC,CAAC;QAC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eAAe,CAAC,CAAC;KAC9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AA1JD,4BA0JC;AAQD,SAAgB,UAAU,CAAC,OAAuB;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,sBAAsB;QACtB,cAAc;QACd,iBAAiB;QACjB,kBAAkB;QAClB,SAAS;QACT,eAAe;QACf,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAxCD,gCAwCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {createComponentGenerator} from './generators/GenerateComponentWindows';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport type {Parser} from '@react-native/codegen/lib/parsers/parser';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\n\n// Load @react-native/codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),\n);\n\nfunction getParser(isTypeScript: boolean): Parser {\n if (isTypeScript) {\n const fp = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript/parser',\n ));\n return new fp.TypeScriptParser();\n } else {\n const fp = require(path.resolve(rncodegenPath, 'lib/parsers/flow/parser'));\n return new fp.FlowParser();\n }\n}\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/SchemaValidator',\n));\n\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n componentsWindows: boolean;\n internalComponents: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n const allExistingFiles = globby\n .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true})\n .map(_ => path.normalize(_));\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allGeneratedFiles.every(filepath =>\n allExistingFiles.includes(\n path.normalize(path.resolve(process.cwd(), filepath)),\n ),\n )\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(\n [`${globbyDir}/**`, `${globbyDir}/**/.*`],\n {absolute: true},\n );\n\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n allExistingFiles.forEach(existingFile => {\n if (!allGeneratedFiles.includes(path.normalize(existingFile))) {\n console.log('Deleting ', existingFile);\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n console.log('Writing ', fileName);\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n const contents = fs.readFileSync(filename, 'utf8');\n const schema = getParser(isTypeScript).parseString(contents, filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nexport function combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n internalComponents,\n componentsWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n // Use local fixed version instead of upstream to fix x86 union padding issue\n // with MixedTypeAnnotation. See GenerateModuleCpp.js for details.\n const generateJsiModuleCpp =\n require('./generators/GenerateModuleCpp').generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCpp',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCpp',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [];\n\n if (internalComponents) {\n componentGenerators.push(\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\n generatorStateCPP,\n generatorStateH,\n );\n }\n\n if (componentsWindows) {\n const generateComponentWindows = createComponentGenerator({\n namespace,\n cppStringType,\n });\n\n componentGenerators.push(generateComponentWindows);\n }\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nexport interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: string[];\n test: boolean;\n}\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n componentsWindows,\n internalComponents,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n componentsWindows,\n internalComponents,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
// Load dependencies from @react-native/codegen
|
|
16
|
+
const rnPath = path.dirname(require.resolve('react-native/package.json'));
|
|
17
|
+
const rncodegenPath = path.dirname(
|
|
18
|
+
require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const {unwrapNullable} = require(
|
|
22
|
+
path.resolve(rncodegenPath, 'lib/parsers/parsers-commons'),
|
|
23
|
+
);
|
|
24
|
+
const {createAliasResolver, getModules} = require(
|
|
25
|
+
path.resolve(rncodegenPath, 'lib/generators/modules/Utils'),
|
|
26
|
+
);
|
|
27
|
+
const HostFunctionTemplate = ({
|
|
28
|
+
hasteModuleName,
|
|
29
|
+
methodName,
|
|
30
|
+
returnTypeAnnotation,
|
|
31
|
+
args,
|
|
32
|
+
}) => {
|
|
33
|
+
const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation';
|
|
34
|
+
const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation';
|
|
35
|
+
const methodCallArgs = [' rt', ...args].join(',\n ');
|
|
36
|
+
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`;
|
|
37
|
+
return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${isVoid ? `\n ${methodCall};` : isNullable ? `\n auto result = ${methodCall};` : ''}
|
|
38
|
+
return ${isVoid ? 'jsi::Value::undefined()' : isNullable ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' : methodCall};
|
|
39
|
+
}`;
|
|
40
|
+
};
|
|
41
|
+
const ModuleTemplate = ({
|
|
42
|
+
hasteModuleName,
|
|
43
|
+
hostFunctions,
|
|
44
|
+
moduleName,
|
|
45
|
+
methods,
|
|
46
|
+
}) => {
|
|
47
|
+
return `${hostFunctions.join('\n')}
|
|
48
|
+
|
|
49
|
+
${hasteModuleName}CxxSpecJSI::${hasteModuleName}CxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
50
|
+
: TurboModule("${moduleName}", jsInvoker) {
|
|
51
|
+
${methods
|
|
52
|
+
.map(({methodName, paramCount}) => {
|
|
53
|
+
return ` methodMap_["${methodName}"] = MethodMetadata {${paramCount}, __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}};`;
|
|
54
|
+
})
|
|
55
|
+
.join('\n')}
|
|
56
|
+
}`;
|
|
57
|
+
};
|
|
58
|
+
const FileTemplate = ({libraryName, modules}) => {
|
|
59
|
+
return `/**
|
|
60
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
61
|
+
*
|
|
62
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
63
|
+
* once the code is regenerated.
|
|
64
|
+
*
|
|
65
|
+
* ${'@'}generated by codegen project: GenerateModuleCpp.js
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
#include "${libraryName}JSI.h"
|
|
69
|
+
|
|
70
|
+
namespace facebook::react {
|
|
71
|
+
|
|
72
|
+
${modules}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
} // namespace facebook::react
|
|
76
|
+
`;
|
|
77
|
+
};
|
|
78
|
+
function serializeArg(moduleName, arg, index, resolveAlias, enumMap) {
|
|
79
|
+
const {typeAnnotation: nullableTypeAnnotation, optional} = arg;
|
|
80
|
+
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
|
81
|
+
let realTypeAnnotation = typeAnnotation;
|
|
82
|
+
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
|
83
|
+
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
|
84
|
+
}
|
|
85
|
+
function wrap(callback) {
|
|
86
|
+
const val = `args[${index}]`;
|
|
87
|
+
const expression = callback(val);
|
|
88
|
+
|
|
89
|
+
// param?: T
|
|
90
|
+
if (optional && !nullable) {
|
|
91
|
+
// throw new Error('are we hitting this case? ' + moduleName);
|
|
92
|
+
return `count <= ${index} || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// param: ?T
|
|
96
|
+
// param?: ?T
|
|
97
|
+
if (nullable || optional) {
|
|
98
|
+
return `count <= ${index} || ${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// param: T
|
|
102
|
+
//return `count <= ${index} ? throw jsi::JSError(rt, "Expected argument in position ${index} to be passed") : ${expression}`;
|
|
103
|
+
//Windows #15545
|
|
104
|
+
return `(count > ${index} || (throw jsi::JSError(rt, "Expected argument in position ${index} to be passed"), false), ${expression})`;
|
|
105
|
+
//Windows
|
|
106
|
+
}
|
|
107
|
+
switch (realTypeAnnotation.type) {
|
|
108
|
+
case 'ReservedTypeAnnotation':
|
|
109
|
+
switch (realTypeAnnotation.name) {
|
|
110
|
+
case 'RootTag':
|
|
111
|
+
return wrap(val => `${val}.asNumber()`);
|
|
112
|
+
default:
|
|
113
|
+
realTypeAnnotation.name;
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.name}"`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
case 'StringTypeAnnotation':
|
|
119
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
120
|
+
case 'StringLiteralTypeAnnotation':
|
|
121
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
122
|
+
case 'StringLiteralUnionTypeAnnotation':
|
|
123
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
124
|
+
case 'BooleanTypeAnnotation':
|
|
125
|
+
return wrap(val => `${val}.asBool()`);
|
|
126
|
+
case 'EnumDeclaration':
|
|
127
|
+
switch (realTypeAnnotation.memberType) {
|
|
128
|
+
case 'NumberTypeAnnotation':
|
|
129
|
+
return wrap(val => `${val}.asNumber()`);
|
|
130
|
+
case 'StringTypeAnnotation':
|
|
131
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
132
|
+
default:
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Unknown enum type for "${arg.name}, found: ${realTypeAnnotation.type}"`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
case 'NumberTypeAnnotation':
|
|
138
|
+
return wrap(val => `${val}.asNumber()`);
|
|
139
|
+
case 'FloatTypeAnnotation':
|
|
140
|
+
return wrap(val => `${val}.asNumber()`);
|
|
141
|
+
case 'DoubleTypeAnnotation':
|
|
142
|
+
return wrap(val => `${val}.asNumber()`);
|
|
143
|
+
case 'Int32TypeAnnotation':
|
|
144
|
+
return wrap(val => `${val}.asNumber()`);
|
|
145
|
+
case 'NumberLiteralTypeAnnotation':
|
|
146
|
+
return wrap(val => `${val}.asNumber()`);
|
|
147
|
+
case 'ArrayTypeAnnotation':
|
|
148
|
+
return wrap(val => `${val}.asObject(rt).asArray(rt)`);
|
|
149
|
+
case 'FunctionTypeAnnotation':
|
|
150
|
+
return wrap(val => `${val}.asObject(rt).asFunction(rt)`);
|
|
151
|
+
case 'GenericObjectTypeAnnotation':
|
|
152
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
153
|
+
case 'UnionTypeAnnotation':
|
|
154
|
+
switch (typeAnnotation.memberType) {
|
|
155
|
+
case 'NumberTypeAnnotation':
|
|
156
|
+
return wrap(val => `${val}.asNumber()`);
|
|
157
|
+
case 'ObjectTypeAnnotation':
|
|
158
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
159
|
+
case 'StringTypeAnnotation':
|
|
160
|
+
return wrap(val => `${val}.asString(rt)`);
|
|
161
|
+
default:
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Unsupported union member type for param "${arg.name}, found: ${realTypeAnnotation.memberType}"`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
case 'ObjectTypeAnnotation':
|
|
167
|
+
return wrap(val => `${val}.asObject(rt)`);
|
|
168
|
+
case 'MixedTypeAnnotation':
|
|
169
|
+
return wrap(val => `jsi::Value(rt, ${val})`);
|
|
170
|
+
default:
|
|
171
|
+
realTypeAnnotation.type;
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.type}"`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function serializePropertyIntoHostFunction(
|
|
178
|
+
moduleName,
|
|
179
|
+
hasteModuleName,
|
|
180
|
+
property,
|
|
181
|
+
resolveAlias,
|
|
182
|
+
enumMap,
|
|
183
|
+
) {
|
|
184
|
+
const [propertyTypeAnnotation] = unwrapNullable(property.typeAnnotation);
|
|
185
|
+
return HostFunctionTemplate({
|
|
186
|
+
hasteModuleName,
|
|
187
|
+
methodName: property.name,
|
|
188
|
+
returnTypeAnnotation: propertyTypeAnnotation.returnTypeAnnotation,
|
|
189
|
+
args: propertyTypeAnnotation.params.map((p, i) =>
|
|
190
|
+
serializeArg(moduleName, p, i, resolveAlias, enumMap),
|
|
191
|
+
),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
module.exports = {
|
|
195
|
+
generate(
|
|
196
|
+
libraryName,
|
|
197
|
+
schema,
|
|
198
|
+
packageName,
|
|
199
|
+
assumeNonnull = false,
|
|
200
|
+
headerPrefix,
|
|
201
|
+
) {
|
|
202
|
+
const nativeModules = getModules(schema);
|
|
203
|
+
const modules = Object.keys(nativeModules)
|
|
204
|
+
.map(hasteModuleName => {
|
|
205
|
+
const nativeModule = nativeModules[hasteModuleName];
|
|
206
|
+
const {
|
|
207
|
+
aliasMap,
|
|
208
|
+
enumMap,
|
|
209
|
+
spec: {methods},
|
|
210
|
+
moduleName,
|
|
211
|
+
} = nativeModule;
|
|
212
|
+
const resolveAlias = createAliasResolver(aliasMap);
|
|
213
|
+
const hostFunctions = methods.map(property =>
|
|
214
|
+
serializePropertyIntoHostFunction(
|
|
215
|
+
moduleName,
|
|
216
|
+
hasteModuleName,
|
|
217
|
+
property,
|
|
218
|
+
resolveAlias,
|
|
219
|
+
enumMap,
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
return ModuleTemplate({
|
|
223
|
+
hasteModuleName,
|
|
224
|
+
hostFunctions,
|
|
225
|
+
moduleName,
|
|
226
|
+
methods: methods.map(
|
|
227
|
+
({name: propertyName, typeAnnotation: nullableTypeAnnotation}) => {
|
|
228
|
+
const [{params}] = unwrapNullable(nullableTypeAnnotation);
|
|
229
|
+
return {
|
|
230
|
+
methodName: propertyName,
|
|
231
|
+
paramCount: params.length,
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
),
|
|
235
|
+
});
|
|
236
|
+
})
|
|
237
|
+
.join('\n');
|
|
238
|
+
const fileName = `${libraryName}JSI-generated.cpp`;
|
|
239
|
+
const replacedTemplate = FileTemplate({
|
|
240
|
+
modules,
|
|
241
|
+
libraryName,
|
|
242
|
+
});
|
|
243
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
244
|
+
},
|
|
245
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -254,10 +254,10 @@ export function generate(
|
|
|
254
254
|
rncodegenPath,
|
|
255
255
|
'lib/generators/modules/GenerateModuleH',
|
|
256
256
|
)).generate;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
// Use local fixed version instead of upstream to fix x86 union padding issue
|
|
258
|
+
// with MixedTypeAnnotation. See GenerateModuleCpp.js for details.
|
|
259
|
+
const generateJsiModuleCpp =
|
|
260
|
+
require('./generators/GenerateModuleCpp').generate;
|
|
261
261
|
const generatorPropsH = require(path.resolve(
|
|
262
262
|
rncodegenPath,
|
|
263
263
|
'lib/generators/components/GeneratePropsH',
|