nitrogen 0.31.1 → 0.31.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.
@@ -0,0 +1 @@
1
+ export declare const NITROGEN_VERSION: string;
@@ -0,0 +1,2 @@
1
+ import packageJson from 'nitrogen/package.json' with { type: 'json' };
2
+ export const NITROGEN_VERSION = packageJson.version;
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@ import { runNitrogen } from './nitrogen.js';
8
8
  import { promises as fs } from 'fs';
9
9
  import { isValidLogLevel, setLogLevel } from './Logger.js';
10
10
  import { initNewNitroModule } from './init.js';
11
- import { NITROGEN_VERSION } from './utils.js';
11
+ import { NITROGEN_VERSION } from './config/nitrogenVersion.js';
12
12
  const commandName = 'nitrogen';
13
13
  // Maximum of 100 col width
14
14
  const cliWidth = Math.min(process.stdout.columns * 0.9, 100);
@@ -71,6 +71,7 @@ await yargs(hideBin(process.argv))
71
71
  `$Nitrogen Version: ${chalk.bold(NITROGEN_VERSION)}`)
72
72
  .help()
73
73
  .strict()
74
+ .version(NITROGEN_VERSION)
74
75
  .wrap(cliWidth).argv;
75
76
  async function runNitrogenCommand(baseDirectory, outputDirectory) {
76
77
  // 1. Prepare output folders
package/lib/nitrogen.js CHANGED
@@ -3,7 +3,7 @@ import { extendsHybridObject, isHybridView, getHybridObjectPlatforms, getHybridV
3
3
  import { generatePlatformFiles } from './createPlatformSpec.js';
4
4
  import path from 'path';
5
5
  import { prettifyDirectory } from './prettifyDirectory.js';
6
- import { capitalizeName, deduplicateFiles, errorToString, indent, NITROGEN_VERSION, } from './utils.js';
6
+ import { capitalizeName, deduplicateFiles, errorToString, indent, } from './utils.js';
7
7
  import { writeFile } from './writeFile.js';
8
8
  import chalk from 'chalk';
9
9
  import { groupByPlatform } from './syntax/SourceFile.js';
@@ -12,6 +12,7 @@ import { NitroConfig } from './config/NitroConfig.js';
12
12
  import { createIOSAutolinking } from './autolinking/createIOSAutolinking.js';
13
13
  import { createAndroidAutolinking } from './autolinking/createAndroidAutolinking.js';
14
14
  import { createGitAttributes } from './createGitAttributes.js';
15
+ import { NITROGEN_VERSION } from './config/nitrogenVersion.js';
15
16
  export async function runNitrogen({ baseDirectory, outputDirectory, }) {
16
17
  let targetSpecs = 0;
17
18
  let generatedSpecs = 0;
@@ -22,7 +22,6 @@ import { VoidType } from '../types/VoidType.js';
22
22
  import { NamedWrappingType } from '../types/NamedWrappingType.js';
23
23
  import { ErrorType } from '../types/ErrorType.js';
24
24
  import { createSwiftFunctionBridge } from './SwiftFunction.js';
25
- import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js';
26
25
  // TODO: Remove enum bridge once Swift fixes bidirectional enums crashing the `-Swift.h` header.
27
26
  export class SwiftCxxBridgedType {
28
27
  type;
@@ -449,21 +448,8 @@ export class SwiftCxxBridgedType {
449
448
  const wrapping = new SwiftCxxBridgedType(array.itemType, true);
450
449
  switch (language) {
451
450
  case 'swift':
452
- if (isPrimitivelyCopyable(array.itemType)) {
453
- // We can primitively copy the data, raw:
454
- const bridge = this.getBridgeOrThrow();
455
- const getDataFunc = `bridge.get_data_${bridge.specializationName}`;
456
- return `
457
- { () -> ${array.getCode('swift')} in
458
- let __data = ${getDataFunc}(${cppParameterName})
459
- let __size = ${cppParameterName}.size()
460
- return Array(UnsafeBufferPointer(start: __data, count: __size))
461
- }()`.trim();
462
- }
463
- else {
464
- // We have to iterate the element one by one to create a resulting Array (mapped)
465
- return `${cppParameterName}.map({ __item in ${wrapping.parseFromCppToSwift('__item', 'swift')} })`.trim();
466
- }
451
+ // We have to iterate the element one by one to create a resulting Array (mapped)
452
+ return `${cppParameterName}.map({ __item in ${wrapping.parseFromCppToSwift('__item', 'swift')} })`.trim();
467
453
  default:
468
454
  return cppParameterName;
469
455
  }
@@ -713,18 +699,9 @@ case ${i}:
713
699
  const wrapping = new SwiftCxxBridgedType(array.itemType, true);
714
700
  switch (language) {
715
701
  case 'swift':
716
- if (isPrimitivelyCopyable(array.itemType)) {
717
- // memory can be copied primitively
718
- const copyFunc = `bridge.${bridge.funcName}`;
719
- return `
720
- ${swiftParameterName}.withUnsafeBufferPointer { __pointer -> bridge.${bridge.specializationName} in
721
- return ${copyFunc}(__pointer.baseAddress!, ${swiftParameterName}.count)
722
- }`.trim();
723
- }
724
- else {
725
- // array has to be iterated and converted one-by-one
726
- const makeFunc = `bridge.${bridge.funcName}`;
727
- return `
702
+ // array has to be iterated and converted one-by-one
703
+ const makeFunc = `bridge.${bridge.funcName}`;
704
+ return `
728
705
  { () -> bridge.${bridge.specializationName} in
729
706
  var __vector = ${makeFunc}(${swiftParameterName}.count)
730
707
  for __item in ${swiftParameterName} {
@@ -732,7 +709,6 @@ ${swiftParameterName}.withUnsafeBufferPointer { __pointer -> bridge.${bridge.spe
732
709
  }
733
710
  return __vector
734
711
  }()`.trim();
735
- }
736
712
  default:
737
713
  return swiftParameterName;
738
714
  }
@@ -17,7 +17,6 @@ import { VoidType } from '../types/VoidType.js';
17
17
  import { NamedWrappingType } from '../types/NamedWrappingType.js';
18
18
  import { ErrorType } from '../types/ErrorType.js';
19
19
  import { ResultWrappingType } from '../types/ResultWrappingType.js';
20
- import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js';
21
20
  export function createSwiftCxxHelpers(type) {
22
21
  switch (type.kind) {
23
22
  case 'hybrid-object':
@@ -227,27 +226,8 @@ function createCxxVectorSwiftHelper(type) {
227
226
  const actualType = type.getCode('c++');
228
227
  const bridgedType = new SwiftCxxBridgedType(type);
229
228
  const name = escapeCppName(actualType);
230
- let code;
231
- let funcName;
232
- if (isPrimitivelyCopyable(type.itemType)) {
233
- const itemType = type.itemType.getCode('c++');
234
- funcName = `copy_${name}`;
235
- code = `
236
- /**
237
- * Specialized version of \`${escapeComments(actualType)}\`.
238
- */
239
- using ${name} = ${actualType};
240
- inline ${actualType} copy_${name}(const ${itemType}* CONTIGUOUS_MEMORY NON_NULL data, size_t size) noexcept {
241
- return margelo::nitro::FastVectorCopy<${itemType}>(data, size);
242
- }
243
- inline const ${itemType}* CONTIGUOUS_MEMORY NON_NULL get_data_${name}(const ${actualType}& vector) noexcept {
244
- return vector.data();
245
- }
246
- `.trim();
247
- }
248
- else {
249
- funcName = `create_${name}`;
250
- code = `
229
+ const funcName = `create_${name}`;
230
+ const code = `
251
231
  /**
252
232
  * Specialized version of \`${escapeComments(actualType)}\`.
253
233
  */
@@ -257,7 +237,6 @@ inline ${actualType} create_${name}(size_t size) noexcept {
257
237
  vector.reserve(size);
258
238
  return vector;
259
239
  }`.trim();
260
- }
261
240
  return {
262
241
  cxxType: actualType,
263
242
  funcName: funcName,
@@ -270,11 +249,6 @@ inline ${actualType} create_${name}(size_t size) noexcept {
270
249
  space: 'system',
271
250
  language: 'c++',
272
251
  },
273
- {
274
- name: 'NitroModules/FastVectorCopy.hpp',
275
- space: 'system',
276
- language: 'c++',
277
- },
278
252
  ...bridgedType.getRequiredImports('c++'),
279
253
  ],
280
254
  },
package/lib/utils.d.ts CHANGED
@@ -2,7 +2,6 @@ import type { SourceFile } from './syntax/SourceFile.js';
2
2
  import type { SwiftCxxHelper } from './syntax/swift/SwiftCxxTypeHelper.js';
3
3
  import type { Type } from 'ts-morph';
4
4
  import { NitroConfig } from './config/NitroConfig.js';
5
- export declare const NITROGEN_VERSION: string;
6
5
  export declare function capitalizeName(name: string): string;
7
6
  export declare function createIndentation(spacesCount: number): string;
8
7
  export declare function indent(string: string, spacesCount: number): string;
package/lib/utils.js CHANGED
@@ -3,7 +3,6 @@ import fs from 'fs';
3
3
  import { isNotDuplicate } from './syntax/helpers.js';
4
4
  import { readUserConfig } from './config/getConfig.js';
5
5
  import { NitroConfig } from './config/NitroConfig.js';
6
- export const NITROGEN_VERSION = process.env.npm_package_version ?? '?.?.?';
7
6
  export function capitalizeName(name) {
8
7
  if (name.length === 0)
9
8
  return name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.31.1",
3
+ "version": "0.31.2",
4
4
  "description": "The code-generator for react-native-nitro-modules.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "chalk": "^5.3.0",
39
- "react-native-nitro-modules": "^0.31.1",
39
+ "react-native-nitro-modules": "^0.31.2",
40
40
  "ts-morph": "^27.0.0",
41
41
  "yargs": "^18.0.0",
42
42
  "zod": "^4.0.5"
@@ -0,0 +1,3 @@
1
+ import packageJson from 'nitrogen/package.json' with { type: 'json' }
2
+
3
+ export const NITROGEN_VERSION = packageJson.version
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ import { runNitrogen } from './nitrogen.js'
9
9
  import { promises as fs } from 'fs'
10
10
  import { isValidLogLevel, setLogLevel } from './Logger.js'
11
11
  import { initNewNitroModule } from './init.js'
12
- import { NITROGEN_VERSION } from './utils.js'
12
+ import { NITROGEN_VERSION } from './config/nitrogenVersion.js'
13
13
 
14
14
  const commandName = 'nitrogen'
15
15
 
@@ -90,6 +90,7 @@ await yargs(hideBin(process.argv))
90
90
  )
91
91
  .help()
92
92
  .strict()
93
+ .version(NITROGEN_VERSION)
93
94
  .wrap(cliWidth).argv
94
95
 
95
96
  async function runNitrogenCommand(
package/src/nitrogen.ts CHANGED
@@ -14,7 +14,6 @@ import {
14
14
  deduplicateFiles,
15
15
  errorToString,
16
16
  indent,
17
- NITROGEN_VERSION,
18
17
  } from './utils.js'
19
18
  import { writeFile } from './writeFile.js'
20
19
  import chalk from 'chalk'
@@ -26,6 +25,7 @@ import { createAndroidAutolinking } from './autolinking/createAndroidAutolinking
26
25
  import type { Autolinking } from './autolinking/Autolinking.js'
27
26
  import { createGitAttributes } from './createGitAttributes.js'
28
27
  import type { PlatformSpec } from 'react-native-nitro-modules'
28
+ import { NITROGEN_VERSION } from './config/nitrogenVersion.js'
29
29
 
30
30
  interface NitrogenOptions {
31
31
  baseDirectory: string
@@ -32,7 +32,6 @@ import { NamedWrappingType } from '../types/NamedWrappingType.js'
32
32
  import { ErrorType } from '../types/ErrorType.js'
33
33
  import { createSwiftFunctionBridge } from './SwiftFunction.js'
34
34
  import type { Language } from '../../getPlatformSpecs.js'
35
- import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js'
36
35
 
37
36
  // TODO: Remove enum bridge once Swift fixes bidirectional enums crashing the `-Swift.h` header.
38
37
 
@@ -490,20 +489,8 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> {
490
489
  const wrapping = new SwiftCxxBridgedType(array.itemType, true)
491
490
  switch (language) {
492
491
  case 'swift':
493
- if (isPrimitivelyCopyable(array.itemType)) {
494
- // We can primitively copy the data, raw:
495
- const bridge = this.getBridgeOrThrow()
496
- const getDataFunc = `bridge.get_data_${bridge.specializationName}`
497
- return `
498
- { () -> ${array.getCode('swift')} in
499
- let __data = ${getDataFunc}(${cppParameterName})
500
- let __size = ${cppParameterName}.size()
501
- return Array(UnsafeBufferPointer(start: __data, count: __size))
502
- }()`.trim()
503
- } else {
504
- // We have to iterate the element one by one to create a resulting Array (mapped)
505
- return `${cppParameterName}.map({ __item in ${wrapping.parseFromCppToSwift('__item', 'swift')} })`.trim()
506
- }
492
+ // We have to iterate the element one by one to create a resulting Array (mapped)
493
+ return `${cppParameterName}.map({ __item in ${wrapping.parseFromCppToSwift('__item', 'swift')} })`.trim()
507
494
  default:
508
495
  return cppParameterName
509
496
  }
@@ -764,17 +751,9 @@ case ${i}:
764
751
  const wrapping = new SwiftCxxBridgedType(array.itemType, true)
765
752
  switch (language) {
766
753
  case 'swift':
767
- if (isPrimitivelyCopyable(array.itemType)) {
768
- // memory can be copied primitively
769
- const copyFunc = `bridge.${bridge.funcName}`
770
- return `
771
- ${swiftParameterName}.withUnsafeBufferPointer { __pointer -> bridge.${bridge.specializationName} in
772
- return ${copyFunc}(__pointer.baseAddress!, ${swiftParameterName}.count)
773
- }`.trim()
774
- } else {
775
- // array has to be iterated and converted one-by-one
776
- const makeFunc = `bridge.${bridge.funcName}`
777
- return `
754
+ // array has to be iterated and converted one-by-one
755
+ const makeFunc = `bridge.${bridge.funcName}`
756
+ return `
778
757
  { () -> bridge.${bridge.specializationName} in
779
758
  var __vector = ${makeFunc}(${swiftParameterName}.count)
780
759
  for __item in ${swiftParameterName} {
@@ -782,7 +761,6 @@ ${swiftParameterName}.withUnsafeBufferPointer { __pointer -> bridge.${bridge.spe
782
761
  }
783
762
  return __vector
784
763
  }()`.trim()
785
- }
786
764
  default:
787
765
  return swiftParameterName
788
766
  }
@@ -19,7 +19,6 @@ 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'
23
22
 
24
23
  export interface SwiftCxxHelper {
25
24
  cxxHeader: {
@@ -268,26 +267,8 @@ function createCxxVectorSwiftHelper(type: ArrayType): SwiftCxxHelper {
268
267
  const actualType = type.getCode('c++')
269
268
  const bridgedType = new SwiftCxxBridgedType(type)
270
269
  const name = escapeCppName(actualType)
271
- let code: string
272
- let funcName: string
273
- if (isPrimitivelyCopyable(type.itemType)) {
274
- const itemType = type.itemType.getCode('c++')
275
- funcName = `copy_${name}`
276
- code = `
277
- /**
278
- * Specialized version of \`${escapeComments(actualType)}\`.
279
- */
280
- using ${name} = ${actualType};
281
- inline ${actualType} copy_${name}(const ${itemType}* CONTIGUOUS_MEMORY NON_NULL data, size_t size) noexcept {
282
- return margelo::nitro::FastVectorCopy<${itemType}>(data, size);
283
- }
284
- inline const ${itemType}* CONTIGUOUS_MEMORY NON_NULL get_data_${name}(const ${actualType}& vector) noexcept {
285
- return vector.data();
286
- }
287
- `.trim()
288
- } else {
289
- funcName = `create_${name}`
290
- code = `
270
+ const funcName = `create_${name}`
271
+ const code = `
291
272
  /**
292
273
  * Specialized version of \`${escapeComments(actualType)}\`.
293
274
  */
@@ -297,7 +278,6 @@ inline ${actualType} create_${name}(size_t size) noexcept {
297
278
  vector.reserve(size);
298
279
  return vector;
299
280
  }`.trim()
300
- }
301
281
 
302
282
  return {
303
283
  cxxType: actualType,
@@ -311,11 +291,6 @@ inline ${actualType} create_${name}(size_t size) noexcept {
311
291
  space: 'system',
312
292
  language: 'c++',
313
293
  },
314
- {
315
- name: 'NitroModules/FastVectorCopy.hpp',
316
- space: 'system',
317
- language: 'c++',
318
- },
319
294
  ...bridgedType.getRequiredImports('c++'),
320
295
  ],
321
296
  },
package/src/utils.ts CHANGED
@@ -7,8 +7,6 @@ import { isNotDuplicate } from './syntax/helpers.js'
7
7
  import { readUserConfig } from './config/getConfig.js'
8
8
  import { NitroConfig } from './config/NitroConfig.js'
9
9
 
10
- export const NITROGEN_VERSION = process.env.npm_package_version ?? '?.?.?'
11
-
12
10
  export function capitalizeName(name: string): string {
13
11
  if (name.length === 0) return name
14
12
  return name.charAt(0).toUpperCase() + name.slice(1)
@@ -1,20 +0,0 @@
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
- }