@napi-rs/cli 3.0.0-alpha.62 → 3.0.0-alpha.64
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 +7 -6
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +1 -1
- package/dist/api/create-npm-dirs.js.map +1 -1
- package/dist/api/templates/cargo.toml.js +1 -0
- package/dist/api/templates/cargo.toml.js.map +1 -1
- package/dist/api/templates/ci-template.js +26 -13
- package/dist/api/templates/ci-template.js.map +1 -1
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/js-binding.js +28 -10
- package/dist/api/templates/js-binding.js.map +1 -1
- package/dist/commands/new.js +12 -34
- package/dist/commands/new.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 +2376 -2667
- package/dist/utils/cargo.js +1 -1
- package/dist/utils/cargo.js.map +1 -1
- package/dist/utils/config.d.ts +1 -1
- package/dist/utils/typegen.js +25 -11
- package/dist/utils/typegen.js.map +1 -1
- package/package.json +15 -15
- package/src/api/build.ts +7 -6
- package/src/api/create-npm-dirs.ts +1 -1
- package/src/api/templates/cargo.toml.ts +1 -0
- package/src/api/templates/ci-template.ts +26 -13
- package/src/api/templates/js-binding.ts +35 -10
- package/src/commands/new.ts +30 -52
- package/src/def/build.ts +10 -0
- 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 +0 -2
- 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/cargo.ts +1 -1
- package/src/utils/config.ts +1 -1
- package/src/utils/typegen.ts +48 -32
package/src/utils/config.ts
CHANGED
|
@@ -139,7 +139,7 @@ export interface CommonPackageJsonFields {
|
|
|
139
139
|
export type NapiConfig = Required<
|
|
140
140
|
Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>
|
|
141
141
|
> &
|
|
142
|
-
Pick<UserNapiConfig, 'wasm' | 'dtsHeader' | 'dtsHeaderFile'> & {
|
|
142
|
+
Pick<UserNapiConfig, 'wasm' | 'dtsHeader' | 'dtsHeaderFile' | 'constEnum'> & {
|
|
143
143
|
targets: Target[]
|
|
144
144
|
packageJson: CommonPackageJsonFields
|
|
145
145
|
}
|
package/src/utils/typegen.ts
CHANGED
|
@@ -12,6 +12,7 @@ enum TypeDefKind {
|
|
|
12
12
|
Enum = 'enum',
|
|
13
13
|
StringEnum = 'string_enum',
|
|
14
14
|
Interface = 'interface',
|
|
15
|
+
Type = 'type',
|
|
15
16
|
Fn = 'fn',
|
|
16
17
|
Struct = 'struct',
|
|
17
18
|
Impl = 'impl',
|
|
@@ -38,6 +39,10 @@ function prettyPrint(
|
|
|
38
39
|
s += `export interface ${line.name} {\n${line.def}\n}`
|
|
39
40
|
break
|
|
40
41
|
|
|
42
|
+
case TypeDefKind.Type:
|
|
43
|
+
s += `export type ${line.name} = \n${line.def}`
|
|
44
|
+
break
|
|
45
|
+
|
|
41
46
|
case TypeDefKind.Enum:
|
|
42
47
|
const enumName = constEnum ? 'const enum' : 'enum'
|
|
43
48
|
s += `${exportDeclare(ambient)} ${enumName} ${line.name} {\n${line.def}\n}`
|
|
@@ -87,39 +92,43 @@ export async function processTypeDef(
|
|
|
87
92
|
const groupedDefs = preprocessTypeDef(defs)
|
|
88
93
|
|
|
89
94
|
header = header ?? ''
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
|
|
96
|
+
const dts =
|
|
97
|
+
sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
|
|
98
|
+
.map(([namespace, defs]) => {
|
|
99
|
+
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
100
|
+
return defs
|
|
101
|
+
.map((def) => {
|
|
102
|
+
switch (def.kind) {
|
|
103
|
+
case TypeDefKind.Const:
|
|
104
|
+
case TypeDefKind.Enum:
|
|
105
|
+
case TypeDefKind.StringEnum:
|
|
106
|
+
case TypeDefKind.Fn:
|
|
107
|
+
case TypeDefKind.Struct: {
|
|
108
|
+
exports.push(def.name)
|
|
109
|
+
if (def.original_name && def.original_name !== def.name) {
|
|
110
|
+
exports.push(def.original_name)
|
|
111
|
+
}
|
|
112
|
+
break
|
|
113
|
+
}
|
|
114
|
+
default:
|
|
115
|
+
break
|
|
106
116
|
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
return prettyPrint(def, constEnum, 0)
|
|
118
|
+
})
|
|
119
|
+
.join('\n\n')
|
|
120
|
+
} else {
|
|
121
|
+
exports.push(namespace)
|
|
122
|
+
let declaration = ''
|
|
123
|
+
declaration += `export declare namespace ${namespace} {\n`
|
|
124
|
+
for (const def of defs) {
|
|
125
|
+
declaration += prettyPrint(def, constEnum, 2, true) + '\n'
|
|
111
126
|
}
|
|
127
|
+
declaration += '}'
|
|
128
|
+
return declaration
|
|
112
129
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
dts += `export declare namespace ${namespace} {\n`
|
|
116
|
-
for (const def of defs) {
|
|
117
|
-
dts += prettyPrint(def, constEnum, 2, true) + '\n'
|
|
118
|
-
}
|
|
119
|
-
dts += '}\n\n'
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
)
|
|
130
|
+
})
|
|
131
|
+
.join('\n\n') + '\n'
|
|
123
132
|
|
|
124
133
|
if (dts.indexOf('ExternalObject<') > -1) {
|
|
125
134
|
header += `
|
|
@@ -215,13 +224,20 @@ export function correctStringIdent(src: string, ident: number): string {
|
|
|
215
224
|
const isInMultilineComment = line.startsWith('*')
|
|
216
225
|
const isClosingBracket = line.endsWith('}')
|
|
217
226
|
const isOpeningBracket = line.endsWith('{')
|
|
227
|
+
const isTypeDeclaration = line.endsWith('=')
|
|
228
|
+
const isTypeVariant = line.startsWith('|')
|
|
218
229
|
|
|
219
230
|
let rightIndent = ident
|
|
220
|
-
if (isOpeningBracket && !isInMultilineComment) {
|
|
231
|
+
if ((isOpeningBracket || isTypeDeclaration) && !isInMultilineComment) {
|
|
221
232
|
bracketDepth += 1
|
|
222
233
|
rightIndent += (bracketDepth - 1) * 2
|
|
223
234
|
} else {
|
|
224
|
-
if (
|
|
235
|
+
if (
|
|
236
|
+
isClosingBracket &&
|
|
237
|
+
bracketDepth > 0 &&
|
|
238
|
+
!isInMultilineComment &&
|
|
239
|
+
!isTypeVariant
|
|
240
|
+
) {
|
|
225
241
|
bracketDepth -= 1
|
|
226
242
|
}
|
|
227
243
|
rightIndent += bracketDepth * 2
|