* build: remove fs-extra dependency from script/gen-filenames.ts

* build: remove fs-extra dependency from script/spec-runner.js

* build: remove fs-extra dependency from script/gn-asar.js

* build: remove fs-extra dependency from spec/api-autoupdater-darwin-spec.ts

* build: remove fs-extra dependency from spec/api-safe-storage-spec.ts

* build: remove fs-extra dependency from spec/lib/codesign-helpers.ts

* build: remove fs-extra dependency from spec/api-app-spec.ts

* build: remove fs-extra dependency from spec/esm-spec.ts

* build: remove fs-extra dependency from spec/lib/fs-helpers.ts

* build: remove fs-extra dependency from spec/lib/api-shell-spec.ts

* build: remove fs-extra dependency from spec/api-context-bridge-spec.ts

* build: remove fs-extra dependency from spec/asar-integrity-spec.ts

* build: remove fs-extra dependency from spec/node-spec.ts

* build: remove fs-extra devdiv

* fixup! build: remove fs-extra dependency from spec/api-context-bridge-spec.ts

* fix: use force: true when removing directories

* chore: reduce diffs to main

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-06-28 12:13:46 -05:00 коммит произвёл GitHub
Родитель 2c3a9fd3c5
Коммит e480e29cfc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
15 изменённых файлов: 55 добавлений и 80 удалений

Просмотреть файл

@ -19,7 +19,6 @@
"@types/chai-as-promised": "^7.1.3",
"@types/dirty-chai": "^2.0.2",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.1",
"@types/minimist": "^1.2.0",
"@types/mocha": "^7.0.2",
"@types/node": "^20.9.0",
@ -50,7 +49,6 @@
"events": "^3.2.0",
"express": "^4.19.2",
"folder-hash": "^2.1.1",
"fs-extra": "^9.0.1",
"got": "^11.8.5",
"husky": "^8.0.1",
"lint": "^1.1.2",

Просмотреть файл

@ -1,5 +1,5 @@
import * as cp from 'node:child_process';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
@ -48,7 +48,7 @@ const main = async () => {
];
const webpackTargetsWithDeps = await Promise.all(webpackTargets.map(async webpackTarget => {
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
const child = cp.spawn('node', [
'./node_modules/webpack-cli/bin/cli.js',
'--config', `./build/webpack/${webpackTarget.config}`,
@ -89,7 +89,7 @@ const main = async () => {
// Make the generated list easier to read
.sort()
};
await fs.remove(tmpDir);
await fs.promises.rm(tmpDir, { force: true, recursive: true });
return webpackTargetWithDeps;
}));

Просмотреть файл

@ -1,6 +1,6 @@
const asar = require('@electron/asar');
const assert = require('node:assert');
const fs = require('fs-extra');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
@ -41,12 +41,12 @@ try {
// Copy all files to a tmp dir to avoid including scrap files in the ASAR
for (const file of files) {
const newLocation = path.resolve(tmpPath, path.relative(base[0], file));
fs.mkdirsSync(path.dirname(newLocation));
fs.mkdirSync(path.dirname(newLocation), { recursive: true });
fs.writeFileSync(newLocation, fs.readFileSync(file));
}
} catch (err) {
console.error('Unexpected error while generating ASAR', err);
fs.remove(tmpPath)
fs.promises.rm(tmpPath, { force: true, recursive: true })
.then(() => process.exit(1))
.catch(() => process.exit(1));
return;
@ -59,5 +59,5 @@ asar.createPackageWithOptions(tmpPath, out[0], {})
console.error('Unexpected error while generating ASAR', err);
process.exit(1);
};
fs.remove(tmpPath).then(exit).catch(exit);
}).then(() => fs.remove(tmpPath));
fs.promises.rm(tmpPath, { force: true, recursive: true }).then(exit).catch(exit);
}).then(() => fs.promises.rm(tmpPath, { force: true, recursive: true }));

Просмотреть файл

@ -3,7 +3,7 @@
const { ElectronVersions, Installer } = require('@electron/fiddle-core');
const childProcess = require('node:child_process');
const crypto = require('node:crypto');
const fs = require('fs-extra');
const fs = require('node:fs');
const { hashElement } = require('folder-hash');
const os = require('node:os');
const path = require('node:path');
@ -216,7 +216,7 @@ async function installSpecModules (dir) {
env.npm_config_nodedir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
}
if (fs.existsSync(path.resolve(dir, 'node_modules'))) {
await fs.remove(path.resolve(dir, 'node_modules'));
await fs.promises.rm(path.resolve(dir, 'node_modules'), { force: true, recursive: true });
}
const { status } = childProcess.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install', '--frozen-lockfile'], {
env,

Просмотреть файл

@ -3,7 +3,7 @@ import * as cp from 'node:child_process';
import * as https from 'node:https';
import * as http from 'node:http';
import * as net from 'node:net';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { promisify } from 'node:util';
import { app, BrowserWindow, Menu, session, net as electronNet, WebContents, utilityProcess } from 'electron/main';
@ -1118,7 +1118,7 @@ describe('app module', () => {
describe('sessionData', () => {
const appPath = path.join(__dirname, 'fixtures', 'apps', 'set-path');
const appName = fs.readJsonSync(path.join(appPath, 'package.json')).name;
const appName = JSON.parse(fs.readFileSync(path.join(appPath, 'package.json'), 'utf8')).name;
const userDataPath = path.join(app.getPath('appData'), appName);
const tempBrowserDataPath = path.join(app.getPath('temp'), appName);
@ -1139,8 +1139,8 @@ describe('app module', () => {
};
beforeEach(() => {
fs.removeSync(userDataPath);
fs.removeSync(tempBrowserDataPath);
fs.rmSync(userDataPath, { force: true, recursive: true });
fs.rmSync(tempBrowserDataPath, { force: true, recursive: true });
});
it('writes to userData by default', () => {

Просмотреть файл

@ -2,7 +2,7 @@ import { expect } from 'chai';
import * as cp from 'node:child_process';
import * as http from 'node:http';
import * as express from 'express';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as psList from 'ps-list';
import { AddressInfo } from 'node:net';
@ -68,14 +68,14 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
await withTempDirectory(async (dir) => {
const secondAppPath = await copyMacOSFixtureApp(dir, fixture);
const appPJPath = path.resolve(secondAppPath, 'Contents', 'Resources', 'app', 'package.json');
await fs.writeFile(
await fs.promises.writeFile(
appPJPath,
(await fs.readFile(appPJPath, 'utf8')).replace('1.0.0', version)
(await fs.promises.readFile(appPJPath, 'utf8')).replace('1.0.0', version)
);
const infoPath = path.resolve(secondAppPath, 'Contents', 'Info.plist');
await fs.writeFile(
await fs.promises.writeFile(
infoPath,
(await fs.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, `$1${version}`)
(await fs.promises.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, `$1${version}`)
);
await mutateAppPreSign?.mutate(secondAppPath);
await signApp(secondAppPath, identity);
@ -221,9 +221,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
const appPath = await copyMacOSFixtureApp(dir, opts.startFixture);
await opts.mutateAppPreSign?.mutate(appPath);
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
await fs.writeFile(
await fs.promises.writeFile(
infoPath,
(await fs.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, '$11.0.0')
(await fs.promises.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, '$11.0.0')
);
await signApp(appPath, identity);
@ -378,9 +378,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
mutationKey: 'prevent-downgrades',
mutate: async (appPath) => {
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
await fs.writeFile(
await fs.promises.writeFile(
infoPath,
(await fs.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
(await fs.promises.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
);
}
}
@ -418,9 +418,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
mutationKey: 'prevent-downgrades',
mutate: async (appPath) => {
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
await fs.writeFile(
await fs.promises.writeFile(
infoPath,
(await fs.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
(await fs.promises.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
);
}
}
@ -558,7 +558,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
await shipItFlipFlopPromise;
expect(requests).to.have.lengthOf(2, 'should not have relaunched the updated app');
expect(JSON.parse(await fs.readFile(path.resolve(appPath, 'Contents/Resources/app/package.json'), 'utf8')).version).to.equal('1.0.0', 'should still be the old version on disk');
expect(JSON.parse(await fs.promises.readFile(path.resolve(appPath, 'Contents/Resources/app/package.json'), 'utf8')).version).to.equal('1.0.0', 'should still be the old version on disk');
retainerHandle.kill('SIGINT');
});
@ -631,7 +631,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
mutationKey: 'add-resource',
mutate: async (appPath) => {
const resourcesPath = path.resolve(appPath, 'Contents', 'Resources', 'app', 'injected.txt');
await fs.writeFile(resourcesPath, 'demo');
await fs.promises.writeFile(resourcesPath, 'demo');
}
}
}, async (appPath, updateZipPath) => {
@ -669,8 +669,8 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
mutationKey: 'modify-shipit',
mutate: async (appPath) => {
const shipItPath = path.resolve(appPath, 'Contents', 'Frameworks', 'Squirrel.framework', 'Resources', 'ShipIt');
await fs.remove(shipItPath);
await fs.symlink('/tmp/ShipIt', shipItPath, 'file');
await fs.promises.rm(shipItPath, { force: true, recursive: true });
await fs.promises.symlink('/tmp/ShipIt', shipItPath, 'file');
}
}
}, async (appPath, updateZipPath) => {
@ -708,7 +708,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
mutationKey: 'modify-eframework',
mutate: async (appPath) => {
const shipItPath = path.resolve(appPath, 'Contents', 'Frameworks', 'Electron Framework.framework', 'Electron Framework');
await fs.appendFile(shipItPath, Buffer.from('123'));
await fs.promises.appendFile(shipItPath, Buffer.from('123'));
}
}
}, async (appPath, updateZipPath) => {

Просмотреть файл

@ -1,7 +1,7 @@
import { BrowserWindow, ipcMain } from 'electron/main';
import { contextBridge } from 'electron/renderer';
import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as http from 'node:http';
import * as os from 'node:os';
import * as path from 'node:path';
@ -34,7 +34,7 @@ describe('contextBridge', () => {
afterEach(async () => {
await closeWindow(w);
if (dir) await fs.remove(dir);
if (dir) await fs.promises.rm(dir, { force: true, recursive: true });
});
it('should not be accessible when contextIsolation is disabled', async () => {
@ -85,9 +85,9 @@ describe('contextBridge', () => {
});`}
(${bindingCreator.toString()})();`;
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-spec-preload-'));
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-spec-preload-'));
dir = tmpDir;
await fs.writeFile(path.resolve(tmpDir, 'preload.js'), worldId === 0 ? preloadContentForMainWorld : preloadContentForIsolatedWorld);
await fs.promises.writeFile(path.resolve(tmpDir, 'preload.js'), worldId === 0 ? preloadContentForMainWorld : preloadContentForIsolatedWorld);
w = new BrowserWindow({
show: false,
webPreferences: {

Просмотреть файл

@ -3,7 +3,7 @@ import * as path from 'node:path';
import { safeStorage } from 'electron/main';
import { expect } from 'chai';
import { ifdescribe } from './lib/spec-helpers';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import { once } from 'node:events';
describe('safeStorage module', () => {
@ -33,8 +33,8 @@ describe('safeStorage module', () => {
after(async () => {
const pathToEncryptedString = path.resolve(__dirname, 'fixtures', 'api', 'safe-storage', 'encrypted.txt');
if (await fs.pathExists(pathToEncryptedString)) {
await fs.remove(pathToEncryptedString);
if (fs.existsSync(pathToEncryptedString)) {
await fs.promises.rm(pathToEncryptedString, { force: true, recursive: true });
}
});

Просмотреть файл

@ -3,7 +3,7 @@ import { shell } from 'electron/common';
import { closeAllWindows } from './lib/window-helpers';
import { ifdescribe, ifit, listen } from './lib/spec-helpers';
import * as http from 'node:http';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { expect } from 'chai';
@ -79,9 +79,9 @@ describe('shell module', () => {
afterEach(closeAllWindows);
it('moves an item to the trash', async () => {
const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
const dir = await fs.promises.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
const filename = path.join(dir, 'temp-to-be-deleted');
await fs.writeFile(filename, 'dummy-contents');
await fs.promises.writeFile(filename, 'dummy-contents');
await shell.trashItem(filename);
expect(fs.existsSync(filename)).to.be.false();
});

Просмотреть файл

@ -2,7 +2,7 @@ import { expect } from 'chai';
import * as cp from 'node:child_process';
import * as nodeCrypto from 'node:crypto';
import * as originalFs from 'node:original-fs';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { ifdescribe } from './lib/spec-helpers';
@ -82,7 +82,7 @@ describe('fuses', function () {
};
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-asar-integrity-spec-'));
tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-asar-integrity-spec-'));
appPath = await copyApp(tmpDir);
});

Просмотреть файл

@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as cp from 'node:child_process';
import { BrowserWindow } from 'electron';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { pathToFileURL } from 'node:url';
@ -72,15 +72,15 @@ describe('esm', () => {
if (w) w.close();
w = null;
while (tempDirs.length) {
await fs.remove(tempDirs.pop()!);
await fs.promises.rm(tempDirs.pop()!, { force: true, recursive: true });
}
});
async function loadWindowWithPreload (preload: string, webPreferences: Electron.WebPreferences) {
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'e-spec-preload-'));
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'e-spec-preload-'));
tempDirs.push(tmpDir);
const preloadPath = path.resolve(tmpDir, 'preload.mjs');
await fs.writeFile(preloadPath, preload);
await fs.promises.writeFile(preloadPath, preload);
w = new BrowserWindow({
show: false,

Просмотреть файл

@ -1,5 +1,5 @@
import * as cp from 'node:child_process';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { expect } from 'chai';
@ -37,13 +37,13 @@ export async function copyMacOSFixtureApp (newDir: string, fixture: string | nul
cp.spawnSync('cp', ['-R', appBundlePath, path.dirname(newPath)]);
if (fixture) {
const appDir = path.resolve(newPath, 'Contents/Resources/app');
await fs.mkdirp(appDir);
await fs.copy(path.resolve(fixturesPath, 'auto-update', fixture), appDir);
await fs.promises.mkdir(appDir, { recursive: true });
await fs.promises.cp(path.resolve(fixturesPath, 'auto-update', fixture), appDir, { recursive: true });
}
const plistPath = path.resolve(newPath, 'Contents', 'Info.plist');
await fs.writeFile(
await fs.promises.writeFile(
plistPath,
(await fs.readFile(plistPath, 'utf8')).replace('<key>BuildMachineOSBuild</key>', `<key>NSAppTransportSecurity</key>
(await fs.promises.readFile(plistPath, 'utf8')).replace('<key>BuildMachineOSBuild</key>', `<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>

Просмотреть файл

@ -1,6 +1,5 @@
import * as cp from 'node:child_process';
import * as fs from 'original-fs';
import * as fsExtra from 'fs-extra';
import * as os from 'node:os';
import * as path from 'node:path';
@ -20,7 +19,7 @@ export async function copyApp (targetDir: string): Promise<string> {
const filesToCopy = (fs.readFileSync(zipManifestPath, 'utf-8')).split('\n').filter(f => f !== 'LICENSE' && f !== 'LICENSES.chromium.html' && f !== 'version' && f.trim());
await Promise.all(
filesToCopy.map(async rel => {
await fsExtra.mkdirp(path.dirname(path.resolve(targetDir, rel)));
await fs.promises.mkdir(path.dirname(path.resolve(targetDir, rel)), { recursive: true });
fs.copyFileSync(path.resolve(baseDir, rel), path.resolve(targetDir, rel));
})
);
@ -29,7 +28,7 @@ export async function copyApp (targetDir: string): Promise<string> {
}
export async function withTempDirectory (fn: (dir: string) => Promise<void>, autoCleanUp = true) {
const dir = await fsExtra.mkdtemp(path.resolve(os.tmpdir(), 'electron-update-spec-'));
const dir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-update-spec-'));
try {
await fn(dir);
} finally {

Просмотреть файл

@ -1,6 +1,6 @@
import { expect } from 'chai';
import * as childProcess from 'node:child_process';
import * as fs from 'fs-extra';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as util from 'node:util';
import { getRemoteContext, ifdescribe, ifit, itremote, useRemoteContext } from './lib/spec-helpers';
@ -738,7 +738,7 @@ describe('node feature', () => {
return;
}
const alienBinary = path.join(appPath, 'Contents/MacOS/node');
await fs.copy(path.join(nodePath, 'node'), alienBinary);
await fs.promises.cp(path.join(nodePath, 'node'), alienBinary, { recursive: true });
// Try to execute electron app from the alien node in app bundle.
const { code, out } = await spawn(alienBinary, [script, path.join(appPath, 'Contents/MacOS/Electron')]);
expect(code).to.equal(0);

Просмотреть файл

@ -789,13 +789,6 @@
"@types/qs" "*"
"@types/serve-static" "*"
"@types/fs-extra@^9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.1.tgz#91c8fc4c51f6d5dbe44c2ca9ab09310bd00c7918"
integrity sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg==
dependencies:
"@types/node" "*"
"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
@ -1547,11 +1540,6 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
available-typed-arrays@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
@ -3050,16 +3038,6 @@ fs-extra@^8.1.0:
jsonfile "^4.0.0"
universalify "^0.1.0"
fs-extra@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^1.0.0"
fs-minipass@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb"