Skip to content

Build your personal knowledge base with Trilium Notes

chore(deps): remove fs-extra

Elian Doran22650e0681cb
diff --git a/apps/build-docs/package.json b/apps/build-docs/package.json
index 029ace4cd9..db0eb5b1c0 100644
--- a/apps/build-docs/package.json
+++ b/apps/build-docs/package.json
@@ -22,7 +22,6 @@
"devDependencies": {
"@redocly/cli": "2.30.4",
"archiver": "7.0.1",
- "fs-extra": "11.3.4",
"js-yaml": "4.1.1",
"typedoc": "0.28.19",
"typedoc-plugin-missing-exports": "4.1.3"
diff --git a/apps/build-docs/src/build-docs.ts b/apps/build-docs/src/build-docs.ts
index 7e415e025e..a1d9f750fb 100644
--- a/apps/build-docs/src/build-docs.ts
+++ b/apps/build-docs/src/build-docs.ts
@@ -44,9 +44,8 @@ const stubImageProvider: ImageProvider = {
};
import archiver from "archiver";
import { execSync } from "child_process";
-import { readFileSync } from "fs";
+import { createWriteStream, readFileSync } from "fs";
import * as fs from "fs/promises";
-import * as fsExtra from "fs-extra";
import yaml from "js-yaml";
import { dirname, join, resolve } from "path";
@@ -145,9 +144,7 @@ async function exportDocs(
const ignoredSet = ignoredFiles ? new Set(ignoredFiles) : undefined;
await extractZip(zipFilePath, outputPath, ignoredSet);
} finally {
- if (await fsExtra.exists(zipFilePath)) {
- await fsExtra.rm(zipFilePath);
- }
+ await fs.rm(zipFilePath, { force: true });
}
}
@@ -162,7 +159,7 @@ async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
const { waitForStreamToFinish } = await import("@triliumnext/server/src/services/utils.js");
const branch = note.getParentBranches()[0];
const taskContext = new TaskContext("no-progress-reporting", "export", null);
- const fileOutputStream = fsExtra.createWriteStream(zipFilePath);
+ const fileOutputStream = createWriteStream(zipFilePath);
await zipExportService.exportToZip(taskContext, branch, "share", fileOutputStream);
await waitForStreamToFinish(fileOutputStream);
@@ -170,9 +167,7 @@ async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
const outputPath = outputSubDir ? join(OUTPUT_DIR, outputSubDir) : OUTPUT_DIR;
await extractZip(zipFilePath, outputPath);
} finally {
- if (await fsExtra.exists(zipFilePath)) {
- await fsExtra.rm(zipFilePath);
- }
+ await fs.rm(zipFilePath, { force: true });
}
}
@@ -253,16 +248,16 @@ async function createImportZip(path: string) {
console.log("Archive path is ", resolve(path));
archive.directory(path, "/");
- const outputStream = fsExtra.createWriteStream(inputFile);
+ const outputStream = createWriteStream(inputFile);
archive.pipe(outputStream);
archive.finalize();
const { waitForStreamToFinish } = await import("@triliumnext/server/src/services/utils.js");
await waitForStreamToFinish(outputStream);
try {
- return await fsExtra.readFile(inputFile);
+ return await fs.readFile(inputFile);
} finally {
- await fsExtra.rm(inputFile);
+ await fs.rm(inputFile);
}
}
@@ -279,7 +274,7 @@ export async function extractZip(
const destPath = join(outputPath, entry.fileName);
const fileContent = await readContent();
- await fsExtra.mkdirs(dirname(destPath));
+ await fs.mkdir(dirname(destPath), { recursive: true });
await fs.writeFile(destPath, fileContent);
}
});
diff --git a/apps/desktop/electron-forge/forge.config.ts b/apps/desktop/electron-forge/forge.config.ts
index 43950d0b0f..d69c2ad586 100644
--- a/apps/desktop/electron-forge/forge.config.ts
+++ b/apps/desktop/electron-forge/forge.config.ts
@@ -1,8 +1,7 @@
import type { ForgeConfig } from "@electron-forge/shared-types";
import { FuseV1Options, FuseVersion } from "@electron/fuses";
import { LOCALES } from "@triliumnext/commons";
-import { existsSync } from "fs";
-import fs from "fs-extra";
+import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync } from "fs";
import path, { join } from "path";
import packageJson from "../package.json" with { type: "json" };
@@ -56,18 +55,21 @@ const config: ForgeConfig = {
(buildPath, _electronVersion, platform, _arch, callback) => {
// Only move resources on non-macOS platforms
if (platform !== "darwin") {
- for (const resource of extraResourcesForPlatform) {
- const baseName = path.basename(resource);
- const sourcePath = path.join(buildPath, "resources", baseName);
-
- // prettier-ignore
- const destPath = (baseName !== "256x256.png")
- ? path.join(buildPath, baseName)
- : path.join(buildPath, "icon.png");
-
- fs.move(sourcePath, destPath)
- .then(() => callback())
- .catch((err) => callback(err));
+ try {
+ for (const resource of extraResourcesForPlatform) {
+ const baseName = path.basename(resource);
+ const sourcePath = path.join(buildPath, "resources", baseName);
+
+ // prettier-ignore
+ const destPath = (baseName !== "256x256.png")
+ ? path.join(buildPath, baseName)
+ : path.join(buildPath, "icon.png");
+
+ renameSync(sourcePath, destPath);
+ }
+ callback();
+ } catch (err) {
+ callback(err as Error);
}
} else {
callback();
@@ -206,12 +208,12 @@ const config: ForgeConfig = {
: [ path.join(outputPath, 'locales') ];
for (const localeDir of localeDirs) {
- if (!fs.existsSync(localeDir)) {
+ if (!existsSync(localeDir)) {
console.log(`No locales directory found in '${localeDir}'.`);
process.exit(2);
}
- const files = fs.readdirSync(localeDir);
+ const files = readdirSync(localeDir);
for (const file of files) {
if (!file.endsWith(extension)) {
@@ -232,9 +234,9 @@ const config: ForgeConfig = {
const filePath = path.join(localeDir, file);
if (isMac) {
- fs.rm(filePath, { recursive: true });
+ rmSync(filePath, { recursive: true });
} else {
- fs.unlinkSync(filePath);
+ unlinkSync(filePath);
}
removedLocales.push(file);
@@ -269,7 +271,7 @@ const config: ForgeConfig = {
// Gather all the artifacts produced by the makers and copy them to a common upload directory.
async postMake(_, makeResults) {
const outputDir = path.join(__dirname, "..", "upload");
- fs.mkdirpSync(outputDir);
+ mkdirSync(outputDir, { recursive: true });
for (const makeResult of makeResults) {
for (const artifactPath of makeResult.artifacts) {
// Ignore certain artifacts.
@@ -287,7 +289,7 @@ const config: ForgeConfig = {
const outputPath = path.join(outputDir, fileName);
console.log(`[Artifact] ${artifactPath} -> ${outputPath}`);
- fs.copyFileSync(artifactPath, outputPath);
+ copyFileSync(artifactPath, outputPath);
}
}
}
@@ -318,7 +320,7 @@ function getExtraResourcesForPlatform() {
}
function getELFArch(file: string) {
- const buf = fs.readFileSync(file);
+ const buf = readFileSync(file);
if (buf[0] !== 0x7f || buf[1] !== 0x45 || buf[2] !== 0x4c || buf[3] !== 0x46) {
throw new Error("Not an ELF file");
diff --git a/apps/edit-docs/package.json b/apps/edit-docs/package.json
index 7e30aebaaa..6b104f25a7 100644
--- a/apps/edit-docs/package.json
+++ b/apps/edit-docs/package.json
@@ -11,10 +11,8 @@
"@triliumnext/client": "workspace:*",
"@triliumnext/core": "workspace:*",
"@triliumnext/desktop": "workspace:*",
- "@types/fs-extra": "11.0.4",
"copy-webpack-plugin": "14.0.0",
- "electron": "41.3.0",
- "fs-extra": "11.3.4"
+ "electron": "41.3.0"
},
"scripts": {
"build": "tsx scripts/build.ts",
diff --git a/apps/edit-docs/src/edit-docs.ts b/apps/edit-docs/src/edit-docs.ts
index 2c7f9cdf45..a5aa00a355 100644
--- a/apps/edit-docs/src/edit-docs.ts
+++ b/apps/edit-docs/src/edit-docs.ts
@@ -5,7 +5,6 @@ import cls from "@triliumnext/server/src/services/cls.js";
import type { NoteMetaFile } from "@triliumnext/server/src/services/meta/note_meta.js";
import type NoteMeta from "@triliumnext/server/src/services/meta/note_meta.js";
import fs from "fs/promises";
-import fsExtra from "fs-extra";
import yaml from "js-yaml";
import path from "path";
@@ -154,8 +153,8 @@ async function exportData(noteId: string, format: ExportFormat, outputPath: stri
const zipFilePath = "output.zip";
try {
- await fsExtra.remove(outputPath);
- await fsExtra.mkdir(outputPath);
+ await fs.rm(outputPath, { recursive: true, force: true });
+ await fs.mkdir(outputPath, { recursive: true });
// First export as zip.
const { zipExportService } = (await import("@triliumnext/core"));
@@ -213,9 +212,7 @@ async function exportData(noteId: string, format: ExportFormat, outputPath: stri
await zipExportService.exportToZipFile(noteId, format, zipFilePath, exportOpts);
await extractZip(zipFilePath, outputPath, ignoredFiles);
} finally {
- if (await fsExtra.exists(zipFilePath)) {
- await fsExtra.rm(zipFilePath);
- }
+ await fs.rm(zipFilePath, { force: true });
}
const minifyMeta = (format === "html" || format === "share");
diff --git a/apps/edit-docs/src/utils.ts b/apps/edit-docs/src/utils.ts
index 1b5aa4c85b..ef20dfbf3c 100644
--- a/apps/edit-docs/src/utils.ts
+++ b/apps/edit-docs/src/utils.ts
@@ -2,9 +2,8 @@ import cls from "@triliumnext/server/src/services/cls.js";
import windowService from "@triliumnext/server/src/services/window.js";
import archiver, { type Archiver } from "archiver";
import electron from "electron";
-import type { WriteStream } from "fs";
+import { createWriteStream, type WriteStream } from "fs";
import fs from "fs/promises";
-import fsExtra from "fs-extra";
import path from "path";
import { deferred, type DeferredPromise } from "../../../packages/commons/src/index.js";
@@ -81,14 +80,14 @@ async function createImportZip(path: string) {
archive.directory(path, "/");
- const outputStream = fsExtra.createWriteStream(inputFile);
+ const outputStream = createWriteStream(inputFile);
archive.pipe(outputStream);
await waitForEnd(archive, outputStream);
try {
- return await fsExtra.readFile(inputFile);
+ return await fs.readFile(inputFile);
} finally {
- await fsExtra.rm(inputFile);
+ await fs.rm(inputFile);
}
}
@@ -103,7 +102,7 @@ function waitForEnd(archive: Archiver, stream: WriteStream) {
export async function createZipFromDirectory(dirPath: string, zipPath: string) {
const archive = archiver("zip", { zlib: { level: 5 } });
- const outputStream = fsExtra.createWriteStream(zipPath);
+ const outputStream = createWriteStream(zipPath);
archive.directory(dirPath, false);
archive.pipe(outputStream);
await waitForEnd(archive, outputStream);
@@ -121,7 +120,7 @@ export async function extractZip(zipFilePath: string, outputPath: string, ignore
const destPath = path.join(outputPath, entry.fileName);
const fileContent = await readContent();
- await fsExtra.mkdirs(path.dirname(destPath));
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
await fs.writeFile(destPath, fileContent);
}
});
diff --git a/apps/server/package.json b/apps/server/package.json
index 4d8318358d..4e07c98144 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -38,8 +38,8 @@
"ai": "6.0.184",
"better-sqlite3": "12.9.0",
"html-to-text": "9.0.5",
- "i18next-fs-backend": "2.6.4",
"i18next": "26.0.8",
+ "i18next-fs-backend": "2.6.4",
"js-yaml": "4.1.1",
"unpdf": "1.6.0"
},
@@ -59,7 +59,6 @@
"@types/ejs": "3.1.5",
"@types/express-http-proxy": "1.6.7",
"@types/express-session": "1.19.0",
- "@types/fs-extra": "11.0.4",
"@types/html": "1.0.4",
"@types/ini": "4.1.1",
"@types/js-yaml": "4.0.9",
@@ -91,7 +90,6 @@
"express-rate-limit": "8.4.1",
"express-session": "1.19.0",
"file-uri-to-path": "2.0.0",
- "fs-extra": "11.3.4",
"helmet": "8.1.0",
"html": "1.0.0",
"html2plaintext": "2.1.4",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7fb838f206..1ca3b2d981 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -190,9 +190,6 @@ importers:
archiver:
specifier: 7.0.1
version: 7.0.1
- fs-extra:
- specifier: 11.3.4
- version: 11.3.4
js-yaml:
specifier: 4.1.1
version: 4.1.1
@@ -554,18 +551,12 @@ importers:
'@triliumnext/desktop':
specifier: workspace:*
version: link:../desktop
- '@types/fs-extra':
- specifier: 11.0.4
- version: 11.0.4
copy-webpack-plugin:
specifier: 14.0.0
electron:
specifier: 41.3.0
version: 41.3.0
- fs-extra:
- specifier: 11.3.4
- version: 11.3.4
apps/icon-pack-builder:
devDependencies:
@@ -675,9 +666,6 @@ importers:
'@types/express-session':
specifier: 1.19.0
version: 1.19.0
- '@types/fs-extra':
- specifier: 11.0.4
- version: 11.0.4
'@types/html':
specifier: 1.0.4
version: 1.0.4
@@ -771,9 +759,6 @@ importers:
file-uri-to-path:
specifier: 2.0.0
version: 2.0.0
- fs-extra:
- specifier: 11.3.4
- version: 11.3.4
helmet:
specifier: 8.1.0
version: 8.1.0
@@ -5764,9 +5749,6 @@ packages:
resolution: {integrity: sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==}
- '@types/[email protected]':
- resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==}
-
resolution: {integrity: sha512-0dzKcwO+S8s2kuF5Z9oUWatQJj5Uq/iqphEtE3GQJVRRYm/tD1LglU2UnXi2A8jLq5umkGouOXOR9y0n613ZwQ==}
@@ -5806,9 +5788,6 @@ packages:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
- '@types/[email protected]':
- resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==}
-
resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==}
@@ -19533,11 +19512,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]':
- dependencies:
- '@types/jsonfile': 6.1.4
- '@types/node': 22.15.21
-
dependencies:
'@types/node': 24.12.4
@@ -19573,10 +19547,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]':
- dependencies:
- '@types/node': 24.12.4
-
dependencies:
'@types/node': 24.12.4
diff --git a/scripts/build-utils.ts b/scripts/build-utils.ts
index 2e7a9a82d8..86b5589050 100644
--- a/scripts/build-utils.ts
+++ b/scripts/build-utils.ts
@@ -1,7 +1,6 @@
import { execSync } from "child_process";
import { build as esbuild } from "esbuild";
-import { cpSync, existsSync, rmSync, writeFileSync } from "fs";
-import { copySync, emptyDirSync, mkdirpSync } from "fs-extra";
+import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
import { delimiter, join } from "path";
export default class BuildHelper {
@@ -15,7 +14,8 @@ export default class BuildHelper {
this.projectDir = join(this.rootDir, projectPath);
this.outDir = join(this.projectDir, "dist");
- emptyDirSync(this.outDir);
+ rmSync(this.outDir, { recursive: true, force: true });
+ mkdirSync(this.outDir, { recursive: true });
}
copy(projectDirPath: string, outDirPath: string) {
@@ -27,9 +27,9 @@ export default class BuildHelper {
}
if (outDirPath.endsWith("/")) {
- mkdirpSync(join(outDirPath));
+ mkdirSync(join(this.outDir, outDirPath), { recursive: true });
}
- copySync(sourcePath, join(this.outDir, outDirPath), { dereference: true });
+ cpSync(sourcePath, join(this.outDir, outDirPath), { recursive: true, dereference: true });
}
deleteFromOutput(path: string) {
@@ -105,7 +105,7 @@ export default class BuildHelper {
triggerBuildAndCopyTo(projectToBuild: string, destPath: string) {
const projectDir = join(this.rootDir, projectToBuild);
execSync("pnpm build", { cwd: projectDir, stdio: "inherit" });
- copySync(join(projectDir, "dist"), join(this.projectDir, "dist", destPath));
+ cpSync(join(projectDir, "dist"), join(this.projectDir, "dist", destPath), { recursive: true });
}
copyNodeModules(nodeModules: string[]) {
@@ -116,7 +116,7 @@ export default class BuildHelper {
]);
const destDir = join(this.outDir, "node_modules", moduleName);
- mkdirpSync(destDir);
+ mkdirSync(destDir, { recursive: true });
cpSync(sourceDir, destDir, { recursive: true, dereference: true });
}
}
@@ -125,7 +125,7 @@ export default class BuildHelper {
const fullPath = join(this.outDir, relativePath);
const dirPath = fullPath.substring(0, fullPath.lastIndexOf("/"));
if (dirPath) {
- mkdirpSync(dirPath);
+ mkdirSync(dirPath, { recursive: true });
}
writeFileSync(fullPath, JSON.stringify(data, null, 4), "utf-8");
}