From cec59d399a13873b7497572040c68b33e5082027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Galeran?= Date: Fri, 28 Apr 2023 16:39:07 +0200 Subject: [PATCH] refactor: remove some promisify to fs.promises (#18990) --- packages/cli/helpers/build.ts | 9 +++------ packages/cli/src/Doctor.ts | 4 +--- packages/cli/src/utils/getClientVersion.ts | 7 ++----- .../cli/src/utils/prompt/utils/isDirEmpty.ts | 4 +--- packages/client/scripts/postinstall.js | 19 ++++++++---------- .../happy/atomic-operations/test.ts | 5 +---- .../happy/uncheckedScalarInputs/test.ts | 5 +---- .../client/src/generation/generateClient.ts | 20 ++++++++----------- packages/client/src/runtime/utils/find.ts | 11 +++------- packages/client/src/utils/getTestClient.ts | 5 +---- packages/fetch-engine/src/cleanupCache.ts | 6 ++---- packages/fetch-engine/src/download.ts | 17 +++++++--------- packages/internals/src/cli/getSchema.ts | 3 +-- packages/internals/src/resolveBinary.ts | 8 ++------ .../src/__tests__/handlePanic.migrate.test.ts | 4 +--- packages/migrate/src/utils/seed.ts | 4 +--- scripts/ci/publish.ts | 16 +++++++-------- 17 files changed, 51 insertions(+), 96 deletions(-) diff --git a/packages/cli/helpers/build.ts b/packages/cli/helpers/build.ts index 577d34e89bde..d434d85f322f 100644 --- a/packages/cli/helpers/build.ts +++ b/packages/cli/helpers/build.ts @@ -3,14 +3,11 @@ import fs from 'fs' import { copy } from 'fs-extra' import lineReplace from 'line-replace' import path from 'path' -import { promisify } from 'util' import type { BuildOptions } from '../../../helpers/compile/build' import { build } from '../../../helpers/compile/build' import { run } from '../../../helpers/compile/run' -const copyFile = promisify(fs.copyFile) - /** * Manages the extra actions that are needed for the CLI to work */ @@ -33,20 +30,20 @@ const cliLifecyclePlugin: esbuild.Plugin = { }) // we copy the contents from checkpoint-client to build - await copyFile( + await fs.promises.copyFile( path.join(require.resolve('checkpoint-client/package.json'), '../dist/child.js'), './build/child.js', ) // we copy the contents from xdg-open to build - await copyFile(path.join(require.resolve('open/package.json'), '../xdg-open'), './build/xdg-open') + await fs.promises.copyFile(path.join(require.resolve('open/package.json'), '../xdg-open'), './build/xdg-open') // as a convention, we install all Prisma's Wasm modules in the internals package const wasmResolveDir = path.join(__dirname, '..', '..', 'internals', 'node_modules') // TODO: create a glob helper for this to import all the wasm modules having pattern /^@prisma\/.*-wasm$/ const prismaWasmFile = path.join(wasmResolveDir, '@prisma', 'prisma-fmt-wasm', 'src', 'prisma_fmt_build_bg.wasm') - await copyFile(prismaWasmFile, './build/prisma_fmt_build_bg.wasm') + await fs.promises.copyFile(prismaWasmFile, './build/prisma_fmt_build_bg.wasm') await replaceFirstLine('./build/index.js', '#!/usr/bin/env node\n') diff --git a/packages/cli/src/Doctor.ts b/packages/cli/src/Doctor.ts index 118acbca7442..bbf17c3750c5 100644 --- a/packages/cli/src/Doctor.ts +++ b/packages/cli/src/Doctor.ts @@ -18,9 +18,7 @@ import equal from 'fast-deep-equal' import fs from 'fs' import { bold, dim, green, red, underline } from 'kleur/colors' import path from 'path' -import { promisify } from 'util' -const readFile = promisify(fs.readFile) type IncorrectFieldTypes = Array<{ localField: DMMF.Field remoteField: DMMF.Field @@ -75,7 +73,7 @@ ${bold('Examples')} const schemaPath = await getSchemaPathAndPrint(args['--schema']) - const schema = await readFile(schemaPath, 'utf-8') + const schema = await fs.promises.readFile(schemaPath, 'utf-8') const localDmmf = await getDMMF({ datamodel: schema }) const config = await getConfig({ datamodel: schema, ignoreEnvVarErrors: false }) diff --git a/packages/cli/src/utils/getClientVersion.ts b/packages/cli/src/utils/getClientVersion.ts index 51a9384e5041..80464ba2a704 100644 --- a/packages/cli/src/utils/getClientVersion.ts +++ b/packages/cli/src/utils/getClientVersion.ts @@ -1,9 +1,6 @@ import fs from 'fs' import Module from 'module' import pkgUp from 'pkg-up' -import { promisify } from 'util' - -const readFileAsync = promisify(fs.readFile) /** * Try reading the installed Prisma Client version @@ -23,7 +20,7 @@ async function getPrismaClientVersionFromNodeModules(cwd: string = process.cwd() return null } - const pkgJsonString = await readFileAsync(pkgJsonPath, 'utf-8') + const pkgJsonString = await fs.promises.readFile(pkgJsonPath, 'utf-8') const pkgJson = JSON.parse(pkgJsonString) if (!pkgJson.version) { @@ -47,7 +44,7 @@ async function getPrismaClientVersionFromLocalPackageJson(cwd: string = process. return null } - const pkgJsonString = await readFileAsync(pkgJsonPath, 'utf-8') + const pkgJsonString = await fs.promises.readFile(pkgJsonPath, 'utf-8') const pkgJson = JSON.parse(pkgJsonString) const clientVersion = pkgJson.dependencies?.['@prisma/client'] ?? pkgJson.devDependencies?.['@prisma/client'] diff --git a/packages/cli/src/utils/prompt/utils/isDirEmpty.ts b/packages/cli/src/utils/prompt/utils/isDirEmpty.ts index ac530b108486..542ca571c752 100644 --- a/packages/cli/src/utils/prompt/utils/isDirEmpty.ts +++ b/packages/cli/src/utils/prompt/utils/isDirEmpty.ts @@ -1,10 +1,8 @@ import fs from 'fs' -import { promisify } from 'util' -const readdir = promisify(fs.readdir) const allowList = ['.DS_Store'] export async function isDirEmpty(dir: string): Promise { - const files = await readdir(dir) + const files = await fs.promises.readdir(dir) return files.filter((f) => !allowList.includes(f)).length === 0 } diff --git a/packages/client/scripts/postinstall.js b/packages/client/scripts/postinstall.js index b3fcb5c3a027..43251d36f49d 100644 --- a/packages/client/scripts/postinstall.js +++ b/packages/client/scripts/postinstall.js @@ -6,9 +6,6 @@ const path = require('path') const c = require('./colors') const exec = promisify(childProcess.exec) -const copyFile = promisify(fs.copyFile) -const mkdir = promisify(fs.mkdir) -const stat = promisify(fs.stat) function debug(message, ...optionalParams) { if (process.env.DEBUG && process.env.DEBUG === 'prisma:postinstall') { @@ -215,27 +212,27 @@ async function createDefaultGeneratedThrowFiles() { await makeDir(defaultDenoClientDir) if (!fs.existsSync(defaultNodeIndexPath)) { - await copyFile(path.join(__dirname, 'default-index.js'), defaultNodeIndexPath) + await fs.promises.copyFile(path.join(__dirname, 'default-index.js'), defaultNodeIndexPath) } if (!fs.existsSync(defaultBrowserIndexPath)) { - await copyFile(path.join(__dirname, 'default-index-browser.js'), defaultBrowserIndexPath) + await fs.promises.copyFile(path.join(__dirname, 'default-index-browser.js'), defaultBrowserIndexPath) } if (!fs.existsSync(defaultNodeIndexDtsPath)) { - await copyFile(path.join(__dirname, 'default-index.d.ts'), defaultNodeIndexDtsPath) + await fs.promises.copyFile(path.join(__dirname, 'default-index.d.ts'), defaultNodeIndexDtsPath) } if (!fs.existsSync(defaultEdgeIndexPath)) { - await copyFile(path.join(__dirname, 'default-edge.js'), defaultEdgeIndexPath) + await fs.promises.copyFile(path.join(__dirname, 'default-edge.js'), defaultEdgeIndexPath) } if (!fs.existsSync(defaultEdgeIndexDtsPath)) { - await copyFile(path.join(__dirname, 'default-index.d.ts'), defaultEdgeIndexDtsPath) + await fs.promises.copyFile(path.join(__dirname, 'default-index.d.ts'), defaultEdgeIndexDtsPath) } if (!fs.existsSync(defaultDenoEdgeIndexPath)) { - await copyFile(path.join(__dirname, 'default-deno-edge.ts'), defaultDenoEdgeIndexPath) + await fs.promises.copyFile(path.join(__dirname, 'default-deno-edge.ts'), defaultDenoEdgeIndexPath) } } catch (e) { console.error(e) @@ -246,7 +243,7 @@ async function createDefaultGeneratedThrowFiles() { function makeDir(input) { const make = async (pth) => { try { - await mkdir(pth) + await fs.promises.mkdir(pth) return pth } catch (error) { @@ -269,7 +266,7 @@ function makeDir(input) { } try { - const stats = await stat(pth) + const stats = await fs.promises.stat(pth) if (!stats.isDirectory()) { throw new Error('The path is not a directory') } diff --git a/packages/client/src/__tests__/integration/happy/atomic-operations/test.ts b/packages/client/src/__tests__/integration/happy/atomic-operations/test.ts index 7a732a58ca36..4d73b96758aa 100644 --- a/packages/client/src/__tests__/integration/happy/atomic-operations/test.ts +++ b/packages/client/src/__tests__/integration/happy/atomic-operations/test.ts @@ -1,14 +1,11 @@ import fs from 'fs' import path from 'path' -import { promisify } from 'util' import { getTestClient } from '../../../../utils/getTestClient' -const copyFile = promisify(fs.copyFile) - test('atomic-operations', async () => { // start with a fresh db - await copyFile(path.join(__dirname, 'dev.db'), path.join(__dirname, 'dev-tmp.db')) + await fs.promises.copyFile(path.join(__dirname, 'dev.db'), path.join(__dirname, 'dev-tmp.db')) const PrismaClient = await getTestClient() const prisma = new PrismaClient() diff --git a/packages/client/src/__tests__/integration/happy/uncheckedScalarInputs/test.ts b/packages/client/src/__tests__/integration/happy/uncheckedScalarInputs/test.ts index d978cfd18b5c..ea3a6b68d960 100644 --- a/packages/client/src/__tests__/integration/happy/uncheckedScalarInputs/test.ts +++ b/packages/client/src/__tests__/integration/happy/uncheckedScalarInputs/test.ts @@ -1,13 +1,10 @@ import fs from 'fs' import path from 'path' -import { promisify } from 'util' import { getTestClient } from '../../../../utils/getTestClient' -const copyFile = promisify(fs.copyFile) - test('uncheckedScalarInputs', async () => { - await copyFile(path.join(__dirname, 'dev.db'), path.join(__dirname, 'dev-tmp.db')) + await fs.promises.copyFile(path.join(__dirname, 'dev.db'), path.join(__dirname, 'dev-tmp.db')) const PrismaClient = await getTestClient() const prisma = new PrismaClient() await prisma.user.deleteMany() diff --git a/packages/client/src/generation/generateClient.ts b/packages/client/src/generation/generateClient.ts index c9392b9c53e7..9dd452408c79 100644 --- a/packages/client/src/generation/generateClient.ts +++ b/packages/client/src/generation/generateClient.ts @@ -15,11 +15,7 @@ import type { Dictionary } from '../runtime/utils/common' import { getPrismaClientDMMF } from './getDMMF' import { BrowserJS, JS, TS, TSClient } from './TSClient' -const remove = promisify(fs.unlink) -const writeFile = promisify(fs.writeFile) const exists = promisify(fs.exists) -const copyFile = promisify(fs.copyFile) -const stat = promisify(fs.stat) const GENERATED_PACKAGE_NAME = '.prisma/client' @@ -261,9 +257,9 @@ export async function generateClient(options: GenerateClientOptions): Promise { try { - const statResult = await stat(name) + const statResult = await fs.promises.stat(name) return statResult.size } catch (e) { return null @@ -574,5 +570,5 @@ async function copyRuntimeFiles({ from, to, runtimeName, sourceMaps }: CopyRunti files.push(...files.filter((file) => file.endsWith('.js')).map((file) => `${file}.map`)) } - await Promise.all(files.map((file) => copyFile(path.join(from, file), path.join(to, file)))) + await Promise.all(files.map((file) => fs.promises.copyFile(path.join(from, file), path.join(to, file)))) } diff --git a/packages/client/src/runtime/utils/find.ts b/packages/client/src/runtime/utils/find.ts index 7ee7f7cd3855..42b921ecd9db 100644 --- a/packages/client/src/runtime/utils/find.ts +++ b/packages/client/src/runtime/utils/find.ts @@ -1,11 +1,6 @@ /* eslint-disable @typescript-eslint/no-inferrable-types */ import fs from 'fs' import path from 'path' -import { promisify } from 'util' - -const readdirAsync = promisify(fs.readdir) -const realpathAsync = promisify(fs.realpath) -const statAsync = promisify(fs.stat) const readdirSync = fs.readdirSync const realpathSync = fs.realpathSync @@ -182,7 +177,7 @@ export async function findAsync( seen: Record = {}, ) { try { - const realRoot = await realpathAsync(root) + const realRoot = await fs.promises.realpath(root) // we make sure not to loop infinitely if (seen[realRoot]) { @@ -195,12 +190,12 @@ export async function findAsync( } // we check that the root is a directory - if (direntToType(await statAsync(realRoot)) !== 'd') { + if (direntToType(await fs.promises.stat(realRoot)) !== 'd') { return found } // we list the items in the current root - const items = await readdirAsync(root, { withFileTypes: true }) + const items = await fs.promises.readdir(root, { withFileTypes: true }) seen[realRoot] = true for (const item of items) { diff --git a/packages/client/src/utils/getTestClient.ts b/packages/client/src/utils/getTestClient.ts index 330f93c24322..edb22c4bd86f 100644 --- a/packages/client/src/utils/getTestClient.ts +++ b/packages/client/src/utils/getTestClient.ts @@ -13,7 +13,6 @@ import { import fs from 'fs' import path from 'path' import { parse } from 'stacktrace-parser' -import { promisify } from 'util' import { getDMMF } from '../generation/getDMMF' import type { GetPrismaClientConfig } from '../runtime/getPrismaClient' @@ -21,8 +20,6 @@ import { getPrismaClient } from '../runtime/getPrismaClient' import { ensureTestClientQueryEngine } from './ensureTestClientQueryEngine' import { generateInFolder } from './generateInFolder' -const readFile = promisify(fs.readFile) - //TODO Rename to generateTestClientInMemory /** * Returns an in-memory client for testing @@ -31,7 +28,7 @@ export async function getTestClient(schemaDir?: string, printWarnings?: boolean) const callSite = path.dirname(require.main?.filename ?? '') const absSchemaDir = path.resolve(callSite, schemaDir ?? '') const schemaPath = await getRelativeSchemaPath(absSchemaDir) - const datamodel = await readFile(schemaPath!, 'utf-8') + const datamodel = await fs.promises.readFile(schemaPath!, 'utf-8') const config = await getConfig({ datamodel, ignoreEnvVarErrors: true }) if (printWarnings) { printConfigWarnings(config.warnings) diff --git a/packages/fetch-engine/src/cleanupCache.ts b/packages/fetch-engine/src/cleanupCache.ts index e70f5b1cec37..f988e1ade3f3 100644 --- a/packages/fetch-engine/src/cleanupCache.ts +++ b/packages/fetch-engine/src/cleanupCache.ts @@ -9,8 +9,6 @@ import { getRootCacheDir } from './utils' const debug = Debug('cleanupCache') const del = promisify(rimraf) -const readdir = promisify(fs.readdir) -const stat = promisify(fs.stat) export async function cleanupCache(n = 5): Promise { try { @@ -21,11 +19,11 @@ export async function cleanupCache(n = 5): Promise { } const channel = 'master' const cacheDir = path.join(rootCacheDir, channel) - const dirs = await readdir(cacheDir) + const dirs = await fs.promises.readdir(cacheDir) const dirsWithMeta = await Promise.all( dirs.map(async (dirName) => { const dir = path.join(cacheDir, dirName) - const statResult = await stat(dir) + const statResult = await fs.promises.stat(dir) return { dir, diff --git a/packages/fetch-engine/src/download.ts b/packages/fetch-engine/src/download.ts index cabf6e30e971..8939dc9e02f4 100644 --- a/packages/fetch-engine/src/download.ts +++ b/packages/fetch-engine/src/download.ts @@ -19,10 +19,7 @@ import { getCacheDir, getDownloadUrl, overwriteFile } from './utils' const { enginesOverride } = require('../package.json') const debug = Debug('prisma:download') -const writeFile = promisify(fs.writeFile) const exists = promisify(fs.exists) -const readFile = promisify(fs.readFile) -const utimes = promisify(fs.utimes) const channel = 'master' export enum BinaryType { @@ -268,7 +265,7 @@ async function binaryNeedsToBeDownloaded( const sha256FilePath = cachedFile + '.sha256' if (await exists(sha256FilePath)) { - const sha256File = await readFile(sha256FilePath, 'utf-8') + const sha256File = await fs.promises.readFile(sha256FilePath, 'utf-8') const sha256Cache = await getHash(cachedFile) if (sha256File === sha256Cache) { if (!targetExists) { @@ -276,7 +273,7 @@ async function binaryNeedsToBeDownloaded( // TODO Remove when https://github.com/docker/for-linux/issues/1015 is fixed // Workaround for https://github.com/prisma/prisma/issues/7037 - await utimes(cachedFile, new Date(), new Date()) + await fs.promises.utimes(cachedFile, new Date(), new Date()) await overwriteFile(cachedFile, job.targetFilePath) } @@ -318,7 +315,7 @@ async function binaryNeedsToBeDownloaded( export async function getVersion(enginePath: string, binaryName: string) { try { if (binaryName === BinaryType.QueryEngineLibrary) { - isNodeAPISupported() + void isNodeAPISupported() const commitHash = require(enginePath).version().commit return `${BinaryType.QueryEngineLibrary} ${commitHash}` @@ -454,8 +451,8 @@ async function saveFileToCache( try { await overwriteFile(job.targetFilePath, cachedTargetPath) - await writeFile(cachedSha256Path, sha256) - await writeFile(cachedSha256ZippedPath, zippedSha256) + await fs.promises.writeFile(cachedSha256Path, sha256) + await fs.promises.writeFile(cachedSha256ZippedPath, zippedSha256) } catch (e) { debug(e) // let this fail silently - the CI system may have reached the file size limit @@ -493,8 +490,8 @@ export async function maybeCopyToTmp(file: string): Promise { const targetDir = path.join(tempDir, 'prisma-binaries') await ensureDir(targetDir) const target = path.join(targetDir, path.basename(file)) - const data = await readFile(file) - await writeFile(target, data) + const data = await fs.promises.readFile(file) + await fs.promises.writeFile(target, data) // We have to read and write until https://github.com/zeit/pkg/issues/639 // is resolved // await copyFile(file, target) diff --git a/packages/internals/src/cli/getSchema.ts b/packages/internals/src/cli/getSchema.ts index dad0d8580a51..8b7a8710a712 100644 --- a/packages/internals/src/cli/getSchema.ts +++ b/packages/internals/src/cli/getSchema.ts @@ -7,7 +7,6 @@ import readPkgUp from 'read-pkg-up' import { promisify } from 'util' const exists = promisify(fs.exists) -const readFile = promisify(fs.readFile) /** * Async @@ -261,7 +260,7 @@ export async function getSchema(schemaPathFromArgs?: string): Promise { ) } - return readFile(schemaPath, 'utf-8') + return fs.promises.readFile(schemaPath, 'utf-8') } /** diff --git a/packages/internals/src/resolveBinary.ts b/packages/internals/src/resolveBinary.ts index ee177a44c64d..8a364a047b88 100644 --- a/packages/internals/src/resolveBinary.ts +++ b/packages/internals/src/resolveBinary.ts @@ -7,10 +7,6 @@ import fs from 'fs' import { ensureDir } from 'fs-extra' import path from 'path' import tempDir from 'temp-dir' -import { promisify } from 'util' - -const readFile = promisify(fs.readFile) -const writeFile = promisify(fs.writeFile) async function getBinaryName(name: BinaryType): Promise { const platform = await getPlatform() @@ -99,8 +95,8 @@ export async function maybeCopyToTmp(file: string): Promise { const target = path.join(targetDir, path.basename(file)) // We have to read and write until https://github.com/zeit/pkg/issues/639 is resolved - const data = await readFile(file) - await writeFile(target, data) + const data = await fs.promises.readFile(file) + await fs.promises.writeFile(target, data) // TODO Undo when https://github.com/vercel/pkg/pull/1484 is released // await copyFile(file, target) diff --git a/packages/migrate/src/__tests__/handlePanic.migrate.test.ts b/packages/migrate/src/__tests__/handlePanic.migrate.test.ts index 5e5aca770b51..fc5bf5be4e8c 100644 --- a/packages/migrate/src/__tests__/handlePanic.migrate.test.ts +++ b/packages/migrate/src/__tests__/handlePanic.migrate.test.ts @@ -7,7 +7,6 @@ import prompt from 'prompts' import stripAnsi from 'strip-ansi' import dedent from 'strip-indent' import tempy from 'tempy' -import { promisify } from 'util' import { Migrate } from '../Migrate' import CaptureStdout from './__helpers__/captureStdout' @@ -26,7 +25,6 @@ const sendKeystrokes = async (io) => { // helper function for timing const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) // Mock stdin so we can send messages to the CLI -const writeFile = promisify(fs.writeFile) const testRootDir = tempy.directory() // eslint-disable-next-line @typescript-eslint/unbound-method @@ -41,7 +39,7 @@ async function writeFiles( for (const name in files) { const filepath = join(root, name) await ensureDir(dirname(filepath)) - await writeFile(filepath, dedent(files[name])) + await fs.promises.writeFile(filepath, dedent(files[name])) } // return the test path return root diff --git a/packages/migrate/src/utils/seed.ts b/packages/migrate/src/utils/seed.ts index e064c10b8ee9..19667f446cb2 100644 --- a/packages/migrate/src/utils/seed.ts +++ b/packages/migrate/src/utils/seed.ts @@ -6,10 +6,8 @@ import hasYarn from 'has-yarn' import { bold, green, italic, red, yellow } from 'kleur/colors' import path from 'path' import pkgUp from 'pkg-up' -import { promisify } from 'util' const debug = Debug('prisma:migrate:seed') -const readFileAsync = promisify(fs.readFile) /* Checks if user has a prisma/seed.ts or prisma/seed.js or prisma/seed.sh @@ -229,7 +227,7 @@ async function getScriptsFromPackageJson(cwd: string = process.cwd()) { return null } - const pkgJsonString = await readFileAsync(pkgJsonPath, 'utf-8') + const pkgJsonString = await fs.promises.readFile(pkgJsonPath, 'utf-8') const pkgJson: PkgJSON = JSON.parse(pkgJsonString) diff --git a/scripts/ci/publish.ts b/scripts/ci/publish.ts index 5d8b0c0e2c0e..9c0900d70689 100644 --- a/scripts/ci/publish.ts +++ b/scripts/ci/publish.ts @@ -3,7 +3,7 @@ import { IncomingWebhook } from '@slack/webhook' import arg from 'arg' import topo from 'batching-toposort' import execa from 'execa' -import { existsSync, promises as fs } from 'fs' +import fs from 'fs' import globby from 'globby' import { blue, bold, cyan, dim, magenta, red, underline } from 'kleur/colors' import fetch from 'node-fetch' @@ -137,7 +137,7 @@ export async function getPackages(): Promise { const packages = await Promise.all( packagePaths.map(async (p) => ({ path: p, - packageJson: JSON.parse(await fs.readFile(p, 'utf-8')), + packageJson: JSON.parse(await fs.promises.readFile(p, 'utf-8')), })), ) @@ -698,7 +698,7 @@ Check them out at https://github.com/prisma/ecosystem-tests/actions?query=workfl async function getEnginesCommit(): Promise { const prisma2Path = path.resolve(process.cwd(), './packages/engines/package.json') - const pkg = JSON.parse(await fs.readFile(prisma2Path, 'utf-8')) + const pkg = JSON.parse(await fs.promises.readFile(prisma2Path, 'utf-8')) // const engineVersion = pkg.prisma.version const engineVersion = pkg.devDependencies['@prisma/engines-version']?.split('.').slice(-1)[0] @@ -1063,7 +1063,7 @@ async function acquireLock(branch: string): Promise<() => void> { async function writeToPkgJson(pkgDir, cb: (pkg: any) => any, dryRun?: boolean) { const pkgJsonPath = path.join(pkgDir, 'package.json') - const file = await fs.readFile(pkgJsonPath, 'utf-8') + const file = await fs.promises.readFile(pkgJsonPath, 'utf-8') let packageJson = JSON.parse(file) if (dryRun) { console.log(`Would write to ${pkgJsonPath} from ${packageJson.version} now`) @@ -1072,19 +1072,19 @@ async function writeToPkgJson(pkgDir, cb: (pkg: any) => any, dryRun?: boolean) { if (result) { packageJson = result } - await fs.writeFile(pkgJsonPath, JSON.stringify(packageJson, null, 2)) + await fs.promises.writeFile(pkgJsonPath, JSON.stringify(packageJson, null, 2)) } } async function writeVersion(pkgDir: string, version: string, dryRun?: boolean) { const pkgJsonPath = path.join(pkgDir, 'package.json') - const file = await fs.readFile(pkgJsonPath, 'utf-8') + const file = await fs.promises.readFile(pkgJsonPath, 'utf-8') const packageJson = JSON.parse(file) if (dryRun) { console.log(`Would update ${pkgJsonPath} from ${packageJson.version} to ${version} now ${dim('(dry)')}`) } else { packageJson.version = version - await fs.writeFile(pkgJsonPath, JSON.stringify(packageJson, null, 2)) + await fs.promises.writeFile(pkgJsonPath, JSON.stringify(packageJson, null, 2)) } } @@ -1193,7 +1193,7 @@ function getCommitEnvVar(name: string): string { } async function cloneOrPull(repo: string, dryRun = false) { - if (existsSync(path.join(__dirname, '../../', repo))) { + if (fs.existsSync(path.join(__dirname, '../../', repo))) { return run(repo, `git pull --tags`, dryRun) } else { await run('.', `git clone ${repoUrl(repo)}`, dryRun)