@napi-rs/cli 3.0.0-alpha.81 → 3.0.0-alpha.83
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 +71 -138
- package/dist/api/build.js.map +1 -1
- package/dist/index.cjs +227 -408
- package/dist/utils/misc.d.ts +2 -1
- package/dist/utils/misc.js +10 -8
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +5 -22
- package/dist/utils/typegen.js.map +1 -1
- package/package.json +2 -2
- package/src/api/build.ts +91 -169
- 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 +2 -16
- 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/misc.ts +10 -9
- package/src/utils/typegen.ts +10 -32
package/src/utils/typegen.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sortBy
|
|
1
|
+
import { sortBy } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
import { readFileAsync } from './misc.js'
|
|
4
4
|
|
|
@@ -85,14 +85,11 @@ function exportDeclare(ambient: boolean): string {
|
|
|
85
85
|
export async function processTypeDef(
|
|
86
86
|
intermediateTypeFile: string,
|
|
87
87
|
constEnum: boolean,
|
|
88
|
-
header?: string,
|
|
89
88
|
) {
|
|
90
89
|
const exports: string[] = []
|
|
91
90
|
const defs = await readIntermediateTypeFile(intermediateTypeFile)
|
|
92
91
|
const groupedDefs = preprocessTypeDef(defs)
|
|
93
92
|
|
|
94
|
-
header = header ?? ''
|
|
95
|
-
|
|
96
93
|
const dts =
|
|
97
94
|
sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
|
|
98
95
|
.map(([namespace, defs]) => {
|
|
@@ -130,41 +127,22 @@ export async function processTypeDef(
|
|
|
130
127
|
})
|
|
131
128
|
.join('\n\n') + '\n'
|
|
132
129
|
|
|
133
|
-
if (dts.indexOf('ExternalObject<') > -1) {
|
|
134
|
-
header += `
|
|
135
|
-
export declare class ExternalObject<T> {
|
|
136
|
-
readonly '': {
|
|
137
|
-
readonly '': unique symbol
|
|
138
|
-
[K: symbol]: T
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
`
|
|
142
|
-
}
|
|
143
|
-
|
|
144
130
|
return {
|
|
145
|
-
dts
|
|
131
|
+
dts,
|
|
146
132
|
exports,
|
|
147
133
|
}
|
|
148
134
|
}
|
|
149
135
|
|
|
150
136
|
async function readIntermediateTypeFile(file: string) {
|
|
151
137
|
const content = await readFileAsync(file, 'utf8')
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const start = line.indexOf(':') + 1
|
|
161
|
-
line = line.slice(start)
|
|
162
|
-
}
|
|
163
|
-
return JSON.parse(line) as TypeDefLine
|
|
164
|
-
})
|
|
165
|
-
.filter((def) => !!def.kind),
|
|
166
|
-
(a, b) => isEqual(a, b),
|
|
167
|
-
)
|
|
138
|
+
|
|
139
|
+
const defs = content
|
|
140
|
+
.split('\n')
|
|
141
|
+
.filter(Boolean)
|
|
142
|
+
.map((line) => {
|
|
143
|
+
line = line.trim()
|
|
144
|
+
return JSON.parse(line) as TypeDefLine
|
|
145
|
+
})
|
|
168
146
|
|
|
169
147
|
// move all `struct` def to the very top
|
|
170
148
|
// and order the rest alphabetically.
|