Skip to content

Commit a4888fd

Browse files
committed
Generate d.ts via napi cli programatically
1 parent 566e7ed commit a4888fd

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

packages/ferric/src/napi-rs.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import assert from "node:assert/strict";
22
import fs from "node:fs";
33
import path from "node:path";
44

5-
import { spawn } from "bufout";
5+
import { NapiCli } from "@napi-rs/cli";
6+
7+
const napiCli = new NapiCli();
8+
69
import { getBlockComment } from "./banner.js";
710

811
const PACKAGE_ROOT = path.join(import.meta.dirname, "..");
@@ -39,28 +42,18 @@ export async function generateTypeScriptDeclarations({
3942
"{}",
4043
"utf8"
4144
);
45+
const tempOutputPath = path.join(tempPath, outputFilename);
4246
// Call into napi.rs to generate TypeScript declarations
43-
const napiCliPath = new URL(
44-
import.meta.resolve("@napi-rs/cli/scripts/index.js")
45-
).pathname;
46-
await spawn(
47-
// TODO: Resolve the CLI path (not using npx because we don't want to npx to mess up the cwd)
48-
napiCliPath,
49-
[
50-
"build",
51-
"--dts",
52-
outputFilename,
53-
"--cargo-cwd",
54-
// This doesn't understand absolute paths
55-
path.relative(tempPath, createPath),
56-
],
57-
{
58-
outputMode: "buffered",
59-
cwd: tempPath,
60-
}
61-
);
47+
// RUSTFLAGS: "-C link-arg=-undefined -C link-arg=dynamic_lookup",
48+
const { task } = await napiCli.build({
49+
verbose: false,
50+
dts: outputFilename,
51+
outputDir: tempPath,
52+
cwd: createPath,
53+
cargoOptions: ["--quiet"],
54+
});
55+
await task;
6256
// Override the banner
63-
const tempOutputPath = path.join(tempPath, outputFilename);
6457
assert(
6558
fs.existsSync(tempOutputPath),
6659
`Expected napi.rs to emit ${tempOutputPath}`

0 commit comments

Comments
 (0)