diff --git a/packages/app-cli/app/command-sync.ts b/packages/app-cli/app/command-sync.ts index cb5c42e8fe..4c4d3594b9 100644 --- a/packages/app-cli/app/command-sync.ts +++ b/packages/app-cli/app/command-sync.ts @@ -9,11 +9,11 @@ import { appTypeToLockType } from '@joplin/lib/services/synchronizer/LockHandler const BaseCommand = require('./base-command').default; const { app } = require('./app.js'); const { OneDriveApiNodeUtils } = require('@joplin/lib/onedrive-api-node-utils.js'); -const { reg } = require('@joplin/lib/registry.js'); +import { reg } from '@joplin/lib/registry'; const { cliUtils } = require('./cli-utils.js'); const md5 = require('md5'); -const locker = require('proper-lockfile'); -const fs = require('fs-extra'); +import * as locker from 'proper-lockfile'; +import { pathExists, writeFile } from 'fs-extra'; class Command extends BaseCommand { @@ -37,21 +37,12 @@ class Command extends BaseCommand { ]; } - static async lockFile(filePath: string): Promise { + private static async lockFile(filePath: string) { return locker.lock(filePath, { stale: 1000 * 60 * 5 }); } - static isLocked(filePath: string) { - return new Promise((resolve, reject) => { - locker.check(filePath, (error: any, isLocked: boolean) => { - if (error) { - reject(error); - return; - } - - resolve(isLocked); - }); - }); + private static async isLocked(filePath: string) { + return locker.check(filePath); } async doAuth() { @@ -114,7 +105,7 @@ class Command extends BaseCommand { // Lock is unique per profile/database const lockFilePath = `${require('os').tmpdir()}/synclock_${md5(escape(Setting.value('profileDir')))}`; // https://github.com/pvorb/node-md5/issues/41 - if (!(await fs.pathExists(lockFilePath))) await fs.writeFile(lockFilePath, 'synclock'); + if (!(await pathExists(lockFilePath))) await writeFile(lockFilePath, 'synclock'); const useLock = args.options.useLock !== 0; diff --git a/packages/app-cli/package.json b/packages/app-cli/package.json index 7afae85023..4db74d2517 100644 --- a/packages/app-cli/package.json +++ b/packages/app-cli/package.json @@ -72,6 +72,7 @@ "@types/fs-extra": "9.0.13", "@types/jest": "29.2.6", "@types/node": "18.11.18", + "@types/proper-lockfile": "^4.1.2", "gulp": "4.0.2", "jest": "29.4.3", "temp": "0.9.4", diff --git a/yarn.lock b/yarn.lock index d91b570fb2..c63467a419 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7727,6 +7727,15 @@ __metadata: languageName: node linkType: hard +"@types/proper-lockfile@npm:^4.1.2": + version: 4.1.2 + resolution: "@types/proper-lockfile@npm:4.1.2" + dependencies: + "@types/retry": "*" + checksum: 9d8a100f96e6df3ce1213eea2696b86de4b75dce3ab5bbc1767226732976bf38d2d2ce1060d6942e76561e8617576547e83bb172e95375192a0b8df1fbca2331 + languageName: node + linkType: hard + "@types/qs@npm:*": version: 6.9.7 resolution: "@types/qs@npm:6.9.7" @@ -7854,6 +7863,13 @@ __metadata: languageName: node linkType: hard +"@types/retry@npm:*": + version: 0.12.2 + resolution: "@types/retry@npm:0.12.2" + checksum: e5675035717b39ce4f42f339657cae9637cf0c0051cf54314a6a2c44d38d91f6544be9ddc0280587789b6afd056be5d99dbe3e9f4df68c286c36321579b1bf4a + languageName: node + linkType: hard + "@types/scheduler@npm:*": version: 0.16.2 resolution: "@types/scheduler@npm:0.16.2" @@ -20213,6 +20229,7 @@ __metadata: "@types/fs-extra": 9.0.13 "@types/jest": 29.2.6 "@types/node": 18.11.18 + "@types/proper-lockfile": ^4.1.2 aws-sdk: 2.1290.0 chalk: 4.1.2 compare-version: 0.1.2