Skip to content

Commit

Permalink
refactor!: use fs/promises (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk authored May 18, 2022
1 parent c812f3b commit f744897
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname, join, resolve } from 'path'
import { emptyDir, ensureDir, readFile, remove, writeFile } from 'fs-extra'
import { performance } from 'perf_hooks'
import { emptyDir, ensureDir, readFile, remove, writeFile } from 'fs-extra'
import jszip from 'jszip'
import HandlerRunner from './handler-runner/index.js'
import LambdaContext from './LambdaContext.js'
Expand Down
21 changes: 9 additions & 12 deletions src/lambda/handler-runner/docker-runner/DockerContainer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createHash } from 'crypto'
import { createWriteStream, unlinkSync } from 'fs'
import { platform } from 'os'
import { dirname, join, sep } from 'path'
import { Lambda } from 'aws-sdk'
import execa from 'execa'
import { ensureDir, pathExists, readFile, writeFile } from 'fs-extra'
import jszip from 'jszip'
import fetch from 'node-fetch'
import pRetry from 'p-retry'
import { Lambda } from 'aws-sdk'
import jszip from 'jszip'
import { createWriteStream, unlinkSync } from 'fs'
import { readFile, writeFile, ensureDir, pathExists } from 'fs-extra'
import { dirname, join, sep } from 'path'
import crypto from 'crypto'
import DockerImage from './DockerImage.js'
import debugLog from '../../../debugLog.js'
import { logLayers, logWarning } from '../../../serverlessLog.js'
Expand Down Expand Up @@ -367,7 +367,7 @@ export default class DockerContainer {
logLayers(`[${layerName}] Unzipping to .layers directory`)
}

const data = await readFile(`${layerZipFile}`)
const data = await readFile(layerZipFile)
const zip = await jszip.loadAsync(data)
await Promise.all(
keys(zip.files).map(async (filename) => {
Expand All @@ -388,7 +388,7 @@ export default class DockerContainer {
logLayers(`[${layerName}] Removing zip file`)
}

unlinkSync(`${layerZipFile}`)
unlinkSync(layerZipFile)
} finally {
if (this.log) layerProgress.remove()
}
Expand Down Expand Up @@ -475,10 +475,7 @@ export default class DockerContainer {
}

#getLayersSha256() {
return crypto
.createHash('sha256')
.update(stringify(this.#layers))
.digest('hex')
return createHash('sha256').update(stringify(this.#layers)).digest('hex')
}

get isRunning() {
Expand Down
3 changes: 1 addition & 2 deletions src/lambda/handler-runner/go-runner/GoRunner.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { promises as fsPromises } from 'fs'
import { mkdir, readFile, rmdir, writeFile } from 'fs/promises'
import { EOL } from 'os'
import { sep, resolve, parse as pathParse } from 'path'
import process, { chdir, cwd } from 'process'
import execa, { sync } from 'execa'

const { writeFile, readFile, mkdir, rmdir } = fsPromises
const { parse, stringify } = JSON

const PAYLOAD_IDENTIFIER = 'offline_payload'
Expand Down

0 comments on commit f744897

Please sign in to comment.