@napi-rs/cli 3.0.0-alpha.55 → 3.0.0-alpha.57

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.
@@ -30,6 +30,7 @@ function prettyPrint(
30
30
  line: TypeDefLine,
31
31
  constEnum: boolean,
32
32
  ident: number,
33
+ ambient = false,
33
34
  ): string {
34
35
  let s = line.js_doc ?? ''
35
36
  switch (line.kind) {
@@ -39,24 +40,28 @@ function prettyPrint(
39
40
 
40
41
  case TypeDefKind.Enum:
41
42
  const enumName = constEnum ? 'const enum' : 'enum'
42
- s += `export ${enumName} ${line.name} {\n${line.def}\n}`
43
+ s += `${exportDeclare(ambient)} ${enumName} ${line.name} {\n${line.def}\n}`
43
44
  break
44
45
 
45
46
  case TypeDefKind.StringEnum:
46
47
  if (constEnum) {
47
- s += `export const enum ${line.name} {\n${line.def}\n}`
48
+ s += `${exportDeclare(ambient)} const enum ${line.name} {\n${line.def}\n}`
48
49
  } else {
49
50
  s += `export type ${line.name} = ${line.def.replaceAll(/.*=/g, '').replaceAll(',', '|')};`
50
51
  }
51
52
  break
52
53
 
53
54
  case TypeDefKind.Struct:
54
- s += `export class ${line.name} {\n${line.def}\n}`
55
+ s += `${exportDeclare(ambient)} class ${line.name} {\n${line.def}\n}`
55
56
  if (line.original_name && line.original_name !== line.name) {
56
57
  s += `\nexport type ${line.original_name} = ${line.name}`
57
58
  }
58
59
  break
59
60
 
61
+ case TypeDefKind.Fn:
62
+ s += `${exportDeclare(ambient)} ${line.def}`
63
+ break
64
+
60
65
  default:
61
66
  s += line.def
62
67
  }
@@ -64,6 +69,14 @@ function prettyPrint(
64
69
  return correctStringIdent(s, ident)
65
70
  }
66
71
 
72
+ function exportDeclare(ambient: boolean): string {
73
+ if (ambient) {
74
+ return 'export'
75
+ }
76
+
77
+ return 'export declare'
78
+ }
79
+
67
80
  export async function processTypeDef(
68
81
  intermediateTypeFile: string,
69
82
  constEnum: boolean,
@@ -99,9 +112,9 @@ export async function processTypeDef(
99
112
  }
100
113
  } else {
101
114
  exports.push(namespace)
102
- dts += `export namespace ${namespace} {\n`
115
+ dts += `export declare namespace ${namespace} {\n`
103
116
  for (const def of defs) {
104
- dts += prettyPrint(def, constEnum, 2) + '\n'
117
+ dts += prettyPrint(def, constEnum, 2, true) + '\n'
105
118
  }
106
119
  dts += '}\n\n'
107
120
  }
@@ -110,7 +123,7 @@ export async function processTypeDef(
110
123
 
111
124
  if (dts.indexOf('ExternalObject<') > -1) {
112
125
  header += `
113
- export class ExternalObject<T> {
126
+ export declare class ExternalObject<T> {
114
127
  readonly '': {
115
128
  readonly '': unique symbol
116
129
  [K: symbol]: T