iobroker.javascript
Version:
Rules Engine for ioBroker
28 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.requestModuleNameByUrl = requestModuleNameByUrl;
const node_child_process_1 = require("node:child_process");
/**
* Request a module name by given url using `npm view`
*
* @param url the url to the package which should be installed via npm
*/
async function requestModuleNameByUrl(url) {
return new Promise((resolve, reject) => {
(0, node_child_process_1.execFile)('npm', ['view', url, 'name'], { windowsHide: true, encoding: 'utf8', shell: false }, (error, stdout) => {
if (error) {
// "ExecFileException" is assembled with Omit<>, which drops its relation to
// Error, so re-wrap it and keep the original as "cause"
reject(new Error(error.message, { cause: error }));
}
else {
if (typeof stdout !== 'string') {
reject(new Error(`Could not determine module name for url "${url}". Unexpected stdout: "${stdout ? JSON.stringify(stdout) : ''}"`));
return;
}
resolve(stdout.trim());
}
});
});
}
//# sourceMappingURL=nodeModulesManagement.js.map