chore: drop fs-extra (#1739)

nb!
This commit is contained in:
Sukka 2024-09-20 02:01:36 +08:00 committed by GitHub
parent 74777df344
commit eefeec7f0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 42 additions and 93 deletions

View File

@ -69,7 +69,6 @@
"devDependencies": { "devDependencies": {
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@tauri-apps/cli": "2.0.0-rc.16", "@tauri-apps/cli": "2.0.0-rc.16",
"@types/fs-extra": "^9.0.13",
"@types/js-cookie": "^3.0.6", "@types/js-cookie": "^3.0.6",
"@types/js-yaml": "^4.0.9", "@types/js-yaml": "^4.0.9",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
@ -80,7 +79,6 @@
"@vitejs/plugin-react": "^4.3.1", "@vitejs/plugin-react": "^4.3.1",
"adm-zip": "^0.5.14", "adm-zip": "^0.5.14",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"fs-extra": "^11.2.0",
"https-proxy-agent": "^5.0.1", "https-proxy-agent": "^5.0.1",
"husky": "^7.0.4", "husky": "^7.0.4",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",

62
pnpm-lock.yaml generated
View File

@ -155,9 +155,6 @@ importers:
"@tauri-apps/cli": "@tauri-apps/cli":
specifier: 2.0.0-rc.16 specifier: 2.0.0-rc.16
version: 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": "@types/js-cookie":
specifier: ^3.0.6 specifier: ^3.0.6
version: 3.0.6 version: 3.0.6
@ -188,9 +185,6 @@ importers:
cross-env: cross-env:
specifier: ^7.0.3 specifier: ^7.0.3
version: 7.0.3 version: 7.0.3
fs-extra:
specifier: ^11.2.0
version: 11.2.0
https-proxy-agent: https-proxy-agent:
specifier: ^5.0.1 specifier: ^5.0.1
version: 5.0.1 version: 5.0.1
@ -2294,12 +2288,6 @@ packages:
integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==, 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": "@types/hast@3.0.4":
resolution: resolution:
{ {
@ -2970,13 +2958,6 @@ packages:
react: react:
optional: true optional: true
fs-extra@11.2.0:
resolution:
{
integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==,
}
engines: { node: ">=14.14" }
fs-minipass@2.1.0: fs-minipass@2.1.0:
resolution: resolution:
{ {
@ -3026,12 +3007,6 @@ packages:
} }
engines: { node: ">=4" } 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: has-flag@3.0.0:
resolution: resolution:
{ {
@ -3288,12 +3263,6 @@ packages:
integrity: sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==, integrity: sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==,
} }
jsonfile@6.1.0:
resolution:
{
integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==,
}
lines-and-columns@1.2.4: lines-and-columns@1.2.4:
resolution: resolution:
{ {
@ -4457,13 +4426,6 @@ packages:
integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==, 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: update-browserslist-db@1.1.0:
resolution: resolution:
{ {
@ -6138,10 +6100,6 @@ snapshots:
"@types/estree@1.0.5": {} "@types/estree@1.0.5": {}
"@types/fs-extra@9.0.13":
dependencies:
"@types/node": 20.14.10
"@types/hast@3.0.4": "@types/hast@3.0.4":
dependencies: dependencies:
"@types/unist": 3.0.2 "@types/unist": 3.0.2
@ -6167,6 +6125,7 @@ snapshots:
"@types/node@20.14.10": "@types/node@20.14.10":
dependencies: dependencies:
undici-types: 5.26.5 undici-types: 5.26.5
optional: true
"@types/parse-json@4.0.2": {} "@types/parse-json@4.0.2": {}
@ -6541,12 +6500,6 @@ snapshots:
optionalDependencies: optionalDependencies:
react: 18.3.1 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: fs-minipass@2.1.0:
dependencies: dependencies:
minipass: 3.3.6 minipass: 3.3.6
@ -6568,8 +6521,6 @@ snapshots:
globals@11.12.0: {} globals@11.12.0: {}
graceful-fs@4.2.11: {}
has-flag@3.0.0: {} has-flag@3.0.0: {}
hasown@2.0.2: hasown@2.0.2:
@ -6695,12 +6646,6 @@ snapshots:
jsonc-parser@3.3.1: {} 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: {} lines-and-columns@1.2.4: {}
locate-path@5.0.0: locate-path@5.0.0:
@ -7430,7 +7375,8 @@ snapshots:
typescript@5.5.3: {} typescript@5.5.3: {}
undici-types@5.26.5: {} undici-types@5.26.5:
optional: true
undici@5.28.4: undici@5.28.4:
dependencies: dependencies:
@ -7487,8 +7433,6 @@ snapshots:
universal-user-agent@6.0.1: {} universal-user-agent@6.0.1: {}
universalify@2.0.1: {}
update-browserslist-db@1.1.0(browserslist@4.23.1): update-browserslist-db@1.1.0(browserslist@4.23.1):
dependencies: dependencies:
browserslist: 4.23.1 browserslist: 4.23.1

View File

@ -1,4 +1,5 @@
import fs from "fs-extra"; import fs from "fs";
import fsp from "fs/promises";
import zlib from "zlib"; import zlib from "zlib";
import tar from "tar"; import tar from "tar";
import path from "path"; import path from "path";
@ -205,16 +206,16 @@ async function resolveSidecar(binInfo) {
const sidecarDir = path.join(cwd, "src-tauri", "sidecar"); const sidecarDir = path.join(cwd, "src-tauri", "sidecar");
const sidecarPath = path.join(sidecarDir, targetFile); const sidecarPath = path.join(sidecarDir, targetFile);
await fs.mkdirp(sidecarDir); await fsp.mkdir(sidecarDir, { recursive: true });
if (!FORCE && (await fs.pathExists(sidecarPath))) return; if (!FORCE && fs.existsSync(sidecarPath)) return;
const tempDir = path.join(TEMP_DIR, name); const tempDir = path.join(TEMP_DIR, name);
const tempZip = path.join(tempDir, zipFile); const tempZip = path.join(tempDir, zipFile);
const tempExe = path.join(tempDir, exeFile); const tempExe = path.join(tempDir, exeFile);
await fs.mkdirp(tempDir); await fsp.mkdir(tempDir, { recursive: true });
try { try {
if (!(await fs.pathExists(tempZip))) { if (!fs.existsSync(tempZip)) {
await downloadFile(downloadURL, tempZip); await downloadFile(downloadURL, tempZip);
} }
@ -224,22 +225,22 @@ async function resolveSidecar(binInfo) {
console.log(`[DEBUG]: "${name}" entry name`, entry.entryName); console.log(`[DEBUG]: "${name}" entry name`, entry.entryName);
}); });
zip.extractAllTo(tempDir, true); zip.extractAllTo(tempDir, true);
await fs.rename(tempExe, sidecarPath); await fsp.rename(tempExe, sidecarPath);
console.log(`[INFO]: "${name}" unzip finished`); console.log(`[INFO]: "${name}" unzip finished`);
} else if (zipFile.endsWith(".tgz")) { } else if (zipFile.endsWith(".tgz")) {
// tgz // tgz
await fs.mkdirp(tempDir); await fsp.mkdir(tempDir, { recursive: true });
await tar.extract({ await tar.extract({
cwd: tempDir, cwd: tempDir,
file: tempZip, file: tempZip,
//strip: 1, // 可能需要根据实际的 .tgz 文件结构调整 //strip: 1, // 可能需要根据实际的 .tgz 文件结构调整
}); });
const files = await fs.readdir(tempDir); const files = await fsp.readdir(tempDir);
console.log(`[DEBUG]: "${name}" files in tempDir:`, files); console.log(`[DEBUG]: "${name}" files in tempDir:`, files);
const extractedFile = files.find((file) => file.startsWith("虚空终端-")); const extractedFile = files.find((file) => file.startsWith("虚空终端-"));
if (extractedFile) { if (extractedFile) {
const extractedFilePath = path.join(tempDir, 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}"`); console.log(`[INFO]: "${name}" file renamed to "${sidecarPath}"`);
execSync(`chmod 755 ${sidecarPath}`); execSync(`chmod 755 ${sidecarPath}`);
console.log(`[INFO]: "${name}" chmod binary finished`); console.log(`[INFO]: "${name}" chmod binary finished`);
@ -269,11 +270,11 @@ async function resolveSidecar(binInfo) {
} }
} catch (err) { } catch (err) {
// 需要删除文件 // 需要删除文件
await fs.remove(sidecarPath); await fsp.rm(sidecarPath, { recursive: true, force: true });
throw err; throw err;
} finally { } finally {
// delete temp dir // 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 resDir = path.join(cwd, "src-tauri/resources");
const targetPath = path.join(resDir, file); 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); await downloadFile(downloadURL, targetPath);
console.log(`[INFO]: ${file} finished`); console.log(`[INFO]: ${file} finished`);
@ -316,7 +317,7 @@ async function downloadFile(url, path) {
headers: { "Content-Type": "application/octet-stream" }, headers: { "Content-Type": "application/octet-stream" },
}); });
const buffer = await response.arrayBuffer(); 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}"`); console.log(`[INFO]: download finished "${url}"`);
} }
@ -334,11 +335,11 @@ const resolvePlugin = async () => {
const tempDll = path.join(tempDir, "SimpleSC.dll"); const tempDll = path.join(tempDir, "SimpleSC.dll");
const pluginDir = path.join(process.env.APPDATA, "Local/NSIS"); const pluginDir = path.join(process.env.APPDATA, "Local/NSIS");
const pluginPath = path.join(pluginDir, "SimpleSC.dll"); const pluginPath = path.join(pluginDir, "SimpleSC.dll");
await fs.mkdirp(pluginDir); await fsp.mkdir(pluginDir, { recursive: true });
await fs.mkdirp(tempDir); await fsp.mkdir(tempDir, { recursive: true });
if (!FORCE && (await fs.pathExists(pluginPath))) return; if (!FORCE && fs.existsSync(pluginPath)) return;
try { try {
if (!(await fs.pathExists(tempZip))) { if (!fs.existsSync(tempZip)) {
await downloadFile(url, tempZip); await downloadFile(url, tempZip);
} }
const zip = new AdmZip(tempZip); const zip = new AdmZip(tempZip);
@ -346,10 +347,10 @@ const resolvePlugin = async () => {
console.log(`[DEBUG]: "SimpleSC" entry name`, entry.entryName); console.log(`[DEBUG]: "SimpleSC" entry name`, entry.entryName);
}); });
zip.extractAllTo(tempDir, true); zip.extractAllTo(tempDir, true);
await fs.copyFile(tempDll, pluginPath); await fsp.cp(tempDll, pluginPath, { recursive: true, force: true });
console.log(`[INFO]: "SimpleSC" unzip finished`); console.log(`[INFO]: "SimpleSC" unzip finished`);
} finally { } 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"); const resDir = path.join(cwd, "src-tauri/resources");
for (let f of serviceExecutables) { for (let f of serviceExecutables) {
const targetPath = path.join(resDir, f); const targetPath = path.join(resDir, f);
if (await fs.pathExists(targetPath)) { if (fs.existsSync(targetPath)) {
execSync(`chmod 755 ${targetPath}`); execSync(`chmod 755 ${targetPath}`);
console.log(`[INFO]: "${targetPath}" chmod finished`); console.log(`[INFO]: "${targetPath}" chmod finished`);
} }

View File

@ -1,4 +1,5 @@
import fs from "fs-extra"; import fs from "fs";
import fsp from "fs/promises";
import path from "path"; import path from "path";
import AdmZip from "adm-zip"; import AdmZip from "adm-zip";
import { createRequire } from "module"; import { createRequire } from "module";
@ -30,12 +31,14 @@ async function resolvePortable() {
const configDir = path.join(releaseDir, ".config"); const configDir = path.join(releaseDir, ".config");
if (!(await fs.pathExists(releaseDir))) { if (!fs.existsSync(releaseDir)) {
throw new Error("could not found the release dir"); throw new Error("could not found the release dir");
} }
await fs.mkdir(configDir); await fsp.mkdir(configDir, { recursive: true });
await fs.createFile(path.join(configDir, "PORTABLE")); if (!fs.existsSync(path.join(configDir, "PORTABLE"))) {
await fsp.writeFile(path.join(configDir, "PORTABLE"), "");
}
const zip = new AdmZip(); const zip = new AdmZip();

View File

@ -1,4 +1,4 @@
import fs from "fs-extra"; import fs from "fs";
import path from "path"; import path from "path";
import AdmZip from "adm-zip"; import AdmZip from "adm-zip";
import { createRequire } from "module"; import { createRequire } from "module";
@ -29,12 +29,14 @@ async function resolvePortable() {
: `./src-tauri/target/release`; : `./src-tauri/target/release`;
const configDir = path.join(releaseDir, ".config"); const configDir = path.join(releaseDir, ".config");
if (!(await fs.pathExists(releaseDir))) { if (!fs.existsSync(releaseDir)) {
throw new Error("could not found the release dir"); throw new Error("could not found the release dir");
} }
await fs.mkdir(configDir); await fsp.mkdir(configDir, { recursive: true });
await fs.createFile(path.join(configDir, "PORTABLE")); if (!fs.existsSync(path.join(configDir, "PORTABLE"))) {
await fsp.writeFile(path.join(configDir, "PORTABLE"), "");
}
const zip = new AdmZip(); const zip = new AdmZip();

View File

@ -1,4 +1,5 @@
import fs from "fs-extra"; import fs from "fs";
import fsp from "fs/promises";
import path from "path"; import path from "path";
const UPDATE_LOG = "UPDATELOG.md"; const UPDATE_LOG = "UPDATELOG.md";
@ -12,11 +13,11 @@ export async function resolveUpdateLog(tag) {
const file = path.join(cwd, UPDATE_LOG); const file = path.join(cwd, UPDATE_LOG);
if (!(await fs.pathExists(file))) { if (!fs.existsSync(file)) {
throw new Error("could not found UPDATELOG.md"); 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 = {}; const map = {};
let p = ""; let p = "";