#1643

Feature Request: Compile TypeScript to Node-API addon, without node-gyp

Opentoyobayashiopened 22d ago

Thanks for bringing this great project!

I wonder if TypeScript can be compiled to native addons without C and node-gyp wrapper. Currently scriptc does not support ffi in dylib mode.

Maybe 2 optional approach?

  1. Auto binding (so cool)
export function add(a: number, b: number): number {
  return a + b
}
const { add } = require('./add.node')
  1. Direct Node-API call (I have tried but failed)
declare function napi_get_cb_info(/* ... */): number
declare function napi_create_function(/* ... */): number
declare function napi_create_double(/* ... */): number

function add(env: number, info: number): number {
  /* napi_get_cb_info(env, info, ...) */
  const ret = argv[0] + argv[1]
  /* napi_create_double(env, ret, addressOf(napiValueRet)) */
  return napiValueRet
}

export function napi_register_module_v1(env: number, exports: number): number {
  let fn: number /* ... */
  napi_create_function(env, /* ... */, add, 0, addressOf(fn))
  return fn
}
const add = require('./add.node')

Activity

0

No activity yet.