From c17ea74856cf67a0d4f1e4250ee3f0fc7a7ebfa1 Mon Sep 17 00:00:00 2001 From: Sukka Date: Fri, 20 Sep 2024 02:01:36 +0800 Subject: [PATCH] chore: drop fs-extra (#1739) nb! --- package.json | 2 - pnpm-lock.yaml | 62 ++--------------------------- scripts/check.mjs | 43 ++++++++++---------- scripts/portable-fixed-webview2.mjs | 11 +++-- scripts/portable.mjs | 10 +++-- scripts/updatelog.mjs | 7 ++-- 6 files changed, 42 insertions(+), 93 deletions(-) diff --git a/package.json b/package.json index 8542a9ae..2bb7dc5f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "devDependencies": { "@actions/github": "^5.1.1", "@tauri-apps/cli": "2.0.0-rc.16", - "@types/fs-extra": "^9.0.13", "@types/js-cookie": "^3.0.6", "@types/js-yaml": "^4.0.9", "@types/lodash-es": "^4.17.12", @@ -80,7 +79,6 @@ "@vitejs/plugin-react": "^4.3.1", "adm-zip": "^0.5.14", "cross-env": "^7.0.3", - "fs-extra": "^11.2.0", "https-proxy-agent": "^5.0.1", "husky": "^7.0.4", "node-fetch": "^3.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f988446..d02e5f17 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -155,9 +155,6 @@ importers: "@tauri-apps/cli": specifier: 2.0.0-rc.16 version: 2.0.0-rc.16 - "@types/fs-extra": - specifier: ^9.0.13 - version: 9.0.13 "@types/js-cookie": specifier: ^3.0.6 version: 3.0.6 @@ -188,9 +185,6 @@ importers: cross-env: specifier: ^7.0.3 version: 7.0.3 - fs-extra: - specifier: ^11.2.0 - version: 11.2.0 https-proxy-agent: specifier: ^5.0.1 version: 5.0.1 @@ -2294,12 +2288,6 @@ packages: integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==, } - "@types/fs-extra@9.0.13": - resolution: - { - integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==, - } - "@types/hast@3.0.4": resolution: { @@ -2970,13 +2958,6 @@ packages: react: optional: true - fs-extra@11.2.0: - resolution: - { - integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==, - } - engines: { node: ">=14.14" } - fs-minipass@2.1.0: resolution: { @@ -3026,12 +3007,6 @@ packages: } engines: { node: ">=4" } - graceful-fs@4.2.11: - resolution: - { - integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==, - } - has-flag@3.0.0: resolution: { @@ -3288,12 +3263,6 @@ packages: integrity: sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==, } - jsonfile@6.1.0: - resolution: - { - integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==, - } - lines-and-columns@1.2.4: resolution: { @@ -4457,13 +4426,6 @@ packages: integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==, } - universalify@2.0.1: - resolution: - { - integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==, - } - engines: { node: ">= 10.0.0" } - update-browserslist-db@1.1.0: resolution: { @@ -6138,10 +6100,6 @@ snapshots: "@types/estree@1.0.5": {} - "@types/fs-extra@9.0.13": - dependencies: - "@types/node": 20.14.10 - "@types/hast@3.0.4": dependencies: "@types/unist": 3.0.2 @@ -6167,6 +6125,7 @@ snapshots: "@types/node@20.14.10": dependencies: undici-types: 5.26.5 + optional: true "@types/parse-json@4.0.2": {} @@ -6541,12 +6500,6 @@ snapshots: optionalDependencies: react: 18.3.1 - fs-extra@11.2.0: - dependencies: - graceful-fs: 4.2.11 - jsonfile: 6.1.0 - universalify: 2.0.1 - fs-minipass@2.1.0: dependencies: minipass: 3.3.6 @@ -6568,8 +6521,6 @@ snapshots: globals@11.12.0: {} - graceful-fs@4.2.11: {} - has-flag@3.0.0: {} hasown@2.0.2: @@ -6695,12 +6646,6 @@ snapshots: jsonc-parser@3.3.1: {} - jsonfile@6.1.0: - dependencies: - universalify: 2.0.1 - optionalDependencies: - graceful-fs: 4.2.11 - lines-and-columns@1.2.4: {} locate-path@5.0.0: @@ -7430,7 +7375,8 @@ snapshots: typescript@5.5.3: {} - undici-types@5.26.5: {} + undici-types@5.26.5: + optional: true undici@5.28.4: dependencies: @@ -7487,8 +7433,6 @@ snapshots: universal-user-agent@6.0.1: {} - universalify@2.0.1: {} - update-browserslist-db@1.1.0(browserslist@4.23.1): dependencies: browserslist: 4.23.1 diff --git a/scripts/check.mjs b/scripts/check.mjs index 19e2ac64..bf22a2f0 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -1,4 +1,5 @@ -import fs from "fs-extra"; +import fs from "fs"; +import fsp from "fs/promises"; import zlib from "zlib"; import tar from "tar"; import path from "path"; @@ -205,16 +206,16 @@ async function resolveSidecar(binInfo) { const sidecarDir = path.join(cwd, "src-tauri", "sidecar"); const sidecarPath = path.join(sidecarDir, targetFile); - await fs.mkdirp(sidecarDir); - if (!FORCE && (await fs.pathExists(sidecarPath))) return; + await fsp.mkdir(sidecarDir, { recursive: true }); + if (!FORCE && fs.existsSync(sidecarPath)) return; const tempDir = path.join(TEMP_DIR, name); const tempZip = path.join(tempDir, zipFile); const tempExe = path.join(tempDir, exeFile); - await fs.mkdirp(tempDir); + await fsp.mkdir(tempDir, { recursive: true }); try { - if (!(await fs.pathExists(tempZip))) { + if (!fs.existsSync(tempZip)) { await downloadFile(downloadURL, tempZip); } @@ -224,22 +225,22 @@ async function resolveSidecar(binInfo) { console.log(`[DEBUG]: "${name}" entry name`, entry.entryName); }); zip.extractAllTo(tempDir, true); - await fs.rename(tempExe, sidecarPath); + await fsp.rename(tempExe, sidecarPath); console.log(`[INFO]: "${name}" unzip finished`); } else if (zipFile.endsWith(".tgz")) { // tgz - await fs.mkdirp(tempDir); + await fsp.mkdir(tempDir, { recursive: true }); await tar.extract({ cwd: tempDir, file: tempZip, //strip: 1, // 可能需要根据实际的 .tgz 文件结构调整 }); - const files = await fs.readdir(tempDir); + const files = await fsp.readdir(tempDir); console.log(`[DEBUG]: "${name}" files in tempDir:`, files); const extractedFile = files.find((file) => file.startsWith("虚空终端-")); if (extractedFile) { const extractedFilePath = path.join(tempDir, extractedFile); - await fs.rename(extractedFilePath, sidecarPath); + await fsp.rename(extractedFilePath, sidecarPath); console.log(`[INFO]: "${name}" file renamed to "${sidecarPath}"`); execSync(`chmod 755 ${sidecarPath}`); console.log(`[INFO]: "${name}" chmod binary finished`); @@ -269,11 +270,11 @@ async function resolveSidecar(binInfo) { } } catch (err) { // 需要删除文件 - await fs.remove(sidecarPath); + await fsp.rm(sidecarPath, { recursive: true, force: true }); throw err; } finally { // delete temp dir - await fs.remove(tempDir); + await fsp.rm(tempDir, { recursive: true, force: true }); } } @@ -286,9 +287,9 @@ async function resolveResource(binInfo) { const resDir = path.join(cwd, "src-tauri/resources"); const targetPath = path.join(resDir, file); - if (!FORCE && (await fs.pathExists(targetPath))) return; + if (!FORCE && fs.existsSync(targetPath)) return; - await fs.mkdirp(resDir); + await fsp.mkdir(resDir, { recursive: true }); await downloadFile(downloadURL, targetPath); console.log(`[INFO]: ${file} finished`); @@ -316,7 +317,7 @@ async function downloadFile(url, path) { headers: { "Content-Type": "application/octet-stream" }, }); const buffer = await response.arrayBuffer(); - await fs.writeFile(path, new Uint8Array(buffer)); + await fsp.writeFile(path, new Uint8Array(buffer)); console.log(`[INFO]: download finished "${url}"`); } @@ -334,11 +335,11 @@ const resolvePlugin = async () => { const tempDll = path.join(tempDir, "SimpleSC.dll"); const pluginDir = path.join(process.env.APPDATA, "Local/NSIS"); const pluginPath = path.join(pluginDir, "SimpleSC.dll"); - await fs.mkdirp(pluginDir); - await fs.mkdirp(tempDir); - if (!FORCE && (await fs.pathExists(pluginPath))) return; + await fsp.mkdir(pluginDir, { recursive: true }); + await fsp.mkdir(tempDir, { recursive: true }); + if (!FORCE && fs.existsSync(pluginPath)) return; try { - if (!(await fs.pathExists(tempZip))) { + if (!fs.existsSync(tempZip)) { await downloadFile(url, tempZip); } const zip = new AdmZip(tempZip); @@ -346,10 +347,10 @@ const resolvePlugin = async () => { console.log(`[DEBUG]: "SimpleSC" entry name`, entry.entryName); }); zip.extractAllTo(tempDir, true); - await fs.copyFile(tempDll, pluginPath); + await fsp.cp(tempDll, pluginPath, { recursive: true, force: true }); console.log(`[INFO]: "SimpleSC" unzip finished`); } finally { - await fs.remove(tempDir); + await fsp.rm(tempDir, { recursive: true, force: true }); } }; @@ -363,7 +364,7 @@ const resolveServicePermission = async () => { const resDir = path.join(cwd, "src-tauri/resources"); for (let f of serviceExecutables) { const targetPath = path.join(resDir, f); - if (await fs.pathExists(targetPath)) { + if (fs.existsSync(targetPath)) { execSync(`chmod 755 ${targetPath}`); console.log(`[INFO]: "${targetPath}" chmod finished`); } diff --git a/scripts/portable-fixed-webview2.mjs b/scripts/portable-fixed-webview2.mjs index 94285ce7..696c21ea 100644 --- a/scripts/portable-fixed-webview2.mjs +++ b/scripts/portable-fixed-webview2.mjs @@ -1,4 +1,5 @@ -import fs from "fs-extra"; +import fs from "fs"; +import fsp from "fs/promises"; import path from "path"; import AdmZip from "adm-zip"; import { createRequire } from "module"; @@ -30,12 +31,14 @@ async function resolvePortable() { const configDir = path.join(releaseDir, ".config"); - if (!(await fs.pathExists(releaseDir))) { + if (!fs.existsSync(releaseDir)) { throw new Error("could not found the release dir"); } - await fs.mkdir(configDir); - await fs.createFile(path.join(configDir, "PORTABLE")); + await fsp.mkdir(configDir, { recursive: true }); + if (!fs.existsSync(path.join(configDir, "PORTABLE"))) { + await fsp.writeFile(path.join(configDir, "PORTABLE"), ""); + } const zip = new AdmZip(); diff --git a/scripts/portable.mjs b/scripts/portable.mjs index 1a9d1258..97a00d4a 100644 --- a/scripts/portable.mjs +++ b/scripts/portable.mjs @@ -1,4 +1,4 @@ -import fs from "fs-extra"; +import fs from "fs"; import path from "path"; import AdmZip from "adm-zip"; import { createRequire } from "module"; @@ -29,12 +29,14 @@ async function resolvePortable() { : `./src-tauri/target/release`; const configDir = path.join(releaseDir, ".config"); - if (!(await fs.pathExists(releaseDir))) { + if (!fs.existsSync(releaseDir)) { throw new Error("could not found the release dir"); } - await fs.mkdir(configDir); - await fs.createFile(path.join(configDir, "PORTABLE")); + await fsp.mkdir(configDir, { recursive: true }); + if (!fs.existsSync(path.join(configDir, "PORTABLE"))) { + await fsp.writeFile(path.join(configDir, "PORTABLE"), ""); + } const zip = new AdmZip(); diff --git a/scripts/updatelog.mjs b/scripts/updatelog.mjs index fae7f628..914098cb 100644 --- a/scripts/updatelog.mjs +++ b/scripts/updatelog.mjs @@ -1,4 +1,5 @@ -import fs from "fs-extra"; +import fs from "fs"; +import fsp from "fs/promises"; import path from "path"; const UPDATE_LOG = "UPDATELOG.md"; @@ -12,11 +13,11 @@ export async function resolveUpdateLog(tag) { const file = path.join(cwd, UPDATE_LOG); - if (!(await fs.pathExists(file))) { + if (!fs.existsSync(file)) { throw new Error("could not found UPDATELOG.md"); } - const data = await fs.readFile(file).then((d) => d.toString("utf8")); + const data = await fsp.readFile(file, "utf-8"); const map = {}; let p = "";