@@ -63,7 +63,16 @@ const nodeBindingsSubdirs = [
6363 "./Debug" ,
6464] ;
6565function findNodeAddonForBindings ( id : string , fromDir : string ) {
66-
66+ const idWithExt = id . endsWith ( ".node" ) ? id : `${ id } .node` ;
67+ // Support traversing the filesystem to find the Node-API module.
68+ // Currently, we check the most common directories like `bindings` does.
69+ for ( const subdir of nodeBindingsSubdirs ) {
70+ const resolvedPath = path . join ( fromDir , subdir , idWithExt ) ;
71+ if ( isNodeApiModule ( resolvedPath ) ) {
72+ return resolvedPath ;
73+ }
74+ }
75+ return undefined ;
6776}
6877
6978export function replaceWithRequireNodeAddon3 (
@@ -120,15 +129,9 @@ export function plugin(): PluginObj {
120129 const [ argument ] = p . parent . arguments ;
121130 if ( argument . type === "StringLiteral" ) {
122131 const id = argument . value ;
123- const idWithExt = id . endsWith ( ".node" ) ? id : `${ id } .node` ;
124- // Support traversing the filesystem to find the Node-API module.
125- // Currently, we check the most common directories from `bindings`.
126- for ( const subdir of nodeBindingsSubdirs ) {
127- const resolvedPath = path . join ( from , subdir , idWithExt ) ;
128- if ( isNodeApiModule ( resolvedPath ) ) {
129- replaceWithRequireNodeAddon3 ( p . parentPath , resolvedPath , this . filename ) ;
130- break ;
131- }
132+ const resolvedPath = findNodeAddonForBindings ( id , from ) ;
133+ if ( resolvedPath !== undefined ) {
134+ replaceWithRequireNodeAddon3 ( p . parentPath , resolvedPath , this . filename ) ;
132135 }
133136 }
134137 } else {
0 commit comments