diff --git a/lib/native/binding.js b/lib/native/binding.js index b869915b..a6f5a571 100644 --- a/lib/native/binding.js +++ b/lib/native/binding.js @@ -58,13 +58,27 @@ if (existsSync(dist)) { const bin_path = path.resolve(source_root, 'bin'); -const search_paths = [ - path.join(bin_path, platformDir, binary_name), +let search_paths = [ + path.join(bin_path, platformDir, binary_name) + '.node', ]; +/* + * Environment variables can inject (at lower-priority) paths into the search process as well. Support both relative + * and absolute path overrides. + */ +let relative_path = process.env.AWS_CRT_NODEJS_BINARY_RELATIVE_PATH; +if (relative_path) { + let final_path = path.resolve(__dirname, ...relative_path.split(path.sep)) + search_paths.push(final_path); +} + +if (process.env.AWS_CRT_NODEJS_BINARY_ABSOLUTE_PATH) { + search_paths.push(process.env.AWS_CRT_NODEJS_BINARY_ABSOLUTE_PATH); +} + let binding; for (const path of search_paths) { - if (existsSync(path + '.node')) { + if (existsSync(path)) { binding = require(path); break; }