Skip to content

Commit 6049967

Browse files
ckerrpull[bot]
authored andcommitted
build: remove fs-extra devdep (#42533)
* 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
1 parent 482713f commit 6049967

15 files changed

Lines changed: 55 additions & 80 deletions

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@types/chai-as-promised": "^7.1.3",
2020
"@types/dirty-chai": "^2.0.2",
2121
"@types/express": "^4.17.13",
22-
"@types/fs-extra": "^9.0.1",
2322
"@types/minimist": "^1.2.0",
2423
"@types/mocha": "^7.0.2",
2524
"@types/node": "^20.9.0",
@@ -50,7 +49,6 @@
5049
"events": "^3.2.0",
5150
"express": "^4.19.2",
5251
"folder-hash": "^2.1.1",
53-
"fs-extra": "^9.0.1",
5452
"got": "^11.8.5",
5553
"husky": "^8.0.1",
5654
"lint": "^1.1.2",

script/gen-filenames.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as cp from 'node:child_process';
2-
import * as fs from 'fs-extra';
2+
import * as fs from 'node:fs';
33
import * as os from 'node:os';
44
import * as path from 'node:path';
55

@@ -48,7 +48,7 @@ const main = async () => {
4848
];
4949

5050
const webpackTargetsWithDeps = await Promise.all(webpackTargets.map(async webpackTarget => {
51-
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
51+
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
5252
const child = cp.spawn('node', [
5353
'./node_modules/webpack-cli/bin/cli.js',
5454
'--config', `./build/webpack/${webpackTarget.config}`,
@@ -89,7 +89,7 @@ const main = async () => {
8989
// Make the generated list easier to read
9090
.sort()
9191
};
92-
await fs.remove(tmpDir);
92+
await fs.promises.rm(tmpDir, { force: true, recursive: true });
9393
return webpackTargetWithDeps;
9494
}));
9595

script/gn-asar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const asar = require('@electron/asar');
22
const assert = require('node:assert');
3-
const fs = require('fs-extra');
3+
const fs = require('node:fs');
44
const os = require('node:os');
55
const path = require('node:path');
66

@@ -41,12 +41,12 @@ try {
4141
// Copy all files to a tmp dir to avoid including scrap files in the ASAR
4242
for (const file of files) {
4343
const newLocation = path.resolve(tmpPath, path.relative(base[0], file));
44-
fs.mkdirsSync(path.dirname(newLocation));
44+
fs.mkdirSync(path.dirname(newLocation), { recursive: true });
4545
fs.writeFileSync(newLocation, fs.readFileSync(file));
4646
}
4747
} catch (err) {
4848
console.error('Unexpected error while generating ASAR', err);
49-
fs.remove(tmpPath)
49+
fs.promises.rm(tmpPath, { force: true, recursive: true })
5050
.then(() => process.exit(1))
5151
.catch(() => process.exit(1));
5252
return;
@@ -59,5 +59,5 @@ asar.createPackageWithOptions(tmpPath, out[0], {})
5959
console.error('Unexpected error while generating ASAR', err);
6060
process.exit(1);
6161
};
62-
fs.remove(tmpPath).then(exit).catch(exit);
63-
}).then(() => fs.remove(tmpPath));
62+
fs.promises.rm(tmpPath, { force: true, recursive: true }).then(exit).catch(exit);
63+
}).then(() => fs.promises.rm(tmpPath, { force: true, recursive: true }));

script/spec-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { ElectronVersions, Installer } = require('@electron/fiddle-core');
44
const childProcess = require('node:child_process');
55
const crypto = require('node:crypto');
6-
const fs = require('fs-extra');
6+
const fs = require('node:fs');
77
const { hashElement } = require('folder-hash');
88
const os = require('node:os');
99
const path = require('node:path');
@@ -216,7 +216,7 @@ async function installSpecModules (dir) {
216216
env.npm_config_nodedir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
217217
}
218218
if (fs.existsSync(path.resolve(dir, 'node_modules'))) {
219-
await fs.remove(path.resolve(dir, 'node_modules'));
219+
await fs.promises.rm(path.resolve(dir, 'node_modules'), { force: true, recursive: true });
220220
}
221221
const { status } = childProcess.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install', '--frozen-lockfile'], {
222222
env,

spec/api-app-spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cp from 'node:child_process';
33
import * as https from 'node:https';
44
import * as http from 'node:http';
55
import * as net from 'node:net';
6-
import * as fs from 'fs-extra';
6+
import * as fs from 'node:fs';
77
import * as path from 'node:path';
88
import { promisify } from 'node:util';
99
import { app, BrowserWindow, Menu, session, net as electronNet, WebContents, utilityProcess } from 'electron/main';
@@ -1118,7 +1118,7 @@ describe('app module', () => {
11181118

11191119
describe('sessionData', () => {
11201120
const appPath = path.join(__dirname, 'fixtures', 'apps', 'set-path');
1121-
const appName = fs.readJsonSync(path.join(appPath, 'package.json')).name;
1121+
const appName = JSON.parse(fs.readFileSync(path.join(appPath, 'package.json'), 'utf8')).name;
11221122
const userDataPath = path.join(app.getPath('appData'), appName);
11231123
const tempBrowserDataPath = path.join(app.getPath('temp'), appName);
11241124

@@ -1139,8 +1139,8 @@ describe('app module', () => {
11391139
};
11401140

11411141
beforeEach(() => {
1142-
fs.removeSync(userDataPath);
1143-
fs.removeSync(tempBrowserDataPath);
1142+
fs.rmSync(userDataPath, { force: true, recursive: true });
1143+
fs.rmSync(tempBrowserDataPath, { force: true, recursive: true });
11441144
});
11451145

11461146
it('writes to userData by default', () => {

spec/api-autoupdater-darwin-spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import * as cp from 'node:child_process';
33
import * as http from 'node:http';
44
import * as express from 'express';
5-
import * as fs from 'fs-extra';
5+
import * as fs from 'node:fs';
66
import * as path from 'node:path';
77
import * as psList from 'ps-list';
88
import { AddressInfo } from 'node:net';
@@ -68,14 +68,14 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
6868
await withTempDirectory(async (dir) => {
6969
const secondAppPath = await copyMacOSFixtureApp(dir, fixture);
7070
const appPJPath = path.resolve(secondAppPath, 'Contents', 'Resources', 'app', 'package.json');
71-
await fs.writeFile(
71+
await fs.promises.writeFile(
7272
appPJPath,
73-
(await fs.readFile(appPJPath, 'utf8')).replace('1.0.0', version)
73+
(await fs.promises.readFile(appPJPath, 'utf8')).replace('1.0.0', version)
7474
);
7575
const infoPath = path.resolve(secondAppPath, 'Contents', 'Info.plist');
76-
await fs.writeFile(
76+
await fs.promises.writeFile(
7777
infoPath,
78-
(await fs.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, `$1${version}`)
78+
(await fs.promises.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, `$1${version}`)
7979
);
8080
await mutateAppPreSign?.mutate(secondAppPath);
8181
await signApp(secondAppPath, identity);
@@ -221,9 +221,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
221221
const appPath = await copyMacOSFixtureApp(dir, opts.startFixture);
222222
await opts.mutateAppPreSign?.mutate(appPath);
223223
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
224-
await fs.writeFile(
224+
await fs.promises.writeFile(
225225
infoPath,
226-
(await fs.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, '$11.0.0')
226+
(await fs.promises.readFile(infoPath, 'utf8')).replace(/(<key>CFBundleShortVersionString<\/key>\s+<string>)[^<]+/g, '$11.0.0')
227227
);
228228
await signApp(appPath, identity);
229229

@@ -378,9 +378,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
378378
mutationKey: 'prevent-downgrades',
379379
mutate: async (appPath) => {
380380
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
381-
await fs.writeFile(
381+
await fs.promises.writeFile(
382382
infoPath,
383-
(await fs.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
383+
(await fs.promises.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
384384
);
385385
}
386386
}
@@ -418,9 +418,9 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
418418
mutationKey: 'prevent-downgrades',
419419
mutate: async (appPath) => {
420420
const infoPath = path.resolve(appPath, 'Contents', 'Info.plist');
421-
await fs.writeFile(
421+
await fs.promises.writeFile(
422422
infoPath,
423-
(await fs.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
423+
(await fs.promises.readFile(infoPath, 'utf8')).replace('<key>NSSupportsAutomaticGraphicsSwitching</key>', '<key>ElectronSquirrelPreventDowngrades</key><true/><key>NSSupportsAutomaticGraphicsSwitching</key>')
424424
);
425425
}
426426
}
@@ -558,7 +558,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
558558

559559
await shipItFlipFlopPromise;
560560
expect(requests).to.have.lengthOf(2, 'should not have relaunched the updated app');
561-
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');
561+
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');
562562

563563
retainerHandle.kill('SIGINT');
564564
});
@@ -631,7 +631,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
631631
mutationKey: 'add-resource',
632632
mutate: async (appPath) => {
633633
const resourcesPath = path.resolve(appPath, 'Contents', 'Resources', 'app', 'injected.txt');
634-
await fs.writeFile(resourcesPath, 'demo');
634+
await fs.promises.writeFile(resourcesPath, 'demo');
635635
}
636636
}
637637
}, async (appPath, updateZipPath) => {
@@ -669,8 +669,8 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
669669
mutationKey: 'modify-shipit',
670670
mutate: async (appPath) => {
671671
const shipItPath = path.resolve(appPath, 'Contents', 'Frameworks', 'Squirrel.framework', 'Resources', 'ShipIt');
672-
await fs.remove(shipItPath);
673-
await fs.symlink('/tmp/ShipIt', shipItPath, 'file');
672+
await fs.promises.rm(shipItPath, { force: true, recursive: true });
673+
await fs.promises.symlink('/tmp/ShipIt', shipItPath, 'file');
674674
}
675675
}
676676
}, async (appPath, updateZipPath) => {
@@ -708,7 +708,7 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
708708
mutationKey: 'modify-eframework',
709709
mutate: async (appPath) => {
710710
const shipItPath = path.resolve(appPath, 'Contents', 'Frameworks', 'Electron Framework.framework', 'Electron Framework');
711-
await fs.appendFile(shipItPath, Buffer.from('123'));
711+
await fs.promises.appendFile(shipItPath, Buffer.from('123'));
712712
}
713713
}
714714
}, async (appPath, updateZipPath) => {

spec/api-context-bridge-spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BrowserWindow, ipcMain } from 'electron/main';
22
import { contextBridge } from 'electron/renderer';
33
import { expect } from 'chai';
4-
import * as fs from 'fs-extra';
4+
import * as fs from 'node:fs';
55
import * as http from 'node:http';
66
import * as os from 'node:os';
77
import * as path from 'node:path';
@@ -34,7 +34,7 @@ describe('contextBridge', () => {
3434

3535
afterEach(async () => {
3636
await closeWindow(w);
37-
if (dir) await fs.remove(dir);
37+
if (dir) await fs.promises.rm(dir, { force: true, recursive: true });
3838
});
3939

4040
it('should not be accessible when contextIsolation is disabled', async () => {
@@ -85,9 +85,9 @@ describe('contextBridge', () => {
8585
});`}
8686
(${bindingCreator.toString()})();`;
8787

88-
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-spec-preload-'));
88+
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-spec-preload-'));
8989
dir = tmpDir;
90-
await fs.writeFile(path.resolve(tmpDir, 'preload.js'), worldId === 0 ? preloadContentForMainWorld : preloadContentForIsolatedWorld);
90+
await fs.promises.writeFile(path.resolve(tmpDir, 'preload.js'), worldId === 0 ? preloadContentForMainWorld : preloadContentForIsolatedWorld);
9191
w = new BrowserWindow({
9292
show: false,
9393
webPreferences: {

spec/api-safe-storage-spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'node:path';
33
import { safeStorage } from 'electron/main';
44
import { expect } from 'chai';
55
import { ifdescribe } from './lib/spec-helpers';
6-
import * as fs from 'fs-extra';
6+
import * as fs from 'node:fs';
77
import { once } from 'node:events';
88

99
describe('safeStorage module', () => {
@@ -33,8 +33,8 @@ describe('safeStorage module', () => {
3333

3434
after(async () => {
3535
const pathToEncryptedString = path.resolve(__dirname, 'fixtures', 'api', 'safe-storage', 'encrypted.txt');
36-
if (await fs.pathExists(pathToEncryptedString)) {
37-
await fs.remove(pathToEncryptedString);
36+
if (fs.existsSync(pathToEncryptedString)) {
37+
await fs.promises.rm(pathToEncryptedString, { force: true, recursive: true });
3838
}
3939
});
4040

spec/api-shell-spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { shell } from 'electron/common';
33
import { closeAllWindows } from './lib/window-helpers';
44
import { ifdescribe, ifit, listen } from './lib/spec-helpers';
55
import * as http from 'node:http';
6-
import * as fs from 'fs-extra';
6+
import * as fs from 'node:fs';
77
import * as os from 'node:os';
88
import * as path from 'node:path';
99
import { expect } from 'chai';
@@ -79,9 +79,9 @@ describe('shell module', () => {
7979
afterEach(closeAllWindows);
8080

8181
it('moves an item to the trash', async () => {
82-
const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
82+
const dir = await fs.promises.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
8383
const filename = path.join(dir, 'temp-to-be-deleted');
84-
await fs.writeFile(filename, 'dummy-contents');
84+
await fs.promises.writeFile(filename, 'dummy-contents');
8585
await shell.trashItem(filename);
8686
expect(fs.existsSync(filename)).to.be.false();
8787
});

spec/asar-integrity-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import * as cp from 'node:child_process';
33
import * as nodeCrypto from 'node:crypto';
44
import * as originalFs from 'node:original-fs';
5-
import * as fs from 'fs-extra';
5+
import * as fs from 'node:fs';
66
import * as os from 'node:os';
77
import * as path from 'node:path';
88
import { ifdescribe } from './lib/spec-helpers';
@@ -82,7 +82,7 @@ describe('fuses', function () {
8282
};
8383

8484
beforeEach(async () => {
85-
tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-asar-integrity-spec-'));
85+
tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-asar-integrity-spec-'));
8686
appPath = await copyApp(tmpDir);
8787
});
8888

0 commit comments

Comments
 (0)