serverless/lib/utils/npm-command-deferred.js
Austen 158f644cd0
feat: Refactor logging to reduce complexity (#12432)
* chore: Change logger

* chore: continue refactor

* chore: WIP

* chore: Sync
2024-04-17 13:26:31 -07:00

23 lines
590 B
JavaScript

import path from 'path';
import fsp from 'fs/promises';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const localNpmBinPath = path.join(__dirname, '../../node_modules/npm/bin/npm-cli.js');
export default fsp
.stat(localNpmBinPath)
.then(
(stats) => stats.isFile(),
(error) => {
if (error.code === 'ENOENT') return null;
throw error;
}
)
.then((isNpmInstalledLocaly) => {
return isNpmInstalledLocaly
? { command: 'node', args: [localNpmBinPath] }
: { command: 'npm', args: [] };
});