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'; 'use strict';
const crypto = require('crypto'); 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. * 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 * 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 // 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). // that are not included in `package.json` (which is expected to not exist).
const commandExists = require('command-exists').sync; const commandExists = require('command-exists').sync;
if (commandExists('bun')) { if (commandExists('npm')) {
const file = Bun.readFile('package.json'); const cmd = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production'];
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']}));
const text = await file.text(); await Promise.all(Object.entries(dependencies).map(async ([pkg, info]) => {
const parsedJSON = JSON.parse(text);
const dependencies = parsedJSON.dependencies;
await Promise.all(Object.entries(dependencies).map(async (pkg) => {
const info = Object();
if (!pkg.startsWith(exports.prefix)) { if (!pkg.startsWith(exports.prefix)) {
delete dependencies[pkg]; delete dependencies[pkg];
return; return;
} }
info.realPath = `${cwd}/node_modules/${pkg}`; info.realPath = await fs.realpath(info.path);
})); }));
return dependencies;
} else { } else {
const cmd = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production']; const cmd = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production'];
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']})); const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']}));