Skip to content

Commit d1434d9

Browse files
authored
feat: Remove fs-extra (#977)
1 parent bf33b5e commit d1434d9

File tree

15 files changed

+73
-93
lines changed

15 files changed

+73
-93
lines changed

packages/electron-icon-generator/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"bin": "dist/index.js",
44
"dependencies": {
55
"commander": "14.0.2",
6-
"fs-extra": "11.3.2",
76
"icon-gen": "5.0.0",
87
"jimp": "1.6.0"
98
},
109
"description": "An icon generator to generate all the icon files needed for electron packaging",
1110
"devDependencies": {
12-
"@types/fs-extra": "11.0.4",
1311
"@types/pngjs": "6.0.5",
1412
"rimraf": "6.1.0",
1513
"tsx": "4.20.6",

packages/electron-icon-generator/src/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3+
import fs from 'node:fs/promises';
34
import path from 'node:path';
4-
import fs from 'fs-extra';
55
import {Jimp} from 'jimp';
66
import icongen from 'icon-gen';
77

@@ -36,9 +36,17 @@ export class IconGenerator {
3636
private async createPNG(size: number): Promise<string> {
3737
const fileName = size.toString();
3838

39-
await fs.ensureDir(this.options.output);
40-
await fs.ensureDir(this.iconsDir);
41-
await fs.ensureDir(this.PNGoutputDir);
39+
try {
40+
await fs.mkdir(this.options.output, {recursive: true});
41+
} catch {}
42+
43+
try {
44+
await fs.mkdir(this.iconsDir, {recursive: true});
45+
} catch {}
46+
47+
try {
48+
await fs.mkdir(this.PNGoutputDir, {recursive: true});
49+
} catch {}
4250

4351
const image = await Jimp.read(this.options.input);
4452
const resizeFilePath = path.join(this.PNGoutputDir, fileName);
@@ -62,7 +70,9 @@ export class IconGenerator {
6270
const macIconsDir = path.join(this.iconsDir, 'mac');
6371
const winIconsDir = path.join(this.iconsDir, 'win');
6472

65-
await fs.ensureDir(macIconsDir);
73+
try {
74+
await fs.mkdir(macIconsDir, {recursive: true});
75+
} catch {}
6676

6777
await icongen.default(this.PNGoutputDir, macIconsDir, {
6878
icns: {
@@ -72,7 +82,9 @@ export class IconGenerator {
7282
report: !this.options.silent,
7383
});
7484

75-
await fs.ensureDir(winIconsDir);
85+
try {
86+
await fs.mkdir(winIconsDir, {recursive: true});
87+
} catch {}
7688

7789
await icongen.default(this.PNGoutputDir, winIconsDir, {
7890
icns: {

packages/electron-info/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
},
1313
"description": "Get useful data about Electron releases.",
1414
"devDependencies": {
15-
"@types/fs-extra": "11.0.4",
1615
"@types/semver": "7.7.1",
17-
"fs-extra": "11.3.2",
1816
"http-status-codes": "2.3.0",
1917
"nock": "14.0.10",
2018
"rimraf": "6.1.0",

packages/electron-info/src/ElectronInfo.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'node:path';
22
import {randomUUID} from 'node:crypto';
3+
import fs from 'node:fs/promises';
34
import {expect, describe, test, beforeEach, beforeAll, afterAll, afterEach} from 'vitest';
45
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
56
import nock from 'nock';
6-
import fs from 'fs-extra';
77

88
import {ElectronInfo, RawReleaseInfo} from './ElectronInfo.js';
99

@@ -30,22 +30,24 @@ const createRandomBody = (): RawReleaseInfo[] => [
3030
];
3131

3232
const provideReleaseFile = async () => {
33-
await fs.copy(fullReleasesFile, path.join(tempDirDownload, 'latest.json'));
33+
await fs.cp(fullReleasesFile, path.join(tempDirDownload, 'latest.json'));
3434
};
3535

3636
describe('ElectronInfo', () => {
3737
let releases: string;
3838

3939
beforeAll(async () => {
40-
await fs.ensureDir(tempDir);
40+
try {
41+
await fs.mkdir(tempDir);
42+
} catch {}
4143
releases = await fs.readFile(fullReleasesFile, 'utf8');
4244
});
4345

4446
beforeEach(() => {
4547
nock(mockUrl).get('/').reply(HTTP_STATUS.OK, releases);
4648
});
4749

48-
afterAll(() => fs.remove(tempDir));
50+
afterAll(() => fs.rm(tempDir, {force: true, recursive: true}));
4951

5052
afterEach(() => nock.cleanAll());
5153

packages/jszip-cli/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
"dependencies": {
55
"commander": "14.0.2",
66
"cosmiconfig": "9.0.0",
7-
"fs-extra": "11.3.2",
87
"glob": "11.0.3",
98
"jszip": "3.10.1",
109
"logdown": "3.3.1",
1110
"progress": "2.0.3"
1211
},
1312
"description": "A zip CLI based on jszip.",
1413
"devDependencies": {
15-
"@types/fs-extra": "11.0.4",
1614
"@types/progress": "2.0.7",
1715
"cross-env": "10.1.0",
1816
"rimraf": "6.1.0",

packages/jszip-cli/src/BuildService.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {expect, describe, test, vi, beforeEach, beforeAll} from 'vitest';
2-
import {JSZipCLI} from '.';
3-
import type {BuildService} from './BuildService';
2+
import {JSZipCLI} from './index.js';
3+
import type {BuildService} from './BuildService.js';
44

55
describe('BuildService', () => {
66
let jsZipCLI: JSZipCLI;
77

88
beforeAll(() => {
9-
vi.mock('fs-extra', () => ({
10-
default: {
11-
lstat: () => Promise.resolve({isDirectory: () => false, isFile: () => true}),
12-
readFile: () => {},
9+
vi.mock('fs', () => ({
10+
promises: {
11+
lstat: async () => ({isDirectory: () => false, isFile: () => true}),
12+
readFile: async () => {},
1313
},
1414
}));
1515
vi.mock('glob', () => ({
@@ -18,7 +18,7 @@ describe('BuildService', () => {
1818
});
1919

2020
const addDefaultSpies = (buildService: BuildService) => {
21-
vi.spyOn<any, any>(buildService, 'checkOutput').mockReturnValue(() => Promise.resolve());
21+
vi.spyOn<any, any>(buildService, 'checkOutput').mockReturnValue(async () => {});
2222
vi.spyOn<any, any>(buildService, 'addFile');
2323
vi.spyOn<any, any>(buildService['fileService'], 'writeFile').mockReturnValue(Promise.resolve());
2424
};

packages/jszip-cli/src/BuildService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'node:path';
2-
import fs from 'fs-extra';
2+
import {promises as fs, Stats as fsStats} from 'node:fs';
33
import JSZip from 'jszip';
44
import logdown from 'logdown';
55
import progress from 'progress';
@@ -87,7 +87,7 @@ export class BuildService {
8787

8888
private async addFile(entry: Entry, isLink = false): Promise<void> {
8989
const {resolvedPath, zipPath} = entry;
90-
let fileStat: fs.Stats;
90+
let fileStat: fsStats;
9191
let fileData: Buffer | string;
9292

9393
try {
@@ -139,7 +139,7 @@ export class BuildService {
139139
}
140140

141141
private async checkEntry(entry: Entry): Promise<void> {
142-
let fileStat: fs.Stats;
142+
let fileStat: fsStats;
143143
try {
144144
fileStat = await fs.lstat(entry.resolvedPath);
145145
} catch (error) {

packages/jszip-cli/src/ExtractService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import fs from 'node:fs/promises';
12
import os from 'node:os';
23
import path from 'node:path';
3-
import fs from 'fs-extra';
44
import JSZip from 'jszip';
55
import logdown from 'logdown';
66
import progress from 'progress';
@@ -37,7 +37,9 @@ export class ExtractService {
3737
for (const entry of rawEntries) {
3838
const jszip = new JSZip();
3939
if (this.outputDir) {
40-
await fs.ensureDir(this.outputDir);
40+
try {
41+
await fs.mkdir(this.outputDir, {recursive: true});
42+
} catch {}
4143
}
4244

4345
const resolvedPath = path.resolve(entry);
@@ -63,9 +65,11 @@ export class ExtractService {
6365
let index = 0;
6466

6567
for (const [filePath, entry] of entries) {
66-
const resolvedFilePath = path.join(this.outputDir!, filePath);
68+
const resolvedFilePath = path.join(this.outputDir, filePath);
6769
if (entry.dir) {
68-
await fs.ensureDir(resolvedFilePath);
70+
try {
71+
await fs.mkdir(resolvedFilePath, {recursive: true});
72+
} catch {}
6973
} else {
7074
const data = await entry.async('nodebuffer');
7175
await fs.writeFile(resolvedFilePath, data, {

packages/jszip-cli/src/FileService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import fs from 'node:fs/promises';
12
import path from 'node:path';
2-
import fs from 'fs-extra';
33
import logdown from 'logdown';
44

55
import type {TerminalOptions} from './interfaces.js';
@@ -29,7 +29,9 @@ export class FileService {
2929
} catch {
3030
this.logger.info(`Directory "${dirPath}" doesn't exist.`, this.options.force ? 'Creating.' : 'Not creating.');
3131
if (this.options.force) {
32-
await fs.ensureDir(dirPath);
32+
try {
33+
await fs.mkdir(dirPath, {recursive: true});
34+
} catch {}
3335
return true;
3436
}
3537
return false;

packages/jszip-cli/src/JSZipCLI.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as fs from 'node:fs/promises';
12
import * as path from 'node:path';
23
import {expect, describe, test, vi, beforeAll, afterAll} from 'vitest';
3-
import fs from 'fs-extra';
4-
import {ConfigFileOptions, JSZipCLI, TerminalOptions} from '.';
4+
import {ConfigFileOptions, JSZipCLI, TerminalOptions} from './index.js';
55

66
const tempDir = path.resolve(__dirname, '.temp');
77
const configFilePath = path.resolve(tempDir, 'config.json');
@@ -28,13 +28,17 @@ async function buildOptions(additionalConfig?: Partial<AllOptions>): Promise<All
2828
...additionalConfig,
2929
};
3030

31-
await fs.writeJSON(configFilePath, fileConfig);
31+
await fs.writeFile(configFilePath, JSON.stringify(fileConfig), 'utf-8');
3232
return fileConfig;
3333
}
3434

3535
describe('JSZipCLI', () => {
36-
beforeAll(() => fs.ensureDir(tempDir));
37-
afterAll(() => fs.remove(tempDir));
36+
beforeAll(async () => {
37+
try {
38+
await fs.mkdir(tempDir);
39+
} catch {}
40+
});
41+
afterAll(() => fs.rm(tempDir, {force: true, recursive: true}));
3842

3943
test('can read from a configuration file', async () => {
4044
const builtOptions = await buildOptions();

0 commit comments

Comments
 (0)