Skip to content

Commit d1729bf

Browse files
bretambroseBret Ambrose
andauthored
Napi search path (#490)
Co-authored-by: Bret Ambrose <bambrose@amazon.com>
1 parent 7dc8379 commit d1729bf

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/native/binding.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,27 @@ if (existsSync(dist)) {
5858

5959
const bin_path = path.resolve(source_root, 'bin');
6060

61-
const search_paths = [
62-
path.join(bin_path, platformDir, binary_name),
61+
let search_paths = [
62+
path.join(bin_path, platformDir, binary_name) + '.node',
6363
];
6464

65+
/*
66+
* Environment variables can inject (at lower-priority) paths into the search process as well. Support both relative
67+
* and absolute path overrides.
68+
*/
69+
let relative_path = process.env.AWS_CRT_NODEJS_BINARY_RELATIVE_PATH;
70+
if (relative_path) {
71+
let final_path = path.resolve(__dirname, ...relative_path.split(path.sep))
72+
search_paths.push(final_path);
73+
}
74+
75+
if (process.env.AWS_CRT_NODEJS_BINARY_ABSOLUTE_PATH) {
76+
search_paths.push(process.env.AWS_CRT_NODEJS_BINARY_ABSOLUTE_PATH);
77+
}
78+
6579
let binding;
6680
for (const path of search_paths) {
67-
if (existsSync(path + '.node')) {
81+
if (existsSync(path)) {
6882
binding = require(path);
6983
break;
7084
}

0 commit comments

Comments
 (0)