Use npm for getting packages.

feature/bun
SamTV12345 2023-10-19 21:09:34 +02:00
parent 0e9020ee1f
commit f5db077355
2 changed files with 12 additions and 12 deletions

View File

@ -1,15 +1,18 @@
'use strict';
const crypto = require('crypto');
const util = require('util');
const newMethod = async (...args) => new Promise((resolve) => crypto.hkdf(...args, resolve));
/**
* Promisified version of Node.js's crypto.hkdf.
*/
exports.hkdf = util.promisify(crypto.hkdf);
exports.hkdf = newMethod;
const newMethod2 = async (...args) => new Promise((resolve) => crypto.randomBytes(...args,
resolve));
/**
* Promisified version of Node.js's crypto.randomBytes
*/
exports.randomBytes = util.promisify(crypto.randomBytes);
exports.randomBytes = newMethod2;

View File

@ -113,20 +113,17 @@ exports.getPackages = async () => {
// unset or set to `development`) because otherwise `npm ls` will not mention any packages
// that are not included in `package.json` (which is expected to not exist).
const commandExists = require('command-exists').sync;
if (commandExists('bun')) {
const file = Bun.readFile('package.json');
const text = await file.text();
const parsedJSON = JSON.parse(text);
const dependencies = parsedJSON.dependencies;
await Promise.all(Object.entries(dependencies).map(async (pkg) => {
const info = Object();
if (commandExists('npm')) {
const cmd = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production'];
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']}));
await Promise.all(Object.entries(dependencies).map(async ([pkg, info]) => {
if (!pkg.startsWith(exports.prefix)) {
delete dependencies[pkg];
return;
}
info.realPath = `${cwd}/node_modules/${pkg}`;
info.realPath = await fs.realpath(info.path);
}));
return dependencies;
} else {
const cmd = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production'];
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']}));