Skip to content

Commit 62900f2

Browse files
committed
Call findNodeAddonForBindings in plugin
1 parent d9cda60 commit 62900f2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/host/src/node/babel-plugin/plugin.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import path from "node:path";
44
import type { PluginObj, NodePath } from "@babel/core";
55
import * as t from "@babel/types";
66

7-
import { getLibraryName, isNodeApiModule, NamingStrategy } from "../path-utils";
7+
import {
8+
getLibraryName,
9+
isNodeApiModule,
10+
findNodeAddonForBindings,
11+
NamingStrategy,
12+
} from "../path-utils";
813

9-
type PluginOptions = {
14+
export type PluginOptions = {
1015
stripPathSuffix?: boolean;
1116
};
1217

@@ -64,10 +69,9 @@ export function plugin(): PluginObj {
6469
const [argument] = p.parent.arguments;
6570
if (argument.type === "StringLiteral") {
6671
const id = argument.value;
67-
const relativePath = path.join(from, id);
68-
// TODO: Support traversing the filesystem to find the Node-API module
69-
if (isNodeApiModule(relativePath)) {
70-
replaceWithRequireNodeAddon(p.parentPath, relativePath, {
72+
const resolvedPath = findNodeAddonForBindings(id, from);
73+
if (typeof resolvedPath === "string") {
74+
replaceWithRequireNodeAddon(p.parentPath, resolvedPath, {
7175
stripPathSuffix,
7276
});
7377
}

0 commit comments

Comments
 (0)