nitrogen 0.31.4 → 0.31.5

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/init.js CHANGED
@@ -54,7 +54,7 @@ async function downloadGitHubFolder(owner, repo, branch, folder, outputPath) {
54
54
  Logger.info(`⏳ Cloning ${chalk.underline(repoUrl)}...`);
55
55
  const tempPath = randomUUID();
56
56
  const tempDir = path.join(outputPath, tempPath);
57
- execSync(`git clone --depth 1 --filter=blob:none -b ${branch} --quiet --sparse ${repoUrl} ${tempDir}`);
57
+ execSync(`git clone --depth 1 --filter=blob:none -b ${branch} --quiet --sparse ${repoUrl} "${tempDir}"`);
58
58
  const prettyOutputPath = prettifyDirectory(outputPath);
59
59
  const initialDir = process.cwd();
60
60
  try {
@@ -269,7 +269,10 @@ export function createType(language, type, isOptional) {
269
269
  }
270
270
  else if (type.isInterface()) {
271
271
  // It is an `interface T { ... }`, which is a `struct`
272
- const typename = type.getSymbolOrThrow().getName();
272
+ const symbol = type.getAliasSymbol() ?? type.getSymbol();
273
+ if (symbol == null)
274
+ throw new Error(`Interface "${type.getText()}" does not have a Symbol!`);
275
+ const typename = symbol.getName();
273
276
  const properties = getInterfaceProperties(language, type);
274
277
  return new StructType(typename, properties);
275
278
  }
@@ -291,6 +294,9 @@ export function createType(language, type, isOptional) {
291
294
  else if (type.isStringLiteral()) {
292
295
  throw new Error(`String literal ${type.getText()} cannot be represented in C++ because it is ambiguous between a string and a discriminating union enum.`);
293
296
  }
297
+ else if (type.isAny()) {
298
+ throw new Error(`The TypeScript type "${type.getText()}" resolved to any - any is not supported in Nitro.`);
299
+ }
294
300
  else {
295
301
  if (type.getSymbol() == null) {
296
302
  // There is no declaration for it!
@@ -1,8 +1,20 @@
1
1
  import { createNamedType } from './createType.js';
2
2
  export function getInterfaceProperties(language, interfaceType) {
3
+ const symbol = interfaceType.getAliasSymbol() ?? interfaceType.getSymbol();
4
+ if (symbol == null)
5
+ throw new Error(`Interface "${interfaceType.getText()}" does not have a Symbol!`);
3
6
  return interfaceType.getProperties().map((prop) => {
4
- const declaration = prop.getValueDeclarationOrThrow();
5
- const propType = prop.getTypeAtLocation(declaration);
7
+ let propType = prop.getDeclaredType();
8
+ if (propType.isAny() || propType.isUnknown()) {
9
+ // the interface is aliased/merged - we need to look into the actual declaration
10
+ for (const declaration of symbol.getDeclarations()) {
11
+ const declared = prop.getTypeAtLocation(declaration);
12
+ if (!declared.isAny() && !declared.isUnknown()) {
13
+ propType = declared;
14
+ break;
15
+ }
16
+ }
17
+ }
6
18
  const refType = createNamedType(language, prop.getName(), propType, prop.isOptional() || propType.isNullable());
7
19
  return refType;
8
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.31.4",
3
+ "version": "0.31.5",
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.4",
39
+ "react-native-nitro-modules": "^0.31.5",
40
40
  "ts-morph": "^27.0.0",
41
41
  "yargs": "^18.0.0",
42
42
  "zod": "^4.0.5"
package/src/init.ts CHANGED
@@ -94,7 +94,7 @@ async function downloadGitHubFolder(
94
94
  const tempPath = randomUUID()
95
95
  const tempDir = path.join(outputPath, tempPath)
96
96
  execSync(
97
- `git clone --depth 1 --filter=blob:none -b ${branch} --quiet --sparse ${repoUrl} ${tempDir}`
97
+ `git clone --depth 1 --filter=blob:none -b ${branch} --quiet --sparse ${repoUrl} "${tempDir}"`
98
98
  )
99
99
  const prettyOutputPath = prettifyDirectory(outputPath)
100
100
 
@@ -329,7 +329,10 @@ export function createType(
329
329
  return new HybridObjectType(typename, language, baseHybrids, sourceConfig)
330
330
  } else if (type.isInterface()) {
331
331
  // It is an `interface T { ... }`, which is a `struct`
332
- const typename = type.getSymbolOrThrow().getName()
332
+ const symbol = type.getAliasSymbol() ?? type.getSymbol()
333
+ if (symbol == null)
334
+ throw new Error(`Interface "${type.getText()}" does not have a Symbol!`)
335
+ const typename = symbol.getName()
333
336
  const properties = getInterfaceProperties(language, type)
334
337
  return new StructType(typename, properties)
335
338
  } else if (type.isObject()) {
@@ -351,6 +354,10 @@ export function createType(
351
354
  throw new Error(
352
355
  `String literal ${type.getText()} cannot be represented in C++ because it is ambiguous between a string and a discriminating union enum.`
353
356
  )
357
+ } else if (type.isAny()) {
358
+ throw new Error(
359
+ `The TypeScript type "${type.getText()}" resolved to any - any is not supported in Nitro.`
360
+ )
354
361
  } else {
355
362
  if (type.getSymbol() == null) {
356
363
  // There is no declaration for it!
@@ -7,9 +7,24 @@ export function getInterfaceProperties(
7
7
  language: Language,
8
8
  interfaceType: Type<ts.ObjectType>
9
9
  ): NamedType[] {
10
+ const symbol = interfaceType.getAliasSymbol() ?? interfaceType.getSymbol()
11
+ if (symbol == null)
12
+ throw new Error(
13
+ `Interface "${interfaceType.getText()}" does not have a Symbol!`
14
+ )
10
15
  return interfaceType.getProperties().map((prop) => {
11
- const declaration = prop.getValueDeclarationOrThrow()
12
- const propType = prop.getTypeAtLocation(declaration)
16
+ let propType = prop.getDeclaredType()
17
+ if (propType.isAny() || propType.isUnknown()) {
18
+ // the interface is aliased/merged - we need to look into the actual declaration
19
+ for (const declaration of symbol.getDeclarations()) {
20
+ const declared = prop.getTypeAtLocation(declaration)
21
+ if (!declared.isAny() && !declared.isUnknown()) {
22
+ propType = declared
23
+ break
24
+ }
25
+ }
26
+ }
27
+
13
28
  const refType = createNamedType(
14
29
  language,
15
30
  prop.getName(),