Replace mkdirp with native fs.mkdir

Prior to this change, Signal-Desktop was using a rather ancient version
of `mkdirp`, which was meant for Node.js versions without native support
for this kind of functionality. Starting with Node v10, `fs.mkdir()` can
perform recursive directory creation.

Since Signal-Desktop doesn't utilize any advantages of using such an old
version of `mkdirp` [1] (let alone any version of `mkdirp`), we can
replace it with the native methods of `fs` (or `fs/promises`).

This transition slightly reduces the amount of packages needed to be
downloaded and included in the final app since it now relies on the
built-in API of Node.js.
This commit is contained in:
Nikita Karamov 2021-11-29 13:05:51 +01:00 committed by Jamie Kyle
parent 16c9c17cc2
commit 7cd566726f
6 changed files with 16 additions and 53 deletions

View file

@ -7,12 +7,17 @@
import { join } from 'path';
import split2 from 'split2';
import { readdirSync, createReadStream, unlinkSync, writeFileSync } from 'fs';
import {
mkdirSync,
readdirSync,
createReadStream,
unlinkSync,
writeFileSync,
} from 'fs';
import type { BrowserWindow } from 'electron';
import { app, ipcMain as ipc } from 'electron';
import pino from 'pino';
import type { StreamEntry } from 'pino';
import * as mkdirp from 'mkdirp';
import { filter, flatten, map, pick, sortBy } from 'lodash';
import readFirstLine from 'firstline';
import { read as readLastLines } from 'read-last-lines';
@ -56,7 +61,7 @@ export async function initialize(
const basePath = app.getPath('userData');
const logPath = join(basePath, 'logs');
mkdirp.sync(logPath);
mkdirSync(logPath, { recursive: true });
let appMetrics = app.getAppMetrics();
@ -73,7 +78,7 @@ export async function initialize(
`Error: ${Errors.toLogFormat(error)}`;
console.error(errorString);
await deleteAllLogs(logPath);
mkdirp.sync(logPath);
mkdirSync(logPath, { recursive: true });
// If we want this log entry to persist on disk, we need to wait until we've
// set up our logging infrastructure.
@ -204,7 +209,7 @@ async function cleanupLogs(logPath: string) {
// delete and re-create the log directory
await deleteAllLogs(logPath);
mkdirp.sync(logPath);
mkdirSync(logPath, { recursive: true });
}
}