Skip to content

Commit 492c8da

Browse files
committed
feat: Remove fs-extra
1 parent 57d5043 commit 492c8da

File tree

15 files changed

+62
-84
lines changed

15 files changed

+62
-84
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.0",
6-
"fs-extra": "11.3.0",
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.0.1",
1513
"typescript": "5.9.2"

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 {promises as fs} from 'node:fs';
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);
41+
} catch {}
42+
43+
try {
44+
await fs.mkdir(this.iconsDir);
45+
} catch {}
46+
47+
try {
48+
await fs.mkdir(this.PNGoutputDir);
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);
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);
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.0",
17-
"fs-extra": "11.3.0",
1816
"http-status-codes": "2.3.0",
1917
"nock": "14.0.8",
2018
"rimraf": "6.0.1",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {randomUUID} from 'node:crypto';
44
import {expect, describe, test, beforeEach, beforeAll, afterAll, afterEach} from 'vitest';
55
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
66
import nock from 'nock';
7-
import fs from 'fs-extra';
7+
import {promises as fs} from 'node:fs';
88

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

@@ -32,22 +32,24 @@ const createRandomBody = (): RawReleaseInfo[] => [
3232
];
3333

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

3838
describe('ElectronInfo', () => {
3939
let releases: string;
4040

4141
beforeAll(async () => {
42-
await fs.ensureDir(tempDir);
42+
try {
43+
await fs.mkdir(tempDir);
44+
} catch {}
4345
releases = await fs.readFile(fullReleasesFile, 'utf8');
4446
});
4547

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

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

5254
afterEach(() => nock.cleanAll());
5355

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.0",
66
"cosmiconfig": "9.0.0",
7-
"fs-extra": "11.3.0",
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.0.0",
1816
"rimraf": "6.0.1",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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', () => ({
9+
vi.mock('fs', () => ({
1010
default: {
1111
lstat: () => Promise.resolve({isDirectory: () => false, isFile: () => true}),
1212
readFile: () => {},

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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import {promises as fs} from 'node:fs';
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);
42+
} catch {}
4143
}
4244

4345
const resolvedPath = path.resolve(entry);
@@ -64,7 +66,9 @@ export class ExtractService {
6466
entries.map(async ([filePath, entry], index) => {
6567
const resolvedFilePath = path.join(this.outputDir!, filePath);
6668
if (entry.dir) {
67-
await fs.ensureDir(resolvedFilePath);
69+
try {
70+
await fs.mkdir(resolvedFilePath);
71+
} catch {}
6872
} else {
6973
const data = await entry.async('nodebuffer');
7074
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 {promises as fs} from 'node:fs';
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);
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 {promises as fs} from 'node:fs';
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)