@napi-rs/cli 3.0.0-alpha.7 → 3.0.0-alpha.9
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 +1 -1
- package/dist/api/build.js.map +1 -1
- package/dist/api/load-wasi-template.js +1 -0
- package/dist/api/load-wasi-template.js.map +1 -1
- package/dist/api/templates/ci-template.js +4 -6
- package/dist/api/templates/ci-template.js.map +1 -1
- package/dist/api/templates/lib.rs.js +1 -4
- package/dist/api/templates/lib.rs.js.map +1 -1
- package/dist/def/build.d.ts +6 -0
- package/dist/def/build.js +4 -0
- package/dist/def/build.js.map +1 -1
- package/dist/index.cjs +23 -24
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/__tests__/typegen.spec.js +8 -4
- package/dist/utils/__tests__/typegen.spec.js.map +1 -1
- package/dist/utils/config.d.ts +4 -0
- package/dist/utils/config.js +2 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +6 -5
- package/dist/utils/typegen.js.map +1 -1
- package/package.json +13 -13
- package/src/api/build.ts +9 -8
- package/src/api/load-wasi-template.ts +1 -0
- package/src/api/templates/ci-template.ts +4 -6
- package/src/api/templates/lib.rs.ts +1 -4
- package/src/def/build.ts +9 -0
- package/src/index.ts +2 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +555 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/typegen.spec.ts +18 -3
- package/src/utils/config.ts +7 -2
- package/src/utils/typegen.ts +10 -4
|
@@ -18,13 +18,13 @@ test('should ident string correctly', (t) => {
|
|
|
18
18
|
foo() {
|
|
19
19
|
a = b
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
bar = () => {
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
}
|
|
25
25
|
boz = 1
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
namespace B {
|
|
29
29
|
namespace C {
|
|
30
30
|
type D = A
|
|
@@ -43,6 +43,21 @@ test('should process type def correctly', async (t) => {
|
|
|
43
43
|
'__fixtures__',
|
|
44
44
|
'napi_type_def',
|
|
45
45
|
),
|
|
46
|
+
true,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
t.snapshot(dts)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('should process type def with noConstEnum correctly', async (t) => {
|
|
53
|
+
const { dts } = await processTypeDef(
|
|
54
|
+
join(
|
|
55
|
+
fileURLToPath(import.meta.url),
|
|
56
|
+
'../',
|
|
57
|
+
'__fixtures__',
|
|
58
|
+
'napi_type_def',
|
|
59
|
+
),
|
|
60
|
+
false,
|
|
46
61
|
)
|
|
47
62
|
|
|
48
63
|
t.snapshot(dts)
|
package/src/utils/config.ts
CHANGED
|
@@ -24,6 +24,11 @@ interface UserNapiConfig {
|
|
|
24
24
|
*/
|
|
25
25
|
npmClient?: string
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Whether generate const enum for typescript bindings
|
|
29
|
+
*/
|
|
30
|
+
constEnum?: boolean
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
33
|
* @deprecated binaryName instead
|
|
29
34
|
*/
|
|
@@ -114,8 +119,8 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
114
119
|
let targets: string[] = userNapiConfig.targets ?? []
|
|
115
120
|
|
|
116
121
|
// compatible with old config
|
|
117
|
-
if (userNapiConfig
|
|
118
|
-
napiConfig.packageName = userNapiConfig.
|
|
122
|
+
if (userNapiConfig?.name) {
|
|
123
|
+
napiConfig.packageName = userNapiConfig.name
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
if (!targets.length) {
|
package/src/utils/typegen.ts
CHANGED
|
@@ -25,7 +25,11 @@ interface TypeDefLine {
|
|
|
25
25
|
js_mod?: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function prettyPrint(
|
|
28
|
+
function prettyPrint(
|
|
29
|
+
line: TypeDefLine,
|
|
30
|
+
constEnum: boolean,
|
|
31
|
+
ident: number,
|
|
32
|
+
): string {
|
|
29
33
|
let s = line.js_doc ?? ''
|
|
30
34
|
switch (line.kind) {
|
|
31
35
|
case TypeDefKind.Interface:
|
|
@@ -33,7 +37,8 @@ function prettyPrint(line: TypeDefLine, ident: number): string {
|
|
|
33
37
|
break
|
|
34
38
|
|
|
35
39
|
case TypeDefKind.Enum:
|
|
36
|
-
|
|
40
|
+
const enumName = constEnum ? 'const enum' : 'enum'
|
|
41
|
+
s += `export ${enumName} ${line.name} {\n${line.def}\n}`
|
|
37
42
|
break
|
|
38
43
|
|
|
39
44
|
case TypeDefKind.Struct:
|
|
@@ -52,6 +57,7 @@ function prettyPrint(line: TypeDefLine, ident: number): string {
|
|
|
52
57
|
|
|
53
58
|
export async function processTypeDef(
|
|
54
59
|
intermediateTypeFile: string,
|
|
60
|
+
constEnum: boolean,
|
|
55
61
|
header?: string,
|
|
56
62
|
) {
|
|
57
63
|
const exports: string[] = []
|
|
@@ -65,7 +71,7 @@ export async function processTypeDef(
|
|
|
65
71
|
([namespace, defs]) => {
|
|
66
72
|
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
67
73
|
for (const def of defs) {
|
|
68
|
-
dts += prettyPrint(def, 0) + '\n\n'
|
|
74
|
+
dts += prettyPrint(def, constEnum, 0) + '\n\n'
|
|
69
75
|
switch (def.kind) {
|
|
70
76
|
case TypeDefKind.Const:
|
|
71
77
|
case TypeDefKind.Enum:
|
|
@@ -85,7 +91,7 @@ export async function processTypeDef(
|
|
|
85
91
|
exports.push(namespace)
|
|
86
92
|
dts += `export namespace ${namespace} {\n`
|
|
87
93
|
for (const def of defs) {
|
|
88
|
-
dts += prettyPrint(def, 2) + '\n'
|
|
94
|
+
dts += prettyPrint(def, constEnum, 2) + '\n'
|
|
89
95
|
}
|
|
90
96
|
dts += '}\n\n'
|
|
91
97
|
}
|