build: remove fs-extra devdep (#42708)

* 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
committed by GitHub
parent 2c3a9fd3c5
commit e480e29cfc
15 changed files with 55 additions and 80 deletions

View File

@@ -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', () => {

View File

@@ -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) => {

View File

@@ -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: {

View File

@@ -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 });
}
});

View File

@@ -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();
});

View File

@@ -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);
});

View File

@@ -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,

View File

@@ -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/>

View File

@@ -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 {

View File

@@ -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);