@napi-rs/cli 3.0.0-alpha.55 → 3.0.0-alpha.56
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/dist/api/build.js +4 -4
- package/dist/api/build.js.map +1 -1
- package/dist/def/artifacts.d.ts +2 -2
- package/dist/def/build.d.ts +2 -2
- package/dist/def/build.js +2 -2
- package/dist/def/create-npm-dirs.d.ts +1 -1
- package/dist/def/new.d.ts +2 -2
- package/dist/def/pre-publish.d.ts +3 -3
- package/dist/def/rename.d.ts +6 -6
- package/dist/def/universalize.d.ts +1 -1
- package/dist/def/version.d.ts +1 -1
- package/dist/index.cjs +2026 -3059
- package/dist/utils/misc.d.ts +0 -1
- package/dist/utils/target.d.ts +0 -1
- package/dist/utils/typegen.js +16 -7
- package/dist/utils/typegen.js.map +1 -1
- package/package.json +5 -5
- package/src/api/build.ts +4 -4
- package/src/def/build.ts +4 -4
- package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +316 -316
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/typegen.ts +19 -6
|
Binary file
|
|
Binary file
|
package/src/utils/typegen.ts
CHANGED
|
@@ -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 +=
|
|
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 +=
|
|
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 +=
|
|
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
|