diff --git a/lib/cli/resolve-configuration-path.js b/lib/cli/resolve-configuration-path.js index 7d4767d6f..8c5354507 100644 --- a/lib/cli/resolve-configuration-path.js +++ b/lib/cli/resolve-configuration-path.js @@ -3,7 +3,7 @@ const ensurePlainObject = require('type/plain-object/ensure'); const ensureString = require('type/string/ensure'); const path = require('path'); -const fs = require('fs').promises; +const fsp = require('fs').promises; const ServerlessError = require('../serverless-error'); const fileExists = require('../utils/fs/fileExists'); const logDeprecation = require('../utils/logDeprecation'); @@ -29,7 +29,7 @@ module.exports = async (options = {}) => { } const stats = await (async () => { try { - return await fs.stat(customConfigPath); + return await fsp.stat(customConfigPath); } catch (error) { if (error.code === 'ENOENT') { throw new ServerlessError( diff --git a/lib/plugins/aws/invokeLocal/index.js b/lib/plugins/aws/invokeLocal/index.js index 2970e7e66..dda1ea3d6 100644 --- a/lib/plugins/aws/invokeLocal/index.js +++ b/lib/plugins/aws/invokeLocal/index.js @@ -2,6 +2,7 @@ const _ = require('lodash'); const os = require('os'); +const fsp = require('fs').promises; const fse = require('fs-extra'); const path = require('path'); const validate = require('../lib/validate'); @@ -644,7 +645,7 @@ class AwsInvokeLocal { async invokeLocalJava(runtime, className, handlerName, artifactPath, event, customContext) { try { - await fse.stat(artifactPath); + await fsp.stat(artifactPath); } catch { throw new ServerlessError( `Artifact ${artifactPath} doesn't exists, please compile it first.`, @@ -669,7 +670,7 @@ class AwsInvokeLocal { const executablePath = path.join(javaBridgePath, 'target'); try { - await fse.stat(executablePath); + await fsp.stat(executablePath); } catch (err) { return new Promise((resolve, reject) => { const mvn = spawn('mvn', ['package', '-f', path.join(javaBridgePath, 'pom.xml')], { diff --git a/lib/plugins/aws/provider.js b/lib/plugins/aws/provider.js index d560348f1..98e6a6a3b 100644 --- a/lib/plugins/aws/provider.js +++ b/lib/plugins/aws/provider.js @@ -4,7 +4,7 @@ const AWS = require('aws-sdk'); const BbPromise = require('bluebird'); const _ = require('lodash'); const naming = require('./lib/naming.js'); -const fs = require('fs'); +const fsp = require('fs').promises; const getS3EndpointForRegion = require('./utils/getS3EndpointForRegion'); const memoizeeMethods = require('memoizee/methods'); const readline = require('readline'); @@ -1916,7 +1916,7 @@ Object.defineProperties( const pathToDockerfile = path.resolve(this.serverless.serviceDir, imagePath, imageFilename); try { - const stats = await fs.promises.stat(pathToDockerfile); + const stats = await fsp.stat(pathToDockerfile); isDockerfileAvailable = stats.isFile(); } catch { // pass and handle after catch block diff --git a/lib/utils/create-from-local-template.js b/lib/utils/create-from-local-template.js index 473661f9c..d0b8e0a23 100644 --- a/lib/utils/create-from-local-template.js +++ b/lib/utils/create-from-local-template.js @@ -1,6 +1,7 @@ 'use strict'; const untildify = require('untildify'); +const fsp = require('fs').promises; const fse = require('fs-extra'); const { renameService } = require('./renameService'); @@ -13,7 +14,7 @@ module.exports = async ({ templatePath, projectDir, projectName }) => { await fse.copy(sourcePath, projectDir, { dereference: true, filter: async (src) => { - const stats = await fse.lstat(src); + const stats = await fsp.lstat(src); return !stats.isSymbolicLink(); }, }); diff --git a/lib/utils/ensureExists.js b/lib/utils/ensureExists.js index 6da1522b8..b724b8aa9 100644 --- a/lib/utils/ensureExists.js +++ b/lib/utils/ensureExists.js @@ -1,13 +1,13 @@ 'use strict'; const fse = require('fs-extra'); -const fs = require('fs'); +const fsp = require('fs').promises; const path = require('path'); module.exports = async (filename, generate) => { const cacheDir = path.dirname(filename); try { - const stats = await fs.promises.lstat(filename); + const stats = await fsp.lstat(filename); if (stats.isFile()) { return; } diff --git a/lib/utils/fs/dirExists.js b/lib/utils/fs/dirExists.js index d354b0875..0df0ed777 100644 --- a/lib/utils/fs/dirExists.js +++ b/lib/utils/fs/dirExists.js @@ -1,9 +1,9 @@ 'use strict'; -const fse = require('fs-extra'); +const fsp = require('fs').promises; async function dirExists(path) { - return fse.lstat(path).then( + return fsp.lstat(path).then( (stats) => stats.isDirectory(), (error) => { if (error.code === 'ENOENT') { diff --git a/lib/utils/fs/fileExists.js b/lib/utils/fs/fileExists.js index 7c3b6c9d1..ed849f66e 100644 --- a/lib/utils/fs/fileExists.js +++ b/lib/utils/fs/fileExists.js @@ -1,9 +1,9 @@ 'use strict'; -const fse = require('fs-extra'); +const fsp = require('fs').promises; async function fileExists(filePath) { - return fse + return fsp .lstat(filePath) .then((stats) => stats.isFile()) .catch(() => false); diff --git a/lib/utils/npm-command-deferred.js b/lib/utils/npm-command-deferred.js index baea3a106..ab882c2ee 100644 --- a/lib/utils/npm-command-deferred.js +++ b/lib/utils/npm-command-deferred.js @@ -1,11 +1,11 @@ 'use strict'; const path = require('path'); -const fse = require('fs-extra'); +const fsp = require('fs').promises; const localNpmBinPath = path.join(__dirname, '../../node_modules/npm/bin/npm-cli.js'); -module.exports = fse +module.exports = fsp .stat(localNpmBinPath) .then( (stats) => stats.isFile(), diff --git a/lib/utils/npmPackage/isWritable.js b/lib/utils/npmPackage/isWritable.js index 75a273dcd..b8333b345 100644 --- a/lib/utils/npmPackage/isWritable.js +++ b/lib/utils/npmPackage/isWritable.js @@ -2,15 +2,15 @@ const { format } = require('util'); const path = require('path'); -const fs = require('fs').promises; +const fsp = require('fs').promises; const log = require('@serverless/utils/log'); const npmPackageRoot = path.resolve(__dirname, '../../../'); module.exports = async () => { - const stats = await fs.stat(npmPackageRoot); + const stats = await fsp.stat(npmPackageRoot); try { - await fs.utimes(npmPackageRoot, String(stats.atimeMs / 1000), String(stats.mtimeMs / 1000)); + await fsp.utimes(npmPackageRoot, String(stats.atimeMs / 1000), String(stats.mtimeMs / 1000)); return true; } catch (error) { if (process.env.SLS_DEBUG) log(format('Auto update: file access error: %O', error)); diff --git a/scripts/pkg/upload/world.js b/scripts/pkg/upload/world.js index 7b1a302fc..9520500f0 100755 --- a/scripts/pkg/upload/world.js +++ b/scripts/pkg/upload/world.js @@ -64,7 +64,7 @@ module.exports = async (versionTag, { isLegacyVersion }) => { body: fs.createReadStream(filePath), headers: { ...requestOptions.headers, - 'content-length': (await fs.promises.stat(filePath)).size, + 'content-length': (await fsp.stat(filePath)).size, 'content-type': 'application/octet-stream', }, } diff --git a/test/unit/lib/plugins/aws/configCredentials.test.js b/test/unit/lib/plugins/aws/configCredentials.test.js index 00874dffd..330dd4d04 100644 --- a/test/unit/lib/plugins/aws/configCredentials.test.js +++ b/test/unit/lib/plugins/aws/configCredentials.test.js @@ -4,6 +4,7 @@ const expect = require('chai').expect; const sandbox = require('sinon'); const { constants } = require('fs'); const fs = require('fs'); +const fsp = require('fs').promises; const fse = require('fs-extra'); const os = require('os'); const path = require('path'); @@ -25,7 +26,7 @@ describe('AwsConfigCredentials', () => { before(() => { // Abort if credentials are found in home directory // (it should not be the case, as home directory is mocked to point temp dir) - return fse.lstat(awsDirectoryPath).then( + return fsp.lstat(awsDirectoryPath).then( () => { throw new Error('Unexpected ~/.aws directory, related tests aborted'); },