import installModule from 'install-module-linked';
import path from 'path';
import url from 'url';
const _dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
const nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');
const moduleName = 'node-version-install';
let cached;
function loadModule(moduleName, callback) {
    if (typeof require === 'undefined') {
        import(moduleName).then((mod)=>{
            var _ref;
            callback(null, (_ref = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _ref !== void 0 ? _ref : null);
        }).catch(callback);
    } else {
        try {
            callback(null, require(moduleName));
        } catch (err) {
            callback(err, null);
        }
    }
}
export default function loadNodeVersionInstall(callback) {
    if (cached !== undefined) return callback(null, cached);
    installModule(moduleName, nodeModules, {}, (err)=>{
        if (err) return callback(err, null);
        loadModule(moduleName, (err, _cached)=>{
            if (err) return callback(err, null);
            cached = _cached;
            callback(null, cached);
        });
    });
}
