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:
parent
16c9c17cc2
commit
7cd566726f
6 changed files with 16 additions and 53 deletions
|
@ -1693,30 +1693,6 @@ Signal Desktop makes use of the following open source projects.
|
|||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
## mkdirp
|
||||
|
||||
Copyright 2010 James Halliday (mail@substack.net)
|
||||
|
||||
This project is free software released under the MIT/X11 license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
## moment
|
||||
|
||||
Copyright (c) JS Foundation and other contributors
|
||||
|
|
|
@ -129,7 +129,6 @@
|
|||
"lru-cache": "6.0.0",
|
||||
"mac-screen-capture-permissions": "2.0.0",
|
||||
"memoizee": "0.4.14",
|
||||
"mkdirp": "0.5.2",
|
||||
"moment": "2.29.4",
|
||||
"mp4box": "0.5.2",
|
||||
"mustache": "2.3.0",
|
||||
|
@ -229,7 +228,6 @@
|
|||
"@types/long": "4.0.1",
|
||||
"@types/lru-cache": "5.1.0",
|
||||
"@types/memoizee": "0.4.2",
|
||||
"@types/mkdirp": "0.5.2",
|
||||
"@types/mocha": "9.0.0",
|
||||
"@types/mustache": "4.1.2",
|
||||
"@types/node": "16.18.3",
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import { mkdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import { randomBytes } from 'crypto';
|
||||
import type { Database, Statement } from 'better-sqlite3';
|
||||
|
@ -524,7 +524,7 @@ async function initialize({
|
|||
indexedDBPath = join(configDir, 'IndexedDB');
|
||||
|
||||
const dbDir = join(configDir, 'sql');
|
||||
mkdirp.sync(dbDir);
|
||||
mkdirSync(dbDir, { recursive: true });
|
||||
|
||||
databaseFilePath = join(dbDir, 'db.sqlite');
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
/* eslint-disable no-console */
|
||||
import { createWriteStream } from 'fs';
|
||||
import { pathExists } from 'fs-extra';
|
||||
import { readdir, stat, writeFile } from 'fs/promises';
|
||||
import { readdir, stat, writeFile, mkdir } from 'fs/promises';
|
||||
import { promisify } from 'util';
|
||||
import { execFile } from 'child_process';
|
||||
import { join, normalize, extname } from 'path';
|
||||
|
@ -19,7 +19,6 @@ import config from 'config';
|
|||
import got from 'got';
|
||||
import { v4 as getGuid } from 'uuid';
|
||||
import pify from 'pify';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import { app, ipcMain } from 'electron';
|
||||
|
@ -51,7 +50,6 @@ import {
|
|||
isValidPreparedData as isValidDifferentialData,
|
||||
} from './differential';
|
||||
|
||||
const mkdirpPromise = pify(mkdirp);
|
||||
const rimrafPromise = pify(rimraf);
|
||||
|
||||
const INTERVAL = 30 * durations.MINUTE;
|
||||
|
@ -860,7 +858,7 @@ function getBaseTempDir() {
|
|||
export async function createTempDir(): Promise<string> {
|
||||
const targetDir = await getTempDir();
|
||||
|
||||
await mkdirpPromise(targetDir);
|
||||
await mkdir(targetDir, { recursive: true });
|
||||
|
||||
return targetDir;
|
||||
}
|
||||
|
@ -871,7 +869,7 @@ export async function getTempDir(): Promise<string> {
|
|||
|
||||
// Create parent folder if not already present
|
||||
if (!(await pathExists(baseTempDir))) {
|
||||
await mkdirpPromise(baseTempDir);
|
||||
await mkdir(baseTempDir, { recursive: true });
|
||||
}
|
||||
|
||||
return join(baseTempDir, uniqueName);
|
||||
|
@ -884,7 +882,7 @@ function getUpdateCacheDir() {
|
|||
|
||||
export async function createUpdateCacheDirIfNeeded(): Promise<string> {
|
||||
const targetDir = getUpdateCacheDir();
|
||||
await mkdirpPromise(targetDir);
|
||||
await mkdir(targetDir, { recursive: true });
|
||||
|
||||
return targetDir;
|
||||
}
|
||||
|
|
14
yarn.lock
14
yarn.lock
|
@ -3522,13 +3522,6 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
|
||||
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
|
||||
|
||||
"@types/mkdirp@0.5.2":
|
||||
version "0.5.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f"
|
||||
integrity sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/mocha@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
|
||||
|
@ -12478,13 +12471,6 @@ mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3:
|
|||
resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113"
|
||||
integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==
|
||||
|
||||
mkdirp@0.5.2:
|
||||
version "0.5.2"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.2.tgz#2e7138d794dfbd097d74c84c410c3edd9eec479f"
|
||||
integrity sha512-jczt4BrifxW743wRHJ05AnqIF52sDrHCAjTO66cFQStG1/jHMLFSGdAa3Rec21jdEObaPugcXfbh6Ammt2VQsw==
|
||||
dependencies:
|
||||
minimist "^1.2.5"
|
||||
|
||||
mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.5:
|
||||
version "0.5.5"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
|
||||
|
|
Loading…
Reference in a new issue