nitrogen 0.29.7 → 0.30.0
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/lib/Logger.d.ts +10 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/index.d.ts +2 -0
- package/lib/init.d.ts +1 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +4 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +5 -1
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +2 -1
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +0 -1
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +3 -6
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/isPrimitivelyCopyable.d.ts +7 -0
- package/lib/syntax/swift/isPrimitivelyCopyable.js +18 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/utils.d.ts +22 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/writeFile.d.ts +5 -0
- package/package.json +3 -3
- package/src/syntax/c++/CppStruct.ts +4 -0
- package/src/syntax/kotlin/KotlinStruct.ts +11 -3
- package/src/syntax/swift/SwiftCxxBridgedType.ts +1 -1
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +3 -7
- package/src/syntax/swift/isPrimitivelyCopyable.ts +20 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class VoidType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SourceFile } from './syntax/SourceFile.js';
|
|
2
|
+
import type { SwiftCxxHelper } from './syntax/swift/SwiftCxxTypeHelper.js';
|
|
3
|
+
import type { Type } from 'ts-morph';
|
|
4
|
+
import { NitroConfig } from './config/NitroConfig.js';
|
|
5
|
+
export declare const NITROGEN_VERSION: string;
|
|
6
|
+
export declare function capitalizeName(name: string): string;
|
|
7
|
+
export declare function createIndentation(spacesCount: number): string;
|
|
8
|
+
export declare function indent(string: string, spacesCount: number): string;
|
|
9
|
+
export declare function indent(string: string, indentation: string): string;
|
|
10
|
+
export declare function errorToString(error: unknown): string;
|
|
11
|
+
export declare function escapeComments(string: string): string;
|
|
12
|
+
export declare function toUnixPath(p: string): string;
|
|
13
|
+
export declare function unsafeFastJoin(...segments: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Deduplicates all files via their full path.
|
|
16
|
+
* If content differs, you are f*cked.
|
|
17
|
+
*/
|
|
18
|
+
export declare function deduplicateFiles(files: SourceFile[]): SourceFile[];
|
|
19
|
+
export declare function filterDuplicateHelperBridges(bridge: SwiftCxxHelper, i: number, array: SwiftCxxHelper[]): boolean;
|
|
20
|
+
export declare function toLowerCamelCase(string: string): string;
|
|
21
|
+
export declare function getBaseTypes(type: Type): Type[];
|
|
22
|
+
export declare function getHybridObjectNitroModuleConfig(type: Type): NitroConfig | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SourceFile } from '../syntax/SourceFile.js';
|
|
2
|
+
import type { HybridObjectSpec } from '../syntax/HybridObjectSpec.js';
|
|
3
|
+
interface ViewComponentNames {
|
|
4
|
+
propsClassName: `${string}Props`;
|
|
5
|
+
stateClassName: `${string}State`;
|
|
6
|
+
nameVariable: `${string}ComponentName`;
|
|
7
|
+
shadowNodeClassName: `${string}ShadowNode`;
|
|
8
|
+
descriptorClassName: `${string}ComponentDescriptor`;
|
|
9
|
+
component: `${string}Component`;
|
|
10
|
+
manager: `${string}Manager`;
|
|
11
|
+
}
|
|
12
|
+
export declare function getViewComponentNames(spec: HybridObjectSpec): ViewComponentNames;
|
|
13
|
+
export declare function createViewComponentShadowNodeFiles(spec: HybridObjectSpec): SourceFile[];
|
|
14
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"chalk": "^5.3.0",
|
|
39
|
-
"react-native-nitro-modules": "^0.
|
|
39
|
+
"react-native-nitro-modules": "^0.30.0",
|
|
40
40
|
"ts-morph": "^27.0.0",
|
|
41
|
-
"yargs": "^
|
|
41
|
+
"yargs": "^18.0.0",
|
|
42
42
|
"zod": "^4.0.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -69,6 +69,7 @@ ${createFileMetadataString(`${typename}.hpp`)}
|
|
|
69
69
|
|
|
70
70
|
${includeNitroHeader('JSIConverter.hpp')}
|
|
71
71
|
${includeNitroHeader('NitroDefines.hpp')}
|
|
72
|
+
${includeNitroHeader('JSIHelpers.hpp')}
|
|
72
73
|
|
|
73
74
|
${cppForwardDeclarations.join('\n')}
|
|
74
75
|
|
|
@@ -111,6 +112,9 @@ namespace margelo::nitro {
|
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
113
114
|
jsi::Object obj = value.getObject(runtime);
|
|
115
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
114
118
|
${indent(cppCanConvertCalls, ' ')}
|
|
115
119
|
return true;
|
|
116
120
|
}
|
|
@@ -18,9 +18,17 @@ val ${p.escapedName}: ${bridged.getTypeCode('kotlin', false)}
|
|
|
18
18
|
`.trim()
|
|
19
19
|
})
|
|
20
20
|
let secondaryConstructor: string
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
|
|
22
|
+
const needsSpecialHandling = structType.properties.some((p) => {
|
|
23
|
+
const bridged = new KotlinCxxBridgedType(p)
|
|
24
|
+
const parseCode = bridged.parseFromKotlinToCpp(
|
|
25
|
+
p.escapedName,
|
|
26
|
+
'kotlin',
|
|
27
|
+
false
|
|
28
|
+
)
|
|
29
|
+
return parseCode !== p.escapedName
|
|
30
|
+
})
|
|
31
|
+
|
|
24
32
|
if (needsSpecialHandling) {
|
|
25
33
|
// If we need special handling for any of our properties, we need to add a convenience initializer.
|
|
26
34
|
const params = structType.properties.map(
|
|
@@ -22,7 +22,6 @@ import { VariantType } from '../types/VariantType.js'
|
|
|
22
22
|
import { getReferencedTypes } from '../getReferencedTypes.js'
|
|
23
23
|
import {
|
|
24
24
|
createSwiftCxxHelpers,
|
|
25
|
-
isPrimitivelyCopyable,
|
|
26
25
|
type SwiftCxxHelper,
|
|
27
26
|
} from './SwiftCxxTypeHelper.js'
|
|
28
27
|
import { createSwiftEnumBridge } from './SwiftEnum.js'
|
|
@@ -33,6 +32,7 @@ import { NamedWrappingType } from '../types/NamedWrappingType.js'
|
|
|
33
32
|
import { ErrorType } from '../types/ErrorType.js'
|
|
34
33
|
import { createSwiftFunctionBridge } from './SwiftFunction.js'
|
|
35
34
|
import type { Language } from '../../getPlatformSpecs.js'
|
|
35
|
+
import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js'
|
|
36
36
|
|
|
37
37
|
// TODO: Remove enum bridge once Swift fixes bidirectional enums crashing the `-Swift.h` header.
|
|
38
38
|
|
|
@@ -19,6 +19,7 @@ import { VoidType } from '../types/VoidType.js'
|
|
|
19
19
|
import { NamedWrappingType } from '../types/NamedWrappingType.js'
|
|
20
20
|
import { ErrorType } from '../types/ErrorType.js'
|
|
21
21
|
import { ResultWrappingType } from '../types/ResultWrappingType.js'
|
|
22
|
+
import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js'
|
|
22
23
|
|
|
23
24
|
export interface SwiftCxxHelper {
|
|
24
25
|
cxxHeader: {
|
|
@@ -148,7 +149,7 @@ return ${cxxNamespace}::get_${internalName}(cppType);
|
|
|
148
149
|
*/
|
|
149
150
|
using ${name} = ${actualType};
|
|
150
151
|
${actualType} create_${name}(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
151
|
-
void* NON_NULL get_${name}(${name} cppType)
|
|
152
|
+
void* NON_NULL get_${name}(${name} cppType);
|
|
152
153
|
`.trim(),
|
|
153
154
|
requiredIncludes: type.getRequiredImports('c++'),
|
|
154
155
|
},
|
|
@@ -157,7 +158,7 @@ void* NON_NULL get_${name}(${name} cppType) noexcept;
|
|
|
157
158
|
${actualType} create_${name}(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
158
159
|
${indent(createImplementation, ' ')}
|
|
159
160
|
}
|
|
160
|
-
void* NON_NULL get_${name}(${name} cppType)
|
|
161
|
+
void* NON_NULL get_${name}(${name} cppType) {
|
|
161
162
|
${indent(getImplementation, ' ')}
|
|
162
163
|
}
|
|
163
164
|
`.trim(),
|
|
@@ -260,11 +261,6 @@ inline ${wrappedBridge.getTypeCode('c++')} get_${name}(const ${actualType}& opti
|
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
263
|
|
|
263
|
-
export function isPrimitivelyCopyable(type: Type): boolean {
|
|
264
|
-
const bridgedType = new SwiftCxxBridgedType(type, true)
|
|
265
|
-
return !bridgedType.needsSpecialHandling
|
|
266
|
-
}
|
|
267
|
-
|
|
268
264
|
/**
|
|
269
265
|
* Creates a C++ `create_vector_T<T>(size)` function that can be called from Swift.
|
|
270
266
|
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Type } from '../types/Type.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the given {@linkcode type} is a datatype that
|
|
5
|
+
* can be copied without running a copy constructor or special logic
|
|
6
|
+
* to copy the data over. In other words; it's _primitively copyable_.
|
|
7
|
+
*/
|
|
8
|
+
export function isPrimitivelyCopyable(type: Type): boolean {
|
|
9
|
+
switch (type.kind) {
|
|
10
|
+
case 'number':
|
|
11
|
+
case 'boolean':
|
|
12
|
+
case 'bigint':
|
|
13
|
+
case 'enum':
|
|
14
|
+
case 'null':
|
|
15
|
+
case 'void':
|
|
16
|
+
return true
|
|
17
|
+
default:
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|