mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
refactor: Replace fse.stat with fs.promises.stat (#9845)
This commit is contained in:
parent
7ae52aa2d9
commit
bb0484e6b5
@ -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(
|
||||
|
||||
@ -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')], {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
},
|
||||
});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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') {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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',
|
||||
},
|
||||
}
|
||||
|
||||
@ -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');
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user