fix(cli): generate ExternalObject type on demand
This commit is contained in:
parent
e607bc158e
commit
f9c618e046
1 changed files with 22 additions and 13 deletions
|
@ -493,18 +493,6 @@ async function processIntermediateTypeFile(
|
||||||
return idents
|
return idents
|
||||||
}
|
}
|
||||||
|
|
||||||
const dtsHeader = `/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/* auto-generated by NAPI-RS */
|
|
||||||
|
|
||||||
export class ExternalObject<T> {
|
|
||||||
readonly '': {
|
|
||||||
readonly '': unique symbol
|
|
||||||
[K: symbol]: T
|
|
||||||
}
|
|
||||||
}\n`
|
|
||||||
|
|
||||||
const allDefs = lines.map((line) => JSON.parse(line) as TypeDef)
|
const allDefs = lines.map((line) => JSON.parse(line) as TypeDef)
|
||||||
|
|
||||||
function convertDefs(defs: TypeDef[], nested = false): string {
|
function convertDefs(defs: TypeDef[], nested = false): string {
|
||||||
|
@ -597,8 +585,29 @@ export class ExternalObject<T> {
|
||||||
return acc + `export namespace ${mod} {\n${convertDefs(defs, true)}}\n`
|
return acc + `export namespace ${mod} {\n${convertDefs(defs, true)}}\n`
|
||||||
}, '')
|
}, '')
|
||||||
|
|
||||||
|
const dtsHeader = `/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
/* auto-generated by NAPI-RS */\n
|
||||||
|
`
|
||||||
|
|
||||||
|
const externalDef =
|
||||||
|
topLevelDef.indexOf('ExternalObject<') > -1 ||
|
||||||
|
namespaceDefs.indexOf('ExternalObject<') > -1
|
||||||
|
? `export class ExternalObject<T> {
|
||||||
|
readonly '': {
|
||||||
|
readonly '': unique symbol
|
||||||
|
[K: symbol]: T
|
||||||
|
}
|
||||||
|
}\n`
|
||||||
|
: ''
|
||||||
|
|
||||||
await unlinkAsync(source)
|
await unlinkAsync(source)
|
||||||
await writeFileAsync(target, dtsHeader + topLevelDef + namespaceDefs, 'utf8')
|
await writeFileAsync(
|
||||||
|
target,
|
||||||
|
dtsHeader + externalDef + topLevelDef + namespaceDefs,
|
||||||
|
'utf8',
|
||||||
|
)
|
||||||
return idents
|
return idents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue