serverless/lib/utils/npm-command-deferred.js
2021-01-04 16:21:24 +01:00

20 lines
458 B
JavaScript

'use strict';
const path = require('path');
const fse = require('fs-extra');
const localNpmBinPath = path.join(__dirname, '../../node_modules/npm/bin/npm-cli.js');
module.exports = fse
.stat(localNpmBinPath)
.then(
(stats) => stats.isFile(),
(error) => {
if (error.code === 'ENOENT') return null;
throw error;
}
)
.then((isNpmInstalledLocaly) => {
return isNpmInstalledLocaly ? `node ${localNpmBinPath}` : 'npm';
});